Skip to main content

Crate nros_node

Crate nros_node 

Source
Expand description

Node abstraction for nros

This crate provides the high-level Node API for creating ROS 2 compatible publishers and subscribers on embedded systems.

§Executor-Based API

The executor-based API provides a unified interface that works on both std (desktop) and no_std (embedded) targets.

§Desktop Example

use nros::prelude::*;
use std_msgs::msg::Int32;

let config = ExecutorConfig::from_env().node_name("my_node");
let mut executor: Executor = Executor::open(&config)?;

// Register subscription callback
let node = executor.node_builder("my_node").build()?;
executor.node_mut(node).create_subscription::<Int32, _>("/topic", |msg: &Int32| {
    println!("Received: {}", msg.data);
})?;

// Spin (processes callbacks)
executor.spin_blocking(SpinOptions::default());

§Embedded Example

use nros::prelude::*;
use std_msgs::msg::Int32;

let config = ExecutorConfig { locator: "tcp/192.168.1.1:7447", ..Default::default() };
let mut executor: Executor = Executor::open(&config)?;

// Register subscription callback
let node = executor.node_builder("my_node").build()?;
executor.node_mut(node).create_subscription::<Int32, _>("/cmd", |msg: &Int32| {
    // process message...
})?;

// In your main loop:
loop {
    executor.spin_once(core::time::Duration::from_millis(10));
    // platform delay...
}

§Features

  • std - Enable standard library support (spin_blocking)
  • alloc - Enable heap allocation (parameter service boxed replies)

Re-exports§

pub use timer::TimerCallbackFn;
pub use timer::TimerDuration;
pub use timer::TimerHandle;
pub use timer::TimerMode;
pub use timer::TimerState;
pub use lifecycle::LifecycleCallbackFn;
pub use lifecycle::LifecycleError;
pub use lifecycle::LifecyclePollingNode;
pub use executor::BootConfig;
pub use executor::BootConfigError;
pub use executor::DOMAIN_ID_EXPLICIT_ZERO_C_ABI;
pub use executor::DOMAIN_ID_MAX;
pub use executor::EnvRung;
pub use executor::ExecutorConfig;
pub use executor::ExecutorSemantics;
pub use executor::GuardCondition;
pub use executor::HandleId;
pub use executor::HandleSet;
pub use executor::InvocationMode;
pub use executor::NodeError;
pub use executor::RawAcceptedCallback;
pub use executor::RawCancelCallback;
pub use executor::RawGoalCallback;
pub use executor::RawResponseCallback;
pub use executor::RawServiceCallback;
pub use executor::RawSubscriptionCallback;
pub use executor::ReadinessSnapshot;
pub use executor::ShutdownCallbackFn;
pub use executor::ShutdownCallbackHandle;
pub use executor::ShutdownPhase;
pub use executor::SpinOnceResult;
pub use executor::SpinOptions;
pub use executor::SpinPeriodPollingResult;
pub use executor::Trigger;
pub use executor::baked_domain_from_c_abi;
pub use executor::ActionClient;
pub use executor::ActionClientCore;
pub use executor::ActionServer;
pub use executor::ActionServerCore;
pub use executor::ActionServerHandle;
pub use executor::ActionServerRawHandle;
pub use executor::ActiveGoal;
pub use executor::CallbackGroup;
pub use executor::CompletedGoal;
pub use executor::EmbeddedPublisher;
pub use executor::EmbeddedRawPublisher;
pub use executor::EmbeddedServiceClient;
pub use executor::EmbeddedServiceServer;
pub use executor::Executor;
pub use executor::FeedbackStream;
pub use executor::GoalFeedbackStream;
pub use executor::LoanError;
pub use executor::NodeHandle;
pub use executor::Promise;
pub use executor::PublishLoan;
pub use executor::RawActionClientSpec;
pub use executor::RawActionServerSpec;
pub use executor::RawActiveGoal;
pub use executor::RawServiceClient;
pub use executor::RawServiceServer;
pub use executor::RawSubscription;
pub use executor::RecvView;
pub use executor::SessionHandle;
pub use executor::Subscription;
pub use executor::action_channel_type;
pub use executor::executor_storage_layout;
pub use executor::executor_storage_u64_len;
pub use executor::ExecutorInlineStorage;
pub use executor::ExecutorSizing;
pub use executor::RMW_SELECTOR_CAP;
pub use executor::default_epoch_us_fn;
pub use executor::SessionSpec;
pub use executor::SpinPeriodResult;

Modules§

boot_report
phase-412 – the boot self-report, for boards with no reachable log sink. A fixed RAM record the image writes about itself, for targets where no log sink reaches a human.
c_waker
Phase 122.3.c.6.e — C-ABI-compatible Waker bridge.
config
Build-time configurable constants.
executor
Embedded executor with build-time configured arena.
format_check
RFC-0088 / phase-421 W1 — the compile-time message-format check.
lifecycle
Lifecycle node API (REP-2002)
limits
Shared string-length and resource caps used by the Rust, C, and C++ APIs.
names
ROS 2 name expansion + launch remap resolution (issue 0255 / phase-306 W3).
rmw_type_registry
Phase 212.K.7.6.b — runtime cyclonedds type-descriptor registry hook. Per-type descriptor registration — generic seam (Phase 248 C2).
session
Concrete session type aliases resolved at compile time.
timer
Timer API for nros

Structs§

ActionInfo
Action information for action client/server
BakedBootConfig
Build-time-baked boot config, emitted (in W4b) into the .nros_boot_config linker section by the entry macro / cmake. Fixed-size + pointer-free so a future post-link tool can patch it in place (RFC-0045). The resolver reads it on embedded via BootConfig::from_baked (in nros-node).
CdrReader
CDR reader for deserialization
CdrWriter
DHeaderMark
Opaque marker returned by CdrWriter::begin_dheader, passed back to CdrWriter::end_dheader. Under XCDR1 it carries nothing (the DHEADER calls are no-ops); under XCDR2 it holds the reserved DHEADER position.
DHeaderScope
Opaque scope returned by CdrReader::begin_dheader, passed back to CdrReader::end_dheader. Under XCDR1 it carries nothing (no-op); under XCDR2 it holds the absolute buffer offset of the delimited struct’s end.
GoalId
Unique identifier for a goal
NodeConfig
Node configuration
PublisherHandle
Handle to a publisher
PublisherOptions
Options for creating a publisher
QoSPolicyMask
Bitmask of QoS policies a backend can honour. See Session::supported_qos_policies.
QoSProfile
Full DDS-shaped QoS profile. Matches the field set of upstream rmw_qos_profile_t.
ServiceInfo
Service information for service client/server
StandaloneNode
ROS 2 Node for embedded systems
SubscriptionHandle
Handle to a subscriber
SubscriptionOptions
Options for creating a subscriber
TopicInfo
Topic information for pub/sub
TransportConfig
Transport session configuration

Enums§

CancelResponse
Per-goal cancel decision returned from a server’s cancel callback.
CancelReturnCode
action_msgs/srv/CancelGoal RPC return codes.
DeserError
Deserialization error.
EncodingVersion
CDR writer for serialization.
GoalResponse
Goal accept/reject response codes
GoalStatus
Goal status states
LifecycleState
Lifecycle state (REP-2002)
LifecycleTransition
Lifecycle transition (REP-2002)
QoSDurabilityPolicy
QoS durability policy
QoSHistoryPolicy
QoS history policy
QoSLivelinessPolicy
QoS liveliness policy. Matches DDS LIVELINESS semantics.
QoSReliabilityPolicy
QoS reliability policy
SerError
Serialization error.
SessionMode
Session mode
StandaloneNodeError
Node error types
TransitionResult
Result of a lifecycle transition callback.
TransportError
Transport error types.

Constants§

BOOT_SET_DOMAIN
Bit 2 — domain_id field is set.
BOOT_SET_LOCATOR
Bit 1 — locator field is set.
BOOT_SET_NAMESPACE
Bit 3 — namespace field is set.
BOOT_SET_NODE_NAME
Bit 0 — node_name field is set.
BOOT_SET_RMW
Bit 4 — rmw field is set (issue 1050 defect (3); layout version 2).
NROS_BOOT_CONFIG_MAGIC
0x4E524243 = ASCII “NRBC”. A post-link tool scans for this magic to locate the struct in a firmware image.
NROS_BOOT_CONFIG_VERSION
Layout version — lets the resolver reject a mismatched baked struct.
SERVER_DISCOVERY_PROBE_TIMEOUT_MS
Server-discovery probe cadence (issue #224 — one shared constant; was independently defined at four call sites across nros-node and nros-c). One probe per second balances “see freshly-declared tokens quickly” against “burn fewer FFI round-trips on a healthy network”; the outer wall-clock budget is the caller’s.

Traits§

ClientTrait
Service client trait for sending requests.
Publisher
Publisher trait for sending messages.
ServiceTrait
Service server trait for handling requests.
Session
Transport session trait — the per-process anchor an RMW backend gives to the executor.
SubscriptionTrait
Subscription trait for receiving messages.