Skip to main content

Axis

Struct Axis 

Source
pub struct Axis {
Show 16 fields pub is_error: bool, pub error_code: u32, pub error_message: String, pub motor_on: bool, pub is_busy: bool, pub in_motion: bool, pub moving_positive: bool, pub moving_negative: bool, pub position: f64, pub raw_position: i64, pub speed: f64, pub at_max_limit: bool, pub at_min_limit: bool, pub at_positive_limit_switch: bool, pub at_negative_limit_switch: bool, pub home_sensor: bool, /* private fields */
}
Expand description

Stateful motion controller for a CiA 402 servo drive.

Manages the CiA 402 protocol (state machine, PP handshake, homing) internally. Call tick() every control cycle to progress operations and update output fields.

Fields§

§is_error: bool

True if a drive fault or operation timeout has occurred.

§error_code: u32

Drive error code (from status word or view error_code).

§error_message: String

Human-readable error description.

§motor_on: bool

True when the drive is in Operation Enabled state.

§is_busy: bool

True when any operation is in progress (enable, move, home, fault recovery, etc.).

Derived from the internal state machine — immediately true when a command is issued, false when the operation completes or a fault cancels it. Use this (not in_motion) to wait for operations to finish.

§in_motion: bool

True while a move operation specifically is active (subset of is_busy).

§moving_positive: bool

True when velocity is positive.

§moving_negative: bool

True when velocity is negative.

§position: f64

Current position in user units (relative to home).

§raw_position: i64

Current position in raw encoder counts (widened from i32).

§speed: f64

Current speed in user units/s (absolute value).

§at_max_limit: bool

True when position is at or beyond the maximum software limit.

§at_min_limit: bool

True when position is at or beyond the minimum software limit.

§at_positive_limit_switch: bool

True when the positive-direction hardware limit switch is active.

§at_negative_limit_switch: bool

True when the negative-direction hardware limit switch is active.

§home_sensor: bool

True when the home reference sensor is active.

Implementations§

Source§

impl Axis

Source

pub fn new(config: AxisConfig, device_name: &str) -> Self

Create a new Axis with the given configuration.

device_name must match the device name in project.json (used for SDO operations during homing).

Source

pub fn config(&self) -> &AxisConfig

Get a reference to the axis configuration.

Source

pub fn move_absolute( &mut self, view: &mut impl AxisView, target: f64, vel: f64, accel: f64, decel: f64, )

Start an absolute move to target in user units.

The axis must be enabled (Operation Enabled) before calling this. If the target exceeds a software position limit, the move is rejected and is_error is set.

Source

pub fn move_relative( &mut self, view: &mut impl AxisView, distance: f64, vel: f64, accel: f64, decel: f64, )

Start a relative move by distance user units from the current position.

The axis must be enabled (Operation Enabled) before calling this. If the resulting position would exceed a software position limit, the move is rejected and is_error is set.

Source

pub fn halt(&mut self, view: &mut impl AxisView)

Halt the current move (decelerate to stop).

Source

pub fn enable(&mut self, view: &mut impl AxisView)

Start the enable sequence (Shutdown → ReadyToSwitchOn → OperationEnabled).

The sequence is multi-tick. Check motor_on for completion.

Source

pub fn disable(&mut self, view: &mut impl AxisView)

Start the disable sequence (OperationEnabled → SwitchedOn).

Source

pub fn reset_faults(&mut self, view: &mut impl AxisView)

Start a fault reset sequence.

Clears bit 7, then asserts it (rising edge), then waits for fault to clear.

Source

pub fn home(&mut self, view: &mut impl AxisView, method: HomingMethod)

Start a homing sequence with the given homing method.

Integrated methods delegate to the drive’s built-in CiA 402 homing mode (SDO writes + homing trigger).

Software methods are implemented by the Axis, which monitors AxisView sensor signals for edge triggers and captures home.

Source

pub fn set_position(&mut self, view: &impl AxisView, user_units: f64)

Set the current position to the given user-unit value.

Adjusts the internal home offset so that the current raw position maps to user_units. Does not move the motor.

Source

pub fn set_home_position(&mut self, user_units: f64)

Set the home position in user units. This value is used by the next home() call to set the axis position at the reference point. Can be called at any time before homing.

Source

pub fn set_software_max_limit(&mut self, user_units: f64)

Set the maximum (positive) software position limit.

Source

pub fn set_software_min_limit(&mut self, user_units: f64)

Set the minimum (negative) software position limit.

Source

pub fn sdo_write( &mut self, client: &mut CommandClient, index: u16, sub_index: u8, value: Value, )

Write an SDO value to the drive.

Source

pub fn sdo_read( &mut self, client: &mut CommandClient, index: u16, sub_index: u8, ) -> u32

Start an SDO read from the drive. Returns a transaction ID.

Source

pub fn sdo_result(&mut self, client: &mut CommandClient, tid: u32) -> SdoResult

Check the result of a previous SDO read.

Source

pub fn tick(&mut self, view: &mut impl AxisView, client: &mut CommandClient)

Update outputs and progress the current operation.

Must be called every control cycle. Does three things:

  1. Checks for drive faults
  2. Progresses the current multi-tick operation
  3. Updates output fields (position, velocity, status)

Outputs are updated last so they reflect the final state after all processing for this tick.

Auto Trait Implementations§

§

impl Freeze for Axis

§

impl RefUnwindSafe for Axis

§

impl Send for Axis

§

impl Sync for Axis

§

impl Unpin for Axis

§

impl UnsafeUnpin for Axis

§

impl UnwindSafe for Axis

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V