Quadrotor project

Hey guys,
I am building my first quadrotor project.I am using Arduino mega ADK for controller and Pololu MinIMU-9 for sensor board.
I am using Arduino AHRS software and Arduino PID library for the hover controll of the robot.
The problem is that i can't tune the PID parameters because the sensor output is too noisy.Here is a sample sensor output when the sensor board is not moved at all.

             !ANG:Roll: 0.01,Pitch: 0.00,Yaw:-21.98
	     !ANG:Roll: 0.28,Pitch: -0.05,Yaw:-21.98
	     !ANG:Roll: 0.19,Pitch: -0.15,Yaw:-21.99
	     !ANG:Roll: 0.09,Pitch: -0.07,Yaw:-22.00
	     !ANG:Roll: 0.15,Pitch: -0.03,Yaw:-21.97
	     !ANG:Roll: 0.07,Pitch: 0.03,Yaw:-21.95
	     !ANG:Roll: -0.12,Pitch: 0.13,Yaw:-21.93
	     !ANG:Roll: -0.15,Pitch: 0.02,Yaw:-21.90
	     !ANG:Roll: -0.25,Pitch: 0.15,Yaw:-21.87
	     !ANG:Roll: -0.25,Pitch: 0.14,Yaw:-21.85
	     !ANG:Roll: -0.18,Pitch: 0.04,Yaw:-21.83
	     !ANG:Roll: -0.18,Pitch: 0.06,Yaw:-21.80
	     !ANG:Roll: -0.25,Pitch: 0.07,Yaw:-21.77
	     !ANG:Roll: -0.38,Pitch: 0.08,Yaw:-21.75
	     !ANG:Roll: -0.34,Pitch: 0.06,Yaw:-21.73
	     !ANG:Roll: -0.21,Pitch: -0.06,Yaw:-21.70
	     !ANG:Roll: -0.28,Pitch: -0.17,Yaw:-21.71
	     !ANG:Roll: -0.32,Pitch: -0.02,Yaw:-21.72
	     !ANG:Roll: -0.24,Pitch: 0.20,Yaw:-21.73
	     !ANG:Roll: -0.31,Pitch: 0.22,Yaw:-21.74
	     !ANG:Roll: -0.48,Pitch: 0.18,Yaw:-21.75
	     !ANG:Roll: -0.56,Pitch: 0.16,Yaw:-21.76
	     !ANG:Roll: -0.60,Pitch: 0.19,Yaw:-21.77
	     !ANG:Roll: -0.68,Pitch: 0.13,Yaw:-21.79
	     !ANG:Roll: -0.66,Pitch: 0.14,Yaw:-21.80
	     !ANG:Roll: -0.54,Pitch: -0.03,Yaw:-21.81
	     !ANG:Roll: -0.51,Pitch: -0.09,Yaw:-21.83
	     !ANG:Roll: -0.55,Pitch: -0.27,Yaw:-21.84
	     !ANG:Roll: -0.54,Pitch: -0.29,Yaw:-21.82
	     !ANG:Roll: -0.67,Pitch: -0.30,Yaw:-21.81
	     !ANG:Roll: -0.52,Pitch: -0.34,Yaw:-21.81
	     !ANG:Roll: -0.47,Pitch: -0.22,Yaw:-21.80
	     !ANG:Roll: -0.33,Pitch: -0.29,Yaw:-21.79
	     !ANG:Roll: -0.25,Pitch: -0.27,Yaw:-21.79
	     !ANG:Roll: -0.38,Pitch: -0.22,Yaw:-21.81
	     !ANG:Roll: -0.36,Pitch: -0.16,Yaw:-21.82
	     !ANG:Roll: -0.26,Pitch: -0.19,Yaw:-21.84
	     !ANG:Roll: -0.35,Pitch: -0.28,Yaw:-21.85
	     !ANG:Roll: -0.43,Pitch: -0.36,Yaw:-21.86
	     !ANG:Roll: -0.51,Pitch: -0.41,Yaw:-21.87
	     !ANG:Roll: -0.57,Pitch: -0.37,Yaw:-21.89
	     !ANG:Roll: -0.40,Pitch: -0.22,Yaw:-21.90

Is there a way to reduse the noise from the sensors ,or tell the PID library to ignore it?
P.S. I can show source code if needed
Thanks.

What do the values you printed out represent?

(I mean are they deflection, speed, acceleration, something else?)

PeterH:
What do the values you printed out represent?

(I mean are they deflection, speed, acceleration, something else?)

Degrees in x ,y ,z axes.

Can you average it? Would that help?

I can try but i don't think that this would help because the readings will get slower. I mean if i get 1 reading every 20 milliseconds that's 50hz right? But if i average 5 readings to get them smoother i will receive a reading every 100 milliseconds and that is 10hz.

Well, how often do you actually get the readings?

In any case by tweaking the PID parameters you can make it react slowly to value changes, which would effectively average them.

Ok first sorry for my bad english.
I already posted that i am looking for a way to reduse the noise of the output,and if there isn't one i am looking for a way to tell the PID library to ignore the noise.Arduino autotune library has a function called "Set NoiseBand()" and it is for setting noise value that would be ignored.But i don't see that kind of function in the original Arduino PID library.
P.S.Thank you for your answer i will try to tune the pid without noise reduction or noise ignorance,but in the meantime i take advices. :slight_smile:
P.S.2 I think the readings are at 50hz.But i am not sure.I am using the original Arduino AHRS code for the sensors

Hey again today i tried to tune the roll kp ,but i am little confused .I was watching this video as a tutorial .But my quadrotor doesn't act like the one in the video .I do not have immediate bounsing(instead when its stable and i run the program it starts slowly to swing and the more it swings the faster it gets.) no matter how high is my kp.
So my question is what am i doing wrong?
In the PID input i am putting the sensor roll value in degrees.I gave min value of the output to be -25 degrees and max value to be 25 degrees.And i tested with what differens between the motors i have 1 degree differens in the roll axes and it was 4 microseconds for 1 degree.So when the output comes in degrees i multiply it by 4 to make it in PWM value.Is all this correct?I accept any advices.
Thanks.

Up.. With some days playing with the pid i managed to make it go to the setpoint angle but it still swings a little.. Advices?

I don't know, personally.

I have played with a PID before and it can take a lot of time tweaking it to get things right. It's just guesswork without the hardware in front of me.

Did you try the idea of averaging the readings?

No but i made something like a noise filter .I mean i made an if statement that doesn't compute the pid unless the differens between to consecutive readings is more than 1 degree

Can you average it? Would that help?

...

I can try ...

But you didn't try.

I don't know about the other forum members here, but when I suggest something, and it is ignored, I lose a little interest in the thread.

No sorry i didn't mean to ignore it .To tell the truth i forgot.But i promise i will try it tomorrow.

Ok i tried the averaging (i add 4 reading in to one and then divide by 4) and the result is still the same(it goes eventually to the setpoint ,but too slow and when it reaches the setpoint starts to swing slowly). :0

I was working on something a little similar (a sensor controlled a motor) and the PID parameters made a huge difference to performance. I can't tell you which ones will fix it, but I suspect tweaking them will.

http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/

Your readings don't look very noisy to me, however the noise may be a problem if the D term is too high. Try setting the D term to zero and see how stable you can get it using just P and I terms. When you have optimised P and I, you can try adding a bit of D.

Hi again ,
i was tweaking the pid again i have a little improvement, but the interesting part is that sometimes with the exact same parameters the quad acts different .I mean that sometimes is almost stable ,and sometimes it shakes and swings .I am wondering is this because of the ballance of the frame.Or just sometimes the sensors are more noisy then other times.
I am wondering would the change of the sensor board with a less noisy one would solve the problem(if there are less noisy boards)? I even have a board in mind it has not only 3 axis gyro,accel and magnetometer ,but also a barometer.Does somebody has an opinion for this board.

dc42:
Your readings don't look very noisy to me, however the noise may be a problem if the D term is too high. Try setting the D term to zero and see how stable you can get it using just P and I terms. When you have optimised P and I, you can try adding a bit of D.

if you are talking about this readings

             !ANG:Roll: 0.01,Pitch: 0.00,Yaw:-21.98
	     !ANG:Roll: 0.28,Pitch: -0.05,Yaw:-21.98
	     !ANG:Roll: 0.19,Pitch: -0.15,Yaw:-21.99
	     !ANG:Roll: 0.09,Pitch: -0.07,Yaw:-22.00
	     !ANG:Roll: 0.15,Pitch: -0.03,Yaw:-21.97
	     !ANG:Roll: 0.07,Pitch: 0.03,Yaw:-21.95
	     !ANG:Roll: -0.12,Pitch: 0.13,Yaw:-21.93
	     !ANG:Roll: -0.15,Pitch: 0.02,Yaw:-21.90
	     !ANG:Roll: -0.25,Pitch: 0.15,Yaw:-21.87
	     !ANG:Roll: -0.25,Pitch: 0.14,Yaw:-21.85
	     !ANG:Roll: -0.18,Pitch: 0.04,Yaw:-21.83
	     !ANG:Roll: -0.18,Pitch: 0.06,Yaw:-21.80
	     !ANG:Roll: -0.25,Pitch: 0.07,Yaw:-21.77
	     !ANG:Roll: -0.38,Pitch: 0.08,Yaw:-21.75
	     !ANG:Roll: -0.34,Pitch: 0.06,Yaw:-21.73
	     !ANG:Roll: -0.21,Pitch: -0.06,Yaw:-21.70
	     !ANG:Roll: -0.28,Pitch: -0.17,Yaw:-21.71
	     !ANG:Roll: -0.32,Pitch: -0.02,Yaw:-21.72
	     !ANG:Roll: -0.24,Pitch: 0.20,Yaw:-21.73
	     !ANG:Roll: -0.31,Pitch: 0.22,Yaw:-21.74
	     !ANG:Roll: -0.48,Pitch: 0.18,Yaw:-21.75
	     !ANG:Roll: -0.56,Pitch: 0.16,Yaw:-21.76
	     !ANG:Roll: -0.60,Pitch: 0.19,Yaw:-21.77
	     !ANG:Roll: -0.68,Pitch: 0.13,Yaw:-21.79
	     !ANG:Roll: -0.66,Pitch: 0.14,Yaw:-21.80
	     !ANG:Roll: -0.54,Pitch: -0.03,Yaw:-21.81
	     !ANG:Roll: -0.51,Pitch: -0.09,Yaw:-21.83
	     !ANG:Roll: -0.55,Pitch: -0.27,Yaw:-21.84
	     !ANG:Roll: -0.54,Pitch: -0.29,Yaw:-21.82
	     !ANG:Roll: -0.67,Pitch: -0.30,Yaw:-21.81
	     !ANG:Roll: -0.52,Pitch: -0.34,Yaw:-21.81
	     !ANG:Roll: -0.47,Pitch: -0.22,Yaw:-21.80
	     !ANG:Roll: -0.33,Pitch: -0.29,Yaw:-21.79
	     !ANG:Roll: -0.25,Pitch: -0.27,Yaw:-21.79
	     !ANG:Roll: -0.38,Pitch: -0.22,Yaw:-21.81
	     !ANG:Roll: -0.36,Pitch: -0.16,Yaw:-21.82
	     !ANG:Roll: -0.26,Pitch: -0.19,Yaw:-21.84
	     !ANG:Roll: -0.35,Pitch: -0.28,Yaw:-21.85
	     !ANG:Roll: -0.43,Pitch: -0.36,Yaw:-21.86
	     !ANG:Roll: -0.51,Pitch: -0.41,Yaw:-21.87
	     !ANG:Roll: -0.57,Pitch: -0.37,Yaw:-21.89
	     !ANG:Roll: -0.40,Pitch: -0.22,Yaw:-21.90

They are taken when the quadrotor is not moving at all .I mean the motors are not rotating and the quad is on the ground.
And by the way this is noting i caught a 1+ degree error once with motors off and quadrotor on ground.It was someting like:
!ANG:Roll: -0.35,Pitch....
!ANG:Roll: -1.47,Pitch....