@@ -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 ;
0 commit comments