0

Using iOS Core Motion I am reading the GForce applied to a device, however if the device is not completely level then the readings are not as accurate.

enter image description here

Say I want the force applied on the Y axis but the phone is not 100% flat. Is there a calculation that can be done using the other axis to correct the figure account for the slight angle?

Darren
  • 10,182
  • 20
  • 95
  • 162
  • 1
    Just project the g-force vector from the sensor onto the rotated Y-axis of the device? – meowgoesthedog Dec 29 '17 at 18:25
  • That sounds like something i'd hear on the starship enterprise. Any demo's of this around? – Darren Dec 29 '17 at 19:10
  • Not sure why you must ridicule a description of a simple geometrical operation. Are you able to compute the Y-axis vector? If not, there are plenty of tutorials to do so - the answers on [this SO post](https://stackoverflow.com/questions/24728022/obtain-absolute-rotation-using-cmdevicemotion) may help you. – meowgoesthedog Dec 29 '17 at 19:32
  • Sorry, I don't mean to ridicule. Geometry is foreign to me. I shall have a look at that answer. My overall goal is simply to get the force of a travelling car, without having to worry about the device being perfectly level and angled correctly. – Darren Dec 29 '17 at 20:23
  • Here are two other helpful links. [(A)](https://forestgiant.com/articles/ios-core-motion/) - initialising a `CMMotionManager`, which `deviceMotion` property. [(B)](https://developer.apple.com/documentation/coremotion/cmdevicemotion) - `deviceMotion` is of type `CMDeviceMotion`, which has two properties `attitude` and `userAcceleration`, which are the rotation and linear acceleration (minus gravity) respectively. I'm not sure which frame the acceleration vector is in, that of the phone or the "world"; the link in my previous comment might answer that. – meowgoesthedog Dec 29 '17 at 21:04
  • just a silly question do you got 3D accelerometer or just scalar value? What does it mean `readings are not as accurate` ? If the `G` is a **3D** vector and its absolute value is not around `9.81` that means your device is accelerated by something (vibration, movement etc). If it is near zero that means your device is substracting `GF` on its own or free falling (but I doubt you got such case). If you got just 1 value instead of vector than you need to know the phone orientation to invert the projection of G force into the device axis. see https://stackoverflow.com/a/19764828/2521214 – Spektre Dec 30 '17 at 09:33
  • iOS provides 3 values. x, y & z. It appears that it’s showing 1.0 for gravity as that’s what shows for z when placed flat on a table. By incorrect results, I mean when traveling in the direction of y and accelerate, I get a reading. If I tilt the phone up slightly and do the same, the reading is different, obviously as the forces are applied differently to each axis. I was hoping there was a formula I could use to combine the 3 axis data to give an overall G-Force figure in the direction of travel regardless how the phone is rotated. – Darren Dec 30 '17 at 11:12
  • 1
    @Darren yes there is `acc = sqrt(ax^2 + ay^2 + az^2)` but you need to use only stable values (filter out too much changing values) to ignore the movement forces. – Spektre Dec 31 '17 at 10:45
  • Thanks @Spektre, this looks exactly what I was after. Using this calculation I get a constant 0.996-1.002 reading regardless of how the device is sitting, which is accurate enough for me. Then when I move the device in any direction I get a greater figure. – Darren Dec 31 '17 at 12:33

0 Answers0