0

I am trying to make my image movement smoother. I know this question has been asked many times, but there is one thing that I am more interested and which doesn't come up in other questions. I am using sensor acceleration value straight for moving bitmap. I am aware that this method limits me between around -9.8 and +9.8 but this is exactly what I want, I want my bitmap to move only as much. I read about low-pass filter, but as far as I understood it is useful for moving the bitmap all around the screen, and in my case it is totally unnecessary. So am I right? Should't I get smooth movement if I use accelerometer values straight for moving bitmap?

Here is the code for getting values from my accelerometer. Its type is TYPE_ACCELEROMETER

public void onSensorChanged(SensorEvent event) {

        xAcceleration = event.values[0];
        yAcceleration = event.values[1];

}
Rohit Malish
  • 3,209
  • 12
  • 49
  • 67

1 Answers1

1

Did you mean a highpass filter? Did you actually try a lowpass filter?

Regardless, the accelerometer is definitely noisy below a certain threshold. So yes, you should expect to see 'rough' not 'smooth' numbers when looking at the raw data. A highpass filter should help. I've also seen decent results just computing averages over an adjustable sample range.

Another thing to try: don't update your bitmap's position every time you get new accelerometer data. That is, decouple the method that updates your bitmap's position from onSensorChange. You should be able to update your bitmap's position less frequently than the sensor data coming from onSensorChange ... and that should make it easier to compute smooth position changes.

There's also lot's of good suggestions here: Filtering accelerometer data noise

Community
  • 1
  • 1
newbyca
  • 1,523
  • 2
  • 13
  • 25
  • But wouldnt updating my bitmaps position less frequently make it just slower? Because I want my image to move as fast as possbile and as smooth as possible. – Rohit Malish Sep 03 '12 at 18:33
  • 'But wouldnt updating my bitmaps position less frequently make it just slower?' - Not necessarily, it only needs to be updated frequently enough that it *appears* smooth. Either way, coupling position updates to raw data from onSensorChange will definitely result in 'noisy' motion. – newbyca Sep 03 '12 at 18:38
  • Sorry, I have some really old sample code on exactly this problem (from Donut!) ... can't find it at the moment. Sure someone else will post some. – newbyca Sep 03 '12 at 18:40
  • Could you link it here when you find it? Because I really need some example – Rohit Malish Sep 03 '12 at 18:42