lidar_measurement_model_beam.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, the mcl_3dl authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDEDNode BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <algorithm>
31 #include <string>
32 #include <vector>
33 
34 #include <ros/ros.h>
35 
36 #include <pcl/point_types.h>
37 #include <pcl_ros/point_cloud.h>
38 
39 #include <mcl_3dl/pf.h>
41 #include <mcl_3dl/point_types.h>
42 #include <mcl_3dl/raycast.h>
43 #include <mcl_3dl/vec3.h>
44 
46 
47 namespace mcl_3dl
48 {
50  const float x, const float y, const float z)
51 {
52  // FIXME(at-wat): remove NOLINT after clang-format or roslint supports it
53  map_grid_min_ = std::min({ x, y, z }); // NOLINT(whitespace/braces)
54  map_grid_max_ = std::max({ x, y, z }); // NOLINT(whitespace/braces)
55 }
56 
58  const ros::NodeHandle& nh,
59  const std::string& name)
60 {
61  ros::NodeHandle pnh(nh, name);
62 
63  int num_points, num_points_global;
64  pnh.param("num_points", num_points, 3);
65  pnh.param("num_points_global", num_points_global, 0);
66  num_points_default_ = num_points_ = num_points;
67  num_points_global_ = num_points_global;
68 
69  double clip_near, clip_far;
70  pnh.param("clip_near", clip_near, 0.5);
71  pnh.param("clip_far", clip_far, 4.0);
72  clip_near_sq_ = clip_near * clip_near;
73  clip_far_sq_ = clip_far * clip_far;
74 
75  double clip_z_min, clip_z_max;
76  pnh.param("clip_z_min", clip_z_min, -2.0);
77  pnh.param("clip_z_max", clip_z_max, 2.0);
78  clip_z_min_ = clip_z_min;
79  clip_z_max_ = clip_z_max;
80 
81  double beam_likelihood_min;
82  pnh.param("beam_likelihood", beam_likelihood_min, 0.2);
83  beam_likelihood_min_ = beam_likelihood_min;
84  beam_likelihood_ = powf(beam_likelihood_min, 1.0 / static_cast<float>(num_points));
85 
86  double ang_total_ref;
87  pnh.param("ang_total_ref", ang_total_ref, M_PI / 6.0);
88  sin_total_ref_ = sinf(ang_total_ref);
89 }
90 
92  const size_t num_particles,
93  const size_t current_num_particles)
94 {
95  if (current_num_particles <= num_particles)
96  {
98  return;
99  }
100  size_t num = num_points_default_ * num_particles / current_num_particles;
101  if (num < num_points_global_)
102  num = num_points_global_;
103 
104  num_points_ = num;
105 }
106 
107 typename pcl::PointCloud<LidarMeasurementModelBase::PointType>::Ptr
109  const typename pcl::PointCloud<LidarMeasurementModelBase::PointType>::ConstPtr& pc) const
110 {
111  const auto local_points_filter = [this](const LidarMeasurementModelBase::PointType& p)
112  {
113  if (p.x * p.x + p.y * p.y > clip_far_sq_)
114  return true;
115  if (p.x * p.x + p.y * p.y < clip_near_sq_)
116  return true;
117  if (p.z < clip_z_min_ || clip_z_max_ < p.z)
118  return true;
119  return false;
120  };
121  pcl::PointCloud<LidarMeasurementModelBase::PointType>::Ptr pc_filtered(
122  new pcl::PointCloud<LidarMeasurementModelBase::PointType>);
123  *pc_filtered = *pc;
124  pc_filtered->erase(
125  std::remove_if(pc_filtered->begin(), pc_filtered->end(), local_points_filter), pc_filtered->end());
126  pc_filtered->width = 1;
127  pc_filtered->height = pc_filtered->points.size();
128 
130 }
131 
134  const typename pcl::PointCloud<LidarMeasurementModelBase::PointType>::ConstPtr& pc,
135  const std::vector<Vec3>& origins,
136  const State6DOF& s) const
137 {
138  if (!pc)
139  return LidarMeasurementResult(1, 0);
140  if (pc->size() == 0)
141  return LidarMeasurementResult(1, 0);
142  pcl::PointCloud<LidarMeasurementModelBase::PointType>::Ptr pc_particle(
143  new pcl::PointCloud<LidarMeasurementModelBase::PointType>);
144  std::vector<int> id(1);
145  std::vector<float> sqdist(1);
146 
147  float score_beam = 1.0;
148  *pc_particle = *pc;
149  s.transform(*pc_particle);
150  for (auto& p : pc_particle->points)
151  {
152  const int beam_header_id = p.label;
154  kdtree,
155  s.pos_ + s.rot_ * origins[beam_header_id],
156  Vec3(p.x, p.y, p.z),
158  for (auto point : ray)
159  {
160  if (point.collision_)
161  {
162  // reject total reflection
163  if (point.sin_angle_ > sin_total_ref_)
164  {
165  score_beam *= beam_likelihood_;
166  }
167  break;
168  }
169  }
170  }
171  if (score_beam < beam_likelihood_min_)
172  score_beam = beam_likelihood_min_;
173 
174  return LidarMeasurementResult(score_beam, 1.0);
175 }
176 } // namespace mcl_3dl
void transform(pcl::PointCloud< PointType > &pc) const
Definition: state_6dof.h:183
pcl::PointCloud< PointType >::Ptr filter(const pcl::PointCloud< PointType >::ConstPtr &pc) const
std::shared_ptr< ChunkedKdtree > Ptr
mcl_3dl::Vec3 pos_
Definition: state_6dof.h:47
LidarMeasurementModelBeam(const float x, const float y, const float z)
LidarMeasurementResult measure(ChunkedKdtree< PointType >::Ptr &kdtree, const pcl::PointCloud< PointType >::ConstPtr &pc, const std::vector< Vec3 > &origins, const State6DOF &s) const
bool param(const std::string &param_name, T &param_val, const T &default_val) const
pcl::PointCloud< POINT_TYPE >::Ptr sample(const typename pcl::PointCloud< POINT_TYPE >::ConstPtr &pc, const size_t num) const
mcl_3dl::Quat rot_
Definition: state_6dof.h:48
void setGlobalLocalizationStatus(const size_t num_particles, const size_t current_num_particles)
void loadConfig(const ros::NodeHandle &nh, const std::string &name)


mcl_3dl
Author(s): Atsushi Watanabe
autogenerated on Mon Jul 8 2019 03:32:36