Page 1 of 1

Accelerometer Data in Object?

Posted: Tue Mar 12, 2013 10:31 pm
by elliebell370
Hi guys!

I am trying to create a moving graph of accelerometer data. In my stack, I have the following code:

Code: Select all

global ax, ay, az
on accelerationChanged ax, ay, az
   put "AccelX: " & ax & return & "AccelY: " & ay & return & "AccelZ: " & az & return into field "Accel"
end accelerationChanged
This works perfectly and updates the field with ax, ay and az constantly.

I also have a button "StartTracking" (with the same global variables called at the top) and calls mobileStartTrackingSensor "acceleration". I have a variable, "sCollect" which I use for the relative points of the line. I cannot find a way of "sending" ax, ay and az from the stack to the object so that they can be used. The global variable doesn't seem to be working as I initially had a test answer dialog to show me az, but it simply wrote the letters az instead of whatever variable was actually in az.

Any thoughts? Your help is much appreciated!

Re: Accelerometer Data in Object?

Posted: Tue Mar 12, 2013 11:28 pm
by Simon
Once again I start a post with...
I'm not completely sure of your request but...
Look up "points" in the dictionary.
"set the points of the selectedObject to myVertexes"

As for the globals are ax, ay and az globals? One thing to watch out for is a global variable should/might as well be listed at the top. and also listed in the object.
e.g. the card has a global ax the button script should have it as well:

Code: Select all

global ax,ay,az
on mouseUp
answer az
end mouseUp
Simon

Re: Accelerometer Data in Object?

Posted: Wed Mar 13, 2013 2:29 am
by dave_probertGA6e24
As well as the points (ax,ay,az) you should also grab a time of the change in acceleration - otherwise you are not going to be able to correctly map the changes over time.

If you only grab the ax..az info then the graph could show a change, but you don't know when that happened in relation to another change.

You should probably end up with 3 graphs - one for ax, one for ay and another for az. These can be created with a repeat loop (of ticks/seconds/minutes!) over the timeframe and use that for the 'x' part of a point and the 'ax' (etc) at the time for the 'y' part of a point.

Hope that helps a bit.

Dave

Re: Accelerometer Data in Object?

Posted: Wed Mar 13, 2013 5:12 pm
by elliebell370
Thanks for the help!

I should have mentioned that I am not having trouble graphing mock data -- only data from the accelerometer, but I appreciate the help on that front! :)

My issue seems to be exclusively with passing the accelerometer data into the objects.

I have tried a simplified version of the program. In the stack script, I have

Code: Select all

global xAccel, yAccel, zAccel

on accelerationChanged ax, ay, az
   put ax into xAccel
   put ay into yAccel
   put az into zAccel
end accelerationChanged
and I have one button with the following script:

Code: Select all

global xAccel, yAccel, zAccel

on mouseUp
   answer xAccel
end mouseUp
When I run it on the Android device and click the button, I get a completely empty dialog box. Any suggestions?

Re: Accelerometer Data in Object?

Posted: Thu Mar 14, 2013 3:24 am
by Simon
I built a test stack that is working on a device here.
accel_test.zip
LC 5.x
(1.57 KiB) Downloaded 197 times
You will have to hit the "Start" button before the accelerationChanged message will trigger.
Bunch of other buttons there, I think they are self explanatory.

Simon
EDIT: For some reason I have to hit the buttons a couple of times to get them to work.. Don't know why... Might be the writing to the screen causing delays.