Skip to content

Commit 3ed4c2d

Browse files
Fix for robot footprint collision in obstacles critic (#3878) (#3947)
* Inscribed/Circumscribed costs must be updated to take into account the current shape of the robot. Was previous only being called once in initialize(). * Add early return to avoid calculations if footprint has not changed. * Only update radius if using footprint. Add perf timers. * Remove perf timers. * Update comments. --------- Co-authored-by: Leif Terry <[email protected]> (cherry picked from commit 98af3b9) Co-authored-by: LeifHookedWireless <[email protected]>
1 parent 74961ca commit 3ed4c2d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

nav2_mppi_controller/include/nav2_mppi_controller/critics/obstacles_critic.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class ObstaclesCritic : public CriticFunction
9292
float possibly_inscribed_cost_;
9393
float collision_margin_distance_;
9494
float near_goal_distance_;
95+
float circumscribed_cost_{0}, circumscribed_radius_{0};
9596

9697
unsigned int power_{0};
9798
float repulsion_weight_, critical_weight_{0};

nav2_mppi_controller/src/critics/obstacles_critic.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ float ObstaclesCritic::findCircumscribedCost(
5555
{
5656
double result = -1.0;
5757
bool inflation_layer_found = false;
58+
59+
const double circum_radius = costmap->getLayeredCostmap()->getCircumscribedRadius();
60+
if (static_cast<float>(circum_radius) == circumscribed_radius_) {
61+
// early return if footprint size is unchanged
62+
return circumscribed_cost_;
63+
}
64+
5865
// check if the costmap has an inflation layer
5966
for (auto layer = costmap->getLayeredCostmap()->getPlugins()->begin();
6067
layer != costmap->getLayeredCostmap()->getPlugins()->end();
@@ -66,7 +73,6 @@ float ObstaclesCritic::findCircumscribedCost(
6673
}
6774

6875
inflation_layer_found = true;
69-
const double circum_radius = costmap->getLayeredCostmap()->getCircumscribedRadius();
7076
const double resolution = costmap->getCostmap()->getResolution();
7177
result = inflation_layer->computeCost(circum_radius / resolution);
7278
auto getParam = parameters_handler_->getParamGetter(name_);
@@ -84,7 +90,10 @@ float ObstaclesCritic::findCircumscribedCost(
8490
"significantly slow down planning times and not avoid anything but absolute collisions!");
8591
}
8692

87-
return static_cast<float>(result);
93+
circumscribed_radius_ = static_cast<float>(circum_radius);
94+
circumscribed_cost_ = static_cast<float>(result);
95+
96+
return circumscribed_cost_;
8897
}
8998

9099
float ObstaclesCritic::distanceToObstacle(const CollisionCost & cost)
@@ -109,6 +118,11 @@ void ObstaclesCritic::score(CriticData & data)
109118
return;
110119
}
111120

121+
if (consider_footprint_) {
122+
// footprint may have changed since initialization if user has dynamic footprints
123+
possibly_inscribed_cost_ = findCircumscribedCost(costmap_ros_);
124+
}
125+
112126
// If near the goal, don't apply the preferential term since the goal is near obstacles
113127
bool near_goal = false;
114128
if (utils::withinPositionGoalTolerance(near_goal_distance_, data.state.pose.pose, data.path)) {

0 commit comments

Comments
 (0)