forked from jorge97fernandez/ImagineCode2018
-
Notifications
You must be signed in to change notification settings - Fork 1
/
race.c
70 lines (61 loc) · 1.45 KB
/
race.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Created by abel on 29/09/18.
//
#include "race.h"
#include "race_white.h"
#include "race_black.h"
#include <pololu/3pi.h>
static char race_mode_selected = 0;
/**
* Function executed only first time mode is executed
*/
void race_mode_setup() {
}
/**
* Function executed when mode is stopped and relaunch.
* If on_mode_create is executed, then this will be executed
*/
void race_mode_start() {
set_motors(0, 0);
unsigned int sensors[5];
unsigned int position = read_line(sensors, IR_EMITTERS_ON);
if (position == 0 || position == 4000) {
race_mode_selected = 1;
} else {
race_mode_selected = 0;
}
}
/**
* Function executed when mode is paused an resume ( When someone press the mode assigned key ).
* If on_mode_start is executed, then this will be executed
*/
void race_mode_resume() {
if (race_mode_selected) {
race_white_mode_resume();
} else {
race_black_mode_resume();
}
}
/**
* Function executed when mode is paused ( When someone press the mode assigned key )
*/
void race_mode_pause() {
set_motors(0, 0);
}
/**
* Function executed when mode is stopped ( When someone press a different mode assigned key ). Its always be executed after
* on_mode_pause.
*/
void race_mode_stop() {
set_motors(0, 0);
}
/**
* Main loop of the mode
*/
void race_mode_loop() {
if (race_mode_selected) {
race_white_mode_loop();
} else {
race_black_mode_loop();
}
}