Skip to content

Commit 1ff1303

Browse files
throw exceptions if out of bounds (#4224)
1 parent 9b13893 commit 1ff1303

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

nav2_smac_planner/src/smac_planner_hybrid.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ nav_msgs::msg::Path SmacPlannerHybrid::createPlan(
287287

288288
// Set starting point, in A* bin search coordinates
289289
unsigned int mx, my;
290-
costmap->worldToMap(start.pose.position.x, start.pose.position.y, mx, my);
290+
if (!costmap->worldToMap(start.pose.position.x, start.pose.position.y, mx, my)) {
291+
throw std::runtime_error("Start pose is out of costmap!");
292+
}
291293
double orientation_bin = tf2::getYaw(start.pose.orientation) / _angle_bin_size;
292294
while (orientation_bin < 0.0) {
293295
orientation_bin += static_cast<float>(_angle_quantizations);
@@ -300,7 +302,9 @@ nav_msgs::msg::Path SmacPlannerHybrid::createPlan(
300302
_a_star->setStart(mx, my, orientation_bin_id);
301303

302304
// Set goal point, in A* bin search coordinates
303-
costmap->worldToMap(goal.pose.position.x, goal.pose.position.y, mx, my);
305+
if (!costmap->worldToMap(goal.pose.position.x, goal.pose.position.y, mx, my)) {
306+
throw std::runtime_error("Goal pose is out of costmap!");
307+
}
304308
orientation_bin = tf2::getYaw(goal.pose.orientation) / _angle_bin_size;
305309
while (orientation_bin < 0.0) {
306310
orientation_bin += static_cast<float>(_angle_quantizations);

0 commit comments

Comments
 (0)