Obtaining small distance displacement of an apple device(watch) in cm

Hi,


I have been working on a private project regarding to development of an Apple watch traning app via Swift programming language (Xcode).

I have done some researches to be able to obtain small distance displacement of an apple watch( in cm ) in a short time period( in seconds), but the only libraries which i found were cllocationmanager or cmmotionmanager,

but as i see none of them were suitable for a small distance calculation (in cm) and as fast as (in seconds) required in my app.
I have found some complex formulas with accelerometer datas to calculate a concrete distance displacement, but unfortunately i could not realize them in Swift.

https://www.nxp.com/files-static/sensors/doc/app_note/AN3397.pdf


I would be grateful, if you could suggest any available libraries in Swift or inform me if it is possible to make concrete calculations for small distance displacements (in cm) in a short time (seconds) or not.
Coding Ex:

->Click button to detect first location

locationManagerInCm.startUpdatingLocation

latestLocation = (x=0cm, y=0cm, z=0cm) ->calculated by Apple watch

locationManagerInCm.stopUpdatingLocation

->Apple watch moves 3 sec

->Click button to detect second location

locationManagerInCm.startUpdatingLocation

latestLocation2 = (x=30cm, y=20cm, z=0) >calculated by Apple watch

locationManagerInCm.stopUpdatingLocation

->Calculate and show displacement

X.text = String(format: "%.2f", latestLocation.x - latestLocation2.x)

Y.text = String(format: "%.2f", latestLocation.y - latestLocation2.y)

Z.text = String(format: "%.2f", latestLocation.z - latestLocation2.z)


Thank you very much in advance.


Best Regards

Emre

Replies

What do you want to measure ?

absolute movement ?

Watch movement relative to the bearer ?


In the first case, you need to know initial speed. Consider the case where you are in a train, moving at constant speed and direction. No acceleration except g (measured by the sensor).

So if you integrate twice acceleration of 0, you get 0 movement ; even though you have moved with the train.


So, the referential must be specified.


In the second case, if you want a very rough estimate of short movements on very small period of time, you could:

- considering that initial speed (relative to body) is zero

- considering the sample time (∂t )of accelero

- compute over the small time period T = N ∂t (for instance 1000 samples of 10 µs for a period of 10 ms


- get the instant accelerations at each sample time : a(n), with n from 0 to N

- compute the velocity (on each axis) at each time, for n between 0 an N

n n

v(n) = ∑ a(i) ∂t = ∂t ∑ a(i) because ∂t is always the same

i=0 i=0


Repeat for movement along this axis: you want the position at instant T = N ∂t, so x(N)

N

x(N) = ∑ v(k) ∂t where values of v(k) have been computed above.

k=0


That could give you some estimate of the movement.


You would not control a rocket with this, but could it be enough for your purpose ? Hope that helps.

Is there an associated use case that demonstrates exactly what type(s) of movement you are using as an example?


Perhaps this API:

https://developer.apple.com/documentation/coremotion/monitoring_movement_disorders


..and this framework will get you going in any case:

https://github.com/ResearchKit