s6.robotic.stepperΒΆ
Stepper axis drivers over RS-485 serial.
Implements a minimal driver for a stepper controller board accessed via a
shared serial connection. The Axis class provides convenient motion
primitives in distance units; conversion to integer steps is handled via
calibration parameters.
Notes
Positions are tracked in integer steps. Distances (e.g., millimeters) are converted using
distance_per_revolutionandstep_per_revolution.Commands are serialized to the controller and acknowledgements are awaited. See
LinearController.wait_for_ack()for timing behavior.
- class s6.robotic.stepper.SerialConnection(port, baudrate, timeout)
Bases:
objectThread-safe singleton for a shared serial port.
- Parameters:
port (str) β Serial device path (e.g.,
"COM4"or"/dev/ttyUSB0").baudrate (int) β Port speed in baud.
timeout (float) β Read timeout in seconds.
Notes
All instances return the same underlying connection. Use the :pyattr:`connection` property to access the configured
serial.Serialobject.- property connection
Return the underlying
serial.Serialconnection.
- class s6.robotic.stepper.LinearController(address, distance_per_revolution, step_per_revolution, nominal_speed=32, nominal_acceleration=32, name='')
Bases:
objectBase controller implementing low-level step and boundary logic.
- Parameters:
address (int) β Device address on the bus.
distance_per_revolution (float) β Linear travel per motor revolution (e.g., mm/rev).
step_per_revolution (int) β Controller steps per revolution.
nominal_speed (int, default 32) β Default step speed (device-specific units).
nominal_acceleration (int, default 32) β Default acceleration (device-specific units).
name (str, default "") β Optional label for logging.
- FWD = 128
- BWD = 0
- distance_to_step(distance)
Convert a linear distance to integer steps.
- Parameters:
distance (float) β Travel in the same units as
distance_per_revolution.- Returns:
Number of controller steps.
- Return type:
int
- wait_for_ack(delay_time)
Wait for an acknowledgement frame or timeout.
- Parameters:
delay_time (float) β Maximum time (seconds) to wait before returning
0.- Returns:
Non-zero code on success;
0on timeout.- Return type:
int
- set_boundaries(min_boundary, max_boundary)
Set motion boundaries in distance units.
The provided limits are converted to steps and enforced on subsequent motions.
- Parameters:
min_boundary (float) β Minimum allowable position (distance units).
max_boundary (float) β Maximum allowable position (distance units).
- step(steps, speed: int = -1, start_acc: int = -1)
Issue a step command with optional speed/acceleration overrides.
- Parameters:
steps (int) β Signed number of steps. Positive moves forward; negative backward.
speed (int, default -1) β Override for speed; when
<= 0usesnominal_speed.start_acc (int, default -1) β Override for acceleration; when
<= 0usesnominal_acceleration.
Notes
Boundaries are enforced; if the motion would exceed limits the step count is clipped so the final position lies on the boundary.
- class s6.robotic.stepper.Axis(address, distance_per_revolution, step_per_revolution, nominal_speed=32, nominal_acceleration=32, name='')
Bases:
LinearControllerHigh-level axis controller with distance-based helpers.
- move(distance, max_speed=-1, acceleration=-1)
Move by a relative linear distance.
- Parameters:
distance (float) β Travel in distance units (e.g., mm). Converted to steps internally.
max_speed (int, default -1) β Optional speed override.
acceleration (int, default -1) β Optional acceleration override.
- zero(max_speed=-1, acceleration=-1)
Move back to absolute position
0and reset the tracker.
- round_trip(distance, max_speed=-1, acceleration=-1)
Context manager for a symmetric outbound and return motion.
- Parameters:
distance (float) β Outbound distance before yielding control.
max_speed (int, default -1) β Optional speed override.
acceleration (int, default -1) β Optional acceleration override.
- Yields:
None β Control is returned to the caller between outbound and return legs.
- property min_boundary_steps
Minimum allowed position in steps (relative to zero).
- property max_boundary_steps
Maximum allowed position in steps (relative to zero).
- run_boundary()
Context manager to traverse from min to max boundaries.
- goto(position)
Move to an absolute position in steps.
- sweep(step_size=1, delay=0.01)
Iterate positions across the boundary range.
- Parameters:
step_size (float, default 1) β Step size in distance units between samples.
delay (float, default 0.01) β Sleep time between moves, in seconds.
- Yields:
None β After each move, yields control to the caller.