This page shows an example of a machine which tests the optical reflectivity of paper. The machine has a lever at the front which can move a paper sample to various distances from the front proximity sensor of Thymio. A reference surface moves facing a lateral sensor of Thymio and provides a distance reference. This machine is constructed using only parts from the LEGO Technic 8069 construction kit.
The coloured paper is moved with a bar actuated by one of Thymio's wheels. Here is a sequence of possible positions:
This machine can be connected to a computer which can recover the data associated with events:
The measuring sequence is as follows: first the coloured paper is moved close to the sensor, then it is moved slowly away while taking the measurements. Between two measurements the paper is changed and this is 'noted' with the lateral arrow buttons. This allows a different number to be added to the data for each paper.
This is how it looks in a video:
The code required to produce the effects in the video is below. NOTE: in order to compile this code an event named plot with three parameters has to be created (on the right in the AsebaStudio environment).
var Tampon0[4] = 0,0,0,0
var TamponPos0 = 0
var Tampon1[4] = 0,0,0,0
var TamponPos1 = 0
var data[3]
var paper = 0 # variable whose value is used to identify the paper when the data are analysed
var record # variable indicating if data are to be emitted or not
onevent buttons #à each time the buttons are checked
when button.forward==1 do # move forward for the measurement
motor.right.target=-100
end
when button.center==1 do # stop
motor.right.target=0
record = 0
end
when button.backward==1 do # reverse rapidly
motor.right.target=400
end
when button.left==1 do # changes the paper variable which identifies the samples
paper = paper - 1
end
when button.right==1 do # ditto
paper = paper +1
end
onevent prox
# The 3 values of interest are put in -data-: no_paper, reference, measurement
data[0]=paper # reference for the paper
Tampon0[TamponPos0] = prox.horizontal[4] # position reference
TamponPos0 = (TamponPos0 + 1) % 4
data[1] = Tampon0[0] + Tampon0[1] + Tampon0[2] + Tampon0[3]
Tampon1[TamponPos1] = prox.horizontal[2] # paper measurement
TamponPos1 = (TamponPos1 + 1) % 4
data[2] = Tampon1[0] + Tampon1[1] + Tampon1[2] + Tampon1[3]
if record==1 then # only when recording
emit plot data
end
when prox.horizontal[4]<1500 do # if very close
motor.right.target=0
end
when prox.horizontal[4]<1600 and motor.right.target<0 do # if close and moving away, start to record
record = 1
end
when prox.horizontal[4]>3600 and motor.right.target<0 do # if too far away, stop
record = 0
motor.right.target=0
end
The procedure to record the measurements is a bit complicated, because the experimental data must be recovered from AsebaStudio in order to be analysed later with software such as Excel or OpenOffice.
To start the process, before launching AsebaStudio, the serial (USB) port to which Thymio II is connected must be opened with asebaswitch. This software allows multiple access to the same Thymio II. The command in a terminal, on a Mac, in the file bin of asebauniversal, is:
./asebaswitch "ser:device=/dev/cu.usbmodemXXX"
where XXX is a number generated case by case by the Mac. You can see this number in AsebaStudio.
Next one can connect with AsebaStudio choosing Network (TCP) and as host localhost and as port 33333.
This results in the usual environment with AsebaStudio connected to Thymio II, but with asebaswitch between the two.
Now all the events created by Thymio II can be recorded by the program asebarec with the following command:
./asebarec "tcp:localhost;port=33333" > myfilelog.txt
In the file myfilelog.txt the text lines have the following format:
timestamp source message_id size data[0] data[1] data[2] data[n]
As can be seen, the data sent by the event are always the last numbers. The 'size' field shows how many data values follow (i.e. n).
With the experiment shown in the video, the data which is stored in myfilelog.txt is as follows:
1309439074.659 1 0 3 1 5882 16306
1309439074.722 1 0 3 1 5878 16302
1309439074.785 1 0 3 1 5871 16301
1309439074.849 1 0 3 1 5877 16302
1309439074.912 1 0 3 1 5890 16307
1309439074.975 1 0 3 1 5907 16312
1309439075.039 1 0 3 1 5923 16317
....
1309439115.768 1 0 3 1 14149 0
1309439115.831 1 0 3 1 14152 0
1309439115.893 1 0 3 1 14154 0
1309439115.957 1 0 3 1 14154 0
1309439116.020 1 0 3 1 14157 0
1309439116.083 1 0 3 1 14170 0
1309439116.147 1 0 3 1 14184 0
1309439116.210 1 0 3 1 14193 0
1309439116.273 1 0 3 1 14219 0
1309439116.337 1 0 3 1 14235 0
1309439141.989 1 0 3 2 5789 16283
1309439142.052 1 0 3 2 5790 16279
1309439142.115 1 0 3 2 5790 16279
1309439142.179 1 0 3 2 5790 16280
1309439142.242 1 0 3 2 5793 16281
1309439142.305 1 0 3 2 5797 16281
1309439142.369 1 0 3 2 5802 16277
1309439142.432 1 0 3 2 5799 16271
1309439142.495 1 0 3 2 5800 16268
1309439142.559 1 0 3 2 5800 16266
....
The complete original file is here.
It can be seen that the value third from the right changes when the paper is changed, thus allowing the data to be sorted.
When this data is processed correctly in Excel or OpenOffice, the following graph can be generated:
This graph corresonds to the reflection from the following four paper types:
Finally, some details of the construction: