2020-08-09 21:56:16 -07:00
# Welcome to panda
2017-04-06 18:11:36 -07:00
2017-06-28 22:20:38 -07:00
[panda ](http://github.com/commaai/panda ) is the nicest universal car interface ever.
2017-04-06 18:11:36 -07:00
2021-11-08 14:12:48 -08:00
<a href="https://comma.ai/shop/products/panda-obd-ii-dongle"><img src="https://github.com/commaai/panda/blob/master/panda.png?raw=true"></a>
2017-04-06 18:56:25 -07:00
2020-08-26 15:37:50 -07:00
It supports 3x CAN, 2x LIN, and 1x GMLAN. It also charges a phone. On the computer side, it has USB.
2017-04-06 18:11:36 -07:00
2020-08-26 15:37:50 -07:00
It uses an [STM32F413 ](http://www.st.com/en/microcontrollers/stm32f413-423.html?querycriteria=productId=LN2004 ).
2017-04-06 18:11:36 -07:00
2020-08-22 19:21:11 -07:00


2017-11-12 18:31:25 -05:00
2020-08-09 21:56:16 -07:00
## Usage
2023-04-12 19:22:19 -04:00
Setup dependencies:
2022-11-17 11:46:43 -08:00
```bash
# Ubuntu
2023-04-11 22:38:02 -04:00
sudo apt-get install dfu-util gcc-arm-none-eabi python3-pip libffi-dev git
2023-04-12 19:22:19 -04:00
```
```bash
2022-11-17 11:46:43 -08:00
# macOS
2023-05-12 11:06:08 -07:00
brew install --cask gcc-arm-embedded
brew install python3 dfu-util gcc@12
2022-11-17 11:46:43 -08:00
```
2023-04-12 19:22:19 -04:00
Clone panda repository:
2020-08-09 21:56:16 -07:00
``` bash
2022-09-15 10:24:36 +02:00
git clone https://github.com/commaai/panda.git
cd panda
2023-04-12 19:22:19 -04:00
```
Install requirements:
```bash
pip install -r requirements.txt
```
Install library:
``` bash
2022-09-15 10:24:36 +02:00
python setup.py install
2017-06-20 15:40:34 -07:00
```
2021-06-16 23:37:34 -05:00
See [the Panda class ](https://github.com/commaai/panda/blob/master/python/__init__.py ) for how to interact with the panda.
2017-04-06 18:23:26 -07:00
For example, to receive CAN messages:
2020-08-09 21:56:16 -07:00
``` python
2017-06-20 11:30:35 -07:00
>>> from panda import Panda
2017-04-06 18:28:59 -07:00
>>> panda = Panda()
2017-04-06 18:23:26 -07:00
>>> panda.can_recv()
```
2017-04-06 18:28:59 -07:00
And to send one on bus 0:
2020-08-09 21:56:16 -07:00
``` python
2017-04-06 18:28:59 -07:00
>>> panda.can_send(0x1aa, "message", 0)
```
2021-06-16 23:37:34 -05:00
Note that you may have to setup [udev rules ](https://github.com/commaai/panda/tree/master/drivers/linux ) for Linux, such as
2020-08-09 21:56:16 -07:00
``` bash
2020-01-05 12:38:45 -08:00
sudo tee /etc/udev/rules.d/11-panda.rules <<EOF
SUBSYSTEM=="usb", ATTRS{idVendor}=="bbaa", ATTRS{idProduct}=="ddcc", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="bbaa", ATTRS{idProduct}=="ddee", MODE="0666"
EOF
sudo udevadm control --reload-rules && sudo udevadm trigger
2019-09-25 10:55:46 -04:00
```
2022-05-12 00:42:21 -04:00
The panda jungle uses different udev rules. See [the repo ](https://github.com/commaai/panda_jungle#udev-rules ) for instructions.
2020-08-09 21:56:16 -07:00
## Software interface support
2017-06-25 23:01:41 -07:00
As a universal car interface, it should support every reasonable software interface.
2022-11-17 11:46:43 -08:00
- [Python library ](https://github.com/commaai/panda/tree/master/python )
- [C++ library ](https://github.com/commaai/openpilot/tree/master/selfdrive/boardd )
2018-07-12 10:08:34 -07:00
- [socketcan in kernel ](https://github.com/commaai/panda/tree/master/drivers/linux ) (alpha)
- [Windows J2534 ](https://github.com/commaai/panda/tree/master/drivers/windows )
2017-06-25 23:01:41 -07:00
2020-08-09 21:56:16 -07:00
## Directory structure
2017-04-06 18:11:36 -07:00
2021-06-21 13:54:09 -07:00
```
.
├── board # Code that runs on the STM32
├── drivers # Drivers (not needed for use with python)
├── python # Python userspace library for interfacing with the panda
├── tests # Tests and helper programs for panda
```
2017-04-06 18:11:36 -07:00
2020-08-26 15:37:50 -07:00
## Programming
2017-04-06 18:11:36 -07:00
2020-08-26 15:37:50 -07:00
See `board/README.md`
2017-04-06 18:11:36 -07:00
2020-08-09 21:56:16 -07:00
## Debugging
2017-04-17 15:28:28 -07:00
2020-08-09 21:56:16 -07:00
To print out the serial console from the STM32, run `tests/debug_console.py`
2017-04-17 15:28:28 -07:00
2020-08-09 21:56:16 -07:00
## Safety Model
2017-07-17 10:48:16 -07:00
2020-07-22 10:38:08 +02:00
When a panda powers up, by default it's in `SAFETY_SILENT` mode. While in `SAFETY_SILENT` mode, the buses are also forced to be silent. In order to send messages, you have to select a safety mode. Currently, setting safety modes is only supported over USB. Some of safety modes (for example `SAFETY_ALLOUTPUT` ) are disabled in release firmwares. In order to use them, compile and flash your own build.
2017-07-17 10:48:16 -07:00
2019-09-27 17:15:34 -07:00
Safety modes optionally supports `controls_allowed` , which allows or blocks a subset of messages based on a customizable state in the board.
2020-08-09 21:56:16 -07:00
## Code Rigor
2021-06-21 13:54:09 -07:00
The panda firmware is written for its use in conjuction with [openpilot ](https://github.com/commaai/openpilot ). The panda firmware, through its safety model, provides and enforces the
2022-07-03 00:17:45 +01:00
[openpilot safety ](https://github.com/commaai/openpilot/blob/master/docs/SAFETY.md ). Due to its critical function, it's important that the application code rigor within the `board` folder is held to high standards.
2019-09-27 17:15:34 -07:00
2020-05-17 19:53:23 -07:00
These are the [CI regression tests ](https://github.com/commaai/panda/actions ) we have in place:
2020-08-09 21:56:16 -07:00
* A generic static code analysis is performed by [cppcheck ](https://github.com/danmar/cppcheck/ ).
* In addition, [cppcheck ](https://github.com/danmar/cppcheck/ ) has a specific addon to check for [MISRA C:2012 ](https://www.misra.org.uk/MISRAHome/MISRAC2012/tabid/196/Default.aspx ) violations. See [current coverage ](https://github.com/commaai/panda/blob/master/tests/misra/coverage_table ).
2021-06-21 13:54:09 -07:00
* Compiler options are relatively strict: the flags `-Wall -Wextra -Wstrict-prototypes -Werror` are enforced.
2019-09-27 17:22:13 -07:00
* The [safety logic ](https://github.com/commaai/panda/tree/master/board/safety ) is tested and verified by [unit tests ](https://github.com/commaai/panda/tree/master/tests/safety ) for each supported car variant.
* A recorded drive for each supported car variant is [replayed through the safety logic ](https://github.com/commaai/panda/tree/master/tests/safety_replay )
2019-09-27 17:15:34 -07:00
to ensure that the behavior remains unchanged.
2019-09-27 17:22:13 -07:00
* An internal Hardware-in-the-loop test, which currently only runs on pull requests opened by comma.ai's organization members, verifies the following functionalities:
2021-06-21 13:54:09 -07:00
* compiling the code and flashing it through USB.
* receiving, sending, and forwarding CAN messages on all buses, over USB.
2017-07-17 10:48:16 -07:00
2020-08-09 21:56:16 -07:00
In addition, we run the [pylint ](https://www.pylint.org/ ) and [flake8 ](https://github.com/PyCQA/flake8 ) linters on all python files within the panda repo.
2019-10-15 14:03:31 -07:00
2020-08-09 21:56:16 -07:00
## Hardware
2017-04-27 20:32:16 -07:00
2017-04-06 18:23:26 -07:00
Check out the hardware [guide ](https://github.com/commaai/panda/blob/master/docs/guide.pdf )
2020-08-09 21:56:16 -07:00
## Licensing
2017-04-06 18:11:36 -07:00
2017-04-06 18:53:43 -07:00
panda software is released under the MIT license unless otherwise specified.