ROS Tf Activity
Introduction
- This activity is designed to help provide experience with the ROS 2 tf trees and it's associated
tf2_rosAPI. - 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
- Walk through the demonstration above to gain familiarity with the tf tools.
- If you get stuck refer to the ROS 2 tf2 Tutorials
- Instead of loading the provided config, run
rviz2without any arguments and duplicate the setup- Set the fixed frame to the
worldframe - Add a
tftree to the view - Change the fixed frame. What happens?
- Set the fixed frame to the
- Modify
in_outso that the transform fromworldtobaseis 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
- Make the
baseframe rotate about it's ownzaxis at a fixed rate, and visualize inrviz2 - Add another frame called
upthat is a child ofworld. Have this frame move in sync withleftandrightbut perpendicular to them - Modify tracker so that when the distance between
upandleftis above a threshold, it prints a message - Add another frame called
turnthat is a child ofbase. Have this frame move with half the speed ofleft, andrightbut along thebaseframe's-xaxis