My RC Controlled Robot - Chacebot, Powered by ROS and C++
11 May 2020
Chacebot has been my side project over the past month and it has been a very fun platform for me to demonstrate my C++ skills and get more hands on experience with the Robotic Operating System (ROS).
Why did I choose this project?
Throughout the past three years of my actuation design career, I have always met a large blocker once all my prototypes were assembled - lack of a control pipeline. My motivation behind this project is to produce a plugin that can easily integrate into a software stack containing motor drivers and directly start controlling motion in open loop. This plugin is a very valuable tool to add to my R and D toolbox so that I can learn from my designs faster and iterate even quicker to produce quality - well tested designs.
Requirements for this project:
- Must be cheap and simple hardware. Developing hardware is my day job, I wanted this project to fully focus on sharpening my software / firmware knowledge
- Must be implemented with ROS I know a lot of companies hate on ROS, however most of the custom middleware alternatives are not much different in terms of message publishing and subscription. Using a common middleware enables this plugin to be more adaptable to a range of projects.
- Must be written in C++. In addition to ROS, a lot of companies also dislike python for robotics and that is something I can get on board with when it comes to writing low level code. Although python is a simpler language to learn and adapt to a wide variety of problems due to the abundance of open source libraries, it is not efficient and safe. Therefore I feel it C++ is a great choice because of its robustness and efficiency.
Although this code is currently running on my raspberry pi powered robot, my future plans are to extend it to any type of robot using an operating system / CPU that can support ROS. With that said, here is an overview of my current setup.
The robot base, drivetrain, and motor drivers are sourced off the shelf from a company called Dexter industries. They make very affordable and fun robotics parts for education. This package without the raspberry pi included cost around $120 and the quality is not terrible. The robot is a holonomic differential drive robot base powered with two brushed DC motors with on axis encoders (on the motor axis). These motors have right angled gear heads with a reduction so the motor driver has to do a little math to get the velocity settings correct. Lastly this robot includes an arduino atmega microcontroller mounted on a custom PCBA running a 12V rail to power the motors. This microcontroller enables a raspberry pi 4 to easily communicate to the peripherals and drive wheels using SPI. Since this microcontroller comes flashed with it’s own firmware off the shelf, I will not discuss it because I did not code it.
I splurged and purchased the dexter industries imu and ultrasonic sensor in addition to the raspberry pi camera as shown in the image above.
Also, what else is that on top? Well, that is the chacebot RC receiver wired up to a STM32F108 microcontroller that talks to the raspberry pi via usb. The RC receiver is paired with a specific 3 channel RC transmitter that is a very common item used to drive RC cars.
I am currently using this device to provide ergonomic open loop control of the drivetrain of my robot (and can be easily modified for any mobile robot). Although this is a major part of this project, it is not the focus of the blog post and will leave you, the reader, something to look forward to in a future post! Let’s now take a look at the ROS software stack running on chacebot.
Package Overview
Currently the ROS stack is composed of Three main components.
- Local Controller: ROS node that continuously reads the serial buffer on a port specified in the source code and publishers it to a topic called /local_cmd
- Motion Allocator: The middleman that subscribes to the /local_cmd topic, processes that steering and drive input and maps that to the appropriate /left_wheel_speed and /right_wheel_speed topics it publishes
- GoPiGo3 Driver: A low level node written in python that subscribes to multiple topics and is composed of the libraries provided by dexter industries with their robot. I did not write this code because the libraries are in python and the purpose of this project was to further develop my C++ skills in addition to not writing hardware specific code.
Here is the overview of the file structure of my ROS stack: It is composed of 4 packages, one for each of the nodes listed above and another for which is solely for custom messages that does not contain any scripts or source code:
chacebot_ws/
|- README.md
|- src/ Source Code
|- gopigo3_node/ GoPiGo3 Python ROS Driver
| |- launch Launch Files
| |- msg Custom Driver Messages use by the driver only
| |- src Source code aka python scripts in this context
| |- srv Custom services within the driver package
| |- CMakeLists.txt
| |- package.xml
|- local_controller/ C++ Pacakge for interpeting RC reciever
| |- src
| |- CMakeLists.txt
| |- package.xml
|- motion_allocator/ C++ Package to make steering, drive to L,R wheel velocities
| |- src
| |- CMakeLists.txt
| |- package.xml
|- msg/ Package for custom messages used across multiple nodes
| |- msg
| | |-RCLocal.msg Custom Message for sending RC transmitter values
| |- CMakeLists.txt
| |- package.xml
Each package contains a CMakeLists.txt and a package.xml that are required by ROS to configure the package correctly for it to successfully be built. These files specify where to find includes, what executables to add, flags for message generation, etc.. We will dive into these specifics in future blog posts about each package.
Lastly, before we dive into the source code for this project in future posts, I would like to share the required dependencies so that anyone interested can try and build this project on their raspberry pi powered dexter robot. Here is a list in order of installation.
How to Install
- A raspbian image with ROS kinetic preinstalled. I found a great one provided by a gentleman named Jack Pien from Hadabot, you can find the image through this Github Repo
- The dexter industries driver libraries to communicate with the microcontroller provided with the GoPiGo. This main drivers are found here and if you are interested in using their sensor accessories, the added libraries to drive those components are found here.
- If using the raspbian image with ROS I mentioned above, you will also need to install ROS nav-msgs because they are required by the ROS GoPiGo3 driver used in this project. These nav-messages provide what is needed for odometry. This is a complex thing to do, luckily someone else ran into this issue when trying to use this driver on this specific ROS image and the instructions for successfully installing these message dependencies are found here. Tldr, seems like the ros install on the raspbian image was non traditional and uses the ROS root directories (the standard /opt/ros location) and instead is installed in a subfolder of the home directory.
- Once the above is completed you are ready to clone this project’s workspace into your file system using
$ git clone https://github.com/chacebot/chacebot_ws
Now that you have this project installed, please try running the individual packages to get more practice with ros! The usage and details for each package will follow in future blog posts for each package. Thank you for reading this far, cheers!