Hadabot is a low-cost robot kit for students, software engineers, makers to learn ROS2 and robotics in a hands-on manner. Our robot kits are easy to build, extensible, and customizable. The Hadabot software stack consists of an open source web browser-based coding environment to make the hacking experience frustration-free.
In a previous post, we showcased the ROS 2 turtlesim running with the Navigation2 (aka Nav2) package. That exercise required the use of the tf2 which manages all the various coordinate frames of a robotics application.
In this post, instead of turtlesim, we'll have Nav2 direct a physical Hadabot Turtle differential drive robot to a goal pose - position and orientation. This exercise will bring together rviz, tf2, Nav2 with our past writeups about the Turtle robot's odometry and kinematics. We'll touch upon:
How we compute odometry for Nav2
The Nav2 parameters we tweaked
1. ROS 2 Nav2 with a Hadabot Turtle robot
As with all Hadabot examples, you can use the Hadabot stacks browser-based VSCode to compile and run the code.
Follow these steps:
Set up / update your turn-key Hadabot software stack (which leverages Docker containers to ensure your code runs securely and efficiently on your local machine):
If you are new to Hadabot, follow these steps to set up Docker and get the Hadabot software stack up and running (5 to 15 minutes).
Else if you are a returning Hadabot hacker, follow these steps to update your Hadabot software stack (1-3 minutes).
Launch the browser-based VSCode workspace specific to this post (this link points to your localhost so everything is running securely on your local system).
In the left VSCode Explorer panel, right-click the README.md file -> Open Preview.
Follow the instructions in the README to:
Update your ROS 2 packages
Flash the example's ESP32 firmware
Compile the Navigation2 Hadabot Turtle robot controller and coordinate frame code.
Launch a browser-based VNC client to run the example.
Run a go-to-goal Navigation2 Hadabot Turtle example.
Rviz to visualize the Nav2 go-to-goal Hadabot Turtle example
If you successfully ran the example, you'll notice that the Turtle starts in the middle of the "arena" (ie map). Each grid-box represents 1 meter in physical distance. The red-axis presents the Turtle pointed forward. Since ROS uses a right-handed coordinate system, positive \(\omega\) rotation results in the Turtle turning counter-clockwise.
For the video example, the goal pose was 1 meter to the Turtle's left, with a 90 degree orientation from its initial orientation.
Notice the Turtle didn't end up exactly 1 meter to its left, nor was it oriented exactly 90 degrees from its initial pose. This is due to 2 reasons due to nothing happening exactly in the real world (this is not a simulation anymore Dorothy) - (1) the Hadabot Turtle's speed sensors have errors which accumulates over time resulting in odometry drift, and (2) Nav2 goal checker allows for a tolerance in both distance and orientation from the specificed end-goal.
2. How we construct TF2 messages from odometry
The Hadabot Turtle publishes each wheel's rotational velocity in radians per second. With the measured wheelbase and wheel radius of the Turtle, we apply dead-reckoning to determine how far each wheel has traveled in meters.
Once we know how far each wheel has traveled for our differential drive model, we can compute the linear distance and angular rotation \((v, \omega)\) for a unicycle model, which allows us to update the current pose and velocities of our Hadabot Turtle as an Odometry ROS message. All this is done in the hadabot_controller.cpp file.
Then we use effectively the same code as the turtlesim example to extract the pose information from the Odometry message and publish that out as tf2 messages which is used by Nav2 and rviz.
3. Setting up Nav2 for the Hadabot Turtle
Nav2 is a complex ROS 2 package with a number of sub-packages / components around 3 main capabilities - localization, planning/controller, and mapping. For our go-to-goal example, we mainly use the planning/controller component.
There are conceptually 2 types of planners in Nav2 - a global planner, and a local planner. The global planner computes a global trajectoy to get to our goal pose. The local planner references the global plan to determine the best linear and angular velocity for the robot to undertake to safely move along the global trajectory.
The global planner (as of 2020-12) defaults to a variation of a A* search based planner. The local planner is called the DWB planner, initially created by David Lu back in the ROS 1 days, which implements the Dynamic Window Approach (DWA) algorithm created by Dieter Fox, Wolfram Burgard, and Sebastian Thrun. The DWB planner is driven by "critics" which vote on various local trajectories to undertake. Each critic "cares" about a certain behavior (ie avoiding abstacles, avoiding oscillation, going fast, etc). The local trajectory with the highest vote wins and that results as the Twist message command to direct the robot's current velocities.
Configuring Nav2 for our go-to-goal example involved tuning the parameters for the planning/controller. The ones we tweaked for the Hadabot Turtle are the max velocities of our robot, and controller update frequency (to update frequently enough but not so much that it floods our "hobbyist" network capabilities). There are many other Nav2 parameters we can consider and tune, which can be a series of posts and exercises on its own.
In this post, we did the following:
Showed a example of running a physical real-life Hadabot Turtle robot using ROS 2 Nav2.
We described how we use dead-reckoning to compute the Turtle's pose and velocities.
We talked a bit about Nav2 and what we tweaked to get our goal-to-goal example to work.
In future posts, we can take this exercise down 2 separate threads - (1) to walk through some of the Nav2 parameters in more detail, start looking closer at Nav2, or (2) to showcase a Hadabot Turtle with a skirt of range-sensors (add-on for the base Turtle kit) to further explore localization and then SLAM with Nav2.
Additionally, we are working with various professors to create a more structured ROS 2 robotics syllabus and curriculum.
Please sign up to stay in touch for more info (as well as any promo offers we will run in the near future)!
Thanks again for following along. If you enjoyed the post, there are 2 ways to continue to learn with Hadabot:
Sign up to stay in touch (via the Stay in Touch buttons above and below) with future post updates, as well as promos and giveaway opps.
Purchase a Hadabot Turtle kit to start your robotics adventures!
Thanks and happy building!
Jack "the Hadabot Maker"