Pedometer algorithm brief and module use

Source: Internet
Author: User

Pedometer as an algorithm function module, this should be separated from the business module, decoupling. This can also be more focused on the upgrade of the algorithm. Let me briefly describe the implementation principle of the pedometer algorithm, and give us some inspiration.

1. Algorithms

For all pedometer, the first step was to use an accelerometer (Accelerometer sensor) to measure the number of steps, and then Google introduced step Counter sensor, By the hardware or the system calculates the step change, makes the algorithm simplifies. Some phones do not provide a step-up sensor; Some phones turn off the step sensor during standby.

Simply introduce the implementation algorithm.
1. Accelerometer (Accelerometer sensor):
The algorithm plots the spatial curve according to the spatial position (XYZ axis) of the accelerometer , and determines the walking or other state according to the time interval between the two peaks and troughs. In a short period of time there is a continuous crest, that is, walking; Peaks appear at a longer interval and are considered to stop walking. At the same time, shielding slight and initial disturbance, improve the accuracy; Improve robustness by adjusting parameters to match sensor differences in different mobile phones.
2. Step Counter sensor (STEP):
The algorithm reads the value of the pedometer sensor, matches the local cache number, and determines whether the step is increased or not. When the screen is off, start the batchmode mode , with the coprocessor , delay the acquisition of values, save power. When the step sensor is stopped (some phones will stop some sensors when the screen is off), the adaptive switching accelerometer, when activated, switches the step-up sensor again.
3. self-adaptability (self-adaption):
According to the system parameters, the algorithm first chooses the step sensor, when the step sensor can not be used, select the acceleration sensor.

2. How to use

This algorithm has generated SDK packages and can be used independently.
First initializes the Pedometer Manager (Pedometermanager), the incoming context , and the step callback, which automatically calls the callback when the number of steps increases. The app uses the number of steps based on the UI interface style. followed by the start of the Step Service (Pedometerservice), the service according to the system state changes since the start, to ensure real-time monitoring steps.

        /** * Use, incoming context and step callback, when the number of steps increase will automatically call the callback, add steprate parameters, to implement the lock screen pedometer. */Pedometermanager.getinstance (). Init (mainactivity. This. Getapplicationcontext (),NewStepcallback () {@Override  Public void Addstep() {//Step frequency (steprate) parameter, the light screen default is 1, lock screen root adaptive adjustmentMstep + = Pedometermanager.getsteprate (); Mtvstep.settext (string.valueof (Mstep +"Step")); LOG.E (TAG,"Step:"+ Mstep); }                });/** * Initially start the service, the service will automatically remain connected and handle system exceptions. */StartService (NewIntent ( This, Pedometerservice.class));

At the outermost of the project build.gradle , add the address of Maven library, incoming account number and password.

allprojects {    repositories {        mavenCentral()        maven {            "http://maven.chunyu.mobi/content/groups/public/"            credentials {                username maven_user                password maven_password            }        }    }    repositories {        jcenter()    }}

Add dependencies to your project, that is [GROUP_ID]:[ARTIFACT_ID]:[VERSION] .

‘me.chunyu.android:pedometer:0.3.0‘
3. Version iteration 0.1.0:

Initializes the project, providing simple step-by-steps functionality.

0.2.0:
    1. When the lock screen, the acceleration sensor frequency is reduced, resulting in the inability to count steps. Modify the algorithm to implement the lock screen low-frequency meter step.
    2. When using, add the step frequency (steprate) parameter, the light screen default is 1, the lock screen according to the sensor frequency adaptive adjustment.
0.3.0:

Add the Upload app activation information feature.

External Cooperation :
This algorithm is currently used only within the company,
If you need to cooperate, please contact the Spring Doctor's website for promotion and cooperation ([email protected]).

OK, that's all.

Pedometer algorithm brief and module use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.