Skip to content

Commit a4c2e17

Browse files
committed
CalibrationSettings example complete
-Note, this example pertains to turning on/off dynamic calibration for each sensor. It does not demo interactive calibration.
1 parent 371d5cd commit a4c2e17

File tree

3 files changed

+32
-112
lines changed

3 files changed

+32
-112
lines changed

examples/Example_19_Calibrate/Example_19_Calibrate.ino renamed to examples/Example_20_CalibrationSettings/Example_20_CalibrationSettings.ino

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
/*
22
Using the BNO08x IMU
33
4-
This example shows how to calibrate the sensor. See document 1000-4044.
5-
You move the sensor into a sequence of positions, then send it an "S" to save.
4+
This example shows how to adjust settings of the dynamic calibration of the
5+
BNO08x.
6+
7+
The BNO08x allows you to turn on/off dynamic calibration for each sensor in
8+
the IMU (accel, gyro, or mag).
9+
10+
Please refer to the BNO08X data sheet Section 3 (page 37)
11+
https://docs.sparkfun.com/SparkFun_VR_IMU_Breakout_BNO086_QWIIC/assets/component_documentation/BNO080_085-Datasheet_v1.16.pdf
612
7-
While Calibration is in progress, it will output the x/y/z/accuracy of the mag
8-
and the i/j/k/real parts of the game rotation vector.
13+
Note, by default, dynamic calibration is enabled for accel and mag.
14+
Some special use cases may require turning on all or any special combo of sensor
15+
dynamic calibration.
16+
17+
After the calibration settings are set, this example will output the
18+
x/y/z/accuracy of the mag and the i/j/k/real parts of the game rotation vector.
919
https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
1020
21+
Note, the "simple calibration" feature, sh2_startCal(), is not available on
22+
the BNO08x. See this issue for more info:
23+
https://github.com/ceva-dsp/sh2/issues/11
24+
1125
By: Nathan Seidle
1226
SparkFun Electronics
1327
Date: December 21st, 2017
@@ -102,8 +116,11 @@ void setup() {
102116

103117
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
104118

105-
//Enable dynamic calibration for accel, gyro, and mag
106-
if (myIMU.calibrateAll() == true) {
119+
// Enable dynamic calibration for desired sensors (accel, gyro, and mag)
120+
// uncomment/comment out as needed to try various options
121+
if (myIMU.setCalibrationConfig(SH2_CAL_ACCEL || SH2_CAL_GYRO || SH2_CAL_MAG) == true) { // all three sensors
122+
//if (myIMU.setCalibrationConfig(SH2_CAL_ACCEL || SH2_CAL_MAG) == true) { // Default settings
123+
//if (myIMU.setCalibrationConfig(SH2_CAL_ACCEL) == true) { // only accel
107124
Serial.println(F("Calibration Command Sent Successfully"));
108125
} else {
109126
Serial.println("Could not send Calibration Command. Freezing...");
@@ -204,51 +221,15 @@ void loop() {
204221

205222
if(incoming == 's')
206223
{
207-
//Saves the current dynamic calibration data (DCD) to memory
224+
// Saves the current dynamic calibration data (DCD) to memory
225+
// Note, The BNO08X stores updated Dynamic Calibration Data (DCD) to RAM
226+
// frequently (every 5 seconds), so this command may not be necessary
227+
// depending on your application.
208228
if (myIMU.saveCalibration() == true) {
209229
Serial.println(F("Calibration data was saved successfully"));
210230
} else {
211231
Serial.println("Save Calibration Failure");
212232
}
213-
214-
////////////////////////////////////
215-
// CODE FROM PREVIOUS BNO080 LIBRARY vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
216-
// BEGIN ///////////////////////////
217-
218-
// myIMU.requestCalibrationStatus(); //Sends command to get the latest calibration status
219-
220-
// //Wait for calibration response, timeout if no response
221-
// int counter = 100;
222-
// while(1)
223-
// {
224-
// if(--counter == 0) break;
225-
// if(myIMU.dataAvailable() == true)
226-
// {
227-
// //The IMU can report many different things. We must wait
228-
// //for the ME Calibration Response Status byte to go to zero
229-
// if(myIMU.calibrationComplete() == true)
230-
// {
231-
// Serial.println("Calibration data successfully stored");
232-
// delay(1000);
233-
// break;
234-
// }
235-
// }
236-
237-
// delay(1);
238-
// }
239-
// if(counter == 0)
240-
// {
241-
// Serial.println("Calibration data failed to store. Please try again.");
242-
// }
243-
244-
//myIMU.endCalibration(); //Turns off all calibration
245-
//In general, calibration should be left on at all times. The BNO080
246-
//auto-calibrates and auto-records cal data roughly every 5 minutes
247-
248-
////////////////////////////////////
249-
// CODE FROM PREVIOUS BNO080 LIBRARY ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
250-
// END /////////////////////////////
251-
252233
}
253234
}
254235
}

src/SparkFun_BNO08x_Arduino_Library.cpp

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -949,51 +949,11 @@ bool BNO08x::enableActivityClassifier(uint16_t timeBetweenReports, uint32_t acti
949949
return enableReport(SENSOR_REPORTID_PERSONAL_ACTIVITY_CLASSIFIER, timeBetweenReports, activitiesToEnable);
950950
}
951951

952-
// //Sends the commands to begin calibration of the accelerometer
953-
// void BNO08x::calibrateAccelerometer()
954-
// {
955-
// sendCalibrateCommand(CALIBRATE_ACCEL);
956-
// }
957-
958-
// //Sends the commands to begin calibration of the gyro
959-
// void BNO08x::calibrateGyro()
960-
// {
961-
// sendCalibrateCommand(CALIBRATE_GYRO);
962-
// }
963-
964-
// //Sends the commands to begin calibration of the magnetometer
965-
// void BNO08x::calibrateMagnetometer()
966-
// {
967-
// sendCalibrateCommand(CALIBRATE_MAG);
968-
// }
969-
970-
// //Sends the commands to begin calibration of the planar accelerometer
971-
// void BNO08x::calibratePlanarAccelerometer()
972-
// {
973-
// sendCalibrateCommand(CALIBRATE_PLANAR_ACCEL);
974-
// }
975-
976-
//See 2.2 of the Calibration Procedure document 1000-4044
977-
bool BNO08x::calibrateAll()
952+
// See 2.2 of the Calibration Procedure document 1000-4044
953+
// Set the desired sensors to have active dynamic calibration
954+
bool BNO08x::setCalibrationConfig(uint8_t sensors)
978955
{
979-
int status;
980-
981-
Serial.print("Attempting sh2_setCalConfig...");
982-
//int status = sh2_setCalConfig(SH2_CAL_ACCEL);
983-
status = sh2_setCalConfig(SH2_CAL_ACCEL || SH2_CAL_GYRO || SH2_CAL_MAG);
984-
985-
if (status != SH2_OK) {
986-
return false;
987-
}
988-
//delay(100); // may not be necessary
989-
990-
Serial.println("complete.");
991-
992-
Serial.print("Attempting sh2_startCal...");
993-
994-
status = sh2_startCal(1000); // argument is report interval in uS
995-
996-
Serial.println("complete.");
956+
int status = sh2_setCalConfig(sensors);
997957

998958
if (status != SH2_OK) {
999959
return false;
@@ -1002,20 +962,6 @@ bool BNO08x::calibrateAll()
1002962
return true;
1003963
}
1004964

1005-
// void BNO08x::endCalibration()
1006-
// {
1007-
// sendCalibrateCommand(CALIBRATE_STOP); //Disables all calibrations
1008-
// }
1009-
1010-
// //See page 51 of reference manual - ME Calibration Response
1011-
// //Byte 5 is parsed during the readPacket and stored in calibrationStatus
1012-
// boolean BNO08x::calibrationComplete()
1013-
// {
1014-
// if (calibrationStatus == 0)
1015-
// return (true);
1016-
// return (false);
1017-
// }
1018-
1019965
bool BNO08x::tareNow(bool zAxis, sh2_TareBasis_t basis)
1020966
{
1021967
int status = sh2_setTareNow(zAxis ? TARE_AXIS_Z : TARE_AXIS_ALL, basis);

src/SparkFun_BNO08x_Arduino_Library.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,8 @@ class BNO08x
250250
float getGravityZ();
251251
uint8_t getGravityAccuracy();
252252

253-
// void calibrateAccelerometer();
254-
// void calibrateGyro();
255-
// void calibrateMagnetometer();
256-
// void calibratePlanarAccelerometer();
257-
bool calibrateAll();
258-
// void endCalibration();
253+
bool setCalibrationConfig(uint8_t sensors);
259254
bool saveCalibration();
260-
// void requestCalibrationStatus(); //Sends command to get status
261-
// boolean calibrationComplete(); //Checks ME Cal response for byte 5, R0 - Status
262255

263256
bool tareNow(bool zAxis=false, sh2_TareBasis_t basis=SH2_TARE_BASIS_ROTATION_VECTOR);
264257
bool saveTare();

0 commit comments

Comments
 (0)