![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
K64F based data logger for GPS (ublox MAX M8Q) & 6 Axis Sensor (FXOS8700Q) - Outputs to SD + UDP - Uses FRDM K64F + ublox "Cellular and positioning shield" (3G version)
Dependencies: MAX_M8Q_Capture EthernetInterface FXOS8700Q SDFileSystem eCompass_FPU_Lib mbed-rtos mbed
meta.cpp@3:6085916c9d74, 2015-05-20 (annotated)
- Committer:
- rlinnmoran
- Date:
- Wed May 20 07:14:22 2015 +0000
- Revision:
- 3:6085916c9d74
- Parent:
- 2:bcd60a69583f
First release V1_0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rlinnmoran | 0:77857a36b4ff | 1 | #include "meta.h" |
rlinnmoran | 0:77857a36b4ff | 2 | #include "mbed.h" |
rlinnmoran | 0:77857a36b4ff | 3 | #include "eCompass_Lib.h" |
rlinnmoran | 0:77857a36b4ff | 4 | #include "MAX_M8Q.h" |
rlinnmoran | 2:bcd60a69583f | 5 | #include "debug.h" |
rlinnmoran | 0:77857a36b4ff | 6 | #include <string> |
rlinnmoran | 0:77857a36b4ff | 7 | |
rlinnmoran | 0:77857a36b4ff | 8 | |
rlinnmoran | 0:77857a36b4ff | 9 | // eCompass external declarations |
rlinnmoran | 0:77857a36b4ff | 10 | extern axis6_t axis6; // Structure to store 6Axis data |
rlinnmoran | 0:77857a36b4ff | 11 | extern int captureCompass(void const *argument); // Prototype |
rlinnmoran | 0:77857a36b4ff | 12 | |
rlinnmoran | 0:77857a36b4ff | 13 | extern gpsinfo_t gpsinfo; // Structure that stores GPS data |
rlinnmoran | 0:77857a36b4ff | 14 | extern int captureMAX_M8Q(void); // Prototype |
rlinnmoran | 0:77857a36b4ff | 15 | |
rlinnmoran | 0:77857a36b4ff | 16 | extern int sd_append(char*); // Prototype |
rlinnmoran | 0:77857a36b4ff | 17 | |
rlinnmoran | 2:bcd60a69583f | 18 | extern int UDPTransmit(char*,int); |
rlinnmoran | 2:bcd60a69583f | 19 | |
rlinnmoran | 0:77857a36b4ff | 20 | // Constructor - builds an object that gathers 6axis and GPS data |
rlinnmoran | 0:77857a36b4ff | 21 | MetaData::MetaData() |
rlinnmoran | 0:77857a36b4ff | 22 | { |
rlinnmoran | 0:77857a36b4ff | 23 | //while(1){led = !led;wait(0.5);} |
rlinnmoran | 0:77857a36b4ff | 24 | |
rlinnmoran | 0:77857a36b4ff | 25 | // Capture compass measurement |
rlinnmoran | 2:bcd60a69583f | 26 | D(printf("Starting compass measurement...\r\n")); |
rlinnmoran | 0:77857a36b4ff | 27 | capture6Axis(&axis6); |
rlinnmoran | 0:77857a36b4ff | 28 | |
rlinnmoran | 0:77857a36b4ff | 29 | |
rlinnmoran | 0:77857a36b4ff | 30 | // Capture GPS measurement |
rlinnmoran | 2:bcd60a69583f | 31 | D(printf("Starting GPS measurement...\r\n")); |
rlinnmoran | 0:77857a36b4ff | 32 | captureGPS(&gpsinfo); |
rlinnmoran | 0:77857a36b4ff | 33 | } |
rlinnmoran | 2:bcd60a69583f | 34 | |
rlinnmoran | 2:bcd60a69583f | 35 | MetaData::~MetaData(){} |
rlinnmoran | 0:77857a36b4ff | 36 | |
rlinnmoran | 0:77857a36b4ff | 37 | |
rlinnmoran | 0:77857a36b4ff | 38 | void MetaData::capture6Axis(axis6_t* metaAxis6){ |
rlinnmoran | 0:77857a36b4ff | 39 | |
rlinnmoran | 0:77857a36b4ff | 40 | // Perform compass measurement |
rlinnmoran | 2:bcd60a69583f | 41 | D(printf("Performing compass measurement\r\n")); |
rlinnmoran | 0:77857a36b4ff | 42 | |
rlinnmoran | 0:77857a36b4ff | 43 | if(captureCompass("")) |
rlinnmoran | 2:bcd60a69583f | 44 | D(printf("compass_thread failed:e001\r\n")); |
rlinnmoran | 0:77857a36b4ff | 45 | |
rlinnmoran | 0:77857a36b4ff | 46 | // Assign compass results to MetaData class |
rlinnmoran | 2:bcd60a69583f | 47 | D(printf("Assigning compass results to MetaData class\r\n")); |
rlinnmoran | 0:77857a36b4ff | 48 | |
rlinnmoran | 0:77857a36b4ff | 49 | // Roll, Pitch, Yaw and Compass from the eCompass algorithm |
rlinnmoran | 0:77857a36b4ff | 50 | roll = metaAxis6->roll; |
rlinnmoran | 0:77857a36b4ff | 51 | pitch = metaAxis6->pitch; |
rlinnmoran | 0:77857a36b4ff | 52 | yaw = metaAxis6->yaw; |
rlinnmoran | 0:77857a36b4ff | 53 | |
rlinnmoran | 0:77857a36b4ff | 54 | // Accelerometer data converted to G's |
rlinnmoran | 0:77857a36b4ff | 55 | fGax = metaAxis6->fGax; |
rlinnmoran | 0:77857a36b4ff | 56 | fGay = metaAxis6->fGay; |
rlinnmoran | 0:77857a36b4ff | 57 | fGaz = metaAxis6->fGaz; |
rlinnmoran | 0:77857a36b4ff | 58 | |
rlinnmoran | 0:77857a36b4ff | 59 | // Magnetometer data converted to UT's |
rlinnmoran | 0:77857a36b4ff | 60 | fUTmx = metaAxis6->fUTmx; |
rlinnmoran | 0:77857a36b4ff | 61 | fUTmy = metaAxis6->fUTmy; |
rlinnmoran | 0:77857a36b4ff | 62 | fUTmz = metaAxis6->fUTmz; |
rlinnmoran | 0:77857a36b4ff | 63 | |
rlinnmoran | 0:77857a36b4ff | 64 | // Data from Quaternion converted to floating point |
rlinnmoran | 0:77857a36b4ff | 65 | q0 = metaAxis6->q0; |
rlinnmoran | 0:77857a36b4ff | 66 | q1 = metaAxis6->q1; |
rlinnmoran | 0:77857a36b4ff | 67 | q2 = metaAxis6->q2; |
rlinnmoran | 0:77857a36b4ff | 68 | q3 = metaAxis6->q3; |
rlinnmoran | 0:77857a36b4ff | 69 | |
rlinnmoran | 2:bcd60a69583f | 70 | D(printf("Compass data measured & stored\r\n")); |
rlinnmoran | 0:77857a36b4ff | 71 | } |
rlinnmoran | 0:77857a36b4ff | 72 | |
rlinnmoran | 0:77857a36b4ff | 73 | |
rlinnmoran | 0:77857a36b4ff | 74 | void MetaData::captureGPS(gpsinfo_t* metaGpsinfo){ |
rlinnmoran | 0:77857a36b4ff | 75 | |
rlinnmoran | 0:77857a36b4ff | 76 | //Perform GPS Measurement |
rlinnmoran | 2:bcd60a69583f | 77 | D(printf("Performing GPS measurement\r\n")); |
rlinnmoran | 0:77857a36b4ff | 78 | if(captureMAX_M8Q()) |
rlinnmoran | 2:bcd60a69583f | 79 | D(printf("GPS (captureMAX_M8Q) failed:e001\r\n")); |
rlinnmoran | 0:77857a36b4ff | 80 | |
rlinnmoran | 0:77857a36b4ff | 81 | // Assign GPS results to MetaData class |
rlinnmoran | 2:bcd60a69583f | 82 | D(printf("Assign GPS results to MetaData class\r\n")); |
rlinnmoran | 0:77857a36b4ff | 83 | |
rlinnmoran | 0:77857a36b4ff | 84 | lat = metaGpsinfo->lat; // GPS Latitude (deg) |
rlinnmoran | 0:77857a36b4ff | 85 | lng = metaGpsinfo->lng; // GPS Longitude (deg) |
rlinnmoran | 0:77857a36b4ff | 86 | alt = metaGpsinfo->alt; // GPS Altitude (m) |
rlinnmoran | 0:77857a36b4ff | 87 | NS = metaGpsinfo->NS; // GPS NS indicator |
rlinnmoran | 0:77857a36b4ff | 88 | EW = metaGpsinfo->EW; // GPS EW indicator |
rlinnmoran | 0:77857a36b4ff | 89 | spd = metaGpsinfo->spd; // GPS Speed (kmph) |
rlinnmoran | 0:77857a36b4ff | 90 | utc = metaGpsinfo->utc; // GPS UTC time (hhmmss.ss) |
rlinnmoran | 0:77857a36b4ff | 91 | dte = metaGpsinfo->dte; // GPS Date (ddmmyy) |
rlinnmoran | 0:77857a36b4ff | 92 | |
rlinnmoran | 2:bcd60a69583f | 93 | D(printf("GPS data measured & stored\r\n")); |
rlinnmoran | 0:77857a36b4ff | 94 | |
rlinnmoran | 0:77857a36b4ff | 95 | } |
rlinnmoran | 0:77857a36b4ff | 96 | |
rlinnmoran | 0:77857a36b4ff | 97 | void MetaData::outputToCVSstring(void){ |
rlinnmoran | 0:77857a36b4ff | 98 | |
rlinnmoran | 2:bcd60a69583f | 99 | // int n; |
rlinnmoran | 2:bcd60a69583f | 100 | // n = sprintf(CSVOutput,"%.5f," |
rlinnmoran | 2:bcd60a69583f | 101 | sprintf(CSVOutput,"%.5f," |
rlinnmoran | 0:77857a36b4ff | 102 | "%.5f," |
rlinnmoran | 0:77857a36b4ff | 103 | "%.1f," |
rlinnmoran | 0:77857a36b4ff | 104 | "%c," |
rlinnmoran | 0:77857a36b4ff | 105 | "%c," |
rlinnmoran | 0:77857a36b4ff | 106 | "%.3f," |
rlinnmoran | 0:77857a36b4ff | 107 | "%.2f," |
rlinnmoran | 0:77857a36b4ff | 108 | "%d," |
rlinnmoran | 0:77857a36b4ff | 109 | "%d," |
rlinnmoran | 0:77857a36b4ff | 110 | "%d," |
rlinnmoran | 0:77857a36b4ff | 111 | "%d," |
rlinnmoran | 0:77857a36b4ff | 112 | "%2.3f," |
rlinnmoran | 0:77857a36b4ff | 113 | "%2.3f," |
rlinnmoran | 0:77857a36b4ff | 114 | "%2.3f," |
rlinnmoran | 0:77857a36b4ff | 115 | "%4.1f," |
rlinnmoran | 0:77857a36b4ff | 116 | "%4.1f," |
rlinnmoran | 0:77857a36b4ff | 117 | "%4.1f," |
rlinnmoran | 0:77857a36b4ff | 118 | "%1.4f," |
rlinnmoran | 0:77857a36b4ff | 119 | "%1.4f," |
rlinnmoran | 0:77857a36b4ff | 120 | "%1.4f," |
rlinnmoran | 0:77857a36b4ff | 121 | "%1.4f\r\n", |
rlinnmoran | 0:77857a36b4ff | 122 | lat, |
rlinnmoran | 0:77857a36b4ff | 123 | lng, |
rlinnmoran | 0:77857a36b4ff | 124 | alt, |
rlinnmoran | 0:77857a36b4ff | 125 | NS, |
rlinnmoran | 0:77857a36b4ff | 126 | EW, |
rlinnmoran | 0:77857a36b4ff | 127 | spd, |
rlinnmoran | 0:77857a36b4ff | 128 | utc, |
rlinnmoran | 0:77857a36b4ff | 129 | dte, |
rlinnmoran | 0:77857a36b4ff | 130 | roll, |
rlinnmoran | 0:77857a36b4ff | 131 | pitch, |
rlinnmoran | 0:77857a36b4ff | 132 | yaw, |
rlinnmoran | 0:77857a36b4ff | 133 | fGax, |
rlinnmoran | 0:77857a36b4ff | 134 | fGay, |
rlinnmoran | 0:77857a36b4ff | 135 | fGaz, |
rlinnmoran | 0:77857a36b4ff | 136 | fUTmx, |
rlinnmoran | 0:77857a36b4ff | 137 | fUTmy, |
rlinnmoran | 0:77857a36b4ff | 138 | fUTmz, |
rlinnmoran | 0:77857a36b4ff | 139 | q0, |
rlinnmoran | 0:77857a36b4ff | 140 | q1, |
rlinnmoran | 0:77857a36b4ff | 141 | q2, |
rlinnmoran | 0:77857a36b4ff | 142 | q3); |
rlinnmoran | 0:77857a36b4ff | 143 | |
rlinnmoran | 2:bcd60a69583f | 144 | D(printf("CSVOutput: %s\r\n",CSVOutput)); |
rlinnmoran | 0:77857a36b4ff | 145 | |
rlinnmoran | 0:77857a36b4ff | 146 | } |
rlinnmoran | 0:77857a36b4ff | 147 | |
rlinnmoran | 2:bcd60a69583f | 148 | int MetaData::appendSDcard(void) |
rlinnmoran | 0:77857a36b4ff | 149 | { |
rlinnmoran | 2:bcd60a69583f | 150 | return sd_append(CSVOutput); |
rlinnmoran | 0:77857a36b4ff | 151 | } |
rlinnmoran | 0:77857a36b4ff | 152 | |
rlinnmoran | 2:bcd60a69583f | 153 | int MetaData::transmitUDP(void) |
rlinnmoran | 2:bcd60a69583f | 154 | { |
rlinnmoran | 2:bcd60a69583f | 155 | return UDPTransmit(CSVOutput,sizeof(CSVOutput)); |
rlinnmoran | 2:bcd60a69583f | 156 | } |
rlinnmoran | 0:77857a36b4ff | 157 |