Nav2 Navigation Stack - jazzy  jazzy
ROS 2 Navigation Stack
publisher.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef DWB_CORE__PUBLISHER_HPP_
36 #define DWB_CORE__PUBLISHER_HPP_
37 
38 #include <memory>
39 #include <string>
40 #include <vector>
41 
42 #include "nav2_costmap_2d/costmap_2d_ros.hpp"
43 #include "dwb_core/trajectory_critic.hpp"
44 #include "dwb_msgs/msg/local_plan_evaluation.hpp"
45 #include "nav_msgs/msg/path.hpp"
46 #include "rclcpp/rclcpp.hpp"
47 #include "sensor_msgs/msg/point_cloud2.hpp"
48 #include "visualization_msgs/msg/marker_array.hpp"
49 #include "nav2_util/lifecycle_node.hpp"
50 #include "builtin_interfaces/msg/duration.hpp"
51 
52 using rclcpp_lifecycle::LifecyclePublisher;
53 
54 namespace dwb_core
55 {
56 
70 {
71 public:
72  explicit DWBPublisher(
73  const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
74  const std::string & plugin_name);
75 
76  nav2_util::CallbackReturn on_configure();
77  nav2_util::CallbackReturn on_activate();
78  nav2_util::CallbackReturn on_deactivate();
79  nav2_util::CallbackReturn on_cleanup();
80 
85  bool shouldRecordEvaluation() {return publish_evaluation_ || publish_trajectories_;}
86 
90  void publishEvaluation(std::shared_ptr<dwb_msgs::msg::LocalPlanEvaluation> results);
91  void publishLocalPlan(
92  const std_msgs::msg::Header & header,
93  const dwb_msgs::msg::Trajectory2D & traj);
94  void publishCostGrid(
95  const std::shared_ptr<nav2_costmap_2d::Costmap2DROS> costmap_ros,
96  const std::vector<TrajectoryCritic::Ptr> critics);
97  void publishGlobalPlan(const nav_2d_msgs::msg::Path2D plan);
98  void publishTransformedPlan(const nav_2d_msgs::msg::Path2D plan);
99  void publishLocalPlan(const nav_2d_msgs::msg::Path2D plan);
100 
101 protected:
102  void publishTrajectories(const dwb_msgs::msg::LocalPlanEvaluation & results);
103 
104  // Helper function for publishing other plans
105  void publishGenericPlan(
106  const nav_2d_msgs::msg::Path2D plan,
107  rclcpp::Publisher<nav_msgs::msg::Path> & pub, bool flag);
108 
109  // Flags for turning on/off publishing specific components
110  bool publish_evaluation_;
111  bool publish_global_plan_;
112  bool publish_transformed_;
113  bool publish_local_plan_;
114  bool publish_trajectories_;
115  bool publish_cost_grid_pc_;
116  bool publish_input_params_;
117 
118  // Marker Lifetime
119  builtin_interfaces::msg::Duration marker_lifetime_;
120 
121  // Publisher Objects
122  std::shared_ptr<LifecyclePublisher<dwb_msgs::msg::LocalPlanEvaluation>> eval_pub_;
123  std::shared_ptr<LifecyclePublisher<nav_msgs::msg::Path>> global_pub_;
124  std::shared_ptr<LifecyclePublisher<nav_msgs::msg::Path>> transformed_pub_;
125  std::shared_ptr<LifecyclePublisher<nav_msgs::msg::Path>> local_pub_;
126  std::shared_ptr<LifecyclePublisher<visualization_msgs::msg::MarkerArray>> marker_pub_;
127  std::shared_ptr<LifecyclePublisher<sensor_msgs::msg::PointCloud2>> cost_grid_pc_pub_;
128 
129  rclcpp_lifecycle::LifecycleNode::WeakPtr node_;
130  rclcpp::Clock::SharedPtr clock_;
131  std::string plugin_name_;
132 };
133 
134 } // namespace dwb_core
135 
136 #endif // DWB_CORE__PUBLISHER_HPP_
Consolidation of all the publishing logic for the DWB Local Planner.
Definition: publisher.hpp:70
bool shouldRecordEvaluation()
Does the publisher require that the LocalPlanEvaluation be saved.
Definition: publisher.hpp:85
void publishEvaluation(std::shared_ptr< dwb_msgs::msg::LocalPlanEvaluation > results)
If the pointer is not null, publish the evaluation and trajectories as needed.
Definition: publisher.cpp:158