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

Linux host

How-to · Level 2: Building real applications

Needs first: Run a talker on an emulated board, What you just built, Get started on the Linux host

Status: nros-board-linux (Linux): Verified on host (daily). From the board support registry; Board Support Levels explains the words.

The starter scaffolded a C++ talker for the Linux host, ran it as an ordinary process, and heard it from ROS 2 over Cyclone DDS. This page covers what comes after it: how the host image is configured, what is particular to the host board, how to read the plan nros run follows, and how to drive the native build yourself.

Use the host board for first experiments, for smoke tests in CI, and to check interoperability with ROS 2 before you move a node to a microcontroller. The node package you write here is the same one an embedded image builds: only the bringup’s image changes.

Configure the platform

The starter’s bringup, src/host_node_bringup/system.toml, holds one image:

[system]
name = "host_node"
rmw = "cyclonedds"
domain_id = 0

[image.linux]
board = "linux"

board = "linux" is what makes the image a host program. The RMW comes from [system] rmw, and an image can override it with its own rmw key. The choices on this board are cyclonedds, zenoh and xrce:

  • Cyclone DDS needs no daemon. A stock ROS 2 node with RMW_IMPLEMENTATION=rmw_cyclonedds_cpp on the same machine and domain discovers the image directly, which is why the starter uses it.
  • zenoh dials a router. The image’s default locator is tcp/127.0.0.1:7447, the port ROS’s rmw_zenohd listens on, and nros run starts that router before the node and stops it after. Provision the backend first with nros setup linux --rmw zenoh.
  • XRCE-DDS talks to a Micro-XRCE-DDS agent, which nros setup linux --rmw xrce installs.

Pick and configure the RMW walks through a switch, and Configure an image lists every key an image takes.

A host image reads four settings from the environment when it starts, so the same binary can join another domain or another router, or run under another name, without a rebuild:

ROS_DOMAIN_ID=0
NROS_LOCATOR=tcp/127.0.0.1:7447
NROS_NODE_NAME=my_talker
NROS_NODE_NAMESPACE=/robot1

The first two replace the image’s domain_id and locator. The other two apply to the image’s nodes, including nodes named in code or by a launch file:

  • NROS_NODE_NAMESPACE replaces the namespace of every node. A node that stated a different namespace gets one warning at start.
  • NROS_NODE_NAME renames the node only when the image states that it creates exactly one. nros build states the count, as [image] node_count in the files it generates. The rename prints one warning that names the old and the new name.
  • With two or more nodes, NROS_NODE_NAME is ignored, since one name can’t name them all, and a notice says so. An image whose count is unstated, such as one built without nros build, ignores it with a notice too. Name each node in system.toml, or with a launch remap, instead.

A launch file’s remaps keep applying to a renamed node.

An embedded image has no environment. Its domain and locator are compiled in from its image’s domain_id and locator keys, and its nodes keep the names the image gives them.

Board notes

  • The board is named linux because Linux is all it supports. The platform layer under it is POSIX, but the board pins a sched task to a CPU with sched_setaffinity and cpu_set_t, which macOS, Windows and FreeBSD lack. No other spelling names this board: an image or a nros new --board that uses one is refused with a hint naming linux.
  • The image is a host process. It uses the host’s sockets and network stack, and its console is the process’s standard output. There is no emulator and nothing to flash.
  • One board crate covers both the host and the POSIX family driver, so a sched task, a timer or a socket behaves here as it does on any POSIX system.
  • The scaffolded examples are copy-out ready. Nothing in a workspace names a path into the SDK: nros finds its own, and --nano-ros-path names another.

Read the run plan

Before it starts anything, nros run resolves a run plan: what launches the image, where its console appears, and how its middleware reaches the rest of the system. Print it for the starter’s talker, from the workspace root:

nros run host_node --dry-run --why

--dry-run prints the plan instead of carrying it out, and --why adds where each fact came from: the command line, the image, your machine’s bench file, the board’s descriptor, or the runner’s defaults. For this board the plan has no emulator: the target is a host process, its console is standard output, and its link is the image’s RMW over the host’s own network.

Drive the native build yourself

nros build writes the generated entry and its build settings under build/, then runs CMake (for a C or C++ node) or cargo (for a Rust node) on them. To see the exact native commands without building:

nros build --dry-run

Use the printed lines to build from an IDE or a CI step of your own. Never edit what nros build writes under build/: the next build regenerates it. A workspace that lives inside a colcon workspace builds with colcon build, and source install/setup.bash then puts its executables on ros2 run’s path.

Deploy on a Linux machine

Host deployment is ordinary process deployment. Copy the executable nros build printed, or install the colcon workspace, onto the target machine, set ROS_DOMAIN_ID and, for zenoh, NROS_LOCATOR, and start it under the service manager you already use. For a zenoh image, run the router on that machine or name a reachable one in NROS_LOCATOR. The checklist in Deploy to production applies unchanged.

If it doesn’t work

  • nros run stops at once and names the router: the image uses zenoh and rmw_zenohd is not on the path. Source ROS 2 and install ros-<distro>-rmw-zenoh-cpp, or pass --router <locator> to use a router you already run.
  • ROS 2 hears nothing: the ROS 2 shell’s RMW_IMPLEMENTATION or ROS_DOMAIN_ID differs from the image’s rmw and domain_id.
  • Everything else: Troubleshoot.

Reference

Design background