Robot is jerky on startup

We are using the REV driver hub with a REV control hub and REV expansion hub. Sometimes when we turn on the driver hub and the robot, when we try to drive the robot it is jerky. Usually if we turn off everything and restart it is fine, but not always. Does anyone have any suggestions about what is happening. Thanks.

There are literally hundreds of reasons why this could be, most are usually explained by problems in your code that might be resolved by lucky timings. You would have to share your code and provide a detailed description of the problem you are facing (when the jerkiness happens).

90% of the time when I find the cause of “jerkiness” or “chatter” it’s because I have more than one “if” statement that can possibly control the same piece of hardware - usually with an “else” statement that ends up setting a motor value to a different value momentarily which upsets the motor controller.

-Danny

Thank you Danny. I will have them check through the code to see if they can find duplicate if/else statements.

I will have them check through the code to see if they can find duplicate if/else statements.

You may not have meant it this way, but remember you’re not looking for duplicate if/else statements, you’re looking for hardware accesses in multiple if/else statements.

Usually beginner issues involving chatter end up looking something like this (this is pseudocode, please don’t mistake it for real code):

if( gamepad1.buttonA.isPressed() )
   lifterMotor.setPower( 1 );
else
   lifterMotor.setPower( 0 );

if( gamepad1.buttonB.isPressed() )
   lifterMotor.setPower( -1 );
else
   lifterMotor.setPower( 0 );

The intent of the code is to make the motor go different directions based on which button is pressed, and not move when the button isn’t pressed, but in effect it ensures that the motor will always be in contention no matter what happens. This causes the motors to “chatter” when they’re being told to do one thing and then a different thing very quickly. This should instead be written as:

if( gamepad1.buttonA.isPressed() )
   lifterMotor.setPower( 1 );
else if( gamepad1.buttonB.isPressed() ) 
   lifterMotor.setPower( -1 );
else
   lifterMotor.setPower( 0 );

This ensures that ALL of the lifterMotor accesses are in a single if statement, and that only one of the lifterMotor accesses can be reached in a single loop through the code.

-Danny