Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 
31 #include "generated/airframe.h"
32 #include "generated/modules.h"
33 #include "modules/core/abi.h"
35 #include "modules/core/commands.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 
58 static 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 
72 static 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;
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,
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
95  commands_init();
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
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).
Event structure to store callbacks in a linked list.
Definition: abi_common.h:67
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:49
uint8_t mode
current autopilot mode
Definition: autopilot.h:63
void commands_init(void)
Definition: commands.c:46
const pprz_t commands_failsafe[COMMANDS_NB]
Definition: commands.c:31
pprz_t commands[COMMANDS_NB]
Definition: commands.c:30
Hardware independent code for commands handling.
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.
float current
current in A
Definition: electrical.h:47
float vsupply
supply voltage in V
Definition: electrical.h:45
#define AP_MODE_MANUAL
AP modes.
void main_recovery_periodic(void)
#define RECOVERY_RC_ID
Definition: main_recovery.c:51
tid_t periodic_tid
id for periodic task timer
Definition: main_recovery.c:44
static void rc_cb(uint8_t sender_id, struct RadioControl *rc)
Definition: main_recovery.c:58
tid_t electrical_tid
id for electrical_periodic() timer
Definition: main_recovery.c:45
uint8_t recovery_mode
Definition: main_recovery.c:42
static void send_fbw_status(struct transport_tx *trans, struct link_device *dev)
Definition: main_recovery.c:72
#define RECOVERY_MODE_OF_PPRZ(mode)
Definition: main_recovery.c:56
tid_t telemetry_tid
id for periodic telemetry
Definition: main_recovery.c:47
void main_recovery_event(void)
void main_recovery_init(void)
Definition: main_recovery.c:89
static abi_event rc_ev
Definition: main_recovery.c:54
Recovery mode: run manual mode in case of hardfault Based on legacy FBW.
#define RECOVERY_MODE_MANUAL
recovery modes
Definition: main_recovery.h:35
#define RECOVERY_MODE_FAILSAFE
Definition: main_recovery.h:36
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
struct RadioControl radio_control
Definition: radio_control.c:33
Generic interface for radio control modules.
#define RC_REALLY_LOST
Definition: radio_control.h:51
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:67
uint8_t status
Definition: radio_control.h:61
uint8_t frame_rate
Definition: radio_control.h:64
#define RC_OK
Definition: radio_control.h:49
Utility functions and includes for autopilots.
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:43
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:123
int8_t tid_t
sys_time timer id type
Definition: sys_time.h:60
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_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.
Definition: vl53l1_types.h:98