libstp.step.motion.drive

Attributes

Strafe

Classes

Drive

Step wrapper around the native LinearMotion controller.

Functions

drive_forward(→ Drive)

Drive forward a specified distance using profiled PID motion control.

drive_backward(→ Drive)

Drive backward a specified distance using profiled PID motion control.

strafe_left(→ Drive)

Strafe left by a specified distance using profiled PID motion control.

strafe_right(→ Drive)

Strafe right by a specified distance using profiled PID motion control.

Module Contents

class libstp.step.motion.drive.Drive(config: libstp.motion.LinearMotionConfig)

Bases: libstp.step.motion.motion_step.MotionStep

Step wrapper around the native LinearMotion controller.

config
to_simulation_step() libstp.step.SimulationStep

Convert this step to a simulation-friendly summary.

The default implementation uses timing history only when it can query the tracker synchronously; otherwise it returns conservative defaults. Override in subclasses that know their motion delta or exact duration.

on_start(robot: libstp.robot.api.GenericRobot) None

Called once before the loop. Override to set up motion/velocity.

on_update(robot: libstp.robot.api.GenericRobot, dt: float) bool

Called each cycle with dt in seconds. Return True when motion is complete.

libstp.step.motion.drive.Strafe
libstp.step.motion.drive.drive_forward(cm: float, speed: float = 1.0) Drive

Drive forward a specified distance using profiled PID motion control.

The robot accelerates, cruises, and decelerates along a trapezoidal velocity profile while maintaining heading via IMU feedback. Odometry tracks the distance traveled and the step completes when the target is reached.

Requires calibrate_distance() to have been run first so that encoder-to-meter conversion is accurate.

Parameters:
  • cm – Distance to drive in centimeters.

  • speed – Fraction of max speed, 0.0 to 1.0 (default 1.0).

Returns:

A Drive step configured for forward motion.

Raises:

CalibrationRequiredError – If calibrate_distance() has not been run.

Example:

from libstp.step.motion import drive_forward

# Drive forward 50 cm at full speed
drive_forward(50)

# Drive forward 30 cm at half speed
drive_forward(30, speed=0.5)
libstp.step.motion.drive.drive_backward(cm: float, speed: float = 1.0) Drive

Drive backward a specified distance using profiled PID motion control.

Identical to drive_forward() but in reverse. The robot drives backward while maintaining heading via IMU feedback.

Requires calibrate_distance() to have been run first.

Parameters:
  • cm – Distance to drive in centimeters.

  • speed – Fraction of max speed, 0.0 to 1.0 (default 1.0).

Returns:

A Drive step configured for backward motion.

Raises:

CalibrationRequiredError – If calibrate_distance() has not been run.

Example:

from libstp.step.motion import drive_backward

# Back up 20 cm
drive_backward(20)
libstp.step.motion.drive.strafe_left(cm: float, speed: float = 1.0) Drive

Strafe left by a specified distance using profiled PID motion control.

Requires a mecanum or omni-wheel drivetrain. The robot moves laterally to the left while maintaining heading via IMU feedback.

Parameters:
  • cm – Distance to strafe in centimeters.

  • speed – Fraction of max speed, 0.0 to 1.0 (default 1.0).

Returns:

A Drive step configured for leftward lateral motion.

Example:

from libstp.step.motion import strafe_left

# Strafe left 15 cm to dodge an obstacle
strafe_left(15)
libstp.step.motion.drive.strafe_right(cm: float, speed: float = 1.0) Drive

Strafe right by a specified distance using profiled PID motion control.

Requires a mecanum or omni-wheel drivetrain. The robot moves laterally to the right while maintaining heading via IMU feedback.

Parameters:
  • cm – Distance to strafe in centimeters.

  • speed – Fraction of max speed, 0.0 to 1.0 (default 1.0).

Returns:

A Drive step configured for rightward lateral motion.

Example:

from libstp.step.motion import strafe_right

# Strafe right 15 cm to align with a game piece
strafe_right(15)