Difference between revisions of "Pedal Interceptor"

From Tinkla: Tinkering with Tesla
m (Flashing the firmware for Tesla Pedal)
Line 61: Line 61:
 
The firmware in my repo for the Tesla Pedal is located in the Panda repository under the [https://github.com/BogGyver/panda/tree/tesla_pedal tesla_pedal branch]. You can flash the pedal from your computer or from the EON. If you have a new board, it will automatically start in DFU mode. To know which mode you're in look at the LED: no light = DFU mode, slow blink = normal flash mode, fast blink = normal operations. Once you are on the latest based code (my repo), for any future code changes you can flash not over can by issuing a "make canflash" command. But first we need to get the base code there through a "make recover" command and having the pedal in DFU mode.
 
The firmware in my repo for the Tesla Pedal is located in the Panda repository under the [https://github.com/BogGyver/panda/tree/tesla_pedal tesla_pedal branch]. You can flash the pedal from your computer or from the EON. If you have a new board, it will automatically start in DFU mode. To know which mode you're in look at the LED: no light = DFU mode, slow blink = normal flash mode, fast blink = normal operations. Once you are on the latest based code (my repo), for any future code changes you can flash not over can by issuing a "make canflash" command. But first we need to get the base code there through a "make recover" command and having the pedal in DFU mode.
  
For this you will need to have your EON connected to the panda and a linux/mac laptop connected via a USB-A to USB-A cable to the pedal.
+
For this you will need to have your EON connected to the panda and a Linux/Mac laptop connected via a USB-A to USB-A cable to the pedal.
 +
If you have a Windows 10 Laptop, install [https://docs.microsoft.com/en-us/windows/wsl/install-win10 WSL (Windows Subystem for Linux)] and run the commands in there.
  
First, you need to get the code from the repo to both your computer and eon.
+
First, you need to get the code from the repo to both your computer and EON.
 
*For EON:
 
*For EON:
cd /data
+
: <source lang="bash">
git clone --depth 1 https://github.com/BogGyver/panda.git -b tesla_pedal
+
cd /data
cd panda/board/pedal
+
git clone --depth 1 https://github.com/BogGyver/panda.git -b tesla_pedal
*For Laptop, pick a location where you want the files to be downloaded then:
+
cd panda/board/pedal
git clone --depth 1 https://github.com/BogGyver/panda.git -b tesla_pedal
+
</source>
cd panda/board/pedal  
+
*For laptop, pick a location where you want the files to be downloaded then:
 +
: <source lang="bash">
 +
git clone --depth 1 https://github.com/BogGyver/panda.git -b tesla_pedal
 +
cd panda/board/pedal
 +
</source>
 +
: Also make sure you have Make, GCC, DFU Util and Python to be able to execute the build command on your laptop:
 +
: <source lang="bash">
 +
sudo apt update
 +
sudo apt install build-essential gcc-arm-none-eabi dfu-util python python-pip
 +
pip install crypto
 +
</source>
  
First, connet the USB from the Panda to the EON. We will kill the OP instance and then we will send the DFU command via CAN:
+
Then, connect the USB from the Panda to the EON. We will kill the OP instance and then we will send the DFU command via CAN:
  
tmux kill-session -t comma
+
<source lang="bash">
./enter_canloader.py --recover
+
tmux kill-session -t comma
 +
./enter_canloader.py --recover
 +
</source>
  
 
Now the LED should be off. Quickly connect the Pedal to the laptop ensureing that car does not go in Car Off mode. Once your laptop is connected to the pedal run the update command
 
Now the LED should be off. Quickly connect the Pedal to the laptop ensureing that car does not go in Car Off mode. Once your laptop is connected to the pedal run the update command
  
sudo make recover
+
<source lang="bash">
 +
sudo make recover
 +
</source>
  
 
Sometimes you have the issue the command on the laptop multiple times untill it completes successfully.
 
Sometimes you have the issue the command on the laptop multiple times untill it completes successfully.
Line 85: Line 100:
 
Once done, let car go off, reboot EON and you should be good to go.
 
Once done, let car go off, reboot EON and you should be good to go.
  
  In case of emergency, you can enter the DFU mode by applying 5 volts to a special point on the board while conencting the board to USB (to power it up). That usually requires at least 2 people: one to keep the jumper for 5V in place and the other to connect the USB. [https://medium.com/@jfrux/flashing-the-comma-pedal-with-ubuntu-a83fb668f6e2 Instructions on how to enter DFU mode] were create by @jfrux. Once in DFU mode, go to the pedal directory and run "make recover"
+
  In case of emergency, you can enter the DFU mode by applying 5 volts to a special point on the board while connecting the board to USB (to power it up). That usually requires at least 2 people: one to keep the jumper for 5V in place and the other to connect the USB. [https://medium.com/@jfrux/flashing-the-comma-pedal-with-ubuntu-a83fb668f6e2 Instructions on how to enter DFU mode] were create by @jfrux. Once in DFU mode, go to the pedal directory and run "make recover"
  
 
===  Installing the Tesla Pedal ===
 
===  Installing the Tesla Pedal ===

Revision as of 00:13, 6 September 2019

The Comma Pedal is used to provide acceleration and regen braking capability on Tesla cars running Openpilot that do not have iBooster installed.

Without electric brakes (iBooster) the car only uses regenerative braking. This is not enough for suddent slowdowns. YOU MUST BE READY TO MANUALLY BRAKE AT ANY MOMENT.
Pedal.jpg
Pedal board.jpg

The Comma Pedal is an accelerator pedal interceptor. It is a device that is inserted between a car's electronic accelerator pedal and the DU (Drive Unit). It detects the voltage from the accelerator pedal which represents the pedal's position. It then writes that same voltage back out to the DU as if the accelerator pedal had produced it.

When Openpilot is engaged, Openpilot sends the virtual acceleration position through the Comma Pedal instead. Comma Pedal receives these signals over the Giraffe's CAN3-EPAS.


What it Does

The Comma Pedal has 4 main systems:

  1. 2 Analog to Digital Convertors
    • This is used to read the voltage from the car's accelerator pedal into the Comma Pedal's processor. The accelerator pedal produces an output Voltage between 0 and 5 Volts.
  2. 2 Digital to Analog Convertors
    • This is used to send voltage back to the car's DU as if the accelerator pedal had produced it.
  3. 1 CAN Bus
    • The CAN Bus is the car's communication network. The Comma Pedal communicates with Openpilot using the CAN Bus. It connects to the Tesla Giraffe on CAN3.
  4. 1 USB
    • This is used to program and monitor the Comma Pedal, itself.

When Openpilot is NOT engaged, the Comma Pedal reads the voltage from the accelerator pedal and just passes it along to the DU.

When Openpilot IS engaged with longitudinal control, the Comma Pedal gets accelerator commands from Openpilot and emulates a accelerator pedal to the DU.

The Comma Pedal is constantly sending the physical accelerator pedal's position to the CAN bus for Openpilot to read.

Obtaining a Comma Pedal

You cannot buy a pre-built comma pedal from Comma. Fortunately there are other people in the community manufacturing and selling them:

Since they're currently always sold out as soon as new ones get in stock, you could also build it yourself (not recommended) or have one fabricated through a service like Macrofab.

Wiring a Tesla Pedal

In order to create your Tesla Pedal you need:

  • 1x Comma Pedal board (for sources see above section)
  • 1x box to hold the board if your Pedal doesn't already have a case (current ones ship with 3D printed cases). You will need to cut some small openings on the sides (and in front of the RJ45) if you use this one.
  • 1x set of WPT-929 connectors
  • ~3ft of wire for the connectors in case your Pedal and connectors don't come with them (~AWG24)
  • 1x SN-28B crimping tool (same one as used for EPAS cable - fast shipping, slow shipping)
  • EITHER 1x ethernet cable ~2ft (not crossover) for current gen Pedal and Tesla Giraffe (rev B) which have RJ45 ports
  • OR 1x JST2 male and 1x female connector plus some twisted pair wire if RJ45 is not present. You can buy this and cut it and you're done (not twisted but will work just fine)
Tesla pedal wiring.png

Use the diagram to connect the female WPT-929 pedal connector to the IN side of the pedal board and the male WSP-929 connector to the OUT side of the pedal connector.

Pedal connector.png

Pedal pinout.png


Pedal CAN connection.png

Connecting the CAN BUS from the Pedal to the Giraffe depends on your setup, as explained in the parts list above.

Via RJ45: Plug in the ethernet cable into the RJ45 port of the Pedal and the other end into the RJ45 port of the Giraffe that is labelled with "comma".
Via JST2: Solder positions 3 and 6 of the fake-ethernet port of the pedal board to the two JST2 connectors (male and female) with enough length to reach EPAS cable/Giraffe. We need both because you will plug the female one in the Giraffe's EPAS connector and then the EPAS Harness into the male JSP2. Red should be CAN+ and black should be CAN- (that's the convention also used in the image showing the CAN wire soldered to pins 3 and 6 of the fake ethernet port on the pedal board).


Flashing the firmware for Tesla Pedal

You have to use a Tesla specific firmware on the pedal in order to work for Tesla. 

The firmware in my repo for the Tesla Pedal is located in the Panda repository under the tesla_pedal branch. You can flash the pedal from your computer or from the EON. If you have a new board, it will automatically start in DFU mode. To know which mode you're in look at the LED: no light = DFU mode, slow blink = normal flash mode, fast blink = normal operations. Once you are on the latest based code (my repo), for any future code changes you can flash not over can by issuing a "make canflash" command. But first we need to get the base code there through a "make recover" command and having the pedal in DFU mode.

For this you will need to have your EON connected to the panda and a Linux/Mac laptop connected via a USB-A to USB-A cable to the pedal. If you have a Windows 10 Laptop, install WSL (Windows Subystem for Linux) and run the commands in there.

First, you need to get the code from the repo to both your computer and EON.

  • For EON:
cd /data
git clone --depth 1 https://github.com/BogGyver/panda.git -b tesla_pedal
cd panda/board/pedal
  • For laptop, pick a location where you want the files to be downloaded then:
git clone --depth 1 https://github.com/BogGyver/panda.git -b tesla_pedal
cd panda/board/pedal
Also make sure you have Make, GCC, DFU Util and Python to be able to execute the build command on your laptop:
sudo apt update
sudo apt install build-essential gcc-arm-none-eabi dfu-util python python-pip
pip install crypto

Then, connect the USB from the Panda to the EON. We will kill the OP instance and then we will send the DFU command via CAN:

tmux kill-session -t comma
./enter_canloader.py --recover

Now the LED should be off. Quickly connect the Pedal to the laptop ensureing that car does not go in Car Off mode. Once your laptop is connected to the pedal run the update command

sudo make recover

Sometimes you have the issue the command on the laptop multiple times untill it completes successfully.

Once done, let car go off, reboot EON and you should be good to go.

In case of emergency, you can enter the DFU mode by applying 5 volts to a special point on the board while connecting the board to USB (to power it up). That usually requires at least 2 people: one to keep the jumper for 5V in place and the other to connect the USB. Instructions on how to enter DFU mode were create by @jfrux. Once in DFU mode, go to the pedal directory and run "make recover"

Installing the Tesla Pedal

To install the pedal, there are two steps:

  1. connecting the board to the accelerator pedal
  2. connecting the board to the Tesla Giraffe

This video for a similar product shows you what you have to do in order to install the pedal interceptror between the accelerator pedal and the car existing connector. Take your time and watch the video first. The process is not complicated if you just follow it step by step.

Once that is complete, disconnect the EPAS cable from the Tesla Giraffe and connect the female JSP2 from your pedal to the Giraffe. Then connect the EPAS cable to the male JSP2 from your pedal.

Using the Tesla Pedal

Without electric brakes (iBooster) the car only uses regenerative braking. This is not enough for suddent slowdowns. YOU MUST BE READY TO MANUALLY BRAKE AT ANY MOMENT.

Out of the box, OP will use the Tesla CC (with stalk spamming) to control CC. This in our OP implementation is called Adaptive Cruise Control or ACC. CC on Tesla only works above 18 MPH (29 km/h).

If you turn off the Tesla CC by pressing on the CC stalk, OP will switch to Tesla Pedal (PDL) mode. This will also provide you with adaptive cruise control by sending the right commands to your Tesla Pedal. Tesla pedal works down to 1 MPH, but be careful, regen brakes stop working at 5 MPH (8 km/h).

Once you get used to it and you don't care about ACC anymore, you can modify the config file to always use pedal

force_pedal_over_cc = True

Guides for Building / Troubleshooting Your Comma Pedal

Comma Pedal: Updating the Firmware over CAN by @jfrux Use this guide to update your Comma Pedal for compatibility with Openpilot v0.5.10+

Comma Pedal: Building with MacroFab by @jfrux

Comma Pedal: Flashing the Firmware by @jfrux