Help with tf2_ros
I need to use tf2_ros because tf doesnt work in python 3. I want to do what I did with tf below,but with tf2_ros. I just want to transform points from one frame to another. DOes anyone know a simple script to use to make this happen?
def transform(self,coord,from_frame='map',to_frame='base_scan',rtn=None):
if rtn is None:
rtn = rospy.Time(0)
self.scope.header.frame_id = from_frame
self.scope.header.stamp = rtn #rospy.get_rostime() # 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(1))
p = self.listener.transformPoint(to_frame, self.scope)
return [p.point.x,p.point.y]
except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException):
self.listener.waitForTransform(from_frame, to_frame, rospy.Time(0), rospy.Duration(1))
p = self.listener.transformPoint(to_frame, self.scope)
return [p.point.x, p.point.y]
raise
The tf2 wiki page has a simple example. Are you trying to accomplish something different?
@Akhil Kurup No this doesnt answer my question, I'm looking to transform anypount anywhere on the map, not neccesarily where my robot is located.
I don't understand your question. In the above example, you can lookup transform from and to any frame (not just the robot location).
trans = tfBuffer.lookup_transform(frame1, frame2, rospy.Time())
You can access the specific transforms using
trans.transform.(translation/rotation)
and use numpy to apply these transforms.numpy.dot(transform matrix, target pose)
@Akhil Kurup I was able to get tf2_ros to do what I want now, but only in python2.7, when I try to import tf2_ros in python3 environment I get:
It does work with Python3.
@Ravi Joshi well I just realized my tf and tf2_ros arent working in python3.
Please check your ROS installation.