31 #include "generated/airframe.h"
51 #ifndef V_CTL_AUTO_THROTTLE_DGAIN
52 #define V_CTL_AUTO_THROTTLE_DGAIN 0.
65 #define V_CTL_AUTO_THROTTLE_MAX_SUM_ERR 150
69 #ifndef V_CTL_AUTO_THROTTLE_PITCH_OF_VZ_DGAIN
70 #define V_CTL_AUTO_THROTTLE_PITCH_OF_VZ_DGAIN 0.
74 #ifdef TUNE_AGRESSIVE_CLIMB
75 float agr_climb_throttle;
76 float agr_climb_pitch;
77 float agr_climb_nav_ratio;
78 float agr_descent_throttle;
79 float agr_descent_pitch;
80 float agr_descent_nav_ratio;
87 #define V_CTL_AUTO_PITCH_MAX_SUM_ERR 100
92 #ifndef V_CTL_PITCH_TRIM
93 #define V_CTL_PITCH_TRIM 0.
98 #ifdef V_CTL_AUTO_PITCH_PGAIN
99 inline static void v_ctl_climb_auto_pitch_loop(
void);
105 float v_ctl_auto_airspeed_pgain;
106 float v_ctl_auto_airspeed_igain;
107 float v_ctl_auto_airspeed_sum_err;
112 #define V_CTL_AUTO_AIRSPEED_MAX_SUM_ERR 200
113 #define V_CTL_AUTO_GROUNDSPEED_MAX_SUM_ERR 100
114 #define V_CTL_AUTO_CLIMB_LIMIT 0.5/4.0 // m/s/s
115 #define V_CTL_AUTO_AGR_CLIMB_GAIN 2.0 // altitude gain multiplier while in aggressive climb mode
118 #ifndef V_CTL_ALTITUDE_PRE_CLIMB_CORRECTION
119 #define V_CTL_ALTITUDE_PRE_CLIMB_CORRECTION 1.0f
122 #if CTRL_VERTICAL_LANDING
123 #ifndef V_CTL_LANDING_THROTTLE_PGAIN
124 #error "V_CTL_LANDING_THROTTLE_PGAIN undefined, please define it in your airfame config file"
126 #ifndef V_CTL_LANDING_THROTTLE_IGAIN
127 #error "V_CTL_LANDING_THROTTLE_IGAIN undefined, please define it in your airfame config file"
129 #ifndef V_CTL_LANDING_THROTTLE_MAX
130 INFO(
"V_CTL_LANDING_THROTTLE_MAX undefined, using V_CTL_AUTO_THROTTLE_MAX_CRUISE_THROTTLE instead")
131 #define V_CTL_LANDING_THROTTLE_MAX V_CTL_AUTO_THROTTLE_MAX_CRUISE_THROTTLE
133 #ifndef V_CTL_LANDING_DESIRED_SPEED
134 #error "V_CTL_LANDING_DESIRED_SPEED undefined, please define it in your airfame config file"
138 #ifndef V_CTL_LANDING_PITCH_PGAIN
139 INFO(
"V_CTL_LANDING_PITCH_PGAIN undefined, using V_CTL_AUTO_PITCH_PGAIN instead")
140 #define V_CTL_LANDING_PITCH_PGAIN V_CTL_AUTO_PITCH_PGAIN
142 #ifndef V_CTL_LANDING_PITCH_IGAIN
143 INFO(
"V_CTL_LANDING_PITCH_IGAIN undefined, using V_CTL_AUTO_PITCH_IGAIN instead")
144 #define V_CTL_LANDING_PITCH_IGAIN V_CTL_AUTO_PITCH_IGAIN
146 #ifndef V_CTL_LANDING_PITCH_LIMITS
147 INFO(
"V_CTL_LANDING_PITCH_LIMITS undefined, using V_CTL_AUTO_PITCH_MAX_PITCH instead")
148 #define V_CTL_LANDING_PITCH_LIMITS V_CTL_AUTO_PITCH_MAX_PITCH
150 #ifndef V_CTL_LANDING_PITCH_FLARE
151 #error "V_CTL_LANDING_PITCH_FLARE undefined, please define it in your airfame config file"
153 #ifndef V_CTL_LANDING_ALT_THROTTLE_KILL
154 #error "V_CTL_LANDING_ALT_THROTTLE_KILL undefined, please define it in your airfame config file"
156 #ifndef V_CTL_LANDING_ALT_FLARE
157 #error "V_CTL_LANDING_ALT_FLARE undefined, please define it in your airfame config file"
160 float v_ctl_landing_throttle_pgain;
161 float v_ctl_landing_throttle_igain;
162 float v_ctl_landing_throttle_max;
163 float v_ctl_landing_desired_speed;
164 float v_ctl_landing_pitch_pgain;
165 float v_ctl_landing_pitch_igain;
166 float v_ctl_landing_pitch_limits;
167 float v_ctl_landing_pitch_flare;
168 float v_ctl_landing_alt_throttle_kill;
169 float v_ctl_landing_alt_flare;
177 #if CTRL_VERTICAL_LANDING
179 v_ctl_landing_throttle_pgain = V_CTL_LANDING_THROTTLE_PGAIN;
180 v_ctl_landing_throttle_igain = V_CTL_LANDING_THROTTLE_IGAIN;
181 v_ctl_landing_throttle_max = V_CTL_LANDING_THROTTLE_MAX;
182 v_ctl_landing_desired_speed = V_CTL_LANDING_DESIRED_SPEED;
183 v_ctl_landing_pitch_pgain = V_CTL_LANDING_PITCH_PGAIN;
184 v_ctl_landing_pitch_igain = V_CTL_LANDING_PITCH_IGAIN;
185 v_ctl_landing_pitch_limits = V_CTL_LANDING_PITCH_LIMITS;
186 v_ctl_landing_pitch_flare = V_CTL_LANDING_PITCH_FLARE;
187 v_ctl_landing_alt_throttle_kill = V_CTL_LANDING_ALT_THROTTLE_KILL;
188 v_ctl_landing_alt_flare = V_CTL_LANDING_ALT_FLARE;
220 #ifdef V_CTL_AUTO_PITCH_PGAIN
230 v_ctl_auto_airspeed_pgain = V_CTL_AUTO_AIRSPEED_PGAIN;
231 v_ctl_auto_airspeed_igain = V_CTL_AUTO_AIRSPEED_IGAIN;
232 v_ctl_auto_airspeed_sum_err = 0.;
243 #ifdef TUNE_AGRESSIVE_CLIMB
244 agr_climb_throttle = AGR_CLIMB_THROTTLE;
245 #undef AGR_CLIMB_THROTTLE
246 #define AGR_CLIMB_THROTTLE agr_climb_throttle
247 agr_climb_pitch = AGR_CLIMB_PITCH;
248 #undef AGR_CLIMB_PITCH
249 #define AGR_CLIMB_PITCH agr_climb_pitch
250 agr_climb_nav_ratio = AGR_CLIMB_NAV_RATIO;
251 #undef AGR_CLIMB_NAV_RATIO
252 #define AGR_CLIMB_NAV_RATIO agr_climb_nav_ratio
253 agr_descent_throttle = AGR_DESCENT_THROTTLE;
254 #undef AGR_DESCENT_THROTTLE
255 #define AGR_DESCENT_THROTTLE agr_descent_throttle
256 agr_descent_pitch = AGR_DESCENT_PITCH;
257 #undef AGR_DESCENT_PITCH
258 #define AGR_DESCENT_PITCH agr_descent_pitch
259 agr_descent_nav_ratio = AGR_DESCENT_NAV_RATIO;
260 #undef AGR_DESCENT_NAV_RATIO
261 #define AGR_DESCENT_NAV_RATIO agr_descent_nav_ratio
271 float altitude_pgain_boost = 1.0;
273 #if USE_AIRSPEED && defined(AGR_CLIMB)
277 altitude_pgain_boost = 1.0 + (V_CTL_AUTO_AGR_CLIMB_GAIN - 1.0) * (dist - AGR_BLEND_END) /
278 (AGR_BLEND_START - AGR_BLEND_END);
279 Bound(altitude_pgain_boost, 1.0, V_CTL_AUTO_AGR_CLIMB_GAIN);
291 if (dist < AGR_BLEND_END) {
293 }
else if (dist > AGR_BLEND_START) {
309 #ifdef V_CTL_AUTO_PITCH_PGAIN
310 #pragma message "AUTO PITCH Enabled!"
312 v_ctl_climb_auto_pitch_loop();
320 #if CTRL_VERTICAL_LANDING
321 static float land_speed_i_err;
322 static float land_alt_i_err;
323 static float kill_alt;
329 > (v_ctl_landing_alt_throttle_kill - v_ctl_landing_alt_flare)) {
337 + land_alt_i_err * v_ctl_landing_throttle_igain;
341 BoundAbs(land_alt_i_err, 50);
344 nav_pitch -= land_speed_err * v_ctl_landing_pitch_pgain / 1000
345 + land_speed_i_err * v_ctl_landing_pitch_igain / 1000;
346 Bound(
nav_pitch, -v_ctl_landing_pitch_limits, v_ctl_landing_pitch_limits);
349 BoundAbs(land_speed_i_err, .2);
355 if (land_alt_err > 0.0) {
372 static float last_err;
374 float f_throttle = 0;
376 float d_err = err - last_err;
388 #if defined AGR_CLIMB
392 f_throttle = AGR_CLIMB_THROTTLE;
395 f_throttle = AGR_DESCENT_THROTTLE;
402 / (AGR_BLEND_START - AGR_BLEND_END);
403 f_throttle = (1 - ratio) * controlled_throttle;
409 f_throttle += ratio * AGR_CLIMB_THROTTLE;
412 f_throttle += ratio * AGR_DESCENT_THROTTLE;
425 #if defined AGR_CLIMB
433 #else // USE_AIRSPEED
437 float f_throttle = 0;
439 float v_ctl_pitch_of_vz;
442 static float v_ctl_climb_setpoint_last = 0;
471 v_ctl_auto_airspeed_sum_err += err_airspeed;
472 BoundAbs(v_ctl_auto_airspeed_sum_err, V_CTL_AUTO_AIRSPEED_MAX_SUM_ERR);
473 controlled_throttle = (err_airspeed + v_ctl_auto_airspeed_sum_err * v_ctl_auto_airspeed_igain) *
474 v_ctl_auto_airspeed_pgain;
484 #endif // USE_AIRSPEED
491 #ifdef V_CTL_AUTO_PITCH_PGAIN
492 inline static void v_ctl_climb_auto_pitch_loop(
void)
504 #ifdef V_CTL_THROTTLE_SLEW_LIMITER
505 #define V_CTL_THROTTLE_SLEW (1./CONTROL_FREQUENCY/(V_CTL_THROTTLE_SLEW_LIMITER))
508 #ifndef V_CTL_THROTTLE_SLEW
509 #define V_CTL_THROTTLE_SLEW 1.
518 v_ctl_throttle_slewed += diff_throttle;
#define V_CTL_AUTO_THROTTLE_DGAIN
#define V_CTL_AUTO_PITCH_MAX_SUM_ERR
static float stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
float v_ctl_auto_throttle_pgain
pprz_t v_ctl_throttle_slewed
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
float v_ctl_altitude_max_climb
float v_ctl_auto_groundspeed_setpoint
in meters per second
float v_ctl_auto_groundspeed_igain
float v_ctl_auto_throttle_sum_err
float v_ctl_auto_throttle_igain
#define V_CTL_ALTITUDE_MAX_CLIMB
float controlled_throttle
static float stateGetAirspeed_f(void)
Get airspeed (float).
void v_ctl_altitude_loop(void)
outer loop
float v_ctl_altitude_pre_climb
Path Angle.
float v_ctl_auto_throttle_climb_throttle_increment
float v_ctl_auto_throttle_pitch_of_vz_dgain
float v_ctl_auto_throttle_nominal_cruise_throttle
float v_ctl_auto_throttle_max_cruise_throttle
float v_ctl_auto_airspeed_setpoint
in meters per second
uint8_t v_ctl_auto_throttle_submode
Fixed wing horizontal control.
static void v_ctl_climb_auto_throttle_loop(void)
auto throttle inner loop
#define V_CTL_AUTO_GROUNDSPEED_MAX_SUM_ERR
#define V_CTL_AUTO_THROTTLE_STANDARD
float v_ctl_auto_groundspeed_sum_err
float v_ctl_auto_pitch_pgain
#define V_CTL_CLIMB_MODE_AUTO_THROTTLE
Vertical control for fixed wing vehicles.
void v_ctl_throttle_slew(void)
Computes slewed throttle from throttle setpoint called at 20Hz.
float v_ctl_altitude_error
in meters, (setpoint - alt) -> positive = too low
#define V_CTL_AUTO_THROTTLE_PITCH_OF_VZ_DGAIN
void v_ctl_landing_loop(void)
#define V_CTL_AUTO_PITCH_IGAIN
float v_ctl_auto_pitch_sum_err
float v_ctl_auto_throttle_min_cruise_throttle
float v_ctl_auto_pitch_igain
float v_ctl_pitch_setpoint
pprz_t v_ctl_throttle_setpoint
#define V_CTL_AUTO_CLIMB_LIMIT
float v_ctl_altitude_pgain
float v_ctl_altitude_setpoint
in meters above MSL
float v_ctl_auto_throttle_cruise_throttle
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
API to get/set the generic vehicle states.
float h_ctl_roll_setpoint
float nav_pitch
with INT32_ANGLE_FRAC
static struct EnuCoor_f * stateGetSpeedEnu_f(void)
Get ground speed in local ENU coordinates (float).
#define V_CTL_AUTO_THROTTLE_MAX_SUM_ERR
void v_ctl_climb_loop(void)
Auto-throttle inner loop.
float v_ctl_climb_setpoint
#define V_CTL_AUTO_THROTTLE_BLENDED
#define LATERAL_MODE_ROLL
#define V_CTL_AUTO_THROTTLE_AGRESSIVE
float v_ctl_auto_throttle_pitch_of_vz_pgain
#define CONTROL_FREQUENCY
#define V_CTL_ALTITUDE_PRE_CLIMB_CORRECTION
#define V_CTL_CLIMB_MODE_AUTO_PITCH
#define V_CTL_MODE_MANUAL
Fixedwing Navigation library.
float v_ctl_auto_groundspeed_pgain
#define V_CTL_THROTTLE_SLEW
auto pitch inner loop
pprz_t nav_throttle_setpoint
float v_ctl_auto_airspeed_controlled
float v_ctl_auto_throttle_dgain
float v_ctl_altitude_pre_climb_correction
Fixedwing autopilot modes.