Hi everyone,
I have an altIMU-10 v5 and I would like to measure the angle of my robot with it (to make nearly perfect 90° turns).
I got it working with the Arduino AHRS code, but I don’t understand how it works. I would like to get the z-axis-values in degrees. There are almost no tutorials on internet for this sensor so I’m looking for help here.
This is what I had so far (but it isn’t even close to working).
Maybe it’s easier to do it with the magnetometer but I don’t know how to use it.
Thanks in advance.
#include <Wire.h>
#include <LSM6.h>
LSM6 imu;
int tijd, gyro_x_cal, gyro_y_cal, gyro_z_cal;
float graden;
char report[80];
void setup()
{
Serial.begin(9600);
Wire.begin();
if (!imu.init())
{
Serial.println("Failed to detect and initialize IMU!");
while (1);
}
imu.enableDefault();
tijd = millis();
for (int calGyro = 0; calGyro < 2000; calGyro++) {
imu.read();
snprintf(report, sizeof(report), "A: %6d %6d %6d G: %6d %6d %6d", imu.a.x, imu.a.y, imu.a.z, imu.g.x, imu.g.y, imu.g.z);
gyro_x_cal += imu.a.x;
gyro_y_cal += imu.a.y;
gyro_z_cal += imu.a.z;
delay(3);
}
gyro_x_cal /= 2000;
gyro_y_cal /= 2000;
gyro_z_cal /= 2000;
}
void loop()
{
imu.read();
snprintf(report, sizeof(report), "A: %6d %6d %6d G: %6d %6d %6d",
imu.a.x, imu.a.y, imu.a.z,
imu.g.x, imu.g.y, imu.g.z);
imu.a.x -= gyro_x_cal;
imu.a.y -= gyro_y_cal;
imu.a.z -= gyro_z_cal;
// graden = ((imu.a.z) * (millis() - tijd) * 0.001) / 8.75;
// 0.00006855 = 1/1660/8.75 because the sensor is running at 1660 Hz (got this from the LSM6.cpp file in the library) and 8.75 from the datasheet (stands by the 245 dps (also got this from the LSM6.cpp file) angular rate sensitivity)
graden += imu.a.z * 0.00006885;;
// Serial.print(report);
Serial.print(imu.a.z);
Serial.print(" ");
Serial.println(graden);
// delay(100);
}