test_filter_inflation.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include "filters.hpp"
3 #include <filters/filter_chain.h>
4 #include <math.h>
5 #include <Eigen/Dense>
6 
7 #define GTEST_COUT std::cerr << "[ INFO ] "
8 
9 TEST(Inflation, active)
10 {
11  EXPECT_EQ(0, 0);
12 }
13 
18 TEST(Inflation, layers_dont_exist)
19 {
20  ros::NodeHandle nh("~");
21 
22  grid_map::GridMap gridMap({"random_layer"});
23  gridMap.setFrameId("random");
24  gridMap.setGeometry(grid_map::Length(3, 3), 1);
25 
26  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
27 
28  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
29  {
30  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
31  }
32 
33  EXPECT_FALSE(filterChain.update(gridMap, gridMap));
34 
35  // Inflation filter needs nonground layer
36  gridMap.add("nonground", 0);
37  EXPECT_TRUE(filterChain.update(gridMap, gridMap));
38 }
39 
56 TEST(Inflation, all_clear)
57 {
58  ros::NodeHandle nh("~");
59 
60  grid_map::GridMap gridMap;
61  gridMap.setFrameId("map");
62  gridMap.setGeometry(grid_map::Length(3, 3), 1);
63 
64  // Initialize nonground plane to all clear
65  gridMap.add("nonground", 0);
66 
67  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
68 
69  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
70  {
71  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
72  }
73 
74  if(!filterChain.update(gridMap, gridMap))
75  {
76  GTEST_FATAL_FAILURE_("Unable to update grid map.");
77  }
78 
79  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
80  {
81  const grid_map::Index index(*it);
82 
83  EXPECT_EQ(0, gridMap.at("nonground", index));
84  }
85 }
86 
104 TEST(Inflation, center_filled)
105 {
106  ros::NodeHandle nh("~");
107 
108  grid_map::GridMap gridMap;
109  gridMap.setFrameId("map");
110  gridMap.setGeometry(grid_map::Length(3, 3), 1);
111 
112  // Initialize nonground plane to all clear
113  gridMap.add("nonground", 0);
114  gridMap.at("nonground", grid_map::Index(1, 1)) = 100;
115 
116  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
117 
118  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
119  {
120  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
121  }
122 
123  if(!filterChain.update(gridMap, gridMap))
124  {
125  GTEST_FATAL_FAILURE_("Unable to update grid map.");
126  }
127 
128  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
129  {
130  const grid_map::Index index(*it);
131 
132  if (index(0) == 1 && index(1) == 1)
133  {
134  EXPECT_EQ(100, gridMap.at("nonground", index));
135  }
136  else
137  {
138  EXPECT_EQ(30, gridMap.at("nonground", index)) <<
139  "Index: " << index(0) << " " << index(1);
140  }
141  }
142 }
143 
163 TEST(Inflation, center_filled_small_radius)
164 {
165  ros::NodeHandle nh("~");
166 
167  grid_map::GridMap gridMap;
168  gridMap.setFrameId("map");
169  gridMap.setGeometry(grid_map::Length(5, 5), 1);
170 
171  // Initialize nonground plane to all clear
172  gridMap.add("nonground", 0);
173  gridMap.at("nonground", grid_map::Index(2, 2)) = 100;
174 
175  // Create answer matrix
176  Eigen::MatrixXi answerMat(5,5);
177  answerMat <<
178  0, 0, 0, 0, 0,
179  0, 30, 30, 30, 0,
180  0, 30, 100, 30, 0,
181  0, 30, 30, 30, 0,
182  0, 0, 0, 0, 0;
183 
184  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
185 
186  if(!filterChain.configure("mitre_fast_layered_map_filters_low_inflation", nh))
187  {
188  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
189  }
190 
191  if(!filterChain.update(gridMap, gridMap))
192  {
193  GTEST_FATAL_FAILURE_("Unable to update grid map.");
194  }
195 
196  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
197  {
198  const grid_map::Index index(*it);
199 
200  EXPECT_EQ(answerMat(index(0), index(1)), gridMap.at("nonground", index)) <<
201  "Index: " << index(0) << " " << index(1);
202  }
203 }
204 
228 TEST(Inflation, complex)
229 {
230  ros::NodeHandle nh("~");
231  grid_map::GridMap gridMap({"ground"});
232  gridMap.setFrameId("map");
233  gridMap.setGeometry(grid_map::Length(5, 5), 1);
234 
235  // Initialize nonground
236  gridMap.add("nonground", 0);
237  gridMap.at("nonground", grid_map::Index(0,2)) = 100;
238  gridMap.at("nonground", grid_map::Index(1,2)) = 100;
239  gridMap.at("nonground", grid_map::Index(2,0)) = 100;
240  gridMap.at("nonground", grid_map::Index(2,4)) = 100;
241  gridMap.at("nonground", grid_map::Index(3,2)) = 100;
242  gridMap.at("nonground", grid_map::Index(4,2)) = 100;
243 
244  // Create matrix of expected output to compare to
245  Eigen::MatrixXi answerMat(5, 5);
246  answerMat <<
247  0, 30, 100, 30, 0,
248  30, 30, 100, 30, 30,
249  100, 30, 30, 30, 100,
250  30, 30, 100, 30, 30,
251  0, 30, 100, 30, 0;
252 
253 
254  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
255 
256  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
257  {
258  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
259  }
260 
261  if(!filterChain.update(gridMap, gridMap))
262  {
263  GTEST_FATAL_FAILURE_("Unable to update grid map.");
264  }
265 
266  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
267  {
268  const grid_map::Index index(*it);
269 
270  EXPECT_EQ(answerMat(index(0), index(1)), gridMap.at("nonground", index)) <<
271  "Index: " << index(0) << " " << index(1);
272  }
273 
274 }
275 
276 TEST(Inflation, move_forward)
277 {
278  ros::NodeHandle nh("~");
279  grid_map::GridMap gridMap({"ground"});
280  gridMap.setFrameId("map");
281  gridMap.setGeometry(grid_map::Length(5, 5), 1);
282 
283  // Initialize nonground
284  gridMap.add("nonground", 0);
285  gridMap.at("nonground", grid_map::Index(0,2)) = 100;
286 
287  gridMap.move(grid_map::Position(1, 0));
288  gridMap["nonground"] = (gridMap["nonground"].array().isNaN()).select(0, gridMap["nonground"]);
289 
290  // Create matrix of expected output to compare to
291  Eigen::MatrixXi answerMat(5, 5);
292  answerMat <<
293  0, 30, 100, 30, 0,
294  0, 30, 30, 30, 0,
295  0, 0, 0, 0, 0,
296  0, 0, 0, 0, 0,
297  0, 30, 30, 30, 0;
298 
299  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
300 
301  if(!filterChain.configure("mitre_fast_layered_map_filters_low_inflation", nh))
302  {
303  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
304  }
305 
306  if(!filterChain.update(gridMap, gridMap))
307  {
308  GTEST_FATAL_FAILURE_("Unable to update grid map.");
309  }
310 
311  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
312  {
313  const grid_map::Index index(*it);
314 
315  EXPECT_EQ(answerMat(index(0), index(1)), gridMap.at("nonground", index)) <<
316  "Index: " << index(0) << " " << index(1);
317  }
318 }
319 
320 TEST(Inflation, move_backward)
321 {
322  ros::NodeHandle nh("~");
323  grid_map::GridMap gridMap({"ground"});
324  gridMap.setFrameId("map");
325  gridMap.setGeometry(grid_map::Length(5, 5), 1);
326 
327  // Initialize nonground
328  gridMap.add("nonground", 0);
329  gridMap.at("nonground", grid_map::Index(4,2)) = 100;
330 
331  gridMap.move(grid_map::Position(-1, 0));
332  gridMap["nonground"] = (gridMap["nonground"].array().isNaN()).select(0, gridMap["nonground"]);
333 
334  // Create matrix of expected output to compare to
335  Eigen::MatrixXi answerMat(5, 5);
336  answerMat <<
337  0, 30, 30, 30, 0,
338  0, 0, 0, 0, 0,
339  0, 0, 0, 0, 0,
340  0, 30, 30, 30, 0,
341  0, 30, 100, 30, 0;
342 
343  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
344 
345  if(!filterChain.configure("mitre_fast_layered_map_filters_low_inflation", nh))
346  {
347  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
348  }
349 
350  if(!filterChain.update(gridMap, gridMap))
351  {
352  GTEST_FATAL_FAILURE_("Unable to update grid map.");
353  }
354 
355  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
356  {
357  const grid_map::Index index(*it);
358 
359  EXPECT_EQ(answerMat(index(0), index(1)), gridMap.at("nonground", index)) <<
360  "Index: " << index(0) << " " << index(1);
361  }
362 }
363 
364 TEST(Inflation, move_left)
365 {
366  ros::NodeHandle nh("~");
367  grid_map::GridMap gridMap({"ground"});
368  gridMap.setFrameId("map");
369  gridMap.setGeometry(grid_map::Length(5, 5), 1);
370 
371  // Initialize nonground
372  gridMap.add("nonground", 0);
373  gridMap.at("nonground", grid_map::Index(2,0)) = 100;
374 
375  gridMap.move(grid_map::Position(0, 1));
376  gridMap["nonground"] = (gridMap["nonground"].array().isNaN()).select(0, gridMap["nonground"]);
377 
378  // Create matrix of expected output to compare to
379  Eigen::MatrixXi answerMat(5, 5);
380  answerMat <<
381  0, 0, 0, 0, 0,
382  30, 30, 0, 0, 30,
383  100, 30, 0, 0, 30,
384  30, 30, 0, 0, 30,
385  0, 0, 0, 0, 0;
386 
387  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
388 
389  if(!filterChain.configure("mitre_fast_layered_map_filters_low_inflation", nh))
390  {
391  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
392  }
393 
394  if(!filterChain.update(gridMap, gridMap))
395  {
396  GTEST_FATAL_FAILURE_("Unable to update grid map.");
397  }
398 
399  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
400  {
401  const grid_map::Index index(*it);
402 
403  EXPECT_EQ(answerMat(index(0), index(1)), gridMap.at("nonground", index)) <<
404  "Index: " << index(0) << " " << index(1);
405  }
406 }
407 
408 TEST(Inflation, move_right)
409 {
410  ros::NodeHandle nh("~");
411  grid_map::GridMap gridMap({"ground"});
412  gridMap.setFrameId("map");
413  gridMap.setGeometry(grid_map::Length(5, 5), 1);
414 
415  // Initialize nonground
416  gridMap.add("nonground", 0);
417  gridMap.at("nonground", grid_map::Index(2,4)) = 100;
418 
419  gridMap.move(grid_map::Position(0, -1));
420  gridMap["nonground"] = (gridMap["nonground"].array().isNaN()).select(0, gridMap["nonground"]);
421 
422  // Create matrix of expected output to compare to
423  Eigen::MatrixXi answerMat(5, 5);
424  answerMat <<
425  0, 0, 0, 0, 0,
426  30, 0, 0, 30, 30,
427  30, 0, 0, 30, 100,
428  30, 0, 0, 30, 30,
429  0, 0, 0, 0, 0;
430 
431  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
432 
433  if(!filterChain.configure("mitre_fast_layered_map_filters_low_inflation", nh))
434  {
435  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
436  }
437 
438  if(!filterChain.update(gridMap, gridMap))
439  {
440  GTEST_FATAL_FAILURE_("Unable to update grid map.");
441  }
442 
443  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
444  {
445  const grid_map::Index index(*it);
446 
447  EXPECT_EQ(answerMat(index(0), index(1)), gridMap.at("nonground", index)) <<
448  "Index: " << index(0) << " " << index(1);
449  }
450 }
451 
452 TEST(Inflation, move_diagonal)
453 {
454  ros::NodeHandle nh("~");
455  grid_map::GridMap gridMap({"ground"});
456  gridMap.setFrameId("map");
457  gridMap.setGeometry(grid_map::Length(5, 5), 1);
458 
459  // Initialize nonground
460  gridMap.add("nonground", 0);
461  gridMap.at("nonground", grid_map::Index(0,0)) = 100;
462 
463  gridMap.move(grid_map::Position(1, 1));
464  gridMap["nonground"] = (gridMap["nonground"].array().isNaN()).select(0, gridMap["nonground"]);
465 
466  // Create matrix of expected output to compare to
467  Eigen::MatrixXi answerMat(5, 5);
468  answerMat <<
469  100, 30, 0, 0, 30,
470  30, 30, 0, 0, 30,
471  0, 0, 0, 0, 0,
472  0, 0, 0, 0, 0,
473  30, 30, 0, 0, 30;
474 
475  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
476 
477  if(!filterChain.configure("mitre_fast_layered_map_filters_low_inflation", nh))
478  {
479  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
480  }
481 
482  if(!filterChain.update(gridMap, gridMap))
483  {
484  GTEST_FATAL_FAILURE_("Unable to update grid map.");
485  }
486 
487  for(grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
488  {
489  const grid_map::Index index(*it);
490 
491  EXPECT_EQ(answerMat(index(0), index(1)), gridMap.at("nonground", index)) <<
492  "Index: " << index(0) << " " << index(1);
493  }
494 }
495 
496 //
497 // STRESS TESTS
498 //
499 // The below tests are just to try and make sure that inflation will never fail or throw and error.
500 // We could consider using try's around the eigen.block() calls since that is where any errors will pop up
501 
502 TEST(Inflation, Stress_test_1)
503 {
504  ros::NodeHandle nh("~");
505  grid_map::GridMap gridMap({"ground"});
506  gridMap.setFrameId("map");
507  gridMap.setGeometry(grid_map::Length(50, 50), 0.3);
508 
509  // Initialize nonground
510  gridMap.add("nonground", 0);
511 
512  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
513 
514  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
515  {
516  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
517  }
518 
519  // Fill every cell in the gridmap
520  // This will cause inflation to run on every single cell
521  for (grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
522  {
523  gridMap.at("nonground", grid_map::Index(*it)) = 100;
524  }
525 
526  EXPECT_NO_FATAL_FAILURE(filterChain.update(gridMap, gridMap));
527 }
528 
529 TEST(Inflation, Stress_test_2)
530 {
531  ros::NodeHandle nh("~");
532  grid_map::GridMap gridMap({"ground"});
533  gridMap.setFrameId("map");
534  gridMap.setGeometry(grid_map::Length(50, 50), 0.3);
535 
536  // Initialize nonground
537  gridMap.add("nonground", 0);
538 
539  filters::FilterChain<grid_map::GridMap> filterChain("grid_map::GridMap");
540 
541  if(!filterChain.configure("mitre_fast_layered_map_filters", nh))
542  {
543  GTEST_FATAL_FAILURE_("Unable to configure filter chain."); // We should never get here
544  }
545 
546  for (int i = 0; i < 100; i++)
547  {
548 
549  int t = i > 50 ? i: -i; // Switch direction halfway through
550  // Create wierd irregular pattern
551  grid_map::Position pos(20*t, 10 * sin(t));
552  // Move the map to keep up
553  gridMap.move(pos);
554 
555  // Fill every cell in the gridmap
556  // This will cause inflation to run on every single cell
557  for (grid_map::GridMapIterator it(gridMap); !it.isPastEnd(); ++it)
558  {
559  gridMap.at("nonground", grid_map::Index(*it)) = 100;
560  }
561 
562  EXPECT_NO_FATAL_FAILURE(filterChain.update(gridMap, gridMap));
563 
564  }
565 }
Eigen::Array2i Index
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
geometry_msgs::TransformStamped t
Eigen::Vector2d Position
float & at(const std::string &layer, const Index &index)
void add(const std::string &layer, const double value=NAN)
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)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
Eigen::Array2d Length
TEST(Inflation, active)


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