Skip to content

Commit a28cdd8

Browse files
Backporting duplicate pose handling in Humble for Smac Planners (#5713)
* Backporting duplicate pose handling in Humble for Smac Planners Signed-off-by: SteveMacenski <stevenmacenski@gmail.com> * linting Signed-off-by: SteveMacenski <stevenmacenski@gmail.com> --------- Signed-off-by: SteveMacenski <stevenmacenski@gmail.com>
1 parent a097086 commit a28cdd8

File tree

2 files changed

+62
-22
lines changed

2 files changed

+62
-22
lines changed

‎nav2_smac_planner/src/smac_planner_hybrid.cpp‎

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -290,34 +290,38 @@ nav_msgs::msg::Path SmacPlannerHybrid::createPlan(
290290
_a_star->setCollisionChecker(&_collision_checker);
291291

292292
// Set starting point, in A* bin search coordinates
293-
unsigned int mx, my;
294-
if (!costmap->worldToMap(start.pose.position.x, start.pose.position.y, mx, my)) {
293+
unsigned int mx_start, my_start, mx_goal, my_goal;
294+
if (!costmap->worldToMap(start.pose.position.x, start.pose.position.y, mx_start, my_start)) {
295295
throw std::runtime_error("Start pose is out of costmap!");
296296
}
297297

298-
double orientation_bin = std::round(tf2::getYaw(start.pose.orientation) / _angle_bin_size);
299-
while (orientation_bin < 0.0) {
300-
orientation_bin += static_cast<float>(_angle_quantizations);
298+
double orientation_bin_start = std::round(tf2::getYaw(start.pose.orientation) / _angle_bin_size);
299+
while (orientation_bin_start < 0.0) {
300+
orientation_bin_start += static_cast<float>(_angle_quantizations);
301301
}
302302
// This is needed to handle precision issues
303-
if (orientation_bin >= static_cast<float>(_angle_quantizations)) {
304-
orientation_bin -= static_cast<float>(_angle_quantizations);
303+
if (orientation_bin_start >= static_cast<float>(_angle_quantizations)) {
304+
orientation_bin_start -= static_cast<float>(_angle_quantizations);
305305
}
306-
_a_star->setStart(mx, my, static_cast<unsigned int>(orientation_bin));
306+
unsigned int start_orientation_bin_int =
307+
static_cast<unsigned int>(orientation_bin_start);
308+
_a_star->setStart(mx_start, my_start, start_orientation_bin_int);
307309

308310
// Set goal point, in A* bin search coordinates
309-
if (!costmap->worldToMap(goal.pose.position.x, goal.pose.position.y, mx, my)) {
311+
if (!costmap->worldToMap(goal.pose.position.x, goal.pose.position.y, mx_goal, my_goal)) {
310312
throw std::runtime_error("Goal pose is out of costmap!");
311313
}
312-
orientation_bin = std::round(tf2::getYaw(goal.pose.orientation) / _angle_bin_size);
313-
while (orientation_bin < 0.0) {
314-
orientation_bin += static_cast<float>(_angle_quantizations);
314+
double orientation_bin_goal = std::round(tf2::getYaw(goal.pose.orientation) / _angle_bin_size);
315+
while (orientation_bin_goal < 0.0) {
316+
orientation_bin_goal += static_cast<float>(_angle_quantizations);
315317
}
316318
// This is needed to handle precision issues
317-
if (orientation_bin >= static_cast<float>(_angle_quantizations)) {
318-
orientation_bin -= static_cast<float>(_angle_quantizations);
319+
if (orientation_bin_goal >= static_cast<float>(_angle_quantizations)) {
320+
orientation_bin_goal -= static_cast<float>(_angle_quantizations);
319321
}
320-
_a_star->setGoal(mx, my, static_cast<unsigned int>(orientation_bin));
322+
unsigned int goal_orientation_bin_int =
323+
static_cast<unsigned int>(orientation_bin_goal);
324+
_a_star->setGoal(mx_goal, my_goal, goal_orientation_bin_int);
321325

322326
// Setup message
323327
nav_msgs::msg::Path plan;
@@ -331,6 +335,23 @@ nav_msgs::msg::Path SmacPlannerHybrid::createPlan(
331335
pose.pose.orientation.z = 0.0;
332336
pose.pose.orientation.w = 1.0;
333337

338+
// Corner case of start and goal being on the same cell
339+
if (std::floor(mx_start) == std::floor(mx_goal) &&
340+
std::floor(my_start) == std::floor(my_goal) &&
341+
start_orientation_bin_int == goal_orientation_bin_int)
342+
{
343+
pose.pose = start.pose;
344+
pose.pose.orientation = goal.pose.orientation;
345+
plan.poses.push_back(pose);
346+
347+
// Publish raw path for debug
348+
if (_raw_plan_publisher->get_subscription_count() > 0) {
349+
_raw_plan_publisher->publish(plan);
350+
}
351+
352+
return plan;
353+
}
354+
334355
// Compute plan
335356
NodeHybrid::CoordinateVector path;
336357
int num_iterations = 0;

‎nav2_smac_planner/src/smac_planner_lattice.cpp‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,19 @@ nav_msgs::msg::Path SmacPlannerLattice::createPlan(
250250
_a_star->setCollisionChecker(&_collision_checker);
251251

252252
// Set starting point, in A* bin search coordinates
253-
unsigned int mx, my;
254-
_costmap->worldToMap(start.pose.position.x, start.pose.position.y, mx, my);
253+
unsigned int mx_start, my_start, mx_goal, my_goal;
254+
_costmap->worldToMap(start.pose.position.x, start.pose.position.y, mx_start, my_start);
255+
unsigned int start_bin =
256+
NodeLattice::motion_table.getClosestAngularBin(tf2::getYaw(start.pose.orientation));
255257
_a_star->setStart(
256-
mx, my,
257-
NodeLattice::motion_table.getClosestAngularBin(tf2::getYaw(start.pose.orientation)));
258+
mx_start, my_start, start_bin);
258259

259260
// Set goal point, in A* bin search coordinates
260-
_costmap->worldToMap(goal.pose.position.x, goal.pose.position.y, mx, my);
261+
_costmap->worldToMap(goal.pose.position.x, goal.pose.position.y, mx_goal, my_goal);
262+
unsigned int goal_bin =
263+
NodeLattice::motion_table.getClosestAngularBin(tf2::getYaw(goal.pose.orientation));
261264
_a_star->setGoal(
262-
mx, my,
263-
NodeLattice::motion_table.getClosestAngularBin(tf2::getYaw(goal.pose.orientation)));
265+
mx_goal, my_goal, goal_bin);
264266

265267
// Setup message
266268
nav_msgs::msg::Path plan;
@@ -274,6 +276,23 @@ nav_msgs::msg::Path SmacPlannerLattice::createPlan(
274276
pose.pose.orientation.z = 0.0;
275277
pose.pose.orientation.w = 1.0;
276278

279+
// Corner case of start and goal being on the same cell
280+
if (std::floor(mx_start) == std::floor(mx_goal) &&
281+
std::floor(my_start) == std::floor(my_goal) &&
282+
start_bin == goal_bin)
283+
{
284+
pose.pose = start.pose;
285+
pose.pose.orientation = goal.pose.orientation;
286+
plan.poses.push_back(pose);
287+
288+
// Publish raw path for debug
289+
if (_raw_plan_publisher->get_subscription_count() > 0) {
290+
_raw_plan_publisher->publish(plan);
291+
}
292+
293+
return plan;
294+
}
295+
277296
// Compute plan
278297
NodeLattice::CoordinateVector path;
279298
int num_iterations = 0;

0 commit comments

Comments
 (0)