0
votes

I'm trying to detect the direction of motion of an android device using the accelerometer. I've removed the gravity components from the accelerometer output values and deducted the angles.

So I am able to get the direction of motion but I also get arbitrary angles momentarily. Like when I stop moving the device.

Any suggestions how I could filter those angles out?

EDIT: I've somewhat been able to solve this by taking the mean of the current and past values. Another problem that persists is that initially for a few moments, the accelerometer reports values in the opposite direction of motion.

1
When you stop moving the device it ceases to have a direction of motion, so what angles do you want it to report? - Beta
@Beta None. Thats's the point. I don't want it to report any angles. But I've been able to solve that problem by taking the mean of the current and a few past values. New problem at hand is that when I start moving, I get acceleration values in the opposite direction initially. - timemanx

1 Answers

0
votes

That's a typical trouble with accelerometers... Initially there's no any solution because of the inertia, etc... But You can try using some kind of "integer controller".

Another possible solution is detecting abrupt changes on the acceleration and interpret them as changes of direction, I mean, for example if you have the acceleration on the X edge (Ax).

while(1){
Ax = readAx();
if(changeSign(Ax)){  //From + to - or - to +.
      //Do what ever you need, for example if sign is changed and keep on it then is that the mobilephone is been moved in the other direction. Else if it's acceleration is close to 0 it means that the device has stopped
}else{
     //The device keep moving on the same direction.
}
}

Feel free to be creative. There are many ways to manage a solution depends on your target.

I hope it helps.