35 from geometry_msgs.msg
import PoseStamped
40 rospy.init_node(
'tf_listener', anonymous=
True)
45 pose_stamped = PoseStamped()
46 pose_stamped.header.stamp = rospy.Time.now() - rospy.Duration(0.1)
47 pose_stamped.header.frame_id = source_frame
48 pose_stamped.pose.position.x = position[0]
49 pose_stamped.pose.position.y = position[1]
50 pose_stamped.pose.position.z = position[2]
51 pose_stamped.pose.orientation.x = orientation[0]
52 pose_stamped.pose.orientation.y = orientation[1]
53 pose_stamped.pose.orientation.z = orientation[2]
54 pose_stamped.pose.orientation.w = orientation[3]
56 self._listener.waitForTransform(target_frame, source_frame, rospy.Time(0), rospy.Duration(4))
58 trans_result = self._listener.transformPose(target_frame, pose_stamped)
60 return ([trans_result.pose.position.x,
61 trans_result.pose.position.y,
62 trans_result.pose.position.z],
63 [trans_result.pose.orientation.x,
64 trans_result.pose.orientation.y,
65 trans_result.pose.orientation.z,
66 trans_result.pose.orientation.w])
70 while time.time() - t < timeout:
72 now = rospy.Time.now()
73 self._listener.waitForTransform(target_frame, source_frame, now, rospy.Duration(0.01))
74 trans_result = self._listener.lookupTransform(target_frame, source_frame, now)
76 except tf.Exception
as e:
82 names = self._listener.getFrameStrings()
86 return fnmatch.filter(names, pattern)
110 if __name__ ==
'__main__':
111 rospy.init_node(
'tf_test', anonymous=
True)
112 rospy.loginfo(
'node started')
116 while not rospy.is_shutdown():
117 ret = util.get_current_pose(
'camera_color_optical_frame',
'object_22_0', timeout=0.1)
def __init__(self, init_node=False)
def transform_pose(self, target_frame, source_frame, position, orientation)
def get_frame_names(self, pattern=None)
def get_current_pose(self, target_frame, source_frame, timeout=4.0)