-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGyro.c
52 lines (41 loc) · 1.08 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
#pragma config(Sensor, in2, gyro, sensorGyro)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
bool gyro_valid = false;
float gyro_angle;
task runGyro()
{
int realBias;
int value;
float angle;
float offsetAngle;
SensorType[gyro] = sensorNone;
wait10Msec(50);
SensorType[gyro]= sensorGyro;
wait10Msec(50);
realBias = SensorBias[gyro];
SensorBias[gyro] = SensorBias[gyro] - 1000;
wait10Msec(100);
SensorScale[gyro] = 130;
offsetAngle = SensorValue[gyro];
while(true){
value = SensorValue[gyro];
// Create float angle, remove offset
angle = (value - offsetAngle) / 10.0;
// normalize into the range 0 - 360
if( angle < 0 )
angle += 360;
// put in global for display
gyro_angle = angle;
// We can use the angle
gyro_valid = true;
// Delay
wait1Msec( 20 );
//writeDebugStreamLine("Angle %f", gyro_angle);
}
}
task main(){
startTask(runGyro);
while(true){
writeDebugStreamLine("Angle %f", gyro_angle);
}
}