I'm not that familiar with how the sensor works, but judging from the
values you report, i looks like the device is not entire horizontal or
vertical.

Your computeRealForce hovers around 0.4 (horizontally) or -1
(vertically).

I guess you have to find a proper 'baseline' against which you can
measure any deviation. In the horizontal case that would be around
0.4, in  the vertical case that would be around -1.

However, it could be that your device was not precisely horizontal or
precisely vertical. How would you know the 'baseline'? I don't know...
Maybe 0 or -1 is precisely horizontal or vertical and you can't assume
that your device will be ever exactly horizontal or vertical...

I guess you have to measure over a period of time and see what the
deviation is. If it's small enough, your phone is in rest.

On Jan 31, 4:19 pm, kretes <kretesena...@gmail.com> wrote:
> There has been a few discussions about it, but there is still not a
> good solution.
> Simple problem - recognize when the device is laying somewhere not
> moving (in relation to earth) and when is moving.
> Accelerometer seems to be a good sensor to use.
>
> First suprise came to me, when I logged data from the sensor events.
> When the device (htc hero) is laying on the table - the values are
> changing!
> sth. like
> -0.7, -0.7, 10.1
> -0.6, -0.8, 10.0
> and so on - fluctuating
>
> I haven't expected that, but let's go on - I thought I woudl compute
> the real force, and went with
>
> private double computeRealForce(SensorEvent event) {
>                 return Math.sqrt(Math.pow(event.values[0], 2)
>                                 + Math.pow(event.values[1], 2)
>                                 + Math.pow(event.values[2], 2))
>                                 - SensorManager.GRAVITY_EARTH;
>
>         }
>
> very similiar approach as seen 
> inhttp://github.com/commonsguy/cw-advandroid/blob/master/Sensor/Shaker/...
> and similiar 
> inhttp://www.anddev.org/example_detecting_-und-quotshake-und-quot_with_...
>
> and the computed value also fluctuates,
> 0,35
> 0,39
> 0,4
> but I can apply force treshold like 0,5 as a kind of filter and
> everything is ok.
>
> But when I put my phone to stand vertically - suddenly my computed
> force turned out to be
> -1,01
> -1,05
>
> I give up - I don't know what is the good enough solution -
> the one that would give around zero value when the device isn't moving
> in relation to earth - is there any?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to