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