14 #include <gtest/gtest.h> 21 template <
typename ConversionTable>
24 using TestValue = std::tuple<Position, unsigned char, double, bool>;
30 std::vector<TestValue> getTestValues();
60 std::vector<TestCostmap2DConversion<Costmap2DSpecialTranslationTable>::TestValue>
62 std::vector<TestValue> testValues;
75 std::vector<TestCostmap2DConversion<Costmap2DLargeIntervalsTranslationTable>::TestValue>
77 std::vector<TestValue> testValues;
93 std::vector<TestCostmap2DConversion<Costmap2DDirectTranslationTable>::TestValue>
95 std::vector<TestValue> testValues;
97 testValues.emplace_back(
111 std::vector<TestCostmap2DConversion<Costmap2DCenturyTranslationTable>::TestValue>
113 std::vector<TestValue> testValues;
133 this->costmap2dConverter_.initializeFromCostmap2D(this->costmap2d_, gridMap);
134 this->assertMapGeometry(gridMap, this->costmap2d_);
140 this->costmap2dConverter_.initializeFromGridMap(this->gridMap_, costmap2d);
141 this->assertMapGeometry(this->gridMap_, costmap2d);
146 const std::string layer(
"layer");
148 this->costmap2dConverter_.initializeFromCostmap2D(this->costmap2d_, gridMap);
151 for (
const auto& testValue : this->getTestValues()) {
152 if (std::get<3>(testValue)) {
153 unsigned int xIndex, yIndex;
154 ASSERT_TRUE(this->costmap2d_.worldToMap(std::get<0>(testValue).x(), std::get<0>(testValue).
y(), xIndex, yIndex));
155 this->costmap2d_.getCharMap()[this->costmap2d_.getIndex(xIndex, yIndex)] = std::get<1>(testValue);
160 this->costmap2dConverter_.addLayerFromCostmap2D(this->costmap2d_, layer, gridMap);
163 for (
const auto& testValue : this->getTestValues()) {
164 if (std::get<3>(testValue)) {
165 EXPECT_EQ(std::get<2>(testValue), gridMap.
atPosition(layer, std::get<0>(testValue)));
173 this->costmap2dConverter_.initializeFromGridMap(this->gridMap_, costmap);
176 const std::string layer(
"layer");
177 this->gridMap_.add(layer);
178 for (
const auto& testValue : this->getTestValues()) {
180 this->gridMap_.getIndex(std::get<0>(testValue), index);
181 this->gridMap_.get(layer)(index(0), index(1)) = std::get<2>(testValue);
185 this->costmap2dConverter_.setCostmap2DFromGridMap(this->gridMap_, layer, costmap);
188 for (
const auto& testValue : this->getTestValues()) {
189 unsigned int xIndex, yIndex;
190 ASSERT_TRUE(costmap.
worldToMap(std::get<0>(testValue).x(), std::get<0>(testValue).
y(), xIndex, yIndex));
const Length & getLength() const
float & atPosition(const std::string &layer, const Position &position)
std::vector< TestValue > getTestValues()
Getter of test data.
bool getPosition(const Index &index, Position &position) const
double getOriginX() const
double getSizeInMetersX() const
TYPED_TEST_CASE(TestCostmap2DConversion, TranslationTableTestTypes)
TFSIMD_FORCE_INLINE const tfScalar & y() const
static const unsigned char FREE_SPACE
double getSizeInMetersY() const
unsigned char * getCharMap() const
Costmap2DConverter< GridMap, ConversionTable > costmap2dConverter_
double getResolution() const
static const unsigned char INSCRIBED_INFLATED_OBSTACLE
void assertMapGeometry(const GridMap &gridMap, const costmap_2d::Costmap2D &costMap)
Check that maps have same geometry.
Costmap2DTranslationTable< 3, 2, 1, 0 > Costmap2DSpecialTranslationTable
Map type that has only mappings for cost map special values.
double getOriginY() const
costmap_2d::Costmap2D costmap2d_
unsigned int getSizeInCellsY() const
Costmap2DTranslationTable< 5, 500, 400, 100 > Costmap2DLargeIntervalsTranslationTable
Map type that has larger intervals between special values.
unsigned int getSizeInCellsX() const
static const unsigned char LETHAL_OBSTACLE
::testing::Types< Costmap2DSpecialTranslationTable, Costmap2DLargeIntervalsTranslationTable, Costmap2DDirectTranslationTable, Costmap2DCenturyTranslationTable > TranslationTableTestTypes
static const unsigned char NO_INFORMATION
TYPED_TEST(TestCostmap2DConversion, initializeFromCostmap2d)
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
std::tuple< Position, unsigned char, double, bool > TestValue
double getResolution() const
Costmap2DTranslationTable< costmap_2d::NO_INFORMATION, costmap_2d::LETHAL_OBSTACLE, costmap_2d::INSCRIBED_INFLATED_OBSTACLE, costmap_2d::FREE_SPACE > Costmap2DDirectTranslationTable
Direct cost translations. This maps the cost directly, simply casting between the underlying unsigned...
bool worldToMap(double wx, double wy, unsigned int &mx, unsigned int &my) const
unsigned int getIndex(unsigned int mx, unsigned int my) const
const Size & getSize() const
TestCostmap2DConversion()
Constructor.