CMAltimeter will tell you the (relative) height of the watch but its accuracy may not be sufficient.
CMAttitude will tell you the orientation of the device. In your case CMAcceleration the X axis will be negative when the hand is raised.
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:
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
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:
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:
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.
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).
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.