FRC5892 / 2021-Infinite-Recharge-2.0

Other
1 stars 0 forks source link

DriveForwardTimed blocks other commands from running #23

Closed Quantaly closed 3 years ago

Quantaly commented 3 years ago

https://github.com/FRC5892/2021-Infinite-Recharge-2.0/blob/727d4510f3a098cd120b105c9afb0785f5f91b08/src/main/java/frc/robot/commands/DriveForwardTimed.java#L25-L33

Refer back to #2 if you need a refresher on why this code is awful. TL;DR: if you try to do anything else while DriveForwardTimed is running, it won't work, because the while loop in initialize() prevents the command-based framework from multitasking, which is the whole point.

You literally don't even need to put timeout logic in your commands; it would probably be easier just to have a DriveForward command that never ends (but doesn't block either!!) and then use that withTimeout() decorator on instances of DriveForward. So, like, the one line I could find where you're instantiating DriveForwardTimed

https://github.com/FRC5892/2021-Infinite-Recharge-2.0/blob/727d4510f3a098cd120b105c9afb0785f5f91b08/src/main/java/frc/robot/RobotContainer.java#L85

would become something like

    driveForwardTimed = new DriveForward(driveTrain).withTimeout(Constants.DriveTrain.DRIVE_FORWARD_TIME);

This isn't a super pressing issue at the moment because (afaik) you never try to multitask with DriveForwardTimed but it could lead to some nasty issues if you ever try to.

Quantaly commented 3 years ago

Here's the nicer documentation on withTimeout() and command decorators in general

memtech3 commented 3 years ago

Yeah this is just a simple sample command from the tutorial I should probably get rid of it