Skip to content

Commit

Permalink
Fixed vector::reserve exception in smac planner due to precision error (
Browse files Browse the repository at this point in the history
#2563)

- Related issue: #2547
  • Loading branch information
zoltan-lengyel authored and SteveMacenski committed Sep 15, 2021
1 parent 0e59580 commit 2eb6e0f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions nav2_smac_planner/src/a_star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,12 @@ typename AStarAlgorithm<NodeT>::AnalyticExpansionNodes AStarAlgorithm<NodeT>::ge
node->motion_table.state_space->interpolate(from(), to(), i / num_intervals, s());
reals = s.reals();
angle = reals[2] / node->motion_table.bin_size;
while (angle >= node->motion_table.num_angle_quantization_float) {
angle -= node->motion_table.num_angle_quantization_float;
}
while (angle < 0.0) {
angle += node->motion_table.num_angle_quantization_float;
}
while (angle >= node->motion_table.num_angle_quantization_float) {
angle -= node->motion_table.num_angle_quantization_float;
}
// Turn the pose into a node, and check if it is valid
index = NodeT::getIndex(
static_cast<unsigned int>(reals[0]),
Expand Down
8 changes: 4 additions & 4 deletions nav2_smac_planner/src/node_hybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ MotionPoses HybridMotionTable::getProjections(const NodeHybrid * node)
const float & node_heading = node->pose.theta;
float new_heading = node_heading + motion_model._theta;

if (new_heading >= num_angle_quantization_float) {
new_heading -= num_angle_quantization_float;
}

if (new_heading < 0.0) {
new_heading += num_angle_quantization_float;
}

if (new_heading >= num_angle_quantization_float) {
new_heading -= num_angle_quantization_float;
}

projection_list.emplace_back(
delta_xs[i][node_heading] + node->pose.x,
delta_ys[i][node_heading] + node->pose.y,
Expand Down
8 changes: 8 additions & 0 deletions nav2_smac_planner/src/smac_planner_hybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ nav_msgs::msg::Path SmacPlannerHybrid::createPlan(
while (orientation_bin < 0.0) {
orientation_bin += static_cast<float>(_angle_quantizations);
}
// This is needed to handle precision issues
if (orientation_bin >= static_cast<float>(_angle_quantizations)) {
orientation_bin -= static_cast<float>(_angle_quantizations);
}
unsigned int orientation_bin_id = static_cast<unsigned int>(floor(orientation_bin));
_a_star->setStart(mx, my, orientation_bin_id);

Expand All @@ -272,6 +276,10 @@ nav_msgs::msg::Path SmacPlannerHybrid::createPlan(
while (orientation_bin < 0.0) {
orientation_bin += static_cast<float>(_angle_quantizations);
}
// This is needed to handle precision issues
if (orientation_bin >= static_cast<float>(_angle_quantizations)) {
orientation_bin -= static_cast<float>(_angle_quantizations);
}
orientation_bin_id = static_cast<unsigned int>(floor(orientation_bin));
_a_star->setGoal(mx, my, orientation_bin_id);

Expand Down

0 comments on commit 2eb6e0f

Please sign in to comment.