Skip to content

Commit df92ffd

Browse files
authored
Fix lattice backward 180 deg issue (#5141)
Signed-off-by: selazarev <[email protected]>
1 parent 5f34bc3 commit df92ffd

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

nav2_smac_planner/src/node_lattice.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@ void NodeLattice::getNeighbors(
499499
NodeVector & neighbors)
500500
{
501501
uint64_t index = 0;
502-
float angle;
503502
bool backwards = false;
504503
NodePtr neighbor = nullptr;
505504
Coordinates initial_node_coords, motion_projection;
@@ -515,6 +514,24 @@ void NodeLattice::getNeighbors(
515514
motion_projection.y = this->pose.y + (end_pose._y / grid_resolution);
516515
motion_projection.theta = motion_primitives[i]->end_angle /*this is the ending angular bin*/;
517516

517+
// if i >= idx, then we're in a reversing primitive. In that situation,
518+
// the orientation of the robot is mirrored from what it would otherwise
519+
// appear to be from the motion primitives file. We want to take this into
520+
// account in case the robot base footprint is asymmetric.
521+
backwards = false;
522+
if (i >= direction_change_index) {
523+
backwards = true;
524+
float opposite_heading_theta =
525+
motion_projection.theta - (motion_table.num_angle_quantization / 2);
526+
if (opposite_heading_theta < 0) {
527+
opposite_heading_theta += motion_table.num_angle_quantization;
528+
}
529+
if (opposite_heading_theta > motion_table.num_angle_quantization) {
530+
opposite_heading_theta -= motion_table.num_angle_quantization;
531+
}
532+
motion_projection.theta = opposite_heading_theta;
533+
}
534+
518535
index = NodeLattice::getIndex(
519536
static_cast<unsigned int>(motion_projection.x),
520537
static_cast<unsigned int>(motion_projection.y),
@@ -524,28 +541,12 @@ void NodeLattice::getNeighbors(
524541
// Cache the initial pose in case it was visited but valid
525542
// don't want to disrupt continuous coordinate expansion
526543
initial_node_coords = neighbor->pose;
527-
// if i >= idx, then we're in a reversing primitive. In that situation,
528-
// the orientation of the robot is mirrored from what it would otherwise
529-
// appear to be from the motion primitives file. We want to take this into
530-
// account in case the robot base footprint is asymmetric.
531-
backwards = false;
532-
angle = motion_projection.theta;
533-
if (i >= direction_change_index) {
534-
backwards = true;
535-
angle = motion_projection.theta - (motion_table.num_angle_quantization / 2);
536-
if (angle < 0) {
537-
angle += motion_table.num_angle_quantization;
538-
}
539-
if (angle > motion_table.num_angle_quantization) {
540-
angle -= motion_table.num_angle_quantization;
541-
}
542-
}
543544

544545
neighbor->setPose(
545546
Coordinates(
546547
motion_projection.x,
547548
motion_projection.y,
548-
angle));
549+
motion_projection.theta));
549550

550551
// Using a special isNodeValid API here, giving the motion primitive to use to
551552
// validity check the transition of the current node to the new node over

0 commit comments

Comments
 (0)