Skip to content

Commit

Permalink
pybricks/util_pb/pb_imu: flip Prime Hub IMU
Browse files Browse the repository at this point in the history
Based on its output values, it appears that the Technic Hub and Prime Hub have this sensor on opposite sides of the PCB.

While orientation is configurable, it is helpful that the default orientation is the same at the driver level, with the buttons facing up.
  • Loading branch information
laurensvalk committed Jan 5, 2021
1 parent f94ab4e commit 2d3410a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pybricks/util_pb/pb_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ void pb_imu_accel_read(pb_imu_dev_t *imu_dev, float_t *values) {
values[0] = data[0] * imu_dev->accel_scale;
values[1] = data[1] * imu_dev->accel_scale;
values[2] = data[2] * imu_dev->accel_scale;

#if PYBRICKS_HUB_PRIMEHUB
// Sensor is upside down
values[0] = -values[0];
values[2] = -values[2];
#endif
}

void pb_imu_gyro_read(pb_imu_dev_t *imu_dev, float_t *values) {
Expand All @@ -203,6 +209,12 @@ void pb_imu_gyro_read(pb_imu_dev_t *imu_dev, float_t *values) {
values[0] = data[0] * imu_dev->gyro_scale;
values[1] = data[1] * imu_dev->gyro_scale;
values[2] = data[2] * imu_dev->gyro_scale;

#if PYBRICKS_HUB_PRIMEHUB
// Sensor is upside down
values[0] = -values[0];
values[2] = -values[2];
#endif
}

#endif // PYBRICKS_PY_COMMON && PYBRICKS_PY_COMMON_IMU

0 comments on commit 2d3410a

Please sign in to comment.