diff --git a/nav2_costmap_2d/src/costmap_2d.cpp b/nav2_costmap_2d/src/costmap_2d.cpp index 9ddbcf5e9d6..ea2de83e4b4 100644 --- a/nav2_costmap_2d/src/costmap_2d.cpp +++ b/nav2_costmap_2d/src/costmap_2d.cpp @@ -303,8 +303,8 @@ bool Costmap2D::worldToMapContinuous(double wx, double wy, float & mx, float & m return false; } - mx = static_cast((wx - origin_x_) / resolution_) + 0.5f; - my = static_cast((wy - origin_y_) / resolution_) + 0.5f; + mx = static_cast((wx - origin_x_) / resolution_); + my = static_cast((wy - origin_y_) / resolution_); if (mx < size_x_ && my < size_y_) { return true; diff --git a/nav2_smac_planner/include/nav2_smac_planner/utils.hpp b/nav2_smac_planner/include/nav2_smac_planner/utils.hpp index fb020a729a1..8975258dab4 100644 --- a/nav2_smac_planner/include/nav2_smac_planner/utils.hpp +++ b/nav2_smac_planner/include/nav2_smac_planner/utils.hpp @@ -46,9 +46,9 @@ inline geometry_msgs::msg::Pose getWorldCoords( { geometry_msgs::msg::Pose msg; msg.position.x = - static_cast(costmap->getOriginX()) + (mx - 0.5) * costmap->getResolution(); + static_cast(costmap->getOriginX()) + mx * costmap->getResolution(); msg.position.y = - static_cast(costmap->getOriginY()) + (my - 0.5) * costmap->getResolution(); + static_cast(costmap->getOriginY()) + my * costmap->getResolution(); return msg; } diff --git a/nav2_smac_planner/test/test_smoother.cpp b/nav2_smac_planner/test/test_smoother.cpp index b216972e60d..2f9e6a89697 100644 --- a/nav2_smac_planner/test/test_smoother.cpp +++ b/nav2_smac_planner/test/test_smoother.cpp @@ -176,12 +176,19 @@ TEST(SmootherTest, test_full_smoother) double max_no_time = 0.0; EXPECT_FALSE(smoother->smooth(plan, costmap, max_no_time)); - // Failure mode: Path is in collision, do 2x to exercise overlapping point - // attempts to update orientation should also fail - pose.pose.position.x = 1.25; - pose.pose.position.y = 1.25; - plan.poses.push_back(pose); - plan.poses.push_back(pose); + // Failure mode: invalid path and invalid orientation + // make the end of the path invalid + geometry_msgs::msg::PoseStamped lastPose = plan.poses.back(); + unsigned int mx, my; + costmap->worldToMap(lastPose.pose.position.x, lastPose.pose.position.y, mx, my); + for (unsigned int i = mx - 5; i <= mx + 5; ++i) { + for (unsigned int j = my - 5; j <= my + 5; ++j) { + costmap->setCost(i, j, 254); + } + } + + // duplicate last pose to make the orientation update fail + plan.poses.push_back(lastPose); EXPECT_FALSE(smoother->smooth(plan, costmap, maxtime)); EXPECT_NEAR(plan.poses.end()[-2].pose.orientation.z, 1.0, 1e-3); EXPECT_NEAR(plan.poses.end()[-2].pose.orientation.x, 0.0, 1e-3);