Skip to content

berickson/car

Repository files navigation

Orange Crash - Self Driving RC Car

This is my personal project to add autonomous capabilities RC cars.

The Cars

Orange Crash

avatar

  • Traxxas Slash 2wd
  • Sensored motor
  • ELP 1.0 Stereo camera
  • Rasberry PI Model 4
  • Hall effect quadrature encoded front wheel sensors
  • Teensy 3.2
  • MPU-9250 IMU

Blue Crash

avatar

  • Traxxas Slash 2wd
  • Sensored motor
  • Neato Lidar
  • Rasberry PI Model 3
  • Hall effect quadrature encoded front wheel sensors
  • Teensy 3.5
  • MPU-9150 IMU
  • Tough looking metal roll cage

Software

The cars expose web servers, and the main control is through a web application using a mixture of Nginx, Flask, and AngularJS.

UI, image processing, path recording and following are handled by the Rasberry PI. The server logic is primarily in C++. I originally tried doing the high level logic in Python, but found C++ was a better fit. You can find the Raspbery Pi code in the cpp folder.

The Teensy microcontroller communicates with the ESC, servo, IMU and quadrature encoders. The microcontroller code is in the teensy folder.

Raspberry PI Setup

  1. Start with a new Raspberry Pi 4 w/4GB RAM and a Samsung EVO Plus 32GB SD Card

  2. Download and Raspbian Buster Lite image (released 2019-09-26)from https://www.raspberrypi.org/downloads/raspbian

  3. Use Balena Etcher to extract the Raspian image onto the SD card

  4. Before placing in Pi, mount the card (click mount button next to boot in explorer) and create the file ssh in the boot folder

    touch /media/$USER/boot/ssh
  5. Eject and remove SD card from PC

  6. Insert SD card, connect PI to your router with an Ethernet cable

  7. Plug USB3 power into the PI to boot it

  8. Find the Pi IP address by going to your router, in my case I go to http://192.168.1.1/ and connected devices are shown in "My Network"

  9. SSH into the Pi

    ssh pi@{ip_address} # the password is raspberry
  10. To SSH without a password, on your Host PC, execute "ssh-keygen" then copy the contents of your Host PC's ~/.ssh/id_rsa.pub into file ~/.ssh/authorized_keys on the Pi.

  11. In the Pi SSH session, launch raspi-config

    sudo raspi-config

    Use the raspi-config menu system to configure the hostname (for me it's orange-crash),

    locale en_US.UTF-8 UTF-8
    timezone US / Pacific Ocean
    hostname {robot name}
    password {you pick}
    WiFi US / {home SSID} / {password}

    finally, expand the file system to take up all of the 32GB on your SD card. Save and reboot.

  12. SSH into the Pi, you should no longer need to use your password.

  13. On the PI, create an SSH key to use with GitHub

    ssh-keygen -t rsa -b 4096 -C "{your email}"

    On GitHub, authorize your pi user by copying the contents of the Pis .ssh/id_rsa.pub to an authorized key

  14. Disable swap on Pi. You don't need it with 4G Pi and you can avoid corrupting your flash.

    sudo systemctl disable dphys-swapfile.service
  15. Setup Wifi to use alternate hotspots

    sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
    

    Replace wpa_supplicant contents with the following (or add whatever networks you need), don't forget to set the passwords

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    country=US
    
    network={
        ssid="EH656"
        psk="**********" # put password here
        id_str="home"
    }
    
    network={
        ssid="BkePixel3"
        psk="***********" # put password here
        id_str="hotspot"
    }
    
  16. Install a few things on the Pi

    sudo apt update
    sudo apt upgrade
    sudo apt install ffmpeg vlc streamer git libncurses5-dev screen nginx
    sudo apt install libeigen3-dev  libblas-dev liblapack-dev git
    
    
  17. Set which robot you are working, default Python environment. Add this to .bashrc

    source activate car
    

    add the following to (new file) /etc/environment

    ROBOT=orange # current valid values are orange or blue
    
  18. Clone this repo

    git clone git@github.com:berickson/car.git
  19. install eigen 3.? library into /home/pi/car/cpp/eigen3/Eigen

  20. Install and config Python Anaconda (miniconda)

    wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh
    /bin/bash Miniconda3-latest-Linux-armv7l.sh
    # notes: install to /home/pi/miniconda3, prepend path[yes]
    
    
    

    ensure following added to end of your .bashrc

    export PATH="/home/pi/miniconda3/bin:/home/pi/car/bin:$PATH"
    export ROBOT=orange
    

    exit and resume ssh

    conda config --add channels rpi
    conda create --name car python=3.5
    
    
    source activate car
    conda install pandas
    conda install flask
    pip install psutil platformio
    
    
  21. Set up your 49-teensy-rules

    sudo su
    cd /etc/udev/rules.d
    wget https://www.pjrc.com/teensy/49-teensy.rules
    exit
    

    Add the following line to the end of 49-teensy.rules

    # added by brian, adds symlink /dev/teensy4317960 to read coms
    ATTRS{idVendor}=="16c0", , ATTRS{idProduct}=="04[789B]?", MODE:="0777",SYMLINK+="teensy$attr{serial}",GROUP="users"
    
  22. Configure baud rate for lidar (if applicable)

    stty -F /dev/teensy12345 115200
    
  23. Download and compile OpenCV (this will take a while)

    cd car
    time bash ./cv3_install.sh

Hacking

car-web

install and update with

cd car/web
sh ./install

view log

sudo journalctl -u car-web -f

run from console to debug

cd car/web
sudo systemctl stop car-web
./run

car-service

download uploads and build with

cd car/cpp
upgrade

Install service with

cd car/web
sh ./install

view log

sudo journalctl -u car -f

teensy