stepper_motion/config/
system.rs

1//! System configuration - root configuration structure.
2
3use heapless::{FnvIndexMap, String};
4use serde::Deserialize;
5
6use super::motor::MotorConfig;
7use super::trajectory::{TrajectoryConfig, WaypointTrajectory};
8
9/// Root configuration structure from TOML.
10#[derive(Debug, Clone, Deserialize)]
11pub struct SystemConfig {
12    /// Named motor configurations.
13    pub motors: FnvIndexMap<String<32>, MotorConfig, 8>,
14
15    /// Named trajectory configurations.
16    #[serde(default)]
17    pub trajectories: FnvIndexMap<String<32>, TrajectoryConfig, 64>,
18
19    /// Named waypoint trajectories (sequences).
20    #[serde(default)]
21    pub sequences: FnvIndexMap<String<32>, WaypointTrajectory, 16>,
22}
23
24impl SystemConfig {
25    /// Get a motor configuration by name.
26    pub fn motor(&self, name: &str) -> Option<&MotorConfig> {
27        self.motors
28            .iter()
29            .find(|(k, _)| k.as_str() == name)
30            .map(|(_, v)| v)
31    }
32
33    /// Get a trajectory configuration by name.
34    pub fn trajectory(&self, name: &str) -> Option<&TrajectoryConfig> {
35        self.trajectories
36            .iter()
37            .find(|(k, _)| k.as_str() == name)
38            .map(|(_, v)| v)
39    }
40
41    /// Get a waypoint trajectory by name.
42    pub fn sequence(&self, name: &str) -> Option<&WaypointTrajectory> {
43        self.sequences
44            .iter()
45            .find(|(k, _)| k.as_str() == name)
46            .map(|(_, v)| v)
47    }
48
49    /// List all motor names.
50    pub fn motor_names(&self) -> impl Iterator<Item = &str> {
51        self.motors.keys().map(|s| s.as_str())
52    }
53
54    /// List all trajectory names.
55    pub fn trajectory_names(&self) -> impl Iterator<Item = &str> {
56        self.trajectories.keys().map(|s| s.as_str())
57    }
58
59    /// List all sequence names.
60    pub fn sequence_names(&self) -> impl Iterator<Item = &str> {
61        self.sequences.keys().map(|s| s.as_str())
62    }
63}
64
65impl Default for SystemConfig {
66    fn default() -> Self {
67        Self {
68            motors: FnvIndexMap::new(),
69            trajectories: FnvIndexMap::new(),
70            sequences: FnvIndexMap::new(),
71        }
72    }
73}