Thymiovpl

Programming with images

This document describes the visual programming environment for the Thymio II robot as implemented in version 1.3 of Aseba.

Environment overview

The visual programming language (VPL) is available in Aseba Studio under the tools tab when a Thymio is connected. Clicking on Launch VPL starts the plug-in. Alternatively, the Thymio VPL program gives you a standalone VPL-only environment. Files saved in one environment can be re-opened in another and vice-versa.

In VPL, a program is created by assembling pairs of event and action blocks. The window looks like this:

vpl.png
  1. The toolbar contains buttons for opening and saving files, loading and stopping the program execution, and changing the editor mode.
  2. This area is used for constructing programs. Programs instruct the robot how to behave.
  3. This line indicates whether or not the pairs composing the program are complete and correct.
  4. The event blocks determine when the robot should start an action. These blocks can be added to the program by clicking on them or dragging them into the left square of an event-action pair that appears in the program area.
  5. The action blocks determine what the robot should do. These blocks can be added to the program by clicking on them or dragging them into the right square of an event-action pair that appears in the program area.
  6. In standalone mode, the corresponding text program is written in this area. When used within Studio, the text program is written in Studio.

A zip archive containing the images of all blocks can be downloaded here.

Toolbar buttons

filenew.svgz new This button clears the editor and returns to simple mode.
fileopen.svgz open file This butunderline textton opens an existing program.
save.svgz save This button saves the program.
save.svgz save as This button saves the program after prompting the user for a file name.
play.svgz load and run This button loads and runs the program on the robot.
stop1.svgz stop This button stops the robot. Once you stop the robot, you must click again on load and run to restart the program.
color-scheme.png colour scheme This button changes the colours of the event and action blocks.
vpl_advanced_mode.svgz advanced mode This button changes the editor to the advanced mode. In that mode, additional features are available.
info.svgz information This button loads this reference documentation page.
exit.svgz quit Only available within Studio, this button closes VPL.

Event blocks

event-buttons.png buttons This event occurs when one or more buttons are touched. For each button, grey means ignore the button, red indicates that the button must be touched. If all buttons are ignored, this event occurs periodically 20 times per second.
event-prox.png horizontal distance sensors This event occurs when the robot sees an object close or far on one of its horizontal sensors. For every sensor, grey means ignore the sensor, red indicates that an object must be close, and white that an object must be distant. If all sensors are ignored, this event occurs periodically 10 times per second.
event-ground.png ground distance sensors This event occurs when the robot either sees the ground or not with one of its ground sensor. Since a black ground behaves like no ground, this event can also be used to sense the ground colour. For every sensor, grey means ignore the sensor, red indicates that the ground is close, white that the ground is far away. If all sensors are ignored, this event occurs periodically 10 times per second.
event-tap.png tap detection This event occurs when the robot detects that it has been tapped.
event-clap.png clap detection This event occurs when the robot detects a loud noise such as someone clapping their hands nearby.
event-timer.png timer elapsed This event occurs when the timer times out.

Action blocks

action-motors.png motors This action sets the speed of the left and right motors (and thus of the wheels).
action-colors-up.png top colour This action sets the colour of the top of the robot, as a mixture of red, green and blue (RGB).
action-colors-down.png bottom colour This action sets the colour of the bottom of the robot, as a mixture of red, green and blue (RGB).
action-music.png music This action plays a 6-note melody defined by the user. For every note, the higher the dot the higher the pitch. A white dot produces a note lasting twice as long as a black dot. To set a note, click on the bar where you want it to appear. Click on the dot to change from white to black or from black to white.
action-timer.png timer This action starts a timer with a timeout in the range of 0 to 4 seconds, defined by the user by clicking somewhere in the clock face. When the timer has elapsed, a timer event is generated.
action-states.png state This action sets the internal 4-bit state of the robot (see later). Grey means keeping the current value, white means set it to 0, yellow means set it to 1.

Programming

Programming in VPL works by associating an event block together with an action block in a pair. You can do that by clicking on blocks in the event or the action lists at the sides of the screen, or by dragging blocks into the pairs in the programming area. For example, a pair composed of a tap detection event and a motors action tells the robot to move when it is tapped.

play.svgz

Several pairs of different instructions can be assembled. Pairs can be dragged and dropped for rearrangement. Clicking on the + button inserts a new pair while clicking on the X button removes a pair. Once the program is created, it must be loaded into the robot by clicking the load and run button (see right) in the toolbar.

To summarize, the steps for visual programming are:

  1. Drag an event block to the left square of an event-action pair.
  2. Drag an action block to the right square of an event-action pair.
  3. Repeat 1 and 2 until the program is complete.
  4. Click the load and run button and see if the robot behaves as expected.

The following video demonstrates a simple programming scenario of linking buttons to the robot's motors and top colour actions (the blocks in this video slightly differ visually but are functionally similar):

Advanced mode

vpl_advanced_mode.svgz

Clicking the advanced mode button in the toolbar enables VPL programs to define and use an internal state. The robot's response to an event can depend on the robot's state. Suppose that you are a robot with a program for deciding what to eat for lunch. The event is "it is now 12:00 noon"; the action is eat X. But X can depend on the weather:

  • it is now 12:00 noon and the weather is cold → eat soup for lunch
  • it is now 12:00 noon and the weather is hot → eat fruit salad for lunch

In terms of an event-action pair, the robot's action depends on both the event and the robot's state; for example:

  • clapping hands occurs and the robot is in state 0 → turn the blue light on
  • clapping hands occurs and the robot is in state 1 → turn the red light on
action-states.png

To set the state, the advanced mode introduces a state action (see right). In advanced mode, there are four buttons (that look like the state action) to the right of each event block in every event-action pair. These correspond to four 1-bit state variables, which can be either 0 or 1 (initially they are 0). The current state of the robot is shown on its top by the four corner LEDs of its circle LEDs (the LED is off for 0 and on for 1). The state action can set any combination of these four bits to either 1 or 0. For the event, the state buttons act as filters, when they are grey, the bit is ignored; when orange, the bit must be 1 for the event to occur; and when white the bit must be 0 for the event to occur.

The example below makes the robot red or blue when it detects a clap, depending on its state. The state is set with the buttons:

vpl-state-example.png

More about VPL

Discover two challenges to develop your skill at VPL!

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License