bmx055 magnetometer fix reference frame (#21026)

pull/21040/head
Willem Melching 2021-05-26 06:53:15 +02:00 committed by GitHub
parent 189ee62d00
commit 6340c2a996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -216,18 +216,22 @@ bool BMX055_Magn::parse_xyz(uint8_t buffer[8], int16_t *x, int16_t *y, int16_t *
void BMX055_Magn::get_event(cereal::SensorEventData::Builder &event){
uint64_t start_time = nanos_since_boot();
uint8_t buffer[8];
int16_t x, y, z;
int16_t _x, _y, x, y, z;
int len = read_register(BMX055_MAGN_I2C_REG_DATAX_LSB, buffer, sizeof(buffer));
assert(len == sizeof(buffer));
if (parse_xyz(buffer, &x, &y, &z)){
if (parse_xyz(buffer, &_x, &_y, &z)){
event.setSource(cereal::SensorEventData::SensorSource::BMX055);
event.setVersion(1);
event.setVersion(2);
event.setSensor(SENSOR_MAGNETOMETER_UNCALIBRATED);
event.setType(SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED);
event.setTimestamp(start_time);
// Move magnetometer into same reference frame as accel/gryo
x = -_y;
y = _x;
// Axis convention
x = -x;
y = -y;