Nav2 Navigation Stack - jazzy  jazzy
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 <memory>
19 #include <string>
20 
21 // xtensor creates warnings that needs to be ignored as we are building with -Werror
22 #pragma GCC diagnostic push
23 #pragma GCC diagnostic ignored "-Warray-bounds"
24 #pragma GCC diagnostic ignored "-Wstringop-overflow"
25 #include <xtensor/xtensor.hpp>
26 #pragma GCC diagnostic pop
27 
28 #include "nav_msgs/msg/path.hpp"
29 #include "rclcpp/rclcpp.hpp"
30 #include "rclcpp_lifecycle/lifecycle_node.hpp"
31 #include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
32 
33 #include "nav2_mppi_controller/tools/parameters_handler.hpp"
34 #include "nav2_mppi_controller/tools/utils.hpp"
35 #include "nav2_mppi_controller/models/trajectories.hpp"
36 
37 namespace mppi
38 {
39 
45 {
46 public:
50  TrajectoryVisualizer() = default;
51 
59  void on_configure(
60  rclcpp_lifecycle::LifecycleNode::WeakPtr parent, const std::string & name,
61  const std::string & frame_id, ParametersHandler * parameters_handler);
62 
66  void on_cleanup();
67 
71  void on_activate();
72 
76  void on_deactivate();
77 
82  void add(
83  const xt::xtensor<float, 2> & trajectory, const std::string & marker_namespace,
84  const builtin_interfaces::msg::Time & cmd_stamp);
85 
90  void add(const models::Trajectories & trajectories, const std::string & marker_namespace);
91 
96  void visualize(const nav_msgs::msg::Path & plan);
97 
101  void reset();
102 
103 protected:
104  std::string frame_id_;
105  std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<visualization_msgs::msg::MarkerArray>>
106  trajectories_publisher_;
107  std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::Path>> transformed_path_pub_;
108  std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<nav_msgs::msg::Path>> optimal_path_pub_;
109 
110  std::unique_ptr<nav_msgs::msg::Path> optimal_path_;
111  std::unique_ptr<visualization_msgs::msg::MarkerArray> points_;
112  int marker_id_ = 0;
113 
114  ParametersHandler * parameters_handler_;
115 
116  size_t trajectory_step_{0};
117  size_t time_step_{0};
118 
119  rclcpp::Logger logger_{rclcpp::get_logger("MPPIController")};
120 };
121 
122 } // namespace mppi
123 
124 #endif // NAV2_MPPI_CONTROLLER__TOOLS__TRAJECTORY_VISUALIZER_HPP_
Handles getting parameters and dynamic parmaeter changes.
Visualizes trajectories for debugging.
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 add(const xt::xtensor< float, 2 > &trajectory, const std::string &marker_namespace, const builtin_interfaces::msg::Time &cmd_stamp)
Add an optimal trajectory to visualize.
void on_cleanup()
Cleanup object on shutdown.
Candidate Trajectories.