The Best Way for Beginners to Learn from Tutorials!
This post is about how beginners can make the most out of every tutorial by digging deep into the code to understand it. This is the best foundation you can give yourself for continuing to work on the code and making your own modifications. It follows on from Getting Started as a Robotics Software Engineer!, where I give the advice:
First, look for and use every resource you have available to you. Look online, ask people, work in the field; anything you can to make your journey easier.
Following on from that, I wanted to show how to take a tutorial and use various resources to understand what's happening in the provided code. I'll take the tutorial from ROS about writing a simple publisher/subscriber, and I'll use C++ to build it, as this is less well-known than Python and so a better way to demonstrate self-learning.
If you'd prefer to follow along, I've built a video demonstrating everything in this article, available here:
To understand the tutorial code, we'll be using the following resources:
- Version control (git) - to check the differences between versions and understand what's changed
- Explaining the code - try to explain as much of the code as you can, either in comments or out loud to someone or something else.
- Setting up your IDE - using your editor to help you move around the code and look up parts of it will help you find out what's going on.
- Using online resources - tutorials, blogs, videos, and a number of other resources can help explain parts that you don't understand up to this point.
- Debugging - using a debugger to attach to running code and stop it to interrogate variables and step through each line.
- Testing - using unit tests to check your understanding or set up simple test cases to focus on a particular area of code.
Using Source Control to your advantage
This isn't strictly speaking about understanding your code - what it does do is help you get back to a known state, and see what's changed since then. Let's follow the tutorial until there's a blank project checked out, then commit our progress using Git.
Installing Git
First, we need to install Git and do some configuration. Follow the install instructions, then set up your username and e-mail address:
# Replace with your username and email!
git config --global user.name "Mike Likes Robots"
git config --global user.email "mikelikesrobots@outlook.com"
Committing the template project
Follow the tutorial up until Create a package, then execute the pkg create command:
ros2 pkg create --build-type ament_cmake --license Apache-2.0 cpp_pubsub
Once this is done, let's stop and commit our progress:
cd cpp_pubsub
# This initializes a git repository
git init
git add --all
git commit -m "Initial commit"
