Weighing scale

This page describes the classical weighing scale Thymio uses to weigh different objects.

In order to create this weighing scale, you will need:

  • a cardboard sheet (110 x 80 cm) of thickness 1.5 mm. This can be bought in every stationers for approximately 6.- CHF or 4.90 EUR
  • A cutter with a cutting board (a metallic ruler helps a lot)
  • A PET bottle or any object you can use as an axis
  • A few objects to weigh (in the picture, it is a big tape measure)
  • A Thymio with the code you will find below

The cardboard

Plan_scale.png

This weighing scale has been made using a 110 cm by 42 cm board with a thickness of 1.5 mm.

The schematics above show you how to cut the board. All dimensions are given in millimeters. The axes, drawn with dotted lines, show where to bend the cardboard.

First, you should cut the periphery of the weighing scale with the cutter. You will probably have to cut the same place a few times in order to go through the cardboard. Once you have cut the periphery, you will have to cut the three little rectangular holes at the bottom of the cardboard.

When you want to bend the cardboard, you can cut just a bit along the axes (where you will bend it) on the outside to help you. This is not necessary but can avoid the cardboard bending nonuniformly. Be careful not to cut through the cardboard completely, you just have to cut half a millimeter deep.

Once you have bent the cardboard, you can attach it using the three clips. You will have to twist the end of the attachments, be careful not to destroy them. You will have to align the holes diagonally with the edge of the cardboard as illustrated here:

Clasp.JPG

The axis

For the axis on which the weighing scale lies, you can use whatever you want. In the example, we used a PET bottle filled with water. There are a few things to take in account:

  • You should not use something which is too small. The PET bottle is probably the smallest thing to try. The bigger the axis, the bigger the angle. Thus, it will be easier for Thymio to weigh something when the scale lies on a large axis. If you take something which is too big, Thymio will have problems climbing the slope.
  • A perfectly round object will be difficult for Thymio to weigh. You should have some kind of a small flat surface on the top of the axis (just squeeze the PET bottle)
  • You should also attach the axis to the table. If it is not stable, Thymio will have some difficulties weighing your objects.

The graduation

You can use the scale we designed. We drew something for the bottom of the weighing scale and also for its borders. You can download, print and glue them using the following images. (Be careful to keep a ~ 5 cm between each mark)

Graduation.png
Graduation_borders_all.png

A4 printable versions are available here:

Ground (part 1) Ground (part 2) Borders
Graduation1.pdf
Graduation2.pdf
Graduation_borders.pdf

Of course, you can create the graduation yourself. Just be careful not to choose something too dark for the borders, Thymio may have trouble seeing them, thus it could be difficult for it to stay aligned with the weighing scale.

The code

The complete code can be found here (it contains constants. If you just copy-paste the code here, they will be lost. The easiest is to right-click here and to save as an .aesl file on your computer, then open it with Aseba Studio)

This code reacts to four events: button.forward, button.backward, acc and prox.

button.forward

This event is triggered when the forward button is pressed. Here, the leds are turned off and the mode goes to MODE_COARSE (which starts Thymio).

button.backward

This event is triggered when the backward button is pressed. Here, the leds are turned off, the motors are stopped and the mode goes to MODE_STOP (which stops Thymio).

prox

This event is triggered at a frequency of 10 Hz (every 0.1 seconds). The variables left_ir and right_ir are computed using the two border horizontal proximity sensors. We want to transform the raw sensor values into data that can be applied to the motor speed. The variable rotation is then computed using left_ir and right_ir. There, we compute a value that can be applied to each motor conversely in order to have Thymio rotating instead of having it going closer to or further away from the walls.

Then, a ground detection is done. If there is no more ground (i.e. Thymio is at the end of the weighing scale) it turns red and stops.

acc

The acc event is divided in two parts. If the variable mode is equal to MODE_COARSE, the first half of the code is triggered. If it is equal to MODE_FINE, the second half is triggered. If mode is equal to MODE_STOP, nothing happens. The two parts are extremely similar. We start by computing the slope angle where Thymio lies using the accelerometer.

angle.pdf

Thymio is on a slope forming an angle α with respect to the ground, its axis X points towards the back (it depends on the physical position of the accelerometer in the robot), its axis Z towards the bottom (with respect to Thymio). The force of gravity points towards the ground, thus an angle α is created between gravity G and the axes X and Z. From there, a bit of trigonometry tells us that the tangent of α is equal to the division of the gravity projected on X (Gx) by the gravity projected on Z (Gz).

As the accelerometer gives the projections of the gravity along the axes X and Z, we just have to use the native function call math.atan2(angle,acc[1],acc[2]) to get the angle of the slope measured by Thymio.

Once the angle is determined, we have to adjust the position of Thymio for the angle α to be null (the weighing scale is horizontal). We can give the angle value to Thymio's motors. The smaller the angle, the lower the speed, thus Thymio will stop at the equilibrium point. The division by the constant ANGLE_DIVISER_FAST is here to adapt the speed of Thymio relative to the angle. Indeed, the angle value varies between -32,768 and +32,767, if we just applied the angle value to the motors speed, Thymio would go much too fast and its motors speed would saturate.

The condition if prox.horizontal[0] > THRESHOLD_IR or prox.horizontal[4] > THRESHOLD_IR then checks if Thymio is correctly aligned in the weighing scale. This code checks if the proximity sensors values are bigger than a threshold (THRESHOLD_IR ). If they are, the robot is too close to the wall, thus a correction is applied using rotation computed in the prox event. If not, the robot just goes forward and backward.

This piece of code checks if Thymio is climbing or descending the slope. When it climbs, the value of acc[1] is positive as the gravity is projected towards its back and Thymio's X-axis is along its back also. When the weighing scale will toggle, the gravity will be projected negatively on Thymio's X-axis, thus the value of acc[1] will be negative. If so, a counter is incremented. Then if this counter is bigger than a threshold (THRESHOLD_ACC_COUNT ), Thymio goes to MODE_FINE and the leds turn blue. The counter is here to avoid false positive due to the noise on the accelerometer.

Finally, the MODE_FINE is nearly the same as the MODE_COARSE with two exceptions. First, there is no detection if Thymio climbs or descends the slope (it has already been done). Secondly, the constant ANGLE_DIVISER_SLOW is bigger than ANGLE_DIVISER_FAST in order to make Thymio go slower, thus it will find the equilibrium point more precisely and more smoothly.

That's it ! Have fun :-)

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