31 #include "generated/airframe.h"
50 #ifndef V_CTL_AUTO_THROTTLE_DGAIN
51 #define V_CTL_AUTO_THROTTLE_DGAIN 0.
64 #define V_CTL_AUTO_THROTTLE_MAX_SUM_ERR 150
68 #ifndef V_CTL_AUTO_THROTTLE_PITCH_OF_VZ_DGAIN
69 #define V_CTL_AUTO_THROTTLE_PITCH_OF_VZ_DGAIN 0.
73 #ifdef TUNE_AGRESSIVE_CLIMB
74 float agr_climb_throttle;
75 float agr_climb_pitch;
76 float agr_climb_nav_ratio;
77 float agr_descent_throttle;
78 float agr_descent_pitch;
79 float agr_descent_nav_ratio;
86 #define V_CTL_AUTO_PITCH_MAX_SUM_ERR 100
91 #ifndef V_CTL_PITCH_TRIM
92 #define V_CTL_PITCH_TRIM 0.
97 #ifdef V_CTL_AUTO_PITCH_PGAIN
98 inline static void v_ctl_climb_auto_pitch_loop(
void);
104 float v_ctl_auto_airspeed_pgain;
105 float v_ctl_auto_airspeed_igain;
106 float v_ctl_auto_airspeed_sum_err;
111 #define V_CTL_AUTO_AIRSPEED_MAX_SUM_ERR 200
112 #define V_CTL_AUTO_GROUNDSPEED_MAX_SUM_ERR 100
113 #define V_CTL_AUTO_CLIMB_LIMIT 0.5/4.0 // m/s/s
114 #define V_CTL_AUTO_AGR_CLIMB_GAIN 2.0 // altitude gain multiplier while in aggressive climb mode
117 #ifndef V_CTL_ALTITUDE_PRE_CLIMB_CORRECTION
118 #define V_CTL_ALTITUDE_PRE_CLIMB_CORRECTION 1.0f
156 #ifdef V_CTL_AUTO_PITCH_PGAIN
166 v_ctl_auto_airspeed_pgain = V_CTL_AUTO_AIRSPEED_PGAIN;
167 v_ctl_auto_airspeed_igain = V_CTL_AUTO_AIRSPEED_IGAIN;
168 v_ctl_auto_airspeed_sum_err = 0.;
179 #ifdef TUNE_AGRESSIVE_CLIMB
180 agr_climb_throttle = AGR_CLIMB_THROTTLE;
181 #undef AGR_CLIMB_THROTTLE
182 #define AGR_CLIMB_THROTTLE agr_climb_throttle
183 agr_climb_pitch = AGR_CLIMB_PITCH;
184 #undef AGR_CLIMB_PITCH
185 #define AGR_CLIMB_PITCH agr_climb_pitch
186 agr_climb_nav_ratio = AGR_CLIMB_NAV_RATIO;
187 #undef AGR_CLIMB_NAV_RATIO
188 #define AGR_CLIMB_NAV_RATIO agr_climb_nav_ratio
189 agr_descent_throttle = AGR_DESCENT_THROTTLE;
190 #undef AGR_DESCENT_THROTTLE
191 #define AGR_DESCENT_THROTTLE agr_descent_throttle
192 agr_descent_pitch = AGR_DESCENT_PITCH;
193 #undef AGR_DESCENT_PITCH
194 #define AGR_DESCENT_PITCH agr_descent_pitch
195 agr_descent_nav_ratio = AGR_DESCENT_NAV_RATIO;
196 #undef AGR_DESCENT_NAV_RATIO
197 #define AGR_DESCENT_NAV_RATIO agr_descent_nav_ratio
207 float altitude_pgain_boost = 1.0;
209 #if USE_AIRSPEED && defined(AGR_CLIMB)
213 altitude_pgain_boost = 1.0 + (V_CTL_AUTO_AGR_CLIMB_GAIN - 1.0) * (dist - AGR_BLEND_END) /
214 (AGR_BLEND_START - AGR_BLEND_END);
215 Bound(altitude_pgain_boost, 1.0, V_CTL_AUTO_AGR_CLIMB_GAIN);
227 if (dist < AGR_BLEND_END) {
229 }
else if (dist > AGR_BLEND_START) {
245 #ifdef V_CTL_AUTO_PITCH_PGAIN
246 #pragma message "AUTO PITCH Enabled!"
248 v_ctl_climb_auto_pitch_loop();
263 static float last_err;
265 float f_throttle = 0;
267 float d_err = err - last_err;
279 #if defined AGR_CLIMB
283 f_throttle = AGR_CLIMB_THROTTLE;
286 f_throttle = AGR_DESCENT_THROTTLE;
293 / (AGR_BLEND_START - AGR_BLEND_END);
294 f_throttle = (1 - ratio) * controlled_throttle;
300 f_throttle += ratio * AGR_CLIMB_THROTTLE;
303 f_throttle += ratio * AGR_DESCENT_THROTTLE;
316 #if defined AGR_CLIMB
324 #else // USE_AIRSPEED
328 float f_throttle = 0;
330 float v_ctl_pitch_of_vz;
333 static float v_ctl_climb_setpoint_last = 0;
362 v_ctl_auto_airspeed_sum_err += err_airspeed;
363 BoundAbs(v_ctl_auto_airspeed_sum_err, V_CTL_AUTO_AIRSPEED_MAX_SUM_ERR);
364 controlled_throttle = (err_airspeed + v_ctl_auto_airspeed_sum_err * v_ctl_auto_airspeed_igain) *
365 v_ctl_auto_airspeed_pgain;
375 #endif // USE_AIRSPEED
382 #ifdef V_CTL_AUTO_PITCH_PGAIN
383 inline static void v_ctl_climb_auto_pitch_loop(
void)
395 #ifdef V_CTL_THROTTLE_SLEW_LIMITER
396 #define V_CTL_THROTTLE_SLEW (1./CONTROL_FREQUENCY/(V_CTL_THROTTLE_SLEW_LIMITER))
399 #ifndef V_CTL_THROTTLE_SLEW
400 #define V_CTL_THROTTLE_SLEW 1.
409 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
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
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
#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 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 V_CTL_AUTO_THROTTLE_AGRESSIVE
float v_ctl_auto_throttle_pitch_of_vz_pgain
#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.