Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
laser.hpp
1 // Copyright (c) 2018 Intel Corporation
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 
17 
18 #ifndef NAV2_AMCL__SENSORS__LASER__LASER_HPP_
19 #define NAV2_AMCL__SENSORS__LASER__LASER_HPP_
20 
21 #include "nav2_amcl/map/map.hpp"
22 #include "nav2_amcl/pf/pf.hpp"
23 #include "nav2_amcl/pf/pf_pdf.hpp"
24 #include "nav2_amcl/pf/pf_vector.hpp"
25 
26 namespace nav2_amcl
27 {
28 
29 // Forward declarations
30 class LaserData;
31 
32 /*
33  * @class Laser
34  * @brief Base class for laser sensor models
35  */
36 class Laser
37 {
38 public:
44  Laser(size_t max_beams, map_t * map);
45 
46  /*
47  * @brief Laser destructor
48  */
49  virtual ~Laser();
50 
51  /*
52  * @brief Run a sensor update on laser
53  * @param pf Particle filter to use
54  * @param data Laser data to use
55  * @return if it was successful
56  */
57  virtual bool sensorUpdate(pf_t * pf, LaserData * data) = 0;
58 
59  /*
60  * @brief Set the laser pose from an update
61  * @param laser_pose Pose of the laser
62  */
63  void SetLaserPose(pf_vector_t & laser_pose);
64 
65 protected:
66  double z_hit_;
67  double z_rand_;
68  double sigma_hit_;
69 
70  /*
71  * @brief Reallocate weights
72  * @param max_samples Max number of samples
73  * @param max_obs number of observations
74  */
75  void reallocTempData(int max_samples, int max_obs);
76  map_t * map_;
77  pf_vector_t laser_pose_;
78  int max_beams_;
79  int max_samples_;
80  int max_obs_;
81  double ** temp_obs_;
82 };
83 
84 /*
85  * @class LaserData
86  * @brief Class of laser data to process
87  */
88 class LaserData
89 {
90 public:
91  Laser * laser;
92 
93  /*
94  * @brief LaserData constructor
95  */
96  LaserData() {ranges = NULL;}
97  /*
98  * @brief LaserData destructor
99  */
100  virtual ~LaserData() {delete[] ranges;}
101 
102 public:
103  int range_count;
104  double range_max;
105  double(*ranges)[2];
106 };
107 
108 /*
109  * @class BeamModel
110  * @brief Beam model laser sensor
111  */
112 class BeamModel : public Laser
113 {
114 public:
115  /*
116  * @brief BeamModel constructor
117  */
118  BeamModel(
119  double z_hit, double z_short, double z_max, double z_rand, double sigma_hit,
120  double lambda_short, double chi_outlier, size_t max_beams, map_t * map);
121 
122  /*
123  * @brief Run a sensor update on laser
124  * @param pf Particle filter to use
125  * @param data Laser data to use
126  * @return if it was successful
127  */
128  bool sensorUpdate(pf_t * pf, LaserData * data);
129 
130 private:
131  static double sensorFunction(LaserData * data, pf_sample_set_t * set);
132  double z_short_;
133  double z_max_;
134  double lambda_short_;
135  double chi_outlier_;
136 };
137 
138 /*
139  * @class LikelihoodFieldModel
140  * @brief likelihood field model laser sensor
141  */
143 {
144 public:
145  /*
146  * @brief BeamModel constructor
147  */
149  double z_hit, double z_rand, double sigma_hit, double max_occ_dist,
150  size_t max_beams, map_t * map);
151 
152  /*
153  * @brief Run a sensor update on laser
154  * @param pf Particle filter to use
155  * @param data Laser data to use
156  * @return if it was successful
157  */
158  bool sensorUpdate(pf_t * pf, LaserData * data);
159 
160 private:
161  /*
162  * @brief Perform the update function
163  * @param data Laser data to use
164  * @param pf Particle filter to use
165  * @return if it was successful
166  */
167  static double sensorFunction(LaserData * data, pf_sample_set_t * set);
168 };
169 
170 /*
171  * @class LikelihoodFieldModelProb
172  * @brief likelihood prob model laser sensor
173  */
175 {
176 public:
177  /*
178  * @brief BeamModel constructor
179  */
181  double z_hit, double z_rand, double sigma_hit, double max_occ_dist,
182  bool do_beamskip, double beam_skip_distance,
183  double beam_skip_threshold, double beam_skip_error_threshold,
184  size_t max_beams, map_t * map);
185 
186  /*
187  * @brief Run a sensor update on laser
188  * @param pf Particle filter to use
189  * @param data Laser data to use
190  * @return if it was successful
191  */
192  bool sensorUpdate(pf_t * pf, LaserData * data);
193 
194 private:
195  /*
196  * @brief Perform the update function
197  * @param data Laser data to use
198  * @param pf Particle filter to use
199  * @return if it was successful
200  */
201  static double sensorFunction(LaserData * data, pf_sample_set_t * set);
202  bool do_beamskip_;
203  double beam_skip_distance_;
204  double beam_skip_threshold_;
205  double beam_skip_error_threshold_;
206 };
207 
208 } // namespace nav2_amcl
209 
210 #endif // NAV2_AMCL__SENSORS__LASER__LASER_HPP_
Laser(size_t max_beams, map_t *map)
A Laser constructor.
Definition: laser.cpp:29
Definition: pf.hpp:112
Definition: map.hpp:62