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

why the turtle2 follow turtle1 in tf2 tutorials?

asked 2021-10-21 14:22:20 -0600

Shivam gravatar image

updated 2021-10-21 14:22:45 -0600

I am following the Python tutorials of tf2 - http://wiki.ros.org/tf2/Tutorials. I have completed it till writing a tf2.listener step. I am confused as to why after this step turtle2 follow the turtle1. All I understood is that the previous broadcaster broadcasts the pose of turtle1 w.r.t to the world frame. And the listener listens to that pose or transform and does frame transformation from turtle2 to turtle1. Why frame transform between frame1 and frame2 makes one turtle follow the other one?

Isn't it true that transform is just a relationship between coordinate frames of both the turtles. We then generally use this information to transform a point in frame1 to frame 2. But I am a little confused about what's happening in that tutorial. Any help is appreciated.

I am using ROS Noetic in Ubuntu 20.04. I wanted to use tf2 to transform vector and point of an object from camera frame to the robot frame in my project.

edit retag flag offensive close merge delete

Comments

Does this code ''trans = tfBuffer.lookup_transform(turtle_name, 'turtle1', rospy.Time())'' gives pose of turtle1 w.r.t turtle_name i.e.turtle2?

Shivam gravatar image Shivam  ( 2021-10-21 16:13:19 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-10-21 16:15:30 -0600

osilva gravatar image

The tf2 broadcaster is publishing the coordinate frames of the lead turtle. A tf2 listener calculates the difference between the coordinate frames of the lead turtle and the follower turtle. It then moves the follower turtle so that it follows the lead turtle.

  30         msg = geometry_msgs.msg.Twist()
  31 
  32         msg.angular.z = 4 * math.atan2(trans.transform.translation.y, trans.transform.translation.x)
  33         msg.linear.x = 0.5 * math.sqrt(trans.transform.translation.x ** 2 + trans.transform.translation.y ** 2)

Where transis tf from turtle1. There is a good tutorial that explains this in more detail: https://automaticaddison.com/working-...

edit flag offensive delete link more

Comments

Thank you for answering Osilva. Can you tell which line of code calculates the difference between the coordinates frame? Is it this one- ''trans = tfBuffer.lookup_transform(turtle_name, 'turtle1', rospy.Time())'' And does this line of code gives pose of turtle1 w.r.t turtle_name i.e.turtle2?

Shivam gravatar image Shivam  ( 2021-10-21 16:28:38 -0600 )edit
1

That line gets the transform from turtle1, the difference is calculated with lines 30-33.

osilva gravatar image osilva  ( 2021-10-21 16:44:42 -0600 )edit

The line which I mentioned, does that line of code gives pose of turtle1 w.r.t turtle_name i.e.turtle2? I don't want to leave any confusion that's why asking again. Thank you again. I find the terminology of transform from and to confusing. The tutorials use this terminology.

Shivam gravatar image Shivam  ( 2021-10-21 16:50:42 -0600 )edit
1

Inherits tf2_ros::BufferInterface and tf2::BufferCore. Stores known frames and offers a ROS service, "tf_frames", which responds to client requests with a response containing a tf2_msgs::FrameGraph representing the relationship of known frames

Check this video: https://ocw.tudelft.nl/course-lecture...

osilva gravatar image osilva  ( 2021-10-21 18:32:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2021-10-21 14:22:20 -0600

Seen: 127 times

Last updated: Oct 21 '21