RoboMind Documentation
Documentation
Example programs
Overview
Introduction
Basisinstructies
Programming structures
Example scripts
- Write your name
- Find the spot
- Line follower
- Maze runner

Example scripts

In the next example programs you'll see how basic instructions and programming structures can lead to interesting behavior of the robot. Try to understand the script and why it works. Even better is to try them yourself by copying the code and pasting it into the RoboMind script panel. Make sure the right map is used before running them.

Example 1 : Write your name

Because the robot is able to paint, you're able to create simple drawing programs. Using fehérreFestand nemFest you can command the robot to put its brush on the ground or not. When you let the robot move, it will leave a line on the ground. In this manner you can write characters like 'A'.

In the map openArea.map you'll have enough space to create a nice piece of art. Try using the remote control (Run > Remote control) to let the robot paint.

See also: basic instructions: paint, move

write 'A'

#character 'A'
fehérreFest


előre(2)
jobbra
előre(1)
jobbra
előre(2)
hátra(1)
jobbra
előre(1)


nemFest

Example 2 : Find the white spot

In the map findSpot1.map which you can find in Rhomboid's default map folder, you'll find somewhere on the left a corner containing a white spot. Assume you don't know in advance at what distance this corner is located. How is the robot able to find it if it starts somewhere along the wall? Of course you can count the number of steps the robot has to move yourself, but there are better ways.

Let the robot make one step forward at the time, and let him check if it already sees the spot on its left. If it sees the spot, it has to stand on it and then it is finished. Else it should make another step forward and check again if it already is near the spot. This can be repeated in a loop.

See also: basic instructions:move, see, programming structures: loops, if-structures, end

find spot
ismétel{
    ha(balraFehér){
        # There's a white spot on your left
        balra
        előre(1)
        vége
    }
    máskép{
        # There's no white spot yet
        előre(1)
    }
}

Another approach that shows the same results is the following script. Here the robot repeats moving forward until it doesn't see the wall anymore (so it must be the corner we are looking for). Then the robot turns and moves forward to land on the spot.

ismételAmíg(vanBalraAkadály){
    előre(1)
}


balra
előre(1)
            

 

Example 3 : Line follower

In default.map you find a white line in the east. This line forms a track through the environment. How can you make the robot follow this track?

The solution is somewhat similar to the previous example. After the robot is brought to the beginning of the track, it determines what to do step by step.

See also: basic instructions:move, see, programming structures: loops, procedures, if-structures, end

line follower
# Go to the start of the line
jobbra
előre(8)


# Keep on track step by step
ismétel
{
    ha(előlFehér){
        előre(1)
    }
    máskép ha(jobbraFehér){
        jobbra
    }
    máskép ha(balraFehér){
        balra
    }
    máskép ha(vanElőlAkadály){
        vége
    }
}
      

Another approach is using so-called recursive procedures. In the next script you see that a procedure follow is defined. In this procedure, after the correct step is performed, you see that follow is used in its own definition. What you get is a sequence of follow(...follow(...follow(...)...)...)that perform the correct action each time step to fulfill the task. This cyclic definition is called recursion, and it is likely that you'll find it somewhat strange the first time you see it. No worries, play with it and becomes more clear.

# Go to the start of the line
jobbra
előre(8)


# Start tracking
follow


# Recursive definition for tracking
eljárás follow{
    ha(előlFehér){
        előre(1)
        follow
    }
    máskép ha(jobbraFehér){
        jobbra
        follow
    }
    máskép ha(balraFehér){
        balra
        follow
    }
    máskép ha(vanElőlAkadály){
        # Finish the current procedure call
        # (because there is nothing to after 
        # this return, all calls will be finished
        # and the program stops)
        vissza
    }
}

Example 4 : Maze runner

How to escape a maze in general? It appears that this hard question has a simple solution. By always following the wall on the right side (or always following the wall on the left side) you will find the exit for sure.

The next script makes the robot find the beacon in for example maze1.map.

See also: basic instructions:move, see, programming structures: loops, if-structures, end

ismétel{
    ha(vanJobbraAkadály){
        ha(előlSzabad){
            előre(1)
        }
        máskép{
            balra
        }
    }
    máskép{
        jobbra
        előre(1)
    }

    ha(vanElőlJeladó){
        felvesz
        vége
    }
}
      

RoboMind - Copyright © 2005 - 2016 - Research Kitchen