Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
energy_ctrl.c File Reference

Total Energy (speed + height) control for fixed wing vehicles. More...

#include "firmwares/fixedwing/guidance/energy_ctrl.h"
#include "state.h"
#include "firmwares/fixedwing/nav.h"
#include "generated/airframe.h"
#include "autopilot.h"
#include "modules/core/abi.h"
Include dependency graph for energy_ctrl.c:

Go to the source code of this file.

Macros

#define V_CTL_AUTO_GROUNDSPEED_MAX_SUM_ERR   100
#define V_CTL_ALTITUDE_MAX_CLIMB   2;
#define STALL_AIRSPEED   NOMINAL_AIRSPEED
#define V_CTL_GLIDE_RATIO   8.
#define AIRSPEED_SETPOINT_SLEW   1
#define V_CTL_MAX_ACCELERATION   0.5
#define V_CTL_ENERGY_IMU_ID   ABI_BROADCAST
#define V_CTL_THROTTLE_SLEW   1.

Functions

static void ac_char_average (float *last_v, float new_v, int count)
static void ac_char_update (float throttle, float pitch, float climb, float accelerate)
static void accel_cb (uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
void v_ctl_init (void)
void v_ctl_altitude_loop (void)
 outer loop
static float low_pass_vdot (float v)
void v_ctl_climb_loop (void)
 Auto-throttle inner loop.
void v_ctl_throttle_slew (void)
 Computes slewed throttle from throttle setpoint called at 20Hz.

Variables

uint8_t v_ctl_mode = V_CTL_MODE_MANUAL
uint8_t v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_THROTTLE
uint8_t v_ctl_auto_throttle_submode = V_CTL_CLIMB_MODE_AUTO_THROTTLE
float v_ctl_auto_throttle_sum_err = 0
float v_ctl_altitude_setpoint
 in meters above MSL
float v_ctl_altitude_pre_climb
 Path Angle.
float v_ctl_altitude_pgain
float v_ctl_airspeed_pgain
float v_ctl_altitude_error
 in meters, (setpoint - alt) -> positive = too low
float v_ctl_max_climb
float v_ctl_max_acceleration
float v_ctl_climb_setpoint
float v_ctl_desired_acceleration
float v_ctl_auto_throttle_cruise_throttle
float v_ctl_auto_throttle_nominal_cruise_throttle
float v_ctl_auto_throttle_nominal_cruise_pitch
float v_ctl_auto_throttle_climb_throttle_increment
float v_ctl_auto_throttle_pitch_of_vz_pgain
float v_ctl_auto_throttle_of_airspeed_pgain
float v_ctl_auto_throttle_of_airspeed_igain
float v_ctl_auto_pitch_of_airspeed_pgain
float v_ctl_auto_pitch_of_airspeed_igain
float v_ctl_auto_pitch_of_airspeed_dgain
float v_ctl_energy_total_pgain
float v_ctl_energy_total_igain
float v_ctl_energy_diff_pgain
float v_ctl_energy_diff_igain
float v_ctl_auto_airspeed_setpoint
 in meters per second
float v_ctl_auto_airspeed_setpoint_slew
float v_ctl_auto_airspeed_controlled
float v_ctl_auto_groundspeed_setpoint
 in meters per second
float v_ctl_auto_groundspeed_pgain
float v_ctl_auto_groundspeed_igain
float v_ctl_auto_groundspeed_sum_err
pprz_t v_ctl_throttle_setpoint
pprz_t v_ctl_throttle_slewed
float v_ctl_pitch_setpoint
uint8_t v_ctl_speed_mode
static struct Int32Vect3 accel_imu_meas
static abi_event accel_ev
float ac_char_climb_pitch = 0.0f
float ac_char_climb_max = 0.0f
int ac_char_climb_count = 0
float ac_char_descend_pitch = 0.0f
float ac_char_descend_max = 0.0f
int ac_char_descend_count = 0
float ac_char_cruise_throttle = 0.0f
float ac_char_cruise_pitch = 0.0f
int ac_char_cruise_count = 0
static const float dt_attidude = 1.0 / ((float)CONTROL_FREQUENCY)
static const float dt_navigation = 1.0 / ((float)NAVIGATION_FREQUENCY)
float lp_vdot [5]

Detailed Description

Total Energy (speed + height) control for fixed wing vehicles.

Energy:

\begin{eqnarray*}E &=& mgh + \frac{1}{2}mV^2 \\
\frac{\dot{E}}{V} &=& \left(\gamma + \frac{\dot{V}}{g}\right) W
\end{eqnarray*}

Equilibrium:

\‍[\frac{\dot{V}}{g} = \frac{\mbox{Thrust}}{W} - \frac{\mbox{Drag}}{W} - \sin(\gamma)
\‍]

with:

\‍[\frac{\mbox{Drag}}{\mbox{Weight}} = \left(\frac{C_l}{C_d}\right)^{-1}
\‍]

  • glide angle: $\dot{V}=0, T=0 \rightarrow \gamma = \frac{C_d}{C_l}$
  • level flight: $\dot{V}=0, \gamma=0 \rightarrow \frac{W}{T} = \frac{C_l}{C_d}$

Strategy:

  • thrust = path + acceleration[g] (total energy)
  • pitch = path - acceleration[g] (energy balance)

Pseudo-Control Unit = dimensionless acceleration [g]

- pitch <-> pseudocontrol:    sin(Theta) steers Vdot in [g]
- throttle <-> pseudocontrol: motor characteristic as function of V x throttle steeds VDot
dot_inline_dotgraph_1.png

Definition in file energy_ctrl.c.

Macro Definition Documentation

◆ AIRSPEED_SETPOINT_SLEW

#define AIRSPEED_SETPOINT_SLEW   1

Definition at line 155 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop().

◆ STALL_AIRSPEED

#define STALL_AIRSPEED   NOMINAL_AIRSPEED

Definition at line 148 of file energy_ctrl.c.

Referenced by draw_osd(), and v_ctl_altitude_loop().

◆ V_CTL_ALTITUDE_MAX_CLIMB

#define V_CTL_ALTITUDE_MAX_CLIMB   2;

Definition at line 143 of file energy_ctrl.c.

Referenced by potential_task(), v_ctl_altitude_loop(), and v_ctl_init().

◆ V_CTL_AUTO_GROUNDSPEED_MAX_SUM_ERR

#define V_CTL_AUTO_GROUNDSPEED_MAX_SUM_ERR   100

Definition at line 129 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop().

◆ V_CTL_ENERGY_IMU_ID

#define V_CTL_ENERGY_IMU_ID   ABI_BROADCAST

Definition at line 162 of file energy_ctrl.c.

Referenced by v_ctl_init().

◆ V_CTL_GLIDE_RATIO

#define V_CTL_GLIDE_RATIO   8.

Definition at line 151 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop().

◆ V_CTL_MAX_ACCELERATION

#define V_CTL_MAX_ACCELERATION   0.5

Definition at line 158 of file energy_ctrl.c.

Referenced by v_ctl_init().

◆ V_CTL_THROTTLE_SLEW

#define V_CTL_THROTTLE_SLEW   1.

Definition at line 432 of file energy_ctrl.c.

Referenced by ArduIMU_init(), and v_ctl_throttle_slew().

Function Documentation

◆ ac_char_average()

void ac_char_average ( float * last_v,
float new_v,
int count )
static

Definition at line 177 of file energy_ctrl.c.

Referenced by ac_char_update().

Here is the caller graph for this function:

◆ ac_char_update()

void ac_char_update ( float throttle,
float pitch,
float climb,
float accelerate )
static

◆ accel_cb()

◆ low_pass_vdot()

float low_pass_vdot ( float v)
static

Definition at line 309 of file energy_ctrl.c.

References lp_vdot.

Referenced by v_ctl_climb_loop().

Here is the caller graph for this function:

◆ v_ctl_altitude_loop()

void v_ctl_altitude_loop ( void )

outer loop

Computes v_ctl_climb_setpoint and sets v_ctl_auto_throttle_submode

Definition at line 286 of file energy_ctrl.c.

References UtmCoor_f::alt, dt_navigation, STALL_AIRSPEED, stateGetPositionUtm_f(), v_ctl_altitude_error, v_ctl_altitude_pgain, v_ctl_altitude_pre_climb, v_ctl_altitude_setpoint, v_ctl_auto_airspeed_setpoint, v_ctl_climb_setpoint, and v_ctl_max_climb.

Referenced by navigation_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ v_ctl_climb_loop()

◆ v_ctl_init()

◆ v_ctl_throttle_slew()

void v_ctl_throttle_slew ( void )

Computes slewed throttle from throttle setpoint called at 20Hz.

Computes throttle_slewed from throttle_setpoint.

Definition at line 437 of file energy_ctrl.c.

References MAX_PPRZ, TRIM_PPRZ, v_ctl_throttle_setpoint, V_CTL_THROTTLE_SLEW, and v_ctl_throttle_slewed.

Referenced by attitude_loop().

Here is the caller graph for this function:

Variable Documentation

◆ ac_char_climb_count

int ac_char_climb_count = 0

Definition at line 169 of file energy_ctrl.c.

Referenced by ac_char_update().

◆ ac_char_climb_max

float ac_char_climb_max = 0.0f

Definition at line 168 of file energy_ctrl.c.

Referenced by ac_char_update().

◆ ac_char_climb_pitch

float ac_char_climb_pitch = 0.0f

Definition at line 167 of file energy_ctrl.c.

Referenced by ac_char_update().

◆ ac_char_cruise_count

int ac_char_cruise_count = 0

Definition at line 175 of file energy_ctrl.c.

Referenced by ac_char_update().

◆ ac_char_cruise_pitch

float ac_char_cruise_pitch = 0.0f

Definition at line 174 of file energy_ctrl.c.

Referenced by ac_char_update().

◆ ac_char_cruise_throttle

float ac_char_cruise_throttle = 0.0f

Definition at line 173 of file energy_ctrl.c.

Referenced by ac_char_update().

◆ ac_char_descend_count

int ac_char_descend_count = 0

Definition at line 172 of file energy_ctrl.c.

Referenced by ac_char_update().

◆ ac_char_descend_max

float ac_char_descend_max = 0.0f

Definition at line 171 of file energy_ctrl.c.

Referenced by ac_char_update().

◆ ac_char_descend_pitch

float ac_char_descend_pitch = 0.0f

Definition at line 170 of file energy_ctrl.c.

Referenced by ac_char_update().

◆ accel_ev

◆ accel_imu_meas

struct Int32Vect3 accel_imu_meas
static

Definition at line 137 of file energy_ctrl.c.

Referenced by accel_cb(), and v_ctl_climb_loop().

◆ dt_attidude

const float dt_attidude = 1.0 / ((float)CONTROL_FREQUENCY)
static

Definition at line 278 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop().

◆ dt_navigation

const float dt_navigation = 1.0 / ((float)NAVIGATION_FREQUENCY)
static

Definition at line 279 of file energy_ctrl.c.

Referenced by mission_run(), mission_run(), and v_ctl_altitude_loop().

◆ lp_vdot

float lp_vdot[5]

Definition at line 306 of file energy_ctrl.c.

Referenced by low_pass_vdot().

◆ v_ctl_airspeed_pgain

float v_ctl_airspeed_pgain

Definition at line 91 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_altitude_error

float v_ctl_altitude_error

in meters, (setpoint - alt) -> positive = too low

Definition at line 92 of file energy_ctrl.c.

Referenced by h_ctl_course_loop(), v_ctl_altitude_loop(), v_ctl_climb_auto_throttle_loop(), and v_ctl_init().

◆ v_ctl_altitude_pgain

float v_ctl_altitude_pgain

Definition at line 90 of file energy_ctrl.c.

Referenced by v_ctl_altitude_loop(), and v_ctl_init().

◆ v_ctl_altitude_pre_climb

float v_ctl_altitude_pre_climb

Path Angle.

Definition at line 89 of file energy_ctrl.c.

Referenced by v_ctl_altitude_loop(), and v_ctl_init().

◆ v_ctl_altitude_setpoint

float v_ctl_altitude_setpoint

◆ v_ctl_auto_airspeed_controlled

float v_ctl_auto_airspeed_controlled

Definition at line 123 of file energy_ctrl.c.

Referenced by send_airspeed(), v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_airspeed_setpoint

float v_ctl_auto_airspeed_setpoint

◆ v_ctl_auto_airspeed_setpoint_slew

float v_ctl_auto_airspeed_setpoint_slew

Definition at line 122 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_groundspeed_igain

float v_ctl_auto_groundspeed_igain

Definition at line 127 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_groundspeed_pgain

float v_ctl_auto_groundspeed_pgain

Definition at line 126 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_groundspeed_setpoint

float v_ctl_auto_groundspeed_setpoint

in meters per second

Definition at line 125 of file energy_ctrl.c.

Referenced by send_airspeed(), v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_groundspeed_sum_err

float v_ctl_auto_groundspeed_sum_err

Definition at line 128 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_pitch_of_airspeed_dgain

float v_ctl_auto_pitch_of_airspeed_dgain

Definition at line 113 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_pitch_of_airspeed_igain

float v_ctl_auto_pitch_of_airspeed_igain

Definition at line 112 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_pitch_of_airspeed_pgain

float v_ctl_auto_pitch_of_airspeed_pgain

Definition at line 111 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_throttle_climb_throttle_increment

float v_ctl_auto_throttle_climb_throttle_increment

◆ v_ctl_auto_throttle_cruise_throttle

◆ v_ctl_auto_throttle_nominal_cruise_pitch

float v_ctl_auto_throttle_nominal_cruise_pitch

Definition at line 105 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_throttle_nominal_cruise_throttle

float v_ctl_auto_throttle_nominal_cruise_throttle

Definition at line 104 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_throttle_of_airspeed_igain

float v_ctl_auto_throttle_of_airspeed_igain

Definition at line 110 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_throttle_of_airspeed_pgain

float v_ctl_auto_throttle_of_airspeed_pgain

Definition at line 109 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_auto_throttle_pitch_of_vz_pgain

float v_ctl_auto_throttle_pitch_of_vz_pgain

◆ v_ctl_auto_throttle_submode

◆ v_ctl_auto_throttle_sum_err

float v_ctl_auto_throttle_sum_err = 0

◆ v_ctl_climb_mode

Definition at line 75 of file energy_ctrl.c.

Referenced by v_ctl_altitude_loop(), v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_climb_setpoint

◆ v_ctl_desired_acceleration

float v_ctl_desired_acceleration

Definition at line 101 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop().

◆ v_ctl_energy_diff_igain

float v_ctl_energy_diff_igain

Definition at line 119 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_energy_diff_pgain

float v_ctl_energy_diff_pgain

Definition at line 118 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_energy_total_igain

float v_ctl_energy_total_igain

Definition at line 116 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_energy_total_pgain

float v_ctl_energy_total_pgain

Definition at line 115 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_max_acceleration

float v_ctl_max_acceleration

Definition at line 95 of file energy_ctrl.c.

Referenced by v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_max_climb

float v_ctl_max_climb

Definition at line 94 of file energy_ctrl.c.

Referenced by v_ctl_altitude_loop(), and v_ctl_init().

◆ v_ctl_mode

◆ v_ctl_pitch_setpoint

◆ v_ctl_speed_mode

uint8_t v_ctl_speed_mode

Definition at line 135 of file energy_ctrl.c.

Referenced by gvf_low_level_control_3D(), v_ctl_climb_loop(), and v_ctl_init().

◆ v_ctl_throttle_setpoint

◆ v_ctl_throttle_slewed

pprz_t v_ctl_throttle_slewed

Definition at line 132 of file energy_ctrl.c.

Referenced by attitude_loop(), and v_ctl_throttle_slew().