-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
124 lines (100 loc) · 2.56 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <avr/io.h>
#include "tools.h"
#include "usart.h"
#include <ctype.h>
#include "roomba.h"
#include "drivecontrol.h"
#include "remotecontrol.h"
#include "floorDetection.h"
#include "power_up.h"
#include "radio.h"
#include "outOfCourseController.h"
/**
* \brief Initialize various modules
*/
void initialization(void) {
usart_init_roomba();
usart_init();
initializeRoomba();
my_msleep(20);
currentPowerUp = NO_POWERUP;
// Get nr. of roomba from remote control
uint8_t rmResult = getRoombaNrFromRemote();
initializeRadio((uint8_t) rmResult);
// Wait a bit so the power button is not pressed immediatley afterwards
my_msleep(200);
}
/**
* \brief See if we received a radio signal and perform corresponding
* actions
*/
void handleRadioSignal(void) {
// Receive radio
// faster when hit by other roomba
char radioSignal = receiveRadio();
if (radioSignal == BUMP_SPEED && !drive_in){
drive_bump_speed();
}
// Receive radio
// Hit by red tank
else if (radioSignal == RED_TANK_SHOT && !drive_in) {
// Hit did not work
if (bigRoombaActive) {
char result[4] = {'N', 'O', 'H', 'T'};
set_Display(result);
playSong(1);
my_msleep(1500);
} else {
char result[4] = {'H', 'I', 'T', ' '};
set_Display(result);
playSong(3);
drive_hit();
}
// Delete Power up
currentPowerUp = NO_POWERUP;
char result[4] = {' ', ' ', ' ', ' '};
set_Display(result);
}
}
int main(int argc, const char* argv[]) {
initialization();
while (1) {
// Get sensor data
// Cliff front left, front right, left, right, remotecontrol, tick_count, bumper, wall sensor
uint8_t packet_ids[8] = {29, 30, 28, 31, 17, 43, 7, 27};
uint8_t packet_length[8] = {2, 2, 2, 2, 1, 2, 1, 2};
uint16_t qdata[8];
getSensorQueryList(8, packet_ids, packet_length, qdata);
remoteSignal signal = getRemoteSignal(qdata[4]);
if (!drive_in) {
bump_handling((uint8_t) qdata[6]);
}
// If we are getting a power up, we need to call this method
// To show the randomize sign at the display and not block
// everything else
showRandomizeSign();
// Count up timer variable
handleTimerVariable();
detectedType dType;
floorDetection(&dType, qdata);
// Detect course border and power up
if (dType != NO_TYPE) {
if (dType == POWER_UP) {
getPowerUp(qdata[5]);
} else {
handleOutOfCourse(dType);
}
}
if (!drive_in) {
// OK Pressed for power ups
if (signal == RSHOOT) {
// Shoot power up
shootPowerUp();
} else {
roomba_drive(signal);
}
}
handleRadioSignal();
}
return 0;
}