gpt4 book ai didi

iphone - 检测 iPhone/Apple Watch 的物理运动

转载 作者:行者123 更新时间:2023-12-03 20:39:59 25 4
gpt4 key购买 nike

我正在尝试检测用户执行的移动(向右或向左)。我们假设用户开始时将 ARM 伸到前面,然后向右或向左移动 ARM (偏离中心约 90 度)。

我已集成 CMMotionManager,并希望了解通过 startAccelerometerUpdatesToQueuestartDeviceMotionUpdatesToQueue 方法检测方向。

有人可以建议如何在 iPhone 上实现这个逻辑,然后在 Apple Watch 上实现吗?

最佳答案

苹果提供watchOS 3 SwingWatch sample code演示如何使用 CMMotionManager()startDeviceMotionUpdates(to:) 来计算 Racket 运动中的挥杆次数。

他们的代码演示了如何检测一秒间隔运动的方向,尽管您可能需要调整阈值以考虑要跟踪的运动的特征。

func processDeviceMotion(_ deviceMotion: CMDeviceMotion) {
let gravity = deviceMotion.gravity
let rotationRate = deviceMotion.rotationRate

let rateAlongGravity = rotationRate.x * gravity.x // r⃗ · ĝ
+ rotationRate.y * gravity.y
+ rotationRate.z * gravity.z
rateAlongGravityBuffer.addSample(rateAlongGravity)

if !rateAlongGravityBuffer.isFull() {
return
}

let accumulatedYawRot = rateAlongGravityBuffer.sum() * sampleInterval
let peakRate = accumulatedYawRot > 0 ?
rateAlongGravityBuffer.max() : rateAlongGravityBuffer.min()

if (accumulatedYawRot < -yawThreshold && peakRate < -rateThreshold) {
// Counter clockwise swing.
if (wristLocationIsLeft) {
incrementBackhandCountAndUpdateDelegate()
} else {
incrementForehandCountAndUpdateDelegate()
}
} else if (accumulatedYawRot > yawThreshold && peakRate > rateThreshold) {
// Clockwise swing.
if (wristLocationIsLeft) {
incrementForehandCountAndUpdateDelegate()
} else {
incrementBackhandCountAndUpdateDelegate()
}
}

// Reset after letting the rate settle to catch the return swing.
if (recentDetection && abs(rateAlongGravityBuffer.recentMean()) < resetThreshold) {
recentDetection = false
rateAlongGravityBuffer.reset()
}
}

关于iphone - 检测 iPhone/Apple Watch 的物理运动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38161365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com