Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited
Resolved Resolved by DJ Sures!

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

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)

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
PRO
Synthiam
#1  
Can you post your project file?
United Kingdom
#3  
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:)
#4  
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?
United Kingdom
#5  
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:)
#6  
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...
United Kingdom
#7  
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:D

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()
United Kingdom
#9  
I just saw that, now that's what I call awesome customer relations!:D
#10  
Geez Dude!... are you sure you're not a robot yourself... how on earth did you put that control feature into ARC in what was basically a blink of an eye... I'll try it right now...
Just means DJ is going to get more of my freekin' money....:D
Thanks DJ and Rich