Page 1 of 1

Data rate implementation

Posted: Sat Oct 14, 2017 11:07 am
by emeath
Greetings,

I have an doubt about the data rate implementation. It's my duty as a programmer to make my program wait the time defined by the data rate to update a new value or can I leave this task for the internal phidget's implementation?

I'm working with an Phidget Spatial 1056. I need to get all 3 axis accelerometer and gyroscope values. Summarizing, in pseudo code, this is my doubt:

in the example below I'm working with only one axis

a)

while(true)
{
getAccelerometerValue('axis_0');
getGyroscopeValue('axis_0');
wait(8000); //working with the deafult value 8ms
}



b)

while(true)
{
getAccelerometerValue('axis_0');
getGyroscopeValue('axis_0');
}

which of the options is true?

Thanks!

Re: Data rate implementation

Posted: Mon Oct 16, 2017 7:41 am
by mparadis
When you call a function like getAccelerometerValue, you are polling for the most recent data point in the accelerometer. In this sense, you could use a 'wait' statement like you've done in option A, but a much easier and cleaner way to do this would be to use the OnAccelerationChange event handler. If you use the event handler, every time data comes in (on the data interval you've selected), you'll be able to execute a piece of code and use the data.

If you want to get acceleration and gyroscope data that is already synchronized, you can use the OnSpatialData event handler, which is part of the "Spatial" API.