47 #if USE_STABILIZATION_RATE
51 #include "generated/settings.h"
56 #if NO_GPS_NEEDED_FOR_NAV
57 #define GpsIsLost() FALSE
59 #define GpsIsLost() TRUE
63 #ifdef POWER_SWITCH_GPIO
67 #include "pprz_version.h"
89 #ifndef AUTOPILOT_IN_FLIGHT_TIME
90 #define AUTOPILOT_IN_FLIGHT_TIME 20
94 #ifndef AUTOPILOT_IN_FLIGHT_MIN_SPEED
95 #define AUTOPILOT_IN_FLIGHT_MIN_SPEED 0.2
99 #ifndef AUTOPILOT_IN_FLIGHT_MIN_ACCEL
100 #define AUTOPILOT_IN_FLIGHT_MIN_ACCEL 2.0
104 #ifndef AUTOPILOT_IN_FLIGHT_MIN_THRUST
105 #define AUTOPILOT_IN_FLIGHT_MIN_THRUST 500
108 #ifndef AUTOPILOT_DISABLE_AHRS_KILL
122 #ifndef FAILSAFE_DESCENT_SPEED
123 #define FAILSAFE_DESCENT_SPEED 1.5
128 #ifndef FAILSAFE_MODE_TOO_FAR_FROM_HOME
129 #define FAILSAFE_MODE_TOO_FAR_FROM_HOME AP_MODE_FAILSAFE
133 #if USE_KILL_SWITCH_FOR_MOTOR_ARMING
136 #elif USE_THROTTLE_FOR_MOTOR_ARMING
145 #define MODE_STARTUP AP_MODE_KILL
149 #ifndef UNLOCKED_HOME_MODE
150 #if MODE_AUTO1 == AP_MODE_HOME
151 #define UNLOCKED_HOME_MODE TRUE
152 PRINT_CONFIG_MSG(
"Enabled UNLOCKED_HOME_MODE since MODE_AUTO1 is AP_MODE_HOME")
153 #elif MODE_AUTO2 == AP_MODE_HOME
154 #define UNLOCKED_HOME_MODE TRUE
155 PRINT_CONFIG_MSG(
"Enabled UNLOCKED_HOME_MODE since MODE_AUTO2 is AP_MODE_HOME")
157 #define UNLOCKED_HOME_MODE FALSE
161 #if MODE_MANUAL == AP_MODE_NAV
162 #error "MODE_MANUAL mustn't be AP_MODE_NAV"
167 static uint32_t ap_version = PPRZ_VERSION_INT;
168 static char *ver_desc = PPRZ_VERSION_DESC;
169 pprz_msg_send_AUTOPILOT_VERSION(trans, dev, AC_ID, &ap_version, strlen(ver_desc), ver_desc);
174 pprz_msg_send_ALIVE(trans, dev, AC_ID, 16, MD5SUM);
180 pprz_msg_send_ATTITUDE(trans, dev, AC_ID, &(att->
phi), &(att->
psi), &(att->
theta));
203 pprz_msg_send_ROTORCRAFT_STATUS(trans, dev, AC_ID,
204 &imu_nb_err, &_motor_nb_err,
219 float power = vsup * curs;
220 pprz_msg_send_ENERGY(trans, dev, AC_ID, &vsup, &curs, &e, &power);
223 static void send_fp(
struct transport_tx *trans,
struct link_device *
dev)
226 pprz_msg_send_ROTORCRAFT_FP(trans, dev, AC_ID,
245 static void send_rc(
struct transport_tx *trans,
struct link_device *
dev)
252 #ifdef RADIO_KILL_SWITCH
257 pprz_msg_send_ROTORCRAFT_RADIO_CONTROL(trans, dev, AC_ID,
271 pprz_msg_send_ACTUATORS(trans, dev, AC_ID , ACTUATORS_NB, actuators);
277 PeriodicSendDlValue(trans, dev);
282 pprz_msg_send_ROTORCRAFT_CMD(trans, dev, AC_ID,
304 #ifdef POWER_SWITCH_GPIO
317 #if USE_STABILIZATION_RATE
343 #define NAV_PRESCALER (PERIODIC_FREQUENCY / NAV_FREQ)
375 #if FAILSAFE_GROUND_DETECT
376 INFO(
"Using FAILSAFE_GROUND_DETECT: KILL")
434 switch (new_autopilot_mode) {
436 #ifndef KILL_AS_FAILSAFE
452 #if USE_STABILIZATION_RATE
480 #ifdef GUIDANCE_H_MODE_MODULE_SETTING
494 switch (new_autopilot_mode) {
496 #ifndef KILL_AS_FAILSAFE
532 #ifdef GUIDANCE_V_MODE_MODULE_SETTING
619 if (bit_is_set(flags, 5)) {
620 if (bit_is_set(flags, 1)) {
626 if (!bit_is_set(flags, 0) && !bit_is_set(flags, 1)) {
630 if (bit_is_set(flags, 1)) {
645 if (bit_is_set(flags, 6)) {
648 if (bit_is_set(flags, 2)) {
659 if (bit_is_set(flags, 7)) {
662 if (bit_is_set(flags, 3)) {
716 #define THRESHOLD_1_PPRZ (MIN_PPRZ / 2)
717 #define THRESHOLD_2_PPRZ (MAX_PPRZ / 2)
739 #if defined RADIO_AUTO_MODE || defined(__DOXYGEN__)
740 static uint8_t ap_mode_of_two_switches(
void)
764 #ifdef RADIO_AUTO_MODE
765 INFO(
"Using RADIO_AUTO_MODE to switch between AUTO1 and AUTO2.")
766 uint8_t new_autopilot_mode = ap_mode_of_two_switches();
801 #ifdef SetAutoCommandsFromRC
806 #ifdef SetCommandsFromRC
bool guidance_v_set_guided_z(float z)
Set z setpoint in GUIDED mode.
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
static void autopilot_arming_set(bool motors_on)
#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)
bool guidance_v_set_guided_vz(float vz)
Set z velocity setpoint in GUIDED mode.
Rotorcraft navigation functions.
float failsafe_mode_dist2
maximum squared distance to home wp before going to failsafe mode
#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.
static void gpio_clear(ioportid_t port, uint16_t pin)
Clear a gpio output to low level.
void guidance_h_read_rc(bool in_flight)
static bool stateIsLocalCoordinateValid(void)
Test if local coordinates are valid.
Dummy stabilization for rotorcrafts.
Periodic telemetry system header (includes downlink utility and generated code).
General attitude stabilization interface for rotorcrafts.
static bool kill_switch_is_on(void)
void guidance_h_run(bool in_flight)
#define AP_MODE_HOVER_DIRECT
uint16_t autopilot_flight_time
flight time in seconds.
void autopilot_set_motors_on(bool motors_on)
#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 AUTOPILOT_IN_FLIGHT_MIN_ACCEL
minimum vertical acceleration for in_flight condition in m/s^2
#define AP_MODE_RATE_Z_HOLD
void guidance_v_mode_changed(uint8_t new_mode)
#define GUIDANCE_H_MODE_ATTITUDE
void stabilization_attitude_init(void)
stabilization_attitude_init
#define AP_MODE_ATTITUDE_Z_HOLD
void nav_home(void)
Home mode navigation (circle around HOME)
bool guidance_h_set_guided_body_vel(float vx, float vy)
Set body relative horizontal velocity setpoint in GUIDED mode.
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)
void guidance_v_run(bool in_flight)
#define AP_MODE_HOVER_CLIMB
uint8_t autopilot_mode_auto2
struct HorizontalGuidance guidance_h
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
void autopilot_check_in_flight(bool motors_on)
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
bool autopilot_guided_goto_body_relative(float dx, float dy, float dz, float dyaw)
Set position and heading setpoints wrt.
Rate stabilization for rotorcrafts.
Automatically arm the motors when applying throttle.
#define SetRotorcraftCommands(_cmd, _in_flight,_motor_on)
Set Rotorcraft commands.
static void send_dl_value(struct transport_tx *trans, struct link_device *dev)
uint32_t autopilot_in_flight_counter
void autopilot_SetModeHandler(float mode)
AP mode setting handler.
bool guidance_h_set_guided_heading(float heading)
Set heading setpoint in GUIDED mode.
bool autopilot_power_switch
#define AP_MODE_RC_DIRECT
#define GUIDANCE_H_MODE_HOVER
Hardware independent API for actuators (servos, motor controllers).
#define AP_MODE_CARE_FREE_DIRECT
Arm the motors using a switch.
static bool stateIsAttitudeValid(void)
Test if attitudes are valid.
bool autopilot_ground_detected
#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.
Architecture independent timing functions.
bool guidance_h_set_guided_pos(float x, float y)
Set horizontal position setpoint in GUIDED mode.
static bool higher_than_max_altitude(void)
bool autopilot_guided_goto_ned_relative(float dx, float dy, float dz, float dyaw)
Set position and heading setpoints wrt.
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.
static void send_fp(struct transport_tx *trans, struct link_device *dev)
#define GUIDANCE_V_MODE_CLIMB
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
void stabilization_attitude_set_failsafe_setpoint(void)
static void autopilot_arming_init(void)
static bool datalink_lost(void)
#define DefaultPeriodic
Set default periodic telemetry.
#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
Optional exceptions triggeringg HOME_MODE 1) GEOFENCE_DATALINK_LOST_TIME: go to HOME mode if datalink...
void nav_init(void)
Navigation Initialisation.
bool guidance_h_set_guided_heading_rate(float rate)
Set heading rate setpoint in GUIDED mode.
void send_autopilot_version(struct transport_tx *trans, struct link_device *dev)
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
bool autopilot_guided_goto_ned(float x, float y, float z, float heading)
Set position and heading setpoints in GUIDED mode.
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)
bool autopilot_guided_move_ned(float vx, float vy, float vz, float heading)
Set velocity and heading setpoints in GUIDED mode.
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 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
#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 RADIO_KILL_SWITCH
#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
bool guidance_h_set_guided_vel(float vx, float vy)
Set horizontal velocity setpoint in GUIDED mode.
struct GpsState gps
global GPS state
void guidance_h_init(void)
bool autopilot_detect_ground_once
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