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: boolTrue if a drive fault or operation timeout has occurred.
error_code: u32Drive error code (from status word or view error_code).
error_message: StringHuman-readable error description.
motor_on: boolTrue when the drive is in Operation Enabled state.
is_busy: boolTrue 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: boolTrue while a move operation specifically is active (subset of is_busy).
moving_positive: boolTrue when velocity is positive.
moving_negative: boolTrue when velocity is negative.
position: f64Current position in user units (relative to home).
raw_position: i64Current position in raw encoder counts (widened from i32).
speed: f64Current speed in user units/s (absolute value).
at_max_limit: boolTrue when position is at or beyond the maximum software limit.
at_min_limit: boolTrue when position is at or beyond the minimum software limit.
at_positive_limit_switch: boolTrue when the positive-direction hardware limit switch is active.
at_negative_limit_switch: boolTrue when the negative-direction hardware limit switch is active.
home_sensor: boolTrue when the home reference sensor is active.
Implementations§
Source§impl Axis
impl Axis
Sourcepub fn new(config: AxisConfig, device_name: &str) -> Self
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).
Sourcepub fn config(&self) -> &AxisConfig
pub fn config(&self) -> &AxisConfig
Get a reference to the axis configuration.
Sourcepub fn move_absolute(
&mut self,
view: &mut impl AxisView,
target: f64,
vel: f64,
accel: f64,
decel: f64,
)
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.
Sourcepub fn move_relative(
&mut self,
view: &mut impl AxisView,
distance: f64,
vel: f64,
accel: f64,
decel: f64,
)
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.
Sourcepub fn enable(&mut self, view: &mut impl AxisView)
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.
Sourcepub fn disable(&mut self, view: &mut impl AxisView)
pub fn disable(&mut self, view: &mut impl AxisView)
Start the disable sequence (OperationEnabled → SwitchedOn).
Sourcepub fn reset_faults(&mut self, view: &mut impl AxisView)
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.
Sourcepub fn home(&mut self, view: &mut impl AxisView, method: HomingMethod)
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.
Sourcepub fn set_position(&mut self, view: &impl AxisView, user_units: f64)
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.
Sourcepub fn set_software_max_limit(&mut self, user_units: f64)
pub fn set_software_max_limit(&mut self, user_units: f64)
Set the maximum (positive) software position limit.
Sourcepub fn set_software_min_limit(&mut self, user_units: f64)
pub fn set_software_min_limit(&mut self, user_units: f64)
Set the minimum (negative) software position limit.
Sourcepub fn sdo_write(
&mut self,
client: &mut CommandClient,
index: u16,
sub_index: u8,
value: Value,
)
pub fn sdo_write( &mut self, client: &mut CommandClient, index: u16, sub_index: u8, value: Value, )
Write an SDO value to the drive.
Sourcepub fn sdo_read(
&mut self,
client: &mut CommandClient,
index: u16,
sub_index: u8,
) -> u32
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.
Sourcepub fn sdo_result(&mut self, client: &mut CommandClient, tid: u32) -> SdoResult
pub fn sdo_result(&mut self, client: &mut CommandClient, tid: u32) -> SdoResult
Check the result of a previous SDO read.
Sourcepub fn tick(&mut self, view: &mut impl AxisView, client: &mut CommandClient)
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:
- Checks for drive faults
- Progresses the current multi-tick operation
- Updates output fields (position, velocity, status)
Outputs are updated last so they reflect the final state after all processing for this tick.