test_beam_likelihood.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, 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 PROVIDED 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 <cmath>
31 #include <cstddef>
32 #include <vector>
33 
34 #include <gtest/gtest.h>
35 
36 #include <ros/ros.h>
37 
38 #include <mcl_3dl/chunked_kdtree.h>
40 #include <mcl_3dl/vec3.h>
41 
42 TEST(BeamModel, LikelihoodFunc)
43 {
44  pcl::PointCloud<mcl_3dl::LidarMeasurementModelBase::PointType> pc;
45  for (float y = -0.2; y <= 0.2; y += 0.1)
46  {
47  for (float z = -0.2; z <= 0.2; z += 0.1)
48  {
50  p.x = 2;
51  p.y = y;
52  p.z = z;
53  pc.push_back(p);
54  }
55  }
56  pcl::PointCloud<mcl_3dl::LidarMeasurementModelBase::PointType> pc_map = pc;
57  {
58  // Add dummy points to expand DDA grid size.
60  p.x = -100.05;
61  p.y = 100;
62  p.z = -0.05;
63  pc_map.push_back(p);
64  p.x = 100;
65  p.y = -100.05;
66  p.z = 4;
67  pc_map.push_back(p);
68  }
69 
72  kdtree->setInputCloud(pc_map.makeShared());
73 
74  for (int method = 0; method < 2; ++method)
75  {
76  for (int mode = 0; mode < 2; ++mode)
77  {
78  for (double hr = 0.0; hr <= 1.0; hr += 0.2)
79  {
80  ros::NodeHandle pnh("~");
81  pnh.setParam("beam/num_points", static_cast<int>(pc.size()));
82  pnh.setParam("beam/beam_likelihood", 0.2);
83  pnh.setParam("beam/hit_range", hr);
84  pnh.setParam("beam/use_raycast_using_dda", method == 1);
85  pnh.setParam("beam/add_penalty_short_only_mode", mode == 1);
86  pnh.setParam("beam/dda_grid_size", 0.1);
87 
88  mcl_3dl::LidarMeasurementModelBeam model(0.1, 0.1, 0.1);
89  model.loadConfig(pnh, "beam");
90 
91  std::cerr << "use_raycast_using_dda: " << (method == 1) << ", ";
92  std::cerr << "add_penalty_short_only_mode: " << (mode == 1) << ", ";
93  std::cerr << "hit_range: " << hr << std::endl;
94  for (int i = -50; i < 50; i++)
95  {
96  if (i == 0)
97  std::cerr << "0";
98  else if (i % 10 == 0)
99  std::cerr << "|";
100  else
101  std::cerr << " ";
102  }
103  std::cerr << std::endl;
104  for (int i = -50; i < 50; i++)
105  {
106  const float x = 0.1 * i;
107  const mcl_3dl::Vec3 pos(x, 0, 0);
108  const std::vector<mcl_3dl::Vec3> origins = { pos }; // NOLINT(whitespace/braces)
110  kdtree, pc.makeShared(), origins,
112  if (v.likelihood < 1.0 / 8)
113  std::cerr << "_";
114  else if (v.likelihood < 2.0 / 8)
115  std::cerr << "▁";
116  else if (v.likelihood < 3.0 / 8)
117  std::cerr << "▂";
118  else if (v.likelihood < 4.0 / 8)
119  std::cerr << "▃";
120  else if (v.likelihood < 5.0 / 8)
121  std::cerr << "▄";
122  else if (v.likelihood < 6.0 / 8)
123  std::cerr << "▅";
124  else if (v.likelihood < 7.0 / 8)
125  std::cerr << "▆";
126  else
127  std::cerr << "▇";
128  }
129  std::cerr << std::endl;
130  for (int i = -50; i < 50; i++)
131  {
132  const float x = 0.1 * i;
133  const mcl_3dl::Vec3 p(x, 0, 0);
136  kdtree, mcl_3dl::Vec3(), p, result);
137  switch (s)
138  {
140  std::cerr << "s";
141  break;
143  std::cerr << "*";
144  break;
146  std::cerr << "l";
147  break;
149  std::cerr << "t";
150  break;
151  }
152  }
153  std::cerr << std::endl;
154  }
155  }
156  }
157 }
158 
159 int main(int argc, char** argv)
160 {
161  testing::InitGoogleTest(&argc, argv);
162  ros::init(argc, argv, "test_beam_likelihood");
163 
164  return RUN_ALL_TESTS();
165 }
XmlRpcServer s
std::shared_ptr< ChunkedKdtree > Ptr
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void setInputCloud(const typename pcl::PointCloud< POINT_TYPE >::ConstPtr &cloud)
TFSIMD_FORCE_INLINE const tfScalar & y() const
LidarMeasurementResult measure(ChunkedKdtree< PointType >::Ptr &kdtree, const pcl::PointCloud< PointType >::ConstPtr &pc, const std::vector< Vec3 > &origins, const State6DOF &s) const
TEST(BeamModel, LikelihoodFunc)
BeamStatus getBeamStatus(ChunkedKdtree< PointType >::Ptr &kdtree, const Vec3 &beam_begin, const Vec3 &beam_end, typename mcl_3dl::Raycast< PointType >::CastResult &result) const
int main(int argc, char **argv)
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
void loadConfig(const ros::NodeHandle &nh, const std::string &name)
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const


mcl_3dl
Author(s): Atsushi Watanabe
autogenerated on Wed May 12 2021 02:16:29