Project of Fall 2015: "Snake 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 snake game. General rules of the game are described below. Note the the rules might evolve during the next weeks, as well as the communication protocol.- At first, a game server is started.
- n robots are placed one after the other - to form a snake - in the starting area of the game, inside of a stadium (the stadium/arena is described below).
- Robots are all given a rank ranging from 1 to n. This rank is provided by the server once the robots have made their bluetooth connection to the server. The id of the robot in the server corresponds to the id of the group, see the group section
- Robot with rank #1 is the leader of the snake. It is responsible for finding a ball, grabbing that ball, and bringing it back to the starting area. While finding and grabbing a ball, the robot with rank #1 remains the leader, and each robot #i must follow the robot #i-1. When the leader has grabbed a ball, it should return to "touchdown area": it is then removed from the arena.
- To follow each other, robots must communicate by bluetooth throughout a server. The specific bluetooth communication protocol is defined in the project repository: https://gitlab.eurecom.fr/ludovic.apvrille/os_robot_project_fall2015. This repository also contains the code of the game server, and example codes for NXT and ev3. The server is started and configured (ids, ranks) before each competition round starts. The protocol contains a "CUSTOM" message that you may used beetween robots to send additional information, to make experiment, etc.
- Robots can use up to four sensors and up to three engines.
- The scoring is as follows: when the leader of the snake grabs a ball, it scores 3 points. If it correctly brings back the ball to the starting area, it scores 2 points. Points are scored only if the leader has sent the LEAD message to the follower between the grabbing of the ball and the touchdown. Whenever a robot "successfully" follows another robot until the point at which the leader sends the LEAD message, it scores 1 point, and its predecesor scores 1 point as well. "Successfully" means that the robot remains less than 50cm from the previous robot all the time.
- The shape of the robot must be the same when the robot starts, but the software used for each role (master, follower) can be different, and the id of the robot can be set before the game starts. The robot can be freely re-programmed between game rounds, but you don't have the right to add/remove lego bricks, sensors, etc.
- 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.
- When a robot is bringing back a ball to the starting area, it should not touch any other robots of the snake. Otherwise, it does not score points for bringing back the ball. Once it has reached the touchdown area, it should simply stop.
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.
- 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 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 some) during game phases.
- Your robot is allowed to lose/throw parts on purpose - or not ;-) - during the game. Destructive weapons are NOT allowed.
- 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.
(Click to enlarge)
The smaller stadium has a wooden fence. 2 red/blue balls are placed at predefined locations.
Deadlines and reports
There are two deadlines:- The 14th of December, 2015, 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.
- Navigate alone, that is, be able to explore the arena without getting out.
- Find a ball at a predefined position, grab that ball, and bring back the ball to the touchdown area.
- Find a ball at a reandom location of the arena, grab that ball, and bring it back to the touchdown area.
- Be able to be the leader of be able to be the second in a 2-robot snake.
- The 18th of January, 2016: 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.
We'll first test each robot alone. Each robot - alone in the arena - shall be able to:
The competition will be as follows, with parallel competitions.
- 2-robot snake competition in the small arena (Linux room), with two balls placed at 50 cm from the opposite fence. Each robot will be involved in at least two games. In each game, the robot will play the role of the leader and of the follower.
- 3-robot, 4-robot and 5-robot snake competition in the large arena.
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: leader strategy (e.g., movement choices and ball management), and follower 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.
Groups
(The group leader is listed first. BT adresse starting with 00:17 -> ev3 ; with 00:16 -> NXT2).- wall-ev3: Federico MADOTTO, Chiara CREMON, Alessandro QUARANTA. BT address: 00:17:E9:F5:B9:DE
- Màdara: Marco LUCARELLA, Enrico GIOIA, Giovanni CAMURATI, Simone MARCHISIO. BT adress: 00:17:E9:F5:AF:56
- Grumblin: Coline DOEBELIN, Arthur PLOTEGHER, Yannick WOLFF. BT address: 00:17:E9:F5:B8:69
- LEGOBOT: Yazid GOGHROD Yazid, Alexandre JACQUEMOT, Elfilani JOO, Solène CHABANIER. BT address: 00:16:53:1B:F0:6D
- Darth Invader: Isa A. Halmøy FREDRIKSEN, Helena HAPPE, Marc-André BÄR, Juhani NUORTEVA. BT adress: 00:16:53:15:10:8A
- Bumblebee: Anasse HASSALA, Fredrik SKRETTEBERG, Tobias SCHUSTER. BT address: 00:17:E9:F5:D0:97
- SexyBot: Amine SEMMA, Luc BONNAFOUX, Mathieu CHEVALIER, Nicolas DAUBRESSE. BT address: 00:17:E9:F5:AC:7D
- Kevin: Gabrielle AYNIÉ, Ngoné DIARISSO, Alexandra GAUDRON, Bastien PONCHON. BT address: 00:17:E9:F5:C2:B1
- Achille: Diane ADJAVON, Mehdi BOUSBAINE, Martin MOREL, Fabien LENTHY. BT address: 00:16:53:0C:91:06
- Lockdown: Qiang GUO, XingHan GUO, XiangLei LI. BT address: 00:16:53:15:FC:44
- Bender: Mikael BOSTANCI, Natacha DESERT, Lise COLLOMB. BT address: 00:17:E96:89:BB:AC
- Ludo3000: Célia FAUCHIER, Laura DELEUZE, pierre ECHEGUT. BT address: 00:16:53:0C:82:47
- PacMan: Quentin CHABERT, Clément WEILL, Thomas CHATON. BT adress: 00:16:53:1B:16:86
- ExMachina: Mohamed El YAMANI, Issameddine DAKHLAOUI, Adrien ARTAUD, Jacques MOLLIERE. BT address: 00:16:53:06:17:E8
How to borrow a robot?
There will be 7 groups of 3 students, and 7 groups of 4 students. Each group will either get a NXT2 or an ev3 robot. Please, take care not to loose parts, especially cables and sensors. For NXT2, a battery charger as well as 6 batteries are provided with the robot. For ev3, a charger is provided, as well as a microsd card. The procedure to borrow a robot is as follows:- Make a group of 3 or 4 students, and decide of a group leader.
- The group leader sends me an email with the list of students of the group: list of: first_name, LAST_NAME, email.
- I validate - or not - the group, depending on the availability of the size of the group. If the group is not validated, 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).
- Once I've answered your group with a "validated" information, you can go to Franck Heurtematte's office, at the IT Department. You will be granted either a NXT2 or an ev3 (random selection).
NXT2: 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.
MacOS
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):
- First, I have first dowmloaded the NXC package. I have uncompressed it, and installed it in e.g., /Applications/nxt 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.).
- 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:
- I have downloaded the tutorial samples code, and I have unzipped it, let say in /Users/ludovic.apvrille/code
- I have compiled the "5_light.nxc" code as follows, from a terminal:
- I have plugged my NXT robot on a USB port, and switched it on. Then, I have run the following command on my Mac:
export PATH= $PATH:/Applications/nxt
$ cd /Users/ludovic.apvrille/code $ nbc -O=program.rxe 5_light.nxc
$nxtcom program.rxe
Linux
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 ')
- Create a new group
- Add your user to that group (already existing user)
- Create a new 'rules' file:
- Edit the file, and put the following lines (without the "-"):
- Create a shell for the file above:
- Edit the file, and put the following lines, without "-":
- Give executable rights to that file:
- Reboot
- Compile, download and run, after plugging the brick to USB:
- Compile & download the program to the brick
- Compile & download & run the program on the brick
$ groupadd legonxt
$ usermod -aG legonxt
$ cd /etc/udev/rules.d $ touch 45-legonxt.rules
SUBSYSTEM=="usb_device", ACTION=="add", SYSFS{idVendor}=="0694", SYSFS{idProduct}=="0002", SYMLINK+="legonxt-%k", GROUP="legonxt", MODE="0660", RUN+="/etc/udev/legonxt.sh"
$ cd /etc/udev $ touch legonxt.sh
#!/bin/bash GROUP=legonxt if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ];then chmod o-rwx "${DEVICE}" chgrp "${GROUP}" "${DEVICE}" chmod g+rw "${DEVICE}" fi
$ chmod a+x legonxt.sh
$ nbc hello.nxc -sm- -d -S=usb
$ 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/
Then, to:
- Compile a nxc program:
$ nbc hello.nxc -O=hello.rxe
$ sudo t2n -i
$ 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.
ev3
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 I suggest you develop in C.Installing Linux on ev3
All information to install Linux on your ev3 are given here. This page also explains how to connect to your ev3 via the usb cable and ssh.Using and programming ev3
- Connect to the EV3 from ssh
- If you want to send files, use secureFx or pscp
root@10.42.0.3: - Install the packages for gcc, libbluetooth-dev
- A sample library is provided in the zip ev3c-master. Samples of how to control the motors and sensors are included in test_motor.c and test_sensor.c. The Ultrasonic Sensor is described there.
- A sample file test.c shows how to turn the motor 30 degrees, check the ultrasonic sensor, and print the value. Compile with "make all", and run ./bin/test
- 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.