Asked — Edited

Goto Question

using the goto command, it takes you to the specified command. does it keep playing the following commands so you can cause a loop or do you do that another way?


ARC Pro

Upgrade to ARC Pro

Discover the limitless potential of robot programming with Synthiam ARC Pro – where innovation and creativity meet seamlessly.

#1  

subsequent instructions that would be below the goto command would not be executed.

PRO
Synthiam
#2  

Goto moves your location to the :Label

To return back from a goto() call, you use return

United Kingdom
#3  

Example Goto Script;


$count = 0
:start
Print("Hello World")
$count = $count++
If($count = 10)
  Goto(end)
EndIf
Goto(start)
:end
Print("Goodbye")

This code will loop around 10 times, display "Hello World" 10 times then go to the end, print "Goodbye" and stop.

An example goto Script with a return (aka V1 of my IR detector script);


# IR Detector Script
# Object avoidance using IR sensor on ADC port

# Adjust values below for configuration
$iradcport = ADC6 # Change for ADC Port with sensor attached
$maxirdistance = 35 # Change for maximum distance from object before avoiding in units
$irreverseturn = 0 # Reverse before turn? 0 = no, 1 = yes
$irturndirection = 0 # Change 0 = left or 1 = right
$irturnamount = 500 # Change for how long to turn for in ms
$irreverseamount = 500 # Change for how long to reverse for in ms (if applicable)
$irmovementspeed = 255 # Change for movement speed


# -- Do not modify below this line --
Goto(detect)

:avoid
IF ($irreverseturn = 1)
  reverse($irmovementspeed,$irreverseamount)
ELSEIF ($irturndirection = 0)
  Left($irmovementspeed,$irturnamount)
ELSE 
  Right($irmovementspeed,$irturnamount)
ENDIF 
Return()

:detect
$currirdistance = GetADC($iradcport)
IF ($currirdistance >= $maxirdistance)
  Goto(avoid)
ENDIF 
Sleep (50)
Goto(detect)

Now the script itself is written a bit back to front, the detect routine could have been placed above avoid and the initial goto removed. However this is a great example of how the goto, labels and return work.

The script (after the config part) will Goto the detect routine, it will check the ADC value of the IR sensor fitted to the EZB ADC port and if it meets the criteria it will Goto the avoid routine otherwise it will Goto the start of the detect routine.

The avoid routine runs it's commands to reverse and turn, then it Returns to where it came from, in this case, the detect routine.

Note the formatting of the explanation. Bold are the commands and italic are the labels.

United Kingdom
#5  

It's a pleasure. It's also why I comment my scripts and I am going to claim that writing the above script backwards was all part of my plan to show Gotos and Returns (although it wasn't, I still have no clue why I wrote it that way round).

The script I used above also shows off If, ElseIf and Else, it's a great script to show someone as an example of some of the most used commands in EZ-Script. If only I had a reason to write more scripts... nothing is as relaxing as writing a script and little is as satisfying as writing a script which works:)