Runner and command packages
Needs first: Organize a larger workspace
You want nros to do something it does not ship: run an image on a launcher
or flasher nano-ros has no runner for, or add a verb of your own, such as a
generator your team runs on every workspace. Both are ordinary packages in
your workspace, built for the host by nros build, with no change to
nano-ros. By the end of this page, nros run drives your runner, or
nros <verb> runs your command.
Before you start
- You have a workspace with a
src/directory thatnros buildbuilds. - The Rust scaffolds build with the host’s Rust toolchain. A C++ package
speaks the same protocol through its own CMake executable: pass
--lang cpptonros new.
Runner packages
A runner teaches nros run, nros flash and nros monitor to drive a
launcher, a flasher or a console: an emulator nano-ros does not know, a
vendor flash tool, a remote board farm.
-
Scaffold the runner, from the workspace root:
nros new my_runner --kind runnernros new: scaffolded runner package `my_runner` at src/my_runnerThe package holds:
package.xml, whose<nano_ros_provides kind="runner" name="my_runner"/>announces the runner;nros-runner.toml, whatnrosreads when this runner is selected:protocol, theverbsit serves (run,flash,monitor), what itneedsfrom the build (elf, …) and thebinthe build produces;src/main.rs, a stub on thenros-extensioncrate that answersdescribeand runs the plan’selfas a host process, as the built-in native runner does. A test in it holdsdescribeequal tonros-runner.toml.
-
Replace
runinsrc/main.rswith what your target needs.nros runresolves a plan and executes your binary as<bin> run --plan <plan.json>;nros-extensionreads the plan, checks the verb and hands you its artifacts and arguments. -
Build it:
nros build --packages-select my_runner -
Select it for an image in the bringup’s
system.toml, then run the image:[image.my_image.run] method = "my_runner"nros run my_imageA runner that serves
flashis selected the same way, with[image.<id>.flash] method. A board can name it once for every image, in its descriptor’s[board.flash] method: which method words exist is the answer of the installed runners, sonroschecks only their shape.
Command packages
A command adds a verb to nros. A verb nros does not know is looked up as
an announced command package.
-
Scaffold the command, from the workspace root:
nros new my_cmd --kind commandnros new: scaffolded command package `my_cmd` at src/my_cmdThe package holds a
package.xmlannouncing<nano_ros_provides kind="command" name="my_cmd"/>, annros-command.tomlwith the command’sprotocol,summary,tierandbin, and asrc/main.rsthat prints its arguments and environment.tier = "user"lists the verb innros help --all. -
Write the command in
src/main.rs.nros my_cmd <args>runs your binary with the arguments unchanged, and with three variables set:NROS_WS_ROOT(the workspace),NROS_TOOLCHAIN(the toolchain’s version) andNROS_CLI(the runningnros). Ask"$NROS_CLI"for facts rather than deriving them again. Your exit status isnros’s. -
Build it, and run it:
nros build --packages-select my_cmd nros my_cmd hello worldnros my_cmd: hello world workspace /home/me/my_ws toolchain 0.6.0 (/home/me/.nros/bin/nros) -
Check that
nroslists it. Put a real sentence insummaryfirst:nros help --allExtension commands (from packages): nros my_cmd TODO: say what `nros my_cmd` does (package my_cmd)A package that announces a built-in verb, such as
build, is refused.
Example
nano-ros’s own extension commands are command packages, and their help is in the CLI reference:
nros px4 msgs, from the packagenros_px4_tools, generatespx4_msgsbindings from a PX4 message tree (PX4).nros router config, from the packagenros_zenoh_tools, prints the zenoh router configuration a bringup’s router runs (Configure zenoh).
If it doesn’t work
nros my_cmdreports that the command is not built. The package is announced but its binary is missing. Runnros build --packages-select my_cmd.nros runcannot use the runner. The image’s[image.<id>.run] methodnames a word no built runner announces, or the runner’snros-runner.tomldoes not list the verb (run,flash,monitor).- The runner fails on a missing artifact. The plan carries only what
needslists. Add the artifact (elf,bin,hex, …) toneeds.
See also
- CLI reference: every built-in verb, so you can pick a name that does not collide.
- Add a board:
[board.run]and[board.flash], which name a runner for every image of a board.
Design background
- RFC-0119: CLI extension packages: runner and command packages
- RFC-0118: target execution model: the plan a runner receives (D5)