test_filter_ray_trace.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include "filters.hpp"
4 #include <filters/filter_chain.h>
5 
6 #define GTEST_COUT std::cerr << "[ INFO ] "
7 
8 TEST(RayTrace, active)
9 {
10  EXPECT_EQ(0, 0);
11 }
12 
17 TEST(RayTrace, layers_dont_exist)
18 {
19  ros::NodeHandle nh("~");
20 
21  grid_map::GridMap gridMap({"random_layer"});
22  gridMap.setFrameId("random");
23  gridMap.setGeometry(grid_map::Length(3, 3), 1);
24 
25  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
26 
27  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
28  {
29  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
30  }
31 
32  EXPECT_FALSE(filterChain.update(gridMap, gridMap));
33 
34  // Add the non ground layer, still missing ground layer
35  gridMap.add("nonground", 0);
36  EXPECT_FALSE(filterChain.update(gridMap, gridMap));
37 
38  // Add ground layer, should now work
39  gridMap.add("ground", 0);
40  EXPECT_TRUE(filterChain.update(gridMap, gridMap));
41 }
42 
60 TEST(RayTrace, fully_open)
61 {
62  ros::NodeHandle nh("~");
63  grid_map::GridMap gridMap({"nonground"});
64  gridMap.setFrameId("map");
65  gridMap.setGeometry(grid_map::Length(3, 3), 1);
66 
67  // Initialize ground as every cell having received one point
68  gridMap.add("ground", 1);
69 
70  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
71 
72  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
73  {
74  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
75  }
76 
77  if(!filterChain.update(gridMap, gridMap))
78  {
79  GTEST_FATAL_FAILURE_("Unable to update grid map.");
80  }
81 
82  // Check each cell to see if was ray traced to 0
83  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
84  {
85  const grid_map::Index index(*it);
86 
87  EXPECT_EQ(1, gridMap.at("ground", index));
88  EXPECT_EQ(0, gridMap.at("nonground", index));
89  }
90 }
91 
92 
122 TEST(RayTrace, front_blocked)
123 {
124  ros::NodeHandle nh("~");
125  grid_map::GridMap gridMap({"occupancy"});
126  gridMap.setFrameId("map");
127  gridMap.setGeometry(grid_map::Length(5, 5), 1);
128 
129  // Initialize nonground
130  gridMap.add("ground", 0);
131  gridMap.add("nonground", 0);
132  gridMap.at("nonground", grid_map::Index(1,1)) = 100;
133  gridMap.at("nonground", grid_map::Index(1,2)) = 100;
134  gridMap.at("nonground", grid_map::Index(1,3)) = 100;
135 
136  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
137 
138  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
139  {
140  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
141  }
142 
143  if(!filterChain.update(gridMap, gridMap))
144  {
145  GTEST_FATAL_FAILURE_("Unable to update grid map.");
146  }
147 
148  /*
149  Uncomment to see that the line iterator will hit the occupied cells (1,1) and (1, 3)
150  before getting to (1, 0) and (1, 4), thus getting in the way of our "ray"
151  */
152  // for(grid_map::LineIterator it(gridMap, grid_map::Index(2, 2), grid_map::Index(1,0)); !it.isPastEnd(); ++it)
153  // {
154  // grid_map::Index index(*it);
155  // GTEST_COUT << index(0) << ", " << index(1) << std::endl;
156  // }
157 
158  gridMap["occupancy"] = gridMap["ground"] + gridMap["nonground"];
159 
160  Eigen::MatrixXi answerMat(5, 5);
161  answerMat <<
162  20, 20, 20, 20, 20,
163  20, 100, 100, 100, 20,
164  0, 0, 0, 0, 0,
165  0, 0, 0, 0, 0,
166  0, 0, 0, 0, 0;
167 
168  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
169  {
170  const grid_map::Index index(*it);
171 
172  // Check that occupancy matches the expected answer
173  EXPECT_EQ(answerMat(index(0), index(1)), gridMap.at("occupancy", index));
174  }
175 }
176 
177 /*************
178  * Performs ray tracing operation on various size grids in order to ensure
179  * the math is performed correctly. In the past we have had small errors
180  * that caused cell calculations to be out of bounds.
181  ************/
182 TEST(RayTrace, stress_test)
183 {
184  ros::NodeHandle nh("~");
185  grid_map::GridMap gridMap({"occupancy"});
186  gridMap.setFrameId("map");
187  // Initialize nonground
188  gridMap.add("ground", 0);
189  gridMap.add("nonground", 0);
190 
191  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
192  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
193  {
194  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
195  }
196 
197  for (int i = 5; i < 100; i+=3)
198  {
199  for (int j = 1; j <= 10; j++)
200  {
201  gridMap.setGeometry(grid_map::Length(i, i), 0.1 * j);
202 
203  gridMap["ground"].setConstant(0);
204  gridMap["nonground"].setConstant(0);
205 
206  if(!filterChain.update(gridMap, gridMap))
207  {
208  GTEST_FATAL_FAILURE_("Unable to update grid map.");
209  }
210  }
211  }
212 
213 
214 }
Eigen::Array2i Index
bool update(const T &data_in, T &data_out)
bool configure(std::string param_name, ros::NodeHandle node=ros::NodeHandle())
Filters that operate on a grid map instance.
void setFrameId(const std::string &frameId)
Eigen::Array2d Length
TEST(RayTrace, active)


mitre_fast_layered_map
Author(s):
autogenerated on Thu Mar 11 2021 03:06:49