Paparazzi UAS  v6.2_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
53 PRINT_CONFIG_VAR(RECOVERY_RC_ID)
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 
radio_control.h
electrical.h
RECOVERY_MODE_OF_PPRZ
#define RECOVERY_MODE_OF_PPRZ(mode)
Definition: main_recovery.c:56
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
telemetry_tid
tid_t telemetry_tid
id for periodic telemetry
Definition: main_recovery.c:47
autopilot_utils.h
commands_init
void commands_init(void)
Definition: commands.c:46
abi.h
RECOVERY_RC_ID
#define RECOVERY_RC_ID
Definition: main_recovery.c:51
main_recovery_init
void main_recovery_init(void)
Definition: main_recovery.c:89
pprz_autopilot::mode
uint8_t mode
current autopilot mode
Definition: autopilot.h:63
abi_struct
Event structure to store callbacks in a linked list.
Definition: abi_common.h:66
main_recovery.h
commands
pprz_t commands[COMMANDS_NB]
Definition: commands.c:30
commands_failsafe
const pprz_t commands_failsafe[COMMANDS_NB]
Definition: commands.c:31
Electrical::vsupply
float vsupply
supply voltage in V
Definition: electrical.h:45
RECOVERY_MODE_MANUAL
#define RECOVERY_MODE_MANUAL
recovery modes
Definition: main_recovery.h:35
RadioControl::frame_rate
uint8_t frame_rate
Definition: radio_control.h:64
rc_cb
static void rc_cb(uint8_t sender_id, struct RadioControl *rc)
Definition: main_recovery.c:58
telemetry.h
autopilot
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:48
periodic_tid
tid_t periodic_tid
id for periodic task timer
Definition: main_recovery.c:44
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
electrical_periodic
void electrical_periodic(void)
Definition: electrical.c:123
main_recovery_periodic
void main_recovery_periodic(void)
Definition: main_recovery.c:136
register_periodic_telemetry
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
RadioControl::status
uint8_t status
Definition: radio_control.h:61
RECOVERY_MODE_FAILSAFE
#define RECOVERY_MODE_FAILSAFE
Definition: main_recovery.h:36
RadioControl
Definition: radio_control.h:60
electrical_init
void electrical_init(void)
Definition: electrical.c:100
tid_t
int8_t tid_t
sys_time timer id type
Definition: sys_time.h:60
rc_ev
static abi_event rc_ev
Definition: main_recovery.c:54
RC_OK
#define RC_OK
Definition: radio_control.h:49
electrical_tid
tid_t electrical_tid
id for electrical_periodic() timer
Definition: main_recovery.c:45
sys_time_register_timer
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:43
main_recovery_event
void main_recovery_event(void)
Definition: main_recovery.c:126
AP_MODE_MANUAL
#define AP_MODE_MANUAL
AP modes.
Definition: autopilot_static.h:36
commands.h
Hardware independent code for commands handling.
electrical
struct Electrical electrical
Definition: electrical.c:66
RC_REALLY_LOST
#define RC_REALLY_LOST
Definition: radio_control.h:51
DefaultPeriodic
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
sys_time_check_and_ack_timer
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:123
Electrical::current
float current
current in A
Definition: electrical.h:46
radio_control
struct RadioControl radio_control
Definition: radio_control.c:33
recovery_mode
uint8_t recovery_mode
Definition: main_recovery.c:42
send_fbw_status
static void send_fbw_status(struct transport_tx *trans, struct link_device *dev)
Definition: main_recovery.c:72
RadioControl::values
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:67