Skip to content

Commit 137b93b

Browse files
authored
Fix world to map coordinate conversion (#4506)
Signed-off-by: HovorunBh <[email protected]>
1 parent 30f028d commit 137b93b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

nav2_smac_planner/include/nav2_smac_planner/utils.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ inline geometry_msgs::msg::Pose getWorldCoords(
4646
{
4747
geometry_msgs::msg::Pose msg;
4848
msg.position.x =
49-
static_cast<float>(costmap->getOriginX()) + (mx + 0.5) * costmap->getResolution();
49+
static_cast<float>(costmap->getOriginX()) + (mx - 0.5) * costmap->getResolution();
5050
msg.position.y =
51-
static_cast<float>(costmap->getOriginY()) + (my + 0.5) * costmap->getResolution();
51+
static_cast<float>(costmap->getOriginY()) + (my - 0.5) * costmap->getResolution();
5252
return msg;
5353
}
5454

nav2_smac_planner/test/test_utils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,17 @@ TEST(create_marker, test_createMarker)
147147
EXPECT_EQ(marker2.id, 8u);
148148
EXPECT_EQ(marker2.points.size(), 0u);
149149
}
150+
151+
TEST(convert_map_to_world_to_map, test_convert_map_to_world_to_map)
152+
{
153+
auto costmap = nav2_costmap_2d::Costmap2D(10.0, 10.0, 0.05, 0.0, 0.0, 0);
154+
155+
float mx = 200.0;
156+
float my = 100.0;
157+
geometry_msgs::msg::Pose pose = getWorldCoords(mx, my, &costmap);
158+
159+
float mx1, my1;
160+
costmap.worldToMapContinuous(pose.position.x, pose.position.y, mx1, my1);
161+
EXPECT_NEAR(mx, mx1, 1e-3);
162+
EXPECT_NEAR(my, my1, 1e-3);
163+
}

0 commit comments

Comments
 (0)