Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag for checking if Compass(HMC5883) is Saturated #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/drivers/drv_mag.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct mag_report {
float range_ga;
float scaling;
float temperature;
bool is_saturated;

int16_t x_raw;
int16_t y_raw;
Expand Down
26 changes: 14 additions & 12 deletions src/drivers/hmc5883/hmc5883.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,17 +895,6 @@ HMC5883::collect()
report.y = (((int16_t)hmc_report.y[0]) << 8) + hmc_report.y[1];
report.z = (((int16_t)hmc_report.z[0]) << 8) + hmc_report.z[1];

/*
* If any of the values are -4096, there was an internal math error in the sensor.
* Generalise this to a simple range check that will also catch some bit errors.
*/
if ((abs(report.x) > 2048) ||
(abs(report.y) > 2048) ||
(abs(report.z) > 2048)) {
perf_count(_comms_errors);
goto out;
}

/* get measurements from the device */
new_report.temperature = 0;
if (_conf_reg & HMC5983_TEMP_SENSOR_ENABLE) {
Expand Down Expand Up @@ -956,6 +945,19 @@ HMC5883::collect()
/* z remains z */
new_report.z_raw = report.z;

/*
* If any of the values are -4096, there was an internal math error in the sensor.
* Generalise this to a simple range check that will also catch some bit errors.
*/
if ((abs(report.x) > 2048) ||
(abs(report.y) > 2048) ||
(abs(report.z) > 2048)) {
new_report.is_saturated = true;
perf_count(_comms_errors);
goto send;
} else{
new_report.is_saturated = false;
}
/* scale values for output */

// XXX revisit for SPI part, might require a bus type IOCTL
Expand Down Expand Up @@ -984,6 +986,7 @@ HMC5883::collect()
/* z remains z */
new_report.z = ((zraw_f * _range_scale) - _scale.z_offset) * _scale.z_scale;

send:
if (!(_pub_blocked)) {

if (_mag_topic != -1) {
Expand Down Expand Up @@ -1024,7 +1027,6 @@ HMC5883::collect()
}

ret = OK;

out:
perf_end(_sample_perf);
return ret;
Expand Down