-
Notifications
You must be signed in to change notification settings - Fork 1
/
B15Autonomous.c
151 lines (128 loc) · 3.83 KB
/
B15Autonomous.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
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
140
141
142
143
144
145
146
147
148
149
150
151
#pragma config(Sensor, in1, gyro, sensorGyro)
#pragma config(Sensor, in2, gyro2, sensorGyro)
#pragma config(Sensor, dgtl1, rightEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, leftEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl5, touchSensor, sensorTouch)
#pragma config(Motor, port1, rightBack, tmotorVex393HighSpeed_HBridge, openLoop, reversed)
#pragma config(Motor, port2, rightMid, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port3, leftBack, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port4, mobileLift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, swingArm, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, elevatorLift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, grabber, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, leftFront, tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor, port9, leftMid, tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port10, rightFront, tmotorVex393HighSpeed_HBridge, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
void moveForward(int speed) {
motor[leftBack] = speed;
motor[leftMid] = speed;
motor[leftFront] = speed;
motor[rightBack] = speed;
motor[rightMid] = speed;
motor[rightFront] = speed;
}
void turnRight(int speed) {
motor[leftBack] = speed;
motor[leftMid] = speed;
motor[leftFront] = speed;
motor[rightBack] = -speed;
motor[rightMid] = -speed;
motor[rightFront] = -speed;
}
void turnLeft(int speed) {
motor[rightBack] = speed;
motor[rightMid] = speed;
motor[rightFront] = speed;
motor[leftBack] = -speed;
motor[leftMid] = -speed;
motor[leftFront] = -speed;
}
task main()
{
SensorValue[rightEncoder] = 0;
SensorType[in1] = sensorNone;
SensorType[in2] = sensorNone;
wait1Msec(1000);
SensorType[in1] = sensorGyro;
SensorType[in2] = sensorGyro;
wait1Msec(2000);
//Keep grabber tight
motor[grabber] = 127;
//Raise the elevator lift
motor[elevatorLift] = -127;
wait1Msec(2000);
motor[elevatorLift] = 0;
//Lower the mobile goal lift
motor[mobileLift] = 127;
wait1Msec(2000);
motor[mobileLift] = 0;
//Move Forward
while (4 * PI * SensorValue[rightEncoder] / 360 < 52) {
moveForward(127);
}
moveForward(0);
//Raise the mobile goal lift
motor[mobileLift] = -127;
wait1Msec(2000);
motor[mobileLift] = 0;
//Raise the arm a little bit and lower elevator lift
motor[swingArm] = -127;
motor[elevatorLift] = 127;
wait1Msec(400);
motor[swingArm] = 0;
wait1Msec(300);
motor[elevatorLift] = 0;
//Release the grabber
motor[grabber] = -127;
wait1Msec(1500);
motor[grabber] = 0;
//Swing the arm back
motor[swingArm] = -127;
wait1Msec(1500);
motor[swingArm] = 0;
//Raise the elevator lift
motor[elevatorLift] = -127;
wait1Msec(1200);
motor[elevatorLift] = 0;
//Move Backward
while(4 * PI * SensorValue[rightEncoder] / 360 > 0) {
moveForward(-127);
}
moveForward(0);
SensorValue[gyro] = 0;
//Turn Left
while( abs( SensorValue[gyro] ) < 1100) {
turnLeft(127);
}
turnLeft(0);
//Reset the rightEncoder
SensorValue[rightEncoder] = 0;
//Move Forward
while (4 * PI * SensorValue[rightEncoder] / 360 < 12) {
moveForward(127);
}
moveForward(0);
//Reset the gyro
SensorValue[gyro] = 0;
//Turn Left 90 Degrees
while ( abs( SensorValue[gyro]) < 800) {
turnLeft(127);
}
turnLeft(0);
//Move Forward at full speed
moveForward(127);
wait1Msec(2000);
moveForward(0);
//Lower the mobile goal lift
motor[mobileLift] = 127;
wait1Msec(2000);
motor[mobileLift] = 0;
//Move backward at full speed
moveForward(-127);
wait1Msec(500);
motor[mobileLift] = -127;
wait1Msec(1500);
moveForward(0);
motor[mobileLift] = 0;
}