Difference between revisions of "Tesla"

From comma wiki
Jump to: navigation, search
Line 162: Line 162:
|2013 s 60
|2013 s 60

Revision as of 18:29, 27 September 2018

Welcome to the Tesla Openpilot Wiki!

We're just getting started filling this out, so feel free to jump in and help document things that need to be here.

This port is currently focused on bringing Openpilot to Teslas from 2014 and earlier, before Autopilot was offered.

Status of Latitudinal control (steering)

OpenPilot latitudinal control is working.

Electronic steering is present in pre-autopilot Teslas, but disabled. The Electric Power Assisted Steering units (EPAS) are capable of turning the steering wheel electronically if fed the right commands. With that in mind, we run a cable from the car's EPAS unit in the frunk to a comma.ai Panda. It allows us to:

  1. Intercept messages the car periodically sends that disable the EPAS' steering feature.
  2. Transmit steering commands from a comma.ai EON to the EPAS unit.

This setup allows the car to steer autonomously.

Status of Longitudinal control (accelerator and brakes)

Longitudinal control is an ongoing effort. These cars lack electronic pedal control and radar.

As of October 2018 we have working software-only Adaptive Cruise Control. Community members are working on more reliable hardware solutions.

Distance detection technique Advantage Disadvantage
Software - Use the EON's computer vision No additional cost Experimental and less precise than radar
Hardware - Install a radar unit High accuracy Expensive ($x00)
Speed control technique Advantage Disadvantage
Software - Adjust the cruise control speed No additional cost Weak braking, jerky acceleration
Hardware - Install electrically controllable pedals Full braking and smooth acceleration Expensive ($x00)
Hardware - Install a comma.ai Pedal proxy smooth acceleration, cheap ($x0) Experimental, not appropriate for brakes.

Adaptive Cruise Control

ACC allows the car to match speed with cars in front of you. The EON judges distances using the camera and dynamically adjusts cruise control speed. There are plenty of downsides to this strategy. The distance estimates are inaccurate. It only operates above 18 mph. The speed changes are not very smooth. And it can't handle sudden slowdowns so YOU MUST BE READY TO MANUALLY BRAKE AT ANY MOMENT. But it works without any new radar/pedal hardware.


Follow these steps to use ACC:

  1. Press the cruise stalk IN so that the orange "cruise control ready" LED on the stalk is lit.
  2. Enable the ACC option on screen if necessary.
  3. Accelerate above 18 MPH.
  4. Enable OpenPilot using a DOUBLE stalk pull (pull the cruise control stalk BACKWARDS TWICE in quick succession.) You will see the blue 'Cruise' icon appear on your dash. ACC is now active.
  5. The initial max speed may be conservative. Press UP on the stalk to increase it.
  6. Cruise is disabled if you brake or the car slows below 18 MPH.
  7. If ACC "AUTO" mode is enabled, manually accelerate above 18 MPH to resume.

Controls while ACC is enabled:

Control Action
Cruise stalk IN Master toggle for cruise control. Must be engaged for cruise or ACC to work.
Cruise stalk DOUBLE PULL Enable OP ACC and steering, and increase the max allowed ACC speed if necessary.
On screen ACC button Toggle between "FOLLOW" and "AUTO" mode. FOLLOW mode attempts to match speed with cars in front of you and disengages if you steer or brake. AUTO mode does the same, but automatically re-engages when you accelerate again.
Cruise stalk UP Increase cruise speed, increasing max allowed ACC speed if necessary.
Cruise stalk DOWN Decrease cruise speed and max allowed ACC speed.
Cruise stalk PUSH Disable OpenPilot (both steering and ACC). Max allowed ACC speed is reset to 0.
Brake pedal Pause both ACC and traditional cruise.
Accelerator (When in AUTO mode) Accel over 18 MPH to unpause ACC.

Community ToDo List

  • Need a writeup of creating the wiring harness for EPAS bypass
  • Need a writeup of installing the wiring harness
  • Need to compare comma code with ours, regarding continue.sh / launch_openpilo.sh / launch_chffr.sh so that on reboot it fetches our repo (auto update). Not all users want to ssh in to update
  • Open source giraffe hardware
  • Code change to OP port to auto flash panda
  • Add longitudinal control (this is a much larger issue than 1 bullet point)
  • Further testing of EPAS enable spamming
  • Have more Teslas using OP than any other car!!! :)
count Confirmed Users with Working OP Vehicle
1 Kalud 2013 S P85
2 zax123 2013 S P85
3 Bobby 2012 S P85
4 SteveRadich 2013 S 85
5 BogGyver 2014 S 85
6 RobP 2013 S P85
7 Edgar 2012 S P85
8 JJ 2013 S P85+
9 David Abrahams (Git:AllWashedOut) 2013 S 60
10 Shane Thomas 2013 S P85+
Enough Users for Bounty to be claimed!
11 sergiociba 2013 s 60
12 Bentis 2014 S P85+
13 Moc 2014 S 85
14 Sid 2014 S 85
15 MarcMarin 2013 S 85
16 FlyBoyn222pa 2013 S 85
17 BastyJuice 2013 S 85

Here's what you'll need to get OpenPilot working on your pre-AP Tesla

  • Panda (white $99, grey $199)
    • Grey Panda includes high accuracy GPS which OpenPilot may use for more accurate steering in the future. White panda won't work starting with OP 0.6, so Grey Panda is strongly recommended.
  • Custom Giraffe and Wiring harness for the Model S.
    • There are 2 variations based on your car manufacture date (before or after May 31, 2013). If you are unsure, check if the OBD connector in your driver footwell is the newer style with metal contacts for pins 1 and 9
    • Contact @appleguru in the #tesla channel on the comma slack to arrange purchase.
    • Approximately $50 in parts for the giraffe, $10 for a case, and $25 in parts for the harness. Will cost more after assembly and shipping

Total price of parts is approximately $1,000.

Instructions to set it all up

This first video walks you through the physical installation of parts from start to finish.

  • Make sure your Eon is up to date This will bring you to the latest version of OpenPilot and update your EON to the latest version of NEOS. If you have problems they aren't Tesla related, check the other wiki / slack places.
  • Install Panda on Giraffe OBDII port (driver footwell)
  • Run the 10 foot USB cable from the EON along your headliner, down the driver side A-Pillar, and down to the Panda
  • Connect EON to Panda via USB cable
  • Install custom tesla branch of OpenPilot on your EON by doing the following:
cd /data
mv openpilot openpilot.stock
git clone https://github.com/jeankalud/openpilot.git
cd openpilot
git checkout tesla
  • Update your Panda while SSH'ed in and Panda connected to ODB port and EON connected to Panda via USB (perhaps) - automated soon - Do we need to do this without data on bus?
cd /data/openpilot/panda/board
  • This is what it should look like for a successful flash. If you get something very different that has an error, check the connectivity between the EON and the Panda. Unplug it all and re-seat all the connections on Panda and giraffe.
root@localhost:/data/openpilot/panda/board$ cd /data/openpilot/panda/board;make                                    
PYTHONPATH=../ python -c "from python import Panda; Panda().flash('obj/panda.bin')"
opening device 41001d000651363038363036 0xddcc
opening device 41001d000651363038363036 0xddee
flash: version is v1.1.2-unknown-DEBUG
flash: unlocking
flash: erasing
flash: flashing
flash: resetting
opening device 41001d000651363038363036 0xddcc
  • If you're having trouble with the Panda not flashing correctly, here's a few things to try:
Power cycle the Panda by unplugging it from the giraffe and reseating it again.

Run these commands on the EON to try and flash the Panda:

cd /data/openpilot/panda/board
killall boardd
make clean

  • Once Panda is successfully flashed, you need to reboot EON again (WHILE the EON is connected to panda via USB).
  • Once everything is set up and working, you'll need to drive for 20-30 minutes above 45mph to complete calibration.
  • Once you're done with calibration, OP can be activated by one pull of the cruise stalk toward you. This is independent of whether the Tesla cruise control is turned on or not.


First Troubleshooting steps:

  • If you're getting power steering errors after flashing panda, make sure you reboot EON while it's connected to Panda via USB
  • Try a different USB cable (a shorter one, or one with EMI filter)
  • Make sure you're using the correct tesla repo
  • run make in /data/openpilot/panda/board
  • make sure CAN-H and CAN-L are not reversed.
  • make sure there is a 120 ohms resistor across CAN-H and CAN-L going to the EPAS (power steering)
  • if using a custom harness ensure these:
    • car CAN on panda port 1 (first port)
    • EPAS CAN on last on port 3 (last one)
  • If everything looks correct (right code, right wiring, right everything), you can always try: Shutdown car ("Power Off" in car settings), wait a few sec and try again.
  • If you've broken your source control (wrong git command, etc) you can always backup/check out from scratch:
cd /data
mv openpilot openpilot.bak
git clone https://github.com/jeankalud/openpilot
cd openpilot
git checkout tesla
cd panda/board
make clean
sleep 5 # (Skip this if running commands individually.)
make recover
  • If you are getting a message about having to recalibrate or re-position the EON, do this:
rm /data/params/d/CalibrationParams

How to change to the development branch of the Tesla OP port

Here's the commands to run on your EON to switch to the tesla_devel branch of the code

cd /data/openpilot
git fetch
git checkout tesla_devel
cd /data/openpilot/panda/board

How to transfer files to your EON

Sometimes while testing or debugging issues you may want to manually transfer files to your EON. One easy way to do this is to use the popular FTP client Filezilla.

  1. Enable SSH. Click on "Settings" in OpenPilot and make sure the "Enable SSH" option is turned on.
  2. Next find the ip address of your EON. Under Settings > Wifi settings > Advanced (click on the 3 dots in the upper right hand corner) scroll all the way to the bottom to find IP. (Make sure your EON is on the same wifi as your computer)
  3. Create a file called openpilot.ppk and save the text at the bottom of this section in it.
  4. In Filezilla, go to your Site Manager and create a new entry for your EON and enter the IP address you found in the Host field. The port is 8022. The protocol should be SFTP. Logon Type will be "Key File". User is "root". Key file is the file you just created. Then hit connect.

If you're having issues connecting, check to make sure you can ping your device on the IP you found. If ping doesn't work, then SSH won't either. You can try turning wifi off and then on again if you can't connect.

All the settings listed above can be used to connect via PuTTY as well for command line access. You specify the keyfile in the settings under Connection -> SSH -> Auth -> Private key for authentication

PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: imported-openssh-key
Public-Lines: 6
Private-Lines: 14
Private-MAC: 2af7f5a599fa35e22392b7770a2eb7a0be8718b7

Editing your Bash Profile

In order to edit the .bash_profile on the EON, first you have to move your the home directory by typing


Then, you have to mount the file system in Read/Write mode by typing

mount -o rw,remount /system

At this point you can edit your .bash_profile file by typing

vi .bash_profile

First, locate the PYTHONPATH line and delete it. Then, at the end of your file, paste the following code

# add these symlinks if you want
export PYTHONPATH="/data/openpilot"
export GIT_SSH_COMMAND="ssh -i /data/gitkey"
cd /data/openpilot/selfdrive/car/tesla
alias cdo='cd /data/openpilot'
alias cdt='cd /data/openpilot/selfdrive/car/tesla'
alias cdp='cd /data/openpilot/panda/board'
alias sop='grep -rni --include=\*.{py,h,c} /data/openpilot/ -e '
alias mrw='mount -o rw,remount /system'
alias dbp='python /data/openpilot/panda/tests/debug_console.py | grep -v "can_push failed"'
alias vic='vi /data/openpilot/selfdrive/car/tesla/carcontroller.py'
alias vii='vi /data/openpilot/selfdrive/car/tesla/interface.py'
alias vit='vi /data/openpilot/selfdrive/car/tesla/teslacan.py'
alias vis='vi /data/openpilot/selfdrive/car/tesla/carstate.py'
alias viu='vi /data/openpilot/selfdrive/ui/ui.c'
alias lop='cd /data/openpilot;./launch_openpilot.sh'
alias gp='git commit; git push'
alias sp='/data/data/com.termux/files/continue.sh'

Save the profile and you're done! If you contribute code, you might also at this point want to configure your git to save your username and password. To do that you just to a push when you still have the file system in RW mode ( or you can use the *mrw* command later to make it RW)

$ git config credential.helper store
$ git push https://github.com/repo.git
Username: <type your username>
Password: <type your password>
$ git push https://github.com/repo.git
[your credentials are used automatically]

Keep in mind the credentials are stored in


in plain text. They are in the format


where *user@email.com* is your username and *pass* is your password. So you can also just edit that file and modify as needed. Just replace *@* with *%40* in your email address. Now, about those shortcuts above:

mrw - make read / write - makes the file system writeable
sop - search OpenPilot - searches the whole OP structure for the keyword that follows - example: sop user_brake
sp - starts OpenPilot after you killed it with tmux -a
dbp - debug panda - launches the debugger for panda
gp - git commit and push - if you saved your credentials this makes commit and push so easy; just add your comment and you're done
cdt - change directory to /data/openpilot/selfdrive/car/tesla folder; this is also the folder when you will now start every time you ssh into your EON
cdo - change directory to /data/openpilot
cdp - change directory to /data/openpilot/panda/board
vic - starts vi for /data/openpilot/selfdrive/car/tesla/carcontroller.py from any folder
vii - starts vi for /data/openpilot/selfdrive/car/tesla/interface.py from any folder
vis - starts vi for /data/openpilot/selfdrive/car/tesla/carstate.py from any folder
vit - starts vi for /data/openpilot/selfdrive/car/tesla/teslacan.py from any folder```

Script to auto delete files to keep EON from filling up

This script comes courtesy of @Sid

Save the following script and run it on your EON. It will install into a cron job a script that checks every hour to see if you're almost full and delete the oldest files if necessary.


Aligning your EON

What you need

  • Measuring tape
  • Masking tape
  • A friend to help


  1. Find a place at the bottom of the windshiled along the driver side pilar that has a similar position on the passenger side (I used the place where the corner of the front hood meets the fender).
  2. With the tape starting from that point, mark 3 places along the side of the windshiled. Use the endge of the masking tape to mark them. I personally used 3" from the bottom, the top of the windshield and then about 1/3 from the bottom, 2/3 from the top. It does not matter what the measuring tape says, as long as it says the SAME distance on both sides.
  3. Repeat the process on the other side of the windshiled, ensuring you mark the same spots.
  4. measure the distance between one edge of the windshield and the other end, keeping the tape at each pair of marked points from before. use masking tape to mark the middle of the windshield. again, use the EDGE of the tape, not the center.
  5. Now use a long piece of masking tape to mark the center of the windshield from top to bottom. This (if you did everything correctly) will cover all 3 of your markers from before and provide a straight line. One edge of the masking tape is now the perfect middle of the windshild. Your mount will have to be aligned with that for a perfect position.
  6. Take a small piece of tape and mark the middle of the GoPro mount. use a slighly longer piece that the go-pro (maybe 1/4-1/2" more on each side) and ensure it is straight and down the middle of the GoPro. If, when looking from inside of the car, your take is to the RIGHT of the center, then put the tape on the LEFT side of the GoPro. Reverse if the other way.
  7. Using your EON without the mounting braket, determine the location along the center of the windshield where you want it placed.make sure the grove on the support is alongside the center of the windshield. use a small piece of maksing tape to mark the upper part of the position where you want your EON to be.
  8. Remove the RED protective tape from the back of the 3M adhesive and be ready to place the GoPro on the windshiled. Align the masking tape we placed on the GoPro mount on the inside with the masking tape we have on the outside of the windshield. They shoud not overlap at all AND you should not see light either. when you are confident on the position press hard on the mount.
  9. Remove all masking tape. You are done. You now have a perfectly centerd, perfectly vertical EON.

Placeholder for pedal instructions

Guide to flashing the pedal

Best way to flash it is to connect pedal straight to EON, go to panda/board/pedal and just type

make recover

Most of the action is happening in the #tesla channel on the comma slack: https://comma.slack.com

Current Tesla branch URL: https://github.com/jeankalud/openpilot/

Some background info on the tesla port: http://openpilot.robertcotran.com/

Last known safe Tesla software update version: 2018.26


AntiLock Braking System, iBooster - a component that allows brakes to applied via electronic control, Electronic Stability Program. These are parts of the automatic braking system that are found on AP1 and later cars. Using EON to control brakes is not feasibly possible on pre-AP Teslas. There has been some talk of upgrading AP0 Teslas to have this hardware, but this is a major undertaking and requires root access.
AP, AP0, AP1, AP2, AP2.5
Tesla AutoPilot. AP0 or pre-AP means no AutoPilot. AP1 is the version 1 using Mobileye technology. AP2 ditched the Mobileye components and is all Tesla parts and software. AP2.5 is upgraded AP2 hardware.
Comma's system for playing back and showing the recorded data from uploaded drives.
Controller Area Network This is a network system inside cars that allow messages to be sent to different auto components. With the Giraffe/Panda/EON setup described above, the Panda's CAN bus 0 is for chassis messages and CAN bus 2 is for the isolated EPAS. The Panda proxies messages between the two (except for the EPAS kill message which is blocked.)
Chassis Can
Steering and braking controls are found on this CAN-bus, so this is the main one that OP uses.
Driver assistance system - the AP1 camera/computer module located behind the windshield on AP1 hardware cars
DataBase Container These are files that contain the definitions of the messages cars send on the CAN-bus.
Diag, Diag port
Diagnostic port that can be found under the MCU (screen) in a Tesla. Chassis-CAN is able to be accessed from this port.
Double Pole Double Throw. It's a type of switch that some use in their wiring harness.
Main hardware component that Comma sells. It's the brains that runs OpenPilot.
Electronic Power (Assisted) Steering. This component allows OP to move the steering wheel.
Process of installing software on embedded hardware.
Piece of hardware that allows the Panda to interface with the OBD port in the car.
Instrument Cluster. The screen behind the steering wheel that has the speedometer on a Tesla.
Lane Keeping Assist System. System built into cars to automatically steer to keep the car in the current lane.
Media Control Unit - The big screen in a Tesla.
Mid Range Radar. Modern cars use radar units to see objects around the car. Pre-AP Teslas don't have any radar units.
MS, MX, M3
Model S, Model X, Model 3. The current Tesla lineup.
The predecessor to the EON. A customized OnePlus3 phone with a custom hardware board attached that also can run OpenPilot.
The operating system softare that runs on the EON.
OnBoard Diagnostics This is a port in the driver footwell that would normally provide emissions diagnostics on most cars, but is useless for that on Teslas. For Teslas built after May 31, 2013, Chassis CAN-bus is able to be accessed from this port.
Piece of Comma hardware that plugs into the OBD port to access the Chassis CAN-bus to send steering and braking messages from OpenPilot running on the EON.
Printed Circuit Board
Powertrain Control Module. This component basically tells the car how much power to put out to make the car go.
PR, pull request, merge
Pull requests or merge refers to a request to integrate code written by others to be "pulled" into the OpenPilot software maintained by Comma.
Repo, git repo
Repository where software is stored. The code for the Tesla version of OpenPilot currently sits in a different repo than the main OpenPilot code.
root, root access
Process of gaining access into the Tesla sofware system at a root level that allows access internal diagnostic not normally available and also allows for changes to be made to the Tesla software.
Steering Column Control Module - This component is part of the steering column and controls all the messages sent from the buttons on the steering wheel as well as the cruise control stalk.
State Of Charge. The percent of power left in your car's battery pack.
Secure SHell - a method of connecting to your EON in order to be able to make changes to it and issue commands for it to run.