From 09dd88ec0159f1aae1bc9de237615206be9ea723 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Fri, 11 Mar 2016 14:41:30 -0800 Subject: [PATCH] df_hmc5883_wrapper: fix mag rotation The external GPS+Mag needs some rotation. --- .../posix/drivers/df_hmc5883_wrapper/df_hmc5883_wrapper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/platforms/posix/drivers/df_hmc5883_wrapper/df_hmc5883_wrapper.cpp b/src/platforms/posix/drivers/df_hmc5883_wrapper/df_hmc5883_wrapper.cpp index 65d2992655..50a496a0f7 100644 --- a/src/platforms/posix/drivers/df_hmc5883_wrapper/df_hmc5883_wrapper.cpp +++ b/src/platforms/posix/drivers/df_hmc5883_wrapper/df_hmc5883_wrapper.cpp @@ -168,6 +168,12 @@ int DfHmc9250Wrapper::_publish(struct mag_sensor_data &data) mag_report mag_report = {}; mag_report.timestamp = data.last_read_time_usec; + /* The standard external mag by 3DR has x pointing to the + * right, y pointing backwards, and z down, therefore switch x + * and y and invert y. */ + data.field_x_ga = -data.field_y_ga; + data.field_y_ga = data.field_x_ga; + // TODO: remove these (or get the values) mag_report.x_raw = NAN; mag_report.y_raw = NAN;