-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFTC_Gyro.c
60 lines (46 loc) · 1014 Bytes
/
FTC_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
#ifndef FTC_GYRO_h
#define FTC_GYRO_h
#include "FTC_ValueUtils.h"
#include "drivers/HTGYRO-driver.h"
#ifndef GYRO
#error "Gyro not defined. Define GYRO or remove Gyro library"
#endif
typedef struct
{
float degsec;
float deg;
int offset;
} gyroData_t;
gyroData_t gyroData;
task gyroTask()
{
float lastTime = nPgmTime;
while(1)
{
gyroData.degsec = HTGYROreadRot(GYRO);
gyroData.deg += dbc(gyroData.degsec,1)*((nPgmTime-lastTime)/1000);
lastTime = nPgmTime;
wait1Msec(1);
}
}
void initGyro()
{
hogCPU();
nxtDisplayBigTextLine(0,"Gyro");
nxtDisplayString(2, "The gyro");
nxtDisplayString(3,"is calibrating!");
nxtDisplayString(5,"DO NOT MOVE THE");
nxtDisplayString(6, " ROBOT.");
wait1Msec(1000);
gyroData.degsec = 0;
gyroData.deg = 0;
gyroData.offset = HTGYROstartCal(GYRO);
eraseDisplay();
releaseCPU();
StartTask(gyroTask, 10);
}
int getGyroAngle()
{
return -gyroData.deg;
}
#endif