How to calibrate Altimu-10 v5

Hello, I am trying to fetch the Roll, Pitch and Yaw values from the Altimu-10 v5 for an orientation related project, I have tried to do this using the MadgwickAHRS library but it keeps giving me values that keeps changing on the serial monitor.
This is my code, can you please help me out?

I have not used this module before

#include <Wire.h>
#include <LSM6.h>
#include <LIS3MDL.h>
#include <LPS.h>
#include <MadgwickAHRS.h>

LSM6 imu;
LIS3MDL mag;
LPS ps;
Madgwick filter;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  
  imu.init();
  imu.enableDefault();

  mag.init();
  mag.enableDefault();

  ps.init();
  ps.enableDefault();

  filter.begin(500); // Madgwick filter sample rate (Hz)
}

void loop() {
  imu.read();
  mag.read();

  float pressure = ps.readPressureMillibars();
  float temperature = ps.readTemperatureC();

  filter.updateIMU(imu.g.x, imu.g.y, imu.g.z, imu.a.x, imu.a.y, imu.a.z); // Madgwick filter update

  float roll = filter.getRoll();
  float pitch = filter.getPitch();
  float yaw = filter.getYaw();

  Serial.print("Roll (deg): ");
  Serial.print(roll);
  Serial.print(", ");

  Serial.print("Pitch (deg): ");
  Serial.print(pitch);
  Serial.print(", ");

  Serial.print("Yaw (deg): ");
  Serial.println(yaw);

  delay(1000);
}

Hello.

I am not familiar with the MadgwickAHRS library you are using, but a good starting point might be to look at the different sensors on the AltIMU individually using the example programs from our libraries, and try to get to a point where each of those look reasonable first.

Keep in mind that some amount of variation in the output should be expected, since there will be noise in the sensor outputs, but one common cause of major inaccuracy in an AHRS system like this is an inadequately calibrated magnetometer which will cause the yaw readings to drift. I am not sure what kind of calibration parameters the MadgwickAHRS library expects or how you are intended to determine them, but it is particularly important to calibrate magnetometers because their readings can be distorted enough to make their uncalibrated measurements more or less useless.

Here are some links to threads with discussions about how you could go about calibrating magnetometers, though please note that they do not all refer the same hardware, programs, or libraries:

- Patrick