Source code
Tree view
The source code is available at: OS Project - GitLab EURECOM
1. Project structure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
.
├── .vscode # vscode config for ev3dev parsing
├── autodeploy.sh # Build and deploy on the ev3 brick script
├── build # Build output directory
│ └── ...
├── cross_compilation # Docker config files to setup cross-compilation
│ ├── docker-compose.yml
│ ├── Dockerfile
│ └── README.md # Instructions
├── ev3 # ev3dev source code for vscode (or other IDE) parsing
│ └── ...
├── README.md # Basic instructions
└── src # Source code (see below)
└── ...
2. Code structure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
./src/
├── main.c # Main file which contains our algorithm for the capture the flag using all other functions
├── Makefile # Makefile to build
├── motors # Motors related
│ ├── grabber.c # Grab and release flag functions
│ ├── grabber.h
│ ├── wheels.c # Control the wheels without using data from sensors (see common.c)
│ └── wheels.h
├── sensors
│ ├── color.c # Get color value with color sensor
│ ├── color.h
│ ├── gyro.c # Get angle with gyroscope
│ ├── gyro.h
│ ├── sonar.c # Get distance with sonar
│ └── sonar.h
└── utils
├── common.c # Functions that uses motors and sensors
├── common.h
└── globals.h # Global variables
3. Functions description
Only important and most used functions with be detailed here.
You can follow the source code and read the description at the same time for better comprehension.
-
int rotate(int target_angle)
:One of the most important function since we need to be able to center to catch the flag.
Its implementation should favor the precision (angle) rather than the speed.
The rotation makes use of the two wheels to keep the center of the robot (center of the wheels) fixed so that when we rotate 360°, the robot doesn’t move.
The rotation is made possible by making one wheel turning in one direction (e.g. positive speed) and the other wheel in the opposite direction (negative speed).
To ensure the precision i.e. the angle at the end is exactly the targeted angle, we get the current angle value every
dt
(small amount of time) to adapt the speed of wheels. Moreover, we slow down the speed when we are aproaching the target angle to avoid oscillation due to a high speed. -
void go_until_color(int base_speed, int duration, int target_color, int min_distance)
:The function that guides the robot to the opponent area since we know that there is a green line.
This function uses all sensors (gyro, sonar and color sensor):
- gyro to keep straight;
- sonar to detect obstacle;
- color sensor to detect the color.
As in
rotate
, the values from sensors are periodically updated (dt
time) to adapt its trajectory (gyro), stop in front of an obstacle (sonar) and stop on the green line (color sensor). -
void centering()
:Key function to catch the flag.
This function makes the robot turn to 90 and -90 degree to compute the distance of its right and left side.
We know that the width of the arena is around 800 (unit from the sonar) so by computing the distance of its right and left side we can find the side where the robot is too far and the go toward that side until we reach the middle distance.
Obstacles can deform the result so we check that the sum of the right and left side distances is greater than the
ARENA_MIN_WIDTH
to make sure there are no obstacle. If it’s not the case, the robot goes forward until there is no obstacle.