rapid
A ROS robotics library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
tf_listener.h
Go to the documentation of this file.
1 #ifndef _RAPID_ROS_TF_LISTENER_H_
2 #define _RAPID_ROS_TF_LISTENER_H_
3 
4 #include <map>
5 #include <string>
6 #include <utility>
7 
8 #include "tf/transform_datatypes.h"
9 #include "tf/transform_listener.h"
10 #include "ros/duration.h"
11 #include "ros/time.h"
12 
13 namespace rapid_ros {
14 // Interface wrapper for a tf::TransformListener.
15 // Supports only a subset of TransformListener for now, more will be added as
16 // needed.
18  public:
19  virtual ~TfListenerInterface() {}
20  // Waits for a transformation to be available
21  virtual bool waitForTransform(const std::string& target_frame,
22  const std::string& source_frame,
23  const ros::Time& time,
24  const ros::Duration& timeout) const = 0;
25  virtual void lookupTransform(const std::string& target_frame,
26  const std::string& source_frame,
27  const ros::Time& time,
28  tf::StampedTransform& transform) const = 0;
29 };
30 
31 // A wrapper around a real tf::TransformListener.
33  public:
34  TfListener();
35  bool waitForTransform(const std::string& target_frame,
36  const std::string& source_frame, const ros::Time& time,
37  const ros::Duration& timeout) const;
38  void lookupTransform(const std::string& target_frame,
39  const std::string& source_frame, const ros::Time& time,
40  tf::StampedTransform& transform) const;
41 
42  private:
43  tf::TransformListener tf_;
44 };
45 
46 // A mock tf listener.
47 //
48 // For each FramePair (target, source), you can specify the transform to be
49 // returned, how long it should take to return the transform, and whether or not
50 // looking up the transform should throw an exception.
51 //
52 // If no duration is set for a FramePair, then it is assumed to be 0.
53 // If the exception flag is not set for a FramePair, then lookups will not throw
54 // an exception.
56  public:
57  typedef std::pair<std::string, std::string> FramePair;
58 
60 
61  // Note we do not simulate anything related to the frame's time.
62  bool waitForTransform(const std::string& target_frame,
63  const std::string& source_frame, const ros::Time& time,
64  const ros::Duration& timeout) const;
65 
66  // Note we do not simulate anything related to the frame's time.
67  void lookupTransform(const std::string& target_frame,
68  const std::string& source_frame, const ros::Time& time,
69  tf::StampedTransform& transform) const;
70 
71  // Mock methods
72  // Sets the transform that should be returned when doing a lookup from the
73  // source to the target frame.
74  void SetTransform(const std::string& target, const std::string& source,
75  const tf::StampedTransform& transform);
76 
77  // Sets how long it should take to perform a lookup from the source to the
78  // target frame.
79  void SetLookupDuration(const std::string& target, const std::string& source,
80  const ros::Duration& duration);
81 
82  // Sets whether or not an exception should be thrown when doing a lookup from
83  // the source to the target frame.
84  void SetThrowException(const std::string& target, const std::string& source,
85  bool should_throw);
86 
87  private:
88  std::map<FramePair, tf::StampedTransform> transforms_;
89  std::map<FramePair, ros::Duration> durations_;
90  std::map<FramePair, bool> should_throw_exception_;
91 };
92 } // namespace rapid_ros
93 
94 #endif // _RAPID_ROS_TF_LISTENER_H_
void SetTransform(const std::string &target, const std::string &source, const tf::StampedTransform &transform)
std::pair< std::string, std::string > FramePair
Definition: tf_listener.h:57
void SetThrowException(const std::string &target, const std::string &source, bool should_throw)
bool waitForTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration &timeout) const
void lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, tf::StampedTransform &transform) const
virtual bool waitForTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration &timeout) const =0
virtual void lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, tf::StampedTransform &transform) const =0
void lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, tf::StampedTransform &transform) const
void SetLookupDuration(const std::string &target, const std::string &source, const ros::Duration &duration)
bool waitForTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration &timeout) const