Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
autopilot.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2012 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 
29 #include <stdint.h>
31 
32 #include "mcu_periph/uart.h"
34 #include "subsystems/commands.h"
35 #include "subsystems/actuators.h"
36 #include "subsystems/electrical.h"
37 #include "subsystems/settings.h"
41 
46 
47 #include "generated/settings.h"
48 
49 #if USE_GPS
50 #include "subsystems/gps.h"
51 #else
52 #if NO_GPS_NEEDED_FOR_NAV
53 #define GpsIsLost() FALSE
54 #else
55 #define GpsIsLost() TRUE
56 #endif
57 #endif
58 
59 #ifdef POWER_SWITCH_GPIO
60 #include "mcu_periph/gpio.h"
61 #endif
62 
63 #include "pprz_version.h"
64 
67 
71 
74 
75 bool_t autopilot_rc;
77 
80 
82 #ifndef AUTOPILOT_IN_FLIGHT_TIME
83 #define AUTOPILOT_IN_FLIGHT_TIME 20
84 #endif
85 
87 #ifndef AUTOPILOT_IN_FLIGHT_MIN_SPEED
88 #define AUTOPILOT_IN_FLIGHT_MIN_SPEED 0.2
89 #endif
90 
92 #ifndef AUTOPILOT_IN_FLIGHT_MIN_ACCEL
93 #define AUTOPILOT_IN_FLIGHT_MIN_ACCEL 2.0
94 #endif
95 
97 #ifndef AUTOPILOT_IN_FLIGHT_MIN_THRUST
98 #define AUTOPILOT_IN_FLIGHT_MIN_THRUST 500
99 #endif
100 
101 #ifndef AUTOPILOT_DISABLE_AHRS_KILL
102 static inline int ahrs_is_aligned(void)
103 {
104  return stateIsAttitudeValid();
105 }
106 #else
107 PRINT_CONFIG_MSG("Using AUTOPILOT_DISABLE_AHRS_KILL")
108 static inline int ahrs_is_aligned(void)
109 {
110  return TRUE;
111 }
112 #endif
113 
115 #ifndef FAILSAFE_DESCENT_SPEED
116 #define FAILSAFE_DESCENT_SPEED 1.5
117 PRINT_CONFIG_VAR(FAILSAFE_DESCENT_SPEED)
118 #endif
119 
121 #ifndef FAILSAFE_MODE_TOO_FAR_FROM_HOME
122 #define FAILSAFE_MODE_TOO_FAR_FROM_HOME AP_MODE_FAILSAFE
123 #endif
124 
125 
126 #if USE_KILL_SWITCH_FOR_MOTOR_ARMING
127 #include "autopilot_arming_switch.h"
128 PRINT_CONFIG_MSG("Using kill switch for motor arming")
129 #elif USE_THROTTLE_FOR_MOTOR_ARMING
131 PRINT_CONFIG_MSG("Using throttle for motor arming")
132 #else
133 #include "autopilot_arming_yaw.h"
134 PRINT_CONFIG_MSG("Using 2 sec yaw for motor arming")
135 #endif
136 
137 #ifndef MODE_STARTUP
138 #define MODE_STARTUP AP_MODE_KILL
139 PRINT_CONFIG_MSG("Using default AP_MODE_KILL as MODE_STARTUP")
140 #endif
141 
142 #ifndef UNLOCKED_HOME_MODE
143 #if MODE_AUTO1 == AP_MODE_HOME
144 #define UNLOCKED_HOME_MODE TRUE
145 PRINT_CONFIG_MSG("Enabled UNLOCKED_HOME_MODE since MODE_AUTO1 is AP_MODE_HOME")
146 #elif MODE_AUTO2 == AP_MODE_HOME
147 #define UNLOCKED_HOME_MODE TRUE
148 PRINT_CONFIG_MSG("Enabled UNLOCKED_HOME_MODE since MODE_AUTO2 is AP_MODE_HOME")
149 #else
150 #define UNLOCKED_HOME_MODE FALSE
151 #endif
152 #endif
153 
154 #if MODE_MANUAL == AP_MODE_NAV
155 #error "MODE_MANUAL mustn't be AP_MODE_NAV"
156 #endif
157 
159 {
160  static uint32_t ap_version = PPRZ_VERSION_INT;
161  static char *ver_desc = PPRZ_VERSION_DESC;
162  pprz_msg_send_AUTOPILOT_VERSION(trans, dev, AC_ID, &ap_version, strlen(ver_desc), ver_desc);
163 }
164 
165 static void send_alive(struct transport_tx *trans, struct link_device *dev)
166 {
167  pprz_msg_send_ALIVE(trans, dev, AC_ID, 16, MD5SUM);
168 }
169 
170 static void send_attitude(struct transport_tx *trans, struct link_device *dev)
171 {
172  struct FloatEulers *att = stateGetNedToBodyEulers_f();
173  pprz_msg_send_ATTITUDE(trans, dev, AC_ID, &(att->phi), &(att->psi), &(att->theta));
174 };
175 
176 #if USE_MOTOR_MIXING
178 #endif
179 
180 static void send_status(struct transport_tx *trans, struct link_device *dev)
181 {
182  uint32_t imu_nb_err = 0;
183 #if USE_MOTOR_MIXING
185 #else
186  uint8_t _motor_nb_err = 0;
187 #endif
188 #if USE_GPS
189  uint8_t fix = gps.fix;
190 #else
191  uint8_t fix = 0;
192 #endif
193  uint16_t time_sec = sys_time.nb_sec;
194  pprz_msg_send_ROTORCRAFT_STATUS(trans, dev, AC_ID,
195  &imu_nb_err, &_motor_nb_err,
197  &fix, &autopilot_mode,
200  &electrical.vsupply, &time_sec);
201 }
202 
203 static void send_energy(struct transport_tx *trans, struct link_device *dev)
204 {
206  if (fabs(electrical.energy) >= INT16_MAX) {
207  e = INT16_MAX;
208  }
209  float vsup = ((float)electrical.vsupply) / 10.0f;
210  float curs = ((float)electrical.current) / 1000.0f;
211  float power = vsup * curs;
212  pprz_msg_send_ENERGY(trans, dev, AC_ID, &vsup, &curs, &e, &power);
213 }
214 
215 static void send_fp(struct transport_tx *trans, struct link_device *dev)
216 {
217  int32_t carrot_up = -guidance_v_z_sp;
218  pprz_msg_send_ROTORCRAFT_FP(trans, dev, AC_ID,
219  &(stateGetPositionEnu_i()->x),
220  &(stateGetPositionEnu_i()->y),
221  &(stateGetPositionEnu_i()->z),
222  &(stateGetSpeedEnu_i()->x),
223  &(stateGetSpeedEnu_i()->y),
224  &(stateGetSpeedEnu_i()->z),
228  &guidance_h.sp.pos.y,
229  &guidance_h.sp.pos.x,
230  &carrot_up,
232  &stabilization_cmd[COMMAND_THRUST],
234 }
235 
236 #ifdef RADIO_CONTROL
237 static void send_rc(struct transport_tx *trans, struct link_device *dev)
238 {
239  pprz_msg_send_RC(trans, dev, AC_ID, RADIO_CONTROL_NB_CHANNEL, radio_control.values);
240 }
241 
242 static void send_rotorcraft_rc(struct transport_tx *trans, struct link_device *dev)
243 {
244 #ifdef RADIO_KILL_SWITCH
246 #else
247  int16_t _kill_switch = 42;
248 #endif
249  pprz_msg_send_ROTORCRAFT_RADIO_CONTROL(trans, dev, AC_ID,
255  &_kill_switch,
257 }
258 #endif
259 
260 #ifdef ACTUATORS
261 static void send_actuators(struct transport_tx *trans, struct link_device *dev)
262 {
263  pprz_msg_send_ACTUATORS(trans, dev, AC_ID , ACTUATORS_NB, actuators);
264 }
265 #endif
266 
267 static void send_dl_value(struct transport_tx *trans, struct link_device *dev)
268 {
269  PeriodicSendDlValue(trans, dev);
270 }
271 
272 static void send_rotorcraft_cmd(struct transport_tx *trans, struct link_device *dev)
273 {
274  pprz_msg_send_ROTORCRAFT_CMD(trans, dev, AC_ID,
275  &stabilization_cmd[COMMAND_ROLL],
276  &stabilization_cmd[COMMAND_PITCH],
277  &stabilization_cmd[COMMAND_YAW],
278  &stabilization_cmd[COMMAND_THRUST]);
279 }
280 
281 
282 void autopilot_init(void)
283 {
284  /* mode is finally set at end of init if MODE_STARTUP is not KILL */
294  autopilot_rc = TRUE;
296 #ifdef POWER_SWITCH_GPIO
298  gpio_clear(POWER_SWITCH_GPIO); // POWER OFF
299 #endif
300 
302 
303  nav_init();
304  guidance_h_init();
305  guidance_v_init();
306 
311 
312  /* set startup mode, propagates through to guidance h/v */
314 
315  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_AUTOPILOT_VERSION, send_autopilot_version);
317  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_STATUS, send_status);
320  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_FP, send_fp);
323 #ifdef ACTUATORS
325 #endif
326 #ifdef RADIO_CONTROL
328  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_RADIO_CONTROL, send_rotorcraft_rc);
329 #endif
330 }
331 
332 
333 #define NAV_PRESCALER (PERIODIC_FREQUENCY / NAV_FREQ)
335 {
336 
337  RunOnceEvery(NAV_PRESCALER, compute_dist2_to_home());
338 
340  if (too_far_from_home) {
343  } else {
345  }
346  }
347  }
348 
349  if (autopilot_mode == AP_MODE_HOME) {
350  RunOnceEvery(NAV_PRESCALER, nav_home());
351  } else {
352  // otherwise always call nav_periodic_task so that carrot is always updated in GCS for other modes
353  RunOnceEvery(NAV_PRESCALER, nav_periodic_task());
354  }
355 
356 
357  /* If in FAILSAFE mode and either already not in_flight anymore
358  * or just "detected" ground, go to KILL mode.
359  */
361  if (!autopilot_in_flight) {
363  }
364 
365 #if FAILSAFE_GROUND_DETECT
366  INFO("Using FAILSAFE_GROUND_DETECT: KILL")
369  }
370 #endif
371  }
372 
373  /* Reset ground detection _after_ running flight plan
374  */
375  if (!autopilot_in_flight) {
378  }
379 
380  /* Set fixed "failsafe" commands from airframe file if in KILL mode.
381  * If in FAILSAFE mode, run normal loops with failsafe attitude and
382  * downwards velocity setpoints.
383  */
384  if (autopilot_mode == AP_MODE_KILL) {
386  } else {
390  }
391 
392 }
393 
394 
395 void autopilot_set_mode(uint8_t new_autopilot_mode)
396 {
397 
398  /* force startup mode (default is kill) as long as AHRS is not aligned */
399  if (!ahrs_is_aligned()) {
400  new_autopilot_mode = MODE_STARTUP;
401  }
402 
403  if (new_autopilot_mode != autopilot_mode) {
404  /* horizontal mode */
405  switch (new_autopilot_mode) {
406  case AP_MODE_FAILSAFE:
407 #ifndef KILL_AS_FAILSAFE
410  break;
411 #endif
412  case AP_MODE_KILL:
416  break;
417  case AP_MODE_RC_DIRECT:
419  break;
420  case AP_MODE_RATE_DIRECT:
421  case AP_MODE_RATE_Z_HOLD:
423  break;
429  break;
430  case AP_MODE_FORWARD:
432  break;
435  break;
437  case AP_MODE_HOVER_CLIMB:
440  break;
441  case AP_MODE_HOME:
442  case AP_MODE_NAV:
444  break;
445  case AP_MODE_MODULE:
446 #ifdef GUIDANCE_H_MODE_MODULE_SETTING
448 #endif
449  break;
450  case AP_MODE_FLIP:
452  break;
453  case AP_MODE_GUIDED:
455  break;
456  default:
457  break;
458  }
459  /* vertical mode */
460  switch (new_autopilot_mode) {
461  case AP_MODE_FAILSAFE:
462 #ifndef KILL_AS_FAILSAFE
465  break;
466 #endif
467  case AP_MODE_KILL:
469  stabilization_cmd[COMMAND_THRUST] = 0;
471  break;
472  case AP_MODE_RC_DIRECT:
473  case AP_MODE_RATE_DIRECT:
477  case AP_MODE_FORWARD:
479  break;
483  break;
485  case AP_MODE_HOVER_CLIMB:
487  break;
488  case AP_MODE_RATE_Z_HOLD:
492  break;
493  case AP_MODE_HOME:
494  case AP_MODE_NAV:
496  break;
497  case AP_MODE_MODULE:
498 #ifdef GUIDANCE_V_MODE_MODULE_SETTING
500 #endif
501  break;
502  case AP_MODE_FLIP:
504  break;
505  case AP_MODE_GUIDED:
507  break;
508  default:
509  break;
510  }
511  autopilot_mode = new_autopilot_mode;
512  }
513 
514 }
515 
516 bool_t autopilot_guided_goto_ned(float x, float y, float z, float heading)
517 {
522  return TRUE;
523  }
524  return FALSE;
525 }
526 
527 bool_t autopilot_guided_goto_ned_relative(float dx, float dy, float dz, float dyaw)
528 {
530  float x = stateGetPositionNed_f()->x + dx;
531  float y = stateGetPositionNed_f()->y + dy;
532  float z = stateGetPositionNed_f()->z + dz;
533  float heading = stateGetNedToBodyEulers_f()->psi + dyaw;
534  return autopilot_guided_goto_ned(x, y, z, heading);
535  }
536  return FALSE;
537 }
538 
539 bool_t autopilot_guided_goto_body_relative(float dx, float dy, float dz, float dyaw)
540 {
542  float psi = stateGetNedToBodyEulers_f()->psi;
543  float x = stateGetPositionNed_f()->x + cosf(-psi) * dx + sinf(-psi) * dy;
544  float y = stateGetPositionNed_f()->y - sinf(-psi) * dx + cosf(-psi) * dy;
545  float z = stateGetPositionNed_f()->z + dz;
546  float heading = psi + dyaw;
547  return autopilot_guided_goto_ned(x, y, z, heading);
548  }
549  return FALSE;
550 }
551 
552 void autopilot_check_in_flight(bool_t motors_on)
553 {
554  if (autopilot_in_flight) {
555  if (autopilot_in_flight_counter > 0) {
556  /* probably in_flight if thrust, speed and accel above IN_FLIGHT_MIN thresholds */
557  if ((stabilization_cmd[COMMAND_THRUST] <= AUTOPILOT_IN_FLIGHT_MIN_THRUST) &&
561  if (autopilot_in_flight_counter == 0) {
563  }
564  } else { /* thrust, speed or accel not above min threshold, reset counter */
566  }
567  }
568  } else { /* currently not in flight */
570  motors_on) {
571  /* if thrust above min threshold, assume in_flight.
572  * Don't check for velocity and acceleration above threshold here...
573  */
574  if (stabilization_cmd[COMMAND_THRUST] > AUTOPILOT_IN_FLIGHT_MIN_THRUST) {
578  }
579  } else { /* currently not in_flight and thrust below threshold, reset counter */
581  }
582  }
583  }
584 }
585 
586 
587 void autopilot_set_motors_on(bool_t motors_on)
588 {
589  if (autopilot_mode != AP_MODE_KILL && ahrs_is_aligned() && motors_on) {
591  } else {
593  }
596 }
597 
598 
599 #define THRESHOLD_1_PPRZ (MIN_PPRZ / 2)
600 #define THRESHOLD_2_PPRZ (MAX_PPRZ / 2)
601 
604 {
606  return autopilot_mode_auto2;
607  }
609  return MODE_AUTO1;
610  }
611  else {
612  return MODE_MANUAL;
613  }
614 }
615 
624 #if defined RADIO_AUTO_MODE || defined(__DOXYGEN__)
625 static uint8_t ap_mode_of_two_switches(void)
626 {
628  /* RADIO_MODE in MANUAL position */
629  return MODE_MANUAL;
630  }
631  else {
632  /* RADIO_MODE not in MANUAL position.
633  * Select AUTO mode bassed on RADIO_AUTO_MODE channel
634  */
635  if (radio_control.values[RADIO_AUTO_MODE] > THRESHOLD_2_PPRZ) {
636  return autopilot_mode_auto2;
637  }
638  else
639  return MODE_AUTO1;
640  }
641 }
642 #endif
643 
645 {
646 
647  if (kill_switch_is_on()) {
649  } else {
650 #ifdef RADIO_AUTO_MODE
651  INFO("Using RADIO_AUTO_MODE to switch between AUTO1 and AUTO2.")
652  uint8_t new_autopilot_mode = ap_mode_of_two_switches();
653 #else
654  uint8_t new_autopilot_mode = ap_mode_of_3way_switch();
655 #endif
656 
657  /* don't enter NAV mode if GPS is lost (this also prevents mode oscillations) */
658  if (!(new_autopilot_mode == AP_MODE_NAV && GpsIsLost())) {
659  /* always allow to switch to manual */
660  if (new_autopilot_mode == MODE_MANUAL) {
661  autopilot_set_mode(new_autopilot_mode);
662  }
663  /* if in HOME mode, don't allow switching to non-manual modes */
664  else if ((autopilot_mode != AP_MODE_HOME)
666  /* Allowed to leave home mode when UNLOCKED_HOME_MODE */
668 #endif
669  ) {
670  autopilot_set_mode(new_autopilot_mode);
671  }
672  }
673  }
674 
675  /* an arming sequence is used to start/stop motors.
676  * only allow arming if ahrs is aligned
677  */
678  if (ahrs_is_aligned()) {
681  }
682 
683  /* if not in FAILSAFE or HOME mode, read RC and set commands accordingly */
685 
686  /* if there are some commands that should always be set from RC, do it */
687 #ifdef SetAutoCommandsFromRC
688  SetAutoCommandsFromRC(commands, radio_control.values);
689 #endif
690 
691  /* if not in NAV_MODE set commands from the rc */
692 #ifdef SetCommandsFromRC
693  if (autopilot_mode != AP_MODE_NAV) {
694  SetCommandsFromRC(commands, radio_control.values);
695  }
696 #endif
697 
700  }
701 
702 }
int32_t current
current in milliamps
Definition: electrical.h:49
int32_t guidance_v_z_sp
altitude setpoint in meters (input).
Definition: guidance_v.c:118
unsigned short uint16_t
Definition: types.h:16
#define AP_MODE_KILL
Definition: autopilot.h:36
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint32_t nb_failure
Definition: motor_mixing.h:42
#define AP_MODE_ATTITUDE_DIRECT
Definition: autopilot.h:40
static void autopilot_arming_check_motors_on(void)
State machine to check if motors should be turned ON or OFF using the kill switch.
#define GUIDANCE_V_MODE_NAV
Definition: guidance_v.h:40
void stabilization_none_init(void)
#define GUIDANCE_H_MODE_RC_DIRECT
Definition: guidance_h.h:57
static void send_alive(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:165
float y
in meters
float phi
in radians
Generic transmission transport header.
Definition: transport.h:89
void send_autopilot_version(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:158
#define GUIDANCE_H_MODE_CARE_FREE
Definition: guidance_h.h:58
#define POWER_SWITCH_GPIO
Definition: apogee_1.0.h:95
#define RADIO_ROLL
Definition: spektrum_arch.h:43
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition: state.h:1114
void autopilot_init(void)
Autopilot inititalization.
Definition: autopilot.c:175
#define THRESHOLD_2_PPRZ
Definition: autopilot.c:600
bool_t autopilot_ground_detected
Definition: autopilot.c:78
uint8_t autopilot_mode
Definition: autopilot.c:65
#define RADIO_YAW
Definition: spektrum_arch.h:45
Dummy stabilization for rotorcrafts.
Periodic telemetry system header (includes downlink utility and generated code).
General attitude stabilization interface for rotorcrafts.
bool_t autopilot_motors_on
Definition: autopilot.c:72
#define AP_MODE_HOVER_DIRECT
Definition: autopilot.h:46
uint16_t autopilot_flight_time
flight time in seconds.
Definition: autopilot.c:48
uint8_t status
Definition: radio_control.h:53
void guidance_v_run(bool_t in_flight)
Definition: guidance_v.c:272
static bool_t kill_switch_is_on(void)
static bool_t stateIsAttitudeValid(void)
Test if attitudes are valid.
Definition: state.h:1038
#define FAILSAFE_MODE_TOO_FAR_FROM_HOME
Mode that is set when the plane is really too far from home.
Definition: autopilot.c:122
void guidance_v_init(void)
Definition: guidance_v.c:174
Some architecture independent helper functions for GPIOs.
#define AP_MODE_RATE_RC_CLIMB
Definition: autopilot.h:41
#define RADIO_KILL_SWITCH
#define AUTOPILOT_IN_FLIGHT_MIN_ACCEL
minimum vertical acceleration for in_flight condition in m/s^2
Definition: autopilot.c:93
#define AP_MODE_FORWARD
Definition: autopilot.h:52
#define AP_MODE_RATE_Z_HOLD
Definition: autopilot.h:44
static void autopilot_arming_set(bool_t motors_on)
void guidance_v_mode_changed(uint8_t new_mode)
Definition: guidance_v.c:223
#define GUIDANCE_H_MODE_ATTITUDE
Definition: guidance_h.h:54
void stabilization_attitude_init(void)
#define AP_MODE_ATTITUDE_Z_HOLD
Definition: autopilot.h:45
float psi
in radians
bool_t autopilot_detect_ground_once
Definition: autopilot.c:79
Autopilot modes.
static void send_rotorcraft_rc(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:242
static void send_energy(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:203
void stabilization_init(void)
Definition: stabilization.c:30
#define AP_MODE_HOVER_CLIMB
Definition: autopilot.h:47
uint8_t autopilot_mode_auto2
Definition: autopilot.c:66
bool_t guidance_v_set_guided_z(float z)
Set z setpoint in GUIDED mode.
Definition: guidance_v.c:453
#define AP_MODE_MODULE
Definition: autopilot.h:53
uint32_t nb_saturation
Definition: motor_mixing.h:41
struct HorizontalGuidance guidance_h
Definition: guidance_h.c:79
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:58
static void send_actuators(struct transport_tx *trans, struct link_device *dev)
#define GUIDANCE_V_MODE_KILL
Definition: guidance_v.h:35
struct HorizontalGuidanceSetpoint sp
setpoints
Definition: guidance_h.h:97
#define FALSE
Definition: std.h:5
const pprz_t commands_failsafe[COMMANDS_NB]
Definition: commands.c:31
#define AP_MODE_RATE_DIRECT
Definition: autopilot.h:39
Rate stabilization for rotorcrafts.
euler angles
float z
in meters
#define MODE_AUTO1
Definition: autopilot.h:84
Automatically arm the motors when applying throttle.
bool_t guidance_h_set_guided_heading(float heading)
Set heading setpoint in GUIDED mode.
Definition: guidance_h.c:631
#define SetRotorcraftCommands(_cmd, _in_flight,_motor_on)
Set Rotorcraft commands.
Definition: autopilot.h:125
#define MODE_AUTO2
Definition: autopilot.h:87
void autopilot_check_in_flight(bool_t motors_on)
Definition: autopilot.c:552
static void send_dl_value(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:267
uint32_t autopilot_in_flight_counter
Definition: autopilot.c:69
float theta
in radians
bool_t autopilot_guided_goto_ned(float x, float y, float z, float heading)
Set position and heading setpoints in GUIDED mode.
Definition: autopilot.c:516
#define AP_MODE_RC_DIRECT
Definition: autopilot.h:50
#define GUIDANCE_H_MODE_HOVER
Definition: guidance_h.h:55
Hardware independent API for actuators (servos, motor controllers).
#define TRUE
Definition: std.h:4
static float heading
Definition: ahrs_infrared.c:45
void autopilot_set_motors_on(bool_t motors_on)
Definition: autopilot.c:587
bool_t autopilot_guided_goto_ned_relative(float dx, float dy, float dz, float dyaw)
Set position and heading setpoints wrt.
Definition: autopilot.c:527
void guidance_h_read_rc(bool_t in_flight)
Definition: guidance_h.c:293
#define AP_MODE_CARE_FREE_DIRECT
Definition: autopilot.h:51
Arm the motors using a switch.
#define AUTOPILOT_IN_FLIGHT_MIN_THRUST
minimum thrust for in_flight condition in pprz_t units (max = 9600)
Definition: autopilot.c:98
static struct NedCoor_f * stateGetSpeedNed_f(void)
Get ground speed in local NED coordinates (float).
Definition: state.h:885
Interface for electrical status: supply voltage, current, battery status, etc.
bool_t autopilot_power_switch
Definition: autopilot.c:76
#define RADIO_PITCH
Definition: spektrum_arch.h:44
static void send_rotorcraft_cmd(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:272
Device independent GPS code (interface)
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
Definition: state.h:1009
bool_t autopilot_in_flight
Definition: autopilot.c:68
static bool_t stateIsLocalCoordinateValid(void)
Test if local coordinates are valid.
Definition: state.h:491
static void send_fp(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:215
#define GUIDANCE_V_MODE_CLIMB
Definition: guidance_v.h:38
void gpio_clear(uint32_t port, uint16_t pin)
Clear a gpio output to low level.
Definition: gpio_ardrone.c:70
unsigned long uint32_t
Definition: types.h:18
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
signed short int16_t
Definition: types.h:17
void stabilization_attitude_set_failsafe_setpoint(void)
static void autopilot_arming_init(void)
bool_t autopilot_rc
Definition: autopilot.c:75
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
bool_t kill_throttle
Definition: autopilot.c:42
void guidance_h_run(bool_t in_flight)
Definition: guidance_h.c:347
#define FAILSAFE_DESCENT_SPEED
Set descent speed in failsafe mode.
Definition: autopilot.c:116
void autopilot_on_rc_frame(void)
Get autopilot mode from two 2way switches.
Definition: autopilot.c:644
#define GUIDANCE_V_MODE_HOVER
Definition: guidance_v.h:39
Hardware independent code for commands handling.
struct RadioControl radio_control
Definition: radio_control.c:30
#define GUIDANCE_H_MODE_NAV
Definition: guidance_h.h:56
static void send_status(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:180
#define RADIO_THROTTLE
Definition: spektrum_arch.h:42
#define AP_MODE_NAV
Definition: autopilot.h:49
#define GUIDANCE_H_MODE_MODULE_SETTING
#define GUIDANCE_H_MODE_KILL
Definition: guidance_h.h:52
bool_t guidance_h_set_guided_pos(float x, float y)
Set horizontal position setpoint in GUIDED mode.
Definition: guidance_h.c:621
Arm the motors by with max yaw stick.
void autopilot_periodic(void)
Definition: autopilot.c:334
signed long int32_t
Definition: types.h:19
#define RADIO_CONTROL_NB_CHANNEL
Definition: spektrum_arch.h:34
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
#define RADIO_MODE
Definition: spektrum_arch.h:59
uint8_t guidance_v_mode
Definition: guidance_v.c:98
static uint8_t ap_mode_of_3way_switch(void)
get autopilot mode as set by RADIO_MODE 3-way switch
Definition: autopilot.c:603
#define SetCommands(t)
Definition: commands.h:41
int32_t heading
with INT32_ANGLE_FRAC
Definition: guidance_h.h:72
unsigned char uint8_t
Definition: types.h:14
pprz_t commands[COMMANDS_NB]
Storage of intermediate command values.
Definition: commands.c:30
Persistent settings interface.
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
static void send_attitude(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:170
static struct EnuCoor_i * stateGetSpeedEnu_i(void)
Get ground speed in local ENU coordinates (int).
Definition: state.h:849
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:48
void guidance_h_mode_changed(uint8_t new_mode)
Definition: guidance_h.c:216
General stabilization interface for rotorcrafts.
#define AUTOPILOT_IN_FLIGHT_MIN_SPEED
minimum vertical speed for in_flight condition in m/s
Definition: autopilot.c:88
void guidance_v_read_rc(void)
Definition: guidance_v.c:201
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Definition: stabilization.c:28
#define AP_MODE_HOVER_Z_HOLD
Definition: autopilot.h:48
#define GUIDANCE_V_MODE_FLIP
Definition: guidance_v.h:42
static int ahrs_is_aligned(void)
Definition: autopilot.c:102
#define AP_MODE_ATTITUDE_RC_CLIMB
Definition: autopilot.h:42
int32_t guidance_v_zd_sp
vertical speed setpoint in meter/s (input).
Definition: guidance_v.c:119
struct MotorMixing motor_mixing
Definition: motor_mixing.c:94
#define AP_MODE_FAILSAFE
Definition: autopilot.h:37
float energy
consumed energy in mAh
Definition: electrical.h:51
#define AP_MODE_HOME
Definition: autopilot.h:38
bool_t autopilot_guided_goto_body_relative(float dx, float dy, float dz, float dyaw)
Set position and heading setpoints wrt.
Definition: autopilot.c:539
#define MODE_STARTUP
Definition: autopilot.c:138
#define SPEED_BFP_OF_REAL(_af)
struct Electrical electrical
Definition: electrical.c:65
#define MODE_MANUAL
Default RC mode.
Definition: autopilot.h:81
#define GpsIsLost()
Definition: gps.h:49
#define AUTOPILOT_IN_FLIGHT_TIME
time steps for in_flight detection (at 20Hz, so 20=1second)
Definition: autopilot.c:83
#define GUIDANCE_V_MODE_RC_CLIMB
Definition: guidance_v.h:37
void stabilization_rate_init(void)
#define UNLOCKED_HOME_MODE
Definition: autopilot.c:144
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
Definition: state.h:657
#define NAV_PRESCALER
Definition: autopilot.c:333
#define GUIDANCE_H_MODE_FORWARD
Definition: guidance_h.h:59
Motor Mixing.
#define GUIDANCE_V_MODE_RC_DIRECT
Definition: guidance_v.h:36
static void send_rc(struct transport_tx *trans, struct link_device *dev)
Definition: autopilot.c:237
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1096
#define GUIDANCE_H_MODE_RATE
Definition: guidance_h.h:53
uint8_t fix
status of fix
Definition: gps.h:82
void autopilot_set_mode(uint8_t new_autopilot_mode)
Definition: autopilot.c:395
static struct NedCoor_f * stateGetPositionNed_f(void)
Get position in local NED coordinates (float).
Definition: state.h:693
#define AP_MODE_ATTITUDE_CLIMB
Definition: autopilot.h:43
#define THRESHOLD_1_PPRZ
Definition: autopilot.c:599
#define AP_MODE_GUIDED
Definition: autopilot.h:55
#define GUIDANCE_H_MODE_FLIP
Definition: guidance_h.h:61
#define GUIDANCE_V_MODE_MODULE_SETTING
#define GUIDANCE_V_MODE_GUIDED
Definition: guidance_v.h:43
struct GpsState gps
global GPS state
Definition: gps.c:41
void guidance_h_init(void)
Definition: guidance_h.c:168
void gpio_setup_output(uint32_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition: gpio_ardrone.c:102
#define AP_MODE_FLIP
Definition: autopilot.h:54
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
struct Int32Vect2 pos
horizontal position setpoint in NED.
Definition: guidance_h.h:70
#define GUIDANCE_H_MODE_GUIDED
Definition: guidance_h.h:62
float x
in meters
uint8_t frame_rate
Definition: radio_control.h:56