Hello everyone,
I'm coming to you because I'm having a little trouble finding the code to know the movement of the Apple Watch. I try to know exactly when the arm movement is up, down, left or right. I can define it thanks to “attitude.pitch” I can define it using "attitude", but it doesn't work correctly when the wrist is rotating at the same time as an arm movement. I no longer know how to move forward to know each movement.
My code is as follows: (attitudeAvant11 is the attitude to the forward scan) (attitude11 is the attitude.pitch on the AppleWatch)
Thank for your help
func knowMove (attitude11:Double, attitudeAvant11:Double) -> (Sens2:String, attitudeAvant12:Double) {
var attitude1 = attitude11
attitude1 = attitude1 * 100
let pourcentage = attitude1 - attitudeAvant
if attitudeAvant != 0 {
if pourcentage >= 0.5 {
sensPrint = "Sens: Move down // ➡️\(pourcentage) ⬅️ // \(attitude1) // \(attitudeAvant)"
sens1 = "1"
} else {
if pourcentage < -1.2 {
sensPrint = "Sens: Move Up // ➡️\(pourcentage)⬅️ // \(attitude1) // \(attitudeAvant)"
sens1 = "2"
} else {
sensPrint = "Sens: No Move // ➡️\(pourcentage)⬅️ // \(attitude1) // \(attitudeAvant)"
sens1 = "0"
}
}
} else {
sensPrint = "Sens: No Move Initialisation // ➡️\(pourcentage)⬅️ // \(attitude1) // \(attitudeAvant) "
}
let DateMaintenant = Date()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
let dateString = formatter.string(from: DateMaintenant)
if sens1 != "Nul" {
TableauAttitude["\(dateString)"] = "\(sens1)"
//print(TableauAttitude)
}
attitudeAvant = attitude1
print("sensPrint: \(sensPrint)")
return (sens1,attitudeAvant)
}