From now until the end of this chapter, I'll assume you're working on your car via SSH.
First, we'll run the createcar
command, which will create a new directory with all of the files needed to run and train our RC.
Command usage from the docs:
donkey createcar --path <dir> [--overwrite] [--template <donkey2>]
Run the following command to create a new donkeycar application:
donkey createcar --path ~/mycar
Open the newly created directory:
cd ~/mycar
We can find a bunch of settings for the application we just created in a file called myconfig.py
. We'll have to edit this file to make our RC work as intended.
Open up the myconfig.py
file in a text editor:
nano myconfig.py
Note: Some settings are commented out by default (read: have a #
at the beginning of the line). Whenever we're filling in a value of some setting, you should uncomment it first/remove the #
at the beginning.
If you're using Nano as your text editor, you can press CTRL+W
and type in CAMERA
and press enter to jump to the camera settings.
If you're using Vim, you probably don't need me to tell you how to search for stuff, but I'll do it anyways: type in /CAMERA
to search forward for the camera settings, and use n
and N
to go back and forth between matches.
Here are the settings:
# #CAMERA
CAMERA_TYPE = "CVCAM" # (PICAM|WEBCAM|CVCAM|CSIC|V4L|MOCK)
IMAGE_W = 1280
IMAGE_H = 720
IMAGE_DEPTH = 3
The different types of camera are:
If your image is flipped, or you want to mount your camera in a rotated position, use:
Also, you can specify your resolution/image depth here:
We also need to specify which bus we've connected our PCA9685 to.
See this to refresh your memory:
We'll also need the I2C address our PCA is connected to, for which we'll need to:
# Add our user to the i2c group
sudo usermod -aG i2c YOUR-USERNAME
# Reboot so it takes effect
sudo reboot
After rebooting, type:
# i2c-tools should come preinstalled with your Nano, but in case they aren't:
# sudo apt install i2c-tools
# For Bus 0: use 0
# For Bus 1: use 1
sudo i2cdetect -r -y 1
If your PCA is wired/connected correctly to the Nano, you should get something 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 -- -- -- -- -- -- --
The results explained:
40 and 70: The addresses of our device. We'll be using the first one, 40, to address it.
–: the address was probed, no chip was found
UU: probing was skipped because the address is currently in use
If you're getting jibberish or all of the addresses are filled, check your connections, you probably swapped SDA and SCL or plugged them into the wrong pins.
Finally, in the myconfig.py
file, find and fill the following:
PCA9685_I2C_ADDR = 0x40
PCA9685_I2C_BUSNUM = 1
We also need to specify to which PCA channels our steering servo and our ESC are connected to.
See this to refresh your memory or just look at the numbers on the PCA, above the places you've connected your servo and ESC connectors to, they correspond to their respective channel numbers.
In the settings, find and fill out the steering:
# #STEERING
STEERING_CHANNEL = 1 #channel on the 9685 pwm board 0-15
And the throttle channel values:
# #THROTTLE
THROTTLE_CHANNEL = 0 #channel on the 9685 pwm board 0-15
In my case, the throttle/ESC is the zeroth channel and the steering/servo is the first channel.
We will also need to fill out the following values for steering:
STEERING_LEFT_PWM = ??? #pwm value for full left steering
STEERING_RIGHT_PWM = ??? #pwm value for full right steering
And throttle:
THROTTLE_FORWARD_PWM = ??? #pwm value for max forward throttle
THROTTLE_STOPPED_PWM = ??? #pwm value for no movement
THROTTLE_REVERSE_PWM = ??? #pwm value for max reverse throttle
To do so, we'll need to calibrate our steering and throttle first, and then come back with the values we've found and fill them in.
Feel free to save the changes you've made to the myconfig.py
file so far:
CTRL+O
and Enter/Return
to save, CTRL+X
to close the editor:wq!
:)