mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-05 03:21:40 +00:00
Use Timer object to calculate FPS
This commit is contained in:
@@ -24,19 +24,12 @@ import org.photonvision.vision.pipe.CVPipe;
|
||||
public class CalculateFPSPipe
|
||||
extends CVPipe<Void, Integer, CalculateFPSPipe.CalculateFPSPipeParams> {
|
||||
private final LinearFilter fpsFilter = LinearFilter.movingAverage(20);
|
||||
|
||||
// roll my own Timer, since this is so trivial
|
||||
double lastTime = -1;
|
||||
private final Timer timer = new Timer();
|
||||
|
||||
@Override
|
||||
protected Integer process(Void in) {
|
||||
if (lastTime < 0) {
|
||||
lastTime = Timer.getFPGATimestamp();
|
||||
}
|
||||
|
||||
var now = Timer.getFPGATimestamp();
|
||||
var dtSeconds = now - lastTime;
|
||||
lastTime = now;
|
||||
var dtSeconds = timer.get();
|
||||
timer.reset();
|
||||
|
||||
// If < 1 uS between ticks, something is probably wrong
|
||||
int fps;
|
||||
|
||||
Reference in New Issue
Block a user