30 #define _USE_MATH_DEFINES 34 #include <costmap_cspace_msgs/MapMetaData3D.h> 38 #include <gtest/gtest.h> 44 TEST(GridMetricConverter, SinglePose)
46 costmap_cspace_msgs::MapMetaData3D map_info;
47 map_info.linear_resolution = 0.1;
48 map_info.angular_resolution = M_PI / 8;
49 map_info.origin.position.x = 100.0;
50 map_info.origin.position.y = 100.0;
52 const float metric[][3] =
54 { 100.01, 100.01, M_PI / 8 },
55 { 100.01, 100.01, -M_PI / 8 },
56 { 105.01, 102.09, M_PI / 2 },
57 { 100.21, 102.51, -M_PI / 2 },
59 { 100.01, 100.01, 2.1 * M_PI / 8 },
60 { 100.01, 100.01, 1.9 * M_PI / 8 }
72 for (
size_t i = 0; i <
sizeof(grid) /
sizeof(grid[0]); ++i)
78 output_grid[0], output_grid[1], output_grid[2],
79 metric[i][0], metric[i][1], metric[i][2]);
80 for (
size_t j = 0; j < 3; ++j)
81 ASSERT_EQ(output_grid[j], grid[i][j]);
84 float output_metric[3];
87 grid[i][0], grid[i][1], grid[i][2],
88 output_metric[0], output_metric[1], output_metric[2]);
89 for (
size_t j = 0; j < 3; ++j)
90 ASSERT_NEAR(output_metric[j], metric[i][j], map_info.linear_resolution / 2);
94 TEST(GridMetricConverter, Path)
96 costmap_cspace_msgs::MapMetaData3D map_info;
97 map_info.linear_resolution = 0.1;
99 map_info.angular_resolution = M_PI / map_info.angle;
100 map_info.origin.position.x = 100.0;
101 map_info.origin.position.y = 100.0;
103 const float metric_expected[][3] =
105 { 100.15, 100.15, M_PI / 8 },
106 { 100.15, 100.25, M_PI / 8 },
107 { 100.25, 100.35, M_PI / 8 },
108 { 100.35, 100.35, 2 * M_PI / 8 }
110 const int grid[][3] =
117 std::vector<CyclicVecFloat<3, 2>> path_grid;
118 for (
const auto& g : grid)
124 for (
const geometry_msgs::PoseStamped& p : path.poses)
126 const double diff_dist = std::hypot(
127 metric_expected[ref][0] - p.pose.position.x,
128 metric_expected[ref][1] - p.pose.position.y);
129 double diff_yaw = std::abs(
tf2::getYaw(p.pose.orientation) - metric_expected[ref][2]);
131 if (diff_yaw < -M_PI)
132 diff_yaw += 2.0 * M_PI;
133 else if (diff_yaw > M_PI)
134 diff_yaw -= 2.0 * M_PI;
136 ASSERT_LT(diff_dist, map_info.linear_resolution * 2);
137 ASSERT_LT(std::abs(diff_yaw), map_info.angular_resolution * 2);
139 if (diff_dist < map_info.linear_resolution / 2 &&
140 std::abs(diff_yaw) < map_info.angular_resolution / 2)
143 if (ref ==
sizeof(metric_expected) /
sizeof(metric_expected[0]))
153 int main(
int argc,
char** argv)
155 testing::InitGoogleTest(&argc, argv);
157 return RUN_ALL_TESTS();
TEST(CostmapBBF, ForEach)
void metric2Grid(const costmap_cspace_msgs::MapMetaData3D &map_info, int &x, int &y, int &yaw, const float gx, const float gy, const float gyaw)
double getYaw(const A &a)
void grid2MetricPath(const costmap_cspace_msgs::MapMetaData3D &map_info, const STL_CONTAINER< CyclicVecFloat< 3, 2 >, std::allocator< CyclicVecFloat< 3, 2 >>> &path_grid, nav_msgs::Path &path)
void grid2Metric(const costmap_cspace_msgs::MapMetaData3D &map_info, const T x, const T y, const T yaw, float &gx, float &gy, float &gyaw)
int main(int argc, char **argv)