We are in the process of setting up a lab experiment in which an inverted pendulum mounted on a cart is to be swung up by a feedback controller. Measurements should be taken every 7ms, and the control signal is to be transmitted every 70ms.
We chose to implement the controller (in C) on Phidgets' single board computer, which runs Debian Linux (SBC3, see http://www.phidgets.com). The measurements are received by interface cards (also bought from Phidgets) which are connected to the SBC via USB.
Problems:
A) We are currently unable to schedule measurements so that they are taken every 7ms. In fact, using the sleep command of C our sampling times vary wildly between 3ms and 15 ms. That's a problem, since our observer (for the angular velocity of the rod and the cart's velocity) is designed for a fixed sampling rate. We have verified that the computational resources required by the controller and the observer are not responsible for these variations.
B) We are also unable to transmit the control signal on time, as it happens that the controller is unexpectedly inactive for at least 200ms. Increasing the priority of the process that runs the controller relaxes the problem somewhat, but the "dead times" are still too long and too frequent to successfully run the experiment.
Questions:
1) What are the chances that we can solve the problems described above by installing a suitable real time linux system on our SBC? Is there a specific OS you can recommend?
2) Is it a problem that the measurements are transmitted via USB to the SBC? If so, is it possible to tune the USB interface so as to better comply with real time requirements?
3) If the setup we are currently using (SBC plus interfaces via USB) turns out to be inappropriate for the above experimental setting, what alternatives could you recommend?
Thanks.