I’ve been learning command based programming for Java in FRC and I’ve been having problems with a digital sensor triggering a command when I don’t want it to. Our robot has a sensor to see if there is a game piece in our infeed. I want that sensor to debounce then go into a compliance position. My problem comes when I try to score. The sensor can still see the game piece and as soon as I let go of the scoring button it goes back into compliance. How can I prevent the incoming compliance commands from running while I am scoring? I know WPILib has conditional commands, but I haven’t found many in depth resources. Any information about conditional commands or other possible solutions would be greatly appreciated.
Once the digital input sensor triggers (say by changing to a true state) you want the state of the digital input to be ignored until the game piece is away from the sensor and the sensor “resets” and goes to false.
You need to wait for another event - the sensor going false - before again looking to trigger from a true state.
I suggest either a fixed timed timeout period or another trigger on the sensor going false that releases some sort of suppression of the undesired action until it triggers.
Rather then triggering a new command on digital input, I’d make a default command that looks at the sensor and runs the intake. As a default command, it won’t interrupt any other running command, so just make sure your store command doesn’t end until it’s done scoring. Another option is to make the score command not-interruptible, as long as that doesn’t cause other issues with your sequencing or error recovery. In all cases, make sure your commands require the correct subsystems.