Hoping someone on here can help out. Our team, 6808, is a second year team, and I am a first year mentor for software. We are stumped. For our command based robot code, we have a command to drive a given distance using our encoders when a button is pressed. The command executes fine once. After that, it seems that the command does not create a new command and call the constructor, so isFinished immediately returns true and won’t execute again unless the roboRIO is reset, or the code is redeployed. Any suggestions would be greatly appreciated.
Here is the code:
OI.java that creates the command on the button press, the command in question is the button press that creates the DriveToDistance2 command
That expains it. I didn’t realize the constructor would only be called once even with the “new” command. I’m new to java and FRC, is this behavior due to java or wpilib? I’m used to C++, “new” will allocate a new object and always call the constructor. Thanks for the help, it’s been driving me crazy for nearly a week!
The whenPressed is setup in a constructor, but is a listener and will fire every time your button is pressed.
Constructors are executed when an object is instantiated. That’s why the initialize and execute methods are so useful in commands. You wouldn’t try to call a constructor over and over again. You could rely on the initialize/execute methods, or write your own method that gets called from within the initialize or execute methods.