Integral action in state space: remove a load offset

Add an integral state to a cart controller, calculate three feedback gains, and compare constant-load tracking with reference feedforward. See why stable dynamics, accurate sensing, and sufficient force still matter.

By 12 min read

A position controller can hold a cart still while missing its target. A constant external force leaves a small position error, and that error supplies the opposing feedback force. Adding an integral state gives the controller another way to maintain the required force.

Add integral action to state feedback

Integral action in state space adds the accumulated output error to the state used for feedback. The added state changes the closed-loop dynamics, so its gain belongs in the stability design alongside the original state gains.

For a stable loop with a reachable constant equilibrium, the integral state can settle only when its derivative, the tracking error, reaches zero. This gives an asymptotic result under stated assumptions; it does not promise zero error at every finite time.

Åström and Murray describe this state augmentation for integral feedback. Their displayed error convention is output minus reference; this lesson uses reference minus output and changes the feedback sign consistently.

Declare the cart and the unknown force

Use the same horizontal cart as the pole-placement lesson: mass m = 2 kg and viscous damping b = 1 N·s/m. Position p increases in the direction of positive actuator force u and external force d.

ṗ = v
m v̇ = u − bv + d
e = r − p

The reference r is a constant position. The load d is a constant external force, unknown to the controller. Both begin at time zero and remain fixed; position and velocity initially equal zero.

The controller receives exact position and velocity and commands an ideal force actuator. Springs, sensor errors, delays, friction thresholds, and motor dynamics are absent. The state-space modeling lesson explains how these choices determine the model being controlled.

Find the offset left by reference feedforward

Start with a controller that combines position and velocity feedback with a reference feedforward term:

u = −kₚp − kᵥv + kₚr = kₚ(r − p) − kᵥv

When d = 0, a stable version of this loop approaches p = r. A constant load changes the equilibrium: at rest, v = v̇ = 0, so the actuator must apply u = −d.

0 = kₚ(r − p∞) + d
p∞ = r + d/kₚ
e∞ = −d/kₚ

A positive load pushes the equilibrium past the target. With kₚ = 22 N/m and d = 1 N, the remaining error is −1/22 m, or −0.045455 m. Increasing the position gain reduces this offset but also changes the response and force demand.

This baseline already tracks a constant reference without a load. The extra integral state below addresses the unknown constant force; a plant's position integrator alone does not remove this particular load-induced offset.

Add error memory as a third state

Define an integral state z and use it in the force command:

ż = r − p, with z(0) = 0
u = −kₚp − kᵥv + kᵢz
xₐ = [p, v, z]ᵀ

Positive position error increases z. With a positive integral gain, that accumulated error increases the positive force contribution kᵢz. The BYU control text's integral-control chapter develops this augmentation and emphasizes redesigning the combined dynamics.

QuantityMeaningUnit
p, r, ePosition, reference, and position errorm
vVelocitym/s
zAccumulated position errorm·s
kₚPosition gainN/m
kᵥVelocity gainN·s/m
kᵢIntegral gainN/(m·s)

The closed-loop equations are:

ẋₐ = Acl xₐ + [0, d/m, r]ᵀ
Acl = [[0, 1, 0], [−kₚ/m, −(b + kᵥ)/m, kᵢ/m], [−1, 0, 0]]

This controller sends the reference through ż and has no direct kₚr feedforward term. The baseline and integral controller therefore have different reference paths as well as different closed-loop orders. Sharing kₚ and kᵥ makes their steady offsets easy to compare; it does not isolate an integrator's effect on a matched transient.

Place all three closed-loop poles

The augmented characteristic polynomial follows from det(sI − Acl):

s³ + ((b + kᵥ)/m)s² + (kₚ/m)s + kᵢ/m

Choose three distinct negative poles at −ρ, −2ρ, and −3ρ, where ρ is a positive rate in s⁻¹. Expanding their product gives:

(s + ρ)(s + 2ρ)(s + 3ρ) = s³ + 6ρs² + 11ρ²s + 6ρ³
kₚ = 11mρ² = 22ρ²
kᵥ = 6mρ − b = 12ρ − 1
kᵢ = 6mρ³ = 12ρ³

At ρ = 1 s⁻¹, the gains are kₚ = 22 N/m, kᵥ = 11 N·s/m, and kᵢ = 12 N/(m·s). All three integral-loop poles are negative. The baseline using those same position and velocity gains has poles −3 ± j√2 s⁻¹.

Adding an arbitrary positive integral gain to an existing controller can destabilize it. For this cubic, positive coefficients also require (b + kᵥ)kₚ > m kᵢ for asymptotic stability. This is the third-order Routh–Hurwitz condition, not a general rule that every positive gain works.

Check the augmented system before assigning poles

Before feedback, the augmented plant has Aₐ = [[0, 1, 0], [0, −0.5, 0], [−1, 0, 0]] and Bₐ = [0, 0.5, 0]ᵀ. The reference enters separately. Its controllability matrix is:

[Bₐ, AₐBₐ, Aₐ²Bₐ] = [[0, 0.5, −0.25], [0.5, −0.25, 0.125], [0, 0, −0.5]]
determinant = 0.125 ≠ 0

This three-state model is controllable. Full-state feedback can therefore assign its three poles. The extra state must be included in that test; controllability of the original plant alone is insufficient.

For a finite-dimensional continuous-time LTI plant with one input, one tracked output, and no direct feedthrough, the augmented pair is controllable when the original pair is controllable and [[A, B], [C, 0]] has full rank. The latter condition excludes an invariant zero at the origin. Raymond Kwong's set-point tracking notes, section 5.3 derive this condition.

For the cart's position output C = [1, 0], that rank-test matrix is [[0, 1, 0], [0, −0.5, 0.5], [1, 0, 0]], with determinant 0.5. The output and input choices permit the augmentation used here.

Calculate the force and memory at equilibrium

At a stable constant equilibrium, ż = 0 requires p∞ = r. The physical force balance still requires u∞ = −d. Combining those conditions gives:

p∞ = r, v∞ = 0
z∞ = (kₚr − d)/kᵢ
u∞ = −kₚr + kᵢz∞ = −d

With r = 1 m, d = 1 N, and the default gains, z∞ = (22 − 1)/12 = 1.75 m·s. The position term contributes −22 N and the integral term contributes +21 N. Their sum is the required −1 N holding force.

The integral term is not the entire actuator command. Its stored value compensates for both the unknown load and the position-feedback term at the selected reference. Even with no external load, this particular reference path needs a nonzero z to hold a nonzero position.

The baseline eventually applies the same −1 N force, but obtains it from a −0.045455 m error. The augmented loop stores the required correction while the measured position error approaches zero.

Compare exact responses under the same load

Remember the error, balance the load

Can an integral state remove the constant offset?

A 2 kg cart has damping 1 N·s/m. Both controllers know position and velocity exactly. The external force is unknown to each controller; each run starts at rest with position zero.

1.000000
1.000000
1.000000
4.000000

Integral: u = −kp p − kv v + ki z, with ż = r − p and z(0) = 0. Baseline: u = kp(r − p) − kv v. Sharing kp and kv does not match their reference paths or transient dynamics. The comparison tests the constant-load offset.

Integral position (m)
0.950466
Baseline position (m)
1.045457
Integral error (m)
0.049534
Baseline error (m)
-0.045457
Integral force (N)
-1.045405
Baseline force (N)
-0.999739
Integral state z (m·s)
1.700050
Integral steady error (m)
0.000000
Baseline steady error (m)
-0.045455
Steady integral state (m·s)
1.750000
Steady applied force (N)
-1.000000
Position gain kp (N/m)
22.000000
Velocity gain kv (N·s/m)
11.000000
Integral gain ki (N/(m·s))
12.000000

Integral poles: −ρ, −2ρ, −3ρ, with ρ = 1.000000 s⁻¹. All selectable designs are stable in this exact continuous model. The baseline poles are −3ρ ± j√2ρ. Steady values are analytical limits, separate from the inspected finite time.

Tracking and the remaining offset

Position (m) over twelve secondsExact continuous-time responses from rest. Solid blue shows integral feedback; dashed amber shows state feedback with reference feedforward. Squares mark 4.000000 seconds. The dotted horizontal line marks the position reference. The vertical axis adapts from minus 1.500000 to plus 1.500000. No force saturation is modeled.-1.501.50612Position (m)Time (s)
Solid blue: integral feedback. Dashed amber: reference feedforward with state feedback. The dotted line is the reference. Their reference paths and transient poles differ. Vertical axes rescale using continuous response bounds; squares mark the inspected time.

Applied force in the two loops

Force (N) over twelve secondsExact continuous-time responses from rest. Solid blue shows integral feedback; dashed amber shows state feedback with reference feedforward. Squares mark 4.000000 seconds. The dotted horizontal line marks the common force equilibrium or integral-state equilibrium. The vertical axis adapts from minus 57.000000 to plus 57.000000. No force saturation is modeled.-570570612Force (N)Time (s)
Solid blue: integral feedback. Dashed amber: the baseline. Both approach the dotted holding force −d. The ideal actuator applies every commanded newton. Vertical axes rescale using continuous response bounds; squares mark the inspected time.

Error accumulated in the integral state

Integral z (m·s) over twelve secondsExact continuous-time responses from rest. Blue shows the integral state. Squares mark 4.000000 seconds. The dotted horizontal line marks the common force equilibrium or integral-state equilibrium. The vertical axis adapts from minus 2.500000 to plus 2.500000. No force saturation is modeled.-2.502.50612Integral z (m·s)Time (s)
Blue: z integrates reference minus position. The dotted line is its predicted equilibrium; ki times z is only one contribution to the total force. Vertical axes rescale using continuous response bounds; squares mark the inspected time.

Reference and load stay constant from t = 0. No force limit, sensor bias, delay, or actuator dynamics enters these responses. Integral action cannot supply force beyond a real actuator's capacity.

Start with Track with a load and inspect the analytical steady readouts alongside the finite-time values. At 4 s, the integral position is 0.950466 m and the baseline position is 1.045457 m. The integral run still has 0.049534 m of error at that instant; its zero-error statement concerns the limit as time grows.

Then choose Reject a load. With reference zero, the load first moves the cart, and the integral state develops the holding correction. Zero input keeps both trajectories at rest because reference, load, and every initial state are zero.

Each curve evaluates a closed-form solution. For the integral position, let q = exp(−ρt), w = 1 − q, and A = d/(2mρ²). This scalar coefficient has units of meters; for m = 2 kg, its numerical SI value is d/(4ρ²):

p(t) = rw³ + Aq w²
z(t) = [r(w + w²/2 + w³/3) − Aw³/3]/ρ

Here A is a scalar coefficient, separate from a state matrix. The first term of p is the reference response; the second is the constant-force response and decays to zero. The plots sample these exact functions for drawing, and their ranges use continuous-time bounds so all supported responses fit.

Moving the time control changes only the inspected instant. Changing ρ redesigns all three gains. No twelve-second plot establishes a settling-time or real-hardware performance guarantee.

Keep the zero-error result within its assumptions

The result requires a stable augmented loop, a reachable constant equilibrium, and enough actuator force to maintain it. Constant reference and disturbance assumptions matter: one error integrator does not establish perfect tracking of arbitrary changing signals.

Measurement accuracy also matters. If the position sensor reads p + ε, a settled integrator makes that measured position equal r, leaving the true position at r − ε. Integral action removes the measured constant error under the model; it cannot identify an unknown sensor bias by itself.

A force limit can make the target impossible to hold. If the actuator cannot oppose d, the error may persist while z keeps accumulating. The integral-windup lesson separates actuator clamping from corrections to the integral state.

Real actuator dynamics and delayed or estimated states can also change stability. An observer supplies estimates under its own assumptions; an actuator model describes dynamics absent from an ideal force source. These plots are calculations for the declared cart, with no hardware validation claim.

Reproduce the cart calculations in Python

This standard-library program evaluates exponential modes independently of the polynomial form used above. It calculates the default finite-time response, equilibrium, and the exercise checks. It requires no control library.

import math

r, d, rho, t = 1.0, 1.0, 1.0, 4.0
kp, kv, ki = 22*rho**2, 12*rho-1, 12*rho**3
c = (-3*r+d/(4*rho**2),
     3*r-d/(2*rho**2),
     -r+d/(4*rho**2))
terms = [c[j-1]*math.exp(-j*rho*t) for j in (1, 2, 3)]
p = r + sum(terms)
v = sum(-j*rho*terms[j-1] for j in (1, 2, 3))
z = -sum(c[j-1]*(-math.expm1(-j*rho*t))/(j*rho)
         for j in (1, 2, 3))
u = -kp*p-kv*v+ki*z

pb_inf = r+d/kp
a = math.sqrt(2)*rho*t
decay = math.exp(-3*rho*t)
pb = pb_inf*(1-decay*(math.cos(a)+3/math.sqrt(2)*math.sin(a)))
vb = pb_inf*11*rho/math.sqrt(2)*decay*math.sin(a)
ub = kp*(r-pb)-kv*vb

print(f'Gains: kp={kp:.6f}, kv={kv:.6f}, ki={ki:.6f}')
print(f'Integral at 4 s: p={p:.6f}, v={v:.6f}, z={z:.6f}')
print(f'Forces at 4 s: integral={u:.6f}, baseline={ub:.6f}')
print(f'Errors at 4 s: integral={r-p:.6f}, baseline={r-pb:.6f}')
print(f'Steady positions: integral={r:.6f}, baseline={pb_inf:.6f}')
print(f'Steady memory={(kp*r-d)/ki:.6f}, force={-d:.6f}')
print(f'Exercise 1: baseline={.5-2/kp:.6f}, memory={(kp*.5+2)/ki:.6f}')
print(f'Integral-gain stability ceiling={((1+kv)*kp/2):.6f}')
Gains: kp=22.000000, kv=11.000000, ki=12.000000
Integral at 4 s: p=0.950466, v=0.048705, z=1.700050
Forces at 4 s: integral=-1.045405, baseline=-0.999739
Errors at 4 s: integral=0.049534, baseline=-0.045457
Steady positions: integral=1.000000, baseline=1.045455
Steady memory=1.750000, force=-1.000000
Exercise 1: baseline=0.409091, memory=1.083333
Integral-gain stability ceiling=132.000000

Try two integral-state exercises

Exercise 1. Keep the default gains, set r = 0.5 m and d = −2 N, and assume both loops settle. Find the baseline position and error, the integral position and memory, and the applied force each controller must supply.

Show the equilibrium calculation

The baseline position is 0.5 − 2/22 = 0.409091 m, leaving error 0.5 − 0.409091 = 0.090909 m. The integral position approaches 0.5 m, with z = (22 × 0.5 + 2)/12 = 13/12 = 1.083333 m·s.

Both actuators apply +2 N to balance the negative external force. In the integral loop, −22 × 0.5 + 12 × (13/12) = −11 + 13 = 2 N. The integral contribution alone is 13 N.

Exercise 2. Keep m = 2, b = 1, kₚ = 22, and kᵥ = 11, but change only kᵢ to 200 in consistent SI units. All gains remain positive. Does this augmented controller stay asymptotically stable, and can you claim it will reach the zero-error equilibrium?

Show the stability calculation

The characteristic polynomial becomes s³ + 6s² + 11s + 100. For this cubic, the Routh condition requires 6 × 11 > 100, which fails. Its first Routh column is 1, 6, −34/6, 100, with two sign changes and therefore two right-half-plane poles.

With the other gains fixed, asymptotic stability requires 0 < kᵢ < 132 N/(m·s). A formal equilibrium still exists at kᵢ = 200, but the unstable loop has no general convergence guarantee. The lab avoids this case by redesigning all three gains together.

Sources and further study

The cart, gain family, exact responses, and exercises are original teaching calculations. These references establish the control concepts used in the derivation:

Continue with integral windup to see how saturation changes this ideal result. If a force command cannot be applied, the integral state's evolution needs attention even when the unconstrained pole calculation is stable.