Check out the javadoc for the
whileHeld method. It might not be doing what you expect.
whileHeld will repeatedly call the command's
start method (50 times a second).
The start method will add the command to the scheduler. In the command based project, the scheduler is the bit of code that is responsible for stepping all active commands through their steps of execution [initialize(), execute(), isfinished(), end()].
The comment on the start() method is worth reading:
Quote:
|
Note that the command will eventually start, however it will not necessarily do so immediately, and may in fact be canceled before initialize is even called.
|
Instead of using the whileHeld method to keep a motor moving while the button pressed, I would instead suggest using the whenPressed and whenReleased methods to kick off a command
once for the pressed and release events. Since your commands are set up to never finish executing, this single instance of the command that is scheduled will continue to run until another command comes along that requires the subsystem specified.
Code:
ForksUp.whenPressed(new LiftForks());
ForksUp.whenReleased(new StopForks());
ForksDown.whenPressed(new LowerForks());
ForksDown.whenReleased(new StopForks());
Note that StopForks is a new command that you will need to make that should call the stop() method for the ForkMotor subsystem. The StopForks method may also be a good one to specify as the default command for the subsystem (see the initDefaultCommand() method comments). Generally you don't want things moving around.
Other than the use of whileHeld, I don't see any other glaring errors in your code.