-
Notifications
You must be signed in to change notification settings - Fork 0
/
_ballField.nxc
139 lines (119 loc) · 3.28 KB
/
_ballField.nxc
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Team cyborg++ [rc2017]
* Copyright (C) 2017 Metis Montessori Lyceum
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// WARNING: Always move/turn off the grabber after calling this function!!
void BallGrabberReset () {
OnFwd(MOTOR_GRABBER, -40);
Wait(500);
OnFwd(MOTOR_GRABBER, 40);
until(Update() && sensBumper[BALL]);
Wait(200);
Off(MOTOR_GRABBER);
ResetRotationCount(MOTOR_GRABBER); // 0 should aways equal top.
Wait(1);
}
void BallGrabberDown() {
OnFwd(MOTOR_GRABBER, -40);
// NOTE: The grabbers should block the wheels of the robot.
until(abs(MotorRotationCount(MOTOR_GRABBER)) > 160);
Float(MOTOR_GRABBER);
}
// the BallGrabberUp is highly dependend on the situation and is therefor not a
// function.
void MoveBackwardUntilWall () {
ResetRotationCount(MOTOR_LEFT);
Wait(1);
Move(MOVE_BACKWARD);
long lastMrc = 0;
long mrc = 0;
long lastDiff = 0;
long diff = 0;
do {
lastDiff = diff;
lastMrc = mrc;
Wait(200);
mrc = abs(MotorRotationCount(MOTOR_LEFT));
diff = mrc - lastMrc;
ClearLine(LCD_LINE1);
NumOut(0,LCD_LINE1, diff - lastDiff);
} while (diff - lastDiff > -20)
}
void FindBall () {
ResetRotationCount(MOTOR_LEFT);
Wait(1);
Move(40, 40);
int lastDist;
int diff;
do {
if (sensBumper[CENTER]) {
MoveRot(200, MOVE_BACKWARD);
MoveRot(500, MOVE_RIGHT);
Move(0,0);
ResetRotationCount(MOTOR_LEFT);
Wait(1);
Move(40, 40);
}
lastDist = DISTNxDistance(SENS_PORT_DIST_IR, 0x02);
Wait(200);
diff = DISTNxDistance(SENS_PORT_DIST_IR, 0x02) - lastDist;
ClearLine(LCD_LINE1);
NumOut(0, LCD_LINE1, diff);
NumOut(50, LCD_LINE1, MotorRotationCount(MOTOR_LEFT));
} while (Update() && (diff > -100 || abs(MotorRotationCount(MOTOR_LEFT)) < 200)); // we are only intrested when something comes closer
Move(0,0);
}
void GrabBall () {
MoveBackwardUntilWall();
Move(0,0);
MoveRot(50, MOVE_FORWARD);
Move(0,0);
OnFwd(MOTOR_GRABBER, 40);
Wait(200);
Move(MOVE_FORWARD);
until(Update() && sensBumper[BALL]);
Off(MOTOR_GRABBER);
Move(0,0);
}
void BallRoutine () {
BallGrabberReset();
BallGrabberDown();
MoveRot(700, MOVE_FORWARD);
Move(0,0);
if (SensorUS(SENS_PORT_DIST_US) > 30) {
MoveRot(550, MOVE_LEFT);
Move(0,0);
MoveBackwardUntilWall();
}
Move(0,0);
FindBall();
MoveRot(50, MOVE_FORWARD);
Move(0,0);
MoveRot(500, MOVE_LEFT);
Move(0,0);
Move(100,100);
until(Update() && sensBumper[CENTER]);
Wait(500);
Move(0,0);
GrabBall();
FollowWall(RIGHT, STOP_ON_BALLDUMP);
MoveRot(800, NORMAL_SPEED*0.7, -NORMAL_SPEED);
MoveRot(200, MOVE_BACKWARD);
Move(0,0);
OnFwd(MOTOR_GRABBER, -40);
Wait(200);
Float(MOTOR_GRABBER);
}