Costmap2DConverterTest.cpp
Go to the documentation of this file.
00001 /*
00002  * Costmap2DConverterTest.cpp
00003  *
00004  *  Created on: Nov 23, 2016
00005  *      Author: Peter Fankhauser
00006  *       Institute: ETH Zurich, ANYbotics
00007  */
00008 
00009 // Grid map
00010 #include <grid_map_core/grid_map_core.hpp>
00011 #include <grid_map_costmap_2d/grid_map_costmap_2d.hpp>
00012 
00013 // Gtest
00014 #include <gtest/gtest.h>
00015 
00016 // Eigen
00017 #include <Eigen/Core>
00018 
00019 using namespace grid_map;
00020 
00021 TEST(Costmap2DConversion, initializeFromCostmap2d)
00022 {
00023   Costmap2DConverter<GridMap> costmap2dConverter;
00024   // Create Costmap2D.
00025   costmap_2d::Costmap2D costmap2d(8, 5, 1.0, 2.0, 3.0);
00026 
00027   // Convert to grid map.
00028   GridMap gridMap;
00029   costmap2dConverter.initializeFromCostmap2D(costmap2d, gridMap);
00030 
00031   // Check map info.
00032   // Different conventions: Costmap2d returns the *centerpoint* of the last cell in the map.
00033   Length length = gridMap.getLength() - Length::Constant(0.5 * gridMap.getResolution());
00034   Length position = gridMap.getPosition() - 0.5 * gridMap.getLength().matrix();
00035   EXPECT_EQ(costmap2d.getSizeInMetersX(), length.x());
00036   EXPECT_EQ(costmap2d.getSizeInMetersY(), length.y());
00037   EXPECT_EQ(costmap2d.getSizeInCellsX(), gridMap.getSize()[0]);
00038   EXPECT_EQ(costmap2d.getSizeInCellsY(), gridMap.getSize()[1]);
00039   EXPECT_EQ(costmap2d.getResolution(), gridMap.getResolution());
00040   EXPECT_EQ(costmap2d.getOriginX(), position.x());
00041   EXPECT_EQ(costmap2d.getOriginY(), position.y());
00042 }
00043 
00044 TEST(Costmap2DConversion, addLayerFromCostmap2d)
00045 {
00046   Costmap2DConverter<GridMap> costmap2dConverter;
00047 
00048   // Create Costmap2D.
00049   costmap_2d::Costmap2D costmap2d(8, 5, 1.0, 2.0, 3.0);
00050 
00051   // Create grid map.
00052   const std::string layer("layer");
00053   GridMap gridMap;
00054   costmap2dConverter.initializeFromCostmap2D(costmap2d, gridMap);
00055 
00056   // Set test data.
00057   using TestValue = std::tuple<Position, unsigned char, double>;
00058   std::vector<TestValue> testValues;
00059   testValues.push_back(TestValue(Position(8.5, 4.5), 1, 1.0));
00060   testValues.push_back(TestValue(Position(3.2, 5.1), 254, 100.0));
00061   testValues.push_back(TestValue(Position(5.2, 7.8), 255, -1.0));
00062 
00063   // Fill in test data to Costmap2D.
00064   for (const auto& testValue : testValues) {
00065     unsigned int xIndex, yIndex;
00066     ASSERT_TRUE(costmap2d.worldToMap(std::get<0>(testValue).x(), std::get<0>(testValue).y(), xIndex, yIndex));
00067     costmap2d.getCharMap()[costmap2d.getIndex(xIndex, yIndex)] = std::get<1>(testValue);
00068   }
00069 
00070   // Copy data.
00071   costmap2dConverter.addLayerFromCostmap2D(costmap2d, layer, gridMap);
00072 
00073   // Check data.
00074   for (const auto& testValue : testValues) {
00075     EXPECT_EQ(std::get<2>(testValue), gridMap.atPosition(layer, std::get<0>(testValue)));
00076   }
00077 }


grid_map_costmap_2d
Author(s): Péter Fankhauser
autogenerated on Tue Jul 9 2019 05:06:21