UP | HOME

ROS Tf Activity

Introduction

  • This activity is designed to help provide experience with the ROS 2 tf trees and it's associated tf2_ros API.
  • It is meant to compliment the ROS 2 tf2 Tutorials

Demonstration

The following demonstration is based on code in https://github.com/m-elwin/me495_tf

# create the workspace and clone the repository and get set up.
# Substitute your own workspace directory for ws
mkdir -p ws/src
cd ws/src
git clone https://github.com/m-elwin/me495_tf.git -b ros2
cd ..
colcon build --symlink-install
source install/setup.bash

# run the broadcaster, in the background (the &)
ros2 run me495_tf in_out &

# list the topics, notice the /tf and /tf_static
ros2 topic list

# use tf2_tools to generate a pdf view of the frames
ros2 run tf2_tools view_frames

# Also can use rqt_tf_tree.
# Need to install the rqt_tf_tree package if it is not installed
sudo apt install ros-kilted-rqt-tf-tree

# Due to what appears to be a bug, need to first discover the plugin
# (Just once it seems, maybe once per rebooot?)
rqt --list-plugins --force-discover

# Actually run the rqt_tf_tree to view the tree
ros2 run rqt_tf_tree rqt_tf_tree

# use tf_echo to see translation between frames. C-c to quit
ros2 run tf2_ros tf2_echo right left

# run in rviz, using the rviz config provided by the package
rviz2 -d src/me495_tf/config/view.rviz

# run the tracker node
ros2 run me495_tf tracker

Exercises

  1. Walk through the demonstration above to gain familiarity with the tf tools.
  2. Instead of loading the provided config, run rviz2 without any arguments and duplicate the setup
    • Set the fixed frame to the world frame
    • Add a tf tree to the view
    • Change the fixed frame. What happens?
  3. Modify in_out so that the transform from world to base is dynamic
    • The transform now needs to be broadcast from the timer even though it is not changing.
    • Make sure that the frame is still visible in rviz2
  4. Make the base frame rotate about it's own z axis at a fixed rate, and visualize in rviz2
  5. Add another frame called up that is a child of world. Have this frame move in sync with left and right but perpendicular to them
  6. Modify tracker so that when the distance between up and left is above a threshold, it prints a message
  7. Add another frame called turn that is a child of base. Have this frame move with half the speed of left, and right but along the base frame's -x axis

Resources

Author: Matthew Elwin.