MotorSystem

Struct MotorSystem 

Source
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

Source

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().

Source

pub fn config(&self) -> &SystemConfig

Get the system configuration.

Source

pub fn trajectories(&self) -> &TrajectoryRegistry

Get the trajectory registry.

Source

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.

Source

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.

Source

pub fn has_motor(&self, name: &str) -> bool

Check if a motor name exists in the configuration.

Source

pub fn motor_names(&self) -> impl Iterator<Item = &str>

List all configured motor names.

Source

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>>
where STEP: OutputPin, DIR: OutputPin, DELAY: DelayNs,

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.

Source

pub fn build_motor<STEP, DIR, DELAY>( &self, name: &str, step_pin: STEP, dir_pin: DIR, delay: DELAY, ) -> Result<StepperMotor<STEP, DIR, DELAY, Idle>>
where STEP: OutputPin, DIR: OutputPin, DELAY: DelayNs,

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.

Source

pub fn is_registered(&self, name: &str) -> bool

Check if a motor has been registered.

Source

pub fn registered_count(&self) -> usize

Get the number of registered motors.

Source

pub fn registered_constraints( &self, name: &str, ) -> Option<&MechanicalConstraints>

Get constraints for a registered motor.

Returns None if the motor is not registered.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.