-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathstabilizer.hpp
More file actions
81 lines (63 loc) · 2.62 KB
/
Copy pathstabilizer.hpp
File metadata and controls
81 lines (63 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Copyright (C) 2026 Simon D. Levy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, in version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <pidcontrol/pids/rollpitch.hpp>
#include <pidcontrol/pids/yaw.hpp>
namespace hf {
class StabilizerPidController {
private:
static constexpr float kYawMaxDps = 160;
public:
Setpoint setpoint;
StabilizerPidController() = default;
StabilizerPidController& operator=(
const StabilizerPidController& other) = default;
StabilizerPidController(
const RollPitchPid & pitch_pid,
const RollPitchPid & roll_pid,
const YawPid & yaw_pid,
const Setpoint & setpoint)
: setpoint(setpoint),
pitch_pid_(pitch_pid),
roll_pid_(roll_pid),
yaw_pid_(yaw_pid) {}
static auto Run(
const StabilizerPidController & s,
const bool airborne,
const float dt,
const VehicleState & state,
const Setpoint & setpoint_in) -> StabilizerPidController
{
const auto roll_pid = RollPitchPid::Run(s.roll_pid_,
dt, airborne, setpoint_in.roll, state.phi, state.dphi);
const auto pitch_pid = RollPitchPid::Run(s.pitch_pid_,
dt, airborne, setpoint_in.pitch, state.theta, state.dtheta);
const auto yaw_pid = YawPid::Run(s.yaw_pid_,
dt, airborne, setpoint_in.yaw * kYawMaxDps, state.dpsi);
const auto setpoint_out = Setpoint(
setpoint_in.thrust,
roll_pid.output,
pitch_pid.output,
yaw_pid.output);
return StabilizerPidController(
roll_pid, pitch_pid, yaw_pid, setpoint_out);
}
private:
RollPitchPid pitch_pid_;
RollPitchPid roll_pid_;
YawPid yaw_pid_;
};
}