0

all.

So basically I'm trying to calculate acceleration in g force using accelerometer. For this I decided to go with Linear accelerometer (because I'll be testing car driving behaviour) with low pass filter.

Code for implementation is found here: code

So now I get x, y, z values. What I want to do is calculate G force using following formula:

sqrt(x*x + y*y + z*z) / 9.8

Whenever I walk I get fgorce from 0.3 to 0.6 g force, but I'm not sure if this is the correct way to calculate gforce. I tried to do test drive and whenever I did a hard brake, I could not get negative acceleration (what I should get, whenever I do hard brake). Also, getting 0.3 - 0.6 gforce isn't too much?

enter image description here

I've a feeling that calculated gforce is too big. Is that true? Is there something missing in my solution?

General idea is to catch not only acceleration, but also deceleration - which should be negative.

MaaAn13
  • 264
  • 5
  • 24
  • 54
  • 1
    `sqrt(x*x + y*y + z*z)` produces a magnitude. It cannot be negative. `sqrt()` cannot return a negative number. You need to measure the acceleration with respect to some _axis_. See [here](https://stackoverflow.com/questions/58959443/how-to-get-only-horizontal-acceleration-in-accelerometer#comment104179149_58959443). – greeble31 Nov 25 '19 at 17:34
  • @greeble31 Thanks for pointing out that my formula produces a magnitude. From your link I understood that what I need is a horizontal acceleration? Well, that includes sqrt() which would still result in non-negative number, right? Maybe small example code would help me better to understand. Sorry, this has been a long night, haha – MaaAn13 Nov 25 '19 at 19:47
  • That link is not going to directly solve your problem; I understand. I don't have any good examples that will give you exactly what you're looking for. What I recommend is to dump the x/y/z acceleration values as you move your phone with your hand, and try to gain an understanding of exactly what they mean. That is just the first problem, of many, you will have to solve. I can't tell if your library produces accelerations in device coordinates, or world coordinates. If the coordinate system isn't appropriate, you might have to abandon that library right off the bat. Good luck. – greeble31 Nov 25 '19 at 20:26

1 Answers1

0

"I've a feeling that calculated gforce is too big"

Looks like you need some way to check and calibrate. IS it possible to tilt the accelerometer 90 degrees ? You should be geting a readout of exactly 1G absolute.

maybe after this you could change the sign of the sqrt result if the sum of x+y+z is negative.

JEVBR
  • 26
  • 3