Our team uses blocks and have defined functions for most of our movements, in which we use the “RUN_TO_POSITION” mode. An issue we run into at times, is that once it basically reaches the targeted tick, motors will independently twitch. I believe it is making some very small adjustments to get to the exact position, for example if the position was 1000, but it went to 1002, it goes backwards for 2, which may then affect another motor so it has to adjust. This causes the robot to spend some extra time sitting there doing the adjustments. Below is an example function we use (copied by using the Java Code window). As you can see, we stay in the function until all of the motors are no longer busy. Is there maybe a better way to handle this, as sometimes it gets to its target point, then will maybe adjust for another second or two - where you see one or more motors twitching. And other times, it just seems to sit there doing nothing for a second or two, and then goes to the next function. And if you run the same exact program 10 times it may do it perfectly 5 times, then a couple where it twitches but runs perfectly, and a couple where it just seems to wait a second or two between functions.
private void moveForward(int ticks, double power) {
leftFront.setPower(power);
leftRear.setPower(power);
rightFront.setPower(power);
rightRear.setPower(power);
leftFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
leftRear.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
rightFront.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
rightRear.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
leftFront.setTargetPosition(ticks);
leftRear.setTargetPosition(ticks);
rightFront.setTargetPosition(ticks);
rightRear.setTargetPosition(ticks);
leftFront.setMode(DcMotor.RunMode.RUN_TO_POSITION);
leftRear.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rightFront.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rightRear.setMode(DcMotor.RunMode.RUN_TO_POSITION);
while (!isStopRequested() && (leftFront.isBusy() || leftRear.isBusy() || rightFront.isBusy() || rightRear.isBusy())) {
telemetry.addData(“Progam”, “FORWARD”);
telemetry.update();
}