Data rate implementation

Comments & issues
Post Reply
emeath
Fresh meat
Posts: 1
Joined: Sat Oct 14, 2017 10:34 am
Contact:

Data rate implementation

Post 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!
User avatar
mparadis
Site Admin
Posts: 960
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Data rate implementation

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 28 guests