Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
ground_detect.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 Ewoud Smeur <e.j.j.smeur@tudelft.nl>
3 * Copyright (C) 2023 Dennis van Wijngaarden <D.C.vanWijngaarden@tudelft.nl>
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
26#include "ground_detect.h"
29#include "modules/core/abi.h"
30
31#include "state.h"
32
33#include "pprzlink/messages.h"
35
36/* Number of triggers which need to be active to assume ground has been detected */
37#ifndef GROUND_DETECT_NUM_TRIGGERS
38#define GROUND_DETECT_NUM_TRIGGERS 3
39#endif
40
41#if GROUND_DETECT_USE_INDI_THRUST
43#endif
45
46#if GROUND_DETECT_USE_AGL_DIST
48#ifndef GROUND_DETECT_AGL_MIN_VALUE
49#define GROUND_DETECT_AGL_MIN_VALUE 0.1
50#endif
51#endif
53
54#ifndef GROUND_DETECT_USE_FORCE_SENSOR
55#define GROUND_DETECT_USE_FORCE_SENSOR 0
56#endif
57
58#ifndef GROUND_DETECT_FORCE_SENSOR_THRESHOLD
59#define GROUND_DETECT_FORCE_SENSOR_THRESHOLD 100000
60#endif
61
62#ifndef GROUND_DETECT_FORCE_SENSOR_MEDIAN_FILT_SIZE
63#define GROUND_DETECT_FORCE_SENSOR_MEDIAN_FILT_SIZE 3
64#endif
65
66#ifndef FORCE_SENSOR_MAX_NB
67#define FORCE_SENSOR_MAX_NB 16
68#endif
69
70#if GROUND_DETECT_USE_FORCE_SENSOR
71#ifndef GROUND_DETECT_FORCE_SENSOR_ID
72#define GROUND_DETECT_FORCE_SENSOR_ID ABI_BROADCAST
73#endif
74#endif
76
77#ifndef GROUND_DETECT_REVERSE_THRUST_ON_GROUND_DETECTED
78#define GROUND_DETECT_REVERSE_THRUST_ON_GROUND_DETECTED false
79#endif
81
82#if GROUND_DETECT_REVERSE_THRUST_ON_GROUND_DETECTED
83#ifndef GROUND_DETECT_REVERSE_THRUST_LEVEL
84#error "GROUND_DETECT_REVERSE_THRUST_LEVEL needs to be defined if GROUND_DETECT_REVERSE_THRUST_ON_GROUND_DETECTED is true"
85#endif
87#else
89#endif
90
91#ifndef GROUND_DETECT_SPECIFIC_THRUST_THRESHOLD
92#define GROUND_DETECT_SPECIFIC_THRUST_THRESHOLD -5.0
93#endif
95
96#ifndef GROUND_DETECT_VERTICAL_SPEED_THRESHOLD
97#define GROUND_DETECT_VERTICAL_SPEED_THRESHOLD 0.1
98#endif
100
101#ifndef GROUND_DETECT_VERTICAL_ACCEL_THRESHOLD
102#define GROUND_DETECT_VERTICAL_ACCEL_THRESHOLD -3.0
103#endif
105
106#ifndef GROUND_DETECT_COUNTER_TRIGGER
107#define GROUND_DETECT_COUNTER_TRIGGER 5
108#endif
109
110// Cutoff frequency of accelerometer filter in Hz
111#ifndef GROUND_DETECT_FILT_FREQ
112#define GROUND_DETECT_FILT_FREQ 5.0
113#endif
114
116
118bool ground_detected = false;
119
120bool reverse_thrust = false;
121
124
126
132
134
135#if GROUND_DETECT_USE_FORCE_SENSOR
137static bool force_sensor_valid = false;
139
140static void force_sensor_autoset_offset(void)
141{
142 if (!force_sensor_valid) {
143 return;
144 }
145
146 for (uint8_t i = 0; i < force_sensor.count; i++) {
148 }
149}
150
152{
153 uint8_t n = count;
154 if (n > FORCE_SENSOR_MAX_NB) {
156 }
157
159 force_sensor_valid = true;
160 for (uint8_t i = 0; i < n; i++) {
162 }
163}
164
165static bool force_sensor_detect_ground(void)
166{
167 if (!force_sensor_valid) {
168 return false;
169 }
170
171 for (uint8_t i = 0; i < force_sensor.count; i++) {
173 return true;
174 }
175 }
176 return false;
177}
178#endif
179
180#if PERIODIC_TELEMETRY
196#endif
197
198
200{
201 // Initialize the ground detection status
206 force_sensor.count = 1; // Needed for force sensor field in ground detect message
207 for (uint8_t i = 0; i < FORCE_SENSOR_MAX_NB; i++) {
208 force_sensor.offsets[i] = 0;
210 }
211
212 float tau = 1.0 / (2.0 * M_PI * GROUND_DETECT_FILT_FREQ);
213 float sample_time = 1.0 / PERIODIC_FREQUENCY;
215
216#if GROUND_DETECT_USE_FORCE_SENSOR
217 for (uint8_t i = 0; i < FORCE_SENSOR_MAX_NB; i++) {
219 }
221 force_sensor_valid = false;
223#endif
224
225#if PERIODIC_TELEMETRY
227#endif
228}
229
231{
232 return ground_detected;
233}
234
235// TODO: use standard pprz ground detection interface
236// bool autopilot_ground_detection(void) {
237// RunOnceEvery(10, printf("Running!\n"););
238// return ground_detected;
239// }
240
242{
243
244 // Evaluate thrust given (less than hover thrust)
245 // Use the control effectiveness in thrust in order to estimate the thrust delivered (only works for multicopters)
246 float specific_thrust = 0.0; // m/s2
247
248#if GROUND_DETECT_USE_INDI_THRUST
249 uint8_t i;
250 for (i = 0; i < INDI_NUM_ACT; i++) {
252 }
253#endif
254
255 // vertical component
258
259 // Evaluate vertical speed (close to zero, not at terminal velocity)
261
262 // Detect free fall (to be done, rearm?)
263
264 // Detect noise level (to be done)
265
266 // Detect ground based on AND of some triggers
267#if GROUND_DETECT_USE_FORCE_SENSOR
268 ground_detect_status.force_sensor_trigger = force_sensor_detect_ground();
269#else
270 ground_detect_status.force_sensor_trigger = false;
271#endif
272
274
275#if GROUND_DETECT_USE_INDI_THRUST
277#else
278 ground_detect_status.spec_thrust_trigger = false;
279#endif
280
282
283#if GROUND_DETECT_USE_AGL_DIST
286#else
287 ground_detect_status.agl_trigger = false;
288#endif
289
290 int trigger_sum = 0;
291 for(uint8_t i = 0; i < 16; i++) trigger_sum += (ground_detect_status.value >> i) & 0x1;
292
294 counter += 1;
296 ground_detected = true;
297
301 }
302 }
303 } else {
304 ground_detected = false;
305 counter = 0;
306 }
307}
308
318
320{
321 // Reverse thrust needs to be enabled with GROUND_DETECT_REVERSE_THRUST_ON_GROUND_DETECTED, and started through for example a flight plan block
323 return true;
324 } else {
325 return false;
326 }
327}
328
330{
331 reverse_thrust = false;
332}
333
335{
336 reverse_thrust = true;
337}
338
340{
342#if GROUND_DETECT_USE_FORCE_SENSOR
344#endif
345}
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
Definition abi_common.h:68
float agl_dist_valid
Definition agl_dist.c:33
float agl_dist_value_filtered
Definition agl_dist.c:35
Bind to agl ABI message and provide a filtered value to be used in flight plans.
bool autopilot_set_motors_on(bool motors_on)
turn motors on/off, eventually depending of the current mode set kill_throttle accordingly FIXME is i...
Definition autopilot.c:250
#define UNUSED(x)
static struct uart_periph * dev
#define GROUND_DETECT_VERTICAL_SPEED_THRESHOLD
void ground_detect_filter_accel(void)
Filter the vertical acceleration with a low cutoff frequency.
#define GROUND_DETECT_FORCE_SENSOR_THRESHOLD
int32_t values_filt[FORCE_SENSOR_MAX_NB]
#define GROUND_DETECT_FORCE_SENSOR_MEDIAN_FILT_SIZE
uint16_t reverse_th_level
void ground_detect_stop_reverse_thrust(void)
bool disarm_on_not_in_flight
bool ground_detect_reverse_thrust(void)
#define GROUND_DETECT_FILT_FREQ
#define GROUND_DETECT_COUNTER_TRIGGER
void ground_detect_init()
struct ground_detect_values_t ground_detect_values
int32_t offsets[FORCE_SENSOR_MAX_NB]
void ground_detect_start_reverse_thrust(void)
float force_sensor_ground_threshold
#define FORCE_SENSOR_MAX_NB
static struct force_sensor_data_t force_sensor
bool ground_detected
static void send_ground_detect(struct transport_tx *trans, struct link_device *dev)
bool ground_detect(void)
#define GROUND_DETECT_USE_FORCE_SENSOR
int32_t counter
#define GROUND_DETECT_REVERSE_THRUST_ON_GROUND_DETECTED
union ground_detect_bitmask_t ground_detect_status
bool reverse_thrust
#define GROUND_DETECT_VERTICAL_ACCEL_THRESHOLD
#define GROUND_DETECT_SPECIFIC_THRUST_THRESHOLD
#define GROUND_DETECT_NUM_TRIGGERS
void ground_detect_periodic()
void ground_detect_set_offset_sensors(bool set_offset)
Butterworth2LowPass accel_down_filt
rotation matrix
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
Definition state.h:1203
static struct FloatRMat * stateGetNedToBodyRMat_f(void)
Get vehicle body attitude rotation matrix (float).
Definition state.h:1308
static struct NedCoor_f * stateGetSpeedNed_f(void)
Get ground speed in local NED coordinates (float).
Definition state.h:1049
float o[2]
output history
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, const float tau, const float sample_time, const float value)
Init a second order Butterworth filter.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, const float value)
Update second order Butterworth low pass filter state with a new value.
uint16_t foo
Definition main_demo5.c:58
static void init_median_filter_i(struct MedianFilterInt *filter, uint8_t size)
static int32_t update_median_filter_i(struct MedianFilterInt *filter, int32_t new_data)
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
float z
in meters
vector in North East Down coordinates Units: meters
Rotorcraft specific autopilot interface and initialization.
bool act_is_servo[INDI_NUM_ACT]
float g1g2[INDI_OUTPUTS][INDI_NUM_ACT]
float actuator_state_filt_vect[INDI_NUM_ACT]
API to get/set the generic vehicle states.
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 short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.