General information

Project of Fall 2016: "Relay race"

Mindstorms NXT(TM)/EV3 robots are robots made of a main unit and a set of sensors and actuators. They have been sold by Lego for several few years now, starting with the NXT version, and now with the ev3 version. Many very elaborate designs have been made using the standard kit (see for example "Mindstorms: Not just a kid's toy"). You may also watch interesting videos on youtube, such as a marble conveyor, a car factory, a walking dog, a scorpion, a forklift truck, the "holononic drive", a rubik's cube solver, a printer, and a sumo game. You can also find some other nice systems on battlebricks.

The project you will work on is not as complex as some aforementioned systems, yet, it requires spending quite a lot of design and programming time on the robot and its interfaces (sensors, actuators).

Project objectives

The robot you have to build shall be the winner of a relay race. General rules of the game are described below. Note that the rules might evolve during the next weeks, along with the communication protocol.

General rules

  • First, a game server is started. Each robot should register to the server. Each Robot receives by BT from the server its team numer (left, right, see below), and its role (beginner, finisher, see below). The id of the robot in the server corresponds to the id of the student group, see the group section

  • Robot are given a role in the team. Either they are the beginner, of the finisher.

  • Robots on the same team must communicate using bluetooth through a server. The specific bluetooth communication protocol is defined in the project repository. This repository also contains the code of the game server, and example code for ev3 robots. The server is started and configured (ids, ranks) before each competition round starts. The protocol contains a "CUSTOM" message that you may use between robots of the same team in order to send additional information.

  • Once a race is started, all participating robots must send their (team id, x, y) information to the server every 2 seconds using a BT message (see the specification of the BT-based protocol). Position information (x, y) is given in centimeters. Sending that message is optional only if the robot has not moved.

  • Whenever a ball is released or grabbed, a "BALL" message must be sent to the BT server.

  • The software used for each role (beginner, finisher) and for each stadium can be different. The robot can be freely re-programmed between game rounds, but you don't have the right to add/remove lego bricks, sensors, etc.

Tournaments will be organized, and medals (master, diamond, platinum, gold, silver and bronze medals) will be given to robots according to their ranking. The ranking is first determined with the number of points, and then with the number of grabbed balls.

Large stadium

  • The large stadium is divided into two parts: the right part, and the left part. 2 robots are placed in each left/right part. The two robots being in the same part are in the same team for the next race. The two robots of the same team are placed opposite each other in the stadium, as depicted below.

  • The beginner of each team must reach the destination area - located along the opposite fence - without bumping into obstacles. The starting and destination areas are depicted below. Also, once triggered with a "START" message, the beginner must place a ball in the ball deposit area located halfway between the starting area and the destination area. Thus, the beginner holds a ball when starting the game. The finisher must do the opposite: it starts when it receives the "NEXT" message. The finisher must grab the ball previsouly released by the beginner ot its team. Then, it must reach its destination area.

  • The scoring is as follows: when the beginner places the ball at the right location - i.e. in the deposit area -, it scores 2 points. If the ball does not stay in the deposit area, then the robot does not score 2 points. When the ball is released, a "BALL" signal must be sent by the beginner. When the beginner reaches its destination area, it scores 2 points. The team scores 2 points if the beginner is the first to arrive (large stadium only). If the finisher starts once the beginner has sent the "NEXT" signal, it scores 1 point. If it correctly grabs the ball, it scores 3 points. The robot doesn't have to lift the ball, but the ball should be securely attached to it. It means that if the robot is kicked backwards, the ball should go with it. If it reaches the arrival area, and sends the "NEXT" signal to the server it scores 3 points (if it has grabbed the ball, otherwise, it gets no point). If the finisher is the first to arrive, the team scores 3 points (i.e each robot of the team scores 3 points). Each time a robot touches an obstacle, or each time it leaves its side of the stadium, it loses one point.

Small stadium

  • The small stadium contains only one team at a time, and contains no obstacles.

  • A game is as follows. The beginner first holds the ball. It must place it in the back square in the middle of the stadium (it then gets 2 points), and it must send the "BALL" message as soon as the ball has been released. Then, it must reach its destination area (2 points). Then, the beginner must send the "NEXT" message to the finisher. Then, the finisher starts: it must grab the ball, wherever it is in the stadium. If it cannot find the ball, the game ends. Otherwise, once it has got the ball (3 points), it must reach its destination area (2 points). Then, it should continue to play by making a U-turn in order to reach the ball deposit area. There, it should release the ball and send the "BALL" message (2 points), and then it should reach its beginning area. Then, the finisher sends the "NEXT" message to the beginner that must grab the ball (3 points), and reach its beginning area (2 points). Then, the game is in its exact inital state. It start again, for a maximum of 5 mn, until it fails.

Specification of the robot and of competition stadiums

  • The robot must be contained in a cube of 35 cm maximum on each dimension at start-up.

  • Robots can use up to four sensors and up to four engines. You are free to use the sensors you want to among the following ones: touch sensor, light sensor, color sensor, ultrasonic sensor (i.e., distance sensor), compass sensor, gyroscope sensor.

  • The robot must contain a flag, on which the number of your group is clearly readable from at least two sides of your robot. The flag dimension is at most 10x10cm. It may also contain a logo, a drawing, and the name of the robot.

  • The communication protocol between robots (bluetooth) will be given (you don't have to specify it). Basically, robots communicate to a server that then forwards messages to other robots.

  • It may change its shape (by deploying elements, or withdrawing them) during game phases, but it should fit in a 35cm cube at starting.

  • Your robot is allowed to lose/throw parts on purpose - or not ;-) - during the game. Destructive weapons are NOT allowed. For your information, a EMP can be constructed for ~300 dollars as shown here.

  • It is forbidden to send orders - remotely or not - to your robot while it is playing, apart from the BT communication: it must be fully autonomous as soon as the game starts, and until it ends. Trying to hijack BT messages, or other kinds of attacks is not allowed.
The game will take place in a stadium which will be 4m x 2m (see photo below), or in a smaller stadium for a race without a competing team (in that case, no points are given for arriving "first"). For the large stadium, the boundary is indicated by a inflexible solid ribbon. A post at each corner is fixed to the floor to hold the ring in place. Solid obstacles are placed in the larger stadium at indicated positions.

this is a PNG
(Click to enlarge)
Overview of the large stadium.

this is a PNG
(Click to enlarge)
Specification of the large stadium

this is a PNG
(Click to enlarge)
Specification of the small stadium. This stadium has a wooden fence.

Competitions and reports

There are two "competitions", as described after. Your project grade takes into account the two competitions (the one in December, the one in January).
  1. The 13th of December, 2016: your website should be started with at least the name of your robot (I don't expect more in the website for this deadline), and your robot shall be able to pass the 5 following tests alone in the small/large stadium:

    • Test #1. Small stadium: be able to go from the beginning starting area to the beginner destination area.
    • Test #2. Small stadium: be able to start from the beginner position, and place the ball in the black square.
    • Test #3. Large stadium: be able to go from the beginning starting area to the beginner destination area, without getting out of the playground, and without bumping into obstacles.
    • Test #4. Large stadium: be able to start from the beginner position, and place the ball in the black square without touching obstacles or getting out of the stadium.
    • Test #5. In one of the two stadium: be able to grab the ball that is placed in the black square (by me!) after you have placed your robot at the position you want outside of the black square.
    I don't expect the bluetooth to be operational.

  2. The 24th of January, 2016: final competition. For the final competition, the website must be fully completed. Also, during the final competition, I may interview each member of the group, so as to understand the contribution of each group member.

The competition will be as follows, with parallel competitions.
  • 1-team race competition in the small stadium (Linux room). In that case, there are no obstacles, and no competition with another team. In each game, the robot will play the role of the beginner and of the finisher.
  • 2 team competition in the large stadium.

Your report consists of a website. The website shall contain the following information:
  • Description of the architecture of the robot: sensors and actuators, etc. Pictures of your robot on the web site would be appreciated.

  • Algorithms used for the two most important points: beginner strategy (e.g., movement choices and ball management), and finisher algorithms. Don't provide source code here, just try to describe the algorithms using a pseudo C language. Also, do comment those algorithms, and explain why you think they are efficient.

  • Source code, and instructions on how to use that source code: how to compile it, how to download it on the robot, and how to start the robot. To protect you work, you can set a password to access to the code (e.g., private git repository). You could even put a fake code on your website until the very last moment ;-). I strongly advice you to rely on a versioning system (svn, git, hg) to work on the code. Alos, frequently backup your code.

  • Videos / pictures of your robot in action [we may provide you with cameras and video recorders if necessary].

  • How you have worked in the group, i.e., who made what. Be clear about that. Each member of groups will get an individual grade.


(The group leader is listed first. BT address starting with 00:17).
  1. link to website, name of the members, name of robot, BT address.

  2. Hugo DERAMBURE, Axel STRUBEL, Alexis CHALLANDE, LeE, 00:17:E9:F5:B9:DE
  3. Sofiene JERBI, Thibault PETITJEAN, Florian KOHLER, BreakingBotA0:E6:F8:DC:88:C5
  4. Nick MANFREDI, Di HAO, Luis Fernando MENDOZA, Eurebot (code): , A0:E6:F8:DC:88:B9
  5. Maria Teresa BEVIVINO, Duy KHUONG, Simone ROSSI, Mjolnir, 00:17:E9:F5:C2:B1
  6. Emilia CEBRAT, Kamil MASLOWSKI, Christian PALMIERO, NAPOLEON, 00:17:E9:F5:AF:56
  7. Hubert ROSIER, Kamélia DAUDEL, Vincent JARASSE, TeleTank, A0:E6:F8:DC:58:8B
  8. Fabio CARACCI, Valerio ARNAUDO, Dounia BOUGHALEM, RobotTiAmo, 00:17:E9:F5:AC:7D
  9. Minh Duc NGUYEN, Quang Viet Hoang NGUYEN, Lu Duc Duong LAM, Bunbo, A0:E6:F8:DC:96:79
  10. Prashant Kumar DEY, Honey KURIAN, Rihab HARRACK, Bobert code, 00:17:E9:F5:D0:97
  11. Marco COLETTA, Francesco CONDEMI, Estelle RAFFIN, Donald, 00:17:E9:F5:B8:69
  12. Chin-Te LIAO, Hamdi AMMAR, Hamza JAAFAR, Cygnus, A0:E6:F8:FC:BB:10
  13. Nesrine KORTAS, Cedric OSORNIO, Faycal FASSI-FEHRI, MrRobot, A0:E6:F8:FC:B4:B8.
  14. Wael TEKAYA, Mohamed HAMHOUM, MEGATRON, A0:E6:F8:FC:C2:59.

How do I borrow a robot?

There will be 12 groups of 3 students, and one group of 2 students. Please, take care not to lose parts, especially cables and sensors. Also, a microsd card comes with the robot. The procedure to borrow a robot is as follows:
  1. Make a group of 3 (or 2), and decide on a group leader.
  2. The group leader sends me an email with the list of students of the group. List of: first_name, LAST_NAME, email. The leader shall be the first student in the list.
  3. I will validate the group. If the group is not validated for some reason I will provide, go back to stage 1. Otherwise, go to next step. Note that I validate groups with a First Come First Served policy (Date of email sending).
  4. Once I've answered your group with "validated", you can go to Franck Heurtematte's office, in the IT Department. You will be granted an ev3 box.

Access to stadiums

  • Small stadium. The small stadium is located in room 52. You are free to use it whenever you want.

  • Large stadium. The large stadium will be settled in room 54 before each robot session (see the schedule). Between the sessions, the stadium will be accessible in room 464. To access to this room, you need to borrow the key at the welcome desk (and bring it back after you have closely locked the room). Try to be as silent as possible in this room since they are engineers/researchers working just next to the room. Also, do not move things and do not use computers located in this room.


For the ev3 system, the idea is to flash on the provided SDcard a Debian GNU/Linux system. Then, you will be able to use the development language of your choice (C, python, etc.). But we ask you to develop in C.

Installing Linux on ev3

All information to install Linux on your ev3 is given here. This page also explains how to connect to your ev3 via the usb cable, bluetooth, and ssh.

Using and programming ev3

  • Connect to the EV3 from ssh
  • Once your robot has access to Internet, it should display its IP address in the upper left corner of its display (let's assume it is Then, you can try to ssh to the robot (the default password is maker):
    $ ssh robot@
    The robot user is a sudoer, i.e. it can execute commands with root privileges when using the command sudo first.

  • Now, update the robot with the latest packages
  • $ sudo apt-get update&&sudo apt-get upgrade

  • Install extra packages you will need for the project:
  • $ sudo apt-get install gcc make libbluetooth-dev

  • You are now ready to compile a toy example, and to run it. To do so, you first need to install the development environment on the robot:
  • $ git clone https://github.com/in4lio/ev3dev-c.git
    $ cd ~/ev3dev-c/source/ev3
    $ make
    $ sudo make install

  • Now, you need to get the toy example. The tester file runs all 3 motors, then tests the color, touch, sonar, and compass sensors, and is provided on the project git. You can either clone the git with the code on the robot, or on your host computer.
  • $ GIT_SSL_NO_VERIFY=true git clone https://gitlab.eurecom.fr/ludovic.apvrille/OS_Robot_Project_Fall2016.git
    $ cd OS_Robot_Project_Fall2016/
    If you are on your host computer, you then need to copy the example files to the robot:
    $ scp tester.c Makefile robot@

  • Then, on the robot, you can compile the toy example main file, and then run it. You need tachos and sensors to be connected to the brick if you want the program to correctly execute.
  • To compile:
    $ gcc -I./ev3dev-c/source/ev3 -O2 -std=gnu99 -W -Wall -Wno-comment -c tester.c -o tester.o
    $ gcc tester.o -Wall -lm -lev3dev-c -o tester
    $ make
    To run the code:
    $ ./tester
    $ make run

Other examples

  • Sample code is also provided in the ev3c-master repository. Samples of how to control the motors and sensors are included in test_motor.c and test_sensor.c. The Ultrasonic Sensor is described here.

  • If your compass sensor does not correctly work with the test_sensor program, we provide a code specific to the use of this sensor. Use the "i2c" target of the provided Makefile to compile the file.

  • Other examples can be downloaded from the ev3dev C library here. Examples are provided in eg/tacho and eg/sensor.

  • rfcomm-client.c is an example of how to communicate with the server over bluetooth. Compile with gcc rfcomm-client.c -o rfcomm-client -lbluetooth.

  • If you can't get your robot working, bring it along with a box of kittens to course staff :-)

Cross compilation

You may want to compile your source code on your laptop, e.g. to check the syntax of your code or to speed up the compilation process. Cross-compilation for ev3 is available as an ev3 docker image. Here is what I've made to make this work on my Linux computer:
  1. I have first installed docker, created a docker group, added myself to the docker group, and started the docker service. Installing docker may require more than a simple apt-get, so please refer to the document of your OS, e.g. for the one for ubuntu
  2. $ sudo apt-get install docker-engine
    $ sudo groupadd docker
    $ sudo gpasswd -a ${USER} docker
    $ sudo service docker start
    You may have to log-out for the group modification to be effective.
  3. Then, I have installed the ev3 docker image:
  4. $ docker pull ev3dev/debian-jessie-cross
  5. Once done, I've created a helloworld in C:
  6. $ cat > hello.c
    int main(int argc, const char *argv[])
        printf("OS is fantastic!!\n");
        return 0;
  7. I've compiled the file using the cross compiler provided within the docker image, and tested the generated file. The following command assumes that hello.c is located in /tmp on your host system (but you can place it wherever you want: update the following command accordingly).
  8. $ docker run -e LOCAL_USER_ID=`id -u $USER`  --rm -it -v /tmp:/src -w /src ev3dev/debian-jessie-cross
    [Shell in container]$ arm-linux-gnueabi-gcc -o hello hello.c
    Then, if you want to execute the generated ARM executable, you first need to install the ARM emulation environment. Then, you can execute "hello":
    $ sudo apt-get install qemu-user-static
    [Shell in container]$ ./hello
    OS is fantastic!!

Competitions results

First tests, December the 13th, 2016

Group #3 also validated test 5.1 after the picture was taken. Group #10 validated for most tests 5.2. Group #2 can get the ball if it is closed (test 5.2). Group #12 perfectly succeeded in test 1 (before : it was stopping too close to the fence).

Final competition, January the 24th, 2017

  • Master: Napoleon
  • Diamond: BreakingBot
  • Platinium: Donald
  • Gold: RoboTiAmo
  • Silver*: TeleTank (the "star" is a special award because Teletank won in some cases by sending obstacles)
  • Bronze: Eurebot & Moljnir