-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminefieldChallenge.c
108 lines (80 loc) · 2.11 KB
/
minefieldChallenge.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
#pragma config(StandardModel, "RVW REMBOT")
/**************************************\
|* ROBOTC Virtual World *|
|* Avoiding obstacles with the Sonar *|
\**************************************/
// This program drives forward until the sonarSensor sensor sees an object closer than a
// set 'threshold' variable. It then backs up and turns right until it sees some space.
//int threshold = 50; threshold for sonarSensor
void moveForward (int waitTime) {
motor[rightMotor] = 75;
motor[leftMotor] = 75;
wait1Msec(waitTime);
}
void pointturnRight (int waitTime) {
motor[rightMotor] = -75;
motor[leftMotor] = 75;
wait1Msec(waitTime);
}
void pointturnLeft (int waitTime) {
motor[rightMotor] = 75;
motor[leftMotor] = -75;
wait1Msec(waitTime);
}
void pause (int waitTime) {
motor[rightMotor] = 0;
motor[leftMotor] = 0;
wait1Msec(waitTime);
}
void avoidWall() {
pause(200);
while(SensorValue(sonar) > 20) {
moveForward(400);
}
pause(200);
pointturnRight(250);
}
task main()
{
//displayString(1, "Dominic Diaz");
displayString(1, "Andrew Cini");
displayString(3, "Joshua Wong");
displayString(5, "Abraham Orea");
for (int i = 0; i <= 2; i++) {
while(SensorValue(sonar) > 50)
{
// go forward at speed 75:
moveForward(400);
}
if (SensorValue(sonar) <= 50)
{
motor[rightMotor] = 0;
motor[leftMotor] = 0;
wait1Msec(150);
// turn right in place at speed 75:
pointturnRight(130);
moveForward(1250);
pause(200);
pointturnLeft(140);
pause(200);
while(SensorValue(sonar) > 20) {
motor[rightMotor] = 75;
motor[leftMotor] = 75;
}
pointturnLeft(120);
moveForward(900);
pause(200);
pointturnRight(120);
moveForward(900);
avoidWall();
avoidWall();
while(SensorValue(sonar) < 50) {
motor[leftMotor] = 15;
motor[rightMotor] = -15;
wait1Msec(20);
pause(200);
}
moveForward(150);
}
}
}