Nav2 Navigation Stack - jazzy  jazzy
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 // xtensor creates warnings that needs to be ignored as we are building with -Werror
24 #pragma GCC diagnostic push
25 #pragma GCC diagnostic ignored "-Warray-bounds"
26 #pragma GCC diagnostic ignored "-Wstringop-overflow"
27 #include <xtensor/xtensor.hpp>
28 #pragma GCC diagnostic pop
29 
30 #include "geometry_msgs/msg/twist.hpp"
31 #include "geometry_msgs/msg/twist_stamped.hpp"
32 
33 #include "nav2_costmap_2d/costmap_2d_ros.hpp"
34 #include "rclcpp_lifecycle/lifecycle_node.hpp"
35 
36 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
37 #include "nav2_mppi_controller/tools/utils.hpp"
38 #include "nav2_mppi_controller/critic_data.hpp"
39 #include "nav2_mppi_controller/critic_function.hpp"
40 
41 namespace mppi
42 {
43 
49 {
50 public:
51  typedef std::vector<std::unique_ptr<critics::CriticFunction>> Critics;
55  CriticManager() = default;
56 
57 
61  virtual ~CriticManager() = default;
62 
70  void on_configure(
71  rclcpp_lifecycle::LifecycleNode::WeakPtr parent, const std::string & name,
72  std::shared_ptr<nav2_costmap_2d::Costmap2DROS>, ParametersHandler *);
73 
78  void evalTrajectoriesScores(CriticData & data) const;
79 
80 protected:
84  void getParams();
85 
89  virtual void loadCritics();
90 
94  std::string getFullName(const std::string & name);
95 
96 protected:
97  rclcpp_lifecycle::LifecycleNode::WeakPtr parent_;
98  std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros_;
99  std::string name_;
100 
101  ParametersHandler * parameters_handler_;
102  std::vector<std::string> critic_names_;
103  std::unique_ptr<pluginlib::ClassLoader<critics::CriticFunction>> loader_;
104  Critics critics_;
105 
106  rclcpp::Logger logger_{rclcpp::get_logger("MPPIController")};
107 };
108 
109 } // namespace mppi
110 
111 #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(rclcpp_lifecycle::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 parmaeter changes.
Data to pass to critics for scoring, including state, trajectories, pruned path, global goal,...
Definition: critic_data.hpp:45