General information

Project of Fall 2014: "Shoot-and-defend game"

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

The project you ought to do is not as complex as some aforementioned systems, but yet, it requires to spend quite a lot of architecture 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 "shoot-and-defend" soccer-like game. One competition round lasts 2 minutes, and is as follows:
  • Two robots are placed in an arena. The arena is 1.2 meters large and 2 meters long, and protected on all sides with a fence high of 7 cm. Each side contains a robot starting zone delimited with a black line. The arena is cut into two equal parts with a black line.

  • One robot plays the role of the attacker, and the other one of the defender.

  • The attacker scores points when it manages to send a ball to the opposite fence. The attacker scores two points for a direct shot, and one point for an indirect one. An indirect shot shall not touch the defense robot, otherwise, no point is given. Also, a bonus of 1 point is given when the sent ball is red.

  • The attacker has the right to go wherever it wants in the arena. The defender looses 4 points the first time it enters in the middle zone, that it, when one of its wheels goes through the black delimitation line.

  • The attacker robot can contain up to two blue balls at startup. Two other blue balls are placed in its side at 20cm of the delimitation black line, and 20cm from the fence. Two other red balls are similarly placed in the defender's camp.

  • Whather the role of the robot (e.g., attacker, defender), the shape of the robot must be the same when the robot starts, but the software used for each role can be different. Said differently, the robot can be freely re-programmed between competition rounds, but you don't have the right to add/remove lego bricks, sensors, etc.

  • this is a PNG

  • 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.

  • Before a round starts, the two competiting robots are placed as desired inside their black starting zone.

  • Robots are allowed to throw/drop things in the arena. Dropped/thrown "things" must not be harmful for robots (no water, explosives, or whatever!), but they can be - of course - annoying.

  • At the end of a round, roles are exchanged, i.e. the attacker robot becomes the defender, and the defender becomes the attacker. The winning robot is the one with the highest score after two rounds.
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 victories, and then with the number of accumulated points.

Specification of the robot

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

  • It may change its shape (by deploying elements, or withdrawing some) during game phases.

  • Your robot is allowed to lose/throw parts on purpose - or not ;-) - during the game.

  • It is forbidden to send orders - remotely or not - to your robot while it is playing: it must be fully autonomous as soon as the game starts, and until it ends.

Deadlines and reports

There are two deadlines:
  1. The 16th of December, 2013, before the lecture on OS starts: you shall have started to make a website on your robot, and a first version of your robot shall be operational.

  2. We'll first test each robot alone. Each robot - alone in the arena - shall be able to:
    • Navigate within its own camp, without going through the first delimitation black line.
    • Throw a ball contained in the robot to the opposite fence - if the robot can contain balls -.
    • Find a ball at a predefined position, grab that ball, and thow the ball.
    • Have a defined strategy for defending. (That strategy might not yet be implemented).
    Thus, we'll first evaluate, for each robot, the three aforementioned points. Then, we'll make real competitions if the robots are able to do it. The final grading of the project takes into account that first evaluation.

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

Your report consists in a website. The web site 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: attacking algorithms (e.g;, managing balls, shooting), defending algorithms. Don't provide a 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.

  • 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.


  • Group #1: Kawtar AHAGGACH, Quynh Nhu TRAN, Truong An PHAM

  • Group #2: Hassen HICHRI, Mohamed ZARROUK, Ala RADDAOUI

  • Group #3: Qianli TIAN, Maciej BIELSKI, Geoffrey DUDRAGNE

  • Group #4: Axel EHRENSTROM, Sébastien BRETON, Soufiane JOUMAR

  • Group #5: Chuan WANG, Thorben BURGEL, Alexandre FRADET

  • Group #6: Pasquale SOLDANO, William NGUIMFACK, Yiqing YAN

The NXT box, and batteries

As soon has your group has been established (i.e., you have sent me an email with the group information: students + email address of each student), and when I have sent you a confirmation email, Robots may be borrowed from Franck Heurtematte, at the IT Department. Please, take care not to loose parts, especially cables and sensors. A battery charger as well as 6 batteries are provided with the robot.

Working with NXC (Not eXactly C)

A good way to program your robot is to use the C language, and more specifically the NXC environment. That environment provides a compiler for programs written in NXC, and an uploader to upload to resulting program to the NXT robot. Good points about NXC is that:
  • The compiler is available under the Mozilla Public License (free and open-source software).

  • You don't need to change the firmware of the NXT robot, i.e., nothing has to be changed on the robot to be able to use NXC.

  • NXC is a language which is very close to the C language: you don't need to learn a new language. There are several tutorials (including this one) on the web site, as well as a reference guide (pdf).

  • Debugging your code could be difficult. You may have have a look to Debugging NXC code (Thanks to Geoffrey) to facilitate this task.


I have tested it on my Mac under MacOS X 10.9.
Here is how I have made on my Mac (it should work quite the same on a PC running Linux or Windows, very good intructions are provided on the NXC environment web site):
  1. First, I have first dowmloaded the NXC package. I have uncompressed it, and installed it in e.g., /Applications/nxt
  2. I have also downloaded and installed the Fantom Drivers from Lego (windows, MacOS). For Linux, it should be enough to install the libusb drivers, with your application manager (apt-get, etc.).

  3. I have modified my .bashrc file so as to be able to execute NXC applications from a shell. More precisely, I have added the following line to my .bashrc file:
  4. export PATH= $PATH:/Applications/nxt

  5. I have downloaded the tutorial samples code, and I have unzipped it, let say in /Users/ludovic.apvrille/code

  6. I have compiled the "5_light.nxc" code as follows, from a terminal:
  7. $ cd /Users/ludovic.apvrille/code
    $ nbc -O=program.rxe 5_light.nxc

  8. I have plugged my NXT robot on a USB port, and switched it on. Then, I have run the following command on my Mac:
  9. $nxtcom program.rxe
This last command uploads the program on the NXT robot. Then, from the NXT robot, you may run that program, by selecting it using menus of the NXT.


Informations on how to use NXC with Linux are given here. Maciej Bielski also proposes his own way to do for the slackware distribution:
(probably some/all of the commands should be done as root or preceded with 'sudo ')
  1. Create a new group
  2. $ groupadd legonxt

  3. Add your user to that group (already existing user)
  4. $ usermod -aG legonxt 

  5. Create a new 'rules' file:
  6. $ cd /etc/udev/rules.d
    $ touch 45-legonxt.rules

  7. Edit the file, and put the following lines (without the "-"):
  8. SUBSYSTEM=="usb_device",

  9. Create a shell for the file above:
  10. $ cd /etc/udev
    $ touch legonxt.sh

  11. Edit the file, and put the following lines, without "-":
  12. #!/bin/bash
    if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ];then
        chmod o-rwx "${DEVICE}"
        chgrp "${GROUP}" "${DEVICE}"
        chmod g+rw "${DEVICE}"

  13. Give executable rights to that file:
  14. $ chmod a+x legonxt.sh

  15. Reboot

  16. Compile, download and run, after plugging the brick to USB:
    • Compile & download the program to the brick
    • $ nbc hello.nxc -sm- -d -S=usb

    • Compile & download & run the program on the brick
    • $ nbc hello.nxc -sm- -r -S=usb 

Another method tested successfully on Ubuntu 14.04 (64-bit version) proposed by Geoffrey Dudragne for Ubuntu. 2 tools only are necessary to do the job. A compiler and t2n that is a little program to simply communicate with the NXT under linux:
  • Compiler: nbc
  • Download from here http://downloads.sourceforge.net/bricxcc/nbc-1.2.1.r5.tgz

  • Talk to NXT: t2n
  • Download and info from this page http://www-verimag.imag.fr/~raymond/edu/lego/t2n/
Follow the same commands as on this page to extract the archives and to copy the 2 binaries to /usr/bin, see "lego_mindstorms_nxt_sur_ubuntu".
Then, to:
  • Compile a nxc program:
  • $ nbc hello.nxc -O=hello.rxe

  • Check if your NXT is plugged:
  • $ sudo t2n -i

  • Upload program on the NXT:
  • $ sudo t2n -put hello.rxe

    Note : You need libusb to make t2n work, and so you may have to install the 32-bit libusb even if you are running a 64-bit machine.

Competitions results

First tests, the 19th of December, 2014

Final competition, the 23th of January, 2015

Robot #2 finished first with the number of victories/draw/loss, and robot #6 finished first with the number of accumulated points.