Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <grid_map_core/grid_map_core.hpp>
00011 #include <grid_map_costmap_2d/grid_map_costmap_2d.hpp>
00012
00013
00014 #include <gtest/gtest.h>
00015
00016
00017 #include <Eigen/Core>
00018
00019 using namespace grid_map;
00020
00021 TEST(Costmap2DConversion, initializeFromCostmap2d)
00022 {
00023 Costmap2DConverter<GridMap> costmap2dConverter;
00024
00025 costmap_2d::Costmap2D costmap2d(8, 5, 1.0, 2.0, 3.0);
00026
00027
00028 GridMap gridMap;
00029 costmap2dConverter.initializeFromCostmap2D(costmap2d, gridMap);
00030
00031
00032
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
00049 costmap_2d::Costmap2D costmap2d(8, 5, 1.0, 2.0, 3.0);
00050
00051
00052 const std::string layer("layer");
00053 GridMap gridMap;
00054 costmap2dConverter.initializeFromCostmap2D(costmap2d, gridMap);
00055
00056
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
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
00071 costmap2dConverter.addLayerFromCostmap2D(costmap2d, layer, gridMap);
00072
00073
00074 for (const auto& testValue : testValues) {
00075 EXPECT_EQ(std::get<2>(testValue), gridMap.atPosition(layer, std::get<0>(testValue)));
00076 }
00077 }