Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
main_ap.c File Reference

AP ( AutoPilot ) tasks. More...

#include <math.h>
#include "firmwares/fixedwing/main_ap.h"
#include "mcu.h"
#include "mcu_periph/sys_time.h"
#include "link_mcu_spi.h"
#include "subsystems/gps.h"
#include "subsystems/imu.h"
#include "subsystems/ahrs.h"
#include "subsystems/ahrs/ahrs_aligner.h"
#include "subsystems/sensors/baro.h"
#include "subsystems/ins.h"
#include "state.h"
#include "firmwares/fixedwing/autopilot.h"
#include "firmwares/fixedwing/stabilization/stabilization_attitude.h"
#include <CTRL_TYPE_H>
#include "subsystems/nav.h"
#include "generated/flight_plan.h"
#include "subsystems/datalink/datalink.h"
#include "subsystems/settings.h"
#include "subsystems/datalink/xbee.h"
#include "subsystems/datalink/w5100.h"
#include "firmwares/fixedwing/ap_downlink.h"
#include "generated/modules.h"
#include "generated/settings.h"
#include "rc_settings.h"
#include "led.h"
+ Include dependency graph for main_ap.c:

Go to the source code of this file.

Macros

#define MODULES_C
 
#define COMMAND_ROLL_TRIM   0
 
#define COMMAND_PITCH_TRIM   0
 
#define COMMAND_YAW_TRIM   0
 
#define TELEMETRY_FREQUENCY   60
 
#define MODULES_FREQUENCY   60
 
#define AHRS_PROPAGATE_FREQUENCY   PERIODIC_FREQUENCY
 
#define AHRS_CORRECT_FREQUENCY   PERIODIC_FREQUENCY
 
#define RC_LOST_MODE   PPRZ_MODE_HOME
 mode to enter when RC is lost in PPRZ_MODE_MANUAL or PPRZ_MODE_AUTO1 More...
 
#define LOW_BATTERY_DELAY   5
 Maximum time allowed for low battery level before going into kill mode. More...
 
#define KILL_MODE_DISTANCE   (1.5*MAX_DIST_FROM_HOME)
 Maximum distance from HOME waypoint before going into kill mode. More...
 
#define MIN_SPEED_FOR_TAKEOFF   5.
 Define minimal speed for takeoff in m/s. More...
 

Functions

static void on_gyro_event (void)
 
static void on_accel_event (void)
 
static void on_mag_event (void)
 
static void on_gps_solution (void)
 
static void on_baro_abs_event (void)
 
static void on_baro_dif_event (void)
 
void init_ap (void)
 
void handle_periodic_tasks_ap (void)
 
static uint8_t pprz_mode_update (void)
 Update paparazzi mode. More...
 
static uint8_t mcu1_status_update (void)
 
static void copy_from_to_fbw (void)
 Send back uncontrolled channels. More...
 
static void telecommand_task (void)
 Function to be called when a message from FBW is available. More...
 
void reporting_task (void)
 Send a series of initialisation messages followed by a stream of periodic ones. More...
 
void navigation_task (void)
 Compute desired_course. More...
 
void attitude_loop (void)
 
void sensors_task (void)
 Run at PERIODIC_FREQUENCY (60Hz if not defined) More...
 
void monitor_task (void)
 monitor stuff run at 1Hz More...
 
void event_task_ap (void)
 

Variables

volatile uint8_t ahrs_timeout_counter = 0
 
static const uint16_t version = 1
 
static uint8_t mcu1_status
 
static uint8_t mcu1_ppm_cpt
 
static int32_t current
 Supply current in milliAmpere. More...
 
tid_t modules_tid
 id for modules_periodic_task() timer More...
 
tid_t telemetry_tid
 id for telemetry_periodic() timer More...
 
tid_t sensors_tid
 id for sensors_task() timer More...
 
tid_t attitude_tid
 id for attitude_loop() timer More...
 
tid_t navigation_tid
 id for navigation_task() timer More...
 
tid_t monitor_tid
 id for monitor_task() timer More...
 

Detailed Description

AP ( AutoPilot ) tasks.

This process is reponsible for the collecting the different sensors data, calling the appropriate estimation algorithms and running the different control loops.

Definition in file main_ap.c.

Macro Definition Documentation

#define AHRS_CORRECT_FREQUENCY   PERIODIC_FREQUENCY

Definition at line 123 of file main_ap.c.

Referenced by on_gyro_event().

#define AHRS_PROPAGATE_FREQUENCY   PERIODIC_FREQUENCY

Definition at line 119 of file main_ap.c.

Referenced by on_gyro_event().

#define COMMAND_PITCH_TRIM   0

Definition at line 93 of file main_ap.c.

Referenced by init_ap().

#define COMMAND_ROLL_TRIM   0

Definition at line 89 of file main_ap.c.

Referenced by init_ap().

#define COMMAND_YAW_TRIM   0

Definition at line 97 of file main_ap.c.

Referenced by init_ap().

#define KILL_MODE_DISTANCE   (1.5*MAX_DIST_FROM_HOME)

Maximum distance from HOME waypoint before going into kill mode.

Definition at line 594 of file main_ap.c.

Referenced by monitor_task().

#define LOW_BATTERY_DELAY   5

Maximum time allowed for low battery level before going into kill mode.

Definition at line 590 of file main_ap.c.

Referenced by monitor_task().

#define MIN_SPEED_FOR_TAKEOFF   5.

Define minimal speed for takeoff in m/s.

Definition at line 598 of file main_ap.c.

Referenced by monitor_task().

#define MODULES_C

Definition at line 31 of file main_ap.c.

#define MODULES_FREQUENCY   60

Definition at line 111 of file main_ap.c.

Referenced by init_ap().

#define RC_LOST_MODE   PPRZ_MODE_HOME

mode to enter when RC is lost in PPRZ_MODE_MANUAL or PPRZ_MODE_AUTO1

Definition at line 346 of file main_ap.c.

Referenced by telecommand_task().

#define TELEMETRY_FREQUENCY   60

Definition at line 106 of file main_ap.c.

Referenced by init_ap().

Function Documentation

static void copy_from_to_fbw ( void  )
inlinestatic

Send back uncontrolled channels.

Definition at line 336 of file main_ap.c.

References ap_state, fbw_state, and RADIO_YAW.

Referenced by telecommand_task().

+ Here is the caller graph for this function:

void event_task_ap ( void  )

Definition at line 628 of file main_ap.c.

References attitude_loop(), BaroEvent, DatalinkEvent, FALSE, GpsEvent, i2c_event(), ImuEvent, inter_mcu_received_fbw, link_mcu_event_task(), on_accel_event(), on_baro_abs_event(), on_baro_dif_event(), on_gps_solution(), on_gyro_event(), on_mag_event(), and telecommand_task().

Referenced by sim_periodic_task().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void handle_periodic_tasks_ap ( void  )

Definition at line 256 of file main_ap.c.

References attitude_loop(), LED_PERIODIC, monitor_task(), navigation_task(), reporting_task(), sensors_task(), and sys_time_check_and_ack_timer().

+ Here is the call graph for this function:

static uint8_t mcu1_status_update ( void  )
inlinestatic

Definition at line 323 of file main_ap.c.

References FALSE, and fbw_state.

Referenced by telecommand_task().

+ Here is the caller graph for this function:

void monitor_task ( void  )

monitor stuff run at 1Hz

Definition at line 601 of file main_ap.c.

References autopilot_flight_time, datalink_time, DefaultChannel, DefaultDevice, dist2_to_home, KILL_MODE_DISTANCE, kill_throttle, launch, LOW_BATTERY_DELAY, MIN_SPEED_FOR_TAKEOFF, sys_time::nb_sec, Square, stateGetHorizontalSpeedNorm_f(), TRUE, and vsupply.

Referenced by handle_periodic_tasks_ap(), and sim_monitor_task().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void on_accel_event ( void  )
inlinestatic

Definition at line 695 of file main_ap.c.

Referenced by event_task_ap().

+ Here is the caller graph for this function:

static void on_baro_abs_event ( void  )
inlinestatic

Definition at line 783 of file main_ap.c.

References ins_update_baro().

Referenced by event_task_ap().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void on_baro_dif_event ( void  )
inlinestatic

Definition at line 787 of file main_ap.c.

Referenced by event_task_ap().

+ Here is the caller graph for this function:

static void on_gps_solution ( void  )
inlinestatic

Definition at line 681 of file main_ap.c.

References ahrs_update_gps(), and ins_update_gps().

Referenced by event_task_ap().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void on_gyro_event ( void  )
inlinestatic
static void on_mag_event ( void  )
inlinestatic

Definition at line 767 of file main_ap.c.

References ahrs, AHRS_RUNNING, ahrs_update_mag(), imu, ImuScaleMag, and Ahrs::status.

Referenced by event_task_ap().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static uint8_t pprz_mode_update ( void  )
inlinestatic

Update paparazzi mode.

Definition at line 288 of file main_ap.c.

References FALSE, fbw_state, ModeUpdate, pprz_mode, PPRZ_MODE_AUTO1, PPRZ_MODE_AUTO2, PPRZ_MODE_GPS_OUT_OF_ORDER, PPRZ_MODE_HOME, PPRZ_MODE_MANUAL, PPRZ_MODE_OF_PULSE, RADIO_MODE, THRESHOLD2, and TRUE.

Referenced by telecommand_task().

+ Here is the caller graph for this function:

void reporting_task ( void  )

Send a series of initialisation messages followed by a stream of periodic ones.

Called at 60Hz.

initialisation phase during boot

then report periodicly

Definition at line 422 of file main_ap.c.

References DefaultChannel, DefaultDevice, FALSE, and TRUE.

Referenced by handle_periodic_tasks_ap(), and sim_periodic_task().

+ Here is the caller graph for this function:

void sensors_task ( void  )

Run at PERIODIC_FREQUENCY (60Hz if not defined)

Definition at line 564 of file main_ap.c.

References ahrs_propagate(), baro_periodic(), imu_periodic(), and ins_periodic().

Referenced by handle_periodic_tasks_ap(), and sim_periodic_task().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void telecommand_task ( void  )
inlinestatic

Function to be called when a message from FBW is available.

In AUTO1 mode, compute roll setpoint and pitch setpoint from RADIO_ROLL and RADIO_PITCH

Roll is bounded between [-AUTO1_MAX_ROLL;AUTO1_MAX_ROLL]

Pitch is bounded between [-AUTO1_MAX_PITCH;AUTO1_MAX_PITCH]

Else asynchronously set by h_ctl_course_loop()

In AUTO1, throttle comes from RADIO_THROTTLE In MANUAL, the value is copied to get it in the telemetry

else asynchronously set by v_ctl_climb_loop();

Definition at line 352 of file main_ap.c.

References autopilot_flight_time, copy_from_to_fbw(), DefaultChannel, DefaultDevice, FALSE, fbw_state, FLOAT_OF_PPRZ, h_ctl_pitch_setpoint, h_ctl_roll_setpoint, launch, mcu1_status_update(), PERIODIC_SEND_PPRZ_MODE, pprz_mode, PPRZ_MODE_AUTO1, PPRZ_MODE_AUTO2, PPRZ_MODE_GPS_OUT_OF_ORDER, PPRZ_MODE_HOME, PPRZ_MODE_MANUAL, pprz_mode_update(), RADIO_PITCH, RADIO_ROLL, RADIO_THROTTLE, RC_LOST_MODE, rc_settings(), THROTTLE_THRESHOLD_TAKEOFF, too_far_from_home, TRUE, v_ctl_throttle_setpoint, and vsupply.

Referenced by event_task_ap().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

volatile uint8_t ahrs_timeout_counter = 0

Definition at line 130 of file main_ap.c.

tid_t attitude_tid

id for attitude_loop() timer

Definition at line 161 of file main_ap.c.

int32_t current
static

Supply current in milliAmpere.

This the ap copy of the measurement from fbw

Definition at line 155 of file main_ap.c.

uint8_t mcu1_ppm_cpt
static

Definition at line 149 of file main_ap.c.

uint8_t mcu1_status
static

Definition at line 146 of file main_ap.c.

tid_t modules_tid

id for modules_periodic_task() timer

Definition at line 158 of file main_ap.c.

tid_t monitor_tid

id for monitor_task() timer

Definition at line 163 of file main_ap.c.

tid_t navigation_tid

id for navigation_task() timer

Definition at line 162 of file main_ap.c.

tid_t sensors_tid

id for sensors_task() timer

Definition at line 160 of file main_ap.c.

tid_t telemetry_tid

id for telemetry_periodic() timer

Definition at line 159 of file main_ap.c.

const uint16_t version = 1
static

Definition at line 144 of file main_ap.c.