24#define JEVOIS_DMP_HEADER_SZ 2
25#define JEVOIS_DMP_ACCEL_DATA_SZ 6
26#define JEVOIS_DMP_GYRO_DATA_SZ 6
27#define JEVOIS_DMP_CPASS_DATA_SZ 6
28#define JEVOIS_DMP_ALS_DATA_SZ 8
29#define JEVOIS_DMP_QUAT6_DATA_SZ 12
30#define JEVOIS_DMP_QUAT9_DATA_SZ 14
31#define JEVOIS_DMP_PQUAT6_DATA_SZ 6
32#define JEVOIS_DMP_GEOMAG_DATA_SZ 14
33#define JEVOIS_DMP_PRESSURE_DATA_SZ 6
34#define JEVOIS_DMP_GYRO_BIAS_DATA_SZ 6
35#define JEVOIS_DMP_CPASS_CALIBR_DATA_SZ 12
36#define JEVOIS_DMP_PED_STEPDET_TIMESTAMP_SZ 4
37#define JEVOIS_DMP_FOOTER_SZ 2
40#define JEVOIS_DMP_HEADER2_SZ 2
41#define JEVOIS_DMP_ACCEL_ACCURACY_SZ 2
42#define JEVOIS_DMP_GYRO_ACCURACY_SZ 2
43#define JEVOIS_DMP_CPASS_ACCURACY_SZ 2
44#define JEVOIS_DMP_FSYNC_SZ 2
45#define JEVOIS_DMP_FLIP_PICKUP_SZ 2
46#define JEVOIS_DMP_ACT_RECOG_SZ 6
49#define JEVOIS_DMP_ODR_CNT_GYRO_SZ 2
87 header1 = (packet[0] << 8) | packet[1];
95 accel[0] = (packet[off + 0] << 8) | packet[off + 1];
96 accel[1] = (packet[off + 2] << 8) | packet[off + 3];
97 accel[2] = (packet[off + 4] << 8) | packet[off + 5];
103 gyro[0] = (packet[off + 0] << 8) | packet[off + 1];
104 gyro[1] = (packet[off + 2] << 8) | packet[off + 3];
105 gyro[2] = (packet[off + 4] << 8) | packet[off + 5];
107 gbias[0] = (packet[off + 0] << 8) | packet[off + 1];
108 gbias[1] = (packet[off + 2] << 8) | packet[off + 3];
109 gbias[2] = (packet[off + 4] << 8) | packet[off + 5];
115 cpass[0] = (packet[off + 0] << 8) | packet[off + 1];
116 cpass[1] = (packet[off + 2] << 8) | packet[off + 3];
117 cpass[2] = (packet[off + 4] << 8) | packet[off + 5];
129 quat6[0] = (packet[off + 0] << 24) | (packet[off + 1] << 16) | (packet[off + 2] << 8) | packet[off + 3];
130 quat6[1] = (packet[off + 4] << 24) | (packet[off + 5] << 16) | (packet[off + 6] << 8) | packet[off + 7];
131 quat6[2] = (packet[off + 8] << 24) | (packet[off + 9] << 16) | (packet[off + 10] << 8) | packet[off + 11];
137 quat9[0] = (packet[off + 0] << 24) | (packet[off + 1] << 16) | (packet[off + 2] << 8) | packet[off + 3];
138 quat9[1] = (packet[off + 4] << 24) | (packet[off + 5] << 16) | (packet[off + 6] << 8) | packet[off + 7];
139 quat9[2] = (packet[off + 8] << 24) | (packet[off + 9] << 16) | (packet[off + 10] << 8) | packet[off + 11];
140 quat9acc = (packet[off + 12] << 24) | (packet[off + 13] << 16);
146 stepts = (packet[off + 0] << 24) | (packet[off + 1] << 16) | (packet[off + 2] << 8) | packet[off + 3];
154 geomag[0] = (packet[off + 0] << 24) | (packet[off + 1] << 16) | (packet[off + 2] << 8) | packet[off + 3];
155 geomag[1] = (packet[off + 4] << 24) | (packet[off + 5] << 16) | (packet[off + 6] << 8) | packet[off + 7];
156 geomag[2] = (packet[off + 8] << 24) | (packet[off + 9] << 16) | (packet[off + 10] << 8) | packet[off + 11];
157 geomagacc = (packet[off + 12] << 24) | (packet[off + 13] << 16);
169 gyrobias[0] = (packet[off + 0] << 8) | packet[off + 1];
170 gyrobias[1] = (packet[off + 2] << 8) | packet[off + 3];
171 gyrobias[2] = (packet[off + 4] << 8) | packet[off + 5];
177 cpasscal[0] = (packet[off + 0] << 24) | (packet[off + 1] << 16) | (packet[off + 2] << 8) | packet[off + 3];
178 cpasscal[1] = (packet[off + 4] << 24) | (packet[off + 5] << 16) | (packet[off + 6] << 8) | packet[off + 7];
179 cpasscal[2] = (packet[off + 8] << 24) | (packet[off + 9] << 16) | (packet[off + 10] << 8) | packet[off + 11];
185 accelacc = (packet[off + 0] << 8) | packet[off + 1];
191 gyroacc = (packet[off + 0] << 8) | packet[off + 1];
197 cpassacc = (packet[off + 0] << 8) | packet[off + 1];
203 fsync = (packet[off + 0] << 8) | packet[off + 1];
209 pickup = (packet[off + 0] << 8) | packet[off + 1];
215 bacstate = (packet[off + 0] << 8) | packet[off + 1];
216 bacts = (packet[off + 2] << 24) | (packet[off + 3] << 16) | (packet[off + 4] << 8) | packet[off + 5];
220 odrcnt = (packet[off + 0] << 8) | packet[off + 1];
223 if (off != siz)
LERROR(
"Decoded " << off <<
" bytes from " << siz <<
" bytes of IMU packet");
229 return float(fsync) * 0.9645F;
235 std::vector<std::string> ret;
241 unsigned char bs[2]; bs[0] = bacstate >> 8; bs[1] = bacstate & 0xff;
243 for (
int i = 0; i < 2; ++i)
245 std::string
const ss = (i == 0) ?
"start " :
"stop ";
248 if (bs[i] &
DMP_BAC_RUN) ret.push_back(ss +
"run");
252 if (bs[i] & ~mask) ret.push_back(ss +
jevois::sformat(
"Unk(0x%02x)", bs[i] & ~mask));
261 std::vector<std::string> ret;
262 static unsigned char act = 0;
267 unsigned char bs[2]; bs[0] = bacstate >> 8; bs[1] = bacstate & 0xff;
284{
return float(val * 1.0 / (1<<30)); }
289 double const ar = arange / 32768.0;
294 double const gr = grange / 32768.0;
299 temp() = rd.
temp() / 333.87F + 21.0F;
301 double const mr = 4912.0 / 32752.0;
306 magovf = ((rd.
mst2() & BIT_AK09916_STATUS2_HOFL) != 0);
#define JEVOIS_DMP_ALS_DATA_SZ
#define JEVOIS_DMP_GYRO_ACCURACY_SZ
#define JEVOIS_DMP_CPASS_CALIBR_DATA_SZ
#define JEVOIS_DMP_HEADER2_SZ
#define JEVOIS_DMP_ODR_CNT_GYRO_SZ
#define JEVOIS_DMP_GYRO_DATA_SZ
#define JEVOIS_DMP_PED_STEPDET_TIMESTAMP_SZ
#define JEVOIS_DMP_HEADER_SZ
#define JEVOIS_DMP_ACT_RECOG_SZ
#define JEVOIS_DMP_ACCEL_ACCURACY_SZ
#define JEVOIS_DMP_PRESSURE_DATA_SZ
#define JEVOIS_DMP_FSYNC_SZ
#define JEVOIS_DMP_FLIP_PICKUP_SZ
#define JEVOIS_DMP_CPASS_ACCURACY_SZ
#define JEVOIS_DMP_QUAT6_DATA_SZ
#define JEVOIS_DMP_GEOMAG_DATA_SZ
#define JEVOIS_DMP_PQUAT6_DATA_SZ
#define JEVOIS_DMP_CPASS_DATA_SZ
#define JEVOIS_DMP_FOOTER_SZ
#define JEVOIS_DMP_ACCEL_DATA_SZ
#define JEVOIS_DMP_GYRO_BIAS_DATA_SZ
#define JEVOIS_DMP_QUAT9_DATA_SZ
#define LERROR(msg)
Convenience macro for users to print out console or syslog messages, ERROR level.
size_t DMPpacketSize(unsigned short ctl1, unsigned short ctl2)
Helper function to determine DMP packet size depending on options.
std::string sformat(char const *fmt,...) __attribute__((format(__printf__
Create a string using printf style arguments.
short cpassacc
Compass accuracy data (when JEVOIS_DMP_CPASS_ACCURACY in header2)
unsigned short bacstate
Activity recognition state (when JEVOIS_DMP_ACT_RECOG in header2)
short gyroacc
Gyro accuracy data (when JEVOIS_DMP_GYRO_ACCURACY in header2)
unsigned short steps
Number of steps (0..7) detected this cycle (when JEVOIS_DMP_PED_STEPDET)
long quat9acc
Quaternion9 accuracy (when JEVOIS_DMP_QUAT9 in header1)
long cpasscal[3]
Compass calibration data (when JEVOIS_DMP_CPASS_CALIBR in header1)
short gyro[3]
Raw gyro data (when JEVOIS_DMP_GYRO in header1)
short gyrobias[3]
Gyro bias/calibration data (when JEVOIS_DMP_GYRO_CALIBR in header1)
std::vector< std::string > activity2()
unsigned short fsync
Delay between FSYNC received from camera and first subsequent IMU data generated.
short accel[3]
Raw accelerometer data (when JEVOIS_DMP_ACCEL in header1)
unsigned short header1
Header 1 fields that indicate what data is valid.
short accelacc
Accelerometer accuracy data (when JEVOIS_DMP_ACCEL_ACCURACY in header2)
void parsePacket(unsigned char const *packet, size_t siz)
Populate our fields from a packet received from the DMP.
short cpass[3]
Raw compass data (when JEVOIS_DMP_CPASS in header1)
std::vector< std::string > activity()
Decode current ongoing activities into a string.
unsigned short header2
Header 2 fields that indicate what data is valid.
unsigned long stepts
Step detection timestamp (when JEVOIS_DMP_PED_STEPDET)
long quat9[3]
Quaternion9 data (when JEVOIS_DMP_QUAT9 in header1)
long geomagacc
Geomag accuracy (when JEVOIS_DMP_GEOMAG in header1)
long quat6[3]
Quaternion6 data (when JEVOIS_DMP_QUAT6 in header1)
float fsync_us() const
Delay between FSYNC and next IMU data, in microseconds.
short pickup
Flip/pickup detection (when JEVOIS_DMP_FLIP_PICKUP in header2)
unsigned short odrcnt
Output data rate counter (always here but unclear what it is)
long geomag[3]
Geomag data (when JEVOIS_DMP_GEOMAG in header1)
long bacts
Activity recognition timestamp (when JEVOIS_DMP_ACT_RECOG in header2)
static float fix2float(long val)
Convert a long fixed-point value to float.
short gbias[3]
Raw gyro bias data (when JEVOIS_DMP_GYRO in header1)
IMUdata(IMUrawData const &rd, double arange, double grange)
Construct from a raw data reading.