# How to tune the two PIDs for quadrotor

I'm trying to implement two PIDs for stabilizing quadrotor for position tracking. The inputs are $x_{d}(t), y_{d}(t), z_{d}(t)$ and $\psi_{d}(t)$. For position tracking, usually the small angle assumption is assumed. This assumption allows for acquiring $\theta_{d}$ and $\phi_{d}$. These are the results The x-axis position is driving me crazy. After alot of attempts for tuning the PIDs, I felt something wrong is going on. Is this a normal behavior for PID controller? Also, what I've noticed is that once $\psi$ reaches to zero, the platform starts oscillating (after 1.5 second in the figure).

For solving ODEs and computing the derivatives for the velocities, I use Euler methods.

It is simulation in Matlab.

• Explain in more detail how you tuned your PID controller.
– Paul
Apr 17, 2015 at 15:33
• @Paul, do you want to know the actual values of the gains? Apr 17, 2015 at 20:20
• Not the values, just the steps you took to arrive at those values.
– Paul
Apr 17, 2015 at 21:30
• @Paul, after a deep thinking, I believe these results are good (not perfect). I've double checked the trajectory, it seems from 0 sec to 1.5 sec, the trajectory is fixed. After 1.5 sec, the trajectory starts varying. I've implemented backstepping controller and the results are perfect. Thank you. Apr 18, 2015 at 18:42

is it real or simulation application?

If simulation there is good examples in matlab codes/models you can look deeper

If real:

1- filter the sensor data

2- use tan2 function for angular error calculations

3- begin PID calculations with all P, I and D constants. if you use just one of them stabilization is not possible. PI or PD control is possible. Be carefefull first constants P>I>D than you can use :

or

http://www.expertune.com/tutor.aspx

• simulation in matlab. yes there are a lot of matlab codes, but the majority of them use simulink. I'm using script. Apr 17, 2015 at 20:24
• This is a good thesis I did simulink model from this and works fine. Also be carefull about using tan2 in angular calculations. also If you can send or share the code may be(if familiar language) I can help/fix your code
– acs
Apr 17, 2015 at 23:16
• @cagdasecking, after a deep thinking, I believe these results are good (not perfect). I've double checked the trajectory, it seems from 0 sec to 1.5 sec, the trajectory is fixed. After 1.5 sec, the trajectory starts varying. I've implemented backstepping controller and the results are perfect. Thank you. Apr 18, 2015 at 18:42

The controller has a definite performance problem after t=1.5sec. [This can be due to the system model or some other coding error.]

The system (model + controller) behaves smooth until t=1.5sec. It is best to magnify and debug the code at that region. The controller behaves as expected until then. Only the X has no error from T0, which makes assessing the X-axis controller impossible.

Another point also worth noting is that, the Y and Z errors should have caused some error in X, but we don't see this. So the simulation model could be simplified (like decoupled in X direction from others maybe?)

Euler angles sometimes cause computational errors in attitudes (for exact zero, or pi or pi/2's). That might be the reason.

For an understanding of the maths behind euler representation singularities, and their solutions, please refer to textbooks or articles, one example is: http://lairs.eng.buffalo.edu/pdffiles/pconf/C10.pdf

• The problem was with the trajectory. From 0-1.5 sec, the trajectory is fixed. This explains why the error decays, after 1.5 sec, the trajectory started varying and hence the error doesn't decay, therefore I just hoped to reduce the error which I've done. I've implemented backstepping controller and the results are much better than PID but still PID is a valid choice. Apr 23, 2015 at 22:28