Tutorial
Build
Designing and fabricating a wheel based mobile robot vs. building on the top of a reliable platform such as an R/C truck 1/8 scale.
- R/C Truck 1/8 Scale
- Embedded system 4 cores Linux
- 5 megapixel camera
- Servo controller
- Power management
- LiPo Battery
- Safety on LiPo charging, use, and storage
- Wireless Emergency Off (EMO) circuit
Donkeycar
Raspberry Pi Setup
Follow the instructions from:
http://docs.donkeycar.com/guide/install_software
to download an image that already contains all that you need to run the donkey car software.
Follow the instructions in Get the Raspberry Pi working.
This next step is very important. If you miss this configuration before you boot for the first time you will not be able to connect to your Pi using the lab network!
Substitute the content of the file /boot/wpa_supplicant.conf
given in the section Setup the Pi's WiFi for first boot by the following:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=US network={ ssid="UCSDRoboCar2.4GHz" key_mgmt=WPA-PSK psk="** ASK YOUR INSTRUCTOR **" priority=60 id_str="ucsdrobocarsfield" } network={ ssid="UCSDRoboCar2.4GHz_lab" key_mgmt=WPA-PSK psk="** ASK YOUR INSTRUCTOR **" priority=50 id_str="ucsdrobocarlab" }
and follow the instructions for booting your Pi for the first time, including the section Setup Pi's Hostname. After the first boot, this file will be moved to /etc/wpa_supplicant/wpa_supplicant.conf
where it may be edited later.
STOP do not run anything starting at Connecting to the Pi.
Installation
First remove the donkey and d2 directories
(env)pi@jackrpi02:~ $ rm -rf donkeycar (env)pi@jackrpi02:~ $ rm -rf d2
Download the latest Donkey code
(env)pi@jackrpi02:~ $ git clone https://github.com/wroscoe/donkey donkeycar
Install Donkeycar:
(env)pi@jackrpi02:~ $ pip install -e donkeycar
Create a car folder.
(env)pi@jackrpi02:~ $ donkey createcar --path ~/d2
The latest command will produce an output similar to:
Using TensorFlow backend. Creating car folder: /home/pi/d2 making dir /home/pi/d2 Creating data & model folders. making dir /home/pi/d2/models making dir /home/pi/d2/data making dir /home/pi/d2/logs Copying car application template: donkey2 Copying car config defaults. Adjust these before starting your car. Donkey setup complete.
Testing the connection of the RPI to the Pulse Width Modulation (PWM) Controller
Type:
(env)pi@jackrpi02:~ $ sudo i2cdetect -y 1
which should produce an output like:
(env)pi@jackrpi02:~ $ sudo i2cdetect -y 1
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 important point here is to get a response from the I2C addresses 40 and 70. If you do not see these numbers you are not connected to the ESC or the Servo controller.
Throttle and Steering Calibration
Before you develop code or you can use a someone's code to control a robot, we need to calibrate the steering servo and the brushless DC motor ESC to find out its range of motion compared to the control or command a computer will send to the controllers.
The calibration is car specific. However, because we are all using the same platform, the numbers for the different groups should be close.
We will following the standard connection from RC CAR world, that is we will use Channel 1 for Steering and Channel 2 for Throttle. Donkeycar uses Channels 0 and 1 so we will need to some settings later.
Perform the following steps:
- Connect the Steering Servo wire to the Servo controller Channel 1
- Connect the Throttle wire to the Servo controller Channel 2
Before proceeding MAKE SURE YOUR CAR IS IN THE STAND.
Perform the following steps:
- Connect the batteries and batteries monitor
- Power the RPI
- Power the Electronic Speed Controller (ESC)
- Enable the robot (EMO) - LED should be RED
Steering Calibration
The following commands need to be run from the directory you created for your car, i.e., d2
Change directory to d2:
(env)pi@jackrpi02:~ $ cd ~/d2 (env)pi@jackrpi02:~/d2 $ python manage.py calibrate
The above command is iterative. Provide the information as in the following output:
Using TensorFlow backend. loading config file: /home/pi/d2/config.py config loaded Enter the channel your actuator uses (0-15).1 Enter a PWM setting to test(100-600)365 Enter a PWM setting to test(100-600)285 Enter a PWM setting to test(100-600)440
Try some values around 360 to center the steering. Take note of the values that steer completely to the left and completely to the right. If you hear a buzzing noise you have reached the maximum left or right. My values are:
365 - Center 285 - Steering left max 440 - Steering right max
Notes: If the command python manage.py calibrate
times-out, just run it again. You can interrupt the calibration by typing CTRL-C
Throttle Calibration
Repeat the commands used to calibrate the steering this time to calibrate the throttle, this time using Channel 2 instead of Channel 1.
(env)pi@jackrpi02:~/d2 $ python manage.py calibrate
The above command is iterative. Provide the information as in the following output:
Using TensorFlow backend. loading config file: /home/pi/d2/config.py config loaded Enter the channel your actuator uses (0-15).2 Enter a PWM setting to test(100-600)370 Enter a PWM setting to test(100-600)380 Enter a PWM setting to test(100-600)390
370 powers up the ESC and put it in neutral. Then go in increments of 10~20 until you can no longer hear increase on the speed of the car. Don’t worry much about the max speed since we won’t drive that fast autonomously and during training the speed will be limited.
My max speed forward was at around 460.
Reverse on RC cars is a little tricky because the ESC needs to receive a reverse pulse, zero pulse, then another reverse pulse, to start to go backwards. Any value below 370 is a reverse throttle.
To see how this works, use the same technique as above to set the PWM setting to your zero throttle (lets say 370). Enter the reverse value, then the zero throttle (e.g., 370) value, then the reverse value again. Increment the reverse value by 10~20 to find a reasonable reverse speed. Remember this reverse PWM value.
An example of a reverse calibration session output is:
(env)pi@jackrpi02:~/d2 $ python manage.py calibrate Using TensorFlow backend. loading config file: /home/pi/d2/config.py config loaded Enter the channel your actuator uses (0-15).2 Enter a PWM setting to test(100-600)360 Enter a PWM setting to test(100-600)370 Enter a PWM setting to test(100-600)360 Enter a PWM setting to test(100-600)350 Enter a PWM setting to test(100-600)340 Enter a PWM setting to test(100-600)330 Enter a PWM setting to test(100-600)320 Enter a PWM setting to test(100-600)310 Enter a PWM setting to test(100-600)300 Enter a PWM setting to test(100-600)290
Update the configuration file
At this point you should have notes of the following extreme values for steering:
- Center - 365
- Steering left max - 285
- Steering right max - 440
and throttle:
- Neutral when power the ESC - 370
- Max speed forward - 460
- Max speed backwards - 280
Now let's write these values into the car configuration file ~/d2/config.py
. Edit this file config.py using your favorite editor, e.g.
(env)pi@jackrpi02:~/ $ cd ~/d2 (env)pi@jackrpi02:~/d2 $ nano config.py
and locate and change the following values to match the ones you obtained in your calibration:
#STEERING STEERING_CHANNEL = 1 STEERING_LEFT_PWM = 285 STEERING_RIGHT_PWM = 440
#THROTTLE THROTTLE_CHANNEL = 2 THROTTLE_FORWARD_PWM = 460 THROTTLE_STOPPED_PWM = 370 THROTTLE_REVERSE_PWM = 280
Also change these:
#JOYSTICK USE_JOYSTICK_AS_DEFAULT = True JOYSTICK_MAX_THROTTLE = 0.5 JOYSTICK_STEERING_SCALE = 1.0 AUTO_RECORD_ON_THROTTLE = True
Track
- Track building - hands-on ~ 40x20 m
Python
Open CV
ROS
Autonomous Vehicles
- Odometry with wheels encoders and IMU
- Short range obstacle avoidance using low cost ultrasonic sensors
- Street light development RED/YELLOW/GREEN
- Image processing with OpenCV
- Image segmentation - far view, close view, fast processing