lidar_measurement_model_likelihood.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/vec3.h>
43 
45 
46 namespace mcl_3dl
47 {
49  const ros::NodeHandle& nh,
50  const std::string& name)
51 {
52  ros::NodeHandle pnh(nh, name);
53 
54  int num_points, num_points_global;
55  pnh.param("num_points", num_points, 96);
56  pnh.param("num_points_global", num_points_global, 8);
57  num_points_default_ = num_points_ = num_points;
58  num_points_global_ = num_points_global;
59 
60  double clip_near, clip_far;
61  pnh.param("clip_near", clip_near, 0.5);
62  pnh.param("clip_far", clip_far, 10.0);
63  clip_near_sq_ = clip_near * clip_near;
64  clip_far_sq_ = clip_far * clip_far;
65 
66  double clip_z_min, clip_z_max;
67  pnh.param("clip_z_min", clip_z_min, -2.0);
68  pnh.param("clip_z_max", clip_z_max, 2.0);
69  clip_z_min_ = clip_z_min;
70  clip_z_max_ = clip_z_max;
71 
72  double match_weight;
73  pnh.param("match_weight", match_weight, 5.0);
74  match_weight_ = match_weight;
75 
76  double match_dist_min, match_dist_flat;
77  pnh.param("match_dist_min", match_dist_min, 0.2);
78  pnh.param("match_dist_flat", match_dist_flat, 0.05);
79  match_dist_min_ = match_dist_min;
80  match_dist_flat_ = match_dist_flat;
81 }
83  const size_t num_particles,
84  const size_t current_num_particles)
85 {
86  if (current_num_particles <= num_particles)
87  {
89  return;
90  }
91  size_t num = num_points_default_ * num_particles / current_num_particles;
92  if (num < num_points_global_)
93  num = num_points_global_;
94 
95  num_points_ = num;
96 }
97 
98 typename pcl::PointCloud<LidarMeasurementModelBase::PointType>::Ptr
100  const typename pcl::PointCloud<LidarMeasurementModelBase::PointType>::ConstPtr& pc) const
101 {
102  const auto local_points_filter = [this](const LidarMeasurementModelBase::PointType& p)
103  {
104  if (p.x * p.x + p.y * p.y > clip_far_sq_)
105  return true;
106  if (p.x * p.x + p.y * p.y < clip_near_sq_)
107  return true;
108  if (p.z < clip_z_min_ || clip_z_max_ < p.z)
109  return true;
110  return false;
111  };
112  pcl::PointCloud<LidarMeasurementModelBase::PointType>::Ptr pc_filtered(
113  new pcl::PointCloud<LidarMeasurementModelBase::PointType>);
114  *pc_filtered = *pc;
115  pc_filtered->erase(
116  std::remove_if(pc_filtered->begin(), pc_filtered->end(), local_points_filter), pc_filtered->end());
117  pc_filtered->width = 1;
118  pc_filtered->height = pc_filtered->points.size();
119 
121 }
122 
125  const typename pcl::PointCloud<LidarMeasurementModelBase::PointType>::ConstPtr& pc,
126  const std::vector<Vec3>& origins,
127  const State6DOF& s) const
128 {
129  if (!pc)
130  return LidarMeasurementResult(1, 0);
131  if (pc->size() == 0)
132  return LidarMeasurementResult(1, 0);
133  pcl::PointCloud<LidarMeasurementModelBase::PointType>::Ptr pc_particle(
134  new pcl::PointCloud<LidarMeasurementModelBase::PointType>);
135  std::vector<int> id(1);
136  std::vector<float> sqdist(1);
137 
138  float score_like = 0;
139  *pc_particle = *pc;
140  s.transform(*pc_particle);
141  size_t num = 0;
142  for (auto& p : pc_particle->points)
143  {
144  if (kdtree->radiusSearch(p, match_dist_min_, id, sqdist, 1))
145  {
146  const float dist = match_dist_min_ - std::max(sqrtf(sqdist[0]), match_dist_flat_);
147  if (dist < 0.0)
148  continue;
149 
150  score_like += dist * match_weight_;
151  num++;
152  }
153  }
154  const float match_ratio = static_cast<float>(num) / pc_particle->points.size();
155 
156  return LidarMeasurementResult(score_like, match_ratio);
157 }
158 } // namespace mcl_3dl
LidarMeasurementResult measure(ChunkedKdtree< PointType >::Ptr &kdtree, const pcl::PointCloud< PointType >::ConstPtr &pc, const std::vector< Vec3 > &origins, const State6DOF &s) const
void transform(pcl::PointCloud< PointType > &pc) const
Definition: state_6dof.h:183
std::shared_ptr< ChunkedKdtree > Ptr
void setGlobalLocalizationStatus(const size_t num_particles, const size_t current_num_particles)
pcl::PointCloud< PointType >::Ptr filter(const pcl::PointCloud< PointType >::ConstPtr &pc) const
void loadConfig(const ros::NodeHandle &nh, const std::string &name)
int radiusSearch(const POINT_TYPE &p, const float &radius, std::vector< int > &id, std::vector< float > &dist_sq, const size_t &num)
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
Author(s): Atsushi Watanabe
autogenerated on Mon Jul 8 2019 03:32:36