Auton error: "Differential Drive..."

When trying to run some code through the VS Alpha test I’m getting this error when running one of my auto command groups. I’m assuming that it is an easy fix. Please let me know

Error: ERROR 1 DifferentialDrive… Output not updated often enough. edu.wpi.first.wpilibj.MotorSafetyHelper.check(MotorSafetyHelper.java:108)

Thank you,

1 Like

All motor controllers must be updated on every control loop iteration, for safety reasons (the motor controller will otherwise continue to run as previously commanded).

For these purposes, a DifferentialDrive object counts as a “motor controller”, which in turn will update the actual motor controllers.

If you want to update the motor controllers directly in autonomous, you will have to either feed the DifferentialDrive’s MotorSafety watchdog (a feedWatchdog() method has been added for the 2019 season), or disable the motor safety on DifferentialDrive (make sure you understand the implications of this before doing so).

^^ as above.

Another possible cause why you might not be updating the motor controller regularly is if you are not actually running the control loop quickly enough, or at all. If you are using iterative or timed or command based, this would most likely be caused by the iterative calls taking more than a few tens of milliseconds.

If you are running sample robot, you need to code to ensure that you are updating the motor speed (even if with the same value over and over) - you cannot “turn on the motor, and just wait for it to go fifteen feet”.

Finally, if nothing here solves your issue, please post the location of the code - all too often, the issue with the code is somewhere you are not even looking. Eyes on the code will help us help you.

Here’s a link to the code I’m currently using. I believe it is an issue with the command named “DriveStraightGyroSPI” as it is the only command called in my default auto. One note… it is almost identical to a command I successfully used last year with the navX.

Code: https://github.com/Phred7/SecondFullTestVSCodeAlpha/tree/master/src/main/java/frc/robot

The DriveStraightGyroSPI command looks correct, and should work even if you get rid of the part that turns off the motor safety.

This issue happens when you run the Auto1 command group, correct?

If I had to guess, you are only getting this error during the wait command.* Basically, while the wait is happening, there is no command being executed which uses the drivetrain. This means that the drive is not being updated, and you get that error.

There are a handful of ways to fix this, but my recommendation is that before the wait, you do an addParallel() with a command that continuously tells the drivetrain not to move, for example:

  
public Auto1() {
    addSequential(new DriveStraightGyroSPI(.5, 0, 36));
    addParallel(new StopDrive());
    addSequential(new WaitCommand(10));
    addSequential(new DriveStraightGyroSPI(-.5, 0, -36));
}

This way, you always have a command running that is telling the drivetrain what to do.

  • I’m assuming that if you ran the code as-is, with the wait command commented out, you would not get this error. Let me know if I’m wrong about that

The easiest way (though there’s likely a *better *way) to do what I think you want to do with the WaitCommand() is to have an init() method which simply remembers how long to run (e.g. saves the 10 to an instance variable, which I’ll call duration), an empty execute() function, and an isFinished() which returns (timeSinceInitialized()>=duration).

If you want the WaitCommand() to explicitly disable the drive train, it would also requires() the drive train and set the drive speed to zero in the execute().

Alright, I’ve added a new command (updated on github) to deal with that which should work but I still have the error with the DifferentialDrive motor helper. More specifically, when auto (and now teleop) is first enabled the error is printed four times and about five seconds after it’s enabled the driveStraight command begins. Then does not do it again until the code has been redeployed or robot has been restarted. Unfortunately, I do not know if the command works yet because the encoder we are using to test won’t return a value to the dashboard.

So it looks like you are calibrating your gyro in the initialization and cleanup of the drive straight command. Don’t do this. Calibrating the gyro takes a few seconds because it involves collecting a bunch of samples while the robot isn’t moving. That’s why you are seeing the autonomous take so long to actually start running.

The simplest option for calibration is to just do it once when the robot boots up. Be careful not to move the robot while it is happening!

More specifically: You are already initializing the drive train (and therefore gyro) in RobotInit() (line 34 of Robot.java). You should not need to do it again in the initialize() method of DriveStraightGyroSPI (line 43).