8 C
Canberra
Friday, July 25, 2025

swift – iOS CoreMotion getting acceleration in North/South East/West


This is perhaps too near this query however I hope not.

I am engaged on an iOS app the place I would prefer to get person acceleration in North/South and East/West. So I am utilizing CoreMotion with the .xTrueNorthZVertical body of reference. After rotating the accelerometer with the transpose of the angle rotation matrix it appears to work wonderful at first however then the built-in hint drifts off into nothing land. Which can be regular however I needed to test to see if I am doing something incorrect.

Begin motionManager

if self.motionManager.isDeviceMotionAvailable {
    self.motionManager.deviceMotionUpdateInterval = 1.0 / 50.0
    self.motionManager.startDeviceMotionUpdates(utilizing: .xTrueNorthZVertical)
            
    self.motionManager.showsDeviceMovementDisplay = true                
}

Then inside a timer I am getting and rotating the accelerometer with the next

// load the accel into SIMD for matrix multiplication
let userAccelSIMD = simd_double3(motionData.userAcceleration.x, motionData.userAcceleration.y, motionData.userAcceleration.z)

// get inverse of angle rotation matrix
let userAttitude = motionData.angle.rotationMatrix
let userAttitudeInverse = simd_double3x3(rows: [
  simd_double3(userAttitude.m11, userAttitude.m12, userAttitude.m13),
  simd_double3(userAttitude.m21, userAttitude.m22, userAttitude.m23),
  simd_double3(userAttitude.m31, userAttitude.m32, userAttitude.m33)
]).transpose
                    
// rotate acceleration into world body
let rotatedUserAccel = matrix_multiply(userAttitudeInverse, userAccelSIMD)

Under is a plot the place I combine that rotated accelerometer and evaluate it to the GPS factors. The plot additionally shows the cellphone heading for each nth accelerometer worth, we will see that the course of journey would not match the cellphone heading after some time.

enter image description here

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles