Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
agl_dist.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 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
30#include "modules/core/abi.h"
31#include "generated/airframe.h"
33
38
40#ifndef AGL_DIST_ID
41#define AGL_DIST_ID ABI_BROADCAST
42#endif
43#ifndef AGL_DIST_MAX_RANGE
44#define AGL_DIST_MAX_RANGE 5.0f
45#endif
46#ifndef AGL_DIST_MIN_RANGE
47#define AGL_DIST_MIN_RANGE 0.001f
48#endif
49#ifndef AGL_DIST_FILTER
50#define AGL_DIST_FILTER 0.1f
51#endif
52
53#ifndef AGL_DIST_TIMEOUT
54#define AGL_DIST_TIMEOUT 1.f
55#endif
56
58static void agl_cb(uint8_t sender_id, uint32_t stamp, float distance);
59
60
61#if PREFLIGHT_CHECKS && defined(AGL_DIST_MIN_DISTANCE_CHECK) && defined(AGL_DIST_MAX_DISTANCE_CHECK)
62/* Preflight checks */
65
66static void agl_dist_preflight(struct preflight_result_t *result) {
68 preflight_success(result, "AGL within limits %.2f < %.2f < %.2f", AGL_DIST_MIN_DISTANCE_CHECK, agl_dist_value, AGL_DIST_MAX_DISTANCE_CHECK);
69 } else {
70 preflight_error(result, "AGL outside limits %.2f < %.2f < %.2f", AGL_DIST_MIN_DISTANCE_CHECK, agl_dist_value, AGL_DIST_MAX_DISTANCE_CHECK);
71 }
72}
73#endif // PREFLIGHT_CHECKS && defined(AGL_DIST_MIN_DISTANCE_CHECK) && defined(AGL_DIST_MAX_DISTANCE_CHECK)
74
75void agl_dist_init(void)
76{
77 agl_dist_valid = false;
78 agl_dist_value = 0.f;
81
82 // Bind to AGL message
84
85 /* Register preflight checks */
86#if PREFLIGHT_CHECKS && defined(AGL_DIST_MIN_DISTANCE_CHECK) && defined(AGL_DIST_MAX_DISTANCE_CHECK)
88#endif // PREFLIGHT_CHECKS && defined(AGL_DIST_MIN_DISTANCE_CHECK) && defined(AGL_DIST_MAX_DISTANCE_CHECK)
89}
90
91static void agl_cb(uint8_t __attribute__((unused)) sender_id, uint32_t __attribute__((unused)) stamp, float distance)
92{
94 agl_dist_value = distance;
95 agl_dist_valid = true;
96 float now = get_sys_time_float();
97 float dt = now - agl_measurement_time;
99
100 // update multirate exponentially weighted moving average filter
102 } else {
103 agl_dist_valid = false;
104 }
105}
106
109 if(dt > AGL_DIST_TIMEOUT) {
110 agl_dist_valid = false;
111 }
112}
113
114
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
Definition abi_common.h:68
float agl_measurement_time
Definition agl_dist.c:37
float agl_dist_valid
Definition agl_dist.c:34
#define AGL_DIST_TIMEOUT
Definition agl_dist.c:54
float agl_dist_value
Definition agl_dist.c:35
float agl_dist_value_filtered
Definition agl_dist.c:36
#define AGL_DIST_FILTER
Definition agl_dist.c:50
static void agl_cb(uint8_t sender_id, uint32_t stamp, float distance)
Definition agl_dist.c:91
void agl_dist_init(void)
Definition agl_dist.c:75
#define AGL_DIST_ID
default sonar
Definition agl_dist.c:41
void agl_dist_timeout(void)
Definition agl_dist.c:107
#define AGL_DIST_MIN_RANGE
Definition agl_dist.c:47
void agl_dist_report(void)
Definition agl_dist.c:115
abi_event agl_ev
Definition agl_dist.c:57
Bind to agl ABI message and provide a filtered value to be used in flight plans.
uint16_t foo
Definition main_demo5.c:58
void preflight_error(struct preflight_result_t *result, const char *fmt,...)
Register a preflight error used inside the preflight checking functions.
void preflight_success(struct preflight_result_t *result, const char *fmt,...)
Register a preflight success used inside the preflight checking functions.
void preflight_check_register(struct preflight_check_t *check, preflight_check_f func)
Register a preflight check and add it to the linked list.
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition sys_time.h:174
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
uint16_t f
Camera baseline, in meters (i.e. horizontal distance between the two cameras of the stereo setup)
Definition wedgebug.c:204