1 /* 2 * Ben NanoNote communication with the Pololu MinIMU-9 with the L3G4200D 3-axis 3 * gyroscope and LSM303DLM accelerometer/magnetometer. 4 * 5 * http://www.pololu.com/catalog/product/1265 6 * 7 * Copyright (C) 2013 Paul Boddie 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 */ 14 15 #ifndef __MEASURE_H__ 16 #define __MEASURE_H__ 17 18 #include "geo.h" 19 20 /* Function definitions. */ 21 22 void ui_calibrate(bool using_filter, int (*print)(const char *, ...), void (*flush)()); 23 void *get_measurements(void *arg); 24 25 #ifdef __MEASURE_H_PRIVATE__ 26 27 /* The raw accelerometer value of 1g. */ 28 29 const double acceleration1g = 1000000.0 / IMU_UG_FACTOR; 30 31 /* The device vectors defined in the chosen coordinate system, together with 32 the corresponding initial view axes. */ 33 34 const vectorf devicex0 = {{0, 0, -1}}, viewz0 = {{0, 0, 1}}, 35 devicey0 = {{-1, 0, 0}}, viewx0 = {{1, 0, 0}}, 36 devicez0 = {{0, -1, 0}}, viewy0 = {{0, 1, 0}}; 37 38 /* Measurements. */ 39 40 vectorf accelerationB[IMU_ACCEL_BUFFER_SIZE], 41 acceleration, 42 acceleration0 = {{0, 0, 0}}, 43 rotation, 44 rotation0 = {{0, 0, 0}}, 45 field, 46 fieldmin = {{-319.0, -303.0, -333.0}}, 47 fieldmax = {{101.0, 124.0, 87.0}}; 48 49 /* Timekeeping. */ 50 51 struct timeval imu_updated, imu_magnet_updated; 52 uint32_t imu_period = 0; 53 54 /* Orientation. */ 55 56 vectorf devicex, devicey, devicez, 57 viewx, viewy, viewz, 58 accelerationD, 59 accelerationR = {{0, 0, -1}}, 60 accelerationRD = {{0, 1, 0}}, 61 fieldD = {{0, 0, 0}}, 62 fieldD0 = {{0, 0, 0}}, 63 field0 = {{0, 0, 0}}, 64 fieldN = {{0, 0, 0}}, 65 fieldE = {{0, 0, 0}}; 66 double direction, elevation, tilt, 67 elevationA = 0, tiltA = 0, 68 directionF, elevationF, 69 directionF0, elevationF0; 70 71 /* Measurement thread. */ 72 73 pthread_t thread; 74 pthread_mutex_t mutex; 75 76 #else 77 78 extern const double acceleration1g; 79 extern vectorf devicex0, devicey0, devicez0, 80 devicex, devicey, devicez, 81 viewx0, viewy0, viewz0, 82 viewx, viewy, viewz, 83 accelerationB[IMU_ACCEL_BUFFER_SIZE], 84 acceleration, 85 acceleration0, 86 accelerationD, 87 accelerationR, 88 accelerationRD, 89 rotation, 90 rotation0, 91 field, 92 fieldmin, fieldmax, 93 fieldD, fieldD0, field0, fieldN, fieldE; 94 extern struct timeval imu_updated; 95 extern uint32_t imu_period; 96 extern double direction, elevation, tilt, 97 elevationA, tiltA, 98 directionF, elevationF, 99 directionF0, elevationF0; 100 101 /* Measurement thread. */ 102 103 extern pthread_t thread; 104 extern pthread_mutex_t mutex; 105 106 #endif /* __MEASURE_H_PRIVATE__ */ 107 108 #endif /* __MEASURE_H__ */