waitForTransform Issues and errors
I am trying to have my code use the
self.listener.waitForTransform(from_frame, to_frame, rtn, rospy.Duration(0.5))
and TransformPoint
to transform points around my robot from map to base_scan frame, as the robot moves. In order to get this to work I have to use the same time stamp for each run so that every point around the robot at any given time gets the same exact transform information to use for the transform calculation.
So this is the psuedocode of how I tried to make this work.
def transform(self,coord,from_frame='map',to_frame='base_scan',rtn=None): if rtn is None: rtn=rospy.get_rostime() self.scope.header.frame_id = from_frame self.scope.header.stamp = rtn # rospy.TIme(0) self.scope.point.x = coord[0] self.scope.point.y = coord[1] self.scope.point.z = 0
try:
self.listener.waitForTransform(from_frame, to_frame, rtn, rospy.Duration(0.5))
p = self.listener.transformPoint(to_frame, self.scope)
return [p.point.x,p.point.y]
except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException):
raise
def use_transform():
points=gather all points around robot at any given time
rtn=rospy.get_rostime()
for point in points:
transform(point,rtn) from map to base scan
........
When I run this code I get this below:
File "/opt/ros/melodic/lib/python2.7/dist-packages/tf/listener.py", line 74, in waitForTransform
can_transform, error_msg = self._buffer.can_transform(strip_leading_slash(target_frame), strip_leading_slash(source_frame), time, timeout, return_debug_tuple=True)
File "/opt/ros/melodic/lib/python2.7/dist-packages/tf/listener.py", line 45, in strip_leading_slash
return s[1:] if s.startswith("/") else s
AttributeError: 'Time' object has no attribute 'startswith'
Is it because I'm using rospy.get_rostime()? Should I be using something else? I've tries rospy.Time(0), rospy.Time.now() and have the same issue. I have searched the listener.py
script the error talks about. I have no diea waht I should change in the script to fix this error.