Command-Based Auto Not Running Consistently

We recently started using command-based Java for our robot programming, and, in autonomous, occasionally the robot “skips” a command and goes right to the next one. They are always drivetrain commands, such as skipping a turn, skipping a drive forward, etc. However, this seems to be happening randomly, and can sometimes be corrected by re-starting the robot and driver station, but this does not always work. My code for the robot is here: https://github.com/AtticusDrakeChristianson/FRC_2022Robot_Command
The issue happens with both the ThreeCargoAuto and the FiveCargoAuto when run (but again, only randomly). There is an error on the driver station about the drive train not being updated enough, could this be causing the issue? I tried adding pauses between commands, but that did not seem to work. How could I go about solving this?

For your turn to angle and drive to distance commands, I would add monitoring of the values are checking (gyro angle and encoder distance) to isFinished. Watch for occasions of isFinished returning true the first time it is called. That would look like a “skip”.

In both cases, you are resetting the sensor in initialize and these are CAN connected sensors. I have seen cases where round trip latency has caused issues like this. That is, the first time or two that you read back the sensor value, you see the pre-reset value rather than 0.

1 Like

Looking at ur code briefly I would double check that ur closing parentheses for the parallel command groups are correct. Also I’d go step by step and comment out all but one step of the sequential command group to try to narrow down if it’s a specific line causing the issue.

Also do some work to make sure that the commands can all be run in succession, multiple times exactly the way you think they should.

For example, we had an odd bug in a turn command that could be run three times in a row, but not four, depending on some initialization steps.

If your commands are 100% accurate in repeatedly performing their actions individually, then start to chain them together in sequences one by one, to see which sequence is the offender.

1 Like