Sphero RVR+ setup part 2
If you have not gone through the previous article Sphero RVR+ setup part 1, please do so before proceeding with this one. But if you did, then you should have the hardware up and running and you are good to go with the software setup.
Assuming you have installed the proper firmware and booted to Ubuntu 22.04 LTS. Congratulations! Now we are good to go to set up the necessary network settings and set up the ROS 2 Humble workspace to eventually create a Sphero RVR+ ROS 2 package driver.
Let’s get started.
Establish SSH
As we want to have the dev kit be the local end to control the robot, we will have a second computer to remotely communicate with the dev kit. A secure and efficient remote communication protocol between the server and client is SSH. To establish the protocol, please refer to this article: Streamlining Secure Remote Access: A Guide to Passwordless SSH Connections Between Linux Servers for the setup details. We will assume the dev kit as the server and the second computer as the client. We summarize the steps here:
Step 1: On Jetson Orin Nano (server and host)
- If you haven’t, generate an SSH key pair on the server with the command:
ssh-keygen -t rsa
to use the RSA encryption method to generate the key pair. As a host or server, we will keep the generated private key for ourselves and share the public key to the client. Once the command is inserted, the terminal will prompt the user to set the localtion for the key pair. Simply hit Enter to accept the default localtion for the key pair and leave the passphrase empty.
Confirm the key gneration by pressing Enter.
If you look under ~/.ssh/ you will see that the key pair has been generated:
ls ~/.ssh
# The terminal returns the following
id_rsa id_rsa.pub
Step 2: Copy the public key to the second computer (client)
You can use sh-copy-id to copy across the network like such
ssh-copy-id <user>@<second_computer_IP>
Replace the corresponding information to the command above.
Step 3: Test the passwrdless connection
First let’s test logging in the client from Jetson Orin Nano:
ssh <user_on_second_computer>@<second_computer_IP>
If you followed the previous two steps then you should have no problem reaching to this step, otherwise check if you have missed a step.
Next, do the same logging from the opposite side. Note that you should accept leaving the footprint on either machines on your first login.
Congratulations if you manage to do passwordless logins from both sides! We are in business.
Set up Zeroconf (Avahi on Linux)
Within the same local network, Zeroconf enables us to type the computer’s domain name instead of its IP address on every login. This step is optional but you may find the setting to save you a great deal of precious time and headache down the road. This article: Install Zeroconf / Bonjour already gives a well written setup instruction manual. But let’s summarize the steps for integrity sake.
Let’s install Avahi if you haven’t:
sudo apt install -y avahi-daemon avahi-autoipd
Now let’s test if Zeroconf has published the decentralized local domain name (mDNS) with the “local” top level domain. You can try with pingging the other machine in the network:
ping my_second_computer.local
# to which the terminal will respond
64 bytes from 192.168.1.42: icmp_seq=0 ttl=54 time=3.14 ms
[...]
Success! Now instead of typing the IP address every time, you can connect the target machine with the mDNS, such as logging in with SSH:
ssh <user>@my_second_computer.local
Replace the user and my_second_computer with your actual user and device name.
Install and test running Sphero SDK
You can follow the instruction to run a testing script. Make sure you git clone the sphero-sdk-raspberrypi-python repository and change directory to under it.
git clone https://github.com/sphero-inc/sphero-sdk-raspberrypi-python.git
# or if you have SSH public key added to your GitHub account:
git clone git@github.com:sphero-inc/sphero-sdk-raspberrypi-python.git
cd sphero-sdk-raspberrypi-pythton
Then run the script:
python getting_started/observer/leds/set_multiple_leds.py
And something should happens, most likely the LEDS would flash. Unfortunately the robot’s system only reminded me once to update the robot’s firmware and upon the next run it shows nothing. Well, no news is good news apparently.
A more direct way is to directly let the script control the motor. First, lift your robot off the ground with something so its wheels or tracks are dangling in the air. Then, fire up the scripts:
python getting_started/observer/driving/drive_raw_motors.py
and it will rotate the wheels in both directions. Congratulations! You just finished setting up the Sphero SDK!!
Install ROS2 Humble
If you want to develop and test on your laptop or destop, you should test with Linux Ubuntu 22.04 LTS and ROS 2 Humble. You can refer to this official guide: Ubuntu (deb packages)
sudo apt update
sudo apt upgrade
sudo apt install -y ros-humble-desktop
sudo apt install -y ros-dev-tools # Development tools: compilers and other tools to build ROS packages
Sourcing the environment setup
vim ~/.bashrc
# Go all the way down to the last line of the script and insert the following
source /opt/ros/humble/setup.bash
# Save and quit the script with the command: :wq and insert the command to take effect
source ~/.bashrc
Now you have the ROS 2 Humble suite installed. Let’s create the workspace
Create the ROS 2 Workspace
You can refer to the official guide: Creating a workspace. Let’s summarize the key steps.
Create a new directory for the workspace. Let’s use ros2_ws as the example.
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
The best practice is to put any package under the src/ directory. But don’t forget to compile the packages under ~/ros2_ws and not in src/.
Resolve the dependencies before building the new worksppace:
# Under ~/ros2_ws/
sudo rosdep init # for the first time
rosdep install -i --from-path src --rosdistro humble -y
rosdep update # for posterior updates and is optional
# If all dependencies are installed, you should receive the following from the terminal:
#All required rosdeps installed successfully
Build the workspace with colcon
Build the packages with the command:
# Under ~/ros2_ws
colcon build # to all packages
colcon build --packages-select <your_particular_package(s)> # build only the selected package(s)
# The console will return the following
Starting >>> turtlesim
Finished <<< turtlesim [5.49s]
Summary: 1 package finished [5.58s]
Similar to what we used to do in ROS 1, we should soure the local setup.bash in the system:
vim ~/.bashrc
# move to the last line and append this after it
source <your/path/to/ros2_ws>/install/local_setup.bash
Replace with your local_setup.bash path.
Creating a package and a node
Please refer to the official guide Creating a package for the actual steps. Note that both the C++ and Python packages have their corresponding setup appraoch. Comparing to ROS 1, the Python ROS2 packages need to be built after making the changes to take effect.
For creating nodes, please look up the corresponding official articles for details. The same for some frequently used commands.
Sphero RVR+ ROS 2 package
From here on out I assume that you have the appropriate knowledge to work with ROS 2 Humble. I have created and developped a ROS2 package based on the available Sphero SDK to run the robot driver, and want to give a big shout-out to Linorobot on providing the actual code implementation. My project is based on the linorobot/sphero_rvr repository which in terms is inspired by the sphero-sdk-raspberrypi-python repository’s drive_rc_si_units.py example code.
I will have a dedicated post for this ROS 2 package so stay tuned. Here is it: sphero_rvr_ros2.