MotorToPositionAction

Overview

MotorToPositionAction is a RR Action that commands a DcMotorEx or an AdvancedDcMotor to move to a specific encoder position using the RUN_TO_POSITION mode. The action completes once the motor reached the target within the tolerance, or if an overcurrent is detected (via AdvancedDcMotor).

For better performance, consider using a custom PID loop, as it is more reliable than the SDK's internal PID loop (see AdvancedDcMotor). Nevertheless, this action will work with either.


Usage

MotorToPositionAction(DcMotorEx, int)

// You can use either an AdvancedDcMotor (recommended) or DcMotorEx
DcMotorEx armMotor = hardwareMap.get(DcMotorEx.class, "arm");
armMotor.setTargetPositionTolerance(10); // Optional: adjust tolerance (default: 10)

runBlocking(
    new SequentialAction(
        new MotorToPositionAction(armMotor, 1000), // Extend arm
        new ServoToPositionAction(claw, 0.0)       // Open claw after arm is extended
    )
);

If using AdvancedDcMotor's custom PID, ensure that AdvancedDcMotor.updateAll() is being called periodically to handle the PID controller and overcurrent protection logic correctly.

Last updated