This is a plot of the heading angles from both sensors:
The plot shows that after changes in the second sensor's orientation, its heading readings drift back to their original value relative to the first sensor. Likewise, when the first sensor's orientation is changed, its heading readings drift back to the original relative value relative to the second sensor. This indicates that one sensor may be affecting the other. I suspect that variables are getting mixed up between the two fusion computations or that the data being sent back over one wire is getting mixed, but am not resourced enough to find out what exactly is happening and how to change it.
I'm hoping someone can help with this issue.
These changes were made to the header file to accommodate two simultaneous sensors:
#include <Wire.h>
#include <Adafruit_LIS3MDL.h>
//Adafruit_LIS3MDL lis3mdl_1 = Adafruit_LIS3MDL(0x1C);
Adafruit_LIS3MDL lis3mdl_1;
Adafruit_LIS3MDL lis3mdl_2;
//lis3mdl_1.begin_i2c(0x1C);
//lis3mdl_1.setAddress(0x1C);
// Can change this to be LSM6DSOX or whatever ya like
#include <Adafruit_LSM6DSOX.h>
Adafruit_LSM6DSOX lsm6ds_1;
Adafruit_LSM6DSOX lsm6ds_2;
bool init_sensors(void) {
if (!lsm6ds_1.begin_I2C(0x6A) || !lis3mdl_1.begin_I2C(0x1C)) {
return false;
}
if (!lsm6ds_2.begin_I2C(0x6B) || !lis3mdl_2.begin_I2C(0x1E)) {
return false;
}
accelerometer_1 = lsm6ds_1.getAccelerometerSensor();
gyroscope_1 = lsm6ds_1.getGyroSensor();
magnetometer_1 = &lis3mdl_1;
accelerometer_2 = lsm6ds_2.getAccelerometerSensor();
gyroscope_2 = lsm6ds_2.getGyroSensor();
magnetometer_2 = &lis3mdl_2;
return true;
}
void setup_sensors(void) {
// set lowest range
lsm6ds_1.setAccelRange(LSM6DS_ACCEL_RANGE_2_G);
lsm6ds_1.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS);
lis3mdl_1.setRange(LIS3MDL_RANGE_4_GAUSS);
lsm6ds_2.setAccelRange(LSM6DS_ACCEL_RANGE_2_G);
lsm6ds_2.setGyroRange(LSM6DS_GYRO_RANGE_250_DPS);
lis3mdl_2.setRange(LIS3MDL_RANGE_4_GAUSS);
// set slightly above refresh rate
lsm6ds_1.setAccelDataRate(LSM6DS_RATE_104_HZ);
lsm6ds_1.setGyroDataRate(LSM6DS_RATE_104_HZ);
lis3mdl_1.setDataRate(LIS3MDL_DATARATE_1000_HZ);
lis3mdl_1.setPerformanceMode(LIS3MDL_MEDIUMMODE);
lis3mdl_1.setOperationMode(LIS3MDL_CONTINUOUSMODE);
lsm6ds_2.setAccelDataRate(LSM6DS_RATE_104_HZ);
lsm6ds_2.setGyroDataRate(LSM6DS_RATE_104_HZ);
lis3mdl_2.setDataRate(LIS3MDL_DATARATE_1000_HZ);
lis3mdl_2.setPerformanceMode(LIS3MDL_MEDIUMMODE);
lis3mdl_2.setOperationMode(LIS3MDL_CONTINUOUSMODE);
}
Turn on the debug output by u commenting to define. What is the speed of your loop? You might be saturating your processor with two filters to be calculated simultaneously.
AHRS Fusion With Two Adafruit LSM6DSOX + LIS3MDL Sensors Simultaneously
I am working on generating AHRS data (see https://learn.adafruit.com/how-to-fuse-motion-sensor-data-into-ahrs-orientation-euler-quaternions) for two independent LSM6DSOX + LIS3MDL sensors (see https://www.adafruit.com/product/4517) simultaneously over one I2C wire. While I've been able to calibrate and read data from each sensor in separate programs with one sensor using its default addresses (mag: 0x1C; acc/gyr: 0x6A) and the other using its alternate addresses(mag: 0x1E; acc/gyr: 0x6B) (see https://learn.adafruit.com/st-9-dof-combo/lsm6ds33-lis3mdl-pinouts); running the fusion process on both in the same program yields faulty results:
This is a plot of the heading angles from both sensors:
The plot shows that after changes in the second sensor's orientation, its heading readings drift back to their original value relative to the first sensor. Likewise, when the first sensor's orientation is changed, its heading readings drift back to the original relative value relative to the second sensor. This indicates that one sensor may be affecting the other. I suspect that variables are getting mixed up between the two fusion computations or that the data being sent back over one wire is getting mixed, but am not resourced enough to find out what exactly is happening and how to change it.
I'm hoping someone can help with this issue.
These changes were made to the header file to accommodate two simultaneous sensors:
And these are the changes to the code:
I appreciate the help.
-Simon