-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner1.c
79 lines (69 loc) · 1.97 KB
/
runner1.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
#pragma config(Sensor, S1, touchSensor, sensorTouch)
#pragma config(Sensor, S2, compassSensor, sensorVirtualCompass)
#pragma config(Sensor, S3, lightSensor, sensorLightActive)
#pragma config(Sensor, S4, sonarSensor, sensorSONAR)
#pragma config(Motor, motorA, gripperMotor, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, rightMotor, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, leftMotor, tmotorNormal, PIDControl, encoder)
/*************************************\
|* Programmer: Mr. Sep *|
|* Class : Intro to Robotic Eng *|
|* Term : Spring 2022 *|
|* *|
|* Task : Line Runner Level 1 *|
|* Robot : Buggy (CSEE) Bot *|
\*************************************/
void driveStraight(int powerLevel)
{
motor[rightMotor] = powerLevel;
motor[leftMotor] = powerLevel;
}
void turnRight90()
{
nMotorEncoder[leftMotor] = 0;
while (nMotorEncoder[leftMotor] < 146)
{
motor[rightMotor] = -50;
motor[leftMotor] = 50;
}
motor[leftMotor] = 0;
}
task main()
{
string botName = "Buggy (CSEE) Bot";
int fullPower = 100;
int halfPower = 50;
int fullStop = 0;
int lineCount = 0;
bool foundBlack = false;
displayTextLine(2, "%s", botName);
while (true)
{
// move forward full power until touch sensor pressed
// then reverse half power and turn right and forward
if (SensorValue(touchSensor) == 0)
{
driveStraight(30);
}
else
{
driveStraight(-halfPower);
wait1Msec(500);
turnRight90();
}
// red is 27
if (SensorValue(lightSensor) < 30)
foundBlack = true;
if (foundBlack && SensorValue(lightSensor) >= 28)
{
foundBlack = false;
lineCount++;
}
displayTextLine(5, " line#: %d", lineCount);
if (lineCount == 1)
{
driveStraight(fullStop);
break; // exit the current loop
}
}
}