Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
nps_sensor_sonar.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Felix Ruess <felix.ruess@gmail.com
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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
29 #include "nps_sensor_sonar.h"
30 
31 #include "generated/airframe.h"
32 
33 #include "std.h"
34 #include "nps_fdm.h"
35 #include "nps_random.h"
36 #include "nps_sensors.h"
37 
39 #ifndef NPS_SONAR_DT
40 #define NPS_SONAR_DT 0.01
41 #endif
42 
44 #ifndef NPS_SONAR_NOISE_STD_DEV
45 #define NPS_SONAR_NOISE_STD_DEV 0.01
46 #endif
47 
48 #ifndef NPS_SONAR_OFFSET
49 #define NPS_SONAR_OFFSET 0
50 #endif
51 
52 #ifndef NPS_SONAR_MIN_DIST
53 #define NPS_SONAR_MIN_DIST 0.1f
54 #endif
55 
56 #ifndef NPS_SONAR_MAX_DIST
57 #define NPS_SONAR_MAX_DIST 7.0f
58 #endif
59 
61 {
62  sonar->value = 0.;
63  sonar->offset = NPS_SONAR_OFFSET;
64  sonar->noise_std_dev = NPS_SONAR_NOISE_STD_DEV;
65  sonar->next_update = time;
66  sonar->data_available = FALSE;
67 }
68 
69 
71 {
72 
73  if (time < sonar->next_update) {
74  return;
75  }
76 
77  /* agl in meters */
78  sonar->value = fdm.agl + sonar->offset;
79  /* add noise with std dev meters */
80  sonar->value += get_gaussian_noise() * sonar->noise_std_dev;
81  /* bound value */
83 
84  sonar->next_update += NPS_SONAR_DT;
85  sonar->data_available = TRUE;
86 }
double agl
Definition: nps_fdm.h:61
struct NpsFdm fdm
Holds all necessary NPS FDM state information.
std::shared_ptr< gazebo::sensors::SonarSensor > sonar
double get_gaussian_noise(void)
Definition: nps_random.c:109
#define NPS_SONAR_OFFSET
#define NPS_SONAR_NOISE_STD_DEV
standard devition in meters (default 1cm)
void nps_sensor_sonar_run_step(struct NpsSensorSonar *sonar, double time)
#define NPS_SONAR_DT
10Hz default
void nps_sensor_sonar_init(struct NpsSensorSonar *sonar, double time)
#define NPS_SONAR_MIN_DIST
#define NPS_SONAR_MAX_DIST
Simulated sonar for NPS simulator.
#define TRUE
Definition: std.h:4
#define FALSE
Definition: std.h:5