Skip to content

Commit 06b9142

Browse files
committed
Use standard orientation for IMU axes
1 parent 2edcc00 commit 06b9142

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

ICM20948.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,6 @@ void ICM20948::getAccel(float& x, float& y, float& z) const {
278278
x = x * G;
279279
y = y * G;
280280
z = z * G;
281-
// orient axes to match MPU9250 library
282-
// TODO: switch to internal accel and gyro axes
283-
double tmp = x;
284-
x = y;
285-
y = tmp;
286-
z = -z;
287281
}
288282

289283
float ICM20948::getTemp() const {
@@ -304,12 +298,6 @@ void ICM20948::getGyro(float& x, float& y, float& z) const {
304298
x = x * DEG_TO_RAD;
305299
y = y * DEG_TO_RAD;
306300
z = z * DEG_TO_RAD;
307-
// orient axes to match MPU9250 library
308-
// TODO: switch to internal accel and gyro axes
309-
double tmp = x;
310-
x = y;
311-
y = tmp;
312-
z = -z;
313301
}
314302

315303
void ICM20948::getMag(float& x, float& y, float& z) const {
@@ -320,12 +308,10 @@ void ICM20948::getMag(float& x, float& y, float& z) const {
320308
x = x * AK09916_MAG_LSB;
321309
y = y * AK09916_MAG_LSB;
322310
z = z * AK09916_MAG_LSB;
323-
// orient axes to match MPU9250 library
324-
// TODO: switch to internal accel and gyro axes
325-
double tmp = x;
326-
x = -y;
327-
y = tmp;
328-
z = z;
311+
// orient magnetometer to match accel and gyro
312+
x = x;
313+
y = -y;
314+
z = -z;
329315
}
330316

331317

MPU9250.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -453,20 +453,20 @@ bool MPU9250::read() {
453453
new_mag_data_ = false;
454454
}
455455
}
456-
/* Convert to float values and rotate the accel / gyro axis */
457-
accel_[0] = static_cast<float>(accel_cnts_[1]) * accel_scale_ * G_MPS2_;
458-
accel_[1] = static_cast<float>(accel_cnts_[0]) * accel_scale_ * G_MPS2_;
459-
accel_[2] = static_cast<float>(accel_cnts_[2]) * accel_scale_ * -1.0f *
460-
G_MPS2_;
456+
/* Convert to float values */
457+
accel_[0] = static_cast<float>(accel_cnts_[0]) * accel_scale_ * G_MPS2_;
458+
accel_[1] = static_cast<float>(accel_cnts_[1]) * accel_scale_ * G_MPS2_;
459+
accel_[2] = static_cast<float>(accel_cnts_[2]) * accel_scale_ * G_MPS2_;
461460
temp_ = (static_cast<float>(temp_cnts_) - 21.0f) / TEMP_SCALE_ + 21.0f;
462-
gyro_[0] = static_cast<float>(gyro_cnts_[1]) * gyro_scale_ * DEG2RAD_;
463-
gyro_[1] = static_cast<float>(gyro_cnts_[0]) * gyro_scale_ * DEG2RAD_;
464-
gyro_[2] = static_cast<float>(gyro_cnts_[2]) * gyro_scale_ * -1.0f * DEG2RAD_;
461+
gyro_[0] = static_cast<float>(gyro_cnts_[0]) * gyro_scale_ * DEG2RAD_;
462+
gyro_[1] = static_cast<float>(gyro_cnts_[1]) * gyro_scale_ * DEG2RAD_;
463+
gyro_[2] = static_cast<float>(gyro_cnts_[2]) * gyro_scale_ * DEG2RAD_;
465464
/* Only update on new data */
466465
if (new_mag_data_) {
467-
mag_[0] = static_cast<float>(mag_cnts_[0]) * mag_scale_[0];
468-
mag_[1] = static_cast<float>(mag_cnts_[1]) * mag_scale_[1];
469-
mag_[2] = static_cast<float>(mag_cnts_[2]) * mag_scale_[2];
466+
/* Orient magnetometer axes to match accel and gyro */
467+
mag_[0] = static_cast<float>(mag_cnts_[1]) * mag_scale_[0];
468+
mag_[1] = static_cast<float>(mag_cnts_[0]) * mag_scale_[1];
469+
mag_[2] = static_cast<float>(mag_cnts_[2]) * mag_scale_[2] * -1.0f;
470470
}
471471
return true;
472472
}

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ The ICM-20948 IMU driver has the same interface. Only the declaration is changed
7575
ICM20948 IMU(SPI);
7676
```
7777

78+
### IMU axes orientation
79+
80+
Orientation of the IMU axes (including magnetometer) on various boards:
81+
82+
|GY-91|MPU-9265|ICM-20948|
83+
|-|-|-|
84+
|<img src="img/gy91-axes.svg" width="200" alt="GY-91 axes orientation">|<img src="img/mpu9265-axes.svg" width="200" alt="MPU-9265 axes orientation">|<img src="img/icm20948-axes.svg" width="200" alt="ICM-20948 axes orientation">|
85+
7886
### Connection
7987

8088
Connecting GY-91 board to ESP32 using VSPI:

0 commit comments

Comments
 (0)