Netherlands
Asked
Resolved Resolved by DJ Sures!

Loopforever Not Working?

Hi community

Hi always had this runnning on my EZ-B (running R2D2), it checks if a dome button is pushed and triggers a script

:loopForever
ADC_wait(ADC0, LOWER, 50)
ControlCommand("Script Manager Animations", ScriptStart, "Remember cantina")
goto(loopForever)

Now I notice (since going to Synthiam) it stops after starting the script once (by pushing the button) while it is not supposed to do that, e.g. loopforever. Something changed? Sorry for asking, couldn't find it in the docs. Or is there a new/better way to implement this, e.g. whatch for an input and if true hit a script

Thanks in advance


Related Hardware EZ-B v4

ARC Pro

Upgrade to ARC Pro

With ARC Pro, your robot is not just a machine; it's your creative partner in the journey of technological exploration.

PRO
Belgium
#1  

charel

maybe its like this?

:loop sleep(100) ADC_wait(ADC0, LOWER, 50) ControlCommand("Script Manager Animations", ScriptStart, "Remember cantina") sleep(100) goto(loop)

PRO
Synthiam
#2  

Nomad is sort of on to something. The trouble is with the logic, because the "Remember Cantina" will start a thousand times in about a second while ADC is lower than 50. you'll need something that resets the ADC to be higher than something. Here's an example for a logic toggle...

This will let the loop reset rather than keep starting the script a thousand times. With your original code, the script will run for long as ADC is less than 50. Which means if you hold your hand there for 1 second, it'll run about 1000 times.


:loop
sleep(100)
ADC_wait(ADC0, LOWER, 50)
ControlCommand("Script Manager Animations", ScriptStart, "Remember cantina")
ADC_wait(ADC0, HIGHER, 60)
goto(loop)

PRO
Netherlands
#3  

Was also on the same path and experimenting with sleep() but your suggestion "ADC_wait(ADC0, HIGHER, 60)" is very smart, shoud have thought of it myself :-) Thanks for the help!

PRO
Synthiam
#4  

also, does the dome button have a resistor for pulling the voltage high? Because it will pickup ambient voltage otherwise and produce false positives

#5  

I had to add pull down resistors to keep the voltage from floating around and triggering scripts. That solved a lot of problems.

Also, I have always used DJ's approach. I found that when the switch was closed the voltage would go way up so I was able to really raise the trigger target voltage in the script. In your example I would have raised it from 60 up to above 150 or so. It gave me lots of headroom both ways.

Is your push button momentary or toggle? If momentary and you raise to trigger value too high you may find you will have to hold the button in a little longer for the voltage value to raise to the proper lever. Not long, just a good contact push. A few more milliseconds but you will notice the difference.

In the ADC control you should be using, you will find a Interval setting measured in milliseconds . This is how often the control will check the value on the port your switch is attached to. I think the default setting is 1/2 second (500 milliseconds ).  My take on this is if you have your script set to check the ADC value every 100 ms it will not see a change till the control recheckes the value in 500 ms. Of course this all depends when in the cycle you push the button. LOL. You can adjust the ADC control to sample quicker or slower. Be aware that this process really eats up your resources and can possibly overwhelm your connection if you sample too fast. Playing with it wont hurt anything so give it a go to see where your sweet spot is. Maybe with a quicker interval sample you can release your momentary button sooner.

PRO
Netherlands
#6  

Thank you for your time and effort to answer. I didn't have "false positives"/jiggling so far so no issue for me. But if it happens in the future I know where to look.  As suggested, I will raise the trigger voltage script, looks like a good practice, e.g. ADC_wait(ADC0, HIGHER, 90) If I understand you correctly you suggest to set it as ADC_wait(ADC0, HIGHER, 90, 100) where the latter 100 signifies it checks every 100 Ms iso every 500 ms?

#7  

Actually I suggest to play with the settings to find your sweet spot. Just be aware if you sample or check to quickly you are wasting resources other things can be using. If everything is working now don't change anything.

Have fun!

PRO
Netherlands
#8  

Thanks, will do!