# Accelerometer and Gyroscope axes don't match up

It seems like the translation matrices for the BHI160 aren't completely consistent. Using the "BHI160" app to read the sensor data, it looks like the accelerometer is a left-handed coordinate system. If the badge is lying flat on a table:

- X points right
- Y points forward
- Z points down (into the table)

However the gyro axes aren't the same (if we assume positive values being clockwise rotation around the directional vector):

- X points right
- Y points forward
- Z points up

As can be seen, the Z axis is inverted. This means that while downward acceleration (like gravity) causes positive accel values, clockwise rotation around the vertical axis causes negative gyro values.

To try to fix this, I changed the translation matrix in bhi.c to invert the Z axis:

```
-static int8_t bhi160_mapping_matrix[3 * 3] = { 0, -1, 0, 1, 0, 0, 0, 0, 1 };
+static int8_t bhi160_mapping_matrix[3 * 3] = { 0, -1, 0, 1, 0, 0, 0, 0, -1 };
```

This does indeed fix the gyro axis! Gyro Z now points down, with clockwise rotation causing positive values. This matrix is used for both the gyro and the accelerometer though, so the accelerometer should have been inverted too - which doesn't happen. In fact the accelerometer seems to be completely immune to this matrix, which may be a separate issue.