Convert Figma logo to code with AI

commaai logopanda

code powering the comma.ai panda

1,615
869
1,615
66

Top Related Projects

PX4 Autopilot Software

25,797

An open autonomous driving platform

10,247

Autoware - the world's leading open-source software project for autonomous driving

Quick Overview

The commaai/panda repository is an open-source project for interfacing with car systems. It provides hardware and software solutions for reading and writing car data, primarily focused on enabling advanced driver assistance systems (ADAS) and autonomous driving research.

Pros

  • Open-source nature allows for community contributions and customization
  • Supports a wide range of vehicle makes and models
  • Provides both hardware and software solutions for comprehensive car interfacing
  • Enables advanced research and development in autonomous driving

Cons

  • May require technical expertise to set up and use effectively
  • Limited official support compared to commercial solutions
  • Potential legal and safety concerns when modifying car systems
  • May void vehicle warranties if not used carefully

Code Examples

# Initialize connection to the Panda
from panda import Panda
p = Panda()

# Read messages from the car's CAN bus
can_recv = p.can_recv()
for address, _, data, src in can_recv:
    print(f"Message from {src}: {hex(address)} - {data.hex()}")
# Send a message on the CAN bus
p.can_send(0x200, b"Hello", bus=0)
# Set safety mode (e.g., to allow certain operations)
from panda import Panda
p = Panda()
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)

Getting Started

  1. Install the Panda Python package:

    pip install pandacan
    
  2. Connect the Panda device to your computer via USB.

  3. Use the following code to establish a connection:

    from panda import Panda
    p = Panda()
    print("Connected to Panda")
    
  4. You can now use various methods to interact with the car's systems, such as can_recv(), can_send(), and set_safety_mode().

Competitor Comparisons

PX4 Autopilot Software

Pros of PX4-Autopilot

  • More comprehensive autopilot system for various types of vehicles (drones, rovers, etc.)
  • Larger community and ecosystem with extensive documentation
  • Supports a wider range of hardware platforms

Cons of PX4-Autopilot

  • Steeper learning curve due to its complexity
  • May be overkill for simpler automotive applications
  • Less focused on specific car integration compared to Panda

Code Comparison

PX4-Autopilot (C++):

void MulticopterPositionControl::control_position(const float dt)
{
    // Position control logic
    Vector3f pos_error = _pos_sp - _pos;
    Vector3f vel_sp = pos_error.emult(_params.pos_p) + _vel_sp;
    control_velocity(dt, vel_sp);
}

Panda (Python):

def update_controls(self):
    # Simple control update
    self.angle_steers = self.CS.angle_steers
    self.angle_steers_rate = self.CS.angle_steers_rate
    self.yaw_rate = self.CS.yaw_rate
    self.standstill = self.CS.standstill

The code snippets illustrate the difference in complexity and focus between the two projects. PX4-Autopilot deals with more advanced position control algorithms, while Panda focuses on simpler vehicle state updates.

25,797

An open autonomous driving platform

Pros of Apollo

  • Comprehensive autonomous driving platform with full-stack capabilities
  • Extensive documentation and community support
  • Supports various vehicle types and sensor configurations

Cons of Apollo

  • Higher complexity and steeper learning curve
  • Requires more computational resources
  • Less focused on specific hardware integration

Code Comparison

Apollo (C++):

void Planning::RunOnce(const LocalView& local_view,
                       ADCTrajectory* const trajectory_pb) {
  // Complex planning logic
  // ...
}

Panda (Python):

def update_panda():
  # Simple hardware interface
  # ...

Key Differences

  • Apollo is a full autonomous driving stack, while Panda focuses on vehicle interface
  • Apollo uses C++ for performance, Panda uses Python for simplicity
  • Apollo has a broader scope, Panda is more specialized for specific hardware

Use Cases

  • Apollo: Research and development of complete autonomous driving systems
  • Panda: Interfacing with vehicle CAN bus and developing ADAS features

Community and Support

  • Apollo: Large community, corporate backing, frequent updates
  • Panda: Smaller but active community, focused on open-source principles

Hardware Requirements

  • Apollo: Requires powerful computing hardware
  • Panda: Can run on simpler embedded systems
10,247

Autoware - the world's leading open-source software project for autonomous driving

Pros of Autoware

  • More comprehensive autonomous driving stack, including perception, planning, and control
  • Larger community and industry support, with contributions from multiple companies
  • Designed for full-scale autonomous vehicles, offering more advanced features

Cons of Autoware

  • Higher complexity and steeper learning curve
  • Requires more computational resources and hardware
  • Less focus on consumer-grade vehicles and retrofitting existing cars

Code Comparison

Panda (C):

void safety_rx_hook(CANPacket_t *to_push) {
  int bus = GET_BUS(to_push);
  int addr = GET_ADDR(to_push);
  
  if (bus == 0 && addr == 0x18DAF1D2) {
    // Process CAN message
  }
}

Autoware (C++):

void VehicleInterface::processCanMessage(const can_msgs::msg::Frame::SharedPtr msg) {
  if (msg->id == 0x18DAF1D2) {
    // Process CAN message
    vehicle_status_.updateFromCanFrame(*msg);
  }
}

Both repositories handle CAN messages, but Autoware's implementation is more object-oriented and uses ROS 2 message types.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Welcome to panda

panda speaks CAN and CAN FD, and it runs on the 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 for panda
├── scripts         # Miscellaneous used for panda development and debugging
├── examples        # Example scripts for using a panda in a car

Safety Model

panda is compiled with safety firmware provided by opendbc. See details about the car safety models, safety testing, and code rigor in that repository.

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:

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

Usage

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

# setup your environment
./setup.sh

# build fw + run the tests
./test.sh

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:

>>> from opendbc.car.structs import CarParams
>>> panda.set_safety_mode(CarParams.SafetyModel.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}=="0483", ATTRS{idProduct}=="df11", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="3801", ATTRS{idProduct}=="ddcc", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="3801", ATTRS{idProduct}=="ddee", MODE="0666"
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

Licensing

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