|
More resolution than 20ms
We need to watch a sensor, then cut a motor off 100ms later.
Right now we are watching the sensor, waiting for it to trip, set t0, and then watching the elapsed time (System.currentTimeMillis() - t0), and returning true from isFinished() when the elapsed time > 100ms (not doing this all at once, it happens over successive calls to isFinish(), as it should be). All as advertised, dead-simple, and worked the first time...
Doing this in isFinished() *is* introducing wobble in the 100ms: because we only get the CPU every 20ms, we could be as little as 0.00000001ms or much as 19.9999999999ms late in seeing the sensor go, and would could be as little as 0.00000001ms or as much as 19.9999999999ms late in seeing the time elapse. We can adjust for consistent delay, but the +/- 19.9999999999ms overall is something I'd like to tighten up.
I know the PID code starts it's own thread, so we can use that as a model if we want to have a separate (tighter) thread handle this.
Has anyone else done this simpler-than-PID case already? I'm willing to work from scratch using the PID code as a base, but am resistant to reinventing wheels...
Also, do we have access to any interrupt and timer capability on the FPGA from Java that would be helpful here?
Last edited by fovea1959 : 13-02-2014 at 11:28.
|