First draft HMC5883 magnetometer sensor using physical quantities, outputting via serial port using std::cout on mbed os 5
Diff: magnetometer.cpp
- Revision:
- 10:75c8ce89aeb7
- Parent:
- 9:87a7169b4d5c
- Child:
- 11:de7c9ae7ef65
--- a/magnetometer.cpp Thu Mar 26 21:35:19 2020 +0000 +++ b/magnetometer.cpp Thu Mar 26 21:59:18 2020 +0000 @@ -10,31 +10,34 @@ bool mag_init() { -// allow magnetometer hardware time to start - if ( Kernel::get_ms_count() < 500U){ - ThisThread::sleep_until(500U); - } - if (! hmc5883L_ID1.detected(true)){ - return false; // usr has been notified - } +// if startup, allow magnetometer hardware time to start + if ( Kernel::get_ms_count() < 500U){ + ThisThread::sleep_until(500U); + } + if (! hmc5883L_ID1.detected(true)){ + return false; // usr has been notified + } - hmc5883L_ID1.set_idle_mode(); - - constexpr auto earth_magnetic_field_flux_density = 31.869_uT; - bool const success = - hmc5883L_ID1.set_samples_average(8) && - hmc5883L_ID1.set_range( earth_magnetic_field_flux_density * 2U); + hmc5883L_ID1.set_idle_mode(); // gains from calib engine quan::three_d::vect<double> gain{1.37689,1.35057,1.56647}; - hmc5883L_ID1.set_gain(gain); - // offsets from calib engine + // offsets from calibration engine + // Need an option to output raw data for calibration quan::three_d::vect< quan::magnetic_flux_density::uT > offset{10.5724_uT,-10.869_uT,2.241468_uT}; - hmc5883L_ID1.set_offset(offset); - return success; + + // TODO should be max earthmagnetic field or + // as a function of location + constexpr auto earth_magnetic_field_flux_density = 31.869_uT; + + return + hmc5883L_ID1.set_samples_average(8) && + hmc5883L_ID1.set_range( earth_magnetic_field_flux_density * 2U) && + hmc5883L_ID1.set_gain(gain) && + hmc5883L_ID1.set_offset(offset); } bool mag_start_measurement()