2016-02-20 13:46:16 -08:00
|
|
|
#if defined(LINUX)
|
2016-02-19 17:05:16 -08:00
|
|
|
|
2016-02-14 15:00:53 -08:00
|
|
|
#include "imuread.h"
|
2016-02-18 01:31:30 -08:00
|
|
|
#include <GL/glut.h> // sudo apt-get install xorg-dev libglu1-mesa-dev freeglut3-dev
|
2016-02-13 16:06:36 -08:00
|
|
|
|
2016-02-19 17:05:16 -08:00
|
|
|
void die(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
|
|
|
|
|
|
2016-02-18 01:31:30 -08:00
|
|
|
static void timer_callback(int val)
|
2016-02-13 16:06:36 -08:00
|
|
|
{
|
2016-02-19 17:05:16 -08:00
|
|
|
int r;
|
|
|
|
|
|
2016-02-13 19:58:30 -08:00
|
|
|
glutTimerFunc(TIMEOUT_MSEC, timer_callback, 0);
|
2016-02-19 17:05:16 -08:00
|
|
|
r = read_serial_data();
|
|
|
|
|
if (r < 0) die("Error reading %s\n", PORT);
|
2016-02-14 15:18:56 -08:00
|
|
|
glutPostRedisplay(); // TODO: only redisplay if data changes
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 01:31:30 -08:00
|
|
|
static void glut_display_callback(void)
|
2016-02-14 15:18:56 -08:00
|
|
|
{
|
2016-02-18 01:31:30 -08:00
|
|
|
display_callback();
|
|
|
|
|
glutSwapBuffers();
|
2016-02-13 19:58:30 -08:00
|
|
|
}
|
|
|
|
|
|
2016-03-13 06:18:44 -07:00
|
|
|
static void glut_keystroke_callback(unsigned char ch, int x, int y)
|
|
|
|
|
{
|
2016-03-13 07:45:41 -07:00
|
|
|
if (magcal.FitError > 9.0) {
|
2016-03-13 06:18:44 -07:00
|
|
|
printf("Poor Calibration: ");
|
2016-03-13 07:45:41 -07:00
|
|
|
printf("soft iron fit error = %.1f%%\n", magcal.FitError);
|
2016-03-13 06:18:44 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2016-03-13 07:45:41 -07:00
|
|
|
printf("Magnetic Calibration: (%.1f%% fit error)\n", magcal.FitError);
|
2016-03-13 06:18:44 -07:00
|
|
|
printf(" %7.2f %6.3f %6.3f %6.3f\n",
|
2016-03-13 07:45:41 -07:00
|
|
|
magcal.V[0], magcal.invW[0][0], magcal.invW[0][1], magcal.invW[0][2]);
|
2016-03-13 06:18:44 -07:00
|
|
|
printf(" %7.2f %6.3f %6.3f %6.3f\n",
|
2016-03-13 07:45:41 -07:00
|
|
|
magcal.V[1], magcal.invW[1][0], magcal.invW[1][1], magcal.invW[1][2]);
|
2016-03-13 06:18:44 -07:00
|
|
|
printf(" %7.2f %6.3f %6.3f %6.3f\n",
|
2016-03-13 07:45:41 -07:00
|
|
|
magcal.V[2], magcal.invW[2][0], magcal.invW[2][1], magcal.invW[2][2]);
|
2016-03-13 06:18:44 -07:00
|
|
|
send_calibration();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-13 19:58:30 -08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2016-03-12 12:00:24 -08:00
|
|
|
raw_data_reset();
|
2016-03-11 07:19:03 -08:00
|
|
|
|
2016-02-13 19:58:30 -08:00
|
|
|
glutInit(&argc, argv);
|
2016-02-14 09:22:11 -08:00
|
|
|
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
2016-02-13 19:58:30 -08:00
|
|
|
glutInitWindowSize(600, 500);
|
|
|
|
|
glutCreateWindow("IMU Read");
|
2016-02-16 17:19:44 -08:00
|
|
|
|
|
|
|
|
visualize_init();
|
2016-02-14 09:22:11 -08:00
|
|
|
|
|
|
|
|
glutReshapeFunc(resize_callback);
|
2016-02-18 01:31:30 -08:00
|
|
|
glutDisplayFunc(glut_display_callback);
|
2016-02-13 19:58:30 -08:00
|
|
|
glutTimerFunc(TIMEOUT_MSEC, timer_callback, 0);
|
2016-03-13 06:18:44 -07:00
|
|
|
glutKeyboardFunc(glut_keystroke_callback);
|
2016-02-13 16:06:36 -08:00
|
|
|
|
2016-02-19 17:05:16 -08:00
|
|
|
if (!open_port(PORT)) die("Unable to open %s\n", PORT);
|
2016-02-13 19:58:30 -08:00
|
|
|
glutMainLoop();
|
2016-02-14 15:00:53 -08:00
|
|
|
close_port();
|
2016-02-13 16:06:36 -08:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 17:05:16 -08:00
|
|
|
void die(const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
|
close_port();
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2016-02-13 16:06:36 -08:00
|
|
|
|
2016-02-19 17:05:16 -08:00
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-02-13 16:06:36 -08:00
|
|
|
|
2016-02-19 17:05:16 -08:00
|
|
|
#endif
|