Create ROS package for Telemetry
The goal of this workshop is to learn enough about creating ROS2 software to create a package that publishes telemetry data which can subsequently be analyzed using CLI tools.
Content outline
Do ROS2 Client Library tutorials related to publishing telemetry:
Colcon build package, create package
Writing a simple publisher and subscriber (C++ or python)
Creating custom msg file, Implementing custom interfaces
Modify a telemetry-output package
Create custom message
Create launch file to run it all
Console output
Build and run package & record bag for analysis
Discuss frames, REP-103, REP-105, tf2, quaternions https://eater.net/quaternions/video/intro
Video of workshop 4
Video of the first half of workshop 4 is here
Package-related cheat sheet
ros2 pkg create --build-type ament_python --license Apache-2.0 --node-name <my_node> <my_package> # create a python package
colcon build --symlink-install --packages-select <my_package> # build a single package, installing symlinks
ROS2 Concepts
Packages
Packages are SW modules - some collection of SW which may hold multiple binaries, or libraries, or message definitions, etc
Packages are suggested to be either C++ or Python. (It's possible to put both in a package but life gets more complicated - as a beginner, don't do dat.)
Packages are built under colcon, and C++ has different build specifications than python
Packages contain a manifest file - package.xml, which declares dependencies on other packages. If you don't fill it out properly, things may fail
C++ package builds are controlled by CMakeLists.txt and built with CMake. Python package builds are controlled in a Pythonic way. Do the Creating a package tutorial for details.
The Writing a simple publisher and subscriber tutorial goes into more details of what needs to be in the build control files.
You really want to get the build-control file right, or bad things happen, like executables not getting transferred to the install directory, dependencies not detected, or not found at runtime, etc.
packages can be nested under whatever directory hierarchy you want. See for example the ros2/examples repo. colcon will discover them. e.g. multiple packages for a robot can be saved in a directory hierarchy for that robot.
Nodes
Every executable in a ROS graph is a node. Systems are composed of nodes which communicate with one another. Nodes should be as simple and general as possible, so that they can be composed flexibly. It's OK to have quite a few nodes. The design pattern of simple SW modules which do one thing well and can be composed flexibly echos that of Unix, wherein simple programs like ls, wc, cat, grep, sed can be flexibly connected with pipes where stdout from one programs feeds stdin of the next, to do quite complex processing.
ROS2 user-nodes are subclasses of the Node class, and inherit the Node classes operations and attributes. (Contrast with ROS1 where nodes used static methods of e.g. rospy.)
Frames
Discuss frames, REP-103, REP-105, tf2, quaternions https://eater.net/quaternions/video/intro
API Docs
The rclpy API for foxy release can be found here: https://docs.ros2.org/foxy/api/rclpy/api/node.html
The github repo for rclpy and instructions for generating python API documentation is here: https://github.com/ros2/rclpy
Links to the rclcpp API are here: https://docs.ros.org/en/humble/p/rclcpp/generated/index.html
Mike Fergusson's ROS2 cookbook repo: https://github.com/mikeferguson/ros2_cookbook
OO Concepts
Check on understanding of class vs. instance, inheritance, constructor, calling superclass constructor
Hands On
In this segment we do several of the ROS2 beginner-level client library tutorials found here: https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries.html
Beginner Client Libraries Tutorials
Do the Using colcon to build packages tutorial - 20 min. Note the cautious wording around --symlink-install, and helpful --packages-select
Do the Creating a package tutorial - 15 min
Clean the workspace and rebuild. Use the rosclean alias.
Do the Writing a simple publisher and subscriber (Python or C++ version, your choice) - 20 min
Do the creating custom msg and srv files. Skip the srv parts of the tutorial - 20 min
Putting it all together:
We build a custom package, run a robot in simulation, record and analyze a bag, and fix a fault
Clone the following repo into ros2_ws/src:
git clone git@github.com:PaulBouchier/turtle_telemetry.git
cd to ~/ros2_ws and build the workspace: colcon build
source the workspace build/setup.bash: source ~/ros2_ws/install/setup.bash
launch a terminator window and split into 5 ros windows
In one window run ros2 run swri_console swri_console
In another window, run the turtelbot simulator: ros2 run turtlesim turtlesim_node
In another window, run the keyboard teleop node: ros2 run turtle_telemetry turtle_telemetry_node
In another window, run the turtle_telemetry node: ros2 run turtlesim turtle_teleop_key
In another window, cd to bag_files and run ros2 bag record -a
In another window, drive the turtle around with the keyboard
Stop the bag recording with Ctrl-C
In the bag_files window, run plotjugger and inspect the data. ros2 run plotjuggler plotjuggler
Open the bagfile yaml file and select topics cmd_vel, /turtle1/pose, turtle_debug
Plot X-Y for robot path from the Pose message.
Plot linear and angular velocity from Odomeitry. Plot linear and angular from the cmd_vel Twist message.
Why is the linear velocity zero in the debug message?
In another window, cd to bag_files and run: rqt_bag
In rqt_bag place the cursor at a point of interest and zoom in.
Display raw data from turtle_debug and twist and step through messages
Inspect the source of turtle_telemetry_node and find and fix the fault causing linear velocity to be zero
Look at CMakeLists.txt
Intermediate Tutorials - Launchfiles and Logging
Do the Creating a launch file tutorial - 10 min
Do the Integrating launch files into packages tutorial - 10 min
Review the demos->logging page & discuss logging options