7 Replies
Latest reply on May 2, 2020 9:55 AM by PBK
Level 1 (0 points)

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!

• ###### Re: Getting vertical position of Apple Watch
Level 7 (3,795 points)

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

• ###### Re: Getting vertical position of Apple Watch
Level 8 (9,145 points)

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.

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

• ###### Re: Getting vertical position of Apple Watch
Level 1 (0 points)

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.

• ###### Re: Getting vertical position of Apple Watch
Level 1 (0 points)

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

• ###### Re: Getting vertical position of Apple Watch
Level 8 (9,145 points)

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).

• ###### Re: Getting vertical position of Apple Watch
Level 7 (3,795 points)

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.