Thymio II as drawing machine

The robot Thymio II has a central hole that will hold a marker pen, for example, to make the drawings. There are different ways to decide what to draw. A simple way is to control the robot remotely (by an IR remote control or by hand clapping) so as to make it draw as desired. The other way is by programming it. This page presents some examples of programs with the corresponding drawings.

full-robot.jpg

The simplest way of drawing is to make sequences of curves and straight lines, with a time counter which determines the lengths.

Here is a small program which uses the temperature reading event, which occurs every second, and makes a loop count using the variable itera, which increases by one every second. With three if it triggers different sequences (turn when itera is 1, advance when itera is 4) and loops with the last if:

var itera = 0

onevent temperature
itera = itera + 1
if itera==1 then
    motor.left.target = 230
    motor.right.target = -120
end
if itera==4 then
    motor.left.target = 80
    motor.right.target = 80
end
if itera==7 then
    itera = 0
end

The drawing which results is the following:

dessin-fleur-simple.jpg

One can also alternate moving forward and backward as in the following very similar program:

var itera = 0

onevent temperature
itera = itera + 1
if itera==1 then
    motor.left.target = 100
    motor.right.target = 90
end
if itera==4 then
    motor.left.target = -100
    motor.right.target = -70
end
if itera==7 then
    itera = 0
end

The pattern which results is very different, here it is:

dessin-etoile-simple.jpg

One can alternate very different sequences which makes regular drawings. If one wants to break the regularity a variable can be added. The following example adds a speed variable that is incremented regularly and which defines the length of the straight lines by increasing the robot's speed:

var itera = 0
var speed = 30

onevent temperature
itera = itera + 1
if itera==1 then
    motor.left.target = 230
    motor.right.target = -140
end
if itera==4 then
    motor.left.target = speed
    motor.right.target = speed
    speed = speed + 2
end
if itera==7 then
    itera = 0
end

The resulting pattern is as follows:

dessin-fleur-croissante.jpg

Another example of a regular pattern with one variable:

var itera = 0
var speed = 20

onevent temperature
itera = itera + 1
if itera==1 then
    motor.left.target = 140
    motor.right.target = -140
end
if itera==4 then
    motor.left.target = speed
    motor.right.target = speed
    speed = speed + 2
end
if itera==7 then
    itera = 0
end

Here is the resulting pattern:

dessin-etoile-croiss.jpg

If you have a careful look, you see that this drawing is built with two spirals, better visible here:

dessin-etoile-explique.jpg

Finally it is possible to make a clearer spiral with the following code, where the robot moves forward, then backwards for a shorter time, then turns and reduces the speed by 1/10, and so on:

var itera = 0
var speed = 256
timer.period[0] = 1000 # 1000ms = 1s 

onevent timer0
itera = itera + 1
if itera==1 then
    motor.left.target = speed
    motor.right.target = speed
end
if itera==4 then
    motor.left.target = -speed
    motor.right.target = -speed
end
if itera==6 then
    motor.left.target = -40
    motor.right.target = 40
    speed = speed - (speed / 10)
end
if itera==7 then
    itera = 0
end

Here is the result of this code:

spiral-700.jpg

At the end a true spiral:

spiral.jpg

With the code that allow to start and stop the drawing of the spiral with forward and backward buttons:

var parti                #started flag
timer.period[0]=100     # 100ms
call leds.top(0, 0, 32)    # bleu

onevent button.forward    #start
    parti=1
    motor.left.target = -200
    motor.right.target = 200
    call leds.top(0, 32, 0)

onevent button.backward        # stop
    parti=0
    call leds.top(32, 0, 0)
    motor.left.target = 0
    motor.right.target = 0

onevent timer0    #every 100ms = 0.1s
    if parti ==1 then
        motor.left.target = motor.left.target+1
        motor.right.target = motor.right.target+1
    end

Here a video illustrating the process:

I hope I have given you the desire to test these simple programs which give very varying patterns. Do not hesitate to post your results on this page!

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