# Why do I need I-gain in my outer-loop?

I'm implementing a set of loops to control pitch-and-roll angular positions.

In an inner-loop, motor speeds are adjusted to achieve desired angular rates of rotation (the "inner-loop setpoints").

An outer-loop decides these desired angular rates (the "inner-loop setpoints") based on the aircraft's angular positions.

### Outer-loop

• Frequency = ~400Hz
• Outer PV = input angular position (in degrees)
• Outer SP = desired angular position - input angular position (in degrees)

### Inner-loop

• Frequency = ~760Hz
• Inner PV = input angular rotation (in degrees-per-second)
• Inner SP = constant1 * Outer MV (in degrees-per-second)
• PWM = Inner MV / constant2 (as percentile)

I understand what I-gain does and why this is important, but I'm not able to see any practical reason for also having I-gain specified in the outer-loop. Surely the inner-loop would compensate for any accumulated error, leaving no error to compensate for in the outer-loop, or is my thinking flawed?

Any example gain values to elaborate would be greatly appreciated.

• ...and there I find a major flaw in the assignment of Outer SP – Biscuits Mar 16 '16 at 18:58

In my own experience, it is not necessary Integral term in any of these loops. I got a fine PD tuning of both inner and outer loop. See for instance this paper, where I firstly tuned PD only with PSO.

Wikipedia shows a simple animation of each of the effects of P-I-D in any tuning https://en.wikipedia.org/wiki/PID_controller#Manual_tuning.

Integral gain is how you eliminate steady state error. An integral gain in the inner loop means you'll (eventually) have no steady state error on the angular velocity.

What ensures no steady state error on angular position, which is arguably the more important of the two? Outer loop integral error.

• Plus consider that any real system has a real lag between commanded position and achieved position. If your integral loop responds to this natural lag in behavior, it will result in an overshoot when the system eventually gets to its setpoint. – SteveO Mar 17 '16 at 2:10
• An error in angular position would give a desired angular rate which would be achieved if there was an integral term in the inner loop. There would be no steady state error in either case. – holmeski Mar 18 '16 at 16:09
• Thanks Chuck, your first sentence makes perfect sense - it's the second one that troubles me. @holmeski said it exactly how I see it. – Biscuits Mar 18 '16 at 18:02
• @Biscuits - Ask yourself, "Where does the angular error go?" Angular position reference is an input to the outer loop, as is angular position feedback. The output - angular error - is then acted on by the outer PID loop. The outer PID loop then feeds a speed request to the inner PID loop. My point is that the outer PID loop will never request the speed required to get the angular position feedback equal to the angular position reference. – Chuck Mar 18 '16 at 18:50
• @holmeski , Biscuits - refer to the comment above and: I think you're thinking of this backwards. If the outer loop had an integral gain, then it could drive angular position error to zero, even if the inner loop did not have integral gain. Ultimately you don't actually care about angular speed; it's just a means to the end, which is angular position. – Chuck Mar 18 '16 at 18:51

Let's assume that the inner loop, whose input is desired angular rate and output is motor input, can track the desired angular rate. Some internet fellow has taken care of that for us. I'm going to be considering a step change in desired position:

Let $$e = x_{des} - x$$ and $$\dot e = -\dot x$$ this will be our outer loop controller

$$\dot x = k_p e + k_d \dot e$$

substituting in $$\dot e$$ gives

$$-\dot e = k_p e + k_d \dot e$$

which can be rearranged as

$$\dot e = - \frac{k_p}{k_d + 1} e$$

which is a first order system. I've ignored inner loop dynamics but that should be fine, inner loop dynamics should be at least an order of magnitude faster than the outer loop dynamics.

I am not saying that integral control is not useful, just that it is not strictly necessary in the outer loop. It is easy to imagine a situation where the inner loop is not behaving correctly that results in a steady state error.

The px4 flight stack for multicopters approaches attitude control with pd control for angular position and pid control for body rate control.