-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrbitPlanet.c
89 lines (73 loc) · 1.86 KB
/
OrbitPlanet.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
void Rotate90(int clockwise)
{
// if clockwise = 1, go clockwise, if -1, ccw
motor[motorB] = 0;
motor[motorC] = clockwise * -50;
wait1Msec(1000);
}
void OrbitPlanet(int planetCode){
if (planetCode == 13){
// Rotate 90 degrees, then start sweeping the sonar sensor
Rotate90(1);
setMotor(0);
// Rotate in the other direction
motor[motorB] = 20;
motor[motorC] = -20;
while(SensorValue[sonarSensor] > 60){
// Keep rotating
}
setMotor(0);
// Now pointing right at the planet, approach the planet
while(SensorValue[sonarSensor] > 20){
setMotor(50);
}
setMotor(0);
// I am now 20cm away from the planet, orbit the planet
// Rotate 90 degrees and do the square orbit
Rotate90(1);
// Go half distance
setMotor(50); // 50 is 22cm/s, square each side should be 50 cm
wait1Msec(100);
setMotor(0);
int i = 0;
for( i = 0; i < 5; i ++){
Rotate90(-1);
// Go full distance
setMotor(50); // 50 is 22cm/s, square each side should be 50 cm
wait1Msec(200);
setMotor(0);
}
}
else if (planetCode==9){
// Rotate 90 degrees, then start sweeping the sonar sensor
Rotate90(-1);
setMotor(0);
// Rotate in the other direction on spot
motor[motorB] = -20;
motor[motorC] = 20;
while(SensorValue[sonarSensor] > 60){
// Keep rotating
}
setMotor(0);
// Now pointing right at the planet, approach the planet
while(SensorValue[sonarSensor] > 20){
setMotor(50);
}
setMotor(0);
// I am now 20cm away from the planet, orbit the planet
// Rotate 90 degrees and do the square orbit
Rotate90(-1);
// Go half distance
setMotor(50); // 50 is 22cm/s, square each side should be 50 cm
wait1Msec(100);
setMotor(0);
int i = 0;
for( i = 0; i < 5; i ++){
Rotate90(1);
// Go full distance
setMotor(50); // 50 is 22cm/s, square each side should be 50 cm
wait1Msec(200);
setMotor(0);
}
}
}