Metadata-Version: 2.4
Name: delibot
Version: 0.1.0
Summary: Raspberry Pi client library for the Delibot STM32 motor controller UART protocol
License: Apache-2.0
Project-URL: Homepage, https://github.com/delibot/Delibot-Controller-RPi-Library
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyserial>=3.5
Dynamic: license-file

# Delibot-Controller-RPi-Library

Raspberry Pi Python client for the Delibot STM32 motor controller's UART protocol (`USART2`, 115200 8N1, `App/Src/rpi_link.c` / `host_commands.c` in [Delibot-Controller](https://github.com/delibot/Delibot-Controller)).

## Install

```bash
pip install delibot
```

or from source:

```bash
pip install -e .
```

## Usage

```python
from delibot import DelibotController, Param

with DelibotController("/dev/ttyAMA0") as robot:
    robot.set_velocity(linear_mm_s=300, angular_mrad_s=0)

    telemetry = robot.telemetry
    if telemetry is not None:
        print(telemetry.yaw_deg, telemetry.left_wheel_mm_s, telemetry.motors_on)

    track_width = robot.get_param(Param.WHEEL_TRACK_WIDTH_MM)
    robot.set_param(Param.WHEEL_TRACK_WIDTH_MM, 210.0)
    robot.save_params()

    ticks = robot.get_encoder_ticks()
    robot.zero_encoders()

    robot.stop()
```

`set_velocity` is kept alive internally by a background heartbeat thread, so the STM32's 500 ms deadman watchdog (`RPI_LINK_TIMEOUT_MS`) never trips between calls — call it once per desired speed change, not on every control-loop tick.

`telemetry` is updated asynchronously from a background reader thread at the firmware's 50 Hz push rate; pass `on_telemetry=` / `on_debug=` callbacks to `DelibotController` to react to updates and firmware debug prints as they arrive instead of polling the property.

## Protocol

- Frame: `SOF(0xFF) LEN CMD PAYLOAD... CRC`, `CRC = CMD ^ PAYLOAD[0] ^ ... ^ PAYLOAD[n-1]`.
- No sequence numbers or NACKs on the wire — request/response calls (`get_param`, `get_encoder_ticks`, `get_crsf_channels`, `ping`) apply a client-side timeout (`DelibotTimeoutError`) instead.
- See `src/delibot/protocol.py` for the full command and parameter ID tables.
