Visual Programming Environment

Thymio Visual Programming Environment

The visual programming language (VPL) allows to program Thymio visually. It is available in two ways:

  • The Thymio VPL program gives you a standalone VPL-only environment.
  • The VPL is available as a plug-in for Aseba Studio. Click on Launch VPL under the Tools tab to start it.

Files saved in one environment can be re-opened in the other and vice-versa.

For users of earlier versions

The version 1.4 brought several new features. If you are used to version 1.3 or earlier, please read the transition guide.

Environment overview

In VPL, a program is created by assembling pairs of one event and one or more 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 part of an event-actions 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 part of an event-actions 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 button opens an existing program.
save.svgz save This button saves the program.
saveas.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.
stop.svgz stop This button stops the robot. Once you stop the robot, you must click again on load and run to restart the program.
vpl-advanced_off.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.
screenshot.svgz screenshot This button takes a screenshot of the VPL program.

Assembling pairs

Programming in VPL works by associating an event block with one or more action block(s) in a pair. You can do that by dragging blocks into the event-actions pairs in the programming area. For example, a pair composed of a button event and a motors action tells the robot to move when a button is touched on the robot.

play.svg

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 part of an event-actions pair.
  2. Drag one or more action block(s) to the right part of an event-actions 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.

Basic mode

When VPL starts, it is in the basic mode. In this mode, only some blocks are shown to make the interface easy to handle.

Event blocks

event-buttons.svg 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.svg horizontal proximity sensors This event occurs when the robot sees an object close or far with its horizontal sensors. For every sensor, grey means ignore the sensor, white indicates that an object must be close, and black that an object must be distant. If all sensors are ignored, this event occurs periodically 10 times per second.
event-ground.svg ground proximity sensors This event occurs when the robot sees a dark or a light ground with its ground sensor. It does so by measuring the amount of reflected light. No ground is therefore equivalent to dark ground (no reflected light). For every sensor, grey means ignore the sensor, white indicates that the ground is light, black that the ground is dark. If all sensors are ignored, this event occurs periodically 10 times per second.
event-tap.svg tap detection This event occurs when the robot detects that it has been tapped.
event-clap.svg clap detection This event occurs when the robot detects a loud noise such as someone clapping their hands nearby.

Action blocks

action-motors.svg motors This action sets the speed of the left and right motors (and thus of the wheels).
action-colors-up.svg 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.svg bottom colour This action sets the colour of the bottom of the robot, as a mixture of red, green and blue (RGB).
action-music.svg music This action plays a melody defined by the user, of maximum 6 notes. 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. Clicking again sets a silence instead of a note.

Advanced mode

vpl-advanced_on.svgz

Clicking the advanced mode button in the toolbar enables VPL programs to define and use an internal state. It also allows you to use additional blocks and to have advanced version of some specific blocks.

The 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-actions 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.svg

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-actions 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 robot's buttons:

vpl-state-example.svg

Additional blocks

In advanced mode, you will see three new blocks. Two of them are related to the timer, a way to trigger an action after a given amount of time, and one allows to set the internal state.

event-timer.svg timer elapsed This event occurs when the timer times out.
action-timer.svg 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.svg state This action sets the internal 4-bit state of the robot. Grey means keeping the current value, white means set it to 0, yellow means set it to 1.

Advanced version of existing blocks

Here are some blocks that possess an advanced version. They are similar to the blocks available in basic mode but have some additional features.

event-rc-arrow.svg remote control arrows This event occurs when someone presses an arrow on the remote control.
event-rc-keypad.svg remote control keypad This event occurs when someone presses a button on the keypad of the remote control.
event-prox-advanced.svg horizontal proximity sensors In addition to the features of the basic mode, this event can detect an object to be close but not too close. Moreover, you can set the threshold values for detection (see example below).
event-prox-advanced-explained.svg horizontal proximity sensors (example) The top bar allows to set the threshold for close objects, while the bottom bar allows to set the threshold for far objects.
event-ground-advanced.svg ground proximity sensors This event has the same extra features as the advanced horizontal proximity sensors.
event-tilt.svg left/right tilt This event occurs in function of the left/right tilt of Thymio. By default, the corresponding actions will be triggered when Thymio is on a flat surface. You can choose the orientation condition by clicking on the white triangle and by making it move to the left or to the right.
event-pitch.svg forward/backward tilt (pitch) This event occurs in function of the forward/backward tilt (technically called pitch) of Thymio. It works the same way as the left/right tilt event.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License