I will be using an Arduino as a bridge between a computer high-level Java client and some low-level hardware computing units (e.g. other Arduinos). I need to find a solution to periodically communicate in both ways. It should be possible to send digital, analog inputs to the PC and receive digital, analog outputs from the PC via serial.
I have very specific requirements for my project to work:
Lowest possible latency in both ways. High latency would cause instability of controlled systems.
Extremely constant, possibly user-defined update period. Varying sample rate would cause inaccuracies in the control.
I need a very fast solution possible for update frequency of 100 Hz and higher.
So far I have tried to send data via Firmata to my java client using time interrupt.
ISR(TIMER1_COMPA_vect) {
Firmata.sendAnalog(analog, analogRead(analog));
}
The messages however don't come at a very constant rate and are sometimes held up for twice the sample period or more which is unnaceptable. For higher frequencies this happens even more often. I suspect some kind of a buffer. Do you have any idea where should I look for bottlenecks? Would it be benefiting to design my own communication protocol and ditch Firmata?
EDIT: Look at the attached diagram . Blue lines are "inputs", green lines "outputs". Right now I am trying to design the "Arduino (Bridge)"

millis()anddelayto help avoid variance in the sampling rate. For latency, IMHO it'd be better to get a very high baud rate. You could reduce errors with this library here.millis(). It'll also be far more deterministic regarding timing constraints. Of course, if you're including the USB's latency (anywhere from 10-200 mS, unpredictable and uncontrollable), you're probably SOL.