Documentation
Programming structures
Overview
Basisinstructies
Programming structures
- comment
- loops
- if-structures
- procedures
- end
Example scripts

Programming structures

Here you'll find the grammatical structures that are allowed to define the behaviour of the robot.

Comments

# free text that will not be evaluated

All text that appears after a hash, '#', will not be interpreted as instructions. The robot will proceed to read the next line in the script. Use this possibility to annotate parts of the script, just for yourself, as documentation about how these parts work

Loops

powtórz(n){...instructions...}
repeats the instructions between curly brackets exactly n times.

Example:

# a square of 2x2
powtórz(4)
{
	naprzód(2)
	wPrawo()
}
                  

powtórz(){...instructions...}
just keeps repeating the instructions between curly brackets for ever.

Example:

# just goes naprzód
# (but eventually will stay hitting a wall)
powtórz()
{
	naprzód()

}

powtórzDopóki(condition){...instructions...}
repeats the instructions between curly brackets as long as the condition holds. This condition must be a perception/seeing instruction (for example zPrzoduPusto)

Example:

# keeps going naprzód, 
# but stops when it can't go any further
powtórzDopóki(zPrzoduPrzeszkoda)
{
	naprzód(1)

}

przerwij
allows you to jump out of the loop (e.g. a repeat() section) so it stops performing the instructions between curly brackets. The robot will resume performing the instructions left after the closing curly bracket of the loop.

Example:

# keep going naprzód, until yu can't go any further
powtórz()
{
	jeżeli(zPrzoduPrzeszkoda())	{	
		przerwij
	}
	wPrzeciwnymRazie
	{	
		naprzód(1)
	}
}
                  

If-structures

jeżeli(condition){...instructions...}
will perform the the instructions between curly brackets, only if the condition holds. Else the robot immediatly steps to the instructions written after the closing curly bracket.The condtion must be a perception/seeing instruction (for example: zPrzoduPusto())

Example:

# jeżeli you see white paint on your wLewo, make it black
jeżeli(lewoBiałe())
{
	wLewo()    
	naprzód(1)
	malujCzarny()
	przestańMalować()
	wstecz(1)
	wPrawo()
}
                  

jeżeli(condition){...instructions...}wPrzeciwnymRazie{...instructions...}
will perform the the instructions between the first pair of curly brackets, only if the condition holds. Then it will not perform the instructions of the else block (second pair of instructions). When the condition does not hold, the robot will only perform the instructions in between the second pair of curly brackets. After it performed one of the instruction blocks, it will read the instructions after the last curly bracket.The condtion must be a perception/seeing instruction (for example: zPrzoduPusto())

Example:

# jeżeli you see white paint on your wLewo, make it black
# wPrzeciwnymRazie drive a few steps naprzód
jeżeli(lewoBiałe())
{
	wLewo()    
	naprzód(1)
	malujCzarny()
	przestańMalować()
	wstecz(1)
	wPrawo()
}
wPrzeciwnymRazie
{
	naprzód(3)
}
                  

Logical
expressions

The conditions of if- and repeatWhile-structures is a so-called logical expression. Such an expression will result in the value prawda or fałsz, which is then used to decide to step to the appropriate part of the code to resume execution.

A logical expression can be a perception instruction, e.g.: prawda(). Basic instructions may also be composed with the boolean operators ~, &, |.

Example:

jeżeli(lewoBiałe())
{
    wLewo()    
    naprzód(1)    
}

The condition can however also be refined to more indicate more precisely when the corresponding instructions should be executed by using (a combination of) the following operators.

Operation
Alternative
notation
Number of
arguments
Explanation
nie ~ 1

Negates the value of the argument :

Truth table :
~ prawda = fałsz
~ fałsz = prawda

Example:
~ zPrzoduPusto()

i & 2

Only true when both arguments are true.

Truth table:
prawda & prawda = prawda
prawda & fałsz = fałsz
fałsz & prawda = fałsz
fałsz & fałsz = fałsz

Example:
zPrzoduPusto() & prawoBiałe()

lub | 2

True when at least one of the arguments is true.

Truth table:
prawda | prawda = prawda
prawda | fałsz = prawda
fałsz | prawda = prawda
fałsz | fałsz = fałsz

Example:
zPrzoduPusto() | prawoBiałe()

The values prawda and fałsz can also be applied directly as if it was a perception instruction.

The order of the operators is of importance (just like multiplying and adding numbers). The operation ~ binds strongest, followed by &, followede by |. Brackets can be used to influence the order of evaluation.

Examples:

				
powtórzDopóki(nie zPrzoduPusto() i (lewoBiałe() lub prawoBiałe())){
    naprzód(1)
}

jeżeli(rzutMonetą() i nie prawoBiałe())
{
    wPrawo()
    wstecz(1)
}

jeżeli(prawda i fałsz){
    # this instruction is never executed
    naprzód(1)
}
              

Procedures

procedura name(par1, par2, ... , parN){...instructions...}
defines a new procedure with the name you want. The procedure can have zero or more parameters, which you may also give useful names. Here they are called par1, par2, . . . , parN. These are the variables you can use in the instruction beteen curly brackets. The code in a procedure will not be performed automatically, you have to write a 'procedure call' every time you want to perform the instructions in the definition (See next instruction).
Tip: create a new procedure when when you you use a sequence of instructions more than once.

Example:

# define how to draw a rectangle
procedura rectangle(width, height)
{
	malujBiały()
	powtórz(2)
	{
		naprzód(height)
		wPrawo()
		naprzód(width)
		wPrawo()
	}
	przestańMalować()
}
                  

name(arg1, arg2, . . . , argN)
is the call to the procedure with the corresponding name and the same amount parameters as you have arguments. The argument, here called arg1, arg2, . . . , argN, are the particular values that will be used in the procedure definition.

Example:

# these instructions will be performed
naprzód(1)
rectangle(3,2) # a call to the 'rectangle' procedura
naprzód(3)
rectangle(1,4) # another call with other arguments


# this is the definition of 'rectangle'
procedura rectangle(width, height)
{
	malujBiały()
	powtórz(2)
	{
		naprzód(height)
		wPrawo()
		naprzód(width)
		wPrawo()
	}
	przestańMalować()
}                  

End

zakończ
will cause the entire program to stop when this instruction is performed.

Example:

# stop after 5 steps, lub earlier when you encouter a beacon on the wPrawo
powtórz(5)
{
	naprzód(1)
	jeżeli(prawoNadajnik())
	{
		zakończ # stops execution of the program
	}
}
# normal zakończ of the program
                  
RoboMind - Copyright © 2005 - 2016 - Research Kitchen