The Donkey Car platform was developed a number of years ago and is comprised of a community of more than 5000+ people around the world. It is an open-source project with the aim of creating cheap autonomous cars.
Robo HAT MM1 was successfully crowd funded on Crowd Supply in June 2019 and is now in the hands of backers.
This guide will show you how to use the Robo HAT MM1 with the Donkey Car Platform to create a self-driving scale car.
- Robo HAT MM1
- Raspberry Pi 3/4 or Jetson Nano
- Magnet Car with RC Controller
- 32GB SD Card (faster the better)
- 4000mAh LiPo Battery
The Donkey Car Community has a full list of options available for building your own custom car. They can be viewed here.
Using the Robo HAT MM1 makes the assembly a little different from the instructions on the Donkey Car Documentation. Most of the physical assembly (3D printed case) is the same. The electronics are different - so we will focus on this side of things.
The first thing you will need to do is put the Robo HAT MM1 HAT onto the top of the Raspberry Pi or Jetson Nano. Just line up the pins on the 40 pin header and carefully side the HAT onto the connector.
Recommendation: For the Raspberry Pi, the camera connector is difficult to access once you have a HAT on the Raspberry Pi. It might be easier to put the Pi camera into the camera connector before putting the Robo HAT on top.
CAREFUL: If you misaligned the connector you will damage the Raspberry Pi / Jetson Nano.
You can remove the HAT by gently pulling up. Try not to bend the pins when pulling off.
The RC Controller
Instead of using a Bluetooth or Web Controller, the Robo HAT MM1 lets you control the car directly with the RC controller that comes with the car. In order to make this work, you have to connect the receiver to the Robo HAT MM1 input (Radio Control Channels - RCC) pins.
In the below images, you will see the receiver and the HAT. Follow the diagram for how to connect the receiver to the HAT so that the software works correctly with Donkey Car. Make sure you go through all three (3) pictures below.
We used an adaptor to join the two parts together (see picture) so simplify the process.
The software (which we talk about later) lets you swap these around to suit your controller.
Default configuration: RCC4 is channel 1, RCC3 is channel 2.
Donkey Car uses two servo connectors for the throttle and steering channels on the car. We connect these to the Robo HAT MM1 as well.
Make sure that you connect the servo connectors the correct way. If you connect them the wrong way round, the car will not operate correctly and you may cause damage.
The Servo outputs are colour coded on the Robo HAT MM1 to make it easier to work out which way the connector goes.
- Yellow (white) - Signal / Data
- Red - 5V Power
- Black - Ground
The throttle cable (which comes from the ESC) is connected into SERVO1. The steering cable is connected to SERVO2.
The software (which we talk about later) lets you swap these around to suit your controller or setup.
The Robo HAT MM1 has a powerful on-board voltage regulator that can output a constant 5A of current and peak of 8A. This is enough to power the Jetson Nano/Raspberry Pi plus some servo motors.
However, the ESC will output it's own voltage to the servo power system.
All we need to do here is connect the battery and ESC power to the Robo HAT MM1. The "IN" connector is for the LiPo Battery. We recommend a large 4000 mAh+ battery. The "OUT" connector is for the ESC power. The ESC has a connector for directly connecting to the Battery, however, we need the battery to power the Robo HAT MM1 and Jetson Nano/Raspberry Pi.
CAREFUL: Connecting the battery terminals the wrong way will result in damage to all connected devices. Please follow the colour coding.
The Robo HAT MM1 has an option to connect a smaller 'backup' rechargeable battery to the connector next to "OUT". This is recommended as it provides an additional 2A of current for powering the Jetson Nano/Raspberry Pi.
That should be all for the electronics of the car. If you encounter any issues please join the Donkey Car Slack community channel and ask. The Donkey Car community are really helpful.
The software comes in two parts -
- (1) CircuitPython component that runs on the Robo HAT MM1
- (2) Donkey Car Software that runs on the Raspberry Pi.
Let's discuss the CircuitPython component first and why we have to use it with the Robo HAT MM1.
The Robo HAT MM1 runs CircuitPython by Adafruit (a Python variant). This lets you write and run Python code on micro-controllers. CircuitPython has libraries for controlling Servos, LEDs, NeoPixels and a lot of other things - making it easy to customise but powerful enough to do lots of complex operations.
Donkey Car traditionally uses a Bluetooth PlayStation controller (through the Raspberry Pi) to send commands to the car. This method is reliable, however, can be annoying to set up (in my opinion). Also - The Jetson Nano does not have Bluetooth on-board, so you would need to by an additional part.
Using CircuitPython on the Robo HAT MM1, we are able to read RC controller signals or pulses, control the servos and send the signals (over serial) to the Donkey Car software all at the same time.
Adding Software to Robo HAT MM1 via USB
You must put the CircuitPython script onto the Robo HAT MM1 with your computer before you can get the car driving.
1. Download the CircuitPython Donkey Car Driver for Robo HAT MM1 to your computer from here
2. Connect the MicroUSB connector on the Robo HAT MM1 to your computer's USB port.
3. A CIRCUITPY device should appear on the computer as a USB Storage Device
4. Copy the file downloaded in Step 1 to the CIRCUITPY USB Storage Device. Rename the file code.py.
5. Unplug USB Cable from the Robo HAT MM1 and place on top of the Raspberry Pi, as you would any HAT (follow step 1 instructions).
This is the same process for adding any CircuitPython software to the Robo HAT MM1. All the code goes into a file on the USB drive called code.py which is run automatically when the board is restarted.
This stage is pretty much the same as the provided Donkey Car Documentation. The only variation is that you need to enable the Hardware Serial Port for a Raspberry Pi.
You may need to enable the hardware serial port on your Raspberry Pi. On your Raspberry Pi...
1. Run the command ```sudo raspi-config```
2. Navigate to the 5 - Interfacing options section.
3. Navigate to the P6 - Serial section.
4. When asked: Would you like a login shell to be accessible over serial? NO
5. When asked: Would you like the serial port hardware to be enabled? YES
6. Close raspi-config
Follow the rest of the instructions on the Donkey Car Documentation to ensure that your car software gets installed correctly. Once you have installed the Donkey Car Software and created a new car. There will be a file called "myconfig.py" that needs to be changed.
HAVE_ROBOHAT = True in your myconfig.py if you have a Robo HAT MM1 board.
Then you can skip ahead to the next step. The Robo HAT MM1 does not need to be calibrated because it is using the RC Controller.
To start driving your car around, make sure you turn on all the power (I miss the ESC switch a lot :P ).
Then in the folder that you created for your car, run the following command:
python manage.py drive --js
Why this command?
Let's take a look at the Donkey Car code:
if use_joystick or cfg.USE_JOYSTICK_AS_DEFAULT:
from donkeycar.parts.robohat import RoboHATController
ctr = RoboHATController()
from donkeycar.parts.controller import get_js_controller
ctr = get_js_controller(cfg)
- The --js flag sets the use_joystick to True.
- We already set the HAVE_ROBOHAT = True in a previous step.
If we did not put in the --js flag in the command, it will not run the Robo HAT MM1 code but instead the Web Controller.
The command to drive with your trained model is:
python manage.py drive --model models/mypilot.h5
Make sure you use the correct name of the model that you created. The mypilot.h5 is an example name.
That's all for getting the Donkey Car to run with the Robo HAT MM1. If you have any issues please reach out.
I have some plans in the future for the Robo HAT MM1 and Donkey Car. I'll outline some of them here and maybe one day write about them on @hacksterio.
1 - IMU Support
The Robo HAT MM1 has an IMU on it and I would like to see what can be done with sending that data back to the Donkey Car software with the steering data to see if models can get better. The IMU support is already included in Donkey Car, however, I have never tested it out.
2 - Power Protection
The Robo HAT MM1 has a very accurate current sensor on it that detects current, voltage and other power related things. I have already started experimenting in CircuitPython with this part and also tried putting in some stall prevention software into the CircuitPython Donkey Car driver. I would like to use this part more to have the most stable Donkey Car set up.
3 - Control Interface
I have been working on making a Donkey Car UI that works with the Robo HAT and other hardware to simplify the control interface and make it easier to use the car at events without good WiFi.
You can check out the progress being made so far: https://github.com/wallarug/donkeycar-ui
I hope you enjoyed reading my story! Thank you for reading.