Difference between revisions of "OHMC2020 Software instructions"

From Open Hardware Miniconf
Jump to: navigation, search
m
m
Line 26: Line 26:
 
== Initial car setup ==
 
== Initial car setup ==
  
Your car will start out set up to talk to a workshop access point. It will display its IP address (among other data) on the oled. You can use this IP address to know where to connect to.
+
Your car will start out set up to talk to a workshop access point. It will display its IP address (among other data) on the oled. You can use this IP address to know where to connect to. Your car is already preconfigured to talk to the LCA ohmc miniconf network.
  
 
First: update the password away from the default!
 
First: update the password away from the default!
Line 32: Line 32:
 
''ssh pi@<IP_ADDRESS>'' with the default password ''raspberry''.  
 
''ssh pi@<IP_ADDRESS>'' with the default password ''raspberry''.  
 
Change this once you log in, using ''passwd'' command.
 
Change this once you log in, using ''passwd'' command.
 
Then: configure it to talk to the conference wifi, by running ''raspi-config'' which will bring up a UI.
 
  
 
== Driving your car manually ==
 
== Driving your car manually ==
Line 132: Line 130:
  
 
= What next? =
 
= What next? =
 +
 +
To connect to your car when you leave LCA, you want to be able to join it onto other networks. It's a good idea to configure it to talk to your phone's hotspot, so that you can access your car anywhere.
 +
Run ''raspi-config'' which will bring up a UI from which you can add more networks.
  
 
A DingoCar is for life, not just for the OHMC at LCA. There's so much more you can do with it. Check out our [[Beyond DingoCar]] section.
 
A DingoCar is for life, not just for the OHMC at LCA. There's so much more you can do with it. Check out our [[Beyond DingoCar]] section.

Revision as of 01:15, 13 January 2020

Overview

Overall, the steps involved are:

  1. Connect to your car, start up the driving management software
  2. Drive the car on a track (through the web interface, or some sort of external controller) and record the session.
  3. Download the data onto your computer
  4. Process the data into a self-driving model (either on Google Colab or on your local environment)
  5. Put the model back on the car.
  6. Start the car in self-driving mode.

From a software perspective, the DingoCar (Raspberry Pi) is self-contained ... driving, data acquisition (for training) and ultimately self-driving are all performed with on-board software. The provided micro-SD card already has all the required software pre-installed, as well as two pre-training A.I / Machine Learning models. The DingoCar software includes a web-server that provides a web interface that works on both desktop and mobile web browsers (which great for driving).

But you need your own laptop to connect to the car (and possibly train the Neural Network, using the data acquired on the DingoCar).

Software environment: Laptop / Desktop

For easiest, and fastest operation, you can use software on Google's Colab to process your car data in the cloud. This means you only need to have on your computer.

  • ssh: to connect to your car. (Windows users, it's now an optional Microsoft update or install putty).
  • scp: to copy files to and from your car (Windows users: putty comes with pscp which is equivalent)
  • a google drive account

If you'd like a local build environment on your computer, check out our quickstart guide, or use the detailed and thorough instructions on the DonkeyCar website.

Initial car setup

Your car will start out set up to talk to a workshop access point. It will display its IP address (among other data) on the oled. You can use this IP address to know where to connect to. Your car is already preconfigured to talk to the LCA ohmc miniconf network.

First: update the password away from the default!

ssh pi@<IP_ADDRESS> with the default password raspberry. Change this once you log in, using passwd command.

Driving your car manually

Caution: Put your car "on blocks" (wheels off the ground) the first time you try driving it

  • ssh pi@<IP_ADDRESS>
  • cd ohmc_car
  • python manage.py drive
 loading config file: /home/pi/play/roba_car/config.py
 config loaded
 PiCamera loaded.. .warming camera
 Starting Donkey Server...
 You can now go to http://xxx.xxx.xxx.xxx:8887 to drive your car.

With a desktop web browser, the user interface provides a virtual joystick (right-hand frame) that you can use to drive the car ... altering the steering and throttle values.

The mobile web browser, the user interface allows you to drive by tilting the phone left-right for steering and forwards-backwards for throttle. For safety, you must press the [Start Vehicle] / [Stop Vehicle] toggle button to enable control.

Further DonkeyCar docs on driving

Training your car

Once you are driving your car confidently around a track, it is time to acquire training data for the Neural Network. DingoCar operates at 10 frames per second, capturing a 160x120 image, along with steering angle and throttle value. This is all stored in the $HOME/ohmc_car/data/tub_$DATE directory.

Before training, clean out previous data. Don't remove all the files in the tub/ directory: the tub/meta.json file is important.

Perform the same commands as for manual driving:

  • ssh pi@$IP_ADDRESS
  • cd ohmc_car
  • python manage.py drive

Then via the web browser press the [Start Recording] button, drive the car around a track, then press the [Stop Recording] button.

It is recommended that you collect between 5K and 20K frames. At 10 frames per second, that is between 500 and 2,000 seconds of driving (6-33 minutes). Practically speaking, you can get away with 5-10 minutes. Make sure that you drive clockwise and anti-clockwise! Just like a human: the more practice in different conditions you can give your car in training, the better it will drive for itself.

When finished acquisition, then transfer the data from the DingoCar to your laptop / desktop for training the Neural Network.

  • First ssh into your car and create a tarball of your data for easier transfer
    • tar czvpf tub_$DATE.tgz ohmc_car/data/tub_$DATE/
  • Then, on your computer, copy the data from your car, back to your computer.
    • If you're using google colab, you can just copy the data to any directory you'd like to use.
    • scp -pi@<car_ip>:tub_$DATE.tgz .

Once training data has been copied to your laptop / desktop, you can begin training the Neural Network. You can train your data on Google Colab, or on your local environment.

Google Colab instructions

This is convenient because it's fast, doesn't require a big setup time on your local computer, and gives you more time playing with your car and less time dealing with installation and configuration. Also, if you don't have a GPU, it's significantly faster using Google's computer power to generate the model than it is to do it on your own.

  • Log into your google account (or sign up on the spot)
  • Go to the google colab site
  • Click the 'Copy to Drive' button to make a copy for your own use.

Gcolab-copytodrive.jpg

The left hand panel has information, the right hand panel is where the operations happen. It's a sequence of steps that you can run, and modify. The sequence of instructions walks you through uploading your data from your car to your google drive account, then running it through the colab machine learning model generator. Every time the web session ends, your session on Google colab also ends and you need to restart operation from the top.

Click on each instruction to execute it.

Gcolab-execute.jpg

Once a command has been run, it shows the output.

Gcolab-afterexecute.jpg

Remember your data file you copied off your car? You need to upload it to your Google drive. The Google colab script expects the tub data to be in a directory on GDrive called mycar.

Once you've finished the script and copied the .h5 file back into your Google Drive, you can get it back down to your laptop and from there, onto your car.

  • scp mypilot.h5 pi@<IP_ADDRESS>:ohmc_car/models/model_$DATE.hdf5

Further DonkeyCar info on training

Training on your computer

If you'd like a local build environment on your computer, check out our quickstart guide, or use the detailed and thorough instructions on the DonkeyCar website.

Further DonkeyCar info on training

Letting your car drive itself!

Once your trained model has been copied back onto the DingoCar, your car can be self-driven as follows:

  • python manage.py drive --model ~/ohmc_car/models/model_$DATE.hdf5

This works similar to the manual driving mode with the addition of a trained model that can either:

  1. User: Manual control of both steering and throttle
  2. Local Angle: Automatically control the steering angle
  3. Local Pilot: Automatically control both the steering angle and throttle amount

The web browser provides a drop-down menu to select between these options.

It is recommended to just start with "Local Angle" and control the throttle manually with the "i" key (faster) and "k" key (slower).

What next?

To connect to your car when you leave LCA, you want to be able to join it onto other networks. It's a good idea to configure it to talk to your phone's hotspot, so that you can access your car anywhere. Run raspi-config which will bring up a UI from which you can add more networks.

A DingoCar is for life, not just for the OHMC at LCA. There's so much more you can do with it. Check out our Beyond DingoCar section.

There's extensive DonkeyCar documentation if you're looking for more detailed installation or configuration instructions.


Background information

Software installation: Raspberry Pi

Your DonkeyCar (Raspberry Pi) is already pre-installed. This section is for reference only.

Extensive DonkeyCar documentation

  • sysctl -w net.ipv6.conf.all.disable_ipv6=1 # Reconnect via ssh afterwards
  • sysctl -w net.ipv6.conf.default.disable_ipv6=1
  • apt-get update
  • apt-get upgrade
  • apt-get install -y vim git mosquitto-clients
  • apt-get install -y virtualenv build-essential python3-dev gfortran libhdf5-dev libatlas-base-dev libopenjp2-7-dev libtiff5
  • apt-get install -y i2c-tools
  • 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 -- -- -- -- -- -- --
  • mv env env.donkeycar
  • virtualenv env -p python3
  • pip install tensorflow==1.8.0
  • pip install adafruit-pca9685
  • pip install picamera

rPi reboots and Auto-starting donkeycar without logging in

If your rPi reboots when you're driving, check the following things:

  1. did you swap the servo wires between steering and power. Turn the ESC off, unplug one servo wire, turn the ESC back on (little toggle switch), and test steering. Make sure that steering does not activate the wheel motors.
  2. is your battery low? are you accelerating too quickly?

Because the battery has a high internal resistance, if you demand a lot of power too quickly, the voltage on the battery drops enough that the rPi gets below its critical voltage (when you add the voltage drop from the voltage converter), and the rPi reboots.

To restart donkey server automatically, do the following on your car:

  • Add this to /etc/rc.local:

su - pi -c 'cd ~/ohmc_car; python manage.py drive &>/tmp/out' &

  • move 'source ~/env/bin/activate' from ~/.bashrc to ~/.profile

Steering and throttle calibration

To save time at the workshop, you won't need to calibrate your car's steering and/or throttle. However, you may get better results and can perform calibration when you have time.

DonkeyCar instructions on calibration