Good night, I'm new to the forum, I write because I have a question and I have more than a week without being able to solve it.
I am trying to measure angles only with the gyroscope by means of the LSM9DS1 sensor that has the Arduino nano 33 ble sense.
Applying the following equation I try to get the angle.
Θ=Θ0+ʃ ω(t)dt
Where:
Θ = angle (deg)
Θ0 = start angle (deg)
ω(t) = angular velocity (deg/sec)
dt = time (sec)
But I can not have logical results, for example I place the sensor at approximately 45º on the X and Y axis, in the first it gives me 1.65 and in the other 5.47, I do not know what the problem would be greatly appreciated if you could give me some advice.
I enclose the code I am using:
#include <Arduino_LSM9DS1.h>
// Variables
float elapsedTime, tiempo, timePrev; //Variables for time control
float GyroX, GyroY, GyroZ; //Here store the value °/seg obtained with Gyro data
float angle_x, angle_y; //Here store value ° obtain integrate the time and multiply by Gyro data
void setup(){
Serial.begin(9600);
while(!Serial);
Serial.print("Start");
if(!IMU.begin()){
Serial.print("Failed to initialize IMU!");
while(1);
}
Serial.print("Gyroscope sample rate = ");
Serial.print(IMU.gyroscopeSampleRate());
Serial.println(" Hz");
Serial.println();
Serial.println("Gyroscope in degrees/second");
Serial.println("X\tY\tZ");
}
void loop(){
timePrev = tiempo; // the previous time is stored before the actual time read
tiempo = millis(); // actual time read
elapsedTime = (tiempo - timePrev) / 1000; //divide by 1000 in order to obtain seconds
if(IMU.gyroscopeAvailable()){
IMU.readGyroscope(GyroX,GyroY,GyroZ);
// multiply degrees/seconds by seconds you obtain degrees
angle_x= angle_x + GyroX * elapsedTime;
angle_y= angle_x + GyroY * elapsedTime;
Serial.print(angle_x);
Serial.print('\t');
Serial.println(angle_y);
}
}