Skip to content

Commit

Permalink
impl(bno055): magnetometer toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDevMinerTV committed Mar 8, 2024
1 parent c7c3baa commit a313e9c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/bno055_adafruit/Adafruit_BNO055.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ class Adafruit_BNO055 {
void enterSuspendMode();
void enterNormalMode();

adafruit_bno055_opmode_t getMode() { return _mode; }

private:
byte read8(adafruit_bno055_reg_t);
bool readLen(adafruit_bno055_reg_t, byte *buffer, uint8_t len);
Expand Down
31 changes: 31 additions & 0 deletions src/sensors/bno055sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@
#include "globals.h"
#include "GlobalVars.h"

/*
Info:
Check the datasheet for the BNO055 for more information on the different
operation modes.
OPERATION_MODE_IMUPLUS = OPR_MODE 0x08
In the IMU mode the relative orientation of the BNO055 in space is
calculated from the accelerometer and gyroscope data. The calculation
is fast.
OPERATION_MODE_NDOF = OPR_MODE 0x0C
This is a fusion mode with 9 degrees of freedom where the fused
absolute orientation data is calculated from accelerometer, gyroscope
and the magnetometer. The advantages of combining all three sensors are
a fast calculation, resulting in high output data rate, and high
robustness from magnetic field distortions. In this mode the
Fast Magnetometer calibration is turned ON and thereby resulting in
quick calibration of the magnetometer and higher output data accuracy.
*/

void BNO055Sensor::motionSetup() {
imu = Adafruit_BNO055(sensorId, addr);
delay(3000);
Expand Down Expand Up @@ -76,3 +97,13 @@ void BNO055Sensor::motionLoop() {
void BNO055Sensor::startCalibration(int calibrationType) {

}

bool BNO055Sensor::hasMagnetometerEnabled() {
return imu.getMode() == Adafruit_BNO055::OPERATION_MODE_NDOF;
}

bool BNO055Sensor::toggleMagnetometer(bool enabled) {
imu.setMode(enabled ? Adafruit_BNO055::OPERATION_MODE_NDOF : Adafruit_BNO055::OPERATION_MODE_IMUPLUS);

return true;
}
4 changes: 4 additions & 0 deletions src/sensors/bno055sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class BNO055Sensor : public Sensor
void motionLoop() override final;
void startCalibration(int calibrationType) override final;

bool supportsTogglingMagnetometer() { return true; };
bool hasMagnetometerEnabled() override final;
bool toggleMagnetometer(bool enabled) override final;

private:
Adafruit_BNO055 imu;
};
Expand Down

0 comments on commit a313e9c

Please sign in to comment.