Skip to content

Commit d09ef67

Browse files
committed
pybricks.hubs.MoveHub.imu: fix signs
Align axes and signs with other hubs.
1 parent 67837ff commit d09ef67

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pybricks/hubs/pb_type_movehub.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,23 @@ static void motion_spi_write(uint8_t reg, uint8_t value) {
131131
GPIOA->BSRR = GPIO_BSRR_BS_4;
132132
}
133133

134+
static void motion_get_acceleration(int8_t *data) {
135+
motion_spi_read(OUT_Y_H, (uint8_t *)&data[0]);
136+
motion_spi_read(OUT_Z_H, (uint8_t *)&data[2]);
137+
motion_spi_read(OUT_X_H, (uint8_t *)&data[1]);
138+
data[1] = -data[1];
139+
}
140+
134141
STATIC mp_obj_t hubs_MoveHub_IMU_acceleration(mp_obj_t self_in) {
135142

136-
uint8_t data[3];
137-
motion_spi_read(OUT_X_H, &data[0]);
138-
motion_spi_read(OUT_Y_H, &data[1]);
139-
motion_spi_read(OUT_Z_H, &data[2]);
143+
// Gets signed acceleration data
144+
int8_t data[3];
145+
motion_get_acceleration(data);
140146

147+
// Convert to appropriate units and return as tuple
141148
mp_obj_t values[3];
142149
for (uint8_t i = 0; i < 3; i++) {
143-
values[i] = MP_OBJ_NEW_SMALL_INT((((int8_t)data[i]) * 10) >> 6);
150+
values[i] = MP_OBJ_NEW_SMALL_INT((data[i] * 10) >> 6);
144151
}
145152
return mp_obj_new_tuple(3, values);
146153
}

0 commit comments

Comments
 (0)