Paparazzi UAS  v5.15_devel-113-g1b57ff1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
autopilot_generated.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
27 #define AUTOPILOT_CORE_AP_C
28 
30 #include "autopilot.h"
31 
33 #include "subsystems/commands.h"
34 #include "subsystems/actuators.h"
35 #include "subsystems/settings.h"
37 
38 #include "generated/settings.h"
39 
40 #if USE_KILL_SWITCH_FOR_MOTOR_ARMING
42 PRINT_CONFIG_MSG("Using kill switch for motor arming")
43 #elif USE_THROTTLE_FOR_MOTOR_ARMING
45 PRINT_CONFIG_MSG("Using throttle for motor arming")
46 #else
47 #include "autopilot_arming_yaw.h"
48 PRINT_CONFIG_MSG("Using 2 sec yaw for motor arming")
49 #endif
50 
51 
53 {
54  // call generated init
55  autopilot_core_ap_init();
56  // copy generated mode to public mode (set at startup)
57  autopilot.mode = autopilot_mode_ap;
58 
59  // init arming
61 }
62 
63 
65 {
66 
67  autopilot_core_ap_periodic_task();
68 
69  // copy generated mode to public mode (may be changed on internal exceptions)
70  autopilot.mode = autopilot_mode_ap;
71 
72  /* Reset ground detection _after_ running flight plan
73  */
74  if (!autopilot_in_flight()) {
75  autopilot.ground_detected = false;
77  }
78 
79 }
80 
86 {
88 }
89 
90 
91 void autopilot_generated_set_mode(uint8_t new_autopilot_mode)
92 {
93  autopilot_core_ap_set_mode(new_autopilot_mode);
94  // copy generated mode to public mode
95  autopilot.mode = autopilot_mode_ap;
96 }
97 
98 
100 {
101  if (ap_ahrs_is_aligned() && motors_on
102 #ifdef AP_MODE_KILL
104 #endif
105  ) {
106  autopilot.motors_on = true;
107  } else {
108  autopilot.motors_on = false;
109  }
111 }
112 
113 
115 {
116 
117  // FIXME what to do here ?
118 
119  /* an arming sequence is used to start/stop motors.
120  * only allow arming if ahrs is aligned
121  */
122  if (ap_ahrs_is_aligned()) {
125  } else {
127  }
128 
129  /* if not in FAILSAFE or HOME mode, read RC and set commands accordingly */
130 // if (autopilot.mode != AP_MODE_FAILSAFE && autopilot.mode != AP_MODE_HOME) {
131 //
132 // /* if there are some commands that should always be set from RC, do it */
133 //#ifdef SetAutoCommandsFromRC
134 // SetAutoCommandsFromRC(commands, radio_control.values);
135 //#endif
136 //
137 // /* if not in NAV_MODE set commands from the rc */
138 //#ifdef SetCommandsFromRC
139 // if (autopilot.mode != AP_MODE_NAV) {
140 // SetCommandsFromRC(commands, radio_control.values);
141 // }
142 //#endif
143 //
144 // guidance_v_read_rc();
145 // guidance_h_read_rc(autopilot.in_flight);
146 // }
147 
148 }
static void autopilot_arming_set(bool motors_on)
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 AP_MODE_KILL
Static autopilot modes.
void autopilot_generated_SetModeHandler(float mode)
AP mode setting handler.
Periodic telemetry system header (includes downlink utility and generated code).
Autopilot generated implementation Calls the code generated from autopilot XML file.
void autopilot_generated_init(void)
void autopilot_generated_on_rc_frame(void)
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
#define AP_ARMING_STATUS_AHRS_NOT_ALLIGNED
bool ap_ahrs_is_aligned(void)
Display descent speed in failsafe mode if needed.
Automatically arm the motors when applying throttle.
Hardware independent API for actuators (servos, motor controllers).
bool detect_ground_once
enable automatic detection of ground (one shot)
Definition: autopilot.h:75
void autopilot_generated_set_mode(uint8_t new_autopilot_mode)
Arm the motors using a switch.
bool autopilot_in_flight(void)
get in_flight flag
Definition: autopilot.c:257
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
static void autopilot_arming_init(void)
void autopilot_generated_set_motors_on(bool motors_on)
Hardware independent code for commands handling.
uint8_t arming_status
arming status
Definition: autopilot.h:67
Arm the motors by with max yaw stick.
Core autopilot interface common to all firmwares.
bool motors_on
motor status
Definition: autopilot.h:68
unsigned char uint8_t
Definition: types.h:14
Persistent settings interface.
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition: sonar_bebop.c:69
bool kill_throttle
allow autopilot to use throttle
Definition: autopilot.h:69
bool ground_detected
automatic detection of landing
Definition: autopilot.h:74
uint8_t mode
current autopilot mode
Definition: autopilot.h:63
void autopilot_generated_periodic(void)