pub struct MotorSystem { /* private fields */ }Expand description
A facade for managing multiple stepper motors from configuration.
MotorSystem provides a high-level API for:
- Creating motors from named configurations
- Accessing motors by name
- Managing trajectory registries
§Example
use stepper_motion::motor::MotorSystem;
let config: SystemConfig = toml::from_str(CONFIG_TOML)?;
let mut system = MotorSystem::from_config(config);
// Register motors with their hardware pins
system.register_motor("x_axis", step_pin_x, dir_pin_x, delay_x)?;
system.register_motor("y_axis", step_pin_y, dir_pin_y, delay_y)?;
// Access motors by name
if let Some(motor) = system.motor("x_axis") {
println!("X position: {}", motor.position_degrees().0);
}Implementations§
Source§impl MotorSystem
impl MotorSystem
Sourcepub fn from_config(config: SystemConfig) -> Self
pub fn from_config(config: SystemConfig) -> Self
Create a new motor system from configuration.
This initializes the trajectory registry but does not create any motors.
Motors must be registered individually using register_motor() or
created using build_motor().
Sourcepub fn config(&self) -> &SystemConfig
pub fn config(&self) -> &SystemConfig
Get the system configuration.
Sourcepub fn trajectories(&self) -> &TrajectoryRegistry
pub fn trajectories(&self) -> &TrajectoryRegistry
Get the trajectory registry.
Sourcepub fn motor_config(&self, name: &str) -> Option<&MotorConfig>
pub fn motor_config(&self, name: &str) -> Option<&MotorConfig>
Get a motor configuration by name.
Returns None if no motor with that name exists in the configuration.
Sourcepub fn constraints(&self, name: &str) -> Option<MechanicalConstraints>
pub fn constraints(&self, name: &str) -> Option<MechanicalConstraints>
Get mechanical constraints for a motor by name.
Returns None if no motor with that name exists.
Sourcepub fn motor_names(&self) -> impl Iterator<Item = &str>
pub fn motor_names(&self) -> impl Iterator<Item = &str>
List all configured motor names.
Sourcepub fn register_motor<STEP, DIR, DELAY>(
&mut self,
name: &str,
step_pin: STEP,
dir_pin: DIR,
delay: DELAY,
) -> Result<StepperMotor<STEP, DIR, DELAY, Idle>>
pub fn register_motor<STEP, DIR, DELAY>( &mut self, name: &str, step_pin: STEP, dir_pin: DIR, delay: DELAY, ) -> Result<StepperMotor<STEP, DIR, DELAY, Idle>>
Register a motor as active in the system.
This marks the motor as registered and stores its constraints. The actual motor instance is returned to the caller.
§Errors
Returns an error if the motor name doesn’t exist in the configuration.
Sourcepub fn build_motor<STEP, DIR, DELAY>(
&self,
name: &str,
step_pin: STEP,
dir_pin: DIR,
delay: DELAY,
) -> Result<StepperMotor<STEP, DIR, DELAY, Idle>>
pub fn build_motor<STEP, DIR, DELAY>( &self, name: &str, step_pin: STEP, dir_pin: DIR, delay: DELAY, ) -> Result<StepperMotor<STEP, DIR, DELAY, Idle>>
Build a motor from configuration without registering it.
Use this when you need a motor but don’t need system-level tracking.
§Errors
Returns an error if the motor name doesn’t exist or building fails.
Sourcepub fn is_registered(&self, name: &str) -> bool
pub fn is_registered(&self, name: &str) -> bool
Check if a motor has been registered.
Sourcepub fn registered_count(&self) -> usize
pub fn registered_count(&self) -> usize
Get the number of registered motors.
Sourcepub fn registered_constraints(
&self,
name: &str,
) -> Option<&MechanicalConstraints>
pub fn registered_constraints( &self, name: &str, ) -> Option<&MechanicalConstraints>
Get constraints for a registered motor.
Returns None if the motor is not registered.
Sourcepub fn trajectory(&self, name: &str) -> Result<&TrajectoryConfig>
pub fn trajectory(&self, name: &str) -> Result<&TrajectoryConfig>
Get a trajectory by name, with error if not found.
This is a convenience method that delegates to the registry.
Sourcepub fn trajectories_for_motor<'a>(
&'a self,
motor_name: &'a str,
) -> impl Iterator<Item = &'a str> + 'a
pub fn trajectories_for_motor<'a>( &'a self, motor_name: &'a str, ) -> impl Iterator<Item = &'a str> + 'a
Get all trajectory names for a specific motor.