Jittery Autonomous Code {Java}

In autonomous, i try to run the following code:


try {

            encLeft.start();
            encRight.start();
            encLeft.reset();
            encRight.reset();

            while (((encLeft.getRaw() > -14797) || (encRight.getRaw() > -14797)) && (this.isAutonomous())) {
                //System.out.println("Left:" + encLeft.getRaw() + " Right:" + encRight.getRaw());
                if (encLeft.getRaw() < 14797) {
                        motor_leftFront_J.setX(.5);
                        motor_leftRear_J.setX(.5);
                } else {
                    motor_leftFront_J.setX(0);
                    motor_leftRear_J.setX(0);
                }
                if (encRight.getRaw() < 14797) {
                        motor_rightFront_J.setX(-.5);
                        motor_rightRear_J.setX(-.5);
                } else {
                    motor_rightFront_J.setX(0);
                    motor_rightRear_J.setX(0);
                }
            }
            Timer.delay(.5);
            encLeft.reset();
            encRight.reset();
}catch(Exception e){
}

The output this produces is a very jittery running of the code, as if it sends the commands, and then immediately after sends it a stop command, following which it repeats. The teleop code works fine, so i know that it is updating the output frequent enough, and it never catches any errors… Any thoughts? Thanks
~Matt Clark

I have a thought.

Your while() loop is running as fast as it can, with no pauses. It might be starving the communication task, which could result in the hardware occasionally shutting down the motor outputs due to a lack of communication. Put a short wait (ten milliseconds might be good) inside the loop and see if that helps.

Tied with:

Timer.delay(.01);
Timer.delay(.02);
Timer.delay(.001);
Timer.delay(.005);

Still no improvment.

Are the motors being controlled by those Jaguar objects also being controlled by a Drive object? I don’t even know if that’s possible in Java, but if it is, you could be seeing the Motor Safety keeping the drive motors turned off because you aren’t calling a Drive command every 100 milliseconds.

Thank you so much!
In my robotInit() I initialized my RobotDrive() that I user later in teleop, and that is what kept stopping the motors. Moved the RobotDrive init to my teleop init and it works perfectly now!