> ## Documentation Index
> Fetch the complete documentation index at: https://motorbridge.seeedstudio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C Examples Overview

## Channel Compatibility (PCAN + slcan + CAN-FD + Damiao Serial Bridge)

* Linux SocketCAN uses interface names directly: `can0`, `can1`, `slcan0`.
* For USB-serial CAN adapters, bring up `slcan0` first: `sudo slcand -o -c -s8 /dev/ttyUSB0 slcan0 && sudo ip link set slcan0 up`.
* Hexfellow examples require CAN-FD path (`motor_controller_new_socketcanfd(...)` / CLI `--transport socketcanfd`).
* Damiao-only serial bridge transport is also available in CLI (`--transport dm-serial --serial-port /dev/ttyACM0 --serial-baud 921600`).
* Full Damiao serial-bridge interface list and command patterns are documented in `motor_cli/README.md` (section `3.6` in `motor_cli/README.zh-CN.md`).
* On Linux SocketCAN, do not append bitrate in `--channel` (for example `can0@1000000` is invalid).
* On Windows (PCAN backend), `can0/can1` map to `PCAN_USBBUS1/2`; optional `@bitrate` suffix is supported.

Direct C demos for `motor_abi`.

> Chinese version: [README.zh-CN.md](/zh/source/examples/c/overview)

## Files

* `c_abi_demo.c`: unified demo for Damiao + RobStride
* `hexfellow_canfd_demo.c`: Hexfellow CAN-FD demo (`mit` / `pos-vel` only)

Vendor coverage:

* Damiao: `enable`, `disable`, `mit`, `pos-vel`, `vel`, `force-pos`
* RobStride: `ping`, `enable`, `disable`, `mit`, `pos-vel`, `vel`, `read-param`, `write-param`
  * note: torque/current is parameter-level only (`write-param` on `iq_ref`/limits), not a unified high-level mode
* Hexfellow (CAN-FD only): `mit`, `pos-vel`

## Build

```bash theme={null}
cargo build -p motor_abi --release
cc examples/c/c_abi_demo.c -I motor_abi/include -L target/release -lmotor_abi -o c_abi_demo
cc examples/c/hexfellow_canfd_demo.c -I motor_abi/include -L target/release -lmotor_abi -o hexfellow_canfd_demo
LD_LIBRARY_PATH=target/release ./c_abi_demo --help
```

## Examples

Damiao MIT:

```bash theme={null}
LD_LIBRARY_PATH=target/release ./c_abi_demo \
  --vendor damiao --channel can0 --model 4340P --motor-id 0x01 --feedback-id 0x11 \
  --mode mit --pos 0 --vel 0 --kp 20 --kd 1 --tau 0 --loop 50 --dt-ms 20
```

RobStride ping:

```bash theme={null}
LD_LIBRARY_PATH=target/release ./c_abi_demo \
  --vendor robstride --channel can0 --model rs-06 --motor-id 127 --mode ping
```

RobStride read position parameter:

```bash theme={null}
LD_LIBRARY_PATH=target/release ./c_abi_demo \
  --vendor robstride --channel can0 --model rs-06 --motor-id 127 \
  --mode read-param --param-id 0x7019 --param-type f32
```

The examples use `rs-06` only as a sample model. Use the RS model you use for limits/logging; runtime parameter IDs and types come from the common section 4 table.

RobStride low-gain MIT:

```bash theme={null}
LD_LIBRARY_PATH=target/release ./c_abi_demo \
  --vendor robstride --channel can0 --model rs-00 --motor-id 2 \
  --mode mit --pos 0.5 --vel 0 --kp 20.0 --kd 0.5 --tau 0 --loop 100 --dt-ms 20
```

Hexfellow (CAN-FD only):

```bash theme={null}
LD_LIBRARY_PATH=target/release ./hexfellow_canfd_demo \
  --channel can0 --motor-id 0x01 --feedback-id 0x00 --mode mit --loop 20 --dt-ms 50
```
