Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
autopilot.c File Reference

Autopilot. More...

+ Include dependency graph for autopilot.c:

Go to the source code of this file.

Macros

#define AUTOPILOT_IN_FLIGHT_TIME   20
 time steps for in_flight detection (at 20Hz, so 20=1second) More...
 
#define AUTOPILOT_IN_FLIGHT_MIN_SPEED   0.2
 minimum vertical speed for in_flight condition in m/s More...
 
#define AUTOPILOT_IN_FLIGHT_MIN_ACCEL   2.0
 minimum vertical acceleration for in_flight condition in m/s^2 More...
 
#define AUTOPILOT_IN_FLIGHT_MIN_THRUST   500
 minimum thrust for in_flight condition in pprz_t units (max = 9600) More...
 
#define FAILSAFE_DESCENT_SPEED   1.5
 Set descent speed in failsafe mode. More...
 
#define FAILSAFE_MODE_TOO_FAR_FROM_HOME   AP_MODE_FAILSAFE
 Mode that is set when the plane is really too far from home. More...
 
#define MODE_STARTUP   AP_MODE_KILL
 
#define UNLOCKED_HOME_MODE   TRUE
 
#define NAV_PRESCALER   (PERIODIC_FREQUENCY / NAV_FREQ)
 
#define THRESHOLD_1_PPRZ   (MIN_PPRZ / 2)
 
#define THRESHOLD_2_PPRZ   (MAX_PPRZ / 2)
 

Functions

static int ahrs_is_aligned (void)
 
void send_autopilot_version (struct transport_tx *trans, struct link_device *dev)
 
static void send_alive (struct transport_tx *trans, struct link_device *dev)
 
static void send_attitude (struct transport_tx *trans, struct link_device *dev)
 
static void send_status (struct transport_tx *trans, struct link_device *dev)
 
static void send_energy (struct transport_tx *trans, struct link_device *dev)
 
static void send_fp (struct transport_tx *trans, struct link_device *dev)
 
static void send_rc (struct transport_tx *trans, struct link_device *dev)
 
static void send_rotorcraft_rc (struct transport_tx *trans, struct link_device *dev)
 
static void send_dl_value (struct transport_tx *trans, struct link_device *dev)
 
static void send_rotorcraft_cmd (struct transport_tx *trans, struct link_device *dev)
 
void autopilot_init (void)
 Autopilot inititalization. More...
 
void autopilot_periodic (void)
 
void autopilot_SetModeHandler (float mode)
 AP mode setting handler. More...
 
void autopilot_set_mode (uint8_t new_autopilot_mode)
 
bool autopilot_guided_goto_ned (float x, float y, float z, float heading)
 Set position and heading setpoints in GUIDED mode. More...
 
bool autopilot_guided_goto_ned_relative (float dx, float dy, float dz, float dyaw)
 Set position and heading setpoints wrt. More...
 
bool autopilot_guided_goto_body_relative (float dx, float dy, float dz, float dyaw)
 Set position and heading setpoints wrt. More...
 
bool autopilot_guided_move_ned (float vx, float vy, float vz, float heading)
 Set velocity and heading setpoints in GUIDED mode. More...
 
void autopilot_guided_update (uint8_t flags, float x, float y, float z, float yaw)
 Set guided setpoints using flag mask in GUIDED mode. More...
 
void autopilot_check_in_flight (bool motors_on)
 
void autopilot_set_motors_on (bool motors_on)
 
static uint8_t ap_mode_of_3way_switch (void)
 get autopilot mode as set by RADIO_MODE 3-way switch More...
 
void autopilot_on_rc_frame (void)
 Get autopilot mode from two 2way switches. More...
 

Variables

uint8_t autopilot_mode
 
uint8_t autopilot_mode_auto2
 
bool autopilot_in_flight
 
uint32_t autopilot_in_flight_counter
 
uint16_t autopilot_flight_time
 flight time in seconds. More...
 
bool autopilot_motors_on
 
bool kill_throttle
 
bool autopilot_rc
 
bool autopilot_power_switch
 
bool autopilot_ground_detected
 
bool autopilot_detect_ground_once
 

Detailed Description

Autopilot.

Definition in file autopilot.c.

Macro Definition Documentation

#define AUTOPILOT_IN_FLIGHT_MIN_ACCEL   2.0

minimum vertical acceleration for in_flight condition in m/s^2

Definition at line 100 of file autopilot.c.

Referenced by autopilot_check_in_flight().

#define AUTOPILOT_IN_FLIGHT_MIN_SPEED   0.2

minimum vertical speed for in_flight condition in m/s

Definition at line 95 of file autopilot.c.

Referenced by autopilot_check_in_flight().

#define AUTOPILOT_IN_FLIGHT_MIN_THRUST   500

minimum thrust for in_flight condition in pprz_t units (max = 9600)

Definition at line 105 of file autopilot.c.

Referenced by autopilot_check_in_flight().

#define AUTOPILOT_IN_FLIGHT_TIME   20

time steps for in_flight detection (at 20Hz, so 20=1second)

Definition at line 90 of file autopilot.c.

Referenced by autopilot_check_in_flight().

#define FAILSAFE_DESCENT_SPEED   1.5

Set descent speed in failsafe mode.

Definition at line 123 of file autopilot.c.

Referenced by autopilot_set_mode().

#define FAILSAFE_MODE_TOO_FAR_FROM_HOME   AP_MODE_FAILSAFE

Mode that is set when the plane is really too far from home.

Definition at line 129 of file autopilot.c.

Referenced by autopilot_periodic().

#define MODE_STARTUP   AP_MODE_KILL

Definition at line 145 of file autopilot.c.

Referenced by autopilot_init(), and autopilot_set_mode().

#define NAV_PRESCALER   (PERIODIC_FREQUENCY / NAV_FREQ)

Definition at line 343 of file autopilot.c.

Referenced by autopilot_periodic().

#define THRESHOLD_1_PPRZ   (MIN_PPRZ / 2)

Definition at line 716 of file autopilot.c.

Referenced by ap_mode_of_3way_switch().

#define THRESHOLD_2_PPRZ   (MAX_PPRZ / 2)

Definition at line 717 of file autopilot.c.

Referenced by ap_mode_of_3way_switch().

#define UNLOCKED_HOME_MODE   TRUE

Definition at line 151 of file autopilot.c.

Referenced by autopilot_on_rc_frame(), and pprz_mode_update().

Function Documentation

static int ahrs_is_aligned ( void  )
inlinestatic

Definition at line 109 of file autopilot.c.

References stateIsAttitudeValid().

Referenced by autopilot_on_rc_frame(), autopilot_set_mode(), and autopilot_set_motors_on().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static uint8_t ap_mode_of_3way_switch ( void  )
static

get autopilot mode as set by RADIO_MODE 3-way switch

Definition at line 720 of file autopilot.c.

References autopilot_mode_auto2, MODE_AUTO1, MODE_MANUAL, radio_control, RADIO_MODE, THRESHOLD_1_PPRZ, THRESHOLD_2_PPRZ, and RadioControl::values.

Referenced by autopilot_on_rc_frame().

+ Here is the caller graph for this function:

void autopilot_check_in_flight ( bool  motors_on)

Definition at line 669 of file autopilot.c.

References autopilot_in_flight, autopilot_in_flight_counter, AUTOPILOT_IN_FLIGHT_MIN_ACCEL, AUTOPILOT_IN_FLIGHT_MIN_SPEED, AUTOPILOT_IN_FLIGHT_MIN_THRUST, AUTOPILOT_IN_FLIGHT_TIME, stabilization_cmd, stateGetAccelNed_f(), and stateGetSpeedNed_f().

Referenced by failsafe_check().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool autopilot_guided_goto_body_relative ( float  dx,
float  dy,
float  dz,
float  dyaw 
)

Set position and heading setpoints wrt.

current position AND heading in GUIDED mode.

Parameters
dxrelative position (body frame, forward) in meters.
dyrelative position (body frame, right) in meters.
dzrelative position (body frame, down) in meters.
dyawOffset relative to current heading setpoint in radians.
Returns
TRUE if setpoint was set (currently in AP_MODE_GUIDED)

Definition at line 573 of file autopilot.c.

References AP_MODE_GUIDED, autopilot_guided_goto_ned(), autopilot_mode, heading, FloatEulers::psi, stateGetNedToBodyEulers_f(), stateGetPositionNed_f(), stateIsLocalCoordinateValid(), NedCoor_f::x, NedCoor_f::y, and NedCoor_f::z.

Referenced by mavlink_common_message_handler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool autopilot_guided_goto_ned ( float  x,
float  y,
float  z,
float  heading 
)

Set position and heading setpoints in GUIDED mode.

Parameters
xNorth position (local NED frame) in meters.
yEast position (local NED frame) in meters.
zDown position (local NED frame) in meters.
headingSetpoint in radians.
Returns
TRUE if setpoint was set (currently in AP_MODE_GUIDED)

Definition at line 550 of file autopilot.c.

References AP_MODE_GUIDED, autopilot_mode, guidance_h_set_guided_heading(), guidance_h_set_guided_pos(), and guidance_v_set_guided_z().

Referenced by autopilot_guided_goto_body_relative(), autopilot_guided_goto_ned_relative(), and mavlink_common_message_handler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool autopilot_guided_goto_ned_relative ( float  dx,
float  dy,
float  dz,
float  dyaw 
)

Set position and heading setpoints wrt.

current position in GUIDED mode.

Parameters
dxOffset relative to current north position (local NED frame) in meters.
dyOffset relative to current east position (local NED frame) in meters.
dzOffset relative to current down position (local NED frame) in meters.
dyawOffset relative to current heading setpoint in radians.
Returns
TRUE if setpoint was set (currently in AP_MODE_GUIDED)

Definition at line 561 of file autopilot.c.

References AP_MODE_GUIDED, autopilot_guided_goto_ned(), autopilot_mode, heading, FloatEulers::psi, stateGetNedToBodyEulers_f(), stateGetPositionNed_f(), stateIsLocalCoordinateValid(), NedCoor_f::x, NedCoor_f::y, and NedCoor_f::z.

Referenced by mavlink_common_message_handler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool autopilot_guided_move_ned ( float  vx,
float  vy,
float  vz,
float  heading 
)

Set velocity and heading setpoints in GUIDED mode.

Parameters
vxNorth velocity (local NED frame) in meters/sec.
vyEast velocity (local NED frame) in meters/sec.
vzDown velocity (local NED frame) in meters/sec.
headingSetpoint in radians.
Returns
TRUE if setpoint was set (currently in AP_MODE_GUIDED)

Definition at line 586 of file autopilot.c.

References AP_MODE_GUIDED, autopilot_mode, guidance_h_set_guided_heading(), guidance_h_set_guided_vel(), and guidance_v_set_guided_vz().

Referenced by mavlink_common_message_handler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void autopilot_guided_update ( uint8_t  flags,
float  x,
float  y,
float  z,
float  yaw 
)

Set guided setpoints using flag mask in GUIDED mode.

Parameters
flagsBits 0-3 are used to determine the axis system to be used. If bits 0 and 1 are clear then the coordinates are set in absolute NE coordinates. If bit 1 is set bit 0 is ignored. Bits 5-7 define whether the setpoints should be used as position or velocity. Bit flags are defined as follows: bit 0: x,y as offset coordinates bit 1: x,y in body coordinates bit 2: z as offset coordinates bit 3: yaw as offset coordinates bit 4: free bit 5: x,y as vel bit 6: z as vel bit 7: yaw as rate
xNorth position/velocity in meters or meters/sec.
yEast position/velocity in meters or meters/sec.
zDown position/velocity in meters or meters/sec.
yawHeading or heading rate setpoint in radians or radians/sec.

Definition at line 610 of file autopilot.c.

References AP_MODE_GUIDED, autopilot_mode, guidance_h_set_guided_body_vel(), guidance_h_set_guided_heading(), guidance_h_set_guided_heading_rate(), guidance_h_set_guided_pos(), guidance_h_set_guided_vel(), guidance_v_set_guided_vz(), guidance_v_set_guided_z(), FloatEulers::psi, stateGetNedToBodyEulers_f(), stateGetPositionNed_f(), stateIsLocalCoordinateValid(), FloatVect2::x, NedCoor_f::x, FloatVect2::y, NedCoor_f::y, and NedCoor_f::z.

Referenced by firmware_parse_msg().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void autopilot_on_rc_frame ( void  )

Get autopilot mode from two 2way switches.

RADIO_MODE switch just selectes between MANUAL and AUTO. If not MANUAL, the RADIO_AUTO_MODE switch selects between AUTO1 and AUTO2.

This is mainly a cludge for entry level radios with no three-way switch, but two available two-way switches which can be used.

Definition at line 758 of file autopilot.c.

References ahrs_is_aligned(), AP_MODE_FAILSAFE, AP_MODE_HOME, AP_MODE_KILL, AP_MODE_NAV, ap_mode_of_3way_switch(), autopilot_arming_check_motors_on(), autopilot_in_flight, autopilot_mode, autopilot_motors_on, autopilot_set_mode(), commands, GpsIsLost, guidance_h_read_rc(), guidance_v_read_rc(), kill_switch_is_on(), kill_throttle, MODE_MANUAL, radio_control, too_far_from_home, UNLOCKED_HOME_MODE, and RadioControl::values.

Referenced by main_event().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void autopilot_set_mode ( uint8_t  new_autopilot_mode)

Definition at line 424 of file autopilot.c.

References ahrs_is_aligned(), AP_MODE_ATTITUDE_CLIMB, AP_MODE_ATTITUDE_DIRECT, AP_MODE_ATTITUDE_RC_CLIMB, AP_MODE_ATTITUDE_Z_HOLD, AP_MODE_CARE_FREE_DIRECT, AP_MODE_FAILSAFE, AP_MODE_FLIP, AP_MODE_FORWARD, AP_MODE_GUIDED, AP_MODE_HOME, AP_MODE_HOVER_CLIMB, AP_MODE_HOVER_DIRECT, AP_MODE_HOVER_Z_HOLD, AP_MODE_KILL, AP_MODE_MODULE, AP_MODE_NAV, AP_MODE_RATE_DIRECT, AP_MODE_RATE_RC_CLIMB, AP_MODE_RATE_Z_HOLD, AP_MODE_RC_DIRECT, autopilot_in_flight, autopilot_in_flight_counter, autopilot_mode, autopilot_set_motors_on(), FAILSAFE_DESCENT_SPEED, FALSE, GUIDANCE_H_MODE_ATTITUDE, GUIDANCE_H_MODE_CARE_FREE, guidance_h_mode_changed(), GUIDANCE_H_MODE_FLIP, GUIDANCE_H_MODE_FORWARD, GUIDANCE_H_MODE_GUIDED, GUIDANCE_H_MODE_HOVER, GUIDANCE_H_MODE_KILL, GUIDANCE_H_MODE_MODULE_SETTING, GUIDANCE_H_MODE_NAV, GUIDANCE_H_MODE_RATE, GUIDANCE_H_MODE_RC_DIRECT, guidance_v_mode_changed(), GUIDANCE_V_MODE_CLIMB, GUIDANCE_V_MODE_FLIP, GUIDANCE_V_MODE_GUIDED, GUIDANCE_V_MODE_HOVER, GUIDANCE_V_MODE_KILL, GUIDANCE_V_MODE_MODULE_SETTING, GUIDANCE_V_MODE_NAV, GUIDANCE_V_MODE_RC_CLIMB, GUIDANCE_V_MODE_RC_DIRECT, guidance_v_zd_sp, MODE_STARTUP, SPEED_BFP_OF_REAL, stabilization_attitude_set_failsafe_setpoint(), and stabilization_cmd.

Referenced by autopilot_init(), autopilot_on_rc_frame(), autopilot_periodic(), autopilot_SetModeHandler(), failsafe_check(), guidance_flip_run(), and mavlink_common_message_handler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void autopilot_set_motors_on ( bool  motors_on)

Definition at line 704 of file autopilot.c.

References ahrs_is_aligned(), AP_MODE_KILL, autopilot_arming_set(), autopilot_mode, autopilot_motors_on, and kill_throttle.

Referenced by actuators_ardrone_motor_status(), actuators_bebop_commit(), autopilot_set_mode(), and mavlink_common_message_handler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void autopilot_SetModeHandler ( float  mode)

AP mode setting handler.

Checks RC status before calling autopilot_set_mode function

Definition at line 408 of file autopilot.c.

References AP_MODE_FAILSAFE, AP_MODE_FLIP, AP_MODE_GUIDED, AP_MODE_HOME, AP_MODE_KILL, AP_MODE_MODULE, AP_MODE_NAV, autopilot_set_mode(), radio_control, RC_OK, and RadioControl::status.

+ Here is the call graph for this function:

static void send_alive ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 172 of file autopilot.c.

Referenced by autopilot_init().

+ Here is the caller graph for this function:

static void send_attitude ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 177 of file autopilot.c.

References FloatEulers::phi, FloatEulers::psi, stateGetNedToBodyEulers_f(), and FloatEulers::theta.

Referenced by autopilot_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void send_autopilot_version ( struct transport_tx *  trans,
struct link_device *  dev 
)

Definition at line 165 of file autopilot.c.

static void send_dl_value ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 275 of file autopilot.c.

Referenced by autopilot_init().

+ Here is the caller graph for this function:

static void send_energy ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 211 of file autopilot.c.

References Electrical::current, electrical, Electrical::energy, and Electrical::vsupply.

Referenced by autopilot_init().

+ Here is the caller graph for this function:

static void send_fp ( struct transport_tx *  trans,
struct link_device *  dev 
)
static
static void send_rc ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 245 of file autopilot.c.

References radio_control, RADIO_CONTROL_NB_CHANNEL, and RadioControl::values.

Referenced by autopilot_init().

+ Here is the caller graph for this function:

static void send_rotorcraft_cmd ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 280 of file autopilot.c.

References stabilization_cmd.

Referenced by autopilot_init().

+ Here is the caller graph for this function:

static void send_rotorcraft_rc ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Definition at line 250 of file autopilot.c.

References radio_control, RADIO_KILL_SWITCH, RADIO_MODE, RADIO_PITCH, RADIO_ROLL, RADIO_THROTTLE, RADIO_YAW, RadioControl::status, and RadioControl::values.

Referenced by autopilot_init().

+ Here is the caller graph for this function:

static void send_status ( struct transport_tx *  trans,
struct link_device *  dev 
)
static

Variable Documentation

bool autopilot_detect_ground_once

Definition at line 83 of file autopilot.c.

Referenced by autopilot_init(), autopilot_periodic(), and DetectGroundEvent().

uint16_t autopilot_flight_time

flight time in seconds.

Definition at line 74 of file autopilot.c.

bool autopilot_ground_detected
uint32_t autopilot_in_flight_counter

Definition at line 73 of file autopilot.c.

Referenced by autopilot_check_in_flight(), autopilot_init(), and autopilot_set_mode().

uint8_t autopilot_mode_auto2

Definition at line 70 of file autopilot.c.

Referenced by ap_mode_of_3way_switch(), autopilot_init(), and guidance_flip_run().

bool autopilot_power_switch

Definition at line 80 of file autopilot.c.

Referenced by autopilot_init().

bool autopilot_rc

Definition at line 79 of file autopilot.c.

Referenced by autopilot_init(), and main_event().

bool kill_throttle

Definition at line 77 of file autopilot.c.

Referenced by autopilot_ClearSettings(), and autopilot_StoreSettings().