Motors
Control DC motors, smart motors, and servos with precision speed, position, and torque control.
Creates a new motor object on the specified port.
| port | int | Motor port number (1-21) |
# Initialize a motor on port 1
left_motor = Motor(1)
# Initialize with reversed direction
right_motor = Motor(2, reversed=True)
spin(direction, velocity, units)
Method
Spins the motor in the specified direction at the given velocity.
| direction | DirectionType | FORWARD or REVERSE |
| velocity | float | Speed value |
| units | VelocityUnits | PCT, RPM, or DPS |
# Spin motor forward at 50% speed
left_motor.spin(FORWARD, 50, PCT)
# Spin motor in reverse at 100 RPM
left_motor.spin(REVERSE, 100, RPM)
spin_to_position(position, units, velocity, wait)
Method
Rotates the motor to an absolute position.
| position | float | Target position value |
| units | RotationUnits | DEG, REV, or RAW |
| velocity | float | Speed (default: 50) |
| wait | bool | Wait for completion (default: True) |
# Rotate to 90 degrees
arm_motor.spin_to_position(90, DEG)
# Rotate 2 full revolutions at 75% speed
arm_motor.spin_to_position(2, REV, 75)
Stops the motor using the specified braking mode.
| brake_type | BrakeType | COAST, BRAKE, or HOLD |
# Stop and hold position
arm_motor.stop(HOLD)
# Stop and coast (no resistance)
drive_motor.stop(COAST)