47 #include "generated/settings.h"
52 #if NO_GPS_NEEDED_FOR_NAV
53 #define GpsIsLost() FALSE
55 #define GpsIsLost() TRUE
59 #ifdef POWER_SWITCH_GPIO
63 #include "pprz_version.h"
82 #ifndef AUTOPILOT_IN_FLIGHT_TIME
83 #define AUTOPILOT_IN_FLIGHT_TIME 20
87 #ifndef AUTOPILOT_IN_FLIGHT_MIN_SPEED
88 #define AUTOPILOT_IN_FLIGHT_MIN_SPEED 0.2
92 #ifndef AUTOPILOT_IN_FLIGHT_MIN_ACCEL
93 #define AUTOPILOT_IN_FLIGHT_MIN_ACCEL 2.0
97 #ifndef AUTOPILOT_IN_FLIGHT_MIN_THRUST
98 #define AUTOPILOT_IN_FLIGHT_MIN_THRUST 500
101 #ifndef AUTOPILOT_DISABLE_AHRS_KILL
115 #ifndef FAILSAFE_DESCENT_SPEED
116 #define FAILSAFE_DESCENT_SPEED 1.5
121 #ifndef FAILSAFE_MODE_TOO_FAR_FROM_HOME
122 #define FAILSAFE_MODE_TOO_FAR_FROM_HOME AP_MODE_FAILSAFE
126 #if USE_KILL_SWITCH_FOR_MOTOR_ARMING
129 #elif USE_THROTTLE_FOR_MOTOR_ARMING
138 #define MODE_STARTUP AP_MODE_KILL
142 #ifndef UNLOCKED_HOME_MODE
143 #if MODE_AUTO1 == AP_MODE_HOME
144 #define UNLOCKED_HOME_MODE TRUE
145 PRINT_CONFIG_MSG(
"Enabled UNLOCKED_HOME_MODE since MODE_AUTO1 is AP_MODE_HOME")
146 #elif MODE_AUTO2 == AP_MODE_HOME
147 #define UNLOCKED_HOME_MODE TRUE
148 PRINT_CONFIG_MSG(
"Enabled UNLOCKED_HOME_MODE since MODE_AUTO2 is AP_MODE_HOME")
150 #define UNLOCKED_HOME_MODE FALSE
154 #if MODE_MANUAL == AP_MODE_NAV
155 #error "MODE_MANUAL mustn't be AP_MODE_NAV"
160 static uint32_t ap_version = PPRZ_VERSION_INT;
161 static char *ver_desc = PPRZ_VERSION_DESC;
162 pprz_msg_send_AUTOPILOT_VERSION(trans, dev, AC_ID, &ap_version, strlen(ver_desc), ver_desc);
167 pprz_msg_send_ALIVE(trans, dev, AC_ID, 16, MD5SUM);
173 pprz_msg_send_ATTITUDE(trans, dev, AC_ID, &(att->
phi), &(att->
psi), &(att->
theta));
194 pprz_msg_send_ROTORCRAFT_STATUS(trans, dev, AC_ID,
195 &imu_nb_err, &_motor_nb_err,
211 float power = vsup * curs;
212 pprz_msg_send_ENERGY(trans, dev, AC_ID, &vsup, &curs, &e, &power);
218 pprz_msg_send_ROTORCRAFT_FP(trans, dev, AC_ID,
244 #ifdef RADIO_KILL_SWITCH
249 pprz_msg_send_ROTORCRAFT_RADIO_CONTROL(trans, dev, AC_ID,
263 pprz_msg_send_ACTUATORS(trans, dev, AC_ID , ACTUATORS_NB, actuators);
269 PeriodicSendDlValue(trans, dev);
274 pprz_msg_send_ROTORCRAFT_CMD(trans, dev, AC_ID,
296 #ifdef POWER_SWITCH_GPIO
333 #define NAV_PRESCALER (PERIODIC_FREQUENCY / NAV_FREQ)
365 #if FAILSAFE_GROUND_DETECT
366 INFO(
"Using FAILSAFE_GROUND_DETECT: KILL")
405 switch (new_autopilot_mode) {
407 #ifndef KILL_AS_FAILSAFE
446 #ifdef GUIDANCE_H_MODE_MODULE_SETTING
460 switch (new_autopilot_mode) {
462 #ifndef KILL_AS_FAILSAFE
498 #ifdef GUIDANCE_V_MODE_MODULE_SETTING
599 #define THRESHOLD_1_PPRZ (MIN_PPRZ / 2)
600 #define THRESHOLD_2_PPRZ (MAX_PPRZ / 2)
624 #if defined RADIO_AUTO_MODE || defined(__DOXYGEN__)
625 static uint8_t ap_mode_of_two_switches(
void)
650 #ifdef RADIO_AUTO_MODE
651 INFO(
"Using RADIO_AUTO_MODE to switch between AUTO1 and AUTO2.")
652 uint8_t new_autopilot_mode = ap_mode_of_two_switches();
687 #ifdef SetAutoCommandsFromRC
692 #ifdef SetCommandsFromRC
int32_t current
current in milliamps
int32_t guidance_v_z_sp
altitude setpoint in meters (input).
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define AP_MODE_ATTITUDE_DIRECT
static void autopilot_arming_check_motors_on(void)
State machine to check if motors should be turned ON or OFF using the kill switch.
#define GUIDANCE_V_MODE_NAV
void stabilization_none_init(void)
#define GUIDANCE_H_MODE_RC_DIRECT
static void send_alive(struct transport_tx *trans, struct link_device *dev)
Generic transmission transport header.
Rotorcraft navigation functions.
float failsafe_mode_dist2
maximum squared distance to home wp before going to failsafe mode
void send_autopilot_version(struct transport_tx *trans, struct link_device *dev)
#define GUIDANCE_H_MODE_CARE_FREE
#define POWER_SWITCH_GPIO
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
void autopilot_init(void)
Autopilot inititalization.
bool_t autopilot_ground_detected
Dummy stabilization for rotorcrafts.
Periodic telemetry system header (includes downlink utility and generated code).
General attitude stabilization interface for rotorcrafts.
bool_t autopilot_motors_on
#define AP_MODE_HOVER_DIRECT
uint16_t autopilot_flight_time
flight time in seconds.
void guidance_v_run(bool_t in_flight)
static bool_t kill_switch_is_on(void)
static bool_t stateIsAttitudeValid(void)
Test if attitudes are valid.
#define FAILSAFE_MODE_TOO_FAR_FROM_HOME
Mode that is set when the plane is really too far from home.
void guidance_v_init(void)
Some architecture independent helper functions for GPIOs.
float dist2_to_home
squared distance to home waypoint
#define AP_MODE_RATE_RC_CLIMB
#define RADIO_KILL_SWITCH
#define AUTOPILOT_IN_FLIGHT_MIN_ACCEL
minimum vertical acceleration for in_flight condition in m/s^2
#define AP_MODE_RATE_Z_HOLD
static void autopilot_arming_set(bool_t motors_on)
void guidance_v_mode_changed(uint8_t new_mode)
#define GUIDANCE_H_MODE_ATTITUDE
void stabilization_attitude_init(void)
#define AP_MODE_ATTITUDE_Z_HOLD
void nav_home(void)
Home mode navigation (circle around HOME)
bool_t autopilot_detect_ground_once
static void send_rotorcraft_rc(struct transport_tx *trans, struct link_device *dev)
static void send_energy(struct transport_tx *trans, struct link_device *dev)
void stabilization_init(void)
#define AP_MODE_HOVER_CLIMB
uint8_t autopilot_mode_auto2
bool_t guidance_v_set_guided_z(float z)
Set z setpoint in GUIDED mode.
struct HorizontalGuidance guidance_h
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
static void send_actuators(struct transport_tx *trans, struct link_device *dev)
#define GUIDANCE_V_MODE_KILL
struct HorizontalGuidanceSetpoint sp
setpoints
const pprz_t commands_failsafe[COMMANDS_NB]
#define AP_MODE_RATE_DIRECT
Rate stabilization for rotorcrafts.
Automatically arm the motors when applying throttle.
bool_t guidance_h_set_guided_heading(float heading)
Set heading setpoint in GUIDED mode.
#define SetRotorcraftCommands(_cmd, _in_flight,_motor_on)
Set Rotorcraft commands.
void autopilot_check_in_flight(bool_t motors_on)
static void send_dl_value(struct transport_tx *trans, struct link_device *dev)
uint32_t autopilot_in_flight_counter
bool_t autopilot_guided_goto_ned(float x, float y, float z, float heading)
Set position and heading setpoints in GUIDED mode.
#define AP_MODE_RC_DIRECT
#define GUIDANCE_H_MODE_HOVER
Hardware independent API for actuators (servos, motor controllers).
void autopilot_set_motors_on(bool_t motors_on)
bool_t autopilot_guided_goto_ned_relative(float dx, float dy, float dz, float dyaw)
Set position and heading setpoints wrt.
void guidance_h_read_rc(bool_t in_flight)
#define AP_MODE_CARE_FREE_DIRECT
Arm the motors using a switch.
#define AUTOPILOT_IN_FLIGHT_MIN_THRUST
minimum thrust for in_flight condition in pprz_t units (max = 9600)
static struct NedCoor_f * stateGetSpeedNed_f(void)
Get ground speed in local NED coordinates (float).
Interface for electrical status: supply voltage, current, battery status, etc.
bool_t autopilot_power_switch
static void send_rotorcraft_cmd(struct transport_tx *trans, struct link_device *dev)
Device independent GPS code (interface)
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
void compute_dist2_to_home(void)
Computes squared distance to the HOME waypoint potentially sets too_far_from_home.
bool_t autopilot_in_flight
static bool_t stateIsLocalCoordinateValid(void)
Test if local coordinates are valid.
static void send_fp(struct transport_tx *trans, struct link_device *dev)
#define GUIDANCE_V_MODE_CLIMB
void gpio_clear(uint32_t port, uint16_t pin)
Clear a gpio output to low level.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
void stabilization_attitude_set_failsafe_setpoint(void)
static void autopilot_arming_init(void)
#define DefaultPeriodic
Set default periodic telemetry.
void guidance_h_run(bool_t in_flight)
#define FAILSAFE_DESCENT_SPEED
Set descent speed in failsafe mode.
void autopilot_on_rc_frame(void)
Get autopilot mode from two 2way switches.
#define GUIDANCE_V_MODE_HOVER
Hardware independent code for commands handling.
struct RadioControl radio_control
#define GUIDANCE_H_MODE_NAV
static void send_status(struct transport_tx *trans, struct link_device *dev)
#define GUIDANCE_H_MODE_MODULE_SETTING
#define GUIDANCE_H_MODE_KILL
void nav_init(void)
Periodic telemetry.
bool_t guidance_h_set_guided_pos(float x, float y)
Set horizontal position setpoint in GUIDED mode.
Arm the motors by with max yaw stick.
void autopilot_periodic(void)
#define RADIO_CONTROL_NB_CHANNEL
static const struct usb_device_descriptor dev
static uint8_t ap_mode_of_3way_switch(void)
get autopilot mode as set by RADIO_MODE 3-way switch
int32_t heading
with INT32_ANGLE_FRAC
pprz_t commands[COMMANDS_NB]
Storage of intermediate command values.
Persistent settings interface.
volatile uint32_t nb_sec
full seconds since startup
static void send_attitude(struct transport_tx *trans, struct link_device *dev)
static struct EnuCoor_i * stateGetSpeedEnu_i(void)
Get ground speed in local ENU coordinates (int).
uint16_t vsupply
supply voltage in decivolts
void guidance_h_mode_changed(uint8_t new_mode)
General stabilization interface for rotorcrafts.
#define AUTOPILOT_IN_FLIGHT_MIN_SPEED
minimum vertical speed for in_flight condition in m/s
void guidance_v_read_rc(void)
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
#define AP_MODE_HOVER_Z_HOLD
#define GUIDANCE_V_MODE_FLIP
static int ahrs_is_aligned(void)
#define AP_MODE_ATTITUDE_RC_CLIMB
int32_t guidance_v_zd_sp
vertical speed setpoint in meter/s (input).
struct MotorMixing motor_mixing
float energy
consumed energy in mAh
bool_t autopilot_guided_goto_body_relative(float dx, float dy, float dz, float dyaw)
Set position and heading setpoints wrt.
#define SPEED_BFP_OF_REAL(_af)
struct Electrical electrical
#define MODE_MANUAL
Default RC mode.
#define AUTOPILOT_IN_FLIGHT_TIME
time steps for in_flight detection (at 20Hz, so 20=1second)
#define GUIDANCE_V_MODE_RC_CLIMB
void stabilization_rate_init(void)
void nav_periodic_task(void)
Navigation main: call to the code generated from the XML flight plan.
#define UNLOCKED_HOME_MODE
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
#define GUIDANCE_H_MODE_FORWARD
#define GUIDANCE_V_MODE_RC_DIRECT
static void send_rc(struct transport_tx *trans, struct link_device *dev)
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
#define GUIDANCE_H_MODE_RATE
void autopilot_set_mode(uint8_t new_autopilot_mode)
static struct NedCoor_f * stateGetPositionNed_f(void)
Get position in local NED coordinates (float).
#define AP_MODE_ATTITUDE_CLIMB
#define GUIDANCE_H_MODE_FLIP
#define GUIDANCE_V_MODE_MODULE_SETTING
#define GUIDANCE_V_MODE_GUIDED
struct GpsState gps
global GPS state
void guidance_h_init(void)
void gpio_setup_output(uint32_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
struct Int32Vect2 pos
horizontal position setpoint in NED.
#define GUIDANCE_H_MODE_GUIDED