Expand description
Phase 212.L.5 — top-level init API; phase-427 W9 — on every target.
Re-exported flat at the crate root: nros::Context (alloc),
nros::ContextSource, nros::InitError, nros::InitOptions (every
target); nros::init(), nros::init_with_args(args) (env).
The env feature gates only the process-environment reader and the
argv entry; freestanding, Context::default_from_env() is the
bake (Context::baked()).
Phase 212.L.5 — top-level init API; phase-427 W9 — on every target.
Context is WHERE this image is connected — locator, domain, RMW,
session mode, and the source those came from (RFC-0089 “Context and
init, settled”). One per process or image; a resolved value, not an
entity on the graph. A Node is a named participant with its own
entities, and one image holds several of those on one Context
(RFC-0047).
§Where the values come from
- Hosted (feature
env): the process environment (ROS_DOMAIN_ID,NROS_LOCATOR,NROS_SESSION_MODE,NROS_RMW/RMW_IMPLEMENTATION) through the one hosted resolver,crate::env::try_resolve_hosted. A launcher projects per-node values into that environment before exec. - Freestanding (no
env): there is no process and no environment; the same values are BAKED at compile time —option_env!("NROS_LOCATOR")andoption_env!("NROS_DOMAIN_ID"), exported into this crate’s build bynros_zephyr_build::bake_nros_config()from Kconfig (build.rs), or present in the process environment of the build for the other RTOS lanes (the board crates read the same two names the same way). The semantics survive with the source moved from run time to build time: “the environment this image was built for or launched in”.
The env feature gates ONLY the process-environment reader and the
argv/launch entry points; Context, ContextSource, InitError,
InitOptions and Context::config compile on every target. The floor
for Context itself is alloc: locator and rmw are owned Strings
so the value outlives whatever transient produced it (an env cache, a
parsed launch file, a harness-supplied override).
§The rclrs family
Context::default_from_env, Context::from_env and (hosted only)
Context::new are the rclrs::Context constructors under the same
names; InitOptions is rclrs’s, with the one option it has. init() is
the C++-symmetric anchor (rclcpp::init) and equals default_from_env().
Two patterns are supported:
- Node pkg — register via the
nros::node!macro (Phase 172 W.3); the generated runtime owns the spin loop and builds itsContextthroughContext::default_from_env. - Application pkg — call
init()/Context::default_from_env(orinit_with_args/Context::newfor argv-style entry) and drive your own spin. The returnedContextcarries the domain id, locator and RMW choice from the environment — see “Where launch content comes from” below.
To actually open a session, call Context::create_executor (alloc) or
Context::create_executor_in (caller-supplied backing, nothing leaked),
then name each node with Executor::create_node. The older spelling —
materialise an crate::ExecutorConfig via Context::config and pass it
to Executor::open — still works and is what a single-node entry wants;
phase-427 W10 added the pair because it cannot express the second node.
§Where launch content comes from
Nothing here reads a launch file at run time. A launch tree reaches an
image at BUILD time: nros sync resolves it into the image’s SystemModel,
and the generated entry (nros::main!(launch = …),
nano_ros_entry(… LAUNCH …)) installs its node identities, remaps and
parameters. What is left for init to read is the environment
(ROS_DOMAIN_ID, NROS_LOCATOR, NROS_SESSION_MODE,
RMW_IMPLEMENTATION) and, through init_with_args / Context::new,
per-process --ros-args. (Issue 1917 retired the runtime-overlay
placeholder and, with issue 1931, the init_with_launch* entry points
named after it.)
Structs§
- Context
- Phase 212.L.5 — resolved init context.
- Init
Options - phase-427 W9 —
rclrs::InitOptions, with the one option it has.
Enums§
- Context
Source - Where the
Contextcame from. Diagnostics only. - Init
Error - Errors returned by the init API.
Constants§
- REFUSE_
INIT_ ARGS - The refusal
init_with_argsandContext::newemit for a ROS argument nano-ros does not honour. Panics carry this text followed by the refused argument.NROS_RCLCPP_REFUSE_INIT_ARGVis the C++ twin (packages/api/nros-cpp/include/rclcpp/logging.hpp), and since phase-467 Row 11’s C++ half it states the same honoured and refused sets, from the same parser.
Functions§
- args_
have_ ros_ args - Does
argsopen a--ros-argsscope at all? - init
- Pattern 3 — raw init, launch file ignored. The C++-symmetric anchor:
rclcpp::init()in the Rust spelling, and EQUAL toContext::default_from_envon a hosted build (RFC-0089 “Context andinit, settled” — each language follows its own upstream; rclrs spells this one on the type, rclcpp as a free function, and both are here). - init_
with_ args - Pattern 3 — like
init()but takes the process arguments, the wayrclcpp::init(argc, argv)/ rclrs’sContext::new(args, ..)do. The free-function twin ofContext::newwith default options.