|
nros C API
Lightweight ROS 2 client for embedded real-time systems
|
See Error Codes for the full rcl_ret_t table with cause and recovery for each return code.
Messages pass through multiple buffer layers. A message must fit every layer to be delivered intact:
| Layer | Env var | Posix default |
|---|---|---|
| Defragmentation | NROS_ZENOH_FRAG_MAX_SIZE | 65536 |
| Batch size | NROS_ZENOH_BATCH_UNICAST_SIZE | 65536 |
| Shim buffer | NROS_SUBSCRIBER_BUFFER_SIZE | 1024 |
For large messages, increase the transport limits (set before building) and the receive class, NROS_SUBSCRIBER_BUFFER_SIZE:
After changing any buffer variable, clean the build cache:
zenoh-pico and zenohd must be the same version. Symptoms: z_publisher_put failed: -100 (_Z_ERR_TRANSPORT_TX_FAILED) followed by -73 (_Z_ERR_SESSION_CLOSED).
The router is the one ROS ships: ros2 run rmw_zenoh_cpp rmw_zenohd. nano-ros vendors none (RFC-0075), and the old build-zenohd recipe was retired with the vendored copy.
git submodule update --init packages/rmw/zenoh/zpico-sys/zenoh-pico. Never --recursive on nano-ros — the transitive closure is large and mostly irrelevant to any one task. nros setup <board> --rmw zenoh provisions it for you, shallow, and is the preferred route.CMakeCache.txt and rebuild. For Cargo-based builds, run cargo clean -p zpico-sys then rebuild.The C API stores pointers to structs passed during initialisation (e.g., rcl_publisher_t, rcl_subscription_t). These structs must not be moved after initialisation. Use static or heap-allocated storage:
All callbacks passed to the nros C API must use the C calling convention. In mixed C/C++ projects, declare callbacks as extern "C":
| Code | Name | Meaning |
|---|---|---|
| -3 | _Z_ERR_TRANSPORT_OPEN_FAILED | Cannot connect to router |
| -73 | _Z_ERR_SESSION_CLOSED | Session closed after failure |
| -78 | _Z_ERR_SYSTEM_OUT_OF_MEMORY | Allocation failed |
| -100 | _Z_ERR_TRANSPORT_TX_FAILED | Transport transmission failed |
| -128 | _Z_ERR_GENERIC | Generic error |
The rcl_ret_t return values map to:
| Value | Constant | Meaning |
|---|---|---|
| 0 | RCL_RET_OK | Success |
| -1 | RCL_RET_ERROR | Generic error |
| -2 | RCL_RET_TIMEOUT | Operation timed out |
| -7 | RCL_RET_NOT_INIT | Object not initialised |
| -10 | RCLC_RET_PUBLISH_FAILED | Publish failed |