Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AC_AttitudeControl/AC_AttitudeControl_Multi.h
9573 views
1
#pragma once
2
3
/// @file AC_AttitudeControl_Multi.h
4
/// @brief ArduCopter attitude control library
5
6
#include "AC_AttitudeControl.h"
7
#include <AP_Motors/AP_MotorsMulticopter.h>
8
9
// default rate controller PID gains
10
#ifndef AC_ATC_MULTI_RATE_RP_P
11
# define AC_ATC_MULTI_RATE_RP_P 0.135f
12
#endif
13
#ifndef AC_ATC_MULTI_RATE_RP_I
14
# define AC_ATC_MULTI_RATE_RP_I 0.135f
15
#endif
16
#ifndef AC_ATC_MULTI_RATE_RP_D
17
# define AC_ATC_MULTI_RATE_RP_D 0.0036f
18
#endif
19
#ifndef AC_ATC_MULTI_RATE_RP_IMAX
20
# define AC_ATC_MULTI_RATE_RP_IMAX 0.5f
21
#endif
22
#ifndef AC_ATC_MULTI_RATE_RPY_FILT_HZ
23
# define AC_ATC_MULTI_RATE_RPY_FILT_HZ 20.0f
24
#endif
25
#ifndef AC_ATC_MULTI_RATE_YAW_P
26
# define AC_ATC_MULTI_RATE_YAW_P 0.180f
27
#endif
28
#ifndef AC_ATC_MULTI_RATE_YAW_I
29
# define AC_ATC_MULTI_RATE_YAW_I 0.018f
30
#endif
31
#ifndef AC_ATC_MULTI_RATE_YAW_D
32
# define AC_ATC_MULTI_RATE_YAW_D 0.0f
33
#endif
34
#ifndef AC_ATC_MULTI_RATE_YAW_IMAX
35
# define AC_ATC_MULTI_RATE_YAW_IMAX 0.5f
36
#endif
37
#ifndef AC_ATC_MULTI_RATE_YAW_FILT_HZ
38
# define AC_ATC_MULTI_RATE_YAW_FILT_HZ 2.5f
39
#endif
40
41
42
class AC_AttitudeControl_Multi : public AC_AttitudeControl {
43
public:
44
AC_AttitudeControl_Multi(AP_AHRS_View &ahrs, AP_MotorsMulticopter& motors);
45
46
// empty destructor to suppress compiler warning
47
virtual ~AC_AttitudeControl_Multi() {}
48
49
// pid accessors
50
AC_PID& get_rate_roll_pid() override { return _pid_rate_roll; }
51
AC_PID& get_rate_pitch_pid() override { return _pid_rate_pitch; }
52
AC_PID& get_rate_yaw_pid() override { return _pid_rate_yaw; }
53
const AC_PID& get_rate_roll_pid() const override { return _pid_rate_roll; }
54
const AC_PID& get_rate_pitch_pid() const override { return _pid_rate_pitch; }
55
const AC_PID& get_rate_yaw_pid() const override { return _pid_rate_yaw; }
56
57
// Update Alt_Hold angle maximum
58
void update_althold_lean_angle_max(float throttle_in) override;
59
60
// Set output throttle
61
void set_throttle_out(float throttle_in, bool apply_angle_boost, float filt_cutoff) override;
62
63
// Calculate body-frame throttle required to produce the given earth-frame throttle input (accounts for vehicle tilt)
64
float get_throttle_boosted(float throttle_in);
65
66
// Set desired throttle vs attitude mixing (actual mix is slewed toward this value over 1~2 seconds)
67
// Low values favor pilot/autopilot throttle over attitude control; high values prioritize attitude control
68
// Has no effect when throttle is above hover throttle
69
void set_throttle_mix_min() override { _throttle_rpy_mix_desired = _thr_mix_min; }
70
void set_throttle_mix_man() override { _throttle_rpy_mix_desired = _thr_mix_man; }
71
void set_throttle_mix_max(float ratio) override;
72
void set_throttle_mix_value(float value) override { _throttle_rpy_mix_desired = _throttle_rpy_mix = value; }
73
float get_throttle_mix(void) const override { return _throttle_rpy_mix; }
74
75
// Returns true if throttle mix is near minimum (i.e., attitude control is deprioritised)
76
bool is_throttle_mix_min() const override { return (_throttle_rpy_mix < 1.25f * _thr_mix_min); }
77
78
// run lowest level body-frame rate controller and send outputs to the motors
79
void rate_controller_run_dt(const Vector3f& gyro_rads, float dt) override;
80
void rate_controller_target_reset() override;
81
void rate_controller_run() override;
82
83
// sanity check parameters. should be called once before take-off
84
void parameter_sanity_check() override;
85
86
// set the PID notch sample rates
87
void set_notch_sample_rate(float sample_rate) override;
88
89
// user settable parameters
90
static const struct AP_Param::GroupInfo var_info[];
91
92
protected:
93
94
// Boosts angle controller gains during rapid throttle changes to improve responsiveness
95
// boost angle_p/pd each cycle on high throttle slew
96
void update_throttle_gain_boost();
97
98
// Slews the current throttle-to-attitude mix ratio toward the target (_throttle_rpy_mix_desired)
99
void update_throttle_rpy_mix();
100
101
// Get throttle limit based on priority of attitude vs throttle control (used for blending during low thrust)
102
float get_throttle_avg_max(float throttle_in);
103
104
AP_MotorsMulticopter& _motors_multi;
105
106
// Roll rate PID controller (used for body-frame angular rate control)
107
AC_PID _pid_rate_roll {
108
AC_PID::Defaults{
109
.p = AC_ATC_MULTI_RATE_RP_P,
110
.i = AC_ATC_MULTI_RATE_RP_I,
111
.d = AC_ATC_MULTI_RATE_RP_D,
112
.ff = 0.0f,
113
.imax = AC_ATC_MULTI_RATE_RP_IMAX,
114
.filt_T_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,
115
.filt_E_hz = 0.0f,
116
.filt_D_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,
117
.srmax = 0,
118
.srtau = 1.0
119
}
120
};
121
// Pitch rate PID controller (used for body-frame angular rate control)
122
AC_PID _pid_rate_pitch{
123
AC_PID::Defaults{
124
.p = AC_ATC_MULTI_RATE_RP_P,
125
.i = AC_ATC_MULTI_RATE_RP_I,
126
.d = AC_ATC_MULTI_RATE_RP_D,
127
.ff = 0.0f,
128
.imax = AC_ATC_MULTI_RATE_RP_IMAX,
129
.filt_T_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,
130
.filt_E_hz = 0.0f,
131
.filt_D_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,
132
.srmax = 0,
133
.srtau = 1.0
134
}
135
};
136
// Yaw rate PID controller (used for body-frame angular rate control)
137
AC_PID _pid_rate_yaw{
138
AC_PID::Defaults{
139
.p = AC_ATC_MULTI_RATE_YAW_P,
140
.i = AC_ATC_MULTI_RATE_YAW_I,
141
.d = AC_ATC_MULTI_RATE_YAW_D,
142
.ff = 0.0f,
143
.imax = AC_ATC_MULTI_RATE_YAW_IMAX,
144
.filt_T_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,
145
.filt_E_hz = AC_ATC_MULTI_RATE_YAW_FILT_HZ,
146
.filt_D_hz = AC_ATC_MULTI_RATE_RPY_FILT_HZ,
147
.srmax = 0,
148
.srtau = 1.0
149
}
150
};
151
152
AP_Float _thr_mix_man; // throttle vs attitude control prioritisation used when using manual throttle (higher values mean we prioritise attitude control over throttle)
153
AP_Float _thr_mix_min; // throttle vs attitude control prioritisation used when landing (higher values mean we prioritise attitude control over throttle)
154
AP_Float _thr_mix_max; // throttle vs attitude control prioritisation used during active flight (higher values mean we prioritise attitude control over throttle)
155
156
// angle_p/pd boost multiplier
157
AP_Float _throttle_gain_boost;
158
};
159
160