-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.pde
115 lines (94 loc) · 2.15 KB
/
utils.pde
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
inline int changeToVal(int val, int toVal, int dec)
{
if (val < toVal)
return incToMax(val, toVal, dec);
else
return decToMin(val, toVal, dec);
}
inline int incToMax(int val, int maxVal, int dec)
{
if (val < maxVal)
val += dec;
if (val > maxVal)
val = maxVal;
return val;
}
inline int decToMin(int val, int minVal, int dec)
{
if (val > minVal)
val -= dec;
if (val < minVal)
val = minVal;
return val;
}
void resetState()
{
g_robotState.leftEncoder = 0;
g_robotState.rightEncoder = 0;
g_robotState.leftPWM = 0;
g_robotState.rightPWM = 0;
g_robotState.corrector = 0;
g_robotState.dontMoveTicks = 0;
g_robotState.minPwm = MIN_MIN_PWM;
g_robotState.currPlane = 0;
g_robotState.currLen = 0;
g_robotState.lastAddedPlane = -1;
g_robotState.startPlaneTime = 0;
g_robotState.startTime = 0;
g_robotState.rightBackPressed = 0;
g_robotState.leftBackPressed = 0;
RESET_FLAG(ALLOW_WORK);
RESET_FLAG(COLLISION);
RESET_FLAG(ENGINE_STOPED);
for(int i = 0; i < PLANE_COUNT; i++)
{
g_robotState.planes[i].len = 0;
g_robotState.planes[i].speed = 0;
g_robotState.planes[i].type = DO_NOTHING;
}
}
void initRedButton()
{
pinMode(RED_BUTTON_PIN, INPUT_PULLUP);
attachInterrupt(RED_BUTTON_PIN, redButtonPressed, CHANGE);
}
void initBackButtons()
{
pinMode(BACK_BUTTON_LEFT, INPUT_PULLUP);
attachInterrupt(BACK_BUTTON_LEFT, backButtonLeftPressed, FALLING);
pinMode(BACK_BUTTON_RIGHT, INPUT_PULLUP);
attachInterrupt(BACK_BUTTON_RIGHT, backButtonRightPressed, FALLING);
}
void backButtonRightPressed()
{
g_robotState.rightBackPressed = 1;
}
void backButtonLeftPressed()
{
g_robotState.leftBackPressed = 1;
}
void initStartPins()
{
pinMode(START_PIN, INPUT_PULLUP);
// attachInterrupt(START_PIN, startPinStarted, CHANGE);
}
void initDirectionPin()
{
pinMode(DIRECTIN_PIN, INPUT_PULLUP);
}
void startPinStarted()
{
SET_FLAG(ALLOW_WORK);
}
void redButtonPressed()
{
shutDown();
}
void shutDown()
{
noInterrupts();
RESET_FLAG(ALLOW_WORK);
stopEngines();
g_leftDoor.detach();
g_rightDoor.detach();
}