Skip to content

Commit 1a8b493

Browse files
Fix incorrect world <-> map coordinates conversions (#5049) (#5074)
* Fix incorrect world <-> map coordinates conversions The conversion between world and map continuous (!) coordinates do not require a +/-0.5. This offset is only required when converting discrete map cell indexes to the coordinates of its center. Signed-off-by: Dylan De Coeyer <[email protected]> * nav2_smac_planner: fix smoother test when path is in collision The added pose was indeed invalid, but the it was ignored by the smoother, since considered as a cusp. Instead, let's make the end of the plan invalid as it won't be ignored. Also, let's duplicate the last pose to make the orientation estimation fail, rather than adding a new arbitrary pose. Signed-off-by: Dylan De Coeyer <[email protected]> --------- Signed-off-by: Dylan De Coeyer <[email protected]> (cherry picked from commit 3ec7c33) Co-authored-by: DylanDeCoeyer-Quimesis <[email protected]>
1 parent a797881 commit 1a8b493

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

nav2_costmap_2d/src/costmap_2d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ bool Costmap2D::worldToMapContinuous(double wx, double wy, float & mx, float & m
303303
return false;
304304
}
305305

306-
mx = static_cast<float>((wx - origin_x_) / resolution_) + 0.5f;
307-
my = static_cast<float>((wy - origin_y_) / resolution_) + 0.5f;
306+
mx = static_cast<float>((wx - origin_x_) / resolution_);
307+
my = static_cast<float>((wy - origin_y_) / resolution_);
308308

309309
if (mx < size_x_ && my < size_y_) {
310310
return true;

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 * costmap->getResolution();
5050
msg.position.y =
51-
static_cast<float>(costmap->getOriginY()) + (my - 0.5) * costmap->getResolution();
51+
static_cast<float>(costmap->getOriginY()) + my * costmap->getResolution();
5252
return msg;
5353
}
5454

nav2_smac_planner/test/test_smoother.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,19 @@ TEST(SmootherTest, test_full_smoother)
176176
double max_no_time = 0.0;
177177
EXPECT_FALSE(smoother->smooth(plan, costmap, max_no_time));
178178

179-
// Failure mode: Path is in collision, do 2x to exercise overlapping point
180-
// attempts to update orientation should also fail
181-
pose.pose.position.x = 1.25;
182-
pose.pose.position.y = 1.25;
183-
plan.poses.push_back(pose);
184-
plan.poses.push_back(pose);
179+
// Failure mode: invalid path and invalid orientation
180+
// make the end of the path invalid
181+
geometry_msgs::msg::PoseStamped lastPose = plan.poses.back();
182+
unsigned int mx, my;
183+
costmap->worldToMap(lastPose.pose.position.x, lastPose.pose.position.y, mx, my);
184+
for (unsigned int i = mx - 5; i <= mx + 5; ++i) {
185+
for (unsigned int j = my - 5; j <= my + 5; ++j) {
186+
costmap->setCost(i, j, 254);
187+
}
188+
}
189+
190+
// duplicate last pose to make the orientation update fail
191+
plan.poses.push_back(lastPose);
185192
EXPECT_FALSE(smoother->smooth(plan, costmap, maxtime));
186193
EXPECT_NEAR(plan.poses.end()[-2].pose.orientation.z, 1.0, 1e-3);
187194
EXPECT_NEAR(plan.poses.end()[-2].pose.orientation.x, 0.0, 1e-3);

0 commit comments

Comments
 (0)