Sawppy Rover #5 – Software: Jetson Nano, ROS and Arduino

After assembly the rover stands on its six wheels, but it doesn’t move a millimetre yet. This post covers the software foundation: the operating system and ROS on the Jetson Nano, the drive controller and the Arduino firmware. At the end the rover can be driven by remote control from the screen. Camera, map and autonomous driving follow in the next two posts.

I didn’t start from scratch. Rhys Mainwaring wrote the ROS package Curio for the Sawppy, including Arduino firmware, a simulation and a clever trick for wheel odometry. His documentation on GitHub is very good, so I link to it in many places and focus here on what is different on the Jetson Nano and where I got stuck.

My adapted version with all changes from this series will be available on GitHub: [link follows].

Overview

The Sawppy’s drive and steering motors are ten LX-16A bus servos: six turn the wheels, four steer the corners. All of them hang on one shared serial bus. The work is split like this:

  • Arduino Mega 2560: talks to the servos via the BusLinker board, reads their positions 30 times per second and sends them to the Jetson via rosserial over USB. Drive commands come back the same way. Rhys chose this split because the BusLinker board’s own USB link was too slow.
  • Jetson Nano: runs ROS Melodic with Curio’s base controller. It turns a drive command (speed and turn rate) into steering angles and wheel speeds and computes the odometry from the servo positions, i.e. how far the rover has travelled.
  • Later the camera (post #6) and map and navigation (post #7) are added.

Rhys uses a Raspberry Pi 4. As announced in post #1, I use the Jetson Nano 4 GB. The software is the same, but installation differs in a few points.

Step 1: Jetson Nano with JetPack

The Jetson Nano runs NVIDIA’s JetPack 4, based on Ubuntu 18.04. There are no newer JetPack versions for the Nano. Mine runs JetPack 4.4.1; the current one for the Nano is 4.6.x. The SD card image and instructions are on NVIDIA’s “Getting Started with Jetson Nano Developer Kit” page.

Tips:

  • A fast SD card with at least 64 GB. ROS, the workspace and maps need space.
  • Network: Wi-Fi is enough indoors. I have an Intel AC 8265 card in the Nano. Turn off Wi-Fi power saving, it causes delays of several hundred milliseconds: sudo nmcli connection modify <wifi-name> 802-11-wireless.powersave 2
  • A fixed IP address from your router makes life easier.

Step 2: Install ROS Melodic

Ubuntu 18.04 goes with ROS 1 Melodic. Melodic has been end of life since 2023, and you notice it: the official repository at packages.ros.org still lists the packages but partly no longer serves the files (error 404). The frozen snapshot archive works reliably:

sudo sh -c 'echo "deb http://snapshots.ros.org/melodic/final/ubuntu bionic main" > /etc/apt/sources.list.d/ros-snapshot-melodic.list'
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key 4B63CF8FDE49746E98FA01DDAD19BAB3CBF125EA
sudo apt update
sudo apt install ros-melodic-desktop python-rosdep python-catkin-tools python-pip
sudo rosdep init && rosdep update
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc

The later posts need more packages; best install them right away:

sudo apt install ros-melodic-rosserial-python ros-melodic-rosserial-arduino \
  ros-melodic-robot-localization ros-melodic-rtabmap-ros \
  ros-melodic-move-base ros-melodic-navfn ros-melodic-teb-local-planner \
  ros-melodic-rqt-robot-steering

Note: ROS Melodic runs on Python 2.7, so install Curio’s Python packages with pip for Python 2:

pip install pyserial joblib numpy pandas scipy scikit-learn==0.20.4

scikit-learn 0.20.4 is the last version for Python 2. The build may need sudo apt install gfortran first.

Step 3: Build the workspace with Curio

mkdir -p ~/curio_ws/src && cd ~/curio_ws && catkin init
cd src
git clone https://github.com/srmainwaring/curio.git          # or my version, see above
git clone https://github.com/srmainwaring/curio_firmware.git
git clone https://github.com/srmainwaring/curio_msgs.git
git clone https://github.com/wjwwood/serial.git
cd ~/curio_ws && catkin build
echo "source ~/curio_ws/devel/setup.bash" >> ~/.bashrc

Building takes a while on the Nano.

Step 4: Arduino firmware

Rhys describes wiring the Arduino Mega to the BusLinker board and flashing the firmware step by step in the README of curio_firmware. In short:

  • BusLinker to Serial1 of the Mega (pins 18/19), 5 V and GND.
  • Generate the ROS library for the Arduino IDE with rosrun rosserial_arduino make_libraries.py . and copy it into the sketchbook folder.
  • Install the EnableInterrupt library (for the optional RC receiver).
  • Open the curio_firmware sketch, check the switches at the top, compile and upload.

I installed the Arduino IDE directly on the Jetson (there is a “Linux ARM 64 bit” version). An original Mega shows up as /dev/ttyACM0, clones with a CH340 USB chip (like mine) as /dev/ttyUSB0. To give your user access:
sudo usermod -a -G dialout $USER (then log in again).

The servo IDs have to match the configuration: wheels 11, 12, 13 (left front, middle, rear) and 21, 22, 23 (right), steering 111, 131, 211, 231. The mapping lives in curio_base/config/base_controller.yaml, together with the steering trim values that make the corners point straight ahead when driving straight.

Step 5: First test, on blocks!

Put the rover on blocks so all wheels spin freely. Then in three terminals:

roscore
roslaunch curio_base arduino_controller.launch port:=/dev/ttyACM0   # or /dev/ttyUSB0
roslaunch curio_base base_controller.launch

and to drive:

rosrun rqt_robot_steering rqt_robot_steering

The sliders set speed and turn rate. The corners steer so that all wheels roll around a common centre of rotation. With turn rate and no speed they turn in for a spin on the spot.

Odometry: a decision tree for the servos

One detail of Curio I find especially neat: in continuous rotation mode the LX-16A reports its position reliably only over part of a revolution and returns nonsense in the rest. But odometry needs to know how far each wheel has turned. Rhys detects this dead zone with a scikit-learn decision tree trained on measured data and estimates the position there.

Important: the bundled model files were created with a specific Python and scikit-learn version. Rhys recommends retraining them on your own machine:

roslaunch curio_base train_classifier.launch
roslaunch curio_base train_regressor.launch

Odometry can be fine-tuned with two factors in base_controller.yaml (wheel radius and track width). I needed a factor of 0.89 on the distance travelled. For the heading I no longer rely on the wheels but on the camera’s gyro, more on that in post #6.

My changes compared to the original

Many things only showed up during autonomous driving. So you don’t take the same detours, here are the most important points. They are all in my version on GitHub:

  • Clock at boot: The Jetson Nano has no battery-backed clock and boots with a wrong date (2021 or 2031 for me). If the network sets the clock while ROS is already running, ROS time jumps by years. rosserial then loses the connection to the Arduino every 15 seconds (“Lost sync with device”) and the rover jerks. Solution: start ROS only once the clock is synchronised (timedatectl reports “System clock synchronized: yes”), and use only one time service (chrony; uninstall ntpdate).
  • Autostart: a systemd service starts roscore and all nodes after boot; a start script waits for the clock first.
  • Steering when turning: If the commanded centre of rotation lies inside the rover, individual wheels stand almost crosswise. The controller then flips them by 180 degrees at the slightest change. My base controller turns cleanly on the spot in that case and drives very wide arcs (radius above 3 m) straight. That calms the servos down a lot.
  • Python 2 and non-ASCII characters: comments with umlauts need the line # -*- coding: utf-8 -*- in Python 2 nodes. Better avoid non-ASCII characters in URDF/xacro files entirely, otherwise joint_state_publisher crashes.

What’s next?

The rover now drives via sliders. In the next post it gets eyes: an Intel RealSense D435i depth camera, including driver installation on the Jetson and calibration.

[Image: rover on blocks with Jetson and Arduino]

Leave a Reply

Your email address will not be published. Required fields are marked *