Skip to content

Commit

Permalink
add missing gyro/mag drivers: adapt to new raw msg (unfiltered)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophTobler committed Dec 27, 2017
1 parent b062b6e commit 7c82fd1
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 57 deletions.
12 changes: 4 additions & 8 deletions src/drivers/bmi055/bmi055_gyro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,17 @@ BMI055_gyro::measure()
* 74 from all measurements centers them around zero.
*/

grb.x_raw = report.gyro_x;
grb.y_raw = report.gyro_y;
grb.z_raw = report.gyro_z;

float xraw_f = report.gyro_x;
float yraw_f = report.gyro_y;
float zraw_f = report.gyro_z;

// apply user specified rotation
rotate_3f(_rotation, xraw_f, yraw_f, zraw_f);

grb.x_raw = (int16_t)(xraw_f * _gyro_range_scale * 1000); // (int16) [rad / s * 1000]
grb.y_raw = (int16_t)(yraw_f * _gyro_range_scale * 1000); // (int16) [rad / s * 1000]
grb.z_raw = (int16_t)(zraw_f * _gyro_range_scale * 1000); // (int16) [rad / s * 1000]

float x_gyro_in_new = ((xraw_f * _gyro_range_scale) - _gyro_scale.x_offset) * _gyro_scale.x_scale;
float y_gyro_in_new = ((yraw_f * _gyro_range_scale) - _gyro_scale.y_offset) * _gyro_scale.y_scale;
float z_gyro_in_new = ((zraw_f * _gyro_range_scale) - _gyro_scale.z_offset) * _gyro_scale.z_scale;
Expand Down Expand Up @@ -867,7 +867,3 @@ BMI055_gyro::print_registers()

printf("\n");
}




4 changes: 4 additions & 0 deletions src/drivers/bmm150/bmm150.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@ BMM150::collect()
// apply user specified rotation
rotate_3f(_rotation, mrb.x, mrb.y, mrb.z);

mrb.x_raw = (int16_t)(mrb.x * _range_scale * 1000); // (int16) [Gs * 1000]
mrb.y_raw = (int16_t)(mrb.y * _range_scale * 1000); // (int16) [Gs * 1000]
mrb.z_raw = (int16_t)(mrb.z * _range_scale * 1000); // (int16) [Gs * 1000]


/* Scaling the data */
mrb.x = ((mrb.x * _range_scale) - _scale.x_offset) * _scale.x_scale;
Expand Down
14 changes: 7 additions & 7 deletions src/drivers/fxas21002c/fxas21002c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,17 +1059,17 @@ FXAS21002C::measure()
// whether it has had failures
gyro_report.error_count = perf_event_count(_bad_registers);

gyro_report.x_raw = swap16(raw_gyro_report.x);
gyro_report.y_raw = swap16(raw_gyro_report.y);
gyro_report.z_raw = swap16(raw_gyro_report.z);

float xraw_f = gyro_report.x_raw;
float yraw_f = gyro_report.y_raw;
float zraw_f = gyro_report.z_raw;
float xraw_f = swap16(raw_gyro_report.x);
float yraw_f = swap16(raw_gyro_report.y);
float zraw_f = swap16(raw_gyro_report.z);

// apply user specified rotation
rotate_3f(_rotation, xraw_f, yraw_f, zraw_f);

gyro_report.x_raw = (int16_t)(xraw_f * _gyro_range_scale * 1000); // (int16) [rad / s * 1000]
gyro_report.y_raw = (int16_t)(yraw_f * _gyro_range_scale * 1000); // (int16) [rad / s * 1000]
gyro_report.z_raw = (int16_t)(zraw_f * _gyro_range_scale * 1000); // (int16) [rad / s * 1000]

float x_in_new = ((xraw_f * _gyro_range_scale) - _gyro_scale.x_offset) * _gyro_scale.x_scale;
float y_in_new = ((yraw_f * _gyro_range_scale) - _gyro_scale.y_offset) * _gyro_scale.y_scale;
float z_in_new = ((zraw_f * _gyro_range_scale) - _gyro_scale.z_offset) * _gyro_scale.z_scale;
Expand Down
15 changes: 4 additions & 11 deletions src/drivers/hmc5883/hmc5883.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,17 +979,6 @@ HMC5883::collect()
}
}

/*
* RAW outputs
*
* to align the sensor axes with the board, x and y need to be flipped
* and y needs to be negated
*/
new_report.x_raw = -report.y;
new_report.y_raw = report.x;
/* z remains z */
new_report.z_raw = report.z;

/* scale values for output */

// XXX revisit for SPI part, might require a bus type IOCTL
Expand All @@ -1014,6 +1003,10 @@ HMC5883::collect()
// apply user specified rotation
rotate_3f(_rotation, xraw_f, yraw_f, zraw_f);

new_report.x_raw = (int16_t)(xraw_f * _range_scale * 1000); // (int16) [Gs * 1000]
new_report.y_raw = (int16_t)(yraw_f * _range_scale * 1000); // (int16) [Gs * 1000]
new_report.z_raw = (int16_t)(zraw_f * _range_scale * 1000); // (int16) [Gs * 1000]

new_report.x = ((xraw_f * _range_scale) - _scale.x_offset) * _scale.x_scale;
/* flip axes and negate value for y */
new_report.y = ((yraw_f * _range_scale) - _scale.y_offset) * _scale.y_scale;
Expand Down
15 changes: 5 additions & 10 deletions src/drivers/ist8310/ist8310.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,23 +959,18 @@ IST8310::collect()
/* temperature measurement is not available on IST8310 */
new_report.temperature = 0;

/*
* raw outputs
*
* Sensor doesn't follow right hand rule, swap x and y to make it obey
* it.
*/
new_report.x_raw = report.y;
new_report.y_raw = report.x;
new_report.z_raw = report.z;

/* scale values for output */
xraw_f = report.y;
yraw_f = report.x;
zraw_f = report.z;

/* apply user specified rotation */
rotate_3f(_rotation, xraw_f, yraw_f, zraw_f);

new_report.x_raw = (int16_t)(xraw_f * _range_scale * 1000); // (int16) [Gs * 1000]
new_report.y_raw = (int16_t)(yraw_f * _range_scale * 1000); // (int16) [Gs * 1000]
new_report.z_raw = (int16_t)(zraw_f * _range_scale * 1000); // (int16) [Gs * 1000]

new_report.x = ((xraw_f * _range_scale) - _scale.x_offset) * _scale.x_scale;
new_report.y = ((yraw_f * _range_scale) - _scale.y_offset) * _scale.y_scale;
new_report.z = ((zraw_f * _range_scale) - _scale.z_offset) * _scale.z_scale;
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/l3gd20/l3gd20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,10 @@ L3GD20::measure()
// apply user specified rotation
rotate_3f(_rotation, xraw_f, yraw_f, zraw_f);

report.x_raw = (int16_t)(xraw_f * _gyro_range_scale * 1000); // (int16) [rad / s * 1000]
report.y_raw = (int16_t)(yraw_f * _gyro_range_scale * 1000); // (int16) [rad / s * 1000]
report.z_raw = (int16_t)(zraw_f * _gyro_range_scale * 1000); // (int16) [rad / s * 1000]

float xin = ((xraw_f * _gyro_range_scale) - _gyro_scale.x_offset) * _gyro_scale.x_scale;
float yin = ((yraw_f * _gyro_range_scale) - _gyro_scale.y_offset) * _gyro_scale.y_scale;
float zin = ((zraw_f * _gyro_range_scale) - _gyro_scale.z_offset) * _gyro_scale.z_scale;
Expand Down
12 changes: 4 additions & 8 deletions src/drivers/lis3mdl/lis3mdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,14 +946,6 @@ LIS3MDL::collect()
sensor_is_onboard = !_interface->ioctl(MAGIOCGEXTERNAL, dummy);
new_report.is_external = !sensor_is_onboard;

/*
* RAW outputs
*
*/
new_report.x_raw = report.x;
new_report.y_raw = report.y;
new_report.z_raw = report.z;

/* the LIS3MDL mag on Pixhawk Pro by Drotek has x pointing towards,
* y pointing to the right, and z down, therefore no switch needed,
* it is better to have no artificial rotation inside the
Expand All @@ -966,6 +958,10 @@ LIS3MDL::collect()
// apply user specified rotation
rotate_3f(_rotation, xraw_f, yraw_f, zraw_f);

new_report.x_raw = (int16_t)(xraw_f * _range_scale * 1000); // (int16) [Gs * 1000]
new_report.y_raw = (int16_t)(yraw_f * _range_scale * 1000); // (int16) [Gs * 1000]
new_report.z_raw = (int16_t)(zraw_f * _range_scale * 1000); // (int16) [Gs * 1000]

new_report.x = ((xraw_f * _range_scale) - _scale.x_offset) * _scale.x_scale;
/* flip axes and negate value for y */
new_report.y = ((yraw_f * _range_scale) - _scale.y_offset) * _scale.y_scale;
Expand Down
7 changes: 4 additions & 3 deletions src/drivers/mpu9250/mag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ MPU9250_mag::_measure(struct ak8963_regs data)
* Align axes - note the accel & gryo are also re-aligned so this
* doesn't look obvious with the datasheet
*/
mrb.x_raw = data.x;
mrb.y_raw = -data.y;
mrb.z_raw = -data.z;

float xraw_f = data.x;
float yraw_f = -data.y;
Expand All @@ -222,6 +219,10 @@ MPU9250_mag::_measure(struct ak8963_regs data)
/* apply user specified rotation */
rotate_3f(_parent->_rotation, xraw_f, yraw_f, zraw_f);

mrb.x_raw = (int16_t)(xraw_f * _mag_range_scale * _mag_asa_x * 1000); // (int16) [Gs * 1000]
mrb.y_raw = (int16_t)(yraw_f * _mag_range_scale * _mag_asa_x * 1000); // (int16) [Gs * 1000]
mrb.z_raw = (int16_t)(zraw_f * _mag_range_scale * _mag_asa_x * 1000); // (int16) [Gs * 1000]

mrb.x = ((xraw_f * _mag_range_scale * _mag_asa_x) - _mag_scale.x_offset) * _mag_scale.x_scale;
mrb.y = ((yraw_f * _mag_range_scale * _mag_asa_y) - _mag_scale.y_offset) * _mag_scale.y_scale;
mrb.z = ((zraw_f * _mag_range_scale * _mag_asa_z) - _mag_scale.z_offset) * _mag_scale.z_scale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,15 @@ int DfAK8963Wrapper::_publish(struct mag_sensor_data &data)
mag_report.timestamp = hrt_absolute_time();
mag_report.is_external = true;

// TODO: remove these (or get the values)
mag_report.x_raw = 0;
mag_report.y_raw = 0;
mag_report.z_raw = 0;

math::Vector<3> mag_val(data.field_x_ga, data.field_y_ga, data.field_z_ga);

// apply sensor rotation on the accel measurement
mag_val = _rotation_matrix * mag_val;

mag_report.x_raw = (int16_t)(mag_val(0) * 1000); // (int16) [Gs * 1000]
mag_report.y_raw = (int16_t)(mag_val(1) * 1000); // (int16) [Gs * 1000]
mag_report.z_raw = (int16_t)(mag_val(2) * 1000); // (int16) [Gs * 1000]

mag_report.x = (mag_val(0) - _mag_calibration.x_offset) * _mag_calibration.x_scale;
mag_report.y = (mag_val(1) - _mag_calibration.y_offset) * _mag_calibration.y_scale;
mag_report.z = (mag_val(2) - _mag_calibration.z_offset) * _mag_calibration.z_scale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,17 @@ int DfHmc5883Wrapper::_publish(struct mag_sensor_data &data)
data.field_x_ga = -data.field_y_ga;
data.field_y_ga = tmp;

// TODO: remove these (or get the values)
mag_report.x_raw = 0;
mag_report.y_raw = 0;
mag_report.z_raw = 0;

math::Vector<3> mag_val(data.field_x_ga,
data.field_y_ga,
data.field_z_ga);

// apply sensor rotation on the accel measurement
mag_val = _rotation_matrix * mag_val;

mag_report.x_raw = (int16_t)(mag_val(0) * 1000); // (int16) [Gs * 1000]
mag_report.y_raw = (int16_t)(mag_val(1) * 1000); // (int16) [Gs * 1000]
mag_report.z_raw = (int16_t)(mag_val(2) * 1000); // (int16) [Gs * 1000]

// Apply calibration after rotation.
mag_report.x = (mag_val(0) - _mag_calibration.x_offset) * _mag_calibration.x_scale;
mag_report.y = (mag_val(1) - _mag_calibration.y_offset) * _mag_calibration.y_scale;
Expand Down

0 comments on commit 7c82fd1

Please sign in to comment.