frc2399 / 2022-Season

This is our NEW repository for the 2022 Season.
Other
0 stars 5 forks source link

Add timeouts to commands as needed #62

Open hschilling opened 2 years ago

hschilling commented 2 years ago

Make use of the the withTimeout decorator

edf42001 commented 2 years ago

Why use a timeout? In case a command gets stuck. This occurs when isFinished() does not finish. If you programmed the robot to go 40 inches, but it goes 39 due to friction, the command won't end and no other commands in your auton sequence will run.

Another rare case is when something goes horribly wrong. If you are turning to an angle and the gyro stops working, the robot will keep spinning and spinning and the command won't stop.

A timeout adds a second isFinished() condition. But you want to consider: in the first case, it would be reasonable to continue auton, in the second, it would be better if the robot just stopped moving entirely.

Here are two ways to add timeouts:

Manually: Add code to isFinished() to check a timer. This would affect all instances of this command .withTimeout() decorator. Specific instances of any command can have a timeout added to it: https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html#withtimeout

There are definitely cases where a timeout will help a stuck robot. But, it might be a better approach to do much testing to assure commands finish correctly. Extra complexity can lead to problems: what if the timeout finishes before the robot is done driving? (or shooter is done spinning, etc).

One idea is as follows: in DriveForwardGivenDistance, the P controller means speed goes to 0 as the robot approaches the target distance. If a small constant value is added here (0.2 / -0.2 depending on robot direction), this would give the robot a small boost to overcome friction. Of course, this might not be needed, you should test it first :)