Alternative CMPedometer for calculating the number of steps with an accelerometer on iOS

Because CMPedometer is not available for below iPhone5S.

CMPedometer StepCounting not available

Is there any algorithm code that we can use to program the number of steps with the ios accelerometer?

thanks

+5
source share
2 answers

You can determine the Event step using accelerometer data with CMMotionManager

 protected CMMotionManager _motionManager; public event EventHandler<bool> OnMotion; public double ACCEL_DETECTION_LIMIT = 0.31; private const double ACCEL_REDUCE_SPEED = 0.9; private double accel = -1; private double accelCurrent = 0; private void StartAccelerometerUpdates() { if (_motionManager.AccelerometerAvailable) _motionManager.AccelerometerUpdateInterval = ACCEL_UPDATE_INTERVAL; _motionManager.StartAccelerometerUpdates (NSOperationQueue.MainQueue, AccelerometerDataUpdatedHandler); } public void AccelerometerDataUpdatedHandler(CMAccelerometerData data, NSError error) { double x = data.Acceleration.X; double y = data.Acceleration.Y; double z = data.Acceleration.Z; double accelLast = accelCurrent; accelCurrent = Math.Sqrt(x * x + y * y + z * z); double delta = accelCurrent - accelLast; accel = accel * ACCEL_REDUCE_SPEED + delta; var didStep = OnMotion; if (accel > ACCEL_DETECTION_LIMIT) { didStep (this, true);//maked a step } else { didStep (this, false); } } 
+1
source

IOS aside, there is no easy solution to create an accurate pedometer using only the output of the accelerometer; it's just noisy. Using the gyroscope output (where available) to filter the output will increase accuracy.

But the rough approach here is to the connection code for the pedometer: - the steps are defined as the change in acceleration detected on the Z axis. Assuming that you know the default acceleration (the influence of gravity) here, how you do it:

 float g = (x * x + y * y + z * z) / (GRAVITY_VALUE * GRAVITY_VALUE) 

Your threshold is g=1 (this is what you will see when standing). Spikes in this meaning are steps. So all you have to do is burst count. Keep in mind that a simple g> 1 will not do, since the g value will increase over a certain period of time by one step and then return (if you build the value over time, it should look like a wave sin, when there is a step - essentially, you want to count the waves of sin)

Keep in mind that this is just something to get you started; You will have to add more complexity to it to increase accuracy. Things like: - hysteresis to avoid false step detection - filtering the output of the accelerometer - determining intervals Here are not included and should be experimented.

+1
source

Source: https://habr.com/ru/post/1242181/


All Articles