-
Notifications
You must be signed in to change notification settings - Fork 2
/
testGyro.c
66 lines (49 loc) · 1.25 KB
/
testGyro.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
#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/time.h>
#include <string.h>
long getinstanttime()
{
struct timeval tv;
gettimeofday(&tv,NULL);
return((tv.tv_sec*1000000) + tv.tv_usec);
}
typedef int16_t int16;
typedef int8_t int8;
/* Converting from raw data to degrees/second. */
float calcGyro(int16 raw)
{
float v;
//-- calculate rotation, unit deg/s, range -250, +250
v = (raw * 1.0) / (65536/ 500);
return v;
}
#define BUILD_INT16(loByte, hiByte) ((int16)(((loByte) & 0x00FF) + (((hiByte) & 0x00FF) << 8)))
int main(int argc, char **argv) {
int16 hexX, hexY, hexZ;
int hex1, hex2, hex3;
int8 pData[6];
int inp, i;
FILE *fp;
char filename[200];
filename[0] = 0;
strcat(filename, "/home/optimus-prime/DR-SensorTag-v2/gyro_");
strcat(filename, argv[argc-1]);
fp = fopen(filename, "a+");
int j=0;
for(i=2;i<8;i++,j++) {
sscanf(argv[i], "%x", &inp);
pData[j] = (int8)inp;
}
hexX = BUILD_INT16(pData[0], pData[1]);
hexY = BUILD_INT16(pData[2], pData[3]);
hexZ = BUILD_INT16(pData[4], pData[5]);
fprintf(fp, "%s , ", argv[1]);
fprintf(fp, "%5.3f , ", calcGyro(hexX));
fprintf(fp, "%5.3f , ", calcGyro(hexY));
fprintf(fp, "%5.3f \n", calcGyro(hexZ));
fclose(fp);
}