Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
main_ap.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2010 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
31 #define MODULES_C
32 
33 #define ABI_C
34 
35 #include <math.h>
36 
38 #include "mcu.h"
39 #include "mcu_periph/sys_time.h"
40 #include "inter_mcu.h"
41 #include "link_mcu.h"
42 
43 // Sensors
44 #if USE_GPS
45 #include "subsystems/gps.h"
46 #endif
47 #if USE_IMU
48 #include "subsystems/imu.h"
49 #endif
50 #if USE_AHRS
51 #include "subsystems/ahrs.h"
52 #endif
53 #if USE_AHRS_ALIGNER
55 #endif
56 #if USE_BARO_BOARD
58 PRINT_CONFIG_MSG_VALUE("USE_BARO_BOARD is TRUE, reading onboard baro: ", BARO_BOARD)
59 #endif
60 
61 
62 // autopilot & control
63 #include "state.h"
66 #include CTRL_TYPE_H
68 #include "generated/flight_plan.h"
69 
70 // datalink & telemetry
71 #if DATALINK || SITL
74 #endif
75 #if PERIODIC_TELEMETRY
77 #endif
78 #include "subsystems/settings.h"
79 
80 // modules & settings
81 #include "generated/modules.h"
82 #include "generated/settings.h"
83 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
84 #include "rc_settings.h"
85 #endif
86 #include "subsystems/abi.h"
87 
88 #include "led.h"
89 
90 #ifdef USE_NPS
91 #include "nps_autopilot.h"
92 #endif
93 
94 /* Default trim commands for roll, pitch and yaw */
95 #ifndef COMMAND_ROLL_TRIM
96 #define COMMAND_ROLL_TRIM 0
97 #endif
98 
99 #ifndef COMMAND_PITCH_TRIM
100 #define COMMAND_PITCH_TRIM 0
101 #endif
102 
103 #ifndef COMMAND_YAW_TRIM
104 #define COMMAND_YAW_TRIM 0
105 #endif
106 
107 /* Geofence exceptions */
109 
110 /* if PRINT_CONFIG is defined, print some config options */
111 PRINT_CONFIG_VAR(PERIODIC_FREQUENCY)
112 PRINT_CONFIG_VAR(NAVIGATION_FREQUENCY)
113 PRINT_CONFIG_VAR(CONTROL_FREQUENCY)
114 
115 /* TELEMETRY_FREQUENCY is defined in generated/periodic_telemetry.h
116  * defaults to 60Hz or set by TELEMETRY_FREQUENCY configure option in airframe file
117  */
118 #ifndef TELEMETRY_FREQUENCY
119 #define TELEMETRY_FREQUENCY 60
120 #endif
121 PRINT_CONFIG_VAR(TELEMETRY_FREQUENCY)
122 
123 /* MODULES_FREQUENCY is defined in generated/modules.h
124  * according to main_freq parameter set for modules in airframe file
125  */
126 PRINT_CONFIG_VAR(MODULES_FREQUENCY)
127 
128 #if USE_BARO_BOARD
129 #ifndef BARO_PERIODIC_FREQUENCY
130 #define BARO_PERIODIC_FREQUENCY 50
131 #endif
132 PRINT_CONFIG_VAR(BARO_PERIODIC_FREQUENCY)
133 #endif
134 
135 
136 #if USE_IMU
137 #ifdef AHRS_PROPAGATE_FREQUENCY
138 #if (AHRS_PROPAGATE_FREQUENCY > PERIODIC_FREQUENCY)
139 #warning "PERIODIC_FREQUENCY should be least equal or greater than AHRS_PROPAGATE_FREQUENCY"
140 INFO_VALUE("it is recommended to configure in your airframe PERIODIC_FREQUENCY to at least ", AHRS_PROPAGATE_FREQUENCY)
141 #endif
142 #endif
143 #endif // USE_IMU
144 
145 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
147 #endif
148 
149 
156 #if USE_BARO_BOARD
157 tid_t baro_tid;
158 #endif
159 
160 
162 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
163 volatile uint8_t new_ins_attitude = 0;
164 static abi_event new_att_ev;
165 static void new_att_cb(uint8_t sender_id __attribute__((unused)),
166  uint32_t stamp __attribute__((unused)),
167  struct Int32Rates *gyro __attribute__((unused)))
168 {
169  new_ins_attitude = 1;
170 }
171 #endif
172 
173 
174 void init_ap(void)
175 {
176 #ifndef SINGLE_MCU
177  mcu_init();
178 #endif /* SINGLE_MCU */
179 
180 #if defined(PPRZ_TRIG_INT_COMPR_FLASH)
181  pprz_trig_int_init();
182 #endif
183 
184  /****** initialize and reset state interface ********/
185 
186  stateInit();
187 
188  /************* Sensors initialization ***************/
189 
190 #if USE_AHRS_ALIGNER
192 #endif
193 
195 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
196  AbiBindMsgIMU_GYRO_INT32(ABI_BROADCAST, &new_att_ev, &new_att_cb);
197 #endif
198 
199 #if USE_AHRS
200  ahrs_init();
201 #endif
202 
203 #if USE_BARO_BOARD
204  baro_init();
205 #endif
206 
207  /************* Links initialization ***************/
208 #if defined MCU_SPI_LINK || defined MCU_UART_LINK || defined MCU_CAN_LINK
209  link_mcu_init();
210 #endif
211 #if USE_AUDIO_TELEMETRY
213 #endif
214 
215  /************ Internal status ***************/
216  autopilot_init();
217  h_ctl_init();
218  v_ctl_init();
219  nav_init();
220 
221  modules_init();
222 
223  settings_init();
224 
225  /**** start timers for periodic functions *****/
226  sensors_tid = sys_time_register_timer(1. / PERIODIC_FREQUENCY, NULL);
227  navigation_tid = sys_time_register_timer(1. / NAVIGATION_FREQUENCY, NULL);
228  attitude_tid = sys_time_register_timer(1. / CONTROL_FREQUENCY, NULL);
229  modules_tid = sys_time_register_timer(1. / MODULES_FREQUENCY, NULL);
230  telemetry_tid = sys_time_register_timer(1. / TELEMETRY_FREQUENCY, NULL);
231  monitor_tid = sys_time_register_timer(1.0, NULL);
232 #if USE_BARO_BOARD
233  baro_tid = sys_time_register_timer(1. / BARO_PERIODIC_FREQUENCY, NULL);
234 #endif
235 
237  mcu_int_enable();
238 
239 #if DOWNLINK
240  downlink_init();
241 #endif
242 
243 #if defined AEROCOMM_DATA_PIN
244  IO0DIR |= _BV(AEROCOMM_DATA_PIN);
245  IO0SET = _BV(AEROCOMM_DATA_PIN);
246 #endif
247 
248  /* set initial trim values.
249  * these are passed to fbw via inter_mcu.
250  */
251  PPRZ_MUTEX_LOCK(ap_state_mtx);
252  ap_state->command_roll_trim = COMMAND_ROLL_TRIM;
253  ap_state->command_pitch_trim = COMMAND_PITCH_TRIM;
254  ap_state->command_yaw_trim = COMMAND_YAW_TRIM;
255  PPRZ_MUTEX_UNLOCK(ap_state_mtx);
256 
257 #if USE_IMU
258  // send body_to_imu from here for now
259  AbiSendMsgBODY_TO_IMU_QUAT(1, orientationGetQuat_f(&imu.body_to_imu));
260 #endif
261 }
262 
263 
265 {
266 
267  if (sys_time_check_and_ack_timer(sensors_tid)) {
268  sensors_task();
269  }
270 
271 #if USE_BARO_BOARD
272  if (sys_time_check_and_ack_timer(baro_tid)) {
273  baro_periodic();
274  }
275 #endif
276 
277  if (sys_time_check_and_ack_timer(navigation_tid)) {
278  navigation_task();
279  }
280 
281 #ifndef AHRS_TRIGGERED_ATTITUDE_LOOP
282  if (sys_time_check_and_ack_timer(attitude_tid)) {
283  attitude_loop();
284  }
285 #endif
286 
287  if (sys_time_check_and_ack_timer(modules_tid)) {
288  modules_periodic_task();
289  }
290 
291  if (sys_time_check_and_ack_timer(monitor_tid)) {
292  monitor_task();
293  }
294 
295  if (sys_time_check_and_ack_timer(telemetry_tid)) {
296  reporting_task();
297  LED_PERIODIC();
298  }
299 
300 }
301 
302 
303 /******************** Interaction with FBW *****************************/
304 
307 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
308 static inline uint8_t pprz_mode_update(void)
309 {
310  if ((pprz_mode != PPRZ_MODE_HOME &&
312 #ifdef UNLOCKED_HOME_MODE
313  || true
314 #endif
315  ) {
316 #ifndef RADIO_AUTO_MODE
317  return ModeUpdate(pprz_mode, PPRZ_MODE_OF_PULSE(imcu_get_radio(RADIO_MODE)));
318 #else
319  INFO("Using RADIO_AUTO_MODE to switch between AUTO1 and AUTO2.")
320  /* If RADIO_AUTO_MODE is enabled mode swithing will be seperated between two switches/channels
321  * RADIO_MODE will switch between PPRZ_MODE_MANUAL and any PPRZ_MODE_AUTO mode selected by RADIO_AUTO_MODE.
322  *
323  * This is mainly a cludge for entry level radios with no three-way switch but two available two-way switches which can be used.
324  */
325  if (PPRZ_MODE_OF_PULSE(imcu_get_radio(RADIO_MODE)) == PPRZ_MODE_MANUAL) {
326  /* RADIO_MODE in MANUAL position */
328  } else {
329  /* RADIO_MODE not in MANUAL position.
330  * Select AUTO mode bassed on RADIO_AUTO_MODE channel
331  */
332  return ModeUpdate(pprz_mode, (imcu_get_radio(RADIO_AUTO_MODE) > THRESHOLD2) ? PPRZ_MODE_AUTO2 : PPRZ_MODE_AUTO1);
333  }
334 #endif // RADIO_AUTO_MODE
335  } else {
336  return false;
337  }
338 }
339 #else // not RADIO_CONTROL
340 static inline uint8_t pprz_mode_update(void)
341 {
342  return false;
343 }
344 #endif
345 
346 static inline uint8_t mcu1_status_update(void)
347 {
348  uint8_t new_status = imcu_get_status();
349  if (mcu1_status != new_status) {
350  bool changed = ((mcu1_status & MASK_FBW_CHANGED) != (new_status & MASK_FBW_CHANGED));
351  mcu1_status = new_status;
352  return changed;
353  }
354  return false;
355 }
356 
357 
360 static inline void copy_from_to_fbw(void)
361 {
362  PPRZ_MUTEX_LOCK(fbw_state_mtx);
363  PPRZ_MUTEX_LOCK(ap_state_mtx);
364 #ifdef SetAutoCommandsFromRC
365  SetAutoCommandsFromRC(ap_state->commands, fbw_state->channels);
366 #elif defined RADIO_YAW && defined COMMAND_YAW
367  ap_state->commands[COMMAND_YAW] = fbw_state->channels[RADIO_YAW];
368 #endif
369  PPRZ_MUTEX_UNLOCK(ap_state_mtx);
370  PPRZ_MUTEX_UNLOCK(fbw_state_mtx);
371 }
372 
374 #ifndef RC_LOST_MODE
375 #define RC_LOST_MODE PPRZ_MODE_HOME
376 #endif
377 
381 static inline void telecommand_task(void)
382 {
383  uint8_t mode_changed = false;
385 
386  /* really_lost is true if we lost RC in MANUAL or AUTO1 */
387  uint8_t really_lost = bit_is_set(imcu_get_status(), STATUS_RADIO_REALLY_LOST) &&
389 
393  mode_changed = true;
394  }
395  if (really_lost) {
397  mode_changed = true;
398  }
399  }
400  if (bit_is_set(imcu_get_status(), AVERAGED_CHANNELS_SENT)) {
401  bool pprz_mode_changed = pprz_mode_update();
402  mode_changed |= pprz_mode_changed;
403 #if defined RADIO_CALIB && defined RADIO_CONTROL_SETTINGS
404  PPRZ_MUTEX_LOCK(fbw_state_mtx);
405  bool calib_mode_changed = RcSettingsModeUpdate(fbw_state->channels);
406  PPRZ_MUTEX_UNLOCK(fbw_state_mtx);
407  rc_settings(calib_mode_changed || pprz_mode_changed);
408  mode_changed |= calib_mode_changed;
409 #endif
410  }
411  mode_changed |= mcu1_status_update();
412  if (mode_changed) { autopilot_send_mode(); }
413 
414 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
415 
418  if (pprz_mode == PPRZ_MODE_AUTO1) {
420  h_ctl_roll_setpoint = FLOAT_OF_PPRZ(imcu_get_radio(RADIO_ROLL), 0., AUTO1_MAX_ROLL);
421 
423  h_ctl_pitch_setpoint = FLOAT_OF_PPRZ(imcu_get_radio(RADIO_PITCH), 0., AUTO1_MAX_PITCH);
424 #if H_CTL_YAW_LOOP && defined RADIO_YAW
425 
426  h_ctl_yaw_rate_setpoint = FLOAT_OF_PPRZ(imcu_get_radio(RADIO_YAW), 0., AUTO1_MAX_YAW_RATE);
427 #endif
428  }
433  v_ctl_throttle_setpoint = imcu_get_radio(RADIO_THROTTLE);
434  }
437  mcu1_ppm_cpt = imcu_get_ppm_cpt();
438 #endif // RADIO_CONTROL
439 
440  // update electrical from FBW
441  imcu_get_electrical(&vsupply, &current, &energy);
442 
443 #ifdef RADIO_CONTROL
444  /* the SITL check is a hack to prevent "automatic" launch in NPS */
445 #ifndef SITL
446  if (!autopilot_flight_time) {
448  launch = true;
449  }
450  }
451 #endif
452 #endif
453 }
454 
455 
456 /**************************** Periodic tasks ***********************************/
457 
462 void reporting_task(void)
463 {
464  static uint8_t boot = true;
465 
466  /* initialisation phase during boot */
467  if (boot) {
468 #if DOWNLINK
469  send_autopilot_version(&(DefaultChannel).trans_tx, &(DefaultDevice).device);
470 #endif
471  boot = false;
472  }
473  /* then report periodicly */
474  else {
475  //PeriodicSendAp(DefaultChannel, DefaultDevice);
476 #if PERIODIC_TELEMETRY
477  periodic_telemetry_send_Ap(DefaultPeriodic, &(DefaultChannel).trans_tx, &(DefaultDevice).device);
478 #endif
479  }
480 }
481 
482 
483 #ifdef FAILSAFE_DELAY_WITHOUT_GPS
484 #define GpsTimeoutError (sys_time.nb_sec - gps.last_3dfix_time > FAILSAFE_DELAY_WITHOUT_GPS)
485 #endif
486 
490 void navigation_task(void)
491 {
492 #if defined FAILSAFE_DELAY_WITHOUT_GPS
493 
494  static uint8_t last_pprz_mode;
495 
498  if (launch) {
499  if (GpsTimeoutError) {
501  last_pprz_mode = pprz_mode;
504  gps_lost = true;
505  }
506  } else if (gps_lost) { /* GPS is ok */
508  pprz_mode = last_pprz_mode;
509  gps_lost = false;
511  }
512  }
513 #endif /* GPS && FAILSAFE_DELAY_WITHOUT_GPS */
514 
516  if (pprz_mode == PPRZ_MODE_HOME) {
517  nav_home();
518  } else if (pprz_mode == PPRZ_MODE_GPS_OUT_OF_ORDER) {
519  nav_without_gps();
520  } else {
522  }
523 
524 #ifdef TCAS
525  callTCAS();
526 #endif
527 
528 #if DOWNLINK && !defined PERIOD_NAVIGATION_Ap_0 // If not sent periodically (in default 0 mode)
529  SEND_NAVIGATION(&(DefaultChannel).trans_tx, &(DefaultDevice).device);
530 #endif
531 
532  /* The nav task computes only nav_altitude. However, we are interested
533  by desired_altitude (= nav_alt+alt_shift) in any case.
534  So we always run the altitude control loop */
537  }
538 
541 #ifdef H_CTL_RATE_LOOP
542  /* Be sure to be in attitude mode, not roll */
543  h_ctl_auto1_rate = false;
544 #endif
546  h_ctl_course_loop(); /* aka compute nav_desired_roll */
547  }
548 
549  // climb_loop(); //4Hz
550  }
551 }
552 
553 
554 void attitude_loop(void)
555 {
556 
557  if (pprz_mode >= PPRZ_MODE_AUTO2) {
558 #if CTRL_VERTICAL_LANDING
561  } else {
562 #endif
566  } else {
569  } /* v_ctl_mode >= V_CTL_MODE_AUTO_CLIMB */
570  } /* v_ctl_mode == V_CTL_MODE_AUTO_THROTTLE */
571 #if CTRL_VERTICAL_LANDING
572  } /* v_ctl_mode == V_CTL_MODE_LANDING */
573 #endif
574 
575 #if defined V_CTL_THROTTLE_IDLE
576  Bound(v_ctl_throttle_setpoint, TRIM_PPRZ(V_CTL_THROTTLE_IDLE * MAX_PPRZ), MAX_PPRZ);
577 #endif
578 
579 #ifdef V_CTL_POWER_CTL_BAT_NOMINAL
580  if (vsupply > 0.) {
581  v_ctl_throttle_setpoint *= 10. * V_CTL_POWER_CTL_BAT_NOMINAL / (float)vsupply;
583  }
584 #endif
585 
586  // Copy the pitch setpoint from the guidance to the stabilization control
588  Bound(h_ctl_pitch_setpoint, H_CTL_PITCH_MIN_SETPOINT, H_CTL_PITCH_MAX_SETPOINT);
591  }
592  }
593 
594  h_ctl_attitude_loop(); /* Set h_ctl_aileron_setpoint & h_ctl_elevator_setpoint */
596  PPRZ_MUTEX_LOCK(ap_state_mtx);
597  ap_state->commands[COMMAND_THROTTLE] = v_ctl_throttle_slewed;
598  ap_state->commands[COMMAND_ROLL] = -h_ctl_aileron_setpoint;
599  ap_state->commands[COMMAND_PITCH] = h_ctl_elevator_setpoint;
600 #if H_CTL_YAW_LOOP && defined COMMAND_YAW
601  ap_state->commands[COMMAND_YAW] = h_ctl_rudder_setpoint;
602 #endif
603 #if H_CTL_CL_LOOP && defined COMMAND_CL
604  ap_state->commands[COMMAND_CL] = h_ctl_flaps_setpoint;
605 #endif
606  PPRZ_MUTEX_UNLOCK(ap_state_mtx);
607 
608 #if defined MCU_SPI_LINK || defined MCU_UART_LINK || defined MCU_CAN_LINK
609  link_mcu_send();
610 #elif defined INTER_MCU && defined SINGLE_MCU
611 
612  inter_mcu_received_ap = true;
613 #endif
614 
615 }
616 
617 
619 void sensors_task(void)
620 {
621  //FIXME: this is just a kludge
622 #if USE_AHRS && defined SITL && !USE_NPS
624 #endif
625 }
626 
627 #ifdef LOW_BATTERY_KILL_DELAY
628 #warning LOW_BATTERY_KILL_DELAY has been renamed to CATASTROPHIC_BAT_KILL_DELAY, please update your airframe file!
629 #endif
630 
632 #ifndef CATASTROPHIC_BAT_KILL_DELAY
633 #define CATASTROPHIC_BAT_KILL_DELAY 5
634 #endif
635 
637 #ifndef KILL_MODE_DISTANCE
638 #define KILL_MODE_DISTANCE (1.5*MAX_DIST_FROM_HOME)
639 #endif
640 
642 #ifndef MIN_SPEED_FOR_TAKEOFF
643 #define MIN_SPEED_FOR_TAKEOFF 5.
644 #endif
645 
647 void monitor_task(void)
648 {
649  if (autopilot_flight_time) {
651  }
652 #if defined DATALINK || defined SITL
653  datalink_time++;
654 #endif
655 
656  static uint8_t t = 0;
657  if (vsupply < CATASTROPHIC_BAT_LEVEL * 10) {
658  t++;
659  } else {
660  t = 0;
661  }
664 
665  if (!autopilot_flight_time &&
668  launch = true; /* Not set in non auto launch */
669 #if DOWNLINK
670  uint16_t time_sec = sys_time.nb_sec;
671  DOWNLINK_SEND_TAKEOFF(DefaultChannel, DefaultDevice, &time_sec);
672 #endif
673  }
674 
675 }
676 
677 
678 /*********** EVENT ***********************************************************/
679 void event_task_ap(void)
680 {
681 
682 #ifndef SINGLE_MCU
683  /* for SINGLE_MCU done in main_fbw */
684  /* event functions for mcu peripherals: i2c, usb_serial.. */
685  mcu_event();
686 #endif /* SINGLE_MCU */
687 
688 #if USE_BARO_BOARD
689  BaroEvent();
690 #endif
691 
692  DatalinkEvent();
693 
694 
695 #if defined MCU_SPI_LINK || defined MCU_UART_LINK
697 #endif
698 
700  /* receive radio control task from fbw */
701  inter_mcu_received_fbw = false;
703  }
704 
705  modules_event_task();
706 
707 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
708  if (new_ins_attitude > 0) {
709  attitude_loop();
710  new_ins_attitude = 0;
711  }
712 #endif
713 
714 } /* event_task_ap() */
715 
#define COMMAND_PITCH_TRIM
Definition: main_ap.c:100
void monitor_task(void)
monitor stuff run at 1Hz
Definition: main_ap.c:647
Event structure to store callbacks in a linked list.
Definition: abi_common.h:65
Interface to align the AHRS via low-passed measurements at startup.
unsigned short uint16_t
Definition: types.h:16
angular rates
void h_ctl_course_loop(void)
uint16_t vsupply
Supply voltage in deciVolt.
Definition: autopilot.c:52
tid_t monitor_tid
id for monitor_task() timer
Definition: main_ap.c:155
tid_t modules_tid
id for modules_periodic_task() timer
Definition: main_ap.c:150
Communication between fbw and ap processes.
Dispatcher to register actual AHRS implementations.
static float stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
Definition: state.h:923
Common barometric sensor implementation.
void h_ctl_attitude_loop(void)
#define AHRS_PROPAGATE_FREQUENCY
Definition: hf_float.c:51
#define RADIO_ROLL
Definition: spektrum_arch.h:43
void autopilot_init(void)
Autopilot inititalization.
Definition: autopilot.c:175
tid_t telemetry_tid
id for telemetry_periodic() timer
Definition: main_ap.c:151
static uint8_t mcu1_status_update(void)
Definition: main_ap.c:346
#define RADIO_YAW
Definition: spektrum_arch.h:45
Variable setting though the radio control.
pprz_t v_ctl_throttle_setpoint
Definition: energy_ctrl.c:131
Periodic telemetry system header (includes downlink utility and generated code).
bool gps_lost
Definition: autopilot.c:56
void navigation_task(void)
Compute desired_course.
Definition: main_ap.c:490
uint16_t autopilot_flight_time
flight time in seconds.
Definition: autopilot.c:48
AP ( AutoPilot ) process API.
void h_ctl_init(void)
static void audio_telemetry_init(void)
uint8_t pprz_mode
Definition: autopilot.c:41
uint8_t lateral_mode
Definition: autopilot.c:50
void callTCAS(void)
Definition: tcas.c:65
tid_t attitude_tid
id for attitude_loop() timer
Definition: main_ap.c:153
static void telecommand_task(void)
Function to be called when a message from FBW is available.
Definition: main_ap.c:381
Main include for ABI (AirBorneInterface).
#define PPRZ_MUTEX_LOCK(_mtx)
Definition: pprz_mutex.h:46
bool launch
Definition: sim_ap.c:38
tid_t sensors_tid
id for sensors_task() timer
Definition: main_ap.c:152
#define COMMAND_ROLL_TRIM
Definition: main_ap.c:96
void baro_init(void)
Definition: baro_board.c:76
volatile bool inter_mcu_received_ap
Definition: inter_mcu.c:41
#define V_CTL_MODE_AUTO_THROTTLE
#define PPRZ_MODE_AUTO2
Definition: autopilot.h:52
#define RC_LOST_MODE
mode to enter when RC is lost in PPRZ_MODE_MANUAL or PPRZ_MODE_AUTO1
Definition: main_ap.c:375
pprz_t h_ctl_elevator_setpoint
pprz_t h_ctl_aileron_setpoint
struct Imu imu
global IMU state
Definition: imu.c:108
void v_ctl_throttle_slew(void)
Computes slewed throttle from throttle setpoint called at 20Hz.
Definition: energy_ctrl.c:450
void v_ctl_climb_loop(void)
Auto-throttle inner loop.
Definition: energy_ctrl.c:334
static uint8_t pprz_mode_update(void)
Update paparazzi mode.
Definition: main_ap.c:308
#define mcu_int_enable()
Definition: mcu_arch.h:38
static uint8_t mcu1_ppm_cpt
Definition: main_ap.c:146
void ahrs_init(void)
AHRS initialization.
Definition: ahrs.c:68
struct fbw_state * fbw_state
Definition: inter_mcu.c:36
int32_t current
Supply current in milliAmpere.
Definition: autopilot.c:53
void init_ap(void)
Definition: main_ap.c:174
#define BARO_BOARD
Definition: baro_board.h:33
float v_ctl_pitch_setpoint
Definition: energy_ctrl.c:133
struct ap_state * ap_state
Definition: inter_mcu.c:37
void baro_periodic(void)
Definition: baro_board.c:90
static void send_autopilot_version(struct transport_tx *trans, struct link_device *dev)
Fixed wing horizontal control.
bool kill_throttle
Definition: autopilot.c:42
void settings_init(void)
Definition: settings.c:43
void stateInit(void)
Definition: state.c:43
bool h_ctl_auto1_rate
void common_nav_periodic_task_4Hz()
Definition: common_nav.c:124
#define TRIM_UPPRZ(pprz)
Definition: paparazzi.h:14
#define V_CTL_MODE_AUTO_ALT
#define THROTTLE_THRESHOLD_TAKEOFF
Definition: autopilot.h:84
void rc_settings(bool mode_changed)
Includes generated code from tuning_rc.xml.
Definition: rc_settings.c:49
Architecture independent timing functions.
static void copy_from_to_fbw(void)
Send back uncontrolled channels.
Definition: main_ap.c:360
#define RADIO_PITCH
Definition: spektrum_arch.h:44
#define PPRZ_MODE_HOME
Definition: autopilot.h:53
Device independent GPS code (interface)
#define COMMAND_YAW_TRIM
Definition: main_ap.c:104
unsigned long uint32_t
Definition: types.h:18
#define BaroEvent
Definition: baro_board.h:36
void event_task_ap(void)
Definition: main_ap.c:679
void update_ahrs_from_sim(void)
Definition: ahrs_sim.c:52
int8_t tid_t
sys_time timer id type
Definition: sys_time.h:60
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
#define PPRZ_MODE_AUTO1
Definition: autopilot.h:51
#define RADIO_THROTTLE
Definition: spektrum_arch.h:42
#define CATASTROPHIC_BAT_KILL_DELAY
Maximum time allowed for catastrophic battery level before going into kill mode.
Definition: main_ap.c:633
void reporting_task(void)
Send a series of initialisation messages followed by a stream of periodic ones.
Definition: main_ap.c:462
uint8_t v_ctl_mode
Definition: energy_ctrl.c:74
Inertial Measurement Unit interface.
#define V_CTL_MODE_AUTO_CLIMB
struct OrientationReps body_to_imu
rotation from body to imu frame
Definition: imu.h:49
#define IO0SET
Definition: LPC21xx.h:334
#define IO0DIR
Definition: LPC21xx.h:335
uint16_t datalink_time
Definition: sim_ap.c:42
void v_ctl_landing_loop(void)
Definition: guidance_v.c:318
void autopilot_send_mode(void)
Send mode over telemetry.
Definition: autopilot.c:167
volatile bool inter_mcu_received_fbw
Definition: inter_mcu.c:40
#define RADIO_MODE
Definition: spektrum_arch.h:59
#define ModeUpdate(_mode, _value)
Assignment, returning _old_value != _value Using GCC expression statements.
Definition: autopilot.h:107
Arch independent mcu ( Micro Controller Unit ) utilities.
float energy
Energy consumption (mAh) This is the ap copy of the measurement from fbw.
Definition: autopilot.c:54
float h_ctl_pitch_setpoint
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
volatile uint8_t new_ins_attitude
Persistent settings interface.
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:114
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
float h_ctl_roll_setpoint
uint8_t mcu1_status
Definition: autopilot.c:43
#define TELEMETRY_FREQUENCY
Definition: main_ap.c:119
#define FLOAT_OF_PPRZ(pprz, center, travel)
Definition: autopilot.h:82
#define LED_PERIODIC()
Definition: led_hw.h:52
arch independent LED (Light Emitting Diodes) API
#define ABI_BROADCAST
Broadcast address.
Definition: abi_common.h:56
#define MIN_SPEED_FOR_TAKEOFF
Default minimal speed for takeoff in m/s.
Definition: main_ap.c:643
void v_ctl_init(void)
Definition: energy_ctrl.c:216
#define NAVIGATION_FREQUENCY
Definition: autopilot.h:145
void mcu_event(void)
MCU event functions.
Definition: mcu.c:217
#define CONTROL_FREQUENCY
Definition: autopilot.h:140
#define MAX_PPRZ
Definition: paparazzi.h:8
#define UNLOCKED_HOME_MODE
Definition: autopilot.c:151
#define PPRZ_MODE_OF_PULSE(pprz)
Definition: autopilot.h:57
#define PPRZ_MODE_MANUAL
AP modes.
Definition: autopilot.h:50
tid_t navigation_tid
id for navigation_task() timer
Definition: main_ap.c:154
#define KILL_MODE_DISTANCE
Maximum distance from HOME waypoint before going into kill mode.
Definition: main_ap.c:638
#define LATERAL_MODE_COURSE
Definition: autopilot.h:77
#define BARO_PERIODIC_FREQUENCY
Definition: main.c:104
void ahrs_aligner_init(void)
Definition: ahrs_aligner.c:79
#define TRIM_PPRZ(pprz)
Definition: paparazzi.h:11
pprz_t v_ctl_throttle_slewed
Definition: energy_ctrl.c:132
#define PPRZ_MUTEX_UNLOCK(_mtx)
Definition: pprz_mutex.h:47
#define THRESHOLD2
Definition: autopilot.h:46
#define PPRZ_MODE_GPS_OUT_OF_ORDER
Definition: autopilot.h:54
void attitude_loop(void)
Definition: main_ap.c:554
#define V_CTL_MODE_LANDING
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:43
static struct FloatQuat * orientationGetQuat_f(struct OrientationReps *orientation)
Get vehicle body attitude quaternion (float).
void sensors_task(void)
Run at PERIODIC_FREQUENCY (60Hz if not defined)
Definition: main_ap.c:619
void handle_periodic_tasks_ap(void)
Definition: main_ap.c:264
void v_ctl_altitude_loop(void)
outer loop
Definition: energy_ctrl.c:296
Fixedwing autopilot modes.