rotation sensor reading returns noise

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rtfuller
Posts: 4
Joined: Mon Jun 24, 2013 12:27 am

rotation sensor reading returns noise

Post by rtfuller » Mon Jun 24, 2013 12:39 am

I'm trying to monitor the angle of the iphone as it turns. I'm using mobilesensorreading("rotation rate", true) and the data that comes back is just noise. The accelerometer, and heading works, but just noise from the gyro's. Any suggestions?

Code:


on updateScreen
if sRunning is true then
put the long seconds into tFrame
put tFrame into field "time"
--Get sensor readings
put mobileSensorReading("Acceleration",true) into tAccelArray
put mobileSensorReading("Heading",true) into tHeadingArray
put mobileSensorReading("Rotation Rate",true) into tRotArray
--Calculate time period
put tFrame- gOldTimeStamp into deltaTime
--calc change in rotation
put 180/pi*tRotArray[z]* deltaTime into deltaAlt
put 180/pi*tRotArray[x]* deltaTime into deltaAz
--add change to last angle
put gCurrentRotAz + deltaAz into gCurrentRotAz
put gCurrentRotAlt + deltaAlt into gCurrentRotAlt
--update time
put tframe into gOldTimeStamp
--calculate angles using accelerometer
put 180/pi *atan2(tAccelArray[z],tAccelArray[y]) into newAlt
put 180/pi *atan2(tAccelArray[x],tAccelArray[y]) into newAz
--update screen
put round(gCurrentRotAz,1) into field "RotAz"
put round(gCurrentRotAlt,1) into field "RotAlt"
put round(newAlt,1) into field "AccelAlt"
put round(newAz,1) into field "AccelAz"
put tHeadingArray["true heading"] into field "Heading"
put round(tHeadingArray["true heading"],1)&&round(tAvRot[Az],4)&&round(deltaAz,4)&&round(gCurrentRotAz,2)&return before field "log"

end if
end updateScreen

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: rotation sensor reading returns noise

Post by sturgis » Mon Jun 24, 2013 2:19 am

Does your device have rotation sensors? Check with mobilesensoravailable("rotation rate")

rtfuller
Posts: 4
Joined: Mon Jun 24, 2013 12:27 am

Re: rotation sensor reading returns noise

Post by rtfuller » Mon Jun 24, 2013 2:54 am

Yes it has rotation sensors. If I use the on rotationRateChanged xValue, yValue, zValue structure, I get reasonable data. However this only updates when the rotation rate changes. I should be able to get the rotation rate on a periodic basis.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: rotation sensor reading returns noise

Post by Dixie » Mon Jun 24, 2013 9:18 am

To get a 'sensor' reading when you want it instead of waiting for the periodic updates... use 'mobileGetSensorReading'... then you can call the change in the rate of rotation when you want it and set your own time periods if you employ the 'send' command as well...

rtfuller
Posts: 4
Joined: Mon Jun 24, 2013 12:27 am

Re: rotation sensor reading returns noise

Post by rtfuller » Wed Jun 26, 2013 5:25 am

How would one use the "send" command?

Post Reply