33 #include "generated/airframe.h"
36 #define AP_MODE_KILL 0
37 #define AP_MODE_FAILSAFE 1
38 #define AP_MODE_HOME 2
39 #define AP_MODE_RATE_DIRECT 3
40 #define AP_MODE_ATTITUDE_DIRECT 4
41 #define AP_MODE_RATE_RC_CLIMB 5
42 #define AP_MODE_ATTITUDE_RC_CLIMB 6
43 #define AP_MODE_ATTITUDE_CLIMB 7
44 #define AP_MODE_RATE_Z_HOLD 8
45 #define AP_MODE_ATTITUDE_Z_HOLD 9
46 #define AP_MODE_HOVER_DIRECT 10
47 #define AP_MODE_HOVER_CLIMB 11
48 #define AP_MODE_HOVER_Z_HOLD 12
49 #define AP_MODE_NAV 13
50 #define AP_MODE_RC_DIRECT 14 // Safety Pilot Direct Commands for helicopter direct control
51 #define AP_MODE_CARE_FREE_DIRECT 15
52 #define AP_MODE_FORWARD 16
53 #define AP_MODE_MODULE 17
54 #define AP_MODE_FLIP 18
55 #define AP_MODE_GUIDED 19
82 #define MODE_MANUAL AP_MODE_ATTITUDE_DIRECT
85 #define MODE_AUTO1 AP_MODE_HOVER_Z_HOLD
88 #define MODE_AUTO2 AP_MODE_NAV
92 #define autopilot_KillThrottle(_kill) { \
94 autopilot_set_motors_on(FALSE); \
96 autopilot_set_motors_on(TRUE); \
99 #ifdef POWER_SWITCH_GPIO
101 #define autopilot_SetPowerSwitch(_v) { \
102 autopilot_power_switch = _v; \
103 if (_v) { gpio_set(POWER_SWITCH_GPIO); } \
104 else { gpio_clear(POWER_SWITCH_GPIO); } \
107 #define autopilot_SetPowerSwitch(_v) { \
108 autopilot_power_switch = _v; \
116 #ifdef ROTORCRAFT_IS_HELI
117 #define SetRotorcraftCommands(_cmd, _in_flight, _motor_on) { \
118 commands[COMMAND_ROLL] = _cmd[COMMAND_ROLL]; \
119 commands[COMMAND_PITCH] = _cmd[COMMAND_PITCH]; \
120 commands[COMMAND_YAW] = _cmd[COMMAND_YAW]; \
121 commands[COMMAND_THRUST] = _cmd[COMMAND_THRUST]; \
125 #ifndef ROTORCRAFT_COMMANDS_YAW_ALWAYS_ENABLED
126 #define SetRotorcraftCommands(_cmd, _in_flight, _motor_on) { \
127 if (!(_in_flight)) { _cmd[COMMAND_YAW] = 0; } \
128 if (!(_motor_on)) { _cmd[COMMAND_THRUST] = 0; } \
129 commands[COMMAND_ROLL] = _cmd[COMMAND_ROLL]; \
130 commands[COMMAND_PITCH] = _cmd[COMMAND_PITCH]; \
131 commands[COMMAND_YAW] = _cmd[COMMAND_YAW]; \
132 commands[COMMAND_THRUST] = _cmd[COMMAND_THRUST]; \
135 #define SetRotorcraftCommands(_cmd, _in_flight, _motor_on) { \
136 if (!(_motor_on)) { _cmd[COMMAND_THRUST] = 0; } \
137 commands[COMMAND_ROLL] = _cmd[COMMAND_ROLL]; \
138 commands[COMMAND_PITCH] = _cmd[COMMAND_PITCH]; \
139 commands[COMMAND_YAW] = _cmd[COMMAND_YAW]; \
140 commands[COMMAND_THRUST] = _cmd[COMMAND_THRUST]; \
146 #ifndef THRESHOLD_GROUND_DETECT
147 #define THRESHOLD_GROUND_DETECT 25.0
183 #include "pprzlink/pprzlink_transport.h"
static void autopilot_ClearSettings(float clear)
void autopilot_periodic(void)
bool autopilot_ground_detected
uint16_t autopilot_flight_time
flight time in seconds.
void autopilot_set_mode(uint8_t new_autopilot_mode)
Some architecture independent helper functions for GPIOs.
void autopilot_guided_update(uint8_t flags, float x, float y, float z, float yaw)
Set guided setpoints using flag mask in GUIDED mode.
int32_t settings_store(void)
store settings marked as persistent to flash
void autopilot_SetModeHandler(float new_autopilot_mode)
AP mode setting handler.
bool autopilot_guided_move_ned(float vx, float vy, float vz, float heading)
Set velocity and heading setpoints in GUIDED mode.
static void autopilot_StoreSettings(float store)
void autopilot_set_motors_on(bool motors_on)
void send_autopilot_version(struct transport_tx *trans, struct link_device *dev)
int32_t settings_clear(void)
clear all persistent settings from flash
vector in North East Down coordinates Units: meters
bool autopilot_guided_goto_ned(float x, float y, float z, float heading)
Set position and heading setpoints in GUIDED mode.
#define THRESHOLD_GROUND_DETECT
Z-acceleration threshold to detect ground in m/s^2.
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
void autopilot_init(void)
Autopilot inititalization.
bool autopilot_detect_ground_once
bool autopilot_guided_goto_body_relative(float dx, float dy, float dz, float dyaw)
Set position and heading setpoints wrt.
bool settings_store_flag
flag for setting feedback.
static const struct usb_device_descriptor dev
API to get/set the generic vehicle states.
Persistent settings interface.
void autopilot_check_in_flight(bool motors_on)
void autopilot_on_rc_frame(void)
Get autopilot mode from two 2way switches.
uint8_t autopilot_mode_auto2
bool autopilot_guided_goto_ned_relative(float dx, float dy, float dz, float dyaw)
Set position and heading setpoints wrt.
static void DetectGroundEvent(void)
Ground detection based on vertical acceleration.
bool autopilot_power_switch