Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
autopilot.h File Reference

Autopilot modes. More...

#include "std.h"
#include "generated/airframe.h"
#include "state.h"
#include "subsystems/settings.h"
+ Include dependency graph for autopilot.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AP_MODE_KILL   0
 
#define AP_MODE_FAILSAFE   1
 
#define AP_MODE_HOME   2
 
#define AP_MODE_RATE_DIRECT   3
 
#define AP_MODE_ATTITUDE_DIRECT   4
 
#define AP_MODE_RATE_RC_CLIMB   5
 
#define AP_MODE_ATTITUDE_RC_CLIMB   6
 
#define AP_MODE_ATTITUDE_CLIMB   7
 
#define AP_MODE_RATE_Z_HOLD   8
 
#define AP_MODE_ATTITUDE_Z_HOLD   9
 
#define AP_MODE_HOVER_DIRECT   10
 
#define AP_MODE_HOVER_CLIMB   11
 
#define AP_MODE_HOVER_Z_HOLD   12
 
#define AP_MODE_NAV   13
 
#define AP_MODE_RC_DIRECT   14
 
#define AP_MODE_CARE_FREE_DIRECT   15
 
#define AP_MODE_FORWARD   16
 
#define AP_MODE_MODULE   17
 
#define AP_MODE_FLIP   18
 
#define AP_MODE_GUIDED   19
 
#define MODE_MANUAL   AP_MODE_ATTITUDE_DIRECT
 Default RC mode. More...
 
#define MODE_AUTO1   AP_MODE_HOVER_Z_HOLD
 
#define MODE_AUTO2   AP_MODE_NAV
 
#define autopilot_KillThrottle(_kill)
 
#define autopilot_SetPowerSwitch(_v)
 
#define SetRotorcraftCommands(_cmd, _in_flight,_motor_on)
 Set Rotorcraft commands. More...
 
#define THRESHOLD_GROUND_DETECT   25.0
 Z-acceleration threshold to detect ground in m/s^2. More...
 

Functions

void autopilot_init (void)
 Autopilot inititalization. More...
 
void autopilot_periodic (void)
 
void autopilot_on_rc_frame (void)
 Get autopilot mode from two 2way switches. More...
 
void autopilot_set_mode (uint8_t new_autopilot_mode)
 
void autopilot_set_motors_on (bool_t motors_on)
 
void autopilot_check_in_flight (bool_t motors_on)
 
static void DetectGroundEvent (void)
 Ground detection based on vertical acceleration. More...
 
static void autopilot_StoreSettings (float store)
 
static void autopilot_ClearSettings (float clear)
 
bool_t autopilot_guided_goto_ned (float x, float y, float z, float heading)
 Set position and heading setpoints in GUIDED mode. More...
 
bool_t autopilot_guided_goto_ned_relative (float dx, float dy, float dz, float dyaw)
 Set position and heading setpoints wrt. More...
 
bool_t autopilot_guided_goto_body_relative (float dx, float dy, float dz, float dyaw)
 Set position and heading setpoints wrt. More...
 

Variables

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

Detailed Description

Autopilot modes.

Definition in file autopilot.h.

Macro Definition Documentation

#define AP_MODE_ATTITUDE_CLIMB   7

Definition at line 43 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_ATTITUDE_DIRECT   4

Definition at line 40 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_ATTITUDE_RC_CLIMB   6

Definition at line 42 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_ATTITUDE_Z_HOLD   9

Definition at line 45 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_CARE_FREE_DIRECT   15

Definition at line 51 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_FLIP   18

Definition at line 54 of file autopilot.h.

Referenced by autopilot_set_mode().

#define AP_MODE_FORWARD   16

Definition at line 52 of file autopilot.h.

Referenced by autopilot_set_mode().

#define AP_MODE_HOME   2
#define AP_MODE_HOVER_CLIMB   11

Definition at line 47 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_HOVER_DIRECT   10

Definition at line 46 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_HOVER_Z_HOLD   12

Definition at line 48 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_MODULE   17

Definition at line 53 of file autopilot.h.

Referenced by autopilot_set_mode(), and stabilization_opticflow_vel_cb().

#define AP_MODE_RATE_DIRECT   3

Definition at line 39 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_RATE_RC_CLIMB   5

Definition at line 41 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_RATE_Z_HOLD   8

Definition at line 44 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define AP_MODE_RC_DIRECT   14

Definition at line 50 of file autopilot.h.

Referenced by autopilot_set_mode(), and mavlink_send_heartbeat().

#define autopilot_KillThrottle (   _kill)
Value:
{ \
if (_kill) \
}
#define FALSE
Definition: std.h:5
#define TRUE
Definition: std.h:4
void autopilot_set_motors_on(bool_t motors_on)
Definition: autopilot.c:587
if(PrimarySpektrumState.SpektrumTimer)

Definition at line 91 of file autopilot.h.

#define autopilot_SetPowerSwitch (   _v)
Value:
{ \
}
bool_t autopilot_power_switch
Definition: autopilot.c:76

Definition at line 106 of file autopilot.h.

#define MODE_AUTO1   AP_MODE_HOVER_Z_HOLD

Definition at line 84 of file autopilot.h.

Referenced by ap_mode_of_3way_switch().

#define MODE_AUTO2   AP_MODE_NAV

Definition at line 87 of file autopilot.h.

Referenced by autopilot_init().

#define MODE_MANUAL   AP_MODE_ATTITUDE_DIRECT
#define SetRotorcraftCommands (   _cmd,
  _in_flight,
  _motor_on 
)
Value:
{ \
if (!(_in_flight)) { _cmd[COMMAND_YAW] = 0; } \
if (!(_motor_on)) { _cmd[COMMAND_THRUST] = 0; } \
commands[COMMAND_ROLL] = _cmd[COMMAND_ROLL]; \
commands[COMMAND_PITCH] = _cmd[COMMAND_PITCH]; \
commands[COMMAND_YAW] = _cmd[COMMAND_YAW]; \
commands[COMMAND_THRUST] = _cmd[COMMAND_THRUST]; \
}
pprz_t commands[COMMANDS_NB]
Storage of intermediate command values.
Definition: commands.c:30
if(PrimarySpektrumState.SpektrumTimer)

Set Rotorcraft commands.

Limit thrust and/or yaw depending of the in_flight and motors_on flag status

Definition at line 125 of file autopilot.h.

Referenced by autopilot_periodic().

#define THRESHOLD_GROUND_DETECT   25.0

Z-acceleration threshold to detect ground in m/s^2.

Definition at line 146 of file autopilot.h.

Referenced by DetectGroundEvent().

Function Documentation

void autopilot_check_in_flight ( bool_t  motors_on)

Definition at line 552 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, FALSE, stabilization_cmd, stateGetAccelNed_f(), stateGetSpeedNed_f(), and TRUE.

Referenced by failsafe_check().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void autopilot_ClearSettings ( float  clear)
inlinestatic

Definition at line 173 of file autopilot.h.

References kill_throttle, settings_clear(), and settings_clear_flag.

+ Here is the call graph for this function:

bool_t 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 539 of file autopilot.c.

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

Referenced by dl_parse_msg(), and mavlink_common_message_handler().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool_t 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 516 of file autopilot.c.

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool_t 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 527 of file autopilot.c.

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

Referenced by dl_parse_msg(), and mavlink_common_message_handler().

+ 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 644 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 395 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(), 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_t  motors_on)

Definition at line 587 of file autopilot.c.

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

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:

static void autopilot_StoreSettings ( float  store)
inlinestatic

Definition at line 165 of file autopilot.h.

References kill_throttle, settings_store(), and settings_store_flag.

+ Here is the call graph for this function:

static void DetectGroundEvent ( void  )
inlinestatic

Ground detection based on vertical acceleration.

Definition at line 150 of file autopilot.h.

References AP_MODE_FAILSAFE, autopilot_detect_ground_once, autopilot_ground_detected, autopilot_mode, FALSE, stateGetAccelNed_f(), THRESHOLD_GROUND_DETECT, TRUE, and NedCoor_f::z.

Referenced by main_event().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

bool_t autopilot_detect_ground_once

Definition at line 79 of file autopilot.c.

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

bool_t autopilot_ground_detected
uint8_t autopilot_mode_auto2

Definition at line 66 of file autopilot.c.

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

bool_t autopilot_power_switch

Definition at line 76 of file autopilot.c.

Referenced by autopilot_init().

bool_t autopilot_rc

Definition at line 75 of file autopilot.c.

Referenced by autopilot_init(), and main_event().