Hello
I recently bought an IMU (Acc_Gyro 6DOF Analog IMU: 3 Axis Accelerometer + 3 Axis Gyro – Starlino Electronics), without fully understanding how IMUs function. What I really needed it for was for measuring yaw for an autonomous underwater vehicle I’m working on. I realize now that in order to get an accurate reading you need a magnetometer as well and use that along with a Kalman filter to get rid of drift. However I dont think that I need an accurate reading for more than 5-10 seconds (it would just be used for relative positioning while turning).
I attempted to just access the yaw gyro and use that solely, but am getting very bad results. I understand that gyros arent the most accurate sensor, but mine seems to be only good for detecting movement and doesnt give an accurate depiction on magnitude or direction of the angular velocity. For example I might start my program, rotate the board 90 degrees and then rotate it back and have the angle decrease upon both rotations. Furthermore my gyro never seems to settle back to the original zero. After rotating it and stopping it seems the zero voltage has changed and thus the gyro starts drifting really badly. I’ve tried fine tuning the zero voltage as closely as possible, but this doesnt really matter if its always changing. I’ve also played around with the parameters for the if statement but that only marginally helps..
So my question is, are gyros really THAT inaccurate? Or should I be getting something at least somewhat useable? Please check out my code and see if you can see any issues. Thank you!
float yawRate; //reading from the gyro
float yawZero = 1.255; //zero rate voltage
float currentAngle = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
//Get the reading from the yaw gyroscope
yawRate = analogRead(A3);
//convert to degrees/second
yawRate /=1023;
yawRate *=5;
yawRate -= yawZero;
Serial.println(yawRate);
yawRate /=.002;
//if statement to help minimize drift
if(yawRate>5||yawRate<-5) {
//running at 100 Hz
yawRate /=100;
//add up the angles
currentAngle+= yawRate;
}
//ensure that the angle stays between 0-360 degrees
if (currentAngle 359)
currentAngle -= 360;
Serial.println(currentAngle);
delay(10);
}