Project Overview
This project aims to build a low-level controller using Arduino, paired with ROS, in order to achieve control interaction directly with the differential drive robot motors. Using DC motors w/ encoders and an IMU, paired with an Arduino Mega and the Arduino library, rosserial.h, to act as a bridge between the hardware and the ROS network that our robot’s algorithms are run on. Additionally, the project uses the PID_v1.h library and the Encoder.h library in order to use PID control and process encoder signals.
Components/ Purchase List
- Arduino Mega
- Hobby Motors with Encoders x2
- L298N Motor Controller
- Jetson Nano 2GB
The Jetbot Kit comes with two yellow 5V hobby motors. In order to get velocity data and be able to control the speed accurately, encoder data is more necessary. A solution for this is to replace the Jetbot motors with Hobby Motors with Encoders, pictured below:
This motor from Sparkfun has a built in motor encoder. It has the same mounting holes as the motors that are included in the Jetbot kit, which makes mounting and placing them easy. Instead of plugging in the power and the ground into the Jetbot’s power distribution board, run the 6 wires through the hole in the bottom of the Jetbot’s motor chassis and out so that it can be wired to the motor driver and external power.
Here is a wiring diagram of the set up of the motors and the motor driver to the Arduino Mega. The Arduino Mega should be plugged in to the Jetson Nano through the use of a USB-B to USB-A connector wire. The motors will need an extra 9V battery to power them–they are rated for 3V-9V, but do not produce enough torque to move the motors until provided ~7V.
The Arduino Mega is equipped with the code that is added at the bottom of this page. This code was developed with lots of help from Richard Hall, a PhD student in the Bridgeman Lab. A high-level overview of the code is illustrated below:
The code has the following dependencies, which can all be downloaded through the Arduino IDE libraries tab in the editor.
ros.h
(Rosserial Arduino Library by Michael Ferguson)Encoder.h
(Encoder by Paul Stroffregen)ArduPID.h
(ArduPID by PowerBroker2)FireTimer.h
(FireTimer by PowerBroker2)
In order to enable ROS communication between the Arduino and the Master Computer, a few repositories need to be built on the Jetbot. These include ROS, as well as ROSserial_Arduino. Directions for accomplishing these things can be found, below.
You will need to be running Ubuntu 18.04 in order to accomplish this tutorial.
Follow this tutorial in order to download ROS and set up your ROS environment.
After configuring your ROS environment, run these commands in order to install the ROSserial binaries onto the Jetson Nano.
$ sudo apt-get install ros-${ROS_DISTRO}-rosserial-arduino $ sudo apt-get install ros-${ROS_DISTRO}-rosserial
After building ROS and installing ROSserial Arduino, you can plug your Arduino Mega into a USB port on the Jetson Nano.
To turn your Arduino into a ROS node on the Jetson Nano, run these commands in terminal windows of your Jetson Nano:
In the first terminal, run
$ roscore
to start ROS.
In a new terminal, run
$ rosrun rosserial_python serial_node.py _port:=/dev/ttyACM0 __name:=”controller”
This will bring up your Arduino as a ROS node and allow you to publish and receive messages from the Arduino on the topics specified in the Arduino code.
In order to view or stream your data on a specific topic, you can run the following in a new tab:
$ rostopic echo <name-of-topic>
To replicate this project for yourself, work through the guidances below that I found helpful!
A good beginner level exercise to help you get started in replicating this project is to work through this tutorial: How to Use the L298N Motor Driver. This tutorial will teach you how to get started with motors and a controller in Arduino. Once you wire up the motor driver with your motors and Arduino, you can check out the code that includes speed control and the code without. This tutorial is the very basic building block for the rest of the project.
Once you are able to control the motor direction and speed, a next building block step to understanding the project is to learn about PID control. This tutorial can help you get started. The PID controller in the Arduino code of this Jetbot project uses the same PID library as the tutorial.
After learning about motor control and PID controller methodology, the next step is to learn about ROS and how to turn your Arduino into a ROS node using ROSserial. The link to Arduino ROSserial tutorials found here is a good resource in helping to learn how ROS works, and how ROS on Arduino works. I would specifically recommend following the Hello World (publisher) and Blink (subscriber) tutorials.
An expert level step that our team was not able to get to is integrating this project with the rest of the subteams. This requires all of the subteam python scripts to be created into python nodes in ROS, making them able to send and receive ROS messages. Additionally, another expert step is to retune the PID controller to the Jetbot that has all of the sensors equipped. The weight of the additional sensors will change the vehicle dynamics slightly, which will affect the controller’s performance. Guidance to create publishers and subscribers for ROS in python can be found here.