Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
robot_utils.hpp
1 // Copyright (c) 2018 Intel Corporation
2 // Copyright (c) 2019 Steven Macenski
3 // Copyright (c) 2019 Samsung Research America
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef NAV2_UTIL__ROBOT_UTILS_HPP_
18 #define NAV2_UTIL__ROBOT_UTILS_HPP_
19 
20 #include <string>
21 #include <memory>
22 
23 #include "geometry_msgs/msg/pose_stamped.hpp"
24 #include "geometry_msgs/msg/twist.hpp"
25 #include "geometry_msgs/msg/twist_stamped.hpp"
26 #include "geometry_msgs/msg/transform_stamped.hpp"
27 #include "tf2/time.hpp"
28 #include "tf2/transform_datatypes.hpp"
29 #include "nav2_ros_common/tf2_factories.hpp"
30 #include "tf2_geometry_msgs/tf2_geometry_msgs.hpp"
31 #include "rclcpp/rclcpp.hpp"
32 
33 namespace nav2_util
34 {
35 
48 bool lookupTransformWithStalenessCheck(
49  nav2::TransformBuffer & tf_buffer,
50  const std::string & target_frame,
51  const std::string & source_frame,
52  const rclcpp::Time & current_time,
53  double staleness_threshold,
54  geometry_msgs::msg::TransformStamped & transform);
55 
61 geometry_msgs::msg::PoseStamped transformToPoseStamped(
62  const geometry_msgs::msg::TransformStamped & transform);
63 
70 geometry_msgs::msg::TransformStamped poseToTransformStamped(
71  const geometry_msgs::msg::PoseStamped & pose, const std::string & child_frame);
72 
84 bool getFreshPose(
85  nav2::TransformBuffer & tf_buffer,
86  const std::string & target_frame,
87  const std::string & source_frame,
88  const rclcpp::Time & current_time,
89  double staleness_threshold,
90  geometry_msgs::msg::PoseStamped & pose);
91 
101 bool getCurrentPose(
102  geometry_msgs::msg::PoseStamped & global_pose,
103  nav2::TransformBuffer & tf_buffer, const std::string global_frame = "map",
104  const std::string robot_frame = "base_link", const double transform_timeout = 0.1,
105  const rclcpp::Time stamp = rclcpp::Time());
106 
116 bool transformPoseInTargetFrame(
117  const geometry_msgs::msg::PoseStamped & input_pose,
118  geometry_msgs::msg::PoseStamped & transformed_pose,
119  nav2::TransformBuffer & tf_buffer, const std::string target_frame,
120  const double transform_timeout = 0.1);
121 
131 bool getTransform(
132  const std::string & source_frame_id,
133  const std::string & target_frame_id,
134  const tf2::Duration & transform_tolerance,
135  const nav2::TransformBuffer::SharedPtr tf_buffer,
136  tf2::Transform & tf2_transform);
137 
151 bool getTransform(
152  const std::string & source_frame_id,
153  const rclcpp::Time & source_time,
154  const std::string & target_frame_id,
155  const rclcpp::Time & target_time,
156  const std::string & fixed_frame_id,
157  const tf2::Duration & transform_tolerance,
158  const nav2::TransformBuffer::SharedPtr tf_buffer,
159  tf2::Transform & tf2_transform);
160 
170 bool getTransform(
171  const std::string & source_frame_id,
172  const std::string & target_frame_id,
173  const tf2::Duration & transform_tolerance,
174  const nav2::TransformBuffer::SharedPtr tf_buffer,
175  geometry_msgs::msg::TransformStamped & transform_msg);
176 
190 bool getTransform(
191  const std::string & source_frame_id,
192  const rclcpp::Time & source_time,
193  const std::string & target_frame_id,
194  const rclcpp::Time & target_time,
195  const std::string & fixed_frame_id,
196  const tf2::Duration & transform_tolerance,
197  const nav2::TransformBuffer::SharedPtr tf_buffer,
198  geometry_msgs::msg::TransformStamped & transform_msg);
199 
205 [[nodiscard]] bool validateTwist(const geometry_msgs::msg::Twist & msg);
206 
207 } // end namespace nav2_util
208 
209 #endif // NAV2_UTIL__ROBOT_UTILS_HPP_