Go Down

Topic: Yaw? (Read 1 time) previous topic - next topic


I recently bought an IMU (http://www.starlino.com/store/acc-gyro), 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() {

void loop() {
//Get the reading from the yaw gyroscope
yawRate = analogRead(A3);
//convert to degrees/second
yawRate /=1023;
yawRate *=5;
yawRate -= yawZero;
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;


When you do that :
Code: [Select]

currentAngle+= yawRate;

It's wrong, you cannot add an angular speed and a angle. You need to integrate the angular speed to get an angle, that can be done with RK4 :
Code: [Select]

float RK4Integrate(float data4, float data3, float data2, float data1, int deltaTmillis)
  float area = ((data4 + 2*data3 + 2*data2 + data1)/6)*deltaTmillis/1000.f;
  return area;

Your code becomes then :
Code: [Select]

currentAngle += RK4Integrate(...);

Also you should display the raw data on a graph (in processing for example) before computing anything.


Correct me if I'm wrong, but isnt
yawRate /=100;
doing a very simple integration? Its the same as multiplying the angular velocity by .01 which is my delta t. I know this isnt the most accurate form of integration but it should give reasonable results.


Allright I understand that line now, sure it's a way to do an integration, but it's a terrible one  :)  I don't think you will get reasonable result.
Euler's method (with 2 values) produces already quite some errors on a short period, your method I don't know but it's probably gonna be a lot worse. Well if you really want to test, you can compare both integration method and display everything on a graph, that would be interesting.

One great thing about rk4 : it filters a bit the noise of the sensor, since it's some sort of average done on 4 values.


I am struggling too see this thread:
I will run the Arduino code you suggested when I get a chance.


I've seen it already, i'm still waiting on the value of GYRO_SENSITIVITY ^^ Because if that value is really big, it might possibly be the problem. It doesn't seems to be a pull up problem as you're not getting exact zeros on long periods, the connection seems strong afaik.

There is one ITG 3205 on a wii motion plus copy I recently bought, and it's giving me a hard time. Oversensibility and saturation, incoherent values sometimes for yaw. I've heard this ITG 3205 is OEM version, designed but not manufactered by Invensense, so that might be the reason why we're getting so much trouble with it.

Go Up