Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
autopilot_static.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2003 Pascal Brisset, Antoine Drouin
3 * Copyright (C) 2017 Gautier Hattenberger <gautier.hattenberger@enac.fr>
4 *
5 * This file is part of paparazzi.
6 *
7 * paparazzi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * paparazzi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with paparazzi; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
20 */
21
29#include "autopilot.h"
31
32#include "state.h"
35#include "generated/flight_plan.h"
36
37/* Geofence exceptions */
39
40#if USE_GPS
41#include "modules/gps/gps.h"
42#endif
43
45
46static inline uint8_t pprz_mode_update(void);
47
49#ifndef RC_LOST_MODE
50#define RC_LOST_MODE AP_MODE_HOME
51#endif
52
53
55#ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
56#include "modules/core/abi.h"
57volatile uint8_t new_ins_attitude = 0;
59static void new_att_cb(uint8_t sender_id __attribute__((unused)),
61 struct Int32Rates *gyro __attribute__((unused)))
62{
64}
65
68void autopilot_event(void)
69{
70 if (new_ins_attitude > 0) {
73 }
74}
75#endif
76
77
82{
85
87#ifdef AHRS_TRIGGERED_ATTITUDE_LOOP
89#endif
90
91}
92
94{
95}
96
101{
102 // Send back uncontrolled channels.
103#ifdef SetAutoCommandsFromRC
105#elif defined RADIO_YAW && defined COMMAND_YAW
107#endif
108
109#if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
116
119#if H_CTL_YAW_LOOP && defined RADIO_YAW
122#endif
123 // Note that old SetApOnlyCommands is no longer needed without a separated FBW
124 } else if (autopilot_get_mode() == AP_MODE_MANUAL) {
125 // Set commands from RC in MANUAL mode
128 }
135 }
137#endif
138}
139
146
151
153{
154 // it doesn't make real sense on fixedwing, as you can still use throttle
155 // in MAN and AUTO1 modes while have motor killed for AUTO2
156 // only needed for consistency with other firmwares
157 autopilot.motors_on = motors_on;
158}
159
164{
165
168 nav_home();
171 } else {
173 }
174
175#ifdef TCAS
176 callTCAS();
177#endif
178
179#if DOWNLINK && !defined PERIOD_NAVIGATION_Ap_0 // If not sent periodically (in default 0 mode)
180 SEND_NAVIGATION(&(DefaultChannel).trans_tx, &(DefaultDevice).device);
181#endif
182
183 /* The nav task computes only nav_altitude. However, we are interested
184 by desired_altitude (= nav_alt+alt_shift) in any case.
185 So we always run the altitude control loop */
188 }
189
193#ifdef H_CTL_RATE_LOOP
194 /* Be sure to be in attitude mode, not roll */
195 h_ctl_auto1_rate = false;
196#endif
198 h_ctl_course_loop(); /* aka compute nav_desired_roll */
199 }
200
201 }
202}
203
217{
218#if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
219 /* check normal mode from RC channel(s)
220 */
221 if (!RadioControlIsLost()) {
222#if defined RADIO_CALIB && defined RADIO_CONTROL_SETTINGS
227#else
229#endif
230 }
231
232 /* RC lost while in use is true if we lost RC in MANUAL or AUTO1
233 *
234 * RC_LOST_MODE defaults to AP_MODE_HOME, but it can also be set to NAV_MODE_NAV or MANUAL when the RC receiver is well configured to send failsafe commands
235 */
236 if (RadioControlIsLost() &&
240 }
241
242 /* Check RC kill switch
243 */
244#ifdef RADIO_KILL_SWITCH
246 autopilot_set_kill_throttle(true); // not a mode change, just set kill_throttle
247 }
248#endif
249
250 /* the SITL check is a hack to prevent "automatic" launch in NPS
251 */
252#ifndef SITL
253 if (!autopilot.flight_time) {
255 autopilot.launch = true; // set launch to true from RC throttel up
256 }
257 }
258#endif
259
260#endif // RADIO_CONTROL
261
262#if USE_GPS && (defined FAILSAFE_DELAY_WITHOUT_GPS)
263 /* This section is used for the failsafe of GPS
264 */
265 static uint8_t last_pprz_mode;
266 static bool gps_lost = false;
267
270 if (autopilot.launch) {
271 // check GPS timeout
277 gps_lost = true;
278 }
279 } else if (gps_lost) { /* GPS is ok */
282 gps_lost = false;
283 }
284 }
285#endif /* GPS && FAILSAFE_DELAY_WITHOUT_GPS */
286
287 /* If in-flight, with good GPS but too far, then activate HOME mode
288 * In MANUAL with good RC, FBW will allow to override. */
294 }
295 }
296}
297
298
300{
301 // Call vertical climb loop if mode is at least AUTO2
303#if CTRL_VERTICAL_LANDING
306 } else {
307#endif
311 } else {
314 }
315 }
316#if CTRL_VERTICAL_LANDING
317 }
318#endif
319
320#if defined V_CTL_THROTTLE_IDLE
322#endif
323
324#ifdef V_CTL_POWER_CTL_BAT_NOMINAL
325 if (electrical.vsupply > 0.f) {
328 }
329#endif
330
331 // Copy the pitch setpoint from the guidance to the stabilization control
336 }
337 }
338
339 // Call attitude control and set commands if mode is at least AUTO1
341 h_ctl_attitude_loop(); /* Set h_ctl_aileron_setpoint & h_ctl_elevator_setpoint */
348 }
349
350}
351
352
355#if defined RADIO_CONTROL || defined RADIO_CONTROL_AUTO1
356static inline uint8_t pprz_mode_update(void)
357{
361 || true
362#endif
363 ) {
364#ifndef RADIO_AUTO_MODE
366 bool b = autopilot_set_mode(nm);
367 return b;
368 //return autopilot_set_mode(AP_MODE_OF_PULSE(radio_control_get(RADIO_MODE)));
369#else
370 INFO("Using RADIO_AUTO_MODE to switch between AUTO1 and AUTO2.")
371 /* If RADIO_AUTO_MODE is enabled mode swithing will be seperated between
372 * two switches/channels
373 * RADIO_MODE will switch between AP_MODE_MANUAL and any AP_MODE_AUTO mode
374 * selected by RADIO_AUTO_MODE.
375 *
376 * This is mainly a cludge for entry level radios with no three-way switch
377 * but two available two-way switches which can be used.
378 */
380 /* RADIO_MODE in MANUAL position */
382 } else {
383 /* RADIO_MODE not in MANUAL position.
384 * Select AUTO mode bassed on RADIO_AUTO_MODE channel
385 */
387 }
388#endif // RADIO_AUTO_MODE
389 } else {
390 return false;
391 }
392}
393#else // not RADIO_CONTROL
394static inline uint8_t pprz_mode_update(void)
395{
396 return false;
397}
398#endif
399
400
Main include for ABI (AirBorneInterface).
#define ABI_BROADCAST
Broadcast address.
Definition abi_common.h:58
Event structure to store callbacks in a linked list.
Definition abi_common.h:67
void WEAK autopilot_event(void)
AP event call.
Definition autopilot.c:174
bool autopilot_set_mode(uint8_t new_autopilot_mode)
set autopilot mode
Definition autopilot.c:193
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition autopilot.c:222
struct pprz_autopilot autopilot
Global autopilot structure.
Definition autopilot.c:49
void autopilot_set_kill_throttle(bool kill)
set kill throttle
Definition autopilot.c:302
Core autopilot interface common to all firmwares.
bool motors_on
motor status
Definition autopilot.h:68
bool launch
request launch
Definition autopilot.h:71
pprz_t throttle
throttle level as will be displayed in GCS
Definition autopilot.h:66
bool kill_throttle
allow autopilot to use throttle
Definition autopilot.h:69
uint8_t mode
current autopilot mode
Definition autopilot.h:63
uint16_t flight_time
flight time in seconds
Definition autopilot.h:65
void common_nav_periodic_task()
Definition common_nav.c:169
bool too_far_from_home
Definition common_nav.c:41
struct Electrical electrical
Definition electrical.c:92
float vsupply
supply voltage in V
Definition electrical.h:45
pprz_t v_ctl_throttle_setpoint
void v_ctl_climb_loop(void)
Auto-throttle inner loop.
float v_ctl_pitch_setpoint
void v_ctl_throttle_slew(void)
Computes slewed throttle from throttle setpoint called at 20Hz.
pprz_t v_ctl_throttle_slewed
void v_ctl_altitude_loop(void)
outer loop
uint8_t v_ctl_mode
Definition energy_ctrl.c:74
uint8_t lateral_mode
#define LATERAL_MODE_MANUAL
#define LATERAL_MODE_COURSE
void attitude_loop(void)
void autopilot_static_init(void)
Static autopilot API.
void navigation_task(void)
Compute desired_course.
void autopilot_static_periodic(void)
static uint8_t pprz_mode_update(void)
Update paparazzi mode from RC.
void autopilot_static_SetModeHandler(float new_autopilot_mode)
void autopilot_static_set_motors_on(bool motors_on)
#define RC_LOST_MODE
mode to enter when RC is lost in AP_MODE_MANUAL or AP_MODE_AUTO1
void autopilot_failsafe_checks(void)
Failsafe checks.
void autopilot_static_on_rc_frame(void)
Function to be called when a message from FBW is available.
void autopilot_static_set_mode(uint8_t new_autopilot_mode)
Fixedwing autopilot modes (static implementation).
#define AP_MODE_HOME
#define AP_MODE_MANUAL
AP modes.
#define AP_MODE_GPS_OUT_OF_ORDER
#define AP_MODE_AUTO2
#define AP_MODE_AUTO1
#define AP_COMMAND_SET_THROTTLE(_throttle)
#define THRESHOLD2
#define AP_COMMAND_SET_CL(_cl)
#define AP_COMMAND_SET_PITCH(_pitch)
#define THROTTLE_THRESHOLD_TAKEOFF
Takeoff detection threshold from throttle.
#define AP_COMMAND_SET_ROLL(_roll)
AP command setter macros for usual commands.
#define FLOAT_OF_PPRZ(pprz, center, travel)
pprz_t to float with saturation
#define AP_COMMAND_SET_YAW(_yaw)
#define AP_MODE_OF_PULSE(pprz)
Get mode from pulse.
Fixed wing horizontal control.
struct GpsState gps
global GPS state
Definition gps.c:74
Device independent GPS code (interface)
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
Definition gps.h:115
angular rates
void v_ctl_landing_loop(void)
Definition guidance_v.c:357
#define V_CTL_MODE_AUTO_THROTTLE
#define V_CTL_MODE_LANDING
#define V_CTL_MODE_AUTO_ALT
#define V_CTL_MODE_AUTO_CLIMB
volatile uint8_t new_ins_attitude
uint16_t foo
Definition main_demo5.c:58
void nav_home(void)
Home mode navigation (circle around HOME)
Definition nav.c:424
pprz_t nav_throttle_setpoint
Definition nav.c:309
void nav_without_gps(void)
Failsafe navigation without position estimation.
Definition nav.c:569
float nav_pitch
Definition nav.c:310
void nav_periodic_task(void)
Navigation main: call to the code generated from the XML flight plan.
Definition nav.c:445
Fixedwing Navigation library.
#define SEND_NAVIGATION(_trans, _dev)
Definition nav.h:245
Optional exceptions triggeringg HOME_MODE 1) GEOFENCE_DATALINK_LOST_TIME: go to HOME mode if datalink...
static bool higher_than_max_altitude(void)
static bool datalink_lost(void)
#define TRIM_UPPRZ(pprz)
Definition paparazzi.h:14
#define MAX_PPRZ
Definition paparazzi.h:8
#define TRIM_PPRZ(pprz)
Definition paparazzi.h:11
#define MIN_PPRZ
Definition paparazzi.h:9
struct RadioControl radio_control
#define RadioControlIsLost()
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
static pprz_t radio_control_get(uint8_t idx)
Get a radio control channel value.
void rc_settings(bool mode_changed)
Includes generated code from tuning_rc.xml.
Definition rc_settings.c:47
#define UNLOCKED_HOME_MODE
static const ShellCommand commands[]
Definition shell_arch.c:78
void h_ctl_course_loop(void)
float h_ctl_pitch_setpoint
pprz_t h_ctl_elevator_setpoint
float h_ctl_roll_setpoint
pprz_t h_ctl_aileron_setpoint
bool h_ctl_auto1_rate
void h_ctl_attitude_loop(void)
API to get/set the generic vehicle states.
volatile uint32_t nb_sec
full seconds since startup
Definition sys_time.h:72
void callTCAS(void)
Definition tcas.c:65
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
float b
Definition wedgebug.c:202