Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
29 #include "modules/sonar/agl_dist.h"
30 #include "subsystems/abi.h"
31 #include "generated/airframe.h"
32 
36 
38 #ifndef AGL_DIST_SONAR_ID
39 #define AGL_DIST_SONAR_ID ABI_BROADCAST
40 #endif
41 #ifndef AGL_DIST_SONAR_MAX_RANGE
42 #define AGL_DIST_SONAR_MAX_RANGE 5.0
43 #endif
44 #ifndef AGL_DIST_SONAR_MIN_RANGE
45 #define AGL_DIST_SONAR_MIN_RANGE 0.001
46 #endif
47 #ifndef AGL_DIST_SONAR_FILTER
48 #define AGL_DIST_SONAR_FILTER 5
49 #endif
50 
52 
53 static void sonar_cb(uint8_t sender_id, float distance);
54 
55 void agl_dist_init(void)
56 {
57  agl_dist_valid = false;
58  agl_dist_value = 0.;
60 
61  // Bind to AGL message
62  AbiBindMsgAGL(AGL_DIST_SONAR_ID, &sonar_ev, sonar_cb);
63 }
64 
65 
66 static void sonar_cb(uint8_t __attribute__((unused)) sender_id, float distance)
67 {
68  if (distance < AGL_DIST_SONAR_MAX_RANGE && distance > AGL_DIST_SONAR_MIN_RANGE) {
69  agl_dist_value = distance;
70  agl_dist_valid = true;
73  } else {
74  agl_dist_valid = false;
75  }
76 }
77 
Event structure to store callbacks in a linked list.
Definition: abi_common.h:65
abi_event sonar_ev
Definition: agl_dist.c:51
Main include for ABI (AirBorneInterface).
#define AGL_DIST_SONAR_MIN_RANGE
Definition: agl_dist.c:45
static void sonar_cb(uint8_t sender_id, float distance)
Definition: agl_dist.c:66
#define AGL_DIST_SONAR_FILTER
Definition: agl_dist.c:48
#define AGL_DIST_SONAR_ID
default sonar
Definition: agl_dist.c:39
void agl_dist_init(void)
Definition: agl_dist.c:55
Bind to sonar ABI message and provide a filtered value to be used in flight plans.
float agl_dist_value
Definition: agl_dist.c:34
unsigned char uint8_t
Definition: types.h:14
float agl_dist_valid
Definition: agl_dist.c:33
float agl_dist_value_filtered
Definition: agl_dist.c:35