Android Tutorial Orientation and accelerometer

MiniDemonic

Member
Licensed User
Longtime User
Is it possible to track the movement of the phone, rather than the orientation?

Like if I move my phone to right, can I track that movement? Think of PSMove or WiiMote, move the phone in different directions to make stuff happen.
 

SlavaVB

Member
Licensed User
Longtime User




How do you import the PhoneOrientation class in basic4android?
 

SlavaVB

Member
Licensed User
Longtime User
You should try to only refresh the parts required.

Refreshing the whole screen each time can be done. In your code you also drew the whole screen each tick.


i figured out why it didnt work... i was in a loop when doing msgbox, works great now!
 

latcc

Banned
I notice that the accelerometer readouts (x,y,z) are not discrete values but are in some way interactive. When you move the device in one axis only the other two axes are changed. So it is not possible to use the (as an example) z axis data to give info on how far on that axis the device has moved, without interfering with the othe two axis values.

Also the values for X,Y,Z are offsets from some initial value, rather than genuine acceleration values. An accelerometer value would always return to zero when the device returns to 'rest'.
 

jjmcc2

New Member
Licensed User
Longtime User
I have two Android device to test with a Xoom and HTC EVO. When I run the Sensor program I get different readings with landscape. Does anyone know this true for all phones and tablets?

Example:
Xoom when I tilt forward and back Y value changes

EVO when I tilt forward and back Z value changes


Xoom when I tilt Left or Right Z value changes

EVO when I tilt Left or Right Y value changes
 

metrick

Active Member
Licensed User
Longtime User
Light Sensor:
My Samsung Galaxy S only show the following light readings;
6,5000,9000,&15000.
6-dark area
5000-light on
9000-on sunny day in the shade
15000-Sunny day(outside) point phone toward the sun
Is there a way to get a better light sensor reading from the phone?
eg increment of 100 between the above numbers base on intensity of light.
 

Gsquared

Member
Licensed User
Longtime User
Sensor fusion supported

Hi Erel,

Thanks for your useful sensor program. Are there plans to support the "fused" sensor types, "TYPE_LINEAR_ACCELERATION", "TYPE_GRAVITY", "TYPE_ROTATION_VECTOR"? Support for these types were introduced in API 10. These are supposed to give much better results for determining rotation angles.

Thanks,

G^2
 

Gsquared

Member
Licensed User
Longtime User
Sensor fusion supported

That did the trick!

Thanks Erel for your quick and helpful response.
 

booster55

New Member
Licensed User
Longtime User
I have a problem with the light sensor:

B4X:
Sub Activity_Create(FirstTime As Boolean)

Dim ps As PhoneSensors
   ps.Initialize(ps.TYPE_LIGHT)   
   ps.StartListening("Sensor")

End Sub

Sub Sensor_SensorChanged(Values() As Float)

Dim s As PhoneSensors
s=Sender

ToastMessageShow(s.TYPE_LIGHT, False)

End Sub

The sensor itself seems to be monitored: I do get a ToastMessage whenever the light changes, however this ToastMessage always just shows "5" and I don't get why. Is something wrong with my code? I have a Galaxy SII and it is certainly capable of measuring the light. I tested the light sensor with an app called "AndroSensor" from the market and in this app, I can see more values coming from the light sensor.


EDIT: Dammit, I'm amazingly stupid...


B4X:
Sub Sensor_SensorChanged(Values() As Float)

ToastMessageShow(Values(0), False)

End Sub

And it works like a charm...
 
Last edited:

Robert28

New Member
Licensed User
Longtime User
Hi all,
first off all, I must say that I am new to android and B4A :sign0013: . I tried the example above wich is running without problem on a samsung ace.
I am just astonished by the fact that, with the phone perfectly still, the datas are always changing. (Acc, Mag and orientation) and, for the accelerometer are not 0 (ex: x=0.153, Y = 0.153, Z = 9.807). Strange for a phone on a table... Is it coming from bad sensors?

By advance, thanks!

Best regards,

Robert.

BTW : what are the units for the accelerometer? m/s² ?
 

xmayeur

Member
Licensed User
Longtime User
Can you please explain the values returned by the accelerometer? According to the library documentation, it returns meters per square seconds. OK. But, if my phone stands still on a table, I expected to get zero values returns for the three X-Y-Z axes (or does it measure the movement of our galaxy in the universe in expansion?). I get the impression that the sensor returns some kind of inclination of the phone with respect to one of the axis, which is not an acceleration... Do I miss something?
 

klaus

Expert
Licensed User
Longtime User
The accelerometer is an absolute accelerometer which measures also the earth gravity.
So if you put your device flat on the table the z axis should show values around 9.8 m/s2.
If you turn it upside down you would see a value about -9.8 m/s2.

You could have a look here
Sensors Overview | Android Developers

Best regards.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…