I'm build an app for mountain biking, and I would like to estimate the ground slope using the phone'

Rebecca Villa

Rebecca Villa

Answered question

2022-07-12

I'm build an app for mountain biking, and I would like to estimate the ground slope using the phone's integrated accelerometer so that I can adapt my pedaling effort based on the current slope.
I took the Y-axis value of the accelerometer and converted it to degrees, using a notion abs(y-axis) * 90 with a offset. So, for example, if the accelerometer reads 0.5 or -0.5 on the Y-axis, that's converted to 45°. If I zero out the accelerometer, that 45° is now considered as 0°, and any frontal movement is negative and back movement is positive. I use that value for slope calculation.
Now, that works perfectly fine when standing still. When I angle the phone at 45° the slope is 100%.
But, problems arise in the real world. Since I'm using a accelerometer for my angle detection, readings when hitting potholes and bumps in the road go all over the place. One second I read 80%, the next -300%, and so on.
What can I do to smooth out the readings and make them semi-accurate?
I could try to discard any invalid value, such as anything +-20% of slope and average that over 10 seconds, but I feel that would be inaccurate.
I was looking into the Kalman filter, based on a thesis on slope detection using an accelerometer for Scania trucks, but the jerking of a truck is much less violent than that of a mountain bike.
What can I do to predict and smooth out sensor values over time?

Answer & Explanation

isscacabby17

isscacabby17

Beginner2022-07-13Added 13 answers

The easiest way is to simply low pass filter it to get rid of frequencies that you are not interested in. For example, let's say that on most roads and trails, the inclination can only change at α Hertz. Think of riding a bicycle on a sinusoid with a certain frequency. How high of a frequency sinusoid do you think you will be navigating? Even if you don't know the value, you can start with a ballpark, say 5 Hertz (that sounds like a lot) and roll back.
θ ^ ( k ) be an estimate of your inclination at time k,
and θ a c c e l ( k ) be the measurement. Then from your estimate, chop off everything above a frequency of w c :
θ ^ ( k + 1 ) = ( 1 w c T s ) θ ^ ( k ) + w c T s θ a c c e l ( k ) ,,where wc is the cutoff frequency in Hz and Ts is the sample rate. I think you can get about 50Hz sample rate from Android phones. That depends on your device.
The Kalman filter route is more complicated and its performance comes when you know more about the problem. You need a model for your movement (can you tell me what your inclination will be for the next ten seconds if I gave you your correct inclination now and removed the accelerometer?), and noise modeling (can you tell me how much noise on the accelerometer is because of the fact that any movement means the accelerometer is no longer measuring gravity?).

Do you have a similar question?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?