Nav2 Navigation Stack - rolling  main
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 "nav2_ros_common/lifecycle_node.hpp"
25 #include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
26 
27 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
28 #include "nav2_mppi_controller/tools/utils.hpp"
29 #include "nav2_mppi_controller/models/trajectories.hpp"
30 
31 namespace mppi
32 {
33 
39 {
40 public:
44  TrajectoryVisualizer() = default;
45 
53  void on_configure(
54  nav2::LifecycleNode::WeakPtr parent, const std::string & name,
55  const std::string & frame_id, ParametersHandler * parameters_handler);
56 
60  void on_cleanup();
61 
65  void on_activate();
66 
70  void on_deactivate();
71 
76  void add(
77  const Eigen::ArrayXXf & trajectory, const std::string & marker_namespace,
78  const builtin_interfaces::msg::Time & cmd_stamp);
79 
84  void add(const models::Trajectories & trajectories, const std::string & marker_namespace);
85 
90  void visualize(const nav_msgs::msg::Path & plan);
91 
95  void reset();
96 
97 protected:
98  std::string frame_id_;
99  nav2::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr
100  trajectories_publisher_;
101  nav2::Publisher<nav_msgs::msg::Path>::SharedPtr transformed_path_pub_;
102  nav2::Publisher<nav_msgs::msg::Path>::SharedPtr optimal_path_pub_;
103 
104  std::unique_ptr<nav_msgs::msg::Path> optimal_path_;
105  std::unique_ptr<visualization_msgs::msg::MarkerArray> points_;
106  int marker_id_ = 0;
107 
108  ParametersHandler * parameters_handler_;
109 
110  size_t trajectory_step_{0};
111  size_t time_step_{0};
112 
113  rclcpp::Logger logger_{rclcpp::get_logger("MPPIController")};
114 };
115 
116 } // namespace mppi
117 
118 #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(nav2::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.