Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
footprint_subscriber.hpp
1 // Copyright (c) 2019 Intel Corporation
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_COSTMAP_2D__FOOTPRINT_SUBSCRIBER_HPP_
16 #define NAV2_COSTMAP_2D__FOOTPRINT_SUBSCRIBER_HPP_
17 
18 #include <atomic>
19 #include <string>
20 #include <vector>
21 
22 #include "rclcpp/rclcpp.hpp"
23 #include "nav2_costmap_2d/footprint.hpp"
24 #include "nav2_ros_common/lifecycle_node.hpp"
25 #include "nav2_ros_common/tf2_factories.hpp"
26 #include "nav2_util/robot_utils.hpp"
27 
28 namespace nav2_costmap_2d
29 {
36 {
37 public:
41  template<typename NodeT>
43  const NodeT & parent,
44  const std::string & topic_name,
45  nav2::TransformBuffer & tf,
46  std::string robot_base_frame = "base_link",
47  double transform_tolerance = 0.1)
48  : tf_(tf),
49  robot_base_frame_(robot_base_frame),
50  transform_tolerance_(transform_tolerance)
51  {
52  // Could be using a user rclcpp::Node, so need to use the Nav2 factory to create the
53  // subscription to convert nav2::LifecycleNode, rclcpp::Node or rclcpp_lifecycle::LifecycleNode
54  footprint_sub_ = nav2::interfaces::create_subscription<geometry_msgs::msg::PolygonStamped>(
55  parent, topic_name,
56  std::bind(&FootprintSubscriber::footprint_callback, this, std::placeholders::_1));
57  }
58 
63 
71  bool getFootprintRaw(
72  std::vector<geometry_msgs::msg::Point> & footprint,
73  std_msgs::msg::Header & footprint_header);
74 
83  std::vector<geometry_msgs::msg::Point> & footprint,
84  std_msgs::msg::Header & footprint_header);
85 
86 protected:
90  void footprint_callback(const geometry_msgs::msg::PolygonStamped::ConstSharedPtr & msg);
91 
92  nav2::TransformBuffer & tf_;
93  std::string robot_base_frame_;
94  double transform_tolerance_;
95  std::atomic_bool footprint_received_{false};
96  std::atomic<geometry_msgs::msg::PolygonStamped::ConstSharedPtr> footprint_;
97  nav2::Subscription<geometry_msgs::msg::PolygonStamped>::SharedPtr footprint_sub_;
98 };
99 
100 } // namespace nav2_costmap_2d
101 
102 #endif // NAV2_COSTMAP_2D__FOOTPRINT_SUBSCRIBER_HPP_
Subscriber to the footprint topic to get current robot footprint (if changing) for use in collision a...
FootprintSubscriber(const NodeT &parent, const std::string &topic_name, nav2::TransformBuffer &tf, std::string robot_base_frame="base_link", double transform_tolerance=0.1)
A constructor.
void footprint_callback(const geometry_msgs::msg::PolygonStamped::ConstSharedPtr &msg)
Callback to process new footprint updates.
bool getFootprintInRobotFrame(std::vector< geometry_msgs::msg::Point > &footprint, std_msgs::msg::Header &footprint_header)
Returns the latest robot footprint, transformed into robot base frame (unoriented).
bool getFootprintRaw(std::vector< geometry_msgs::msg::Point > &footprint, std_msgs::msg::Header &footprint_header)
Returns the latest robot footprint, in the form as received from topic (oriented).