Create your car application
If you are not already, please ssh into your vehicle.
Create Donkeycar from Template
Create a set of files to control your Donkey with this command:
donkey createcar --path ~/mycar
That creates a car using the default deep learning template. You can also create a car the uses the gps path follow template;
donkey createcar --template=path_follow --path ~/mycar
You can also create a car the uses the computer vision template;
donkey createcar --template=cv_control --path ~/mycar
mycaris not a special name; you can name your car folder anything you want.
See also more information on createcar.
Look at myconfig.py in your newly created directory, ~/mycar
cd ~/mycar nano myconfig.py
Each line has a comment mark. The commented text shows the default value. When you want to make an edit to over-write the default, uncomment the line by removing the # and any spaces before the first character of the option.
# STEERING_LEFT_PWM = 460
STEERING_LEFT_PWM = 500
when edited. You will adjust these later in the calibrate section.
Configure I2C PCA9685
If you are using a PCA9685 servo driver board, make sure you can see it on I2C.
sudo usermod -aG i2c $USER sudo reboot
After a reboot, then try:
sudo i2cdetect -r -y 1
sudo apt-get install -y i2c-tools sudo i2cdetect -y 1
This should show you a grid of addresses like:
0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: 70 -- -- -- -- -- -- --
In this case, the 40 shows up as the address of our PCA9685 board. If this does not show up, then check your wiring to the board. On a pi, ensure I2C is enabled in menu of
sudo raspi-config (notice, it suggest reboot).
If you have assigned a non-standard address to your board, then adjust the address in the
myconfig.py under variable
PCA9685_I2C_ADDR. If your board is on another bus, then you can specify that with the
Jetson Nano: set
PCA9685_I2C_BUSNUM = 1 in your myconfig.py . For the pi, this will be auto detected by the Adafruit library. But not on the Jetson Nano.
HAVE_SOMBRERO = True in your myconfig.py if you have a sombrero board.
Robo HAT MM1 Setup
HAVE_ROBOHAT = True in your myconfig.py if you have a Robo HAT MM1 board. Also set the following variables according to your setup. Most people will be using the below values, however, if you are using a Jetson Nano, please set
MM1_SERIAL_PORT = '/dev/ttyTHS1'
#ROBOHAT MM1 HAVE_ROBOHAT = True # set to true when using the Robo HAT MM1 from Robotics Masters. This will change to RC Control. MM1_STEERING_MID = 1500 # Adjust this value if your car cannot run in a straight line MM1_MAX_FORWARD = 2000 # Max throttle to go fowrward. The bigger the faster MM1_STOPPED_PWM = 1500 MM1_MAX_REVERSE = 1000 # Max throttle to go reverse. The smaller the faster MM1_SHOW_STEERING_VALUE = False # Serial port # -- Default Pi: '/dev/ttyS0' # -- Jetson Nano: '/dev/ttyTHS1' # -- Google coral: '/dev/ttymxc0' # -- Windows: 'COM3', Arduino: '/dev/ttyACM0' # -- MacOS/Linux:please use 'ls /dev/tty.*' to find the correct serial port for mm1 # eg.'/dev/tty.usbmodemXXXXXX' and replace the port accordingly MM1_SERIAL_PORT = '/dev/ttyS0' # Serial Port for reading and sending MM1 data (raspberry pi default) # adjust controller type as Robohat MM1 CONTROLLER_TYPE='MM1' # adjust drive train for web interface DRIVE_TRAIN_TYPE = 'MM1'
The Robo HAT MM1 uses a RC Controller and CircuitPython script to drive the car during training. You must put the CircuitPython script onto the Robo HAT MM1 with your computer before you can continue.
- Download the CircuitPython Donkey Car Driver for Robo HAT MM1 to your computer from here
- Connect the MicroUSB connector on the Robo HAT MM1 to your computer's USB port.
- A CIRCUITPY device should appear on the computer as a USB Storage Device
- Copy the file downloaded in Step 1 to the CIRCUITPY USB Storage Device. The file should be named code.py. It should be at the top level of the drive, not in any folder.
- Download the Adafruit logging library python file, adafruit_logging.py, here
- Copy the adafruit_logging.py file into the CIRCUITPY "lib" folder
- Unplug USB Cable from the Robo HAT MM1 and place on top of the Raspberry Pi, as you would any HAT.
You may need to enable the hardware serial port on your Raspberry Pi. On your Raspberry Pi...
- Run the command
- Navigate to the 5 - Interfaceing options section.
- Navigate to the P6 - Serial section.
- When asked: Would you like a login shell to be accessible over serial? NO
- When asked: Would you like the serial port hardware to be enabled? YES
- Close raspi-config
If you would like additional hardware or software support with Robo HAT MM1, there are a few guides published on Hackster.io. They are listed below.
If you plan to use a joystick, take a side track over to here.
If you are using the default deep learning template then you will need a camera. By default myconfig.py assumes a RaspberryPi camera. You can change this by editing the myconfig.py file in your
If you are using the gps path follow template then you do not need, and may not want, a camera. In this case you can change the camera type to mock;
CAMERA_TYPE = "MOCK".
If you are on a raspberry pi and using the recommended pi camera ("PICAM"), then no changes are needed to your myconfg.py.
When using a Sony IMX219 based camera, and you are using the default car template, then you will want edit your myconfg.py to have:
CAMERA_TYPE = "CSIC".
For flipping the image vertically set
CSIC_CAM_GSTREAMER_FLIP_PARM = 6 - this is helpful if you have to mount the camera in a rotated position.
CAMERA_TYPE = CVCAM is a camera type that has worked for USB cameras when OpenCV is setup. This requires additional setup for OpenCV for Nano or OpenCV for Raspberry Pi.
You can also use a USB camera if you prefer. If you have installed the optional OpenCV dependencies then you can use OpenCV to connect to the camera by editing the camera type to
CAMERA_TYPE = "CVCAM". If you have installed the optional pygame library then you can connect to the camera by editing the camera type to
CAMERA_TYPE = "WEBCAM". See the required additional setup for pygame.
We are adding other cameras over time, so read the camera section in myconfig.py to see what options are available.
If you are having troubles with your camera, check out our Discord hardware channel for more help.
Upgrade Donkey Car Software
Make all config changes to myconfig.py and they will be preserved through an update. When changes occur that you would like to get, you can pull the latest code, then issue a:
cd projects/donkeycar git pull donkey createcar --path ~/mycar --overwrite
If you created a car with the gps path follow template then remember to include the --template argument;
donkey createcar --template=path_follow --path ~/mycar --overwrite
Your ~/mycar/manage.py, ~/mycar/config.py and other files will change with this operation, but myconfig.py will not be touched. Your data and models dirs will not be touched.