Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Porting Overview

nano-ros is designed for customization at three independent levels: RMW (transport protocol), Platform (OS or RTOS), and Board (hardware). The core crates define stable interfaces through Rust traits. You extend nano-ros by implementing those traits for your target – you never modify the core.

Which chapter do I need?

I want to…Chapter
Add a new transport protocol (MQTT, DDS, custom)Custom RMW Backend
Port to a new RTOS or bare-metal targetCustom Platform
Bring up nano-ros on a new MCU boardCustom Board Package

Most porting work falls into the second or third category. Adding a new RMW backend is rare and substantially more involved.

What stays untouched

The following core packages define the interfaces you implement. They compile and work without modification for any new target.

PackageRole
nrosFacade crate: re-exports and feature-axis enforcement
nros-coreMessage, service, and action type traits
nros-serdesCDR serialization
nros-nodeExecutor, Node, pub/sub/service/action handles
nros-rmwRMW trait definitions (Session, Publisher, Subscriber, etc.)
nros-platformPlatform trait definitions and ConcretePlatform type alias
zpico-sys alias TUMaps zenoh-pico z_* C symbols to nros_platform_* (default-on platform-aliases)
nros-rmw-xrce alias TUMaps XRCE-DDS uxr_* C symbols to nros_platform_*
nros-c, nros-cppC and C++ API wrappers

These define the interfaces. You implement them; you do not modify them.

The customization boundary

Everything in nano-ros sits on one side of a trait boundary defined in nros-platform/src/traits.rs.

Above the boundary (yours to write): board crates, platform crates, peripheral drivers, and application code.

Below the boundary (fixed): RMW backends, shim crates, core library, executor, and serialization.

Your platform crate implements traits as inherent methods on a zero-sized type. The shim crates automatically forward RMW-layer C symbols to your implementation through the ConcretePlatform type alias – no dynamic dispatch, no generics propagation.

Platform trait requirements by RMW backend

Not every trait is required. The set depends on which RMW backend the application uses.

Traitzenoh-picoXRCE-DDS
PlatformClockRequiredRequired
PlatformAllocRequired (~64 KB heap)Not needed
PlatformSleepRequiredNot needed
PlatformRandomRequiredNot needed
PlatformTimeRequiredNot needed
PlatformThreadingRequired (multi-threaded platforms)Not needed
PlatformTcpRequiredNot needed
PlatformUdpRequiredNot needed
PlatformSocketHelpersRequiredNot needed
PlatformNetworkPollBare-metal onlyNot needed
PlatformUdpMulticastDesktop platforms onlyNot needed
PlatformLibcBare-metal onlyNot needed

XRCE-DDS is significantly simpler to port: it is single-threaded, heap-free, and uses user-provided transport callbacks rather than a full socket API. A minimal XRCE-DDS port requires only PlatformClock and four C function pointers (open, close, read, write).

zenoh-pico requires a complete platform implementation but provides richer functionality (peer-to-peer, scouting, zero-copy receive, actions).

Registration

After implementing the required traits, you register your platform with two changes:

  1. Add a platform-<name> feature to nros-platform/Cargo.toml that pulls in your crate as an optional dependency.
  2. Add a ConcretePlatform type alias in nros-platform/src/resolve.rs gated by that feature.

The shim crates pick up the new platform automatically. No changes to RMW backends or core crates are needed.

Existing platform implementations

These serve as reference when writing a new port.

Platform crateTargetThreadingNetworking
nros-platform-posixLinux, *BSDpthreadslibc BSD sockets
nros-platform-freertosFreeRTOSFreeRTOS taskslwIP
nros-platform-nuttxNuttXpthreadsPOSIX sockets
nros-platform-threadxThreadXThreadX threadsNetX Duo
nros-platform-zephyrZephyrZephyr POSIXZephyr sockets
nros-platform-mps2-an385Cortex-M3 bare-metalSingle-threadedsmoltcp
nros-platform-stm32f4STM32F4 bare-metalSingle-threadedsmoltcp
nros-platform-esp32-qemuESP32-C3 (QEMU) bare-metalSingle-threadedsmoltcp + OpenETH

Further reading