{{{#!wiki tip Using ROS 2? Check out the [[https://docs.ros.org/en/rolling/Tutorials/Intermediate/Tf2/Tf2-Main.html|ROS 2 tf2 tutorials]]. }}} #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note =This tutorial assumes you have a working knowledge of compiling programs in ROS. Check out the [[ROS/Tutorials| ROS tutorials]] to learn how to do this ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0= ## descriptive title for the tutorial ## title =Introduction to tf2 ## multi-line description to be displayed in search ## description = This tutorial will give you a good idea of what tf2 can do for you. It shows off some of the tf2 power in a multi-robot example using [[turtlesim]]. This also introduces using [[tf2#tf2_echo|tf2_echo]], [[tf2#view_frames|view_frames]], and [[rviz]]. ## the next tutorial description (optional) ## next = Writing a tf2 broadcaster ## links to next tutorial (optional) ## next.0.link=[[tf2/Tutorials/Writing a tf2 broadcaster (Python)|(Python)]] ## next.1.link=[[tf2/Tutorials/Writing a tf2 broadcaster (C++)|(C++)]] ## what level user is this tutorial for ## level= BeginnerCategory ## keywords = transforms, coordinate frames #################################### <> <> == Installing the Demo == Let's start by getting any dependencies and compiling the demo package. {{{ $ sudo apt-get install ros-${ROS_DISTRO}-turtle-tf2 ros-${ROS_DISTRO}-tf2-tools ros-${ROS_DISTRO}-tf }}} == Running the Demo == Now that we're done compiling the turtle_tf2 tutorial package let's run the demo. {{{ $ roslaunch turtle_tf2 turtle_tf2_demo.launch }}} You will see the turtlesim start with two turtles. . {{attachment:turtle_tf_start.png}} Once the turtlesim is started you can drive the center turtle around in the turtlesim using the keyboard arrow keys, '''select the roslaunch terminal window''' so that your keystrokes will be captured to drive the turtle. . {{attachment:turtle_tf_drive.png}} As you can see that one turtle will continuously move to follow the turtle you are driving around. == What is Happening == This demo is using the tf2 library to create three coordinate frames: a world frame, a turtle1 frame, and a turtle2 frame. This tutorial uses a '''tf2 broadcaster''' to publish the turtle coordinate frames and a '''tf2 listener''' to compute the difference in the turtle frames and move one turtle to follow the other. == tf2 Tools == Now let's look at how tf2 is being used to create this demo. We can use tf2 tools to look at what tf2 is doing behind the scenes. === Using view_frames === `view_frames` creates a diagram of the frames being broadcast by tf2 over ROS. {{{ $ rosrun tf2_tools view_frames.py }}} You will see: . {{{ Listening to tf data during 5 seconds... Generating graph in frames.pdf file... }}} Here a tf2 listener is listening to the frames that are being broadcast over ROS and drawing a tree of how the frames are connected. To view the tree: {{{ $ evince frames.pdf }}} . {{attachment:view_frames_2.png||width="605px"}} Here we can see the three frames that are broadcast by tf2 the world, turtle1, and turtle2 and that world is the parent of the turtle1 and turtle2 frames. `view_frames` also report some diagnostic information about when the oldest and most recent frame transforms were received and how fast the tf2 frame is published to tf2 for debugging purposes. === Using tf_echo === `tf_echo` reports the transform between any two frames broadcast over ROS. Usage: {{{ rosrun tf tf_echo [reference_frame] [target_frame] }}} Let's look at the transform of the turtle2 frame with respect to turtle1 frame which is equivalent to <> : {{{ $ rosrun tf tf_echo turtle1 turtle2 }}} You will see the transform displayed as the `tf_echo` listener receives the frames broadcast over ROS. . {{{ [ INFO] 1253585683.529245000: Started node [/tf2_echo_1253585683508144000], pid [24418], bound on [aqy], xmlrpc port [41125], tcpros port [57369], logging to [~/ros/ros/log/tf2_echo_1253585683508144000_24418.log], using [real] time Exception thrown:Frame id /turtle1 does not exist! When trying to transform between /turtle2 and /turtle1. The current list of frames is: Success at 1253585684.557003974 [0.000000 0.000000 0.140754 0.990045] Euler(0.282446 -0.000000 0.000000) Translation: [-0.000036 -0.000010 0.000000] Success at 1253585685.544698953 [0.000000 0.000000 0.140754 0.990045] Euler(0.282446 -0.000000 0.000000) Translation: [-0.000036 -0.000010 0.000000] Success at 1253585686.557049989 [0.000000 0.000000 0.140754 0.990045] Euler(0.282446 -0.000000 0.000000) Translation: [-0.000036 -0.000010 0.000000] Success at 1253585687.552628993 [0.000000 0.000000 0.140754 0.990045] Euler(0.282446 -0.000000 0.000000) Translation: [-0.000036 -0.000010 0.000000] Success at 1253585688.553683042 [0.000000 0.000000 0.140754 0.990045] Euler(0.282446 -0.000000 0.000000) Translation: [-0.000036 -0.000010 0.000000] Success at 1253585688.910640001 [0.000000 0.000000 0.140754 0.990045] Euler(0.282446 -0.000000 0.000000) Translation: [-0.000036 -0.000010 0.000000] }}} As you drive your turtle around you will see the transform change as the two turtles move relative to each other. == rviz and tf2 == [[rviz]] is a visualization tool that is useful for examining tf2 frames. Let's look at our turtle frames using `rviz`. Let's start `rviz` with the turtle_tf2 configuration file using the `-d` option for `rviz`: {{{ $ rosrun rviz rviz -d `rospack find turtle_tf2`/rviz/turtle_rviz.rviz }}} [[attachment:turtle_tf_rviz.png|{{attachment:turtle_tf_rviz.png|attachment:turtle_tf_rviz.png|width="100%"}}]] In the side bar you will see the frames broadcast by tf2. As you drive the turtle around you will see the frames move in rviz. Now that we have examined the turtle_tf2_demo, let's look at how to write the broadcaster [[tf2/Tutorials/Writing a tf2 broadcaster (Python)|(Python)]] [[tf2/Tutorials/Writing a tf2 broadcaster (C++)|(C++)]] for this demo. ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## TutorialTurtlesim ## IntroductionCategory