transform_listener.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
32 #ifndef TF_TRANSFORMLISTENER_H
33 #define TF_TRANSFORMLISTENER_H
34 
35 #include "sensor_msgs/PointCloud.h"
36 #include "std_msgs/Empty.h"
37 #include "tf/tfMessage.h"
38 #include "tf/tf.h"
39 #include "ros/ros.h"
40 #include "ros/callback_queue.h"
41 #include "ros/macros.h"
42 
43 #include "tf/FrameGraph.h" //frame graph service
44 #include "boost/thread.hpp"
45 
47 
48 
49 namespace tf{
50 
55 inline std::string getPrefixParam(ros::NodeHandle & nh) {
56  std::string param;
57  if (!nh.searchParam("tf_prefix", param))
58  return "";
59 
60  std::string return_val;
61  nh.getParam(param, return_val);
62  return return_val;
63 }
64 
67 ROS_DEPRECATED std::string remap(const std::string& frame_id);
68 
70 class TransformListener : public Transformer { //subscribes to message and automatically stores incoming data
71 
72 public:
75  TransformListener(ros::Duration max_cache_time = ros::Duration(DEFAULT_CACHE_TIME), bool spin_thread = true);
76 
83  ros::Duration max_cache_time = ros::Duration(DEFAULT_CACHE_TIME), bool spin_thread = true);
84 
86 
87  /* Methods from transformer unhiding them here */
92 
93 
96  void transformQuaternion(const std::string& target_frame, const geometry_msgs::QuaternionStamped& stamped_in, geometry_msgs::QuaternionStamped& stamped_out) const;
99  void transformVector(const std::string& target_frame, const geometry_msgs::Vector3Stamped& stamped_in, geometry_msgs::Vector3Stamped& stamped_out) const;
102  void transformPoint(const std::string& target_frame, const geometry_msgs::PointStamped& stamped_in, geometry_msgs::PointStamped& stamped_out) const;
105  void transformPose(const std::string& target_frame, const geometry_msgs::PoseStamped& stamped_in, geometry_msgs::PoseStamped& stamped_out) const;
106 
107  /* \brief Transform a Stamped Twist Message into the target frame
108  * This can throw all that lookupTransform can throw as well as tf::InvalidTransform */
109  // http://www.ros.org/wiki/tf/Reviews/2010-03-12_API_Review
110  // void transformTwist(const std::string& target_frame, const geometry_msgs::TwistStamped& stamped_in, geometry_msgs::TwistStamped& stamped_out) const;
111 
114  void transformQuaternion(const std::string& target_frame, const ros::Time& target_time,
115  const geometry_msgs::QuaternionStamped& qin,
116  const std::string& fixed_frame, geometry_msgs::QuaternionStamped& qout) const;
119  void transformVector(const std::string& target_frame, const ros::Time& target_time,
120  const geometry_msgs::Vector3Stamped& vin,
121  const std::string& fixed_frame, geometry_msgs::Vector3Stamped& vout) const;
124  void transformPoint(const std::string& target_frame, const ros::Time& target_time,
125  const geometry_msgs::PointStamped& pin,
126  const std::string& fixed_frame, geometry_msgs::PointStamped& pout) const;
129  void transformPose(const std::string& target_frame, const ros::Time& target_time,
130  const geometry_msgs::PoseStamped& pin,
131  const std::string& fixed_frame, geometry_msgs::PoseStamped& pout) const;
132 
133 
136  void transformPointCloud(const std::string& target_frame, const sensor_msgs::PointCloud& pcin, sensor_msgs::PointCloud& pcout) const;
137 
140  void transformPointCloud(const std::string& target_frame, const ros::Time& target_time,
141  const sensor_msgs::PointCloud& pcin,
142  const std::string& fixed_frame, sensor_msgs::PointCloud& pcout) const;
143 
144 
145 
147 
148  bool getFrames(tf::FrameGraph::Request&, tf::FrameGraph::Response& res)
149  {
150  res.dot_graph = allFramesAsDot();
151  return true;
152  }
153 
154  /* \brief Resolve frame_name into a frame_id using tf_prefix parameter */
155  std::string resolve(const std::string& frame_name)
156  {
157  ros::NodeHandle n("~");
158  std::string prefix = tf::getPrefixParam(n);
159  return tf::resolve(prefix, frame_name);
160  };
161 
162 protected:
163  bool ok() const;
164 
165 private:
166 
167  // Must be above the listener
169 
172 
174  void transformPointCloud(const std::string & target_frame, const Transform& transform, const ros::Time& target_time, const sensor_msgs::PointCloud& pcin, sensor_msgs::PointCloud& pcout) const;
175 
176 };
177 }
178 
179 #endif //TF_TRANSFORMLISTENER_H
tf::TransformListener::transformPointCloud
void transformPointCloud(const std::string &target_frame, const sensor_msgs::PointCloud &pcin, sensor_msgs::PointCloud &pcout) const
Transform a sensor_msgs::PointCloud natively This can throw all that lookupTransform can throw as wel...
Definition: transform_listener.cpp:184
tf::Transformer::allFramesAsDot
std::string allFramesAsDot(double current_time=0) const
A way to see what frames have been cached Useful for debugging.
Definition: tf.cpp:439
tf::TransformListener::resolve
std::string resolve(const std::string &frame_name)
Definition: transform_listener.h:155
tf::TransformListener::transformPose
void transformPose(const std::string &target_frame, const geometry_msgs::PoseStamped &stamped_in, geometry_msgs::PoseStamped &stamped_out) const
Transform a Stamped Pose Message into the target frame This can throw all that lookupTransform can th...
Definition: transform_listener.cpp:97
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
ros.h
tf::TransformListener::transformPoint
void transformPoint(const std::string &target_frame, const geometry_msgs::PointStamped &stamped_in, geometry_msgs::PointStamped &stamped_out) const
Transform a Stamped Point Message into the target frame This can throw all that lookupTransform can t...
Definition: transform_listener.cpp:87
tf::resolve
std::string resolve(const std::string &prefix, const std::string &frame_name)
resolve tf names
Definition: tf.cpp:159
tf::TransformListener::transformVector
void transformVector(const std::string &target_frame, const geometry_msgs::Vector3Stamped &stamped_in, geometry_msgs::Vector3Stamped &stamped_out) const
Transform a Stamped Vector Message into the target frame This can throw all that lookupTransform can ...
Definition: transform_listener.cpp:77
tf::Transformer
A Class which provides coordinate transforms between any two frames in a system.
Definition: tf.h:103
ROS_DEPRECATED
#define ROS_DEPRECATED
tf::TransformListener::transformQuaternion
void transformQuaternion(const std::string &target_frame, const geometry_msgs::QuaternionStamped &stamped_in, geometry_msgs::QuaternionStamped &stamped_out) const
Transform a Stamped Quaternion Message into the target frame This can throw all that lookupTransform ...
Definition: transform_listener.cpp:65
tf2_ros::TransformListener
tf::Transformer::DEFAULT_CACHE_TIME
static const double DEFAULT_CACHE_TIME
10.0 is the default amount of time to cache data in seconds, set in cpp file.
Definition: tf.h:108
tf.h
tf::getPrefixParam
std::string getPrefixParam(ros::NodeHandle &nh)
Get the tf_prefix from the parameter server.
Definition: transform_listener.h:55
ros::NodeHandle::searchParam
bool searchParam(const std::string &key, std::string &result) const
tf::Transformer::transformPose
void transformPose(const std::string &target_frame, const Stamped< tf::Pose > &stamped_in, Stamped< tf::Pose > &stamped_out) const
Transform a Stamped Pose into the target frame This can throw anything a lookupTransform can throw as...
Definition: tf.cpp:494
tf::Transform
The Transform class supports rigid transforms with only translation and rotation and no scaling/shear...
Definition: Transform.h:31
tf::TransformListener::tf2_listener_
tf2_ros::TransformListener tf2_listener_
replacing implementation with tf2_ros'
Definition: transform_listener.h:171
tf::TransformListener::ok
bool ok() const
Definition: transform_listener.cpp:61
tf::TransformListener::TransformListener
TransformListener(ros::Duration max_cache_time=ros::Duration(DEFAULT_CACHE_TIME), bool spin_thread=true)
Constructor for transform listener.
Definition: transform_listener.cpp:43
callback_queue.h
transform_listener.h
tf::Transformer::transformVector
void transformVector(const std::string &target_frame, const Stamped< tf::Vector3 > &stamped_in, Stamped< tf::Vector3 > &stamped_out) const
Transform a Stamped Vector3 into the target frame This can throw anything a lookupTransform can throw...
Definition: tf.cpp:466
ros::Time
tf::Transformer::transformQuaternion
void transformQuaternion(const std::string &target_frame, const Stamped< tf::Quaternion > &stamped_in, Stamped< tf::Quaternion > &stamped_out) const
Transform a Stamped Quaternion into the target frame This can throw anything a lookupTransform can th...
Definition: tf.cpp:453
tf::TransformListener
This class inherits from Transformer and automatically subscribes to ROS transform messages.
Definition: transform_listener.h:70
param
T param(const std::string &param_name, const T &default_val)
tf::Transformer::transformPoint
void transformPoint(const std::string &target_frame, const Stamped< tf::Point > &stamped_in, Stamped< tf::Point > &stamped_out) const
Transform a Stamped Point into the target frame This can throw anything a lookupTransform can throw a...
Definition: tf.cpp:484
tf::TransformListener::node_
ros::NodeHandle node_
Definition: transform_listener.h:168
tf
Definition: exceptions.h:38
tf::TransformListener::getFrames
bool getFrames(tf::FrameGraph::Request &, tf::FrameGraph::Response &res)
Definition: transform_listener.h:148
macros.h
tf::TransformListener::~TransformListener
~TransformListener()
Definition: transform_listener.cpp:55
ros::Duration
tf::remap
static ROS_DEPRECATED std::string remap(const std::string &prefix, const std::string &frame_name)
Definition: tf.h:72
ros::NodeHandle


tf
Author(s): Tully Foote, Eitan Marder-Eppstein, Wim Meeussen
autogenerated on Sat Aug 19 2023 02:38:08