OK now that the sensors are calibrated, and you know what the options are for filters - its time to FUSE THOSE SENSORS! That's what we're here for, right?
Install the Adafruit AHRS library from the library manager. We strongly recommend using Arduino IDE 1.8.10+ because it will automatically install any dependancy libraries. See all dependencies here
Open up the calibrated_orientation sketch
At the top of the sketch you'll see a section where you can #include
different sensor sets. Not every sensor-set is defined, but our most popular ones are! (You'll need sensors that are Adafruit_Sensor
compatible.)
Uncomment whichever kit you are using, and comment out the rest
// uncomment one combo 9-DoF! #include "LSM6DS_LIS3MDL.h" // can adjust to LSM6DS33, LSM6DS3U, LSM6DSOX... //#include "LSM9DS.h" // LSM9DS1 or LSM9DS0 //#include "NXP_FXOS_FXAS.h" // NXP 9-DoF breakout
Next, you can select which fusion algorithm you want to try:
// pick your filter! slower == better quality output //Adafruit_NXPSensorFusion filter; // slowest Adafruit_Madgwick filter; // faster than NXP //Adafruit_Mahony filter; // fastest/smalleset
By default we'll be performing a calculation every 10 ms (100Hz) and printing out 1 out of 10 calculations, however you can adjust those numbers up or down in this section as well as adding debug output
#define FILTER_UPDATE_RATE_HZ 100 #define PRINT_EVERY_N_UPDATES 10 //#define AHRS_DEBUG_OUTPUT
OK now compile & upload!
Open the serial console and you'll see the sensors detected and then text like this
Orientation: 180.82 -1.65 2.48
These are the Euler angle outputs from the fusion algorithm
You'll also see text like
Quaternion: 0.7545, 0.2937, 0.5858, -0.0356
These are the quaternion outputs.
Euler Angles
Euler angles describe orientation (in degrees) around a single reference point in three-dimensional space.
Various names are employed for the three angles, but the most common terminology with aircraft is Roll (x), Pitch (y) and Yaw (z).
The illustration below from the Wikipedia article on Euler angles should illustrate the concept clearly. You normally have both positive and negative angles (-180° to 180°) depending on the direction the airplane is tilted, with 0° in every direction corresponding to the airplane being perfectly aligned with each axis:
The print out of data is is in Yaw (Z) Pitch (Y) Roll (X) order, So if you get
Orientation: 163.00 -4.90 33.56
The yaw is 163 degrees, pitch is -4.90 degrees and roll is about 33.56 degrees. The sketch will keep updating itself with the latest values at whatever speed we've set in the example sketch.