ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

waitForTransform Issues and errors

asked 2022-04-04 14:10:06 -0500

distro gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-04-04 14:26:53 -0500

tfoote gravatar image

It's not related to how you constructed your time object. From the error it looks like you're passing a Time object where it's expecting a string frame_id. As it's trying to strip a potentially leading slash from the frame_id. You should make sure to check your arguments that you're inputting to the functions.

There's presumably truncated backtrace information above the section that you've quoted which will show you your problem.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-04-04 14:10:06 -0500

Seen: 192 times

Last updated: Apr 04 '22