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
81 #define MODE_MANUAL AP_MODE_ATTITUDE_DIRECT
84 #define MODE_AUTO1 AP_MODE_HOVER_Z_HOLD
87 #define MODE_AUTO2 AP_MODE_NAV
91 #define autopilot_KillThrottle(_kill) { \
93 autopilot_set_motors_on(FALSE); \
95 autopilot_set_motors_on(TRUE); \
98 #ifdef POWER_SWITCH_GPIO
100 #define autopilot_SetPowerSwitch(_v) { \
101 autopilot_power_switch = _v; \
102 if (_v) { gpio_set(POWER_SWITCH_GPIO); } \
103 else { gpio_clear(POWER_SWITCH_GPIO); } \
106 #define autopilot_SetPowerSwitch(_v) { \
107 autopilot_power_switch = _v; \
115 #ifdef ROTORCRAFT_IS_HELI
116 #define SetRotorcraftCommands(_cmd, _in_flight, _motor_on) { \
117 commands[COMMAND_ROLL] = _cmd[COMMAND_ROLL]; \
118 commands[COMMAND_PITCH] = _cmd[COMMAND_PITCH]; \
119 commands[COMMAND_YAW] = _cmd[COMMAND_YAW]; \
120 commands[COMMAND_THRUST] = _cmd[COMMAND_THRUST]; \
124 #ifndef ROTORCRAFT_COMMANDS_YAW_ALWAYS_ENABLED
125 #define SetRotorcraftCommands(_cmd, _in_flight, _motor_on) { \
126 if (!(_in_flight)) { _cmd[COMMAND_YAW] = 0; } \
127 if (!(_motor_on)) { _cmd[COMMAND_THRUST] = 0; } \
128 commands[COMMAND_ROLL] = _cmd[COMMAND_ROLL]; \
129 commands[COMMAND_PITCH] = _cmd[COMMAND_PITCH]; \
130 commands[COMMAND_YAW] = _cmd[COMMAND_YAW]; \
131 commands[COMMAND_THRUST] = _cmd[COMMAND_THRUST]; \
134 #define SetRotorcraftCommands(_cmd, _in_flight, _motor_on) { \
135 if (!(_motor_on)) { _cmd[COMMAND_THRUST] = 0; } \
136 commands[COMMAND_ROLL] = _cmd[COMMAND_ROLL]; \
137 commands[COMMAND_PITCH] = _cmd[COMMAND_PITCH]; \
138 commands[COMMAND_YAW] = _cmd[COMMAND_YAW]; \
139 commands[COMMAND_THRUST] = _cmd[COMMAND_THRUST]; \
145 #ifndef THRESHOLD_GROUND_DETECT
146 #define THRESHOLD_GROUND_DETECT 25.0
static void autopilot_ClearSettings(float clear)
void autopilot_periodic(void)
bool_t autopilot_power_switch
Generic transmission transport header.
uint16_t autopilot_flight_time
flight time in seconds.
void send_autopilot_version(struct transport_tx *trans, struct link_device *dev)
void autopilot_set_mode(uint8_t new_autopilot_mode)
Some architecture independent helper functions for GPIOs.
bool_t autopilot_in_flight
int32_t settings_store(void)
store settings marked as persistent to flash
bool_t settings_store_flag
flag for setting feedback.
static void autopilot_StoreSettings(float store)
bool_t autopilot_motors_on
int32_t settings_clear(void)
clear all persistent settings from flash
vector in North East Down coordinates Units: meters
#define THRESHOLD_GROUND_DETECT
Z-acceleration threshold to detect ground in m/s^2.
bool_t autopilot_detect_ground_once
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
void autopilot_init(void)
Autopilot inititalization.
bool_t settings_clear_flag
bool_t autopilot_guided_goto_body_relative(float dx, float dy, float dz, float dyaw)
Set position and heading setpoints wrt.
void autopilot_check_in_flight(bool_t motors_on)
static const struct usb_device_descriptor dev
bool_t autopilot_guided_goto_ned_relative(float dx, float dy, float dz, float dyaw)
Set position and heading setpoints wrt.
API to get/set the generic vehicle states.
Persistent settings interface.
void autopilot_on_rc_frame(void)
Get autopilot mode from two 2way switches.
bool_t autopilot_guided_goto_ned(float x, float y, float z, float heading)
Set position and heading setpoints in GUIDED mode.
void autopilot_set_motors_on(bool_t motors_on)
uint8_t autopilot_mode_auto2
bool_t autopilot_ground_detected
static void DetectGroundEvent(void)
Ground detection based on vertical acceleration.