-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstop_third_line.c
82 lines (66 loc) · 1.66 KB
/
stop_third_line.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
#pragma config(Sensor, S3, light, sensorLightActive)
#pragma config(Sensor, S1, touch, sensorTouch)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// 48 threshold
void go(int lines);
void back(void);
void pivot_turn(float degrees);
void forward(float revolutions);
void forward_cm(float cm);
task main()
{
for (int i = 1; i < 5; i++) {
go(i);
motor[motorB] = 0;
wait1Msec(200);
back();
}
}
void go(int lines) {
int threshold = 48;
int white_touches = 0;
while (white_touches < lines) {
nSyncedMotors = synchBC;
nSyncedTurnRatio = 100;
motor[motorB] = 40;
if (SensorValue(light) <= threshold) {
motor[motorB] = 0;
white_touches++;
motor[motorB] = 20;
while (SensorValue(light) <= threshold) {}
}
}
nSyncedMotors = synchNone;
}
void back(void) {
pivot_turn(180);
wait1Msec(1000);
nSyncedMotors = synchBC;
nSyncedTurnRatio = 100;
motor[motorB] = 40;
while (SensorValue(touch) == 0) {}
forward_cm(-8);
wait1Msec(1000);
pivot_turn(180);
}
void pivot_turn(float degrees) {
nSyncedMotors = synchCB;
nSyncedTurnRatio = -100;
nMotorEncoder[motorC] = 0;
nMotorEncoderTarget[motorC] = 365 * (degrees/180);
motor[motorC] = (degrees >= 0) ? -20 : 20;
while(nMotorRunState[motorC] != runStateIdle) {}
nSyncedMotors = synchNone;
motor[motorC] = 0;
}
void forward(float revolutions) {
nSyncedMotors = synchBC;
nMotorEncoder[motorB] = 0;
nMotorEncoderTarget[motorB] = revolutions * 360;
nSyncedTurnRatio = 100;
motor[motorB] = (revolutions > 0) ? 40 : -40;
while(nMotorRunState[motorB] != runStateIdle) {}
}
void forward_cm(float cm) {
forward((5 * (cm / 90)) * 100/98);
}