By Alissone Mendes and Daniel Stojmenovic, pupils in the 1'st OC info. at the Blaise-Cendrars High School, June 2012
General presentation
We got the idea from a children's game "Croc the crocodile". The game is simple, Croc is suffering from a bad tooth, the aim is to find it. To do this one has to press on each of his teeth, at the same time obviously avoiding the bad one, because as soon as that one is touched the jaws will close on the fingers of the player. The game is won when only the bad tooth is left.
To restart the game the jaw of the crocodile needs to be opened, a new bad tooth is then selected automatically.
Principle of our game
To start the game the crocodile's jaw has to be open. If not, it can be made to open by pressing the rear left distance sensor, then by pressing on the rear right sensor to stop the movement. Once this is done the game can be started again. Move your finger closer to the teeth (front distance sensors), being careful not to touch several sensors at once. If nothing happens, you can change tooth, as this means that the tooth you chose is not the bad one. Repeat this either until only one tooth is left, in which case you have won, or else the jaws close, in which case you have lost. Once the jaws have closed, you can open them again using the rear left distance sensor to start opening, and the rear right sensor to stop.
Error sources and problems encountered
Adapting our idea to a Thymio robot
Once we had had our idea, we found ourselves facing a very concrete problem : how to adapt our game to the robot ?
We thought to use Lego blocks to construct the jaw of the animal. The jaw would be moved by the robot's wheels. So we placed our robot upside down.
Building the jaw was quite complicated because it had to be big enough to be detected so that the wheels stop and the Lego blocks are not damaged. The front distance sensors are the teeth of the animal. One of them closes the jaws. This one is chosen at random and changes each time the game is started.
Calling the actions
First we started by wanting to perform several actions, but the program did not accept them. We had to write a 'call' before each action so that it was accepted and correctly executed.
Position of the variables
During our project we had to use several variables. The first time the variables were not recognized by the program because we forgot to place them right at the beginning of our code.
Stopping the wheel rotation
We had to find a way of stopping the wheels before the Lego blocks of the jaw touch the Thymio, thus avoiding damaging either the blocks or the robot. We used the bottom sensors to stop the wheels moving as soon as the jaw was detected. We added several Lego blocks under the jaw to facilitate the detection.
The problem of randomness
Randomness is certainly the part of the programming of our project which caused most difficulties. First of all we had to find a built-in function in the Thymio which generated random numbers. For that we consulted the Aseba internet site. This turned out to be very slow, but, with patience, we found the native function which was going to be useful to us : « math.rand ».
It took a little time to learn to use random numbers correctly, but by searching we found out how to access the generated number and introduce it as a variable .
Unfortunately the function generated numbers from -16383 to 16383 and we needed numbers from 0 to 4 which are the numbers corresponding to the robot's front distance sensors. Then we had the idea of splitting the range of numbers generated into 5 equal parts, each part corresponding to a sensor. We allocated one of the rear sensors to restarting the program, so that once this detector fires a new random number is generated and thus a new bad tooth is chosen.
Restart the program
Once the program code was written we found ourselves faced with a new problem, how to start a new game? We then thought of using the two rear sensors. One of them is used to raise the jaw and the other to restart the program so that a new bad tooth is chosen. In order that the program restarts when the sensor is touched, we had to use two « if » and some tables to offset the second condition so that the program understands that they are secondary.
The file containing the code can be downloaded here.
Conclusion of the work
In starting this project, our aim was to adapt and modernise an already known game with the help of current progress in the field of informatics. We kept that at heart because we believe that one of the challenges for informatics today is to succeed in improving what already exists.
With this in mind, we think that we reached our goal. The robot is obviously not perfect but it copies very faithfully the behaviour of the game "Croc the crocodile".
In spite of our satisfaction, we nevertheless have some regrets due to the lack of time and means. We would have liked to put in a counter so that when all the teeth except the bad one have been touched, the robot plays a sound to show that the player has won, also a "timer" so that the machine stops automatically when the jaw is raised. Certain objects would have improved our project, such as special Lego parts to make a more aesthetic aspect, or a micro SD memory card so as to be able to use our own more appropriate sounds, instead of having to be content with the sounds available in the Thymio.
Video demonstration
Here is a video showing the crocodile in operation: