The almighty TF package (Tue Oct 8, lecture 11) previous next
TF is the heart of the efficient conversion of coordinates between frames

Homework due for today

Legend: : Participation (pass/fail) | : PDF | : Team | : Attachment

  1. Read and actually code up the examples in the TF2 Tutorials Sequence. There’s not a lot of code to write, but I would like you to actually run all the examples and try to understand what is going on. With that, answer the following questions about TF2:
    1. What is the TF tree? Where is it stored? (that may be a trick question!)
    2. In your own words, how does turtle_tf2_demo work?
    3. Please write one or two things that are still confusing to you; if it’s all clear, then please write one or two major takeaways. Deliverable: Your responses to the above questions, in brief, in a pdf with your name and homework number at the top.

Review

  • An x,y,z is always within a specific coordinate system
  • For example, is it relative to the bottom left corner of the room, or the center of the robot?
  • It is far easier to reason in an appropriate coordinate system
  • As long as there are easy ways to convert back and forth.
  • Pose = position and orientation
  • Pose is always with respect of a specific coordinate frame or TF
  • Usually a coordinate begins as the “natural” way to think about It
    • Angle of obstacle, with respect to the LIDAR
    • Position a corner, with respect to the whole room
    • Angle to turn, from the point of view of the robot itself
    • So when you see phrases like “with respect to”, and “from the point of view of” you know these refer to coordinate frames.
  • It is very common to want to see that same point or angle from another’s point of view
    • How bit a turn to I need to point directly away from the wall?
    • What direction is the nearest door from me?
  • Compare starboard/port and driver vs. passenger side

TF

  • TF package in ROS is central
  • It recently was rewritten and shows up as TF2 in many places
  • It is interesting and important to understand in some more detail
TF framework in ROS
  • An API to make conversions of coordinates between systems easy and efficient
  • Coordinate systems are given names, e.g. “world” or “lidar-1”
  • They are organized into a tree
  • Every named tf has just one parent, and unlimited number of children
  • TF broadcasts
    • Any node can report on the relationship between two coordinate system
    • Generally this is a node who knows something about one or the other.
    • For example, the node that moved the arm, can report the new relative position
    • That is, to get from tf “a” to tf “b”, add add 10 to the x or rotate 180 degrees around z.
  • TF Listeners
    • If my node needs to interpret coordinates I might listen to tf messages
    • Allowing to convert coordinates between any two coordinate frames.
Lets look at some code
$ sudo apt-get install ros-melodic-turtle-tf2 ros-melodic-tf2-tools ros-melodic-tf
$ roslaunch turtle_tf2 turtle_tf2_demo.launch
  • Notice that as you use the cursor keys to teleop the orange turtle around, the grey one follows right on it’s heels!
High Level explanation
  • Code is using tf2 to create three coordinate frames: one for the “world”, and one each for the two turtles
  • Realize that if we give turtle1’s coordinates as x,y, we’d still need to say, in what coordinate frame those were.
  • In t1’s coordinate frame, t1’s coordinates are always 0,0!
  • Lets take a look!
$ rosrun tf2_tools view_frames.py
$ evince frames.pdf
  • See the three coordinate frames and their hierarchical relationship
  • The diagram doesn’t display the actual transform just the relationships
  • To see those we need to echo the transform:
$ rosrun tf tf_echo turtle1 turtle2
$ rosrun tf tf_echo turtle1 world
Discussion: You can see the transform needed to get from turtle1 to turtle2 is different from the one betweek turtle1 and world. Why is that?
Visualization
$ rosrun rviz rviz -d `rospack find turtle_tf2`/rviz/turtle_rviz.rviz
Discussion: You now visualize all three tfs. Why do two move and one stay still?
Lets see how all this works: tf2_broadcaster
  • Examine the code in prrexamples: tf2_demo.launch and turtle_tf2_broadcaster.py
$ roslaunch learning_tf2 start_demo.launch
$ rosrun tf tf_echo /world /turtle1
  • Only one turtle so far!
  • Notice that it is publishing turtle1’s tfs relative to world
  • Drive around and notice that it is updating turtle1’s pose and also a transform
Lets see how all this works: tf2_listener
  • Examine the code in prrexamples: tf2_demo.launch and turtle_tf2_listener.py

$ roslaunch learning_tf2 start_demo.launch $ rosrun tf tf_echo /world /turtle1 $ rosrun tf tf_echo /world /turtle2 ~~~~~~

tf2 frames are organized in a tree
$ rosrun tf2_tools view_frames.py
$ evince frames.pdf
  • No cycles, one root
  • This ensures that there’s only one path from one frame to another
  • Which ensure that we can compute the transform by following that path
  • New frame would be added as a child of an existing frame
  • How to decide what the parent frame should be?
  • Its the one that has the most obvious and simple transform
Adding a frame

Next Class