2017년 4월 19일 수요일

Re: Pedometer


How do I build a pedometer function that counts my steps every time I move forward or backward a step when walking or running?

--
It would be a bit complicated.  You'll need Location services turned on on your device.  You'll have to use the location sensor to determine that you've moved.  You'll have to calculate whether you moved forwards or backwards.

You'll also have to create a calibration system so you can measure what a true step is.

What have you tried so far?

--
This link explains how you can build a pedometer using App Inventor 2.    You need the Acellerometer.  pedometer

You are using App Inventor Classic..the procedure would be similar.  

Here is a partially built pedometer with an aia ...the discussion shows there are issues but forum members made suggestions that allow it to work I believe. First Project help  

Did this help?

--
Here is a screenshot of the blocks editor code i have so far.


--
Some suggestions:

Do not open another screen .. if you open another screen you have to pass the accelleraton variables to it and that is difficult.  It is easier to develop on a single screen.   I do not know if App Inventor classic has layouts, but if it does, you should be using layouts instead of changing screens.   Set the layout Visible to false to hide, to true to show.

You probably only want to record one of the accelleraometer axis (but perhaps you will need several)

⦁ xAccel: 0 when the phone is at rest on a flat surface, positive when the phone is tilted to the right (i.e., its left side is raised), and negative when the phone is tilted to the left (i.e., its right size is raised).
⦁ yAccel: 0 when the phone is at rest on a flat surface, positive when its bottom is raised, and negative when its top is raised.
⦁ zAccel: Equal to -9.8 (earth's gravity in meters per second per second when the device is at rest parallel to the ground with the display facing up, 0 when perpindicular to the ground, and +9.8 when facing down. The value can also be affected by accelerating it with or against gravity.

I never tried to make a pedometer; I know it is possible with AI2 because others have done it. I expect it would be better to use a property of the accellerometer called shaking to record steps.   Here is how someone did it using AI2 blocks

Perhaps it will give you ideas.  Try some blocks, run the app then take some steps with your Android in hand and see if Shaking records some steps?
Good luck...let us know how this progresses and what you come up with.

Lastly, if at all possible, we recommend you code the pedometer with AI2 blocks, not the Classic blocks.

--
Thanks Steve. I will let you know how i get on.

--
I am still not getting anywhere. 
It only increases the step count when i physically shake the phone when I hold it in mu hand. 
I want it to increase by 1 step when it is in my pocket and I take one step at a time.

--
I ran some test code a short while ago and got a similar result Ewen.   I suspect some devices have Accelerometers more sensitive than others.

I found this Accelerometer tester  which might be helpful.. and. this video https://www.youtube.com/watch?v=_wPvSnL1jzY that links to it .... someone commented they got a pedometer to work using a combination of shaking and the orientation sensor... I have not had time to follow that up.   Try Scott's links.


--
Steve use the code in this app,


You dont want to use the shake event, you want to use the xyz values , the event fires much faster so this is good for response.
The trick is when your feet hit the ground and you push your body upwards you send a force slighly higher than the force of gravity (9.8m/s/s) through your phone, ( I've called this the initial_force_trigger_
and conversely before your next foot hits the ground your body falls slightly as it moves forward ( especially when running)  , the forces become slightly lower than the force of gravity. ( I've called this relief force trigger)

because the accelerometer changed event fires almost continuously we need to filer out the values so that it responds to the initial_trigger_force ( i set this to 10.8 but you can play with it) , the force needs to reach at least this value in order to set the variable allow to true, which then means it can  ( in my case iterate a counter and play a sound but you can modify this to record the gps etc) , then it's important it does not keep doing it, so we ignore all future readings until we see the relief_force trigger reach as low as 8 m/s/s. After this point, the next time we see a value greater than 10.8 again, ( which will be when my foot hits the ground) it fires again.
This means that if I was to have a long duration force greater than 9.8 it would not fire repeatedly, eg if I was walking up a set of stairs.

I also make sure that the interval between 2 reading is not less than 100ms, thats 10 steps a second, again you could play with that value.

The playsound procedure runs when your feet push into the ground and the forces through the phone increase, you could use this to count steps, capture the gps lat,lng or do what ever you wish.
Hope this helps you   

--
I cant find this and block in App Inventor 2 Blocks Editor

--
Never mind I found an alternative. Also does call play link to the playsound feature you were talking about? this is because I want to replace it with the count step feature for counting steps in my pedometer app.

--
AND is under logic

It counts steps already, I've deleted the bits you dont need.

So you just need a label called label1
-an accelerometer called accelerometer1 ( minimum interval 0 )
-a clock called clock 1, (always fires)
and this code.
To make it more sensitive to impact reduce the value of initialtriggerforce closer to 9.8
to increase the amount of " fall" needed before the next step will be recorded bring the value of relief force trigger closer to 0
 and if you are using it for walking you can probably increase the maximuminterval to perhaps 300 ( milliseconds) which allows your uses to make a maximum of  3 steps per second 
--
What do I need to do for xcount?

--
@James ... thanks for the link, I will look at this later

@Ewen...I experimented for a while.... I had limited success using ONLY the z value in the accelerometer  to count stepps and then only when the device is in a vertical position.  I had to set some bounds ...thing is too sensitive and I could not get reproducible step counts with my code.  (which still does not work properly).

Keep on trying.  It is possible part of the issue is how the accelerometer behaves on different devices.  I'll look at James' code when I get some time.  So far, I have not found any reliable way of counting steps although the device certainly records the shock of some steps, but not all so far.   Thought you would like an update.

--
In the play block, where is t he xcount variable suppose to appear from? It is not showing up in my blocks editor so I cant get my code to work like the example from James in the screenshot. James or Steve can you help me clarify where xcount is specified and how i get it to appear in my blocks editor for app inventor 2?

--
I tried your code and tested it out. I had no joy and it doesnt seem to record my steps. Any other suggestions?

--
It does work.
I assume you have the phone vertical ( top of phone points to sky, bottom of phone to ground) ?
You have a label, clock and accelerometer with the same names ? 

here is the project, import it into AI.
Xcount is a local variable passed into the procedure, you can see it being passed in if you look at the purple block inside the first IF statement in the accelerometer block - the global variable count is passed into the play procedure the value of count becomes xcount inside the play procedure.
see the bottom of this page for assistance in understanding how values are passed into procedures Procedures

댓글 없음:

댓글 쓰기