From 2d3410aa2b7018dfc5f523f25e43ded35e22f34a Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Tue, 5 Jan 2021 10:22:21 +0100 Subject: [PATCH] pybricks/util_pb/pb_imu: flip Prime Hub IMU 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. --- pybricks/util_pb/pb_imu.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pybricks/util_pb/pb_imu.c b/pybricks/util_pb/pb_imu.c index b27d798de..61aa1ac1a 100644 --- a/pybricks/util_pb/pb_imu.c +++ b/pybricks/util_pb/pb_imu.c @@ -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) { @@ -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