Hopper Capacity Detector
Disclaimer: WIP and untested; tune thresholds on your robot. Custom code built on WPILib APIs.
Code (Java)
public class HopperCapacity {
private final DigitalInput beam;
private final Timer fullTimer = new Timer();
private final double fullSeconds;
public HopperCapacity(int beamDio, double fullSeconds) {
this.beam = new DigitalInput(beamDio);
this.fullSeconds = fullSeconds;
}
public boolean isFull() {
if (beam.get()) {
if (!fullTimer.isRunning()) fullTimer.start();
return fullTimer.hasElapsed(fullSeconds);
} else {
fullTimer.stop(); fullTimer.reset();
return false;
}
}
}
Usage in indexer: if isFull() is true during inactive hub, stop intake; when hub goes active, switch to burst.