Nav2 Navigation Stack - rolling  main
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 <vector>
21 #include <pluginlib/class_loader.hpp>
22 
23 #include "geometry_msgs/msg/twist.hpp"
24 #include "geometry_msgs/msg/twist_stamped.hpp"
25 #include "nav2_msgs/msg/critics_stats.hpp"
26 
27 #include "nav2_costmap_2d/costmap_2d_ros.hpp"
28 #include "rclcpp_lifecycle/lifecycle_node.hpp"
29 
30 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
31 #include "nav2_mppi_controller/tools/utils.hpp"
32 #include "nav2_mppi_controller/critic_data.hpp"
33 #include "nav2_mppi_controller/critic_function.hpp"
34 
35 namespace mppi
36 {
37 
43 {
44 public:
45  typedef std::vector<std::unique_ptr<critics::CriticFunction>> Critics;
49  CriticManager() = default;
50 
51 
55  virtual ~CriticManager() = default;
56 
64  void on_configure(
65  nav2::LifecycleNode::WeakPtr parent, const std::string & name,
66  std::shared_ptr<nav2_costmap_2d::Costmap2DROS>, ParametersHandler *);
67 
72  void evalTrajectoriesScores(CriticData & data) const;
73 
74 protected:
78  void getParams();
79 
83  virtual void loadCritics();
84 
88  std::string getFullName(const std::string & name);
89 
90 protected:
91  nav2::LifecycleNode::WeakPtr parent_;
92  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
93  std::string name_;
94 
95  ParametersHandler * parameters_handler_;
96  std::vector<std::string> critic_names_;
97  std::unique_ptr<pluginlib::ClassLoader<critics::CriticFunction>> loader_;
98  Critics critics_;
99 
100  nav2::Publisher<nav2_msgs::msg::CriticsStats>::SharedPtr critics_effect_pub_;
101  bool publish_critics_stats_;
102 
103  rclcpp::Logger logger_{rclcpp::get_logger("MPPIController")};
104 };
105 
106 } // namespace mppi
107 
108 #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 getParams()
Get parameters (critics to load)
void evalTrajectoriesScores(CriticData &data) const
Score trajectories by the set of loaded critic functions.
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