Skip to first unread message

hlalibe

unread,
Jun 5, 2017, 3:29:15 PM6/5/17
to mitappinv...@googlegroups.com
Hi guys,

Been trying to troubleshoot this for 2 days now, need help.

What i want to do:
- I have a part of a machine that goes up and back down, kind of a sledge hammer.
- I'm attaching my phone to it to count the number of times it goes up and down (1 cycle = 1 count)
- So i'm reading the Y accelerometer to detect when it dips below a certain threshold value, that means the phone is going down (the phone is attached standing vertically)

Problem:
- often my cycle counter will increase by 3 or 4 units for one physical cycle of the part/phone.

You can see my code below. At the end of my Start Button program, i enabled the Accelerometer, and as soon as the acceleration has changed, i instruct to disable it. Then i check the accelerometer value, if it is below a certain threshold, i increase my counter by 1, i show it on screen, then i re-enable the accelerometer again.


SteveJG

unread,
Jun 5, 2017, 3:50:30 PM6/5/17
to MIT App Inventor Forum

Some things to consider:

1) The accelerometer in a device is not a precision piece of hardware.

2)  Because App Inventor works asynchronously placing lots of calls within the accelerometer.changed event handler might cause an event to be masked and could cause errors. Talking mainly about your TextToSpeech and TinyDB blocks.    

3) You said "often my cycle counter will increase by 3 or 4 units for one physical cycle of the part/phone." ...Is the app inadvertently capturing both the strike and recover. There is an acceleration on the down and another on the up and your safeguard code might not be cycling...The accelerometer is also capturing vibration- possibly will trigger your counter.

You might be able to simplify your 'counter' by doing a different approach.  Why not try the Pedometer object ( http://ai2.appinventor.mit.edu/reference/components/sensors.html#Pedometer ) .. it uses the accelerometer to  count steps ... essentially what your gadget is doing.... going down, then going back up = count one step.


Regards,
Steve 

Abraham Getzler

unread,
Jun 5, 2017, 3:59:19 PM6/5/17
to MIT App Inventor Forum
Your speak procedure has a delay loop in it, inappropriate for event-oriented AI2.

To prevent timing problems and speech overlap,
queue up your announcements into a list and have the speech component
announce the next list item only in the speech-completion event block.

For an example of this, see

ABG

hlalibe

unread,
Jun 5, 2017, 4:18:55 PM6/5/17
to mitappinv...@googlegroups.com
Thanks Abraham. I remember reading this was not the way to go, but i wanted to improve it later.

But it seems it's not the root cause of my problem, because i now disabled all these blocks, speak, sound, tinydb (as per below code) and the problem remains, count jumps by 3 or 4.

Thanks Steve for your feed-back, i looked at the pedometer component, but i would like to understand first why the accelerometer behaves like this before going into another direction. 

Could it be that between the accelerometer sensor enables to TRUE and then FALSE the accelerometer has time to change 3 or 4 times, therefore the program loops 3 or 4 times ? If so then maybe i can capture these 3 or 4 measures and average out or get the minimum value ?


SteveJG

unread,
Jun 5, 2017, 5:16:33 PM6/5/17
to MIT App Inventor Forum
Graph the y, x and z axis of the accelerometer to see what is actually being recorded and find out what is happening.  It might help you to understand why?  You want this to work?  Try the pedometer component ...it uses the accelerometer ...it is not technically a different component, it is a tool using Java to use the accelerometer in a specific way.

You are aware, your image did not post correctly?

hlalibe

unread,
Jun 6, 2017, 1:36:29 AM6/6/17
to MIT App Inventor Forum
indeed strange the images were gone this morning when i checked, now they are back.

I did write a small program to graph and record the Y accelerometer values, along with min and max, program below. But it shows what i was expecting. So still don't know why my counter jumps by 4.

I will try the pedometer tonight, do you know which block i should be using, SimpleStep or WalkSTep. I guess SimpleStep. I tried SImpleStep quickly yesterday but my counter did not move no matter how i shaked the phone. But i will try again.


Abraham Getzler

unread,
Jun 6, 2017, 8:39:26 AM6/6/17
to MIT App Inventor Forum
If you're collecting data on the Accelerometer, look at the effects of the
Sensitivity and MinimumInterval settings on your results.

MinimumInterval
The minimum interval, in milliseconds, between phone shakes
Sensitivity
A number that encodes how sensitive the accelerometer is. The choices are: 1 = weak, 2 = moderate, 3 = strong.

Maybe that will explain your results.

ABG

hlalibe

unread,
Jun 6, 2017, 2:51:13 PM6/6/17
to MIT App Inventor Forum
I did play with MinimumInterval and Sensitivity, although these 2 parameters seem to work only when you use the When Accelerometer1.shaking rather than When Accelerometer1.AccelerationChanged. I tried the first one and could not dial the settings right, i could get mostly 1 count only per cycle, but not consistently enough, like 19 out of 20, which is not sufficient for my application. 

Maybe i need to stay on the "over sensitive" side and record all the measures coming in, then pick the minimum value, do my tests, then run another cycle.

I also tried the pedometer, .Simplestep, it records 2 for each cycle, which is not a problem if it does it consistently, but it's too sensitive, and not sure how to decrease it's sensitivity. I think Pedometer also reacts to X and/or Z axis changes, while i need to react only to Y axis changes, and ignore Z and X.

Evan Patton

unread,
Jun 7, 2017, 6:47:57 PM6/7/17
to MIT App Inventor Forum
You could also compute something along the lines of an exponential moving average to smooth out jitteriness in the sensor readings to tease out signals in the noise. You may have to tune the alpha value to get the desired result.

Evan

hlalibe

unread,
Jun 10, 2017, 12:19:22 PM6/10/17
to MIT App Inventor Forum
thanks Evan for the feed-back, but moving average won't work for my application, i need to detect if one value goes below a certain threshold.

I managed to have my app do what i wanted, but it's ugly code, below. I had to record up to 5 values of the accelerometer, then get the minimum value of these 5 values. 

I also had to slow down the counter.

Ugly code, but it works.
Reply all
Reply to author
Forward
0 new messages