Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
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 #define ABI_C
34 
35 #include <math.h>
36 
38 #include "mcu.h"
39 #include "mcu_periph/sys_time.h"
40 
41 #include "link_mcu_spi.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 #include "subsystems/air_data.h"
57 #if USE_BARO_BOARD
59 PRINT_CONFIG_MSG_VALUE("USE_BARO_BOARD is TRUE, reading onboard baro: ", BARO_BOARD)
60 #endif
61 #include "subsystems/ins.h"
62 
63 
64 // autopilot & control
65 #include "state.h"
68 #include CTRL_TYPE_H
70 #include "generated/flight_plan.h"
71 #ifdef TRAFFIC_INFO
73 #endif
74 
75 // datalink & telemetry
78 #include "subsystems/settings.h"
81 
82 // modules & settings
83 #include "generated/modules.h"
84 #include "generated/settings.h"
85 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
86 #include "rc_settings.h"
87 #endif
88 #include "subsystems/abi.h"
89 
90 #include "led.h"
91 
92 #ifdef USE_NPS
93 #include "nps_autopilot.h"
94 #endif
95 
96 /* Default trim commands for roll, pitch and yaw */
97 #ifndef COMMAND_ROLL_TRIM
98 #define COMMAND_ROLL_TRIM 0
99 #endif
100 
101 #ifndef COMMAND_PITCH_TRIM
102 #define COMMAND_PITCH_TRIM 0
103 #endif
104 
105 #ifndef COMMAND_YAW_TRIM
106 #define COMMAND_YAW_TRIM 0
107 #endif
108 
109 /* if PRINT_CONFIG is defined, print some config options */
113 
114 /* TELEMETRY_FREQUENCY is defined in generated/periodic_telemetry.h
115  * defaults to 60Hz or set by TELEMETRY_FREQUENCY configure option in airframe file
116  */
117 PRINT_CONFIG_VAR(TELEMETRY_FREQUENCY)
118 
119 /* MODULES_FREQUENCY is defined in generated/modules.h
120  * according to main_freq parameter set for modules in airframe file
121  */
122 PRINT_CONFIG_VAR(MODULES_FREQUENCY)
123 
124 #if USE_BARO_BOARD
125 #ifndef BARO_PERIODIC_FREQUENCY
126 #define BARO_PERIODIC_FREQUENCY 50
127 #endif
129 #endif
130 
131 #if USE_AHRS && USE_IMU
132 
133 #ifndef AHRS_PROPAGATE_FREQUENCY
134 #define AHRS_PROPAGATE_FREQUENCY PERIODIC_FREQUENCY
135 #endif
137 #ifndef AHRS_CORRECT_FREQUENCY
138 #define AHRS_CORRECT_FREQUENCY PERIODIC_FREQUENCY
139 #endif
141 
142 #if (AHRS_PROPAGATE_FREQUENCY > PERIODIC_FREQUENCY)
143 #warning "PERIODIC_FREQUENCY should be least equal or greater than AHRS_PROPAGATE_FREQUENCY"
144 INFO_VALUE("it is recommended to configure in your airframe PERIODIC_FREQUENCY to at least ",AHRS_PROPAGATE_FREQUENCY)
145 #endif
146 
147 static inline void on_gyro_event( void );
148 static inline void on_accel_event( void );
149 static inline void on_mag_event( void );
151 
152 //FIXME not the correct place
153 static void send_fliter_status(void) {
154  uint8_t mde = 3;
155  if (ahrs.status == AHRS_UNINIT) mde = 2;
156  if (ahrs_timeout_counter > 10) mde = 5;
157  uint16_t val = 0;
158  DOWNLINK_SEND_STATE_FILTER_STATUS(DefaultChannel, DefaultDevice, &mde, &val);
159 }
160 
161 #endif // USE_AHRS && USE_IMU
162 
163 #if USE_GPS
164 static inline void on_gps_solution( void );
165 #endif
166 
167 // what version is this ????
168 static const uint16_t version = 1;
169 
170 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
172 #endif
173 
174 
181 #if USE_BARO_BOARD
182 tid_t baro_tid;
183 #endif
184 
185 void init_ap( void ) {
186 #ifndef SINGLE_MCU
187  mcu_init();
188 #endif /* SINGLE_MCU */
189 
190  /****** initialize and reset state interface ********/
191 
192  stateInit();
193 
194  /************* Sensors initialization ***************/
195 #if USE_GPS
196  gps_init();
197 #endif
198 
199 #if USE_IMU
200  imu_init();
201 #if USE_IMU_FLOAT
202  imu_float_init();
203 #endif
204 #endif
205 
206 #if USE_AHRS_ALIGNER
208 #endif
209 
210 #if USE_AHRS
211  ahrs_init();
212 #endif
213 
214 #if USE_AHRS && USE_IMU
215  register_periodic_telemetry(DefaultPeriodic, "STATE_FILTER_STATUS", send_fliter_status);
216 #endif
217 
218  air_data_init();
219 #if USE_BARO_BOARD
220  baro_init();
221 #endif
222 
223  ins_init();
224 
225  /************* Links initialization ***************/
226 #if defined MCU_SPI_LINK || defined MCU_UART_LINK
227  link_mcu_init();
228 #endif
229 #if USE_AUDIO_TELEMETRY
231 #endif
232 
233  /************ Internal status ***************/
234  autopilot_init();
235  h_ctl_init();
236  v_ctl_init();
237  nav_init();
238 
239  modules_init();
240 
241  settings_init();
242 
243  /**** start timers for periodic functions *****/
244  sensors_tid = sys_time_register_timer(1./PERIODIC_FREQUENCY, NULL);
245  navigation_tid = sys_time_register_timer(1./NAVIGATION_FREQUENCY, NULL);
246  attitude_tid = sys_time_register_timer(1./CONTROL_FREQUENCY, NULL);
247  modules_tid = sys_time_register_timer(1./MODULES_FREQUENCY, NULL);
248  telemetry_tid = sys_time_register_timer(1./TELEMETRY_FREQUENCY, NULL);
249  monitor_tid = sys_time_register_timer(1.0, NULL);
250 #if USE_BARO_BOARD
252 #endif
253 
255  mcu_int_enable();
256 
257 #if defined DATALINK
258 #if DATALINK == XBEE
259  xbee_init();
260 #endif
261 #if DATALINK == W5100
262  w5100_init();
263 #endif
264 #endif /* DATALINK */
265 
266 #if defined AEROCOMM_DATA_PIN
267  IO0DIR |= _BV(AEROCOMM_DATA_PIN);
268  IO0SET = _BV(AEROCOMM_DATA_PIN);
269 #endif
270 
271  /************ Multi-uavs status ***************/
272 
273 #ifdef TRAFFIC_INFO
275 #endif
276 
277  /* set initial trim values.
278  * these are passed to fbw via inter_mcu.
279  */
280  ap_state->command_roll_trim = COMMAND_ROLL_TRIM;
281  ap_state->command_pitch_trim = COMMAND_PITCH_TRIM;
282  ap_state->command_yaw_trim = COMMAND_YAW_TRIM;
283 }
284 
285 
287 
288  if (sys_time_check_and_ack_timer(sensors_tid))
289  sensors_task();
290 
291 #if USE_BARO_BOARD
292  if (sys_time_check_and_ack_timer(baro_tid))
293  baro_periodic();
294 #endif
295 
296  if (sys_time_check_and_ack_timer(navigation_tid))
297  navigation_task();
298 
299 #ifndef AHRS_TRIGGERED_ATTITUDE_LOOP
300  if (sys_time_check_and_ack_timer(attitude_tid))
301  attitude_loop();
302 #endif
303 
304  if (sys_time_check_and_ack_timer(modules_tid))
305  modules_periodic_task();
306 
307  if (sys_time_check_and_ack_timer(monitor_tid))
308  monitor_task();
309 
310  if (sys_time_check_and_ack_timer(telemetry_tid)) {
311  reporting_task();
312  LED_PERIODIC();
313  }
314 
315 }
316 
317 
318 /******************** Interaction with FBW *****************************/
319 
322 #if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
323 static inline uint8_t pprz_mode_update( void ) {
324  if ((pprz_mode != PPRZ_MODE_HOME &&
326 #ifdef UNLOCKED_HOME_MODE
327  || TRUE
328 #endif
329  ) {
330 #ifndef RADIO_AUTO_MODE
332 #else
333  INFO("Using RADIO_AUTO_MODE to switch between AUTO1 and AUTO2.")
334  /* If RADIO_AUTO_MODE is enabled mode swithing will be seperated between two switches/channels
335  * RADIO_MODE will switch between PPRZ_MODE_MANUAL and any PPRZ_MODE_AUTO mode selected by RADIO_AUTO_MODE.
336  *
337  * This is mainly a cludge for entry level radios with no three-way switch but two available two-way switches which can be used.
338  */
340  /* RADIO_MODE in MANUAL position */
342  } else {
343  /* RADIO_MODE not in MANUAL position.
344  * Select AUTO mode bassed on RADIO_AUTO_MODE channel
345  */
346  return ModeUpdate(pprz_mode, (fbw_state->channels[RADIO_AUTO_MODE] > THRESHOLD2) ? PPRZ_MODE_AUTO2 : PPRZ_MODE_AUTO1);
347  }
348 #endif // RADIO_AUTO_MODE
349  } else
350  return FALSE;
351 }
352 #else // not RADIO_CONTROL
353 static inline uint8_t pprz_mode_update( void ) {
354  return FALSE;
355 }
356 #endif
357 
358 static inline uint8_t mcu1_status_update( void ) {
359  uint8_t new_status = fbw_state->status;
360  if (mcu1_status != new_status) {
361  bool_t changed = ((mcu1_status&MASK_FBW_CHANGED) != (new_status&MASK_FBW_CHANGED));
362  mcu1_status = new_status;
363  return changed;
364  }
365  return FALSE;
366 }
367 
368 
371 static inline void copy_from_to_fbw ( void ) {
372 #ifdef SetAutoCommandsFromRC
373  SetAutoCommandsFromRC(ap_state->commands, fbw_state->channels);
374 #elif defined RADIO_YAW && defined COMMAND_YAW
375  ap_state->commands[COMMAND_YAW] = fbw_state->channels[RADIO_YAW];
376 #endif
377 }
378 
380 #ifndef RC_LOST_MODE
381 #define RC_LOST_MODE PPRZ_MODE_HOME
382 #endif
383 
387 static inline void telecommand_task( void ) {
388  uint8_t mode_changed = FALSE;
390 
391  uint8_t really_lost = bit_is_set(fbw_state->status, STATUS_RADIO_REALLY_LOST) && (pprz_mode == PPRZ_MODE_AUTO1 || pprz_mode == PPRZ_MODE_MANUAL);
393  if (too_far_from_home) {
395  mode_changed = TRUE;
396  }
397  if (really_lost) {
399  mode_changed = TRUE;
400  }
401  }
402  if (bit_is_set(fbw_state->status, AVERAGED_CHANNELS_SENT)) {
403  bool_t pprz_mode_changed = pprz_mode_update();
404  mode_changed |= pprz_mode_changed;
405 #if defined RADIO_CALIB && defined RADIO_CONTROL_SETTINGS
406  bool_t calib_mode_changed = RcSettingsModeUpdate(fbw_state->channels);
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(fbw_state->channels[RADIO_ROLL], 0., AUTO1_MAX_ROLL);
421 
423  h_ctl_pitch_setpoint = FLOAT_OF_PPRZ(fbw_state->channels[RADIO_PITCH], 0., AUTO1_MAX_PITCH);
424  }
430  }
433  mcu1_ppm_cpt = fbw_state->ppm_cpt;
434 #endif // RADIO_CONTROL
435 
436 
437  vsupply = fbw_state->vsupply;
438  current = fbw_state->current;
439  energy = fbw_state->energy;
440 
441 #ifdef RADIO_CONTROL
442  /* the SITL check is a hack to prevent "automatic" launch in NPS */
443 #ifndef SITL
444  if (!autopilot_flight_time) {
446  launch = TRUE;
447  }
448  }
449 #endif
450 #endif
451 }
452 
453 
454 /**************************** Periodic tasks ***********************************/
455 
460 void reporting_task( void ) {
461  static uint8_t boot = TRUE;
462 
464  if (boot) {
465  DOWNLINK_SEND_BOOT(DefaultChannel, DefaultDevice, &version);
466  boot = FALSE;
467  }
469  else {
470  //PeriodicSendAp(DefaultChannel, DefaultDevice);
471  periodic_telemetry_send_Ap();
472  }
473 }
474 
475 
476 #ifdef FAILSAFE_DELAY_WITHOUT_GPS
477 #define GpsTimeoutError (sys_time.nb_sec - gps.last_3dfix_time > FAILSAFE_DELAY_WITHOUT_GPS)
478 #endif
479 
483 void navigation_task( void ) {
484 #if defined FAILSAFE_DELAY_WITHOUT_GPS
485 
486  static uint8_t last_pprz_mode;
487 
490  if (launch) {
491  if (GpsTimeoutError) {
493  last_pprz_mode = pprz_mode;
496  gps_lost = TRUE;
497  }
498  } else if (gps_lost) { /* GPS is ok */
500  pprz_mode = last_pprz_mode;
501  gps_lost = FALSE;
503  }
504  }
505 #endif /* GPS && FAILSAFE_DELAY_WITHOUT_GPS */
506 
508  if (pprz_mode == PPRZ_MODE_HOME)
509  nav_home();
511  nav_without_gps();
512  else
514 
515 #ifdef TCAS
516  CallTCAS();
517 #endif
518 
519 #ifndef PERIOD_NAVIGATION_Ap_0 // If not sent periodically (in default 0 mode)
521 #endif
522 
523  /* The nav task computes only nav_altitude. However, we are interested
524  by desired_altitude (= nav_alt+alt_shift) in any case.
525  So we always run the altitude control loop */
528 
531 #ifdef H_CTL_RATE_LOOP
532  /* Be sure to be in attitude mode, not roll */
534 #endif
536  h_ctl_course_loop(); /* aka compute nav_desired_roll */
537 
538  // climb_loop(); //4Hz
539  }
540 }
541 
542 
543 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
544 volatile uint8_t new_ins_attitude = 0;
545 #endif
546 
547 void attitude_loop( void ) {
548 
549 #if USE_INFRARED
551 #endif /* USE_INFRARED */
552 
553  if (pprz_mode >= PPRZ_MODE_AUTO2)
554  {
558  }
559  else if (v_ctl_mode >= V_CTL_MODE_AUTO_CLIMB)
560  {
562  }
563 
564 #if defined V_CTL_THROTTLE_IDLE
565  Bound(v_ctl_throttle_setpoint, TRIM_PPRZ(V_CTL_THROTTLE_IDLE*MAX_PPRZ), MAX_PPRZ);
566 #endif
567 
568 #ifdef V_CTL_POWER_CTL_BAT_NOMINAL
569  if (vsupply > 0.) {
570  v_ctl_throttle_setpoint *= 10. * V_CTL_POWER_CTL_BAT_NOMINAL / (float)vsupply;
572  }
573 #endif
574 
575  h_ctl_pitch_setpoint = v_ctl_pitch_setpoint; // Copy the pitch setpoint from the guidance to the stabilization control
576  Bound(h_ctl_pitch_setpoint, H_CTL_PITCH_MIN_SETPOINT, H_CTL_PITCH_MAX_SETPOINT);
579  }
580 
581  h_ctl_attitude_loop(); /* Set h_ctl_aileron_setpoint & h_ctl_elevator_setpoint */
583  ap_state->commands[COMMAND_THROTTLE] = v_ctl_throttle_slewed;
584  ap_state->commands[COMMAND_ROLL] = -h_ctl_aileron_setpoint;
585 
586  ap_state->commands[COMMAND_PITCH] = h_ctl_elevator_setpoint;
587 
588 #if defined MCU_SPI_LINK || defined MCU_UART_LINK
589  link_mcu_send();
590 #elif defined INTER_MCU && defined SINGLE_MCU
591 
593 #endif
594 
595 }
596 
597 
599 void sensors_task( void ) {
600 #if USE_IMU
601  imu_periodic();
602 
603 #if USE_AHRS
604  if (ahrs_timeout_counter < 255)
605  ahrs_timeout_counter ++;
606 #endif // USE_AHRS
607 #endif // USE_IMU
608 
609  //FIXME: this is just a kludge
610 #if USE_AHRS && defined SITL && !USE_NPS
611  ahrs_propagate();
612 #endif
613 
614 #if USE_GPS
616 #endif
617 
618  ins_periodic();
619 }
620 
621 
622 #ifdef LOW_BATTERY_KILL_DELAY
623 #warning LOW_BATTERY_KILL_DELAY has been renamed to CATASTROPHIC_BAT_KILL_DELAY, please update your airframe file!
624 #endif
625 
627 #ifndef CATASTROPHIC_BAT_KILL_DELAY
628 #define CATASTROPHIC_BAT_KILL_DELAY 5
629 #endif
630 
632 #ifndef KILL_MODE_DISTANCE
633 #define KILL_MODE_DISTANCE (1.5*MAX_DIST_FROM_HOME)
634 #endif
635 
637 #define MIN_SPEED_FOR_TAKEOFF 5.
638 
640 void monitor_task( void ) {
643 #if defined DATALINK || defined SITL
644  datalink_time++;
645 #endif
646 
647  static uint8_t t = 0;
648  if (vsupply < CATASTROPHIC_BAT_LEVEL*10)
649  t++;
650  else
651  t = 0;
654 
655  if (!autopilot_flight_time &&
658  launch = TRUE; /* Not set in non auto launch */
659  uint16_t time_sec = sys_time.nb_sec;
660  DOWNLINK_SEND_TAKEOFF(DefaultChannel, DefaultDevice, &time_sec);
661  }
662 
663 }
664 
665 
666 /*********** EVENT ***********************************************************/
667 void event_task_ap( void ) {
668 
669 #ifndef SINGLE_MCU
670 #if USE_I2C0 || USE_I2C1 || USE_I2C2
671  i2c_event();
672 #endif
673 #endif
674 
675 #if USE_AHRS && USE_IMU
677 #endif
678 
679 #ifdef InsEvent
680  TODO("calling InsEvent, remove me..")
681  InsEvent(NULL);
682 #endif
683 
684 #if USE_GPS
686 #endif /* USE_GPS */
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 */
703  }
704 
705  modules_event_task();
706 
707 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
708  if (new_ins_attitude > 0)
709  {
710  attitude_loop();
711  new_ins_attitude = 0;
712  }
713 #endif
714 
715 } /* event_task_ap() */
716 
717 
718 #if USE_GPS
719 static inline void on_gps_solution( void ) {
720  ins_update_gps();
721 #if USE_AHRS
722  ahrs_update_gps();
723 #endif
724 #ifdef GPS_TRIGGERED_FUNCTION
725  GPS_TRIGGERED_FUNCTION();
726 #endif
727 }
728 #endif
729 
730 
731 #if USE_AHRS
732 #if USE_IMU
733 static inline void on_accel_event( void ) {
734 }
735 
736 static inline void on_gyro_event( void ) {
737 
738  ahrs_timeout_counter = 0;
739 
740 #if USE_AHRS_ALIGNER
741  // Run aligner on raw data as it also makes averages.
742  if (ahrs.status == AHRS_UNINIT) {
743  ImuScaleGyro(imu);
747  ahrs_align();
748  return;
749  }
750 #endif
751 
752 #if PERIODIC_FREQUENCY == 60
753  ImuScaleGyro(imu);
755 
756  ahrs_propagate();
758 
759 #else //PERIODIC_FREQUENCY
760  static uint8_t _reduced_propagation_rate = 0;
761  static uint8_t _reduced_correction_rate = 0;
762  static struct Int32Vect3 acc_avg;
763  static struct Int32Rates gyr_avg;
764 
765  RATES_ADD(gyr_avg, imu.gyro_unscaled);
766  VECT3_ADD(acc_avg, imu.accel_unscaled);
767 
768  _reduced_propagation_rate++;
769  if (_reduced_propagation_rate < (PERIODIC_FREQUENCY / AHRS_PROPAGATE_FREQUENCY))
770  {
771  return;
772  }
773  else
774  {
775  _reduced_propagation_rate = 0;
776 
778  INT_RATES_ZERO(gyr_avg);
779 
780  ImuScaleGyro(imu);
781 
782  ahrs_propagate();
783 
784  _reduced_correction_rate++;
785  if (_reduced_correction_rate >= (AHRS_PROPAGATE_FREQUENCY / AHRS_CORRECT_FREQUENCY))
786  {
787  _reduced_correction_rate = 0;
789  INT_VECT3_ZERO(acc_avg);
792  }
793  }
794 #endif //PERIODIC_FREQUENCY
795 
796 #if defined SITL && USE_NPS
797  if (nps_bypass_ahrs) sim_overwrite_ahrs();
798 #endif
799 
800 #ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
801  new_ins_attitude = 1;
802 #endif
803 
804 }
805 
806 static inline void on_mag_event(void)
807 {
808 #if USE_MAGNETOMETER
809  ImuScaleMag(imu);
810  if (ahrs.status == AHRS_RUNNING) {
811  ahrs_update_mag();
812  }
813 #endif
814 }
815 
816 #endif // USE_IMU
817 
818 #endif // USE_AHRS
819 
#define COMMAND_PITCH_TRIM
Definition: main_ap.c:102
void monitor_task(void)
monitor stuff run at 1Hz
Definition: main_ap.c:640
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)
uint16_t vsupply
Supply voltage in deciVolt.
Definition: autopilot.c:51
tid_t monitor_tid
id for monitor_task() timer
Definition: main_ap.c:180
tid_t modules_tid
id for modules_periodic_task() timer
Definition: main_ap.c:175
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:733
Common barometric sensor implementation.
void h_ctl_attitude_loop(void)
void autopilot_init(void)
Autopilot inititalization.
Definition: autopilot.c:142
void ins_update_gps(void)
Update INS state with GPS measurements.
tid_t telemetry_tid
id for telemetry_periodic() timer
Definition: main_ap.c:176
static uint8_t mcu1_status_update(void)
Definition: main_ap.c:358
Variable setting though the radio control.
void imu_float_init(void)
Definition: imu.c:158
pprz_t v_ctl_throttle_setpoint
Definition: energy_ctrl.c:134
Periodic telemetry system header (includes downlink utility and generated code).
void navigation_task(void)
Compute desired_course.
Definition: main_ap.c:483
uint16_t autopilot_flight_time
flight time in seconds.
Definition: autopilot.c:47
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:40
static void on_gyro_event(void)
Definition: main_ap.c:736
uint8_t lateral_mode
Definition: autopilot.c:49
void w5100_init(void)
Definition: w5100.c:169
tid_t attitude_tid
id for attitude_loop() timer
Definition: main_ap.c:178
#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:387
Main include for ABI (AirBorneInterface).
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:49
#define ImuScaleMag(_imu)
Definition: ahrs_gx3.h:59
void ahrs_update_gps(void)
Update AHRS state with GPS measurements.
void imu_periodic(void)
Definition: imu_apogee.c:87
#define INT_RATES_ZERO(_e)
Integrated Navigation System interface.
tid_t sensors_tid
id for sensors_task() timer
Definition: main_ap.c:177
#define COMMAND_ROLL_TRIM
Definition: main_ap.c:98
void baro_init(void)
Definition: baro_board.c:68
#define V_CTL_MODE_AUTO_THROTTLE
#define PPRZ_MODE_AUTO2
Definition: autopilot.h:52
void ins_init(void)
INS initialization.
Definition: ins_alt_float.c:76
static void send_fliter_status(void)
Definition: main_ap.c:153
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:381
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:428
void v_ctl_climb_loop(void)
Auto-throttle inner loop.
Definition: energy_ctrl.c:314
bool_t register_periodic_telemetry(struct pprz_telemetry *_pt, const char *_msg, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:38
static uint8_t pprz_mode_update(void)
Update paparazzi mode.
Definition: main_ap.c:323
static uint8_t mcu1_ppm_cpt
Definition: main_ap.c:171
struct fbw_state * fbw_state
Definition: inter_mcu.c:32
int32_t current
Supply current in milliAmpere.
Definition: autopilot.c:52
void init_ap(void)
Definition: main_ap.c:185
#define BARO_BOARD
Definition: baro_board.h:33
float v_ctl_pitch_setpoint
Definition: energy_ctrl.c:136
#define FALSE
Definition: imu_chimu.h:141
#define RADIO_PITCH
Definition: spektrum_arch.h:45
struct ap_state * ap_state
Definition: inter_mcu.c:33
void baro_periodic(void)
Definition: baro_board.c:76
#define CallTCAS()
Definition: tcas.h:57
#define RATES_SDIV(_ro, _ri, _s)
Definition: pprz_algebra.h:375
Fixed wing horizontal control.
void ins_periodic(void)
INS periodic call.
Definition: ins_ardrone2.c:71
void settings_init(void)
Definition: settings.c:41
#define mcu_int_enable()
Definition: mcu_arch.h:37
void stateInit(void)
Definition: state.c:43
#define AHRS_PROPAGATE_FREQUENCY
Definition: main_ap.c:134
static void on_mag_event(void)
Definition: main_ap.c:806
void ahrs_update_mag(void)
Update AHRS state with magnetometer measurements.
void common_nav_periodic_task_4Hz()
Definition: common_nav.c:119
#define TRIM_UPPRZ(pprz)
Definition: paparazzi.h:14
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:50
bool_t gps_lost
Definition: autopilot.c:55
#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)
Architecture independent timing functions.
static void copy_from_to_fbw(void)
Send back uncontrolled channels.
Definition: main_ap.c:371
static const uint16_t version
Definition: main_ap.c:168
#define PPRZ_MODE_HOME
Definition: autopilot.h:53
Device independent GPS code (interface)
#define COMMAND_YAW_TRIM
Definition: main_ap.c:106
uint16_t val[TCOUPLE_NB]
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:47
uint8_t status
status of the AHRS, AHRS_UNINIT or AHRS_RUNNING
Definition: ahrs.h:45
#define ImuScaleAccel(_imu)
Definition: ahrs_gx3.h:54
#define BaroEvent
Definition: baro_board.h:36
void event_task_ap(void)
Definition: main_ap.c:667
#define AHRS_ALIGNER_LOCKED
Definition: ahrs_aligner.h:37
Air Data interface.
bool_t kill_throttle
Definition: autopilot.c:41
#define PPRZ_MODE_AUTO1
Definition: autopilot.h:51
#define RATES_ADD(_a, _b)
Definition: pprz_algebra.h:333
#define INT_VECT3_ZERO(_v)
#define ImuEvent(_gyro_handler, _accel_handler, _mag_handler)
Definition: ins_xsens.h:63
#define CATASTROPHIC_BAT_KILL_DELAY
Maximum time allowed for catastrophic battery level before going into kill mode.
Definition: main_ap.c:628
void reporting_task(void)
Send a series of initialisation messages followed by a stream of periodic ones.
Definition: main_ap.c:460
uint8_t v_ctl_mode
Definition: energy_ctrl.c:77
Inertial Measurement Unit interface.
volatile uint8_t ahrs_timeout_counter
Definition: main_ap.c:150
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:48
#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
static void on_gps_solution(void)
Definition: main_ap.c:719
void air_data_init(void)
AirData initialization.
Definition: air_data.c:61
#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
void autopilot_send_mode(void)
Send mode over telemetry.
Definition: autopilot.c:73
#define VECT3_ADD(_a, _b)
Definition: pprz_algebra.h:136
#define ModeUpdate(_mode, _value)
Assignment, returning _old_value != _value Using GCC expression statements.
Definition: autopilot.h:107
#define RADIO_MODE
Definition: spektrum_arch.h:69
#define RADIO_THROTTLE
Definition: spektrum_arch.h:39
#define LED_PERIODIC()
Definition: led_hw.h:8
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:53
float h_ctl_pitch_setpoint
W5100 ethernet chip I/O.
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.
float h_ctl_roll_setpoint
bool_t h_ctl_auto1_rate
void gps_periodic_check(void)
Periodic GPS check.
Definition: gps.c:136
uint8_t mcu1_status
Definition: autopilot.c:42
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
void ahrs_update_accel(void)
Update AHRS state with accerleration measurements.
#define FLOAT_OF_PPRZ(pprz, center, travel)
Definition: autopilot.h:82
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:51
arch independent LED (Light Emitting Diodes) API
#define MIN_SPEED_FOR_TAKEOFF
Define minimal speed for takeoff in m/s.
Definition: main_ap.c:637
void v_ctl_init(void)
Definition: energy_ctrl.c:202
#define NAVIGATION_FREQUENCY
Definition: autopilot.h:145
#define CONTROL_FREQUENCY
Definition: autopilot.h:140
void i2c_event(void)
Definition: i2c_arch.c:368
#define MAX_PPRZ
Definition: paparazzi.h:8
#define RADIO_ROLL
Definition: spektrum_arch.h:42
#define UNLOCKED_HOME_MODE
Definition: autopilot.c:125
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:57
#define PPRZ_MODE_MANUAL
AP modes.
Definition: autopilot.h:50
tid_t navigation_tid
id for navigation_task() timer
Definition: main_ap.c:179
#define KILL_MODE_DISTANCE
Maximum distance from HOME waypoint before going into kill mode.
Definition: main_ap.c:633
void imu_init(void)
Definition: imu.c:113
#define LATERAL_MODE_COURSE
Definition: autopilot.h:77
#define VECT3_SDIV(_vo, _vi, _s)
Definition: pprz_algebra.h:185
#define BARO_PERIODIC_FREQUENCY
Definition: main.c:101
#define AHRS_CORRECT_FREQUENCY
Definition: main_ap.c:138
void ahrs_aligner_init(void)
Definition: ahrs_aligner.c:62
#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:46
void ahrs_aligner_run(void)
Definition: ahrs_aligner.c:84
void xbee_init(void)
Definition: xbee.c:87
#define PPRZ_MODE_GPS_OUT_OF_ORDER
Definition: autopilot.h:54
void gps_init(void)
initialize the global GPS state
Definition: gps.c:107
void attitude_loop(void)
Definition: main_ap.c:547
#define ImuScaleGyro(_imu)
Definition: ahrs_gx3.h:49
#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:599
void handle_periodic_tasks_ap(void)
Definition: main_ap.c:286
void ahrs_init(void)
AHRS initialization.
void v_ctl_altitude_loop(void)
outer loop
Definition: energy_ctrl.c:276
Fixedwing autopilot modes.