kriswiner / GY-80

10DoF sensor fusion with AHRS
10 stars 6 forks source link

Why accelerometer measurements are shifted by 6 places while calculating bias #2

Open nsparag opened 8 years ago

nsparag commented 8 years ago

Why accelerometer measurements are shifted by 6 places while calculating bias

(line number 1080-1086) for(ii = 0; ii < samples ; ii++) { _readBytes(ADXL345_ADDRESS, ADXL345DATAX0, 6, &data[0]); _accel_bias[0] += (((int16t)data[1] << 8) | data[0]) >> 6; _accel_bias[1] += (((int16t)data[3] << 8) | data[2]) >> 6; _accel_bias[2] += (((int16t)data[5] << 8) | data[4]) >> 6; }_

whereas while reading raw data, measurements are not shifted

(line number 688 to 695) _void readAccelData(int16t * destination) { _uint8_t rawData[6]; // x/y/z accel register data stored here readBytes(ADXL345_ADDRESS, ADXL345_DATAX0, 6, &rawData[0]); // Read the six raw data registers into data array destination[0] = ((int16_t)rawData[1] << 8) | rawData[0]; // Turn the MSB and LSB into a signed 16-bit value destination[1] = ((int16_t)rawData[3] << 8) | rawData[2];
destination[2] = ((int16t)rawData[5] << 8) | rawData[4]; }

kriswiner commented 8 years ago

It's a good question. It's been a couple of years since I looked at this but it seems that for the offset registers, the data is in a particular format, sot his might be one reason. In other words, the format is always 10-bit resolution, so shifting to the right 6 bits seems right. On the other hand, the data proper can be 10- or 13-bit depending on the resolution mode and the full-scale range, so the choice is made to read the full 16-bits including the repeated bits to the left of the MSB and this way it is independent of resolution. Maybe the same choice could have been made for the bias calibration but this is the choice I made. You should consult the data sheet, which you sill find wickedly complicated and confusing. Good luck!

Kris

-----Original Message----- From: nsparag [mailto:notifications@github.com] Sent: April 10, 2016 3:00 AM To: kriswiner/GY-80 Subject: [kriswiner/GY-80] Why accelerometer measurements are shifted by 6 places while calculating bias (#2)

Why accelerometer measurements are shifted by 6 places while calculating bias

(line number 1080-1086) for(ii = 0; ii < samples ; ii++) { readBytes(ADXL345_ADDRESS, ADXL345_DATAX0, 6, &data[0]); accel_bias[0] += (((int16_t)data[1] << 8) | data[0]) >> 6; accel_bias[1] += (((int16_t)data[3] << 8) | data[2]) >> 6; accel_bias[2] += (((int16t)data[5] << 8) | data[4]) >> 6; }

whereas while reading raw data, measurements are not shifted

(line number 688 to 695) void readAccelData(int16_t * destination) { uint8_t rawData[6]; // x/y/z accel register data stored here readBytes(ADXL345_ADDRESS, ADXL345_DATAX0, 6, &rawData[0]); // Read the six raw data registers into data array destination[0] = ((int16_t)rawData[1] << 8) | rawData[0]; // Turn the MSB and LSB into a signed 16-bit value destination[1] = ((int16_t)rawData[3] << 8) | rawData[2];

destination[2] = ((int16_t)rawData[5] << 8) | rawData[4]; }

You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/kriswiner/GY-80/issues/2 https://github.com/notifications/beacon/AGY1qv_erLQwWsCsXp1jjghC21OMbAoVks5 p2MoygaJpZM4IDz9P.gif