Nav2 Navigation Stack - kilted  kilted
ROS 2 Navigation Stack
trajectory_visualizer.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__TOOLS__TRAJECTORY_VISUALIZER_HPP_
16 #define NAV2_MPPI_CONTROLLER__TOOLS__TRAJECTORY_VISUALIZER_HPP_
17 
18 #include <Eigen/Dense>
19 
20 #include <memory>
21 #include <string>
22 
23 #include "nav_msgs/msg/path.hpp"
24 #include "rclcpp/rclcpp.hpp"
25 #include "rclcpp_lifecycle/lifecycle_node.hpp"
26 #include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
27 
28 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
29 #include "nav2_mppi_controller/tools/utils.hpp"
30 #include "nav2_mppi_controller/models/trajectories.hpp"
31 
32 namespace mppi
33 {
34 
40 {
41 public:
45  TrajectoryVisualizer() = default;
46 
54  void on_configure(
55  rclcpp_lifecycle::LifecycleNode::WeakPtr parent, const std::string & name,
56  const std::string & frame_id, ParametersHandler * parameters_handler);
57 
61  void on_cleanup();
62 
66  void on_activate();
67 
71  void on_deactivate();
72 
77  void add(
78  const Eigen::ArrayXXf & trajectory, const std::string & marker_namespace,
79  const builtin_interfaces::msg::Time & cmd_stamp);
80 
85  void add(const models::Trajectories & trajectories, const std::string & marker_namespace);
86 
91  void visualize(const nav_msgs::msg::Path & plan);
92 
96  void reset();
97 
98 protected:
99  std::string frame_id_;
100  std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<visualization_msgs::msg::MarkerArray>>
101  trajectories_publisher_;
102  std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::Path>> transformed_path_pub_;
103  std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::Path>> optimal_path_pub_;
104 
105  std::unique_ptr<nav_msgs::msg::Path> optimal_path_;
106  std::unique_ptr<visualization_msgs::msg::MarkerArray> points_;
107  int marker_id_ = 0;
108 
109  ParametersHandler * parameters_handler_;
110 
111  size_t trajectory_step_{0};
112  size_t time_step_{0};
113 
114  rclcpp::Logger logger_{rclcpp::get_logger("MPPIController")};
115 };
116 
117 } // namespace mppi
118 
119 #endif // NAV2_MPPI_CONTROLLER__TOOLS__TRAJECTORY_VISUALIZER_HPP_
Handles getting parameters and dynamic parameter changes.
Visualizes trajectories for debugging.
void add(const Eigen::ArrayXXf &trajectory, const std::string &marker_namespace, const builtin_interfaces::msg::Time &cmd_stamp)
Add an optimal trajectory to visualize.
void visualize(const nav_msgs::msg::Path &plan)
Visualize the plan.
void on_deactivate()
Deactivate object.
TrajectoryVisualizer()=default
Constructor for mppi::TrajectoryVisualizer.
void on_configure(rclcpp_lifecycle::LifecycleNode::WeakPtr parent, const std::string &name, const std::string &frame_id, ParametersHandler *parameters_handler)
Configure trajectory visualizer.
void on_activate()
Activate object.
void on_cleanup()
Cleanup object on shutdown.
Candidate Trajectories.