Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
30#include "state.h"
31
32#if USE_GROUND_DETECT_INDI_THRUST
34#endif
35
36#if USE_GROUND_DETECT_AGL_DIST
38#ifndef GROUND_DETECT_AGL_MIN_VALUE
39#define GROUND_DETECT_AGL_MIN_VALUE 0.1
40#endif
41#endif
42
43#include "pprzlink/messages.h"
45
46#define GROUND_DETECT_COUNTER_TRIGGER 5
47
48// Cutoff frequency of accelerometer filter in Hz
49#define GROUND_DETECT_FILT_FREQ 5.0
50
52
54
56bool ground_detected = false;
57
58#define DEBUG_GROUND_DETECT TRUE
59
61{
62 float tau = 1.0 / (2.0 * M_PI * GROUND_DETECT_FILT_FREQ);
63 float sample_time = 1.0 / PERIODIC_FREQUENCY;
65}
66
67bool ground_detect(void)
68{
69 return ground_detected;
70}
71
72// TODO: use standard pprz ground detection interface
73// bool autopilot_ground_detection(void) {
74// RunOnceEvery(10, printf("Running!\n"););
75// return ground_detected;
76// }
77
79{
80
81 // Evaluate thrust given (less than hover thrust)
82 // Use the control effectiveness in thrust in order to estimate the thrust delivered (only works for multicopters)
83 float specific_thrust = 0.0; // m/s2
84
85#if USE_GROUND_DETECT_INDI_THRUST
86 uint8_t i;
87 for (i = 0; i < INDI_NUM_ACT; i++) {
89 }
90#endif
91
92 // vertical component
93 float spec_thrust_down;
96
97 // Evaluate vertical speed (close to zero, not at terminal velocity)
99
100 // Detect free fall (to be done, rearm?)
101
102 // Detect noise level (to be done)
103
104 // Detect ground based on AND of all triggers
105 if ((fabsf(vspeed_ned) < 5.0)
106 && (spec_thrust_down > -5.0)
107 && (fabsf(accel_filter.o[0]) < 2.0)
110#endif
111 ) {
112
113 counter += 1;
115 ground_detected = true;
116
120 }
121 }
122 } else {
123 ground_detected = false;
124 counter = 0;
125 }
126
127#ifdef DEBUG_GROUND_DETECT
128 float payload[7];
129 payload[0] = vspeed_ned;
130 payload[1] = spec_thrust_down;
131 payload[2] = accel_filter.o[0];
132 payload[3] = stateGetAccelNed_f()->z;
133#if USE_GROUND_DETECT_AGL_DIST
134 payload[4] = agl_dist_valid;
135 payload[5] = agl_dist_value_filtered;
136#else
137 payload[4] = 0;
138 payload[5] = 0;
139#endif
140 payload[6] = 1.f * ground_detected;
141
143#endif
144}
145
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
Butterworth2LowPass accel_filter
void ground_detect_filter_accel(void)
Filter the vertical acceleration with a low cutoff frequency.
bool disarm_on_not_in_flight
#define GROUND_DETECT_FILT_FREQ
#define GROUND_DETECT_COUNTER_TRIGGER
void ground_detect_init()
bool ground_detected
bool ground_detect(void)
int32_t counter
void ground_detect_periodic()
rotation matrix
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
Definition state.h:1195
static struct FloatRMat * stateGetNedToBodyRMat_f(void)
Get vehicle body attitude rotation matrix (float).
Definition state.h:1300
static struct NedCoor_f * stateGetSpeedNed_f(void)
Get ground speed in local NED coordinates (float).
Definition state.h:1049
Simple first order low pass filter with bilinear transform.
float o[2]
output history
static void init_butterworth_2_low_pass(Butterworth2LowPass *filter, float tau, float sample_time, float value)
Init a second order Butterworth filter.
static float update_butterworth_2_low_pass(Butterworth2LowPass *filter, float value)
Update second order Butterworth low pass filter state with a new value.
Second order low pass filter structure.
uint16_t foo
Definition main_demo5.c:58
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.
int int32_t
Typedef defining 32 bit int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.