Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AC_AttitudeControl/AC_AttitudeControl_Heli.h
9673 views
1
#pragma once
2
3
/// @file AC_AttitudeControl_Heli.h
4
/// @brief ArduCopter attitude control library for traditional helicopters
5
6
#include "AC_AttitudeControl.h"
7
#include <AP_Motors/AP_MotorsHeli.h>
8
#include <AC_PID/AC_HELI_PID.h>
9
#include <Filter/Filter.h>
10
11
// default rate controller PID gains
12
#define AC_ATC_HELI_RATE_RP_P 0.024f
13
#define AC_ATC_HELI_RATE_RP_I 0.15f
14
#define AC_ATC_HELI_RATE_RP_D 0.001f
15
#define AC_ATC_HELI_RATE_RP_IMAX 0.4f
16
#define AC_ATC_HELI_RATE_RP_FF 0.15f
17
#define AC_ATC_HELI_RATE_RP_FILT_HZ 20.0f
18
#define AC_ATC_HELI_RATE_RP_ILMI 0.05f // Default I-term Leak Minimum
19
#define AC_ATC_HELI_RATE_YAW_P 0.18f
20
#define AC_ATC_HELI_RATE_YAW_I 0.12f
21
#define AC_ATC_HELI_RATE_YAW_D 0.003f
22
#define AC_ATC_HELI_RATE_YAW_IMAX 0.4f
23
#define AC_ATC_HELI_RATE_YAW_FF 0.024f
24
#define AC_ATC_HELI_RATE_YAW_FILT_HZ 20.0f
25
26
#define AC_ATTITUDE_HELI_ANGLE_LIMIT_THROTTLE_MAX 0.95f // Heli's use 95% of max collective before limiting frame angle
27
#define AC_ATTITUDE_HELI_RATE_INTEGRATOR_LEAK_RATE 0.02f
28
#define AC_ATTITUDE_HELI_RATE_RP_FF_FILTER 20.0f
29
#define AC_ATTITUDE_HELI_RATE_Y_FF_FILTER 20.0f
30
#define AC_ATTITUDE_HELI_HOVER_ROLL_TRIM_DEFAULT 300
31
#define AC_ATTITUDE_HELI_ACRO_OVERSHOOT_ANGLE_RAD radians(30.0f)
32
#define AC_ATTITUDE_HELI_INVERTED_TRANSITION_TIME 3.0f
33
34
class AC_AttitudeControl_Heli : public AC_AttitudeControl {
35
public:
36
AC_AttitudeControl_Heli( AP_AHRS_View &ahrs,
37
AP_MotorsHeli& motors);
38
39
// pid accessors
40
AC_PID& get_rate_roll_pid() override { return _pid_rate_roll; }
41
AC_PID& get_rate_pitch_pid() override { return _pid_rate_pitch; }
42
AC_PID& get_rate_yaw_pid() override { return _pid_rate_yaw; }
43
const AC_PID& get_rate_roll_pid() const override { return _pid_rate_roll; }
44
const AC_PID& get_rate_pitch_pid() const override { return _pid_rate_pitch; }
45
const AC_PID& get_rate_yaw_pid() const override { return _pid_rate_yaw; }
46
47
// passthrough_bf_roll_pitch_rate_yaw_norm - roll and pitch are passed through directly, body-frame rate target for yaw
48
void passthrough_bf_roll_pitch_rate_yaw_norm(float roll_passthrough_norm, float pitch_passthrough_norm, float yaw_passthrough_norm) override;
49
50
// subclass non-passthrough too, for external gyro, no flybar
51
void input_rate_bf_roll_pitch_yaw_rads(float roll_rate_bf_rads, float pitch_rate_bf_rads, float yaw_rate_bf_rads) override;
52
53
// rate_controller_run - run lowest level body-frame rate controller and send outputs to the motors
54
// should be called at 100hz or more
55
virtual void rate_controller_run() override;
56
57
// Update Alt_Hold angle maximum
58
void update_althold_lean_angle_max(float throttle_in) override;
59
60
// use_leaky_i - controls whether we use leaky i term for body-frame to motor output stage
61
void use_leaky_i(bool leaky_i) override { _flags_heli.leaky_i = leaky_i; }
62
63
// use_flybar_passthrough - controls whether we pass-through
64
// control inputs to swash-plate and tail
65
void use_flybar_passthrough(bool passthrough, bool tail_passthrough) override {
66
_flags_heli.flybar_passthrough = passthrough;
67
_flags_heli.tail_passthrough = tail_passthrough;
68
}
69
70
// set_hover_roll_scalar - scales Hover Roll Trim parameter. To be used by vehicle code according to vehicle condition.
71
void set_hover_roll_trim_scalar(float scalar) override {_hover_roll_trim_scalar = constrain_float(scalar, 0.0f, 1.0f);}
72
73
// get_roll_trim - angle in centi-degrees to be added to roll angle for learn hover collective. Used by helicopter to counter tail rotor thrust in hover
74
float get_roll_trim_cd() override;
75
76
// Set output throttle
77
void set_throttle_out(float throttle_in, bool apply_angle_boost, float filt_cutoff) override;
78
79
// calculate total body frame throttle required to produce the given earth frame throttle
80
float get_throttle_boosted(float throttle_in);
81
82
// Sets desired roll and pitch angles (in radians) and yaw rate (in radians/s).
83
// Used when roll/pitch stabilization is needed with manual or autonomous yaw rate control.
84
// Applies acceleration-limited input shaping for smooth transitions and computes body-frame angular velocity targets.
85
void input_euler_angle_roll_pitch_euler_rate_yaw_rad(float euler_roll_angle_rad, float euler_pitch_angle_rad, float euler_yaw_rate_rads) override;
86
87
// Sets desired roll, pitch, and yaw angles (in radians).
88
// Used to follow an absolute attitude setpoint. Input shaping and yaw slew limits are applied.
89
// Outputs are passed to the rate controller via shaped angular velocity targets.
90
void input_euler_angle_roll_pitch_yaw_rad(float euler_roll_angle_rad, float euler_pitch_angle_rad, float euler_yaw_angle_rad, bool slew_yaw) override;
91
92
// Sets desired thrust vector and heading rate (in radians/s).
93
// Used for tilt-based navigation with independent yaw control.
94
// The thrust vector defines the desired orientation (e.g., pointing direction for vertical thrust),
95
// while the heading rate adjusts yaw. The input is shaped by acceleration and slew limits.
96
void input_thrust_vector_rate_heading_rads(const Vector3f& thrust_vector, float heading_rate_rads, bool slew_yaw = true) override;
97
98
// Sets desired thrust vector and heading (in radians) with heading rate (in radians/s).
99
// Used for advanced attitude control where thrust direction is separated from yaw orientation.
100
// Heading slew is constrained based on configured limits.
101
void input_thrust_vector_heading_rad(const Vector3f& thrust_vector, float heading_angle_rad, float heading_rate_rads) override;
102
103
// enable/disable inverted flight
104
void set_inverted_flight(bool inverted) override { _inverted_flight = inverted; }
105
106
// accessor for inverted flight flag
107
bool get_inverted_flight() override { return _inverted_flight; }
108
109
// set the PID notch sample rates
110
void set_notch_sample_rate(float sample_rate) override;
111
112
// user settable parameters
113
static const struct AP_Param::GroupInfo var_info[];
114
115
private:
116
117
// To-Do: move these limits flags into the heli motors class
118
struct AttControlHeliFlags {
119
uint8_t leaky_i : 1; // 1 if we should use leaky i term for body-frame rate to motor stage
120
uint8_t flybar_passthrough : 1; // 1 if we should pass through pilots roll & pitch input directly to swash-plate
121
uint8_t tail_passthrough : 1; // 1 if we should pass through pilots yaw input to tail
122
} _flags_heli;
123
124
// true in inverted flight mode
125
bool _inverted_flight;
126
127
// Integrate vehicle rate into _att_error_rot_vec_rad
128
void integrate_bf_rate_error_to_angle_errors();
129
130
//
131
// body-frame rate controller
132
//
133
// rate_bf_to_motor_roll_pitch - ask the rate controller to calculate the motor outputs to achieve the target body-frame rate (in radians/sec) for roll, pitch and yaw
134
// outputs are sent directly to motor class
135
void rate_bf_to_motor_roll_pitch(const Vector3f &rate_rads, float rate_roll_target_rads, float rate_pitch_target_rads);
136
float rate_target_to_motor_yaw(float rate_yaw_actual_rads, float rate_yaw_rads);
137
138
//
139
// throttle methods
140
//
141
142
// pass through for roll and pitch
143
float _passthrough_roll_norm;
144
float _passthrough_pitch_norm;
145
146
// pass through for yaw if tail_passthrough is set
147
float _passthrough_yaw_norm;
148
149
// internal variables
150
float _hover_roll_trim_scalar = 0; // scalar used to suppress Hover Roll Trim
151
152
153
// This represents an euler axis-angle rotation vector from the vehicles
154
// estimated attitude to the reference (setpoint) attitude used in the attitude
155
// controller, in radians in the vehicle body frame of reference.
156
Vector3f _att_error_rot_vec_rad;
157
158
// parameters
159
AP_Int8 _piro_comp_enabled; // Flybar present or not. Affects attitude controller used during ACRO flight mode
160
AP_Int16 _hover_roll_trim_cd; // Angle in centi-degrees used to counter tail rotor thrust in hover
161
162
// Roll and Pitch rate PIDs share the same defaults:
163
const AC_PID::Defaults rp_defaults {
164
AC_PID::Defaults{
165
.p = AC_ATC_HELI_RATE_RP_P,
166
.i = AC_ATC_HELI_RATE_RP_I,
167
.d = AC_ATC_HELI_RATE_RP_D,
168
.ff = AC_ATC_HELI_RATE_RP_FF,
169
.imax = AC_ATC_HELI_RATE_RP_IMAX,
170
.filt_T_hz = AC_ATTITUDE_HELI_RATE_RP_FF_FILTER,
171
.filt_E_hz = AC_ATC_HELI_RATE_RP_FILT_HZ,
172
.filt_D_hz = 0.0,
173
.srmax = 0,
174
.srtau = 1.0
175
}
176
};
177
AC_HELI_PID _pid_rate_roll { rp_defaults, AC_ATC_HELI_RATE_RP_ILMI };
178
AC_HELI_PID _pid_rate_pitch { rp_defaults, AC_ATC_HELI_RATE_RP_ILMI };
179
180
AC_HELI_PID _pid_rate_yaw {
181
AC_PID::Defaults{
182
.p = AC_ATC_HELI_RATE_YAW_P,
183
.i = AC_ATC_HELI_RATE_YAW_I,
184
.d = AC_ATC_HELI_RATE_YAW_D,
185
.ff = AC_ATC_HELI_RATE_YAW_FF,
186
.imax = AC_ATC_HELI_RATE_YAW_IMAX,
187
.filt_T_hz = AC_ATTITUDE_HELI_RATE_Y_FF_FILTER,
188
.filt_E_hz = AC_ATC_HELI_RATE_YAW_FILT_HZ,
189
.filt_D_hz = 0.0,
190
.srmax = 0,
191
.srtau = 1.0
192
}
193
, 0.0f // default_ilmi
194
};
195
196
};
197
198