|
|
@@ -60,9 +60,9 @@ Icm20948::Icm20948(SpiManager *spi, icm20948_Config *config){
|
|
|
|
|
|
while(!this->icm20948_who_am_i());
|
|
|
|
|
|
- this->accSensor->data.type = ICM20948_ID;
|
|
|
- this->gyroSensor->data.type = ICM20948_ID + 1;
|
|
|
- this->magSensor->data.type = ICM20948_ID + 2;
|
|
|
+ this->accSensor->data.type = ICM20948_ACCEL + _activeDevice;
|
|
|
+ this->gyroSensor->data.type = ICM20948_GYRO + _activeDevice;
|
|
|
+ this->magSensor->data.type = ICM20948_MAG + _activeDevice;
|
|
|
|
|
|
this->icm20948_device_reset();
|
|
|
this->Wakeup();
|
|
|
@@ -95,8 +95,8 @@ Icm20948::Icm20948(SpiManager *spi, icm20948_Config *config){
|
|
|
|
|
|
void Icm20948::Calibrate(void)
|
|
|
{
|
|
|
- this->icm20948_gyro_calibration();
|
|
|
- this->icm20948_accel_calibration();
|
|
|
+ this->accSensor->Calibrate();
|
|
|
+ this->gyroSensor->Calibrate();
|
|
|
}
|
|
|
|
|
|
bool Icm20948::icm20948_who_am_i()
|
|
|
@@ -204,97 +204,6 @@ void Icm20948::icm20948_odr_align_enable()
|
|
|
_spi->write_single_reg(_activeDevice, ub_2, B2_ODR_ALIGN_EN, 0x01);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void Icm20948::icm20948_gyro_calibration(void)
|
|
|
-{
|
|
|
- axises temp;
|
|
|
- int32_t gyro_bias[3] = {0};
|
|
|
- uint8_t gyro_offset[6] = {0};
|
|
|
-
|
|
|
- for(int i = 0; i < 100; i++)
|
|
|
- {
|
|
|
- this->gyroSensor->Read(&temp);
|
|
|
- gyro_bias[0] += temp.x;
|
|
|
- gyro_bias[1] += temp.y;
|
|
|
- gyro_bias[2] += temp.z;
|
|
|
- }
|
|
|
-
|
|
|
- gyro_bias[0] /= 100;
|
|
|
- gyro_bias[1] /= 100;
|
|
|
- gyro_bias[2] /= 100;
|
|
|
-
|
|
|
- // Construct the gyro biases for push to the hardware gyro bias registers,
|
|
|
- // which are reset to zero upon device startup.
|
|
|
- // Divide by 4 to get 32.9 LSB per deg/s to conform to expected bias input format.
|
|
|
- // Biases are additive, so change sign on calculated average gyro biases
|
|
|
- gyro_offset[0] = (-gyro_bias[0] / 4 >> 8) & 0xFF;
|
|
|
- gyro_offset[1] = (-gyro_bias[0] / 4) & 0xFF;
|
|
|
- gyro_offset[2] = (-gyro_bias[1] / 4 >> 8) & 0xFF;
|
|
|
- gyro_offset[3] = (-gyro_bias[1] / 4) & 0xFF;
|
|
|
- gyro_offset[4] = (-gyro_bias[2] / 4 >> 8) & 0xFF;
|
|
|
- gyro_offset[5] = (-gyro_bias[2] / 4) & 0xFF;
|
|
|
-
|
|
|
- _spi->write_multiple_reg(_activeDevice, ub_2, B2_XG_OFFS_USRH, gyro_offset, 6);
|
|
|
-}
|
|
|
-
|
|
|
-void Icm20948::icm20948_accel_calibration()
|
|
|
-{
|
|
|
- axises temp;
|
|
|
- uint8_t* temp2;
|
|
|
- uint8_t* temp3;
|
|
|
- uint8_t* temp4;
|
|
|
-
|
|
|
- int32_t accel_bias[3] = {0};
|
|
|
- int32_t accel_bias_reg[3] = {0};
|
|
|
- uint8_t accel_offset[6] = {0};
|
|
|
-
|
|
|
- for(int i = 0; i < 100; i++)
|
|
|
- {
|
|
|
- this->accSensor->Read(&temp);
|
|
|
- accel_bias[0] += temp.x;
|
|
|
- accel_bias[1] += temp.y;
|
|
|
- accel_bias[2] += temp.z;
|
|
|
- }
|
|
|
-
|
|
|
- accel_bias[0] /= 100;
|
|
|
- accel_bias[1] /= 100;
|
|
|
- accel_bias[2] /= 100;
|
|
|
-
|
|
|
- uint8_t mask_bit[3] = {0, 0, 0};
|
|
|
-
|
|
|
- temp2 = _spi->read_multiple_reg(_activeDevice, ub_1, B1_XA_OFFS_H, 2);
|
|
|
- accel_bias_reg[0] = (int32_t)(temp2[0] << 8 | temp2[1]);
|
|
|
- mask_bit[0] = temp2[1] & 0x01;
|
|
|
-
|
|
|
- temp3 = _spi->read_multiple_reg(_activeDevice, ub_1, B1_YA_OFFS_H, 2);
|
|
|
- accel_bias_reg[1] = (int32_t)(temp3[0] << 8 | temp3[1]);
|
|
|
- mask_bit[1] = temp3[1] & 0x01;
|
|
|
-
|
|
|
- temp4 = _spi->read_multiple_reg(_activeDevice, ub_1, B1_ZA_OFFS_H, 2);
|
|
|
- accel_bias_reg[2] = (int32_t)(temp4[0] << 8 | temp4[1]);
|
|
|
- mask_bit[2] = temp4[1] & 0x01;
|
|
|
-
|
|
|
- accel_bias_reg[0] -= (accel_bias[0] / 8);
|
|
|
- accel_bias_reg[1] -= (accel_bias[1] / 8);
|
|
|
- accel_bias_reg[2] -= (accel_bias[2] / 8);
|
|
|
-
|
|
|
- accel_offset[0] = (accel_bias_reg[0] >> 8) & 0xFF;
|
|
|
- accel_offset[1] = (accel_bias_reg[0]) & 0xFE;
|
|
|
- accel_offset[1] = accel_offset[1] | mask_bit[0];
|
|
|
-
|
|
|
- accel_offset[2] = (accel_bias_reg[1] >> 8) & 0xFF;
|
|
|
- accel_offset[3] = (accel_bias_reg[1]) & 0xFE;
|
|
|
- accel_offset[3] = accel_offset[3] | mask_bit[1];
|
|
|
-
|
|
|
- accel_offset[4] = (accel_bias_reg[2] >> 8) & 0xFF;
|
|
|
- accel_offset[5] = (accel_bias_reg[2]) & 0xFE;
|
|
|
- accel_offset[5] = accel_offset[5] | mask_bit[2];
|
|
|
-
|
|
|
- _spi->write_multiple_reg(_activeDevice, ub_1, B1_XA_OFFS_H, &accel_offset[0], 2);
|
|
|
- _spi->write_multiple_reg(_activeDevice, ub_1, B1_YA_OFFS_H, &accel_offset[2], 2);
|
|
|
- _spi->write_multiple_reg(_activeDevice, ub_1, B1_ZA_OFFS_H, &accel_offset[4], 2);
|
|
|
-}
|
|
|
-
|
|
|
void Icm20948::SetInterruptSource(interrupt_source_enum int_source)
|
|
|
{
|
|
|
_spi->write_single_reg(_activeDevice, ub_0, B0_INT_PIN_CFG, (INT_PIN_CFG_2CLEAR)); // ( INT_PIN_CFG_LATCH | ...
|
|
|
@@ -384,6 +293,10 @@ void Icm20948::ak09916_operation_mode_setting(AK09916_operation_mode mode)
|
|
|
}
|
|
|
|
|
|
|
|
|
+uint8_t Icm20948::GetIndex(void)
|
|
|
+{
|
|
|
+ return this->_activeDevice + 1;
|
|
|
+}
|
|
|
|
|
|
/* ----------------- SENSORS --------------------
|
|
|
* 1) Sensor Accel
|
|
|
@@ -743,3 +656,94 @@ uint8_t SensorGyro::GetRange(void){
|
|
|
uint8_t new_val = _spi->read_single_reg(_activeDevice, ub_2, B2_GYRO_CONFIG_1);
|
|
|
return (new_val >> 1) & 0x03;
|
|
|
}
|
|
|
+
|
|
|
+void SensorGyro::Calibrate(void)
|
|
|
+{
|
|
|
+ axises temp;
|
|
|
+ int32_t gyro_bias[3] = {0};
|
|
|
+ uint8_t gyro_offset[6] = {0};
|
|
|
+
|
|
|
+ for(int i = 0; i < 100; i++)
|
|
|
+ {
|
|
|
+// this->gyroSensor->Read(&temp);
|
|
|
+ this->Read(&temp);
|
|
|
+ gyro_bias[0] += temp.x;
|
|
|
+ gyro_bias[1] += temp.y;
|
|
|
+ gyro_bias[2] += temp.z;
|
|
|
+ }
|
|
|
+
|
|
|
+ gyro_bias[0] /= 100;
|
|
|
+ gyro_bias[1] /= 100;
|
|
|
+ gyro_bias[2] /= 100;
|
|
|
+
|
|
|
+ // Construct the gyro biases for push to the hardware gyro bias registers,
|
|
|
+ // which are reset to zero upon device startup.
|
|
|
+ // Divide by 4 to get 32.9 LSB per deg/s to conform to expected bias input format.
|
|
|
+ // Biases are additive, so change sign on calculated average gyro biases
|
|
|
+ gyro_offset[0] = (-gyro_bias[0] / 4 >> 8) & 0xFF;
|
|
|
+ gyro_offset[1] = (-gyro_bias[0] / 4) & 0xFF;
|
|
|
+ gyro_offset[2] = (-gyro_bias[1] / 4 >> 8) & 0xFF;
|
|
|
+ gyro_offset[3] = (-gyro_bias[1] / 4) & 0xFF;
|
|
|
+ gyro_offset[4] = (-gyro_bias[2] / 4 >> 8) & 0xFF;
|
|
|
+ gyro_offset[5] = (-gyro_bias[2] / 4) & 0xFF;
|
|
|
+
|
|
|
+ _spi->write_multiple_reg(_activeDevice, ub_2, B2_XG_OFFS_USRH, gyro_offset, 6);
|
|
|
+}
|
|
|
+
|
|
|
+void SensorAccel::Calibrate()
|
|
|
+{
|
|
|
+ axises temp;
|
|
|
+ uint8_t* temp2;
|
|
|
+ uint8_t* temp3;
|
|
|
+ uint8_t* temp4;
|
|
|
+
|
|
|
+ int32_t accel_bias[3] = {0};
|
|
|
+ int32_t accel_bias_reg[3] = {0};
|
|
|
+ uint8_t accel_offset[6] = {0};
|
|
|
+
|
|
|
+ for(int i = 0; i < 100; i++)
|
|
|
+ {
|
|
|
+ this->Read(&temp);
|
|
|
+ accel_bias[0] += temp.x;
|
|
|
+ accel_bias[1] += temp.y;
|
|
|
+ accel_bias[2] += temp.z;
|
|
|
+ }
|
|
|
+
|
|
|
+ accel_bias[0] /= 100;
|
|
|
+ accel_bias[1] /= 100;
|
|
|
+ accel_bias[2] /= 100;
|
|
|
+
|
|
|
+ uint8_t mask_bit[3] = {0, 0, 0};
|
|
|
+
|
|
|
+ temp2 = _spi->read_multiple_reg(_activeDevice, ub_1, B1_XA_OFFS_H, 2);
|
|
|
+ accel_bias_reg[0] = (int32_t)(temp2[0] << 8 | temp2[1]);
|
|
|
+ mask_bit[0] = temp2[1] & 0x01;
|
|
|
+
|
|
|
+ temp3 = _spi->read_multiple_reg(_activeDevice, ub_1, B1_YA_OFFS_H, 2);
|
|
|
+ accel_bias_reg[1] = (int32_t)(temp3[0] << 8 | temp3[1]);
|
|
|
+ mask_bit[1] = temp3[1] & 0x01;
|
|
|
+
|
|
|
+ temp4 = _spi->read_multiple_reg(_activeDevice, ub_1, B1_ZA_OFFS_H, 2);
|
|
|
+ accel_bias_reg[2] = (int32_t)(temp4[0] << 8 | temp4[1]);
|
|
|
+ mask_bit[2] = temp4[1] & 0x01;
|
|
|
+
|
|
|
+ accel_bias_reg[0] -= (accel_bias[0] / 8);
|
|
|
+ accel_bias_reg[1] -= (accel_bias[1] / 8);
|
|
|
+ accel_bias_reg[2] -= (accel_bias[2] / 8);
|
|
|
+
|
|
|
+ accel_offset[0] = (accel_bias_reg[0] >> 8) & 0xFF;
|
|
|
+ accel_offset[1] = (accel_bias_reg[0]) & 0xFE;
|
|
|
+ accel_offset[1] = accel_offset[1] | mask_bit[0];
|
|
|
+
|
|
|
+ accel_offset[2] = (accel_bias_reg[1] >> 8) & 0xFF;
|
|
|
+ accel_offset[3] = (accel_bias_reg[1]) & 0xFE;
|
|
|
+ accel_offset[3] = accel_offset[3] | mask_bit[1];
|
|
|
+
|
|
|
+ accel_offset[4] = (accel_bias_reg[2] >> 8) & 0xFF;
|
|
|
+ accel_offset[5] = (accel_bias_reg[2]) & 0xFE;
|
|
|
+ accel_offset[5] = accel_offset[5] | mask_bit[2];
|
|
|
+
|
|
|
+ _spi->write_multiple_reg(_activeDevice, ub_1, B1_XA_OFFS_H, &accel_offset[0], 2);
|
|
|
+ _spi->write_multiple_reg(_activeDevice, ub_1, B1_YA_OFFS_H, &accel_offset[2], 2);
|
|
|
+ _spi->write_multiple_reg(_activeDevice, ub_1, B1_ZA_OFFS_H, &accel_offset[4], 2);
|
|
|
+}
|