Quadrotor PID control help please

Hi all, i've been googling and reading up on plenty of projects and papers, but not much have been discussed about PID control and updating of PWM of quadrotor.

from my understanding, there are 2 ways of doing the quadrotor hover control..
1) brute force calibration, input = euler angles from IMU which most hobbyists do. set point=0 degree

front motor PWM = user_thrust + PIDpitch - PIDyaw
back motor PWM  = user_thrust -PIDpitch - PIDyaw
left motor PWM = user+thrust+PIDroll+PIDyaw
right motor PWM = user thrust -PIDroll + PIDyaw

wait, do we calibrate all PID parameters for pitch roll yaw at the same time or do we calibrate them separately like see-saw balancing? 

2) include dynamics, physics, consider moment of inertia.etcetc which research graduates do

Well i chose to use brute force calibration due to time constraints.
Here are some questions I have:
1) do we need to consider the Centre of Gravity in our PID control? My quadrotor's CG is more towards back motor.

2) What is the common frequency of PID control loop? Normally, the IMU data is updated then PID is updated right? The maximum I can go on my 16bit 33MHz MCU is 200Hz, and sending data wirelessly via XBee at 100Hz. Is it too slow?

3) I find my PID too slow because I can never find the Pgain(Igain=0 and Dgain=0) (i.e the pitch pole) that  does not oscillate.
We need some limit of the maximum and minimum PWM if we are flying autonomously. however, my PID always reaches the maximum and minimum limit and by the time the pole crosses 0degree, the pitch pole does not change direction even though the PID has caused the PWM to switch. Please see attached (problem.jpg) note that my pwm has been shifted down to see the effects with respect to error pitch.

4) What is the frequency of the PWM sent to the ESC? reverse engineering the common RF receivers, the pwm used should be 50Hz. If we're updating PID(200Hz) wouldn't the PWM be too slow?
However, i have found somebody doing a test that going beyond 50Hz PWM actually affects the motor's thrust, which does more harm than good. please see attached (wobbletest.jpg)

5) Using Pgain and Dgain together, the control has improved, but the pitch pole still oscillates up to +/-20degrees which is bad. Increasing Dgain any further causes the pole to be "stuck".

6) My prof had actually advised me to use PDsquare control but it doesn't help because Dsquare refers to d(error square)/dt= d/dt[d(error)/dt] right? if 1/dt = 200, then  will be multiplying the D term by 4000 which will hit the PWM limit even faster.

7) What is PID saturation, steady state error, integral windup, integral antiwindup? omg I'm noob with control theory.


/////My pid code in c/////

float inv_dt=200; // means 1/dt, pid loop at 200Hz
float error_pitch; //global variable
float fm,bm; //front motor and back motor pwm on cycle
float Kp_pitch,Ki_pitch,Kd_pitch; //set these values using my ground station when tuning

float PIDpitch(float Kp, float Ki, float Kd)
{
float previous_error;
previous_error= error_pitch;

error_pitch = 0 -    kalman_pitch; //set point = 0 degree

integral_pitch  += error_pitch*dt;

derivative_pitch = (error_pitch - previous_error)*inv_dt;         
return (Kp*error_pitch)+(Ki*integral_pitch)+(Kd*derivative_pitch);
}

 

void motorControl() //controls front and back motor's PWM
{
float pitch=0; int temp=0;
pitch = PIDpitch(Kp_pitch,Ki_pitch,Kd_pitch); //update PID loop

fm=fm+pitch;

fm = 750 + pitch;                            //750=start off at 1.5ms
temp=(int)bm;
if(temp>1000)fm=1000;                    //max pwm limit 2ms 
else if(temp<600)fm=600;            //min pwm limit 1.2ms
TPU1.TGRA=(int)fm;

bm=bm-pitch;

bm = 750 - pitch;                            //750=start off at 1.5ms
temp=(int)bm;
if(temp>1000)bm=1000;                    //max pwm limit 2ms
else if(temp<600)bm=600;            //min pwm limit 1.2ms
TPU3.TGRA=(int)bm;

}

wobbletest.jpg

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • does anybody encounter problem with centre of gravity and pidcontrol? mine seems to be affecting a great deal.
  • Thank you for the reply Jason. Somehow i dont use any of the arducopter, aeroquad or some other code. I wrote all by myself cause my electronics are different, so i guess i need to study arducopter code and use modified version of it in my code. But last question is which file do i need to check or study ? Is it control_modes.pde that you write ? Thank you in advance...
  • I have asked this on some other topics but i will ask here again. im kind of desperate about it, couldnt get any satisfying answer.  The question is im designing a quadrotor as an final project not as a hobby. so i built frame by hand using carbon fiber sticks, and material called plexi glass etc. didnt use any similar electronics to arducopter except for arduino usb and arduino imu.  As i see from arducopter there is only pid algrotihm used.  No motor speed feedback or power feedback used from Lipos.  Im deriving equations and system model and used pid, but didnt work well. it was because when lipo voltage decreases, motor thrusts at the same pwm decrease, so pid terms didnt match for that situation. i have seen that a lot. so how do people solve that ? Any ideas or recommendations ?
  • Developer

    Please se the ACM code http://code.google.com/p/arducopter/source/browse/#svn%2Ftrunk%2FAr...

    It can fly perfectly stabilized with almost any kP value. Tuning is only a matter of deciding how responsive you want the quad to be.

     

    What I've found that you need to limit the D term so that it is symmetrical with the P term. Think of two forces opposing each other. If one is greater it will oscillate.  (The D term is the rate of rotation dampener.)

     

    I term is not needed for the most part and you can fly fine without it.

     

    Jason

  • i seem to face the same problems you faced !!

    have you fixed it !!

    i have also heard of LQR control !!have you tried it !!

     

  • here is the response curve. please advise. thanks!3692140284?profile=original
  • hey guys i found a serious bloody error in my pid highlighted in red.

  • Thanks Roy. I asked this because im reading and searching about design, not only interested building Arducopter. The data is from one of the guys master thesis. As I read from the theses he makes linearization like on the data, measures each brushless and plot pwm versus speed of them. Then draws regression line, finds transfer function ( brushless gains etc ) then finds system model, then finally find PID parameters accourding to design. Since i dont see these kind of stuff here between ArduCopter people, i felt just a little curious.

  •       I have found a solution to my previous question, but i have another now :) 

    Quadrotor and brushless motors used in the Quad systems are not LINEAR. So PID control design shouldnt work well with it if you run your brushless motors in nonlinear region. However, brushless motors have some region which is almost linear, So PID is ok to use in that range as a control method. So system must be linearized, then PID method should be used, thats what its needed. Here is an example of  angular velocity versus pulse width. Its seen that there are nonlinear region.

      The question im asking is do you guys measure your brushless and use that linear range before you write control algorithm ?  Or just go for PID tuning and try to find parameters ?  AeroQuad or ArduCopter  codes are ready to use, so I guess most of the Quad users just go with PID tuning. Any comment will help, thanks...

  • Im working on my quadrotors PID. Somehow I have some concerns about suppyling power from Li Po's. As you know brushless motors can supply different thrusts on different voltage levels supplied from Li Po's.
    For example while using fully charged 12.6V 3S Lipo on 9000rpm with XX brand brushless, it can supply 900gr thrust. On the other hand, everything same but Lipo charged only 11.0V, it may supply like 820gr thrust.
    Therefore, because of different voltage conditions, PID parameters will never match. It will be ok only if I have a voltage feedback from LiPo's and then change PID parameters for each voltage level. Adding voltage feedback on the control algorithm will solve the problem i guess. Anyone do this kind of feedback for their PID ? Thanks, have a nice one...
This reply was deleted.

Activity