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
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 #include <math.h>
34 
36 #include "mcu.h"
37 #include "mcu_periph/sys_time.h"
38 
39 #include "link_mcu_spi.h"
40 
41 // Sensors
42 #if USE_GPS
43 #include "subsystems/gps.h"
44 #endif
45 #if USE_IMU
46 #include "subsystems/imu.h"
47 #endif
48 #if USE_AHRS
49 #include "subsystems/ahrs.h"
50 #endif
51 #if USE_AHRS_ALIGNER
53 #endif
54 #if USE_BAROMETER
56 #endif
57 #include "subsystems/ins.h"
58 
59 
60 // autopilot & control
61 #include "state.h"
64 #include CTRL_TYPE_H
65 #include "subsystems/nav.h"
66 #include "generated/flight_plan.h"
67 #ifdef TRAFFIC_INFO
69 #endif
70 
71 // datalink & telemetry
73 #include "subsystems/settings.h"
77 
78 // modules & settings
79 #include "generated/modules.h"
80 #include "generated/settings.h"
81 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
82 #include "rc_settings.h"
83 #endif
84 
85 #include "led.h"
86 
87 /* Default trim commands for roll, pitch and yaw */
88 #ifndef COMMAND_ROLL_TRIM
89 #define COMMAND_ROLL_TRIM 0
90 #endif
91 
92 #ifndef COMMAND_PITCH_TRIM
93 #define COMMAND_PITCH_TRIM 0
94 #endif
95 
96 #ifndef COMMAND_YAW_TRIM
97 #define COMMAND_YAW_TRIM 0
98 #endif
99 
100 /* if PRINT_CONFIG is defined, print some config options */
101 PRINT_CONFIG_VAR(PERIODIC_FREQUENCY)
102 PRINT_CONFIG_VAR(NAVIGATION_FREQUENCY)
103 PRINT_CONFIG_VAR(CONTROL_FREQUENCY)
104 
105 #ifndef TELEMETRY_FREQUENCY
106 #define TELEMETRY_FREQUENCY 60
107 #endif
108 PRINT_CONFIG_VAR(TELEMETRY_FREQUENCY)
109 
110 #ifndef MODULES_FREQUENCY
111 #define MODULES_FREQUENCY 60
112 #endif
113 PRINT_CONFIG_VAR(MODULES_FREQUENCY)
114 
115 
116 #if USE_AHRS && USE_IMU
117 
118 #ifndef AHRS_PROPAGATE_FREQUENCY
119 #define AHRS_PROPAGATE_FREQUENCY PERIODIC_FREQUENCY
120 #endif
121 PRINT_CONFIG_VAR(AHRS_PROPAGATE_FREQUENCY)
122 #ifndef AHRS_CORRECT_FREQUENCY
123 #define AHRS_CORRECT_FREQUENCY PERIODIC_FREQUENCY
124 #endif
125 PRINT_CONFIG_VAR(AHRS_CORRECT_FREQUENCY)
126 
127 static inline void on_gyro_event( void );
128 static inline void on_accel_event( void );
129 static inline void on_mag_event( void );
131 
132 #endif // USE_AHRS && USE_IMU
133 
134 #if USE_GPS
135 static inline void on_gps_solution( void );
136 #endif
137 
138 #if USE_BAROMETER
139 static inline void on_baro_abs_event( void );
140 static inline void on_baro_dif_event( void );
141 #endif
142 
143 // what version is this ????
144 static const uint16_t version = 1;
145 
147 
148 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
150 #endif
151 
155 static int32_t current; // milliAmpere
156 
157 
164 
165 
166 void init_ap( void ) {
167 #ifndef SINGLE_MCU
168  mcu_init();
169 #endif /* SINGLE_MCU */
170 
171  /****** initialize and reset state interface ********/
172 
173  stateInit();
174 
175  /************* Sensors initialization ***************/
176 #if USE_GPS
177  gps_init();
178 #endif
179 
180 #if USE_IMU
181  imu_init();
182 #endif
183 
184 #if USE_AHRS_ALIGNER
186 #endif
187 
188 #if USE_AHRS
189  ahrs_init();
190 #endif
191 
192 #if USE_BAROMETER
193  baro_init();
194 #endif
195 
196  ins_init();
197 
198  /************* Links initialization ***************/
199 #if defined MCU_SPI_LINK || defined MCU_UART_LINK
200  link_mcu_init();
201 #endif
202 #if USE_AUDIO_TELEMETRY
204 #endif
205 
206  /************ Internal status ***************/
207  autopilot_init();
208  h_ctl_init();
209  v_ctl_init();
210  nav_init();
211 
212  modules_init();
213 
214  settings_init();
215 
216  /**** start timers for periodic functions *****/
217  sensors_tid = sys_time_register_timer(1./PERIODIC_FREQUENCY, NULL);
218  navigation_tid = sys_time_register_timer(1./NAVIGATION_FREQUENCY, NULL);
219  attitude_tid = sys_time_register_timer(1./CONTROL_FREQUENCY, NULL);
220  modules_tid = sys_time_register_timer(1./MODULES_FREQUENCY, NULL);
221  telemetry_tid = sys_time_register_timer(1./TELEMETRY_FREQUENCY, NULL);
222  monitor_tid = sys_time_register_timer(1.0, NULL);
223 
225  mcu_int_enable();
226 
227 #if defined DATALINK
228 #if DATALINK == XBEE
229  xbee_init();
230 #endif
231 #if DATALINK == W5100
232  w5100_init();
233 #endif
234 #endif /* DATALINK */
235 
236 #if defined AEROCOMM_DATA_PIN
237  IO0DIR |= _BV(AEROCOMM_DATA_PIN);
238  IO0SET = _BV(AEROCOMM_DATA_PIN);
239 #endif
240 
241  /************ Multi-uavs status ***************/
242 
243 #ifdef TRAFFIC_INFO
245 #endif
246 
247  /* set initial trim values.
248  * these are passed to fbw via inter_mcu.
249  */
250  ap_state->command_roll_trim = COMMAND_ROLL_TRIM;
251  ap_state->command_pitch_trim = COMMAND_PITCH_TRIM;
252  ap_state->command_yaw_trim = COMMAND_YAW_TRIM;
253 }
254 
255 
257 
258  if (sys_time_check_and_ack_timer(sensors_tid))
259  sensors_task();
260 
261  if (sys_time_check_and_ack_timer(navigation_tid))
262  navigation_task();
263 
264 #ifndef AHRS_TRIGGERED_ATTITUDE_LOOP
265  if (sys_time_check_and_ack_timer(attitude_tid))
266  attitude_loop();
267 #endif
268 
269  if (sys_time_check_and_ack_timer(modules_tid))
270  modules_periodic_task();
271 
272  if (sys_time_check_and_ack_timer(monitor_tid))
273  monitor_task();
274 
275  if (sys_time_check_and_ack_timer(telemetry_tid)) {
276  reporting_task();
277  LED_PERIODIC();
278  }
279 
280 }
281 
282 
283 /******************** Interaction with FBW *****************************/
284 
287 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
288 static inline uint8_t pprz_mode_update( void ) {
289  if ((pprz_mode != PPRZ_MODE_HOME &&
291 #ifdef UNLOCKED_HOME_MODE
292  || TRUE
293 #endif
294  ) {
295 #ifndef RADIO_AUTO_MODE
297 #else
298  INFO("Using RADIO_AUTO_MODE to switch between AUTO1 and AUTO2.")
299  /* If RADIO_AUTO_MODE is enabled mode swithing will be seperated between two switches/channels
300  * RADIO_MODE will switch between PPRZ_MODE_MANUAL and any PPRZ_MODE_AUTO mode selected by RADIO_AUTO_MODE.
301  *
302  * This is mainly a cludge for entry level radios with no three-way switch but two available two-way switches which can be used.
303  */
305  /* RADIO_MODE in MANUAL position */
307  } else {
308  /* RADIO_MODE not in MANUAL position.
309  * Select AUTO mode bassed on RADIO_AUTO_MODE channel
310  */
311  return ModeUpdate(pprz_mode, (fbw_state->channels[RADIO_AUTO_MODE] > THRESHOLD2) ? PPRZ_MODE_AUTO2 : PPRZ_MODE_AUTO1);
312  }
313 #endif // RADIO_AUTO_MODE
314  } else
315  return FALSE;
316 }
317 #else // not RADIO_CONTROL
318 static inline uint8_t pprz_mode_update( void ) {
319  return FALSE;
320 }
321 #endif
322 
323 static inline uint8_t mcu1_status_update( void ) {
324  uint8_t new_status = fbw_state->status;
325  if (mcu1_status != new_status) {
326  bool_t changed = ((mcu1_status&MASK_FBW_CHANGED) != (new_status&MASK_FBW_CHANGED));
327  mcu1_status = new_status;
328  return changed;
329  }
330  return FALSE;
331 }
332 
333 
336 static inline void copy_from_to_fbw ( void ) {
337 #ifdef SetAutoCommandsFromRC
338  SetAutoCommandsFromRC(ap_state->commands, fbw_state->channels);
339 #elif defined RADIO_YAW && defined COMMAND_YAW
340  ap_state->commands[COMMAND_YAW] = fbw_state->channels[RADIO_YAW];
341 #endif
342 }
343 
345 #ifndef RC_LOST_MODE
346 #define RC_LOST_MODE PPRZ_MODE_HOME
347 #endif
348 
352 static inline void telecommand_task( void ) {
353  uint8_t mode_changed = FALSE;
355 
356  uint8_t really_lost = bit_is_set(fbw_state->status, STATUS_RADIO_REALLY_LOST) && (pprz_mode == PPRZ_MODE_AUTO1 || pprz_mode == PPRZ_MODE_MANUAL);
358  if (too_far_from_home) {
360  mode_changed = TRUE;
361  }
362  if (really_lost) {
364  mode_changed = TRUE;
365  }
366  }
367  if (bit_is_set(fbw_state->status, AVERAGED_CHANNELS_SENT)) {
368  bool_t pprz_mode_changed = pprz_mode_update();
369  mode_changed |= pprz_mode_changed;
370 #if defined RADIO_CALIB && defined RADIO_CONTROL_SETTINGS
371  bool_t calib_mode_changed = RcSettingsModeUpdate(fbw_state->channels);
372  rc_settings(calib_mode_changed || pprz_mode_changed);
373  mode_changed |= calib_mode_changed;
374 #endif
375  }
376  mode_changed |= mcu1_status_update();
377  if ( mode_changed )
379 
380 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
381 
384  if (pprz_mode == PPRZ_MODE_AUTO1) {
386  h_ctl_roll_setpoint = FLOAT_OF_PPRZ(fbw_state->channels[RADIO_ROLL], 0., AUTO1_MAX_ROLL);
387 
389  h_ctl_pitch_setpoint = FLOAT_OF_PPRZ(fbw_state->channels[RADIO_PITCH], 0., AUTO1_MAX_PITCH);
390  }
396  }
399  mcu1_ppm_cpt = fbw_state->ppm_cpt;
400 #endif // RADIO_CONTROL
401 
402 
403  vsupply = fbw_state->vsupply;
404  current = fbw_state->current;
405 
406 #ifdef RADIO_CONTROL
407  if (!autopilot_flight_time) {
409  launch = TRUE;
410  }
411  }
412 #endif
413 }
414 
415 
416 /**************************** Periodic tasks ***********************************/
417 
422 void reporting_task( void ) {
423  static uint8_t boot = TRUE;
424 
426  if (boot) {
427  DOWNLINK_SEND_BOOT(DefaultChannel, DefaultDevice, &version);
428  boot = FALSE;
429  }
431  else {
432  PeriodicSendAp(DefaultChannel, DefaultDevice);
433  }
434 }
435 
436 
437 #ifdef FAILSAFE_DELAY_WITHOUT_GPS
438 #define GpsTimeoutError (sys_time.nb_sec - gps.last_fix_time > FAILSAFE_DELAY_WITHOUT_GPS)
439 #endif
440 
444 void navigation_task( void ) {
445 #if defined FAILSAFE_DELAY_WITHOUT_GPS
446 
447  static uint8_t last_pprz_mode;
448 
451  if (launch) {
452  if (GpsTimeoutError) {
454  last_pprz_mode = pprz_mode;
457  gps_lost = TRUE;
458  }
459  } else if (gps_lost) { /* GPS is ok */
461  pprz_mode = last_pprz_mode;
462  gps_lost = FALSE;
463 
465  }
466  }
467 #endif /* GPS && FAILSAFE_DELAY_WITHOUT_GPS */
468 
470  if (pprz_mode == PPRZ_MODE_HOME)
471  nav_home();
473  nav_without_gps();
474  else
476 
477 #ifdef TCAS
478  CallTCAS();
479 #endif
480 
481 #ifndef PERIOD_NAVIGATION_0 // If not sent periodically (in default 0 mode)
483 #endif
484 
486 
487  /* The nav task computes only nav_altitude. However, we are interested
488  by desired_altitude (= nav_alt+alt_shift) in any case.
489  So we always run the altitude control loop */
492 
495 #ifdef H_CTL_RATE_LOOP
496  /* Be sure to be in attitude mode, not roll */
498 #endif
500  h_ctl_course_loop(); /* aka compute nav_desired_roll */
501 
502  // climb_loop(); //4Hz
503  }
504  energy += ((float)current) / 3600.0f * 0.25f; // mAh = mA * dt (4Hz -> hours)
505 }
506 
507 
508 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
509 volatile uint8_t new_ins_attitude = 0;
510 #endif
511 
512 void attitude_loop( void ) {
513 
514 #if USE_INFRARED
516 #endif /* USE_INFRARED */
517 
518  if (pprz_mode >= PPRZ_MODE_AUTO2)
519  {
523  }
524  else if (v_ctl_mode >= V_CTL_MODE_AUTO_CLIMB)
525  {
527  }
528 
529 #if defined V_CTL_THROTTLE_IDLE
530  Bound(v_ctl_throttle_setpoint, TRIM_PPRZ(V_CTL_THROTTLE_IDLE*MAX_PPRZ), MAX_PPRZ);
531 #endif
532 
533 #ifdef V_CTL_POWER_CTL_BAT_NOMINAL
534  if (vsupply > 0.) {
535  v_ctl_throttle_setpoint *= 10. * V_CTL_POWER_CTL_BAT_NOMINAL / (float)vsupply;
537  }
538 #endif
539 
540  h_ctl_pitch_setpoint = v_ctl_pitch_setpoint; // Copy the pitch setpoint from the guidance to the stabilization control
541  Bound(h_ctl_pitch_setpoint, H_CTL_PITCH_MIN_SETPOINT, H_CTL_PITCH_MAX_SETPOINT);
544  }
545 
546  h_ctl_attitude_loop(); /* Set h_ctl_aileron_setpoint & h_ctl_elevator_setpoint */
548  ap_state->commands[COMMAND_THROTTLE] = v_ctl_throttle_slewed;
549  ap_state->commands[COMMAND_ROLL] = -h_ctl_aileron_setpoint;
550 
551  ap_state->commands[COMMAND_PITCH] = h_ctl_elevator_setpoint;
552 
553 #if defined MCU_SPI_LINK || defined MCU_UART_LINK
554  link_mcu_send();
555 #elif defined INTER_MCU && defined SINGLE_MCU
556 
558 #endif
559 
560 }
561 
562 
564 void sensors_task( void ) {
565 #if USE_IMU
566  imu_periodic();
567 
568 #if USE_AHRS
569  if (ahrs_timeout_counter < 255)
570  ahrs_timeout_counter ++;
571 #endif // USE_AHRS
572 #endif // USE_IMU
573 
574  //FIXME: this is just a kludge
575 #if USE_AHRS && defined SITL
576  ahrs_propagate();
577 #endif
578 
579 #if USE_BAROMETER
580  baro_periodic();
581 #endif
582 
583  ins_periodic();
584 }
585 
586 
587 
588 
590 #define LOW_BATTERY_DELAY 5
591 
593 #ifndef KILL_MODE_DISTANCE
594 #define KILL_MODE_DISTANCE (1.5*MAX_DIST_FROM_HOME)
595 #endif
596 
598 #define MIN_SPEED_FOR_TAKEOFF 5.
599 
601 void monitor_task( void ) {
604 #if defined DATALINK || defined SITL
605  datalink_time++;
606 #endif
607 
608  static uint8_t t = 0;
609  if (vsupply < CATASTROPHIC_BAT_LEVEL*10)
610  t++;
611  else
612  t = 0;
615 
616  if (!autopilot_flight_time &&
619  launch = TRUE; /* Not set in non auto launch */
620  uint16_t time_sec = sys_time.nb_sec;
621  DOWNLINK_SEND_TAKEOFF(DefaultChannel, DefaultDevice, &time_sec);
622  }
623 
624 }
625 
626 
627 /*********** EVENT ***********************************************************/
628 void event_task_ap( void ) {
629 
630 #ifndef SINGLE_MCU
631 #if defined USE_I2C0 || defined USE_I2C1 || defined USE_I2C2
632  i2c_event();
633 #endif
634 #endif
635 
636 #if USE_AHRS && USE_IMU
638 #endif
639 
640 #ifdef InsEvent
641  TODO("calling InsEvent, remove me..")
642  InsEvent(NULL);
643 #endif
644 
645 #if USE_GPS
647 #endif /* USE_GPS */
648 
649 #if USE_BAROMETER
651 #endif
652 
653  DatalinkEvent();
654 
655 
656 #if defined MCU_SPI_LINK || defined MCU_UART_LINK
658 #endif
659 
661  /* receive radio control task from fbw */
664  }
665 
666  modules_event_task();
667 
668 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
669  if (new_ins_attitude > 0)
670  {
671  attitude_loop();
672  //LED_TOGGLE(3);
673  new_ins_attitude = 0;
674  }
675 #endif
676 
677 } /* event_task_ap() */
678 
679 
680 #if USE_GPS
681 static inline void on_gps_solution( void ) {
682  ins_update_gps();
683 #if USE_AHRS
684  ahrs_update_gps();
685 #endif
686 #ifdef GPS_TRIGGERED_FUNCTION
687  GPS_TRIGGERED_FUNCTION();
688 #endif
689 }
690 #endif
691 
692 
693 #if USE_AHRS
694 #if USE_IMU
695 static inline void on_accel_event( void ) {
696 }
697 
698 static inline void on_gyro_event( void ) {
699 
700  ahrs_timeout_counter = 0;
701 
702 #if USE_AHRS_ALIGNER
703  // Run aligner on raw data as it also makes averages.
704  if (ahrs.status == AHRS_UNINIT) {
705  ImuScaleGyro(imu);
709  ahrs_align();
710  return;
711  }
712 #endif
713 
714 #if PERIODIC_FREQUENCY == 60
715  ImuScaleGyro(imu);
717 
718  ahrs_propagate();
720 
721 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
722  new_ins_attitude = 1;
723 #endif
724 
725 #else //PERIODIC_FREQUENCY
726  static uint8_t _reduced_propagation_rate = 0;
727  static uint8_t _reduced_correction_rate = 0;
728  static struct Int32Vect3 acc_avg;
729  static struct Int32Rates gyr_avg;
730 
731  RATES_ADD(gyr_avg, imu.gyro_unscaled);
732  VECT3_ADD(acc_avg, imu.accel_unscaled);
733 
734  _reduced_propagation_rate++;
735  if (_reduced_propagation_rate < (PERIODIC_FREQUENCY / AHRS_PROPAGATE_FREQUENCY))
736  {
737  }
738  else
739  {
740  _reduced_propagation_rate = 0;
741 
743  INT_RATES_ZERO(gyr_avg);
744 
745  ImuScaleGyro(imu);
746 
747  ahrs_propagate();
748 
749  _reduced_correction_rate++;
750  if (_reduced_correction_rate >= (AHRS_PROPAGATE_FREQUENCY / AHRS_CORRECT_FREQUENCY))
751  {
752  _reduced_correction_rate = 0;
754  INT_VECT3_ZERO(acc_avg);
757  }
758 
759 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
760  new_ins_attitude = 1;
761 #endif
762  }
763 #endif //PERIODIC_FREQUENCY
764 
765 }
766 
767 static inline void on_mag_event(void)
768 {
769 #if USE_MAGNETOMETER
770  ImuScaleMag(imu);
771  if (ahrs.status == AHRS_RUNNING) {
772  ahrs_update_mag();
773  }
774 #endif
775 }
776 
777 #endif // USE_IMU
778 
779 #endif // USE_AHRS
780 
781 #if USE_BAROMETER
782 
783 static inline void on_baro_abs_event( void ) {
784  ins_update_baro();
785 }
786 
787 static inline void on_baro_dif_event( void ) {
788 
789 }
790 
791 #endif // USE_BAROMETER
#define COMMAND_PITCH_TRIM
Definition: main_ap.c:93
void monitor_task(void)
monitor stuff run at 1Hz
Definition: main_ap.c:601
Interface to align the AHRS via low-passed measurements at startup.
unsigned short uint16_t
Definition: types.h:16
void h_ctl_course_loop(void)
static int32_t current
Supply current in milliAmpere.
Definition: main_ap.c:155
uint16_t vsupply
Supply voltage in deciVolt.
Definition: autopilot.c:41
tid_t monitor_tid
id for monitor_task() timer
Definition: main_ap.c:163
tid_t modules_tid
id for modules_periodic_task() timer
Definition: main_ap.c:158
bool_t launch
Definition: sim_ap.c:40
Attitude and Heading Reference System interface.
void traffic_info_init(void)
Definition: traffic_info.c:37
static void on_accel_event(void)
Definition: main_ap.c:695
Common barometric sensor implementation.
void h_ctl_attitude_loop(void)
void autopilot_init(void)
Autopilot inititalization.
Definition: autopilot.c:48
void ins_update_gps(void)
Update INS state with GPS measurements.
tid_t telemetry_tid
id for telemetry_periodic() timer
Definition: main_ap.c:159
static uint8_t mcu1_status_update(void)
Definition: main_ap.c:323
Variable setting though the radio control.
pprz_t v_ctl_throttle_setpoint
Definition: energy_ctrl.c:134
void navigation_task(void)
Compute desired_course.
Definition: main_ap.c:444
#define BaroEvent(_b_abs_handler, _b_diff_handler)
Definition: baro_board.h:55
uint16_t autopilot_flight_time
flight time in seconds.
Definition: autopilot.c:37
void ahrs_propagate(void)
Propagation.
volatile bool_t inter_mcu_received_ap
Definition: inter_mcu.c:37
AP ( AutoPilot ) process API.
void h_ctl_init(void)
static void audio_telemetry_init(void)
uint8_t pprz_mode
Definition: autopilot.c:31
static void on_gyro_event(void)
Definition: main_ap.c:698
uint8_t lateral_mode
Definition: autopilot.c:39
void w5100_init(void)
Definition: w5100.c:155
tid_t attitude_tid
id for attitude_loop() timer
Definition: main_ap.c:161
#define GpsEvent(_sol_available_callback)
Definition: gps_ardrone2.h:39
static float * stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
Definition: state.h:854
struct Ahrs ahrs
global AHRS state
Definition: ahrs.c:30
static void telecommand_task(void)
Function to be called when a message from FBW is available.
Definition: main_ap.c:352
volatile bool_t inter_mcu_received_fbw
Definition: inter_mcu.c:36
uint8_t tid_t
sys_time timer id type
Definition: sys_time.h:57
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:48
#define ImuScaleMag(_imu)
Definition: ahrs_gx3.h:64
void ahrs_update_gps(void)
Update AHRS state with GPS measurements.
void imu_periodic(void)
Definition: imu_apogee.c:79
#define INT_RATES_ZERO(_e)
Integrated Navigation System interface.
tid_t sensors_tid
id for sensors_task() timer
Definition: main_ap.c:160
#define COMMAND_ROLL_TRIM
Definition: main_ap.c:89
void baro_init(void)
Definition: baro_board.c:42
#define V_CTL_MODE_AUTO_THROTTLE
#define PPRZ_MODE_AUTO2
Definition: autopilot.h:53
uint8_t status
Definition: ahrs_aligner.h:45
#define RC_LOST_MODE
mode to enter when RC is lost in PPRZ_MODE_MANUAL or PPRZ_MODE_AUTO1
Definition: main_ap.c:346
pprz_t h_ctl_elevator_setpoint
pprz_t h_ctl_aileron_setpoint
void v_ctl_throttle_slew(void)
Computes slewed throttle from throttle setpoint called at 20Hz.
Definition: energy_ctrl.c:416
float dist2_to_home
Definition: common_nav.c:32
void v_ctl_climb_loop(void)
auto throttle inner loop
Definition: energy_ctrl.c:303
void imu_init(void)
Definition: ins_xsens700.c:86
static uint8_t pprz_mode_update(void)
Update paparazzi mode.
Definition: main_ap.c:288
static uint8_t mcu1_ppm_cpt
Definition: main_ap.c:149
struct fbw_state * fbw_state
Definition: inter_mcu.c:32
void init_ap(void)
Definition: main_ap.c:166
float v_ctl_pitch_setpoint
Definition: energy_ctrl.c:136
#define FALSE
Definition: imu_chimu.h:141
#define RADIO_PITCH
Definition: spektrum_arch.h:40
struct ap_state * ap_state
Definition: inter_mcu.c:33
void baro_periodic(void)
Definition: baro_board.c:50
#define CallTCAS()
Definition: tcas.h:57
#define RATES_SDIV(_ro, _ri, _s)
Definition: pprz_algebra.h:350
Fixed wing horizontal control.
void settings_init(void)
Definition: settings.c:8
#define mcu_int_enable()
Definition: mcu_arch.h:37
void stateInit(void)
Definition: state.c:43
#define AHRS_PROPAGATE_FREQUENCY
Definition: main_ap.c:119
static void on_mag_event(void)
Definition: main_ap.c:767
void common_nav_periodic_task_4Hz()
Definition: common_nav.c:103
#define TRIM_UPPRZ(pprz)
Definition: paparazzi.h:14
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:49
bool_t gps_lost
Definition: autopilot.c:44
#define V_CTL_MODE_AUTO_ALT
#define THROTTLE_THRESHOLD_TAKEOFF
Definition: autopilot.h:84
struct AhrsAligner ahrs_aligner
Definition: ahrs_aligner.c:35
void ahrs_update_infrared(void)
Definition: ahrs_infrared.c:90
Architecture independent timing functions.
static void copy_from_to_fbw(void)
Send back uncontrolled channels.
Definition: main_ap.c:336
static const uint16_t version
Definition: main_ap.c:144
#define PPRZ_MODE_HOME
Definition: autopilot.h:54
Device independent GPS code (interface)
#define COMMAND_YAW_TRIM
Definition: main_ap.c:97
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:50
uint8_t status
status of the AHRS, AHRS_UNINIT or AHRS_RUNNING
Definition: ahrs.h:45
#define ImuScaleAccel(_imu)
Definition: ahrs_gx3.h:59
void event_task_ap(void)
Definition: main_ap.c:628
#define AHRS_ALIGNER_LOCKED
Definition: ahrs_aligner.h:37
bool_t kill_throttle
Definition: autopilot.c:32
#define PPRZ_MODE_AUTO1
Definition: autopilot.h:52
#define RATES_ADD(_a, _b)
Definition: pprz_algebra.h:308
#define INT_VECT3_ZERO(_v)
#define ImuEvent(_gyro_handler, _accel_handler, _mag_handler)
Definition: ins_xsens.h:63
void reporting_task(void)
Send a series of initialisation messages followed by a stream of periodic ones.
Definition: main_ap.c:422
uint8_t v_ctl_mode
Definition: energy_ctrl.c:77
Inertial Measurement Unit interface.
volatile uint8_t ahrs_timeout_counter
Definition: main_ap.c:130
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:37
angular rates
#define RADIO_YAW
Definition: spektrum_arch.h:41
#define V_CTL_MODE_AUTO_CLIMB
static bool_t sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:111
#define MODULES_FREQUENCY
Definition: main_ap.c:111
static void on_gps_solution(void)
Definition: main_ap.c:681
signed long int32_t
Definition: types.h:19
#define IO0SET
Definition: LPC21xx.h:334
#define AHRS_UNINIT
Definition: ahrs.h:35
#define TRUE
Definition: imu_chimu.h:144
#define IO0DIR
Definition: LPC21xx.h:335
uint16_t datalink_time
Definition: sim_ap.c:44
static void on_baro_abs_event(void)
Definition: main_ap.c:783
#define VECT3_ADD(_a, _b)
Definition: pprz_algebra.h:118
#define ModeUpdate(_mode, _value)
Assignment, returning _old_value != _value Using GCC expression statements.
Definition: autopilot.h:102
#define RADIO_MODE
Definition: spektrum_arch.h:61
#define RADIO_THROTTLE
Definition: spektrum_arch.h:38
#define LED_PERIODIC()
Definition: led_hw.h:8
Arch independent mcu ( Micro Controller Unit ) utilities.
float energy
Fuel consumption (mAh) TODO: move to electrical subsystem.
Definition: autopilot.c:42
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
static void on_baro_dif_event(void)
Definition: main_ap.c:787
void ins_update_baro()
Update INS state with barometer measurements.
Definition: ins_alt_float.c:87
float h_ctl_roll_setpoint
bool_t h_ctl_auto1_rate
bool_t too_far_from_home
Definition: common_nav.c:35
void ahrs_update_mag(void)
Update AHRS state with magnetometer measurements.
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
#define TELEMETRY_FREQUENCY
Definition: main_ap.c:106
void ahrs_update_accel(void)
Update AHRS state with accerleration measurements.
#define FLOAT_OF_PPRZ(pprz, center, travel)
Definition: autopilot.h:82
void ins_init(void)
INS initialization.
Definition: ins_xsens700.c:178
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
arch independent LED (Light Emitting Diodes) API
#define MIN_SPEED_FOR_TAKEOFF
Define minimal speed for takeoff in m/s.
Definition: main_ap.c:598
void v_ctl_init(void)
Definition: energy_ctrl.c:196
#define NAVIGATION_FREQUENCY
Definition: autopilot.h:135
#define LOW_BATTERY_DELAY
Maximum time allowed for low battery level before going into kill mode.
Definition: main_ap.c:590
#define CONTROL_FREQUENCY
Definition: autopilot.h:130
void i2c_event(void)
Definition: i2c_arch.c:364
#define MAX_PPRZ
Definition: paparazzi.h:8
#define RADIO_ROLL
Definition: spektrum_arch.h:39
void ins_periodic(void)
INS periodic call.
Definition: ins_alt_float.c:75
void rc_settings(bool_t mode_changed)
Includes generated code from tuning_rc.xml.
Definition: rc_settings.c:49
#define PPRZ_MODE_OF_PULSE(pprz)
Definition: autopilot.h:58
#define PPRZ_MODE_MANUAL
AP modes.
Definition: autopilot.h:51
tid_t navigation_tid
id for navigation_task() timer
Definition: main_ap.c:162
#define KILL_MODE_DISTANCE
Maximum distance from HOME waypoint before going into kill mode.
Definition: main_ap.c:594
#define LATERAL_MODE_COURSE
Definition: autopilot.h:77
#define VECT3_SDIV(_vo, _vi, _s)
Definition: pprz_algebra.h:167
#define AHRS_CORRECT_FREQUENCY
Definition: main_ap.c:123
static uint8_t mcu1_status
Definition: main_ap.c:146
void ahrs_aligner_init(void)
Definition: ahrs_aligner.c:45
#define TRIM_PPRZ(pprz)
Definition: paparazzi.h:11
pprz_t v_ctl_throttle_slewed
Definition: energy_ctrl.c:135
void ahrs_align(void)
Aligns the AHRS.
#define THRESHOLD2
Definition: autopilot.h:47
void ahrs_aligner_run(void)
Definition: ahrs_aligner.c:63
void xbee_init(void)
Definition: xbee.c:87
#define PPRZ_MODE_GPS_OUT_OF_ORDER
Definition: autopilot.h:55
void gps_init(void)
initialize the global GPS state
Definition: gps.c:37
void attitude_loop(void)
Definition: main_ap.c:512
#define ImuScaleGyro(_imu)
Definition: ahrs_gx3.h:54
#define AHRS_RUNNING
Definition: ahrs.h:36
Information relative to the other aircrafts.
void sensors_task(void)
Run at PERIODIC_FREQUENCY (60Hz if not defined)
Definition: main_ap.c:564
void handle_periodic_tasks_ap(void)
Definition: main_ap.c:256
void ahrs_init(void)
AHRS initialization.
void v_ctl_altitude_loop(void)
outer loop
Definition: energy_ctrl.c:268
Fixedwing autopilot modes.