Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
main_recovery.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 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 */
21
29
31#include "generated/airframe.h"
32#include "generated/modules.h"
33#include "modules/core/abi.h"
37#include "autopilot_utils.h"
38#if PERIODIC_TELEMETRY
40#endif
41
43
46#if PERIODIC_TELEMETRY
48#endif
49
50#ifndef RECOVERY_RC_ID
51#define RECOVERY_RC_ID ABI_BROADCAST
52#endif
55
56#define RECOVERY_MODE_OF_PPRZ(mode) ((mode) < THRESHOLD_MANUAL_PPRZ ? RECOVERY_MODE_MANUAL : RECOVERY_MODE_FAILSAFE)
57
58static void rc_cb(uint8_t __attribute__((unused)) sender_id,
59 struct RadioControl *rc)
60{
63 // on RC callback in manual, set commands from RC
64 SetCommandsFromRC(commands, rc->values);
65 }
66}
67
68/********** PERIODIC MESSAGES ************************************************/
69#if PERIODIC_TELEMETRY
71
72static void send_fbw_status(struct transport_tx *trans, struct link_device *dev)
73{
74#ifdef RADIO_CONTROL
75 uint8_t rc_status = radio_control.status;
76 uint8_t rc_rate = radio_control.frame_rate;
77#else
78 uint8_t rc_status = 0;
79 uint8_t rc_rate = 0;
80#endif
81 pprz_msg_send_FBW_STATUS(trans, dev, AC_ID,
82 &rc_status, &rc_rate, &recovery_mode,
83 &electrical.vsupply, &electrical.current);
84}
85
86#endif /* PERIODIC_TELEMETRY */
87
88/********** INIT *************************************************************/
90{
91 // mcu init done in main
92
93 // don't call all core modules, only a subset
96
97 modules_radio_control_init();
98 modules_actuators_init();
99 modules_datalink_init();
100
102
103 /**** start timers for periodic functions *****/
104 periodic_tid = sys_time_register_timer((1. / 60.), NULL);
106
107 // actuators periodic will update the actuators
108 // but the autopilot.mode is passed to SetActuatorsFromCommands
109 // it is set to manual if possible, otherwise behavior is undefined
110#ifdef AP_MODE_MANUAL
112#endif
113
114 // Bind to RC event
115 AbiBindMsgRADIO_CONTROL(RECOVERY_RC_ID, &rc_ev, rc_cb);
116
117#if PERIODIC_TELEMETRY
118 telemetry_tid = sys_time_register_timer((1. / TELEMETRY_FREQUENCY), NULL);
120#endif /* PERIODIC_TELEMETRY */
121
122}
123
124/********** EVENT ************************************************************/
125
127{
128 modules_mcu_event_task();
129 modules_radio_control_event_task();
130 modules_actuators_event_task();
131 modules_datalink_event_task();
132}
133
134/************* PERIODIC ******************************************************/
135
137{
139 modules_mcu_periodic_task();
140 modules_radio_control_periodic_task();
141 // if RC is lost or not in manual, set failsafe commands
142 if (radio_control.status == RC_REALLY_LOST ||
145 SetCommands(commands_failsafe);
146 }
147 modules_actuators_periodic_task();
148 }
149
150#if !(RECOVERY_DISABLE_ELECTRICAL)
153 }
154#endif
155
156#if PERIODIC_TELEMETRY
158 // only fbw part during recovery
159 periodic_telemetry_send_Fbw(DefaultPeriodic, &(DefaultChannel).trans_tx, &(DefaultDevice).device);
160 }
161#endif
162
163}
164
Main include for ABI (AirBorneInterface).
struct abi_struct abi_event
Definition abi_common.h:101
static void rc_cb(uint8_t sender_id, struct RadioControl *rc)
Definition autopilot.c:58
struct pprz_autopilot autopilot
Global autopilot structure.
Definition autopilot.c:50
static abi_event rc_ev
Definition autopilot.c:56
void commands_init(void)
Definition commands.c:46
const pprz_t commands_failsafe[COMMANDS_NB]
Definition commands.c:31
Hardware independent code for commands handling.
static struct uart_periph * dev
struct Electrical electrical
Definition electrical.c:92
void electrical_init(void)
Definition electrical.c:128
void electrical_periodic(void)
Definition electrical.c:166
Interface for electrical status: supply voltage, current, battery status, etc.
static void send_fbw_status(struct transport_tx *trans, struct link_device *dev)
#define AP_MODE_MANUAL
AP modes.
Utility functions and includes for autopilots.
void main_recovery_periodic(void)
#define RECOVERY_RC_ID
tid_t periodic_tid
id for periodic task timer
static void rc_cb(uint8_t sender_id, struct RadioControl *rc)
tid_t electrical_tid
id for electrical_periodic() timer
uint8_t recovery_mode
static void send_fbw_status(struct transport_tx *trans, struct link_device *dev)
#define RECOVERY_MODE_OF_PPRZ(mode)
tid_t telemetry_tid
id for periodic telemetry
void main_recovery_event(void)
void main_recovery_init(void)
Recovery mode: run manual mode in case of hardfault Based on legacy FBW.
#define RECOVERY_MODE_MANUAL
recovery modes
#define RECOVERY_MODE_FAILSAFE
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
struct RadioControl radio_control
Generic interface for radio control modules.
#define RC_REALLY_LOST
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
#define RC_OK
static const ShellCommand commands[]
Definition shell_arch.c:77
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition sys_time.c:172
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition sys_time.h:226
int8_t tid_t
sys_time timer id type
Definition sys_time.h:68
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.