What is cereal?
mastermsgq and handles data serialization using Cap'n proto.repository·master·Indexed 21 days ago
https://github.com/sunnypilot/sunnypilotAn 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.
msgq and handles data serialization using Cap'n proto.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.sunnypilot (based on openpilot) is an open source driver assistance system. It provides several Advanced Driver Assistance System (ADAS) functions, including:
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.
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.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:
joystick_control.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:
Disclaimer: sunnypilot is provided with no warranty of fitness for any purpose.
sunnypilot uses Quaternions, rotation matrices, and Euler angles.
[roll, pitch, yaw] corresponding to rotations around [x, y, z] axes.[qw, qx, qy, qz].qw to ensure a unique representation of orientation.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.
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.
In _macros.yaml:
macros:
offroad: [{type: offroad_only}]
longitudinal: [{type: capability, field: has_longitudinal_control, equals: true}]In a page YAML file, use the {$ref: "#/macros/<name>"} syntax within an enablement array:
enablement:
- {$ref: "#/macros/offroad"}
- {$ref: "#/macros/longitudinal"}Constraints:
macros:
offroad: [{type: offroad_only}]
longitudinal: [{type: capability, field: has_longitudinal_control, equals: true}]
enablement:
- {$ref: "#/macros/offroad"}
- {$ref: "#/macros/longitudinal"}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.
| Rule | When to use | Behavior |
|---|---|---|
offroad_only | Most 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_engaged | Use 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-based | When behavior depends on another setting's value (e.g., a parent toggle or mode selector). | Composes with not/any/all for arbitrary logic. |
capability-based | When 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"}].