sunnypilot Documentation

repository·master·Indexed 21 days ago

https://github.com/sunnypilot/sunnypilot

An open-source driver assistance system based on a fork of comma.ai's openpilot. Documentation covers the cereal messaging system (pub/sub using Cap'n proto), coordinate reference frames and transformations, ONNX network visualization, and the sunnylink Settings UI management via YAML source files.

Tokens
39.7K
Snippets
77
Records
195
Agent score
84%

What's inside sunnypilot

  1. Overview of sunnypilot

    master
    sunnypilot is an open-source driver assistance system that is a fork of comma.ai's openpilot. It provides a unique driving experience for over 300 supported car makes and models by offering modified behaviors for driving assist engagements. While it provides enhanced features, it aims to comply with comma.ai's safety rules as closely as possible.
  2. Overview of openpilot tools directory structure

    master

    The tools/ directory contains various utilities for interacting with openpilot, including visualization, simulation, and hardware control:

    • cabana/: View and plot CAN messages from drives or in realtime.
    • camerastream/: Cameras stream over the network.
    • joystick/: Control your car with a joystick.
    • lib/: Libraries to support the tools and reading openpilot logs.
    • plotjuggler/: A tool to plot openpilot logs.
    • replay/: Replay drives and mock openpilot services.
    • scripts/: Miscellaneous scripts.
    • serial/: Tools for using the comma serial.
    • sim/: Run openpilot in a simulator.
    • webcam/: Run openpilot on a PC with webcams.
  3. What is sunnypilot/openpilot?

    master

    sunnypilot (based on openpilot) is an open source driver assistance system. It provides several Advanced Driver Assistance System (ADAS) functions, including:

    • Adaptive Cruise Control (ACC): Manages vehicle speed and following distance.
    • Automated Lane Centering (ALC): Assists with steering to keep the vehicle in its lane.
    • Forward Collision Warning (FCW): Alerts the driver to potential frontal collisions.
    • Lane Departure Warning (LDW): Alerts the driver if the vehicle drifts from its lane.
    • Driver Monitoring (DM): A camera-based feature that alerts distracted or asleep drivers while the system is engaged.

    The system works by utilizing the car's existing APIs for its built-in ADAS and providing improved acceleration, braking, and steering inputs compared to the stock system.

  4. Overview of Cabana

    master
    Cabana is a tool designed for viewing raw CAN data. It is primarily used for creating and editing CAN Dictionaries (DBC files). It features direct integration with commaai/opendbc, allowing users to load DBC files directly from the source and save changes to their own forks. Additionally, Cabana can load routes directly from comma connect.
  5. Identify supported vehicles for sunnypilot

    master
    A supported vehicle is defined as one that provides a seamless experience when a comma device is installed, offering improved performance compared to the stock system. Unless otherwise specified, all supported vehicles refer to the US market.
  6. Debug controls with joystick_control

    master

    The joystick_control tool allows you to connect a laptop to a comma device over a network to debug vehicle controls using a joystick or a keyboard. It uses the inputs library to support various gamepads and joysticks.

    Prerequisites:

    • A device running openpilot.
    • A laptop.
    • A joystick (optional).
    • Crucial: The car must be off and openpilot must be offroad before starting joystick_control.
  7. Safety requirements and driver responsibilities for sunnypilot

    master

    sunnypilot is an Adaptive Cruise Control (ACC) and Automated Lane Centering (ALC) system. It is a failsafe passive system and requires the driver to be alert and attentive at all times.

    Key Safety Principles:

    • Driver Alertness: Driver alertness is necessary but not sufficient for safe use. sunnypilot includes driver monitoring to alert when distraction is detected.
    • Manual Control: The driver must always be able to immediately retake manual control by stepping on the brake pedal or pressing the cancel button.
    • Trajectory Constraints: The vehicle must not alter its trajectory too quickly for the driver to react. Actuators are constrained to operate within reasonable limits (observing ISO11270 and ISO15622, such as limiting lateral actuation to 0.9 seconds for a 1m lateral deviation).

    Disclaimer: sunnypilot is provided with no warranty of fitness for any purpose.

  8. Orientation Conventions for Euler Angles and Quaternions

    master

    sunnypilot uses Quaternions, rotation matrices, and Euler angles.

    Euler Angles

    • Convention: [roll, pitch, yaw] corresponding to rotations around [x, y, z] axes.
    • Units: Always use radians or radians/s (except for display/plotting).
    • Rotation Order: To rotate from one frame to another, rotate around roll, then pitch, then yaw, using intrinsic rotations (rotating around the rotated axes, not the original axes).

    Quaternions

    • Convention: Hamilton notation [qw, qx, qy, qz].
    • Requirements: All quaternions must be normalized and have a strictly positive qw to ensure a unique representation of orientation.
  9. Differentiate between Brand Ports and Model Ports

    master

    When porting openpilot to a new vehicle, the complexity depends on whether you are introducing a new brand or a new model within an existing brand.

    • Brand Port: A port to a substantially new car brand or a new platform within an existing brand. This is more complex as the architecture and APIs are unknown.
    • Model Port: A port to a new car model within an already supported brand. These are generally easier because the car's existing APIs and communication structures are already known to the system.
  10. Define reusable rules using Macros

    master

    You can define reusable rule fragments in settings_ui_src/_macros.yaml and reference them in your page YAML files. This is useful for common constraints like offroad_only or platform-specific gates.

    Defining a Macro

    In _macros.yaml:

    macros:
      offroad: [{type: offroad_only}]
      longitudinal: [{type: capability, field: has_longitudinal_control, equals: true}]

    Referencing a Macro

    In a page YAML file, use the {$ref: "#/macros/<name>"} syntax within an enablement array:

    enablement:
      - {$ref: "#/macros/offroad"}
      - {$ref: "#/macros/longitudinal"}

    Constraints:

    • The compiler splices the macro's list into the parent list.
    • Macros can reference other macros up to a depth of 3.
    • Circular references will cause a compiler error.
    macros:
      offroad: [{type: offroad_only}]
      longitudinal: [{type: capability, field: has_longitudinal_control, equals: true}]
    
    enablement:
      - {$ref: "#/macros/offroad"}
      - {$ref: "#/macros/longitudinal"}
  11. Pick a writability rule for settings

    master

    When defining settings in the sunnylink UI, you must choose an enablement rule to determine when a parameter can be modified. This prevents unsafe changes while the vehicle is in motion.

    RuleWhen to useBehavior
    offroad_onlyMost user-facing toggles. Use when a parameter can only be safely changed when the car is parked.Strictest. Frontend shows a "device is driving" badge and disables the row.
    not_engagedUse for items that must be applied mid-drive (e.g., test maneuvers, longitudinal stock-vs-OP toggle).Less strict. Param can be changed while the car is started but only when sunnypilot/MADS is not actively driving.
    param-basedWhen behavior depends on another setting's value (e.g., a parent toggle or mode selector).Composes with not/any/all for arbitrary logic.
    capability-basedWhen behavior depends on the connected car or device (brand, longitudinal, hardware).Resolved on the device from CarParams or hardware.
    (no rule)Rare. Use only if a parameter is genuinely safe to flip mid-drive.Param is always writable, no gating.

    Default for new toggles: enablement: [{$ref: "#/macros/offroad"}].