-
Notifications
You must be signed in to change notification settings - Fork 6
/
Gyro.c
80 lines (60 loc) · 1.72 KB
/
Gyro.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
#pragma config(Sensor, in8, gyroSensor, sensorGyro)
#pragma config(Motor, port2, frontL, tmotorVex393TurboSpeed_MC29, openLoop, reversed, encoderPort, None)
#pragma config(Motor, port3, backL, tmotorVex393TurboSpeed_MC29, openLoop, reversed)
#pragma config(Motor, port4, frontR, tmotorVex393TurboSpeed_MC29, openLoop)
#pragma config(Motor, port5, backR, tmotorVex393TurboSpeed_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task initialize(){
SensorValue(gyroSensor) = sensorNone;
SensorValue(gyroSensor) = gyroSensor;
}
//place holder until I find Motor control code
void turn (char side) {
/*
int speed = 0;
if (side == 'l' || side == 'L') {
speed = 50;
}
else if (side == 'r' || side == 'R') {
speed = -50;
}
motor[frontL] = speed;
motor[backL] = speed;
motor[frontR] = -speed;
motor[backR] = -speed;
*/
}
//generic turn method, à la DRY
void turnBy (int degrees, char side) {
int degrees10 = degrees * 10;
//clear sensor value
SensorType[gyroSensor] = sensorNone;
SensorValue[gyroSensor] = sensorGyro;
while (abs(SensorValue[gyroSensor]) < degrees10) {
turn(side);
}
}
//what should be called if robot wants to turn left or right by specified amount
void turnLeftBy(int degrees)
{
turnBy(degrees,'L');
}
void turnRightBy(int degrees)
{
turnBy(degrees, 'R');
}
//Tests the gyro sensor. Makes the robot turn left 90 degrees, and then return into the starting postion.
task gyroTest()
{
int degrees = 90;
turnLeftBy(degrees);
wait1Msec(200);
turnRightBy(degrees);
wait1Msec(500);
}
task main() {
while(true) {
startTask(initialize);
startTask(gyroTest);
}
}