Difference between revisions of "Tutorial"

From MAE/ECE 148 - Introduction to Autonomous Vehicles
Jump to: navigation, search
(Raspberry Pi Setup)
(Throttle and Steering Calibration)
Line 108: Line 108:
 
=== Throttle and Steering Calibration ===
 
=== 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 actuator/mechanism to find out its range of motion compared to the control / command a computer will send to the controller of the actuator/mechanism.
+
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. If you use the same platform, the numbers should be really close. Otherwise, you will need to calibrate your car.
+
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.
  
I am following the standard from RC CAR world, Channel 1 for Steering, Channel 2 for Throttle
+
At this time:
Donkey use Channels 0 and 1
 
  
Connect the Steering Servo on Channel 1
+
'''Connect the Steering Servo wire to the Servo controller Channel 1'''
Connect the Throttle on Channel 2
 
  
The calibration is RoboCar specific. If you use the same platform, the numbers should be really close. Otherwise, you will need to calibrate your car.
+
'''Connect the Throttle wire to the Servo controller Channel 2'''
  
The example below is for the Hobbyking GTR Drift Car
+
Before proceeding '''MAKE SURE YOUR CAR IS IN THE STAND'''.
 
 
I am following the standard from RC/CAR world, Channel 1 for Steering, Channel 2 for Throttle
 
 
 
MAKE SURE THE ROBOT IS IN THE STAND
 
  
 
Connect the batteries and batteries monitor
 
Connect the batteries and batteries monitor
Line 239: Line 234:
 
JOYSTICK_STEERING_SCALE = 1.0
 
JOYSTICK_STEERING_SCALE = 1.0
 
AUTO_RECORD_ON_THROTTLE = True
 
AUTO_RECORD_ON_THROTTLE = True
 
 
  
 
== Track ==
 
== Track ==

Revision as of 16:18, 13 October 2017

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

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.

Donkeycar

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.

At this time:

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.

Connect the batteries and batteries monitor Power the RPI Power the Electronic Speed Controller (ESC) Enable the robot (EMO) - LED should be RED

Lets run a Python command to calibrate Steering and Throttle The donkey 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


Using TensorFlow backend. Channel 1 has the Steering Servo (STEERING). Try some values around 400 to center the steering Enter the channel your actuator uses (0-15).1 Enter a PWM setting to test(100-600)370 Enter a PWM setting to test(100-600)365 Enter a PWM setting to test(100-600)360

In my case, 365 seems to center the steering Take note of the left max, right max, ex:

365 - Center 285 - Steering left max 440 - Steering right max

Note: When the manage.py calibrate times-out, just run it again (env)pi@jackrpi02:~/d2 $ python manage.py calibrate You can interrupt the calibration by typing CTRL-C


Now to calibrate the Throttle Electronic Speed Controller ESC (THROTTLE) Following the standard for R/C cars. Throttle goes on channel 2 Using TensorFlow backend. Enter the channel your actuator uses (0-15).2 Enter a PWM setting to test(100-600)370 (neutral) Enter a PWM setting to test(100-600)380 Enter a PWM setting to test(100-600)390

370 when power up the ESC seems to be the middle point (neutral), lets use 370 also to be compatible with Donkey.

Neutral when power the ESC - 370 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.

Max speed forward - 460


Reverse on RC cars is a little tricky because the ESC needs to receive a reverse pulse, zero pulse, and again reverse pulse to start to go backwards. Use the same technique as above 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. Enter values +/- 10 of the reverse value to find a reasonable reverse speed. Remember this reverse PWM value. (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 (env)pi@jackrpi02:~/d2 $


--- Neutral when power the ESC - 370 Max speed forward - 460 Max speed backwards - 280

and from the steering calibration

Center - 365 Steering left max - 285 Steering right max - 440 ---

Now lets write these values into the car configuration file (env)pi@jackrpi02:~/d2 $ ls config.py data logs manage.py models


Edit the file config.py (env)pi@jackrpi02:~/d2 $ nano config.py

Change these values according to calibration values and where you have the steering servo and ESC connected 

...

  1. STEERING

STEERING_CHANNEL = 1 STEERING_LEFT_PWM = 285 STEERING_RIGHT_PWM = 440

  1. THROTTLE

THROTTLE_CHANNEL = 2 THROTTLE_FORWARD_PWM = 460 THROTTLE_STOPPED_PWM = 370 THROTTLE_REVERSE_PWM = 280

Also change these

  1. 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