This repository contains sample code for competitors of the Autodrift Grand Prix NUS competition.
The implementation in this repo requires the use of the Robot Operating System (ROS1). You can find out more about ROS from their website: http://wiki.ros.org/. While competitors are free to decide on their own choice of software and libraries, and the use of ROS is completely optional, it is nevertheless highly recommended.
As of the time of writing, there has yet to be a version of the ROS binary that can be installed on the Raspberry Pi 4 using apt-get
, so you will need to install ROS from source. A link to a guide containing the instructions is included in the Useful Links
section below. Of course, if you have other ways of obtaining a version of ROS on the Raspberry Pi, that is fine as well.
In the src/ folder, you will find 2 subfolders, the joy package and the drift_racer package.
The joy package is a clone of the official ROS joy package, for your convenience. This package will allow you to use the provided Logitech Controller to interface with your robot. Credit to the authors found on the official ROS page: Morgan Quigley, Brian Gerkey, Kevin Watts, Blaise Gassend.
The drift_racer package, on the other hand, is implemented by us and contains some of our code, for your reference. The src
folder contains some basic source code that can serve as a starting point, while the launch
folder contains a launch file that you can use with the ros command roslaunch
. Do note that the original implementation contains several other scripts that have been omitted.
Only 2 nodes need to be implemented to control the robot manually.
-
joystick_teleop.cpp: for interpreting the instructions provided by the
joy
package and converting it into instructions of typeTwist
. In this implementation, it also controls the state of the robot and arbitrates between autonomous navigation commands and manual controls. -
actuators_controller.py: receives control messages from the joystick_teleop node and controls the actuators accordingly.
Because the Machine Learning library used requires Python 3, and ROS only supports Python 2, we need some form of communication between ROS and the Machine Learning library. In this implementation, this is achieved using a combination of TCP socket programming
and pickle
.
-
drive_agent.py: feeds the live image stream from the camera to the trained neural network, encodes the output of the neural network using
pickle
and sends it over a TCP connection. -
nav_controller.py: sets up a TCP socket to receive the output of drive_agent, and controls the car appropriately. Note that some parts of the code has been deliberately omitted.
A sample launch file, drift_racer.launch
has been included, which will allow the robot to be controlled using the provided Logitech controller. You can use this as a starting point to creating your own launch files, which will surely contain more nodes than that shown.
-
Install ROS on Raspberry Pi 4: https://www.seeedstudio.com/blog/2019/08/01/installing-ros-melodic-on-raspberry-pi-4-and-rplidar-a1m8/. Credits: Dmitry Maslov, who authored the instructions, and Elaine Wu. Note that you will only need to complete up to step 3 to install ROS.
-
Official ROS Tutorial: http://wiki.ros.org/ROS/Tutorials. While having a good understanding of ROS will prove extremely beneficial, the most important topics to understand well are 3, 4, 5, 6, 8, 12, and 13 of the Beginner Level section.
-
Official ROS joy package page: http://wiki.ros.org/joy.
To be able to use ROS well, make sure you understand what following terminology/commands mean and how to use them:
Terminology:
- nodes
- topics
- messages
Commands:
- catkin_make
- roscore
- rosrun
- roslaunch
- rostopic