midtownrobotics / 2024-Offseason

Other
0 stars 0 forks source link

Rewrite beambreak subsystem #76

Open Gray486 opened 1 week ago

Mysterium422 commented 1 week ago

BeamBreak.java should have 3 methods:

isBroken(): Returns true if the beam break has been broken for at least 2 cycles. Returns false if the beam break isn't broken, the beam break isn't working, or the beam break was broken for only 1 cycle.

getBrokenTime(): Returns a double - the amount of time (in seconds) the Beam Break has been broken for (based on isBroken()). Use Timer.getFPGATimestamp. Should return 0 whenever isBroken is false.

Note that these will require you to use the BeamBreak periodic function in order to keep track of if the beam break has been broken for multiple cycles or not.

BeamBreak should be passed into the RobotState constructor, along with the controllers.

Create a function called setControllerRumble. This should update the controllerRumble based on the isBroken() and getBrokenTime() functions from before. Also note that rumble should only happen when RobotState.isTeleop(). <- Wpilib RobotState not our RobotState. An interesting point here is that you don't want to setControllerRumble every cycle in case of it ruining the i/o system (most likely it is already resilient to this, but its always safer to do the check yourself). Therefore, you have two ways to do this. This function will be run at the end of updateState().

1) You can keep track of the previously rumble set within RobotState, and not call setRumble if its the same value. 2) A slightly more rigorous way would be to extend XboxController and override the setRumble function to always do this check.

It's up to you but if you can figure it out, the 2nd way is just a better principle in general, and is the reason why OOP can be so powerful.

Lastly, within State.Intaking, if isBroken is true, switch to State.NoteHeld