Skip to main content

nros_params/
lib.rs

1//! Parameter server for nros
2//!
3//! This crate provides a ROS 2 compatible parameter server for embedded systems.
4//! Parameters live in storage the CALLER places and lends to the server
5//! ([`ParameterStorage`] / [`ParameterTable`]); [`MAX_PARAMETERS`] is only the
6//! default capacity of that storage.
7//!
8//! # Example
9//!
10//! ```
11//! use nros_params::{
12//!     NodeKey, ParameterDescriptor, ParameterServer, ParameterStorage, ParameterType,
13//!     ParameterValue,
14//! };
15//!
16//! // phase-382 W2' — storage is CALLER-OWNED: place it (a `static`, a struct
17//! // field, a local), then lend it. `ParameterStorage` defaults to
18//! // `MAX_PARAMETERS` slots; any length works, and the server's capacity is
19//! // whatever it is handed.
20//! let mut storage = ParameterStorage::<8>::new();
21//! let mut server = ParameterServer::new_in(storage.as_table());
22//!
23//! // phase-426 W1 — every per-parameter call names the NODE it is about, so
24//! // two nodes composed onto one executor never share a name.
25//! let node = NodeKey::PRIMARY;
26//!
27//! // Declare a simple parameter
28//! server.declare(node, "max_speed", ParameterValue::Double(1.0));
29//!
30//! // Declare a parameter with constraints
31//! let desc = ParameterDescriptor::new("velocity", ParameterType::Double)
32//!     .unwrap()
33//!     .with_description("Maximum velocity in m/s")
34//!     .with_float_range(0.0, 10.0, 0.1);
35//! server.declare_with_descriptor(node, "velocity", ParameterValue::Double(5.0), Some(desc));
36//!
37//! // Get and set parameters
38//! assert_eq!(server.get_double(node, "max_speed"), Some(1.0));
39//! server.set_double(node, "max_speed", 2.0);
40//! ```
41//!
42//! # Features
43//!
44//! - `std` - Enable standard library support
45//! - `alloc` - Enable heap allocation
46
47#![no_std]
48
49#[cfg(feature = "std")]
50extern crate std;
51
52#[cfg(feature = "alloc")]
53extern crate alloc;
54
55pub(crate) mod config;
56// phase-359 W10 / issue 0080 — `persist` is GONE. It held the parameter
57// PERSISTENCE seam (`ParamStore`, `NullParamStore`, `ParamStoreError`,
58// `FileParamStore`), which 0080 ruled a non-goal in July: nano-ros does not
59// persist parameters on-device, and launch-baked defaults are the supported
60// model. Runtime get/set/describe — the `server` module — stay.
61// phase-446 W6 -- what each node's contract declares, looked up when the code
62// declares a parameter.
63pub mod declared;
64pub mod server;
65pub mod typed;
66pub mod types;
67
68// Re-export main types
69pub use declared::{DeclaredParamMismatch, DeclaredParams};
70pub use server::{
71    DeclarationError, LegacyParameterBuilder, MAX_ON_SET_CALLBACKS, OnSetContext, OnSetParameterFn,
72    OnSetParameterHandle, PARAMETER_EVENT_LOG_LEN, ParameterEventKind, ParameterServer,
73    ParameterSlot, ParameterStorage, ParameterTable, PendingParameterEvent,
74};
75pub use typed::{
76    MandatoryParameter, OptionalParameter, ParameterBuilder, ParameterError, RangeConvertible,
77    ReadOnlyParameter, UndeclaredParameters,
78};
79pub use types::{
80    FloatingPointRange, IMPLIED_STORE_SLOTS, IntegerRange, MAX_ARRAY_LEN, MAX_BYTE_ARRAY_LEN,
81    MAX_PARAM_CONSTRAINTS_LEN, MAX_PARAM_DESCRIPTION_LEN, MAX_PARAM_NAME_LEN, MAX_PARAMETERS,
82    MAX_STRING_VALUE_LEN, NodeFlags, NodeKey, PARAM_EVENTS_DEPTH, Parameter, ParameterDescriptor,
83    ParameterRange, ParameterType, ParameterValue, ParameterVariant, SetParameterResult,
84    fit_description,
85};