Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
critic_manager.hpp
1 // Copyright (c) 2022 Samsung Research America, @artofnothingness Alexey Budyakov
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NAV2_MPPI_CONTROLLER__CRITIC_MANAGER_HPP_
16 #define NAV2_MPPI_CONTROLLER__CRITIC_MANAGER_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 #include <pluginlib/class_loader.hpp>
23 
24 #include "geometry_msgs/msg/twist.hpp"
25 #include "geometry_msgs/msg/twist_stamped.hpp"
26 #include "nav2_msgs/msg/critics_stats.hpp"
27 
28 #include "nav2_costmap_2d/costmap_2d_ros.hpp"
29 #include "rclcpp_lifecycle/lifecycle_node.hpp"
30 
31 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
32 #include "nav2_mppi_controller/tools/utils.hpp"
33 #include "nav2_mppi_controller/critic_data.hpp"
34 #include "nav2_mppi_controller/critic_function.hpp"
35 
36 namespace mppi
37 {
38 
44 {
45 public:
46  typedef std::vector<std::unique_ptr<critics::CriticFunction>> Critics;
50  CriticManager() = default;
51 
52 
56  virtual ~CriticManager() = default;
57 
65  void on_configure(
66  nav2::LifecycleNode::WeakPtr parent, const std::string & name,
67  std::shared_ptr<nav2_costmap_2d::Costmap2DROS>, ParametersHandler *);
68 
74 
79  const std::vector<std::pair<std::string, Eigen::ArrayXf>> & getCriticCosts() const
80  {
81  return critic_costs_;
82  }
83 
84 protected:
88  void getParams();
89 
93  virtual void loadCritics();
94 
98  std::string getFullName(const std::string & name);
99 
100 protected:
101  nav2::LifecycleNode::WeakPtr parent_;
102  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
103  std::string name_;
104 
105  ParametersHandler * parameters_handler_;
106  std::vector<std::string> critic_names_;
107  std::unique_ptr<pluginlib::ClassLoader<critics::CriticFunction>> loader_;
108  Critics critics_;
109 
110  nav2::Publisher<nav2_msgs::msg::CriticsStats>::SharedPtr critics_effect_pub_;
111  bool visualize_;
112  std::vector<std::pair<std::string, Eigen::ArrayXf>> critic_costs_;
113  rclcpp::Clock::SharedPtr clock_;
114 
115  rclcpp::Logger logger_{rclcpp::get_logger("MPPIController")};
116 };
117 
118 } // namespace mppi
119 
120 #endif // NAV2_MPPI_CONTROLLER__CRITIC_MANAGER_HPP_
Manager of objective function plugins for scoring trajectories.
virtual ~CriticManager()=default
Virtual Destructor for mppi::CriticManager.
void on_configure(nav2::LifecycleNode::WeakPtr parent, const std::string &name, std::shared_ptr< nav2_costmap_2d::Costmap2DROS >, ParametersHandler *)
Configure critic manager on bringup and load plugins.
void evalTrajectoriesScores(CriticData &data)
Score trajectories by the set of loaded critic functions.
void getParams()
Get parameters (critics to load)
const std::vector< std::pair< std::string, Eigen::ArrayXf > > & getCriticCosts() const
Get stored per-critic costs from last evaluation.
CriticManager()=default
Constructor for mppi::CriticManager.
virtual void loadCritics()
Load the critic plugins.
std::string getFullName(const std::string &name)
Get full-name namespaced critic IDs.
Handles getting parameters and dynamic parameter changes.
Data to pass to critics for scoring, including state, trajectories, pruned path, global goal,...
Definition: critic_data.hpp:40