setTargetPosition

open fun setTargetPosition(position: Int)

Sets the desired encoder target position to which the motor should advance or retreat and then actively hold thereat. This behavior is similar to the operation of a servo. The maximum speed at which this advance or retreat occurs is governed by the power level currently set on the motor. While the motor is advancing or retreating to the desired taget position, isBusy will return true if using a PIDF controller.

Note that adjustment to a target position is only effective when the motor is in RUN_TO_POSITION RunMode. Note further that, clearly, the motor must be equipped with an encoder in order for this mode to function properly.

Additionally note that the target positioning functionality of the Motor class handles the propagation of target position following internally.

Parameters

position

the desired encoder target position

See also

setMode(DcMotor.RunMode)
DcMotor.RunMode