forked from PaulStoffregen/MotionCal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimuread.c
More file actions
79 lines (64 loc) · 1.82 KB
/
imuread.c
File metadata and controls
79 lines (64 loc) · 1.82 KB
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
#if defined(LINUX)
#include "imuread.h"
#include <GL/glut.h> // sudo apt-get install xorg-dev libglu1-mesa-dev freeglut3-dev
void die(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
static void timer_callback(int val)
{
int r;
glutTimerFunc(TIMEOUT_MSEC, timer_callback, 0);
r = read_serial_data();
if (r < 0) die("Error reading %s\n", PORT);
glutPostRedisplay(); // TODO: only redisplay if data changes
}
static void glut_display_callback(void)
{
display_callback();
glutSwapBuffers();
}
static void glut_keystroke_callback(unsigned char ch, int x, int y)
{
if (magcal.FitError > 9.0) {
printf("Poor Calibration: ");
printf("soft iron fit error = %.1f%%\n", magcal.FitError);
return;
}
printf("Magnetic Calibration: (%.1f%% fit error)\n", magcal.FitError);
printf(" %7.2f %6.3f %6.3f %6.3f\n",
magcal.V[0], magcal.invW[0][0], magcal.invW[0][1], magcal.invW[0][2]);
printf(" %7.2f %6.3f %6.3f %6.3f\n",
magcal.V[1], magcal.invW[1][0], magcal.invW[1][1], magcal.invW[1][2]);
printf(" %7.2f %6.3f %6.3f %6.3f\n",
magcal.V[2], magcal.invW[2][0], magcal.invW[2][1], magcal.invW[2][2]);
send_calibration();
}
int main(int argc, char *argv[])
{
raw_data_reset();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(600, 500);
glutCreateWindow("IMU Read");
visualize_init();
glutReshapeFunc(resize_callback);
glutDisplayFunc(glut_display_callback);
glutTimerFunc(TIMEOUT_MSEC, timer_callback, 0);
glutKeyboardFunc(glut_keystroke_callback);
if (!open_port(PORT)) die("Unable to open %s\n", PORT);
glutMainLoop();
close_port();
return 0;
}
void die(const char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
close_port();
exit(1);
}
#else
int main(int argc, char *argv[])
{
return 0;
}
#endif