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
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#ifndef GROUND_DETECT_SPECIFIC_THRUST_THRESHOLD
44#define GROUND_DETECT_SPECIFIC_THRUST_THRESHOLD -5.0
45#endif
46
47#include "pprzlink/messages.h"
49
50#define GROUND_DETECT_COUNTER_TRIGGER 5
51
52// Cutoff frequency of accelerometer filter in Hz
53#define GROUND_DETECT_FILT_FREQ 5.0
54
56
58
60bool ground_detected = false;
61
62#define DEBUG_GROUND_DETECT TRUE
63
65{
66 float tau = 1.0 / (2.0 * M_PI * GROUND_DETECT_FILT_FREQ);
67 float sample_time = 1.0 / PERIODIC_FREQUENCY;
69}
70
71bool ground_detect(void)
72{
73 return ground_detected;
74}
75
76// TODO: use standard pprz ground detection interface
77// bool autopilot_ground_detection(void) {
78// RunOnceEvery(10, printf("Running!\n"););
79// return ground_detected;
80// }
81
83{
84
85 // Evaluate thrust given (less than hover thrust)
86 // Use the control effectiveness in thrust in order to estimate the thrust delivered (only works for multicopters)
87 float specific_thrust = 0.0; // m/s2
88
89#if USE_GROUND_DETECT_INDI_THRUST
90 uint8_t i;
91 for (i = 0; i < INDI_NUM_ACT; i++) {
93 }
94#endif
95
96 // vertical component
97 float spec_thrust_down;
100
101 // Evaluate vertical speed (close to zero, not at terminal velocity)
103
104 // Detect free fall (to be done, rearm?)
105
106 // Detect noise level (to be done)
107
108 // Detect ground based on AND of all triggers
109 if ((fabsf(vspeed_ned) < 5.0)
111 && (fabsf(accel_filter.o[0]) < 2.0)
114#endif
115 ) {
116
117 counter += 1;
119 ground_detected = true;
120
124 }
125 }
126 } else {
127 ground_detected = false;
128 counter = 0;
129 }
130
131#ifdef DEBUG_GROUND_DETECT
132 float payload[7];
133 payload[0] = vspeed_ned;
134 payload[1] = spec_thrust_down;
135 payload[2] = accel_filter.o[0];
136 payload[3] = stateGetAccelNed_f()->z;
137#if USE_GROUND_DETECT_AGL_DIST
138 payload[4] = agl_dist_valid;
139 payload[5] = agl_dist_value_filtered;
140#else
141 payload[4] = 0;
142 payload[5] = 0;
143#endif
144 payload[6] = 1.f * ground_detected;
145
147#endif
148}
149
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
#define GROUND_DETECT_SPECIFIC_THRUST_THRESHOLD
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.