123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- #include <costmap_2d/costmap_2d.h>
- #include <costmap_2d/layered_costmap.h>
- #include <costmap_2d/observation_buffer.h>
- #include <costmap_2d/testing_helper.h>
- #include <set>
- #include <gtest/gtest.h>
- using namespace costmap_2d;
- TEST(costmap, testRaytracing){
- tf2_ros::Buffer tf;
- LayeredCostmap layers("frame", false, false);
- addStaticLayer(layers, tf);
- ObstacleLayer* olayer = addObstacleLayer(layers, tf);
-
-
- addObservation(olayer, 0.0, 0.0, MAX_Z/2, 0, 0, MAX_Z/2);
-
- layers.updateMap(0,0,0);
-
-
- int lethal_count = countValues(*(layers.getCostmap()), LETHAL_OBSTACLE);
-
- ASSERT_EQ(lethal_count, 21);
- }
- TEST(costmap, testRaytracing2){
- tf2_ros::Buffer tf;
- LayeredCostmap layers("frame", false, false);
- addStaticLayer(layers, tf);
- ObstacleLayer* olayer = addObstacleLayer(layers, tf);
-
-
-
- layers.updateMap(0,0,0);
-
-
-
- int obs_before = countValues(*(layers.getCostmap()), LETHAL_OBSTACLE);
- ASSERT_EQ(obs_before, 20);
-
-
-
- addObservation(olayer, 9.5, 9.5, MAX_Z/2, 0.5, 0.5, MAX_Z/2);
- layers.updateMap(0, 0, 0);
-
-
- int obs_after = countValues(*(layers.getCostmap()), LETHAL_OBSTACLE);
-
-
-
- ASSERT_EQ(obs_after, obs_before + 1);
-
- for(int i = 0; i < olayer->getSizeInCellsY(); ++i)
- {
- olayer->setCost(i, i, LETHAL_OBSTACLE);
- }
-
-
- layers.updateMap(0, 0, 0);
-
-
- int with_static = countValues(*(layers.getCostmap()), LETHAL_OBSTACLE);
-
- ASSERT_EQ(with_static, obs_after);
-
- ASSERT_EQ(79, countValues(*(layers.getCostmap()), costmap_2d::FREE_SPACE));
- }
- TEST(costmap, testWaveInterference){
- tf2_ros::Buffer tf;
-
- LayeredCostmap layers("frame", false, true);
- layers.resizeMap(10, 10, 1, 0, 0);
- ObstacleLayer* olayer = addObstacleLayer(layers, tf);
-
-
-
- addObservation(olayer, 3.0, 3.0, MAX_Z);
- addObservation(olayer, 5.0, 5.0, MAX_Z);
- addObservation(olayer, 7.0, 7.0, MAX_Z);
- layers.updateMap(0,0,0);
- Costmap2D* costmap = layers.getCostmap();
-
-
-
- ASSERT_EQ(3, countValues(*costmap, costmap_2d::LETHAL_OBSTACLE));
- ASSERT_EQ(92, countValues(*costmap, costmap_2d::NO_INFORMATION));
- ASSERT_EQ(5, countValues(*costmap, costmap_2d::FREE_SPACE));
- }
- TEST(costmap, testZThreshold){
- tf2_ros::Buffer tf;
-
- LayeredCostmap layers("frame", false, true);
- layers.resizeMap(10, 10, 1, 0, 0);
- ObstacleLayer* olayer = addObstacleLayer(layers, tf);
-
- addObservation(olayer, 0.0, 5.0, 0.4);
- addObservation(olayer, 1.0, 5.0, 2.2);
- layers.updateMap(0,0,0);
- Costmap2D* costmap = layers.getCostmap();
- ASSERT_EQ(countValues(*costmap, costmap_2d::LETHAL_OBSTACLE), 1);
- }
- TEST(costmap, testDynamicObstacles){
- tf2_ros::Buffer tf;
- LayeredCostmap layers("frame", false, false);
- addStaticLayer(layers, tf);
- ObstacleLayer* olayer = addObstacleLayer(layers, tf);
-
- addObservation(olayer, 0.0, 0.0);
- addObservation(olayer, 0.0, 0.0);
- addObservation(olayer, 0.0, 0.0);
- layers.updateMap(0,0,0);
- Costmap2D* costmap = layers.getCostmap();
-
- ASSERT_EQ(countValues(*costmap, costmap_2d::LETHAL_OBSTACLE), 21);
-
- ASSERT_EQ(countValues(*costmap, costmap_2d::LETHAL_OBSTACLE), 21);
- }
- TEST(costmap, testMultipleAdditions){
- tf2_ros::Buffer tf;
- LayeredCostmap layers("frame", false, false);
- addStaticLayer(layers, tf);
- ObstacleLayer* olayer = addObstacleLayer(layers, tf);
-
- addObservation(olayer, 9.5, 0.0);
- layers.updateMap(0,0,0);
- Costmap2D* costmap = layers.getCostmap();
-
- ASSERT_EQ(countValues(*costmap, costmap_2d::LETHAL_OBSTACLE), 20);
- }
- int main(int argc, char** argv){
- ros::init(argc, argv, "obstacle_tests");
- testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
- }
|