Getting vertical position of Apple Watch

How would I get the vertical position of the watch?


For instance, if the user were touching their hair, I would want to know that.


I have been thinking that things like accelerometer, attitude, rotation, etc. don't really help.


This is for a simple project so I want to be able to use some simple cut.


Basically:


IF "value" is measured to be greater than threshold:


THEN do something



So I need to figure out what that "value" is I am going to measure and be fairly accurate. Something ideal would be.....


If the watch is at a vertical position higher than 2 feet from its average position for the last 3 minutes, then do whatever


I am a beginner so please be gentle!


Thanks!

Replies

CMAltimeter will tell you the (relative) height of the watch but its accuracy may not be sufficient.

https://developer.apple.com/documentation/coremotion/cmaltimeter?language=objc


CMAttitude will tell you the orientation of the device. In your case CMAcceleration the X axis will be negative when the hand is raised.

https://developer.apple.com/documentation/coremotion/cmattitude?language=objc

Your goal:

For instance, if the user were touching their hair, I would want to know that.

I have been thinking that things like accelerometer, attitude, rotation, etc. don't really help.


You need to do more than just detect altitude or even acceleration.

You need to make the difference between some one climbing 2 stairs and someone moving its hand to the head.

What about the person is lying in bed ? No altitude change.


So, you would have to analyze move pattern thoroughly to discriminate. Not a trivial task.

It should look like fall down detection, so it is possible, but certainly advanced data filtering and machine learning.

It is probably out of reach for a beginner (and even more seasoned developer), I would advise you to start with something simpler.


May read this article:

h ttps://www.popsci.com/apple-watch-fall-detection/

Thanks for help! To clarify, right now I have an on/off toggle switch so this will only be used when person is sitting upright. Right now I have made variables for all sorts of things.... XYZ accelerations, XYZ rotations, pitch, yaw, roll What I want to do now is save those results to device log while the on button is on so I can analyze them on my computer and decide what to use as value and threshold.

How do I do that? I have saved them into os_log But when I go into device logs after running my code on my watch I don’t see anything. I checked console too. I did get the watch is logging profile and installed that

so I can analyze them on my computer and decide what to use as value and threshold.


That would really be a good candidate for machine learning:

- pass your set of data

- plus the information: touched the head or not.


Doing it algorithmically would be really hard (and a loss of time).

I have saved them into os_log But when I go into device logs after running my code on my watch I don’t see anything. I checked console too


Did you read this:

https://developer.apple.com/documentation/os/logging


and this

https://forums.developer.apple.com/thread/94693

see logs on my Apple Watch through Console.app

Finally I fixed it by installing the sysdiagnose profile to my Apple Watch.

Download the watchOS profile from here:

https://developer.apple.com/bug-reporting/profiles-and-logs/?name=sysdiagnose

Airdrop it to your iPhone and you will get the choice to choose "Apple Watch" to install it to. Once you install it and click "Done" then you will start seeing Apple Watch logs in Console.app.

You wrote that you are a beginner so let me respond both to an expert and a beginner:


If you are an expert then logging and machine learning and deducing the exact motion of the arm is something that you could pursue - and Claude31 has given you a good start. This is beyond me....good luck!


If you are a beginner then step back a bit. No need to log much data. If you simply detect when the arm's orientation changes towards the upward direction 'you just might find you get what you need'. You do that by recording a few values of "accelerometerData.acceleration.x" in an NSMutableArray that you load with a new value each time you get a call to the completion handler of startDeviceMotionUpdatesUsingReferenceFrame: . An improvement would be to detect both the X orientation and the gyroscope rotation about y or z - but again, only a second of data is needed. All of the analysis can be done on the watch itself.