Award
Congratulations DJ Sures, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Exiting A Classic Control Loop In A Script Via Voice Command?

Assistance Requested

Help Richard R with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

Richard R claims to have checked these sources:
 
#1

Below is a simple code I hacked up to use with the voice recognition control... It works as expected... I am controlling the robot via voice mostly, but sometimes i want it to roam autonomously (as per my simple code below). However, problem is I can't figure out how to exit the script at will... Once this script starts it only stops when the ping detects an object... Ideally, I would like to take back control of the robot at any time... So my question is, how do I break out of the control loop using a voice command or any other way for that matter? By the way, the script has no name because it is within the voice command control...

Say("Forward slowly")
SendSerial(D0, 38400, 161)
SendSerial(D0, 38400, 93)
:loop
$fping=getping(D7,D7) #using a SRF05 sonar with echo and trigger on the same pin
if($fping<15)
say("Object close by, stopping")
SendSerial(D0, 38400, 0)
SendSerial(D0, 38400, 0)
Halt()
endif
goto(loop)

I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.


Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


#2

Can you post your project file?

#3

It's cheesy as it is still only in the beginning stages... but ok
Zargos.EZB

#4

I haven't looked at the project file but an idea could be to use a variable for aborting and a voice command that sets the variable. Something like

Code:

$abort = 1



Then in your main script, periodically check the abort variable, you could do this by throwing in;

Code:

If($abort = 1)
#reset the variable
$abort = 0
Halt()
EndIf



Or you could combine it with the ping checking;

Code:

If($fping<15 OR $abort = 1)



Just a couple of ideas off the top of my head Smile

#5

I though of that, but how do you send an abort istruction ($abort) to the running script? In other words how do I set the $abort to 1 outside of the running script itself?

#6

Hold on, it's easier than that.

Use script manager for the scripts then just ControlCommand() to start the script with the correct voice command. Have another voice command of abort which ControlCommand() to stop all scripts.

Code:

ControlCommand("script manager", ScriptStopAll)



Simple Smile

#7

Ha, ha... way ahead of you Rich I tried ControlCommand("script manager", ScriptStopAll) under script manager, but all my scripts are within the speech recognition control panel I am not using any separate scripts... I only have 2 controls... a Movement Panel and a speech control panel, that's it so far... For some reason ControlCommand("script manager", ScriptStopAll) does not stop the scripts from within the voice recognition panel, or at least it did not terminate the "forward slowly" script running within my voice recognition control... Geeze, hope I am making sense here...

#8

Back to my first suggestion though and your question of how to set the abort from outside of the script.

All variables are global. I.E. If you have script a;

Code:

:loop
$variable1 = "hello"
Sleep(100)
Goto(loop)



script b;

Code:

:loop
$variable2 = "world"
Sleep(100)
Goto(loop)



and script c;

Code:

Print($varialble1 + " " + $variable2)



Run script a, then b, then c. Script C will print "hello world".
Note: Script a and b have no need to loop really since nothing is changing but it filled out the code a bit Grin

So, with that in mind, having a voice command which has a script of

Code:

$abort = 1



Will set the global variable $abort to 1. All other scripts know this. So if the if statement I posted for the abort is in the code and gets run periodically it will abort. Your script looks like it runs very fast so would know about the abort in a matter of milliseconds.

Otherwise, you could just keep pasting that if statement in to the code throughout, if it was a longer script. Or better still use a label and goto

Code:

Goto(abort)
# lots more code
Goto(abort)
#even more code


:abort
If($abort = 1)
$abort = 0
Halt()
EndIf
Return()

#9

@rryerson get the latest EZ-Builder.

Here are the release notes which addresses your issue: http://www.ez-robot.com/Community/Forum/posts.aspx?threadId=5044

#10

I just saw that, now that's what I call awesome customer relations! Grin