From 29321d661f6acb505192d4b24aa983fe10a733c5 Mon Sep 17 00:00:00 2001 From: Renan Salles Date: Fri, 12 Jan 2024 13:02:39 +0900 Subject: [PATCH] Add inflation_layer_name param (#4047) Signed-off-by: Renan Salles --- nav2_mppi_controller/README.md | 1 + .../nav2_mppi_controller/critics/obstacles_critic.hpp | 4 +++- nav2_mppi_controller/src/critics/obstacles_critic.cpp | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/nav2_mppi_controller/README.md b/nav2_mppi_controller/README.md index 4f5a9398d1..fd7ad80214 100644 --- a/nav2_mppi_controller/README.md +++ b/nav2_mppi_controller/README.md @@ -107,6 +107,7 @@ This process is then repeated a number of times and returns a converged solution | collision_cost | double | Default 100000.0. Cost to apply to a true collision in a trajectory. | | collision_margin_distance | double | Default 0.10. Margin distance from collision to apply severe penalty, similar to footprint inflation. Between 0.05-0.2 is reasonable. | | near_goal_distance | double | Default 0.5. Distance near goal to stop applying preferential obstacle term to allow robot to smoothly converge to goal pose in close proximity to obstacles. + | inflation_layer_name | string | Default "". Name of the inflation layer. If empty, it uses the last inflation layer in the costmap. If you have multiple inflation layers, you may want to specify the name of the layer to use. | #### Path Align Critic | Parameter | Type | Definition | diff --git a/nav2_mppi_controller/include/nav2_mppi_controller/critics/obstacles_critic.hpp b/nav2_mppi_controller/include/nav2_mppi_controller/critics/obstacles_critic.hpp index fd6eeab012..358994c238 100644 --- a/nav2_mppi_controller/include/nav2_mppi_controller/critics/obstacles_critic.hpp +++ b/nav2_mppi_controller/include/nav2_mppi_controller/critics/obstacles_critic.hpp @@ -16,9 +16,10 @@ #define NAV2_MPPI_CONTROLLER__CRITICS__OBSTACLES_CRITIC_HPP_ #include +#include + #include "nav2_costmap_2d/footprint_collision_checker.hpp" #include "nav2_costmap_2d/inflation_layer.hpp" - #include "nav2_mppi_controller/critic_function.hpp" #include "nav2_mppi_controller/models/state.hpp" #include "nav2_mppi_controller/tools/utils.hpp" @@ -96,6 +97,7 @@ class ObstaclesCritic : public CriticFunction unsigned int power_{0}; float repulsion_weight_, critical_weight_{0}; + std::string inflation_layer_name_; }; } // namespace mppi::critics diff --git a/nav2_mppi_controller/src/critics/obstacles_critic.cpp b/nav2_mppi_controller/src/critics/obstacles_critic.cpp index 274315a06b..ecb22b295b 100644 --- a/nav2_mppi_controller/src/critics/obstacles_critic.cpp +++ b/nav2_mppi_controller/src/critics/obstacles_critic.cpp @@ -29,6 +29,7 @@ void ObstaclesCritic::initialize() getParam(collision_cost_, "collision_cost", 100000.0); getParam(collision_margin_distance_, "collision_margin_distance", 0.10); getParam(near_goal_distance_, "near_goal_distance", 0.5); + getParam(inflation_layer_name_, "inflation_layer_name", std::string("")); collision_checker_.setCostmap(costmap_); possibly_inscribed_cost_ = findCircumscribedCost(costmap_ros_); @@ -69,7 +70,10 @@ float ObstaclesCritic::findCircumscribedCost( ++layer) { auto inflation_layer = std::dynamic_pointer_cast(*layer); - if (!inflation_layer) { + if (!inflation_layer || + (!inflation_layer_name_.empty() && + inflation_layer->getName() != inflation_layer_name_)) + { continue; }