code powering the comma.ai panda
Go to file
Jason Young abdc41856b
Toyota: 2021+ RAV4 Prime (#2042)
* from @pd0wm commaai/panda#1841

* diff reduction: won't need the flag rename

* run tests with new DBC and new gas/brake messages

* toyota_secoc_car to global

* consolidate alt_brake_101

* consolidate alt_pcm_cruise_176

* consolidate alt_gas_pedal_116

* don't allow transmit/forward for 0x131 unless SecOC

* cleanup and todo

* diff reduction

* reorder by usage frequency

* test for no LTA actuation

* bump opendbc commit ref in Dockerfile

* gate SecOC variant on ALLOW_DEBUG

* tweak gating for MISRA

* mutation test hates lta_angle surviving various changes

* common rx checks styling

* don't allow short version of 0x2E5 for SecOC mode

* whitespace diff reduction

* secoc_car -> secoc

* fix comment typo

* retry CI

* missed a couple secoc_car -> secoc

* one big secoc/not-secoc block

* genuinely useful MISRA warning

* test both STEERING_LTA and STEERING_LTA_2

* comment labeling for STEERING_LTA_2 signals

* Update board/safety/safety_toyota.h

Co-authored-by: Shane Smiskol <shane@smiskol.com>

* STEERING_LTA and STEERING_LTA_2 consistency

* update gas/brake/cruise signal annotations

---------

Co-authored-by: Shane Smiskol <shane@smiskol.com>
2024-10-04 11:22:18 -07:00
.github/workflows safety mutation tests (#2040) 2024-09-25 21:56:09 -07:00
board Toyota: 2021+ RAV4 Prime (#2042) 2024-10-04 11:22:18 -07:00
certs Deprecate ESP (#592) 2020-08-26 15:37:50 -07:00
crypto CI: set PYTHONWARNINGS=error (#1323) 2023-04-02 09:33:35 -07:00
docs move this to commaai/neo 2023-12-09 14:54:16 -08:00
drivers update bash scripts to #!/usr/bin/env bash (#1987) 2024-08-26 17:25:15 -07:00
examples deprecate busTime (#1989) 2024-07-30 21:20:48 -07:00
python Toyota: 2021+ RAV4 Prime (#2042) 2024-10-04 11:22:18 -07:00
release update bash scripts to #!/usr/bin/env bash (#1987) 2024-08-26 17:25:15 -07:00
tests Toyota: 2021+ RAV4 Prime (#2042) 2024-10-04 11:22:18 -07:00
.gitignore safety mutation tests (#2040) 2024-09-25 21:56:09 -07:00
.pre-commit-config.yaml pre-commit: autoupdate hooks (#2051) 2024-10-01 10:14:12 -07:00
Dockerfile Toyota: 2021+ RAV4 Prime (#2042) 2024-10-04 11:22:18 -07:00
Jenkinsfile Add multiple pandas selector (#2015) 2024-09-24 16:37:23 -07:00
LICENSE initial commit 2017-04-06 18:11:36 -07:00
README.md compile libpanda with clang (#2041) 2024-09-25 20:14:12 -07:00
SConscript misra8.4: board/*.h (#2026) 2024-09-19 21:15:08 -07:00
SConstruct revert libpanda with clang (#2044) 2024-09-26 12:35:45 -07:00
__init__.py make uds and isotp general imports (#1998) 2024-08-16 23:01:54 -07:00
mypy.ini Same mypy checks as openpilot (#1233) 2023-02-11 12:25:13 -08:00
panda.png update readme graphics 2018-05-10 00:01:08 -07:00
pyproject.toml fix test_mutation.py performace (#2012) 2024-09-06 13:30:05 -07:00
setup.cfg Created python package and implemented industry best practices. 2017-06-14 12:00:04 -07:00
setup.py fix python setup (#2018) 2024-09-10 21:49:03 -07:00

README.md

Welcome to panda

panda tests panda drivers

panda speaks CAN and CAN FD, and it runs on STM32F413 and STM32H725.

Directory structure

.
├── 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

Safety Model

When a panda powers up, by default it's in SAFETY_SILENT mode. While in SAFETY_SILENT mode, the CAN buses are forced to be silent. In order to send messages, you have to select a safety mode. Some of safety modes (for example SAFETY_ALLOUTPUT) are disabled in release firmwares. In order to use them, compile and flash your own build.

Safety modes optionally support controls_allowed, which allows or blocks a subset of messages based on a customizable state in the board.

Code Rigor

The panda firmware is written for its use in conjunction with openpilot. The panda firmware, through its safety model, provides and enforces the openpilot safety. Due to its critical function, it's important that the application code rigor within the board folder is held to high standards.

These are the CI regression tests we have in place:

  • A generic static code analysis is performed by cppcheck.
  • In addition, cppcheck has a specific addon to check for MISRA C:2012 violations. See current coverage.
  • Compiler options are relatively strict: the flags -Wall -Wextra -Wstrict-prototypes -Werror are enforced.
  • The safety logic is tested and verified by unit tests for each supported car variant. to ensure that the behavior remains unchanged.
  • A hardware-in-the-loop test verifies panda's functionalities on all active panda variants, including:
    • additional safety model checks
    • compiling and flashing the bootstub and app code
    • receiving, sending, and forwarding CAN messages on all buses
    • CAN loopback and latency tests through USB and SPI

The above tests are themselves tested by:

  • a mutation test on the MISRA coverage
  • 100% line coverage enforced on the safety unit tests

In addition, we run the ruff linter and mypy on panda's Python library.

Usage

Setup dependencies:

# Ubuntu
sudo apt-get install dfu-util gcc-arm-none-eabi python3-pip libffi-dev git clang-17

# macOS
brew install --cask gcc-arm-embedded
brew install python3 dfu-util gcc@13

Clone panda repository and install:

git clone https://github.com/commaai/panda.git
cd panda

# install dependencies
pip install -e .[dev]

# install panda
python setup.py install

See the Panda class for how to interact with the panda.

For example, to receive CAN messages:

>>> from panda import Panda
>>> panda = Panda()
>>> panda.can_recv()

And to send one on bus 0:

>>> panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
>>> panda.can_send(0x1aa, b'message', 0)

Note that you may have to setup udev rules for Linux, such as

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

The panda jungle uses different udev rules. See the repo for instructions.

Software interface support

As a universal car interface, it should support every reasonable software interface.

Licensing

panda software is released under the MIT license unless otherwise specified.