Chapter 11: PID Control Basics

Lesson 3: Derivative Action and Improvement of Transient Response

This lesson introduces the derivative component of PID control and its role in shaping the transient response of linear feedback systems. We derive how derivative action modifies the effective damping of second-order plants, relate it to time-domain performance measures (overshoot, rise time, settling time), and illustrate implementation via PD controllers in robotics-oriented software environments (Python, C++, Java, MATLAB/Simulink, and Mathematica).

1. Conceptual Overview of Derivative Action

In a single-input single-output (SISO) feedback system with error signal \( e(t) = r(t) - y(t) \), the derivative term is defined as

\[ u_D(t) = K_d \frac{d e(t)}{d t}, \]

where \( K_d > 0 \) is the derivative gain. In a proportional-derivative (PD) controller, the control law is

\[ u(t) = K_p e(t) + K_d \frac{d e(t)}{d t}. \]

Intuitively, the derivative term reacts to how fast the error is changing. If the output rises quickly toward the reference, the derivative term produces a control action opposing that rapid change, providing a damping-like effect that can reduce overshoot and oscillation.

Under zero initial conditions, the Laplace transform of the derivative term is \( \mathcal{L}\{\tfrac{d e(t)}{d t}\} = s E(s) \), so the PD controller has transfer function

\[ C(s) = K_p + K_d s = K_p(1 + T_d s), \quad T_d = \frac{K_d}{K_p}. \]

The parameter \( T_d \) is called the derivative time. For fixed \( K_p \), increasing \( K_d \) increases \( T_d \), strengthening the damping effect.

flowchart TD
  R["Reference r(t)"] --> E["Error e(t) = r(t) - y(t)"]
  E --> P["Proportional term: Kp * e"]
  E --> D["Derivative term: Kd * de/dt"]
  P --> SUM["Control signal u(t)"]
  D --> SUM
  SUM --> G["Plant G(s)"]
  G --> Y["Output y(t)"]
  Y --> E
        

2. PD Control of a Second-Order Mass–Spring–Damper Plant

Consider a mechanical translational system with mass \( M > 0 \), viscous damping \( B \ge 0 \), and stiffness \( K > 0 \). The equation of motion with control input \( u(t) \) and output position \( y(t) \) is

\[ M \ddot{y}(t) + B \dot{y}(t) + K y(t) = u(t). \]

Assume unity feedback with reference \( r(t) \), error \( e(t) = r(t) - y(t) \), and PD control law

\[ u(t) = K_p e(t) + K_d \frac{d e(t)}{d t}. \]

For a constant reference (step input), \( r(t) = r_0 \), we have \( \dot{r}(t) = 0 \) and thus \( \tfrac{d e(t)}{d t} = - \dot{y}(t) \). Substituting into the control law:

\[ u(t) = K_p (r_0 - y(t)) - K_d \dot{y}(t). \]

Substituting this into the plant dynamics yields

\[ M \ddot{y}(t) + B \dot{y}(t) + K y(t) = K_p (r_0 - y(t)) - K_d \dot{y}(t). \]

Rearranging terms,

\[ M \ddot{y}(t) + (B + K_d)\dot{y}(t) + (K + K_p) y(t) = K_p r_0. \]

This is the closed-loop differential equation for the output under step input. Comparing with the standard second-order form

\[ \ddot{y}(t) + 2 \zeta \omega_n \dot{y}(t) + \omega_n^2 y(t) = \omega_n^2 r_0, \]

we can identify the effective natural frequency \( \omega_n \) and damping ratio \( \zeta \) as

\[ \omega_n^2 = \frac{K + K_p}{M}, \quad 2 \zeta \omega_n = \frac{B + K_d}{M}. \]

Solving explicitly:

\[ \omega_n = \sqrt{\frac{K + K_p}{M}}, \quad \zeta = \frac{B + K_d}{2 \sqrt{M (K + K_p)}}. \]

Key conclusion: for fixed plant parameters \( M, B, K \) and proportional gain \( K_p \), increasing derivative gain \( K_d \) increases the effective damping ratio \( \zeta \), which tends to reduce overshoot and oscillations in the step response. At the same time, increasing \( K_p \) increases \( \omega_n \) (speed) but also influences \( \zeta \).

3. Transient Response Metrics and the Effect of Derivative Gain

Recall from earlier chapters that for a standard second-order system with \( 0 < \zeta < 1 \), the percent overshoot \( M_p \) and approximate settling time \( T_s \) (for a 2% criterion) satisfy

\[ M_p = \exp\!\left( -\frac{\pi \zeta}{\sqrt{1 - \zeta^2}} \right) \times 100\%, \quad T_s \approx \frac{4}{\zeta \omega_n}. \]

Using the expressions from the previous section, \( \zeta = \frac{B + K_d}{2 \sqrt{M (K + K_p)}} \) and \( \omega_n = \sqrt{\frac{K + K_p}{M}} \), we can write

\[ T_s \approx \frac{4}{\zeta \omega_n} = \frac{8 M}{B + K_d}. \]

Thus, for fixed \( M \) and \( B \), raising \( K_d \) decreases \( T_s \) approximately as \( T_s \propto \tfrac{1}{B+K_d} \). Because the overshoot \( M_p \) is a decreasing function of \( \zeta \) on \( (0, 1) \), increasing \( K_d \) (for fixed \( K_p \)) also decreases \( M_p \).

For design purposes, given a desired damping ratio \( \zeta_d \) and a chosen \( K_p \), we can solve for \( K_d \):

\[ \zeta_d = \frac{B + K_d}{2 \sqrt{M (K + K_p)}} \quad \Longrightarrow \quad K_d = 2 \zeta_d \sqrt{M (K + K_p)} - B. \]

This relation quantifies how much derivative gain is needed to reach a desired damping ratio and thus a desired overshoot.

flowchart TD
  S["Choose Kp for speed (omega_n)"] --> ZDES["Specify desired damping zeta_d"]
  ZDES --> KD["Compute Kd = 2 * zeta_d * sqrt(M*(K+Kp)) - B"]
  KD --> SIM["Simulate step response"]
  SIM --> CHECK["Check Mp, Ts, rise time"]
  CHECK --> ADJ["Adjust Kp, Kd if needed"]
        

4. Derivative on Error vs Derivative on Measurement and Noise

In the derivation above we used \( u(t) = K_p e(t) + K_d \dot{e}(t) \). For a step reference, \( \dot{r}(t) = 0 \) and therefore \( \dot{e}(t) = -\dot{y}(t) \). This is equivalent to taking the derivative of the measured output and using

\[ u(t) = K_p e(t) - K_d \dot{y}(t). \]

In practice, many implementations use derivative on the measurement (or on the process variable) rather than derivative on the error to avoid impulsive action when the reference undergoes steps. For the step-tracking case, the two forms coincide in their effect on the homogeneous dynamics.

Derivatives amplify high-frequency components. If sensor noise \( n(t) \) is present in the measurement, the derivative term effectively applies a high-pass operation to the noise, which can cause large, undesired fluctuations in the control input. This motivates the filtered derivative used in practice, which will be studied in a later chapter.

5. Python Lab — PD Control of a Mass–Spring–Damper (Robotics-Oriented)

In robotics, PD controllers are commonly used for joint position control of manipulators and mobile robots. The following Python example uses the python-control library (often used as a low-level analysis tool in robotics) to simulate PD control of a mass–spring–damper plant.


import numpy as np
import matplotlib.pyplot as plt

# If python-control is installed:
# pip install control
import control as ctrl

# Physical parameters (e.g., robot joint approximated as mass-spring-damper)
M = 1.0   # kg
B = 0.5   # N s/m
K = 4.0   # N/m

# PD gains
Kp = 16.0
Kd = 4.0

# Plant: M d2y/dt2 + B dy/dt + K y = u
# Transfer function from u to y: 1 / (M s^2 + B s + K)
s = ctrl.TransferFunction.s
G = 1.0 / (M * s**2 + B * s + K)

# PD controller: C(s) = Kp + Kd s
C = Kd * s + Kp

# Unity feedback closed-loop from r to y
T = ctrl.feedback(C * G, 1)

# Step response (unit step reference)
t = np.linspace(0, 10, 1000)
t, y = ctrl.step_response(T, T=t)

# Compute effective zeta and omega_n from formulas
omega_n = np.sqrt((K + Kp) / M)
zeta = (B + Kd) / (2.0 * np.sqrt(M * (K + Kp)))

print("Effective omega_n =", omega_n)
print("Effective zeta    =", zeta)

plt.figure()
plt.plot(t, y, label="y(t)")
plt.axhline(1.0, linestyle="--", label="reference")
plt.xlabel("Time [s]")
plt.ylabel("Position")
plt.title("PD-Controlled Mass-Spring-Damper Step Response")
plt.grid(True)
plt.legend()
plt.show()
      

In a robotics stack (e.g., ROS-based), the same PD law is applied at the joint level inside a joint position controller, while libraries like python-control are used offline to tune gains based on desired damping and natural frequency.

6. C++ Implementation — Discrete-Time PD Loop for a Robot Joint

A typical low-level controller in robotics firmware (or a ROS-control plugin) runs a discrete-time PD loop at a fixed sampling period \( T_s \). A simple C++ implementation using finite differences for the derivative term is:


#include <iostream>

struct PDController {
    double Kp;
    double Kd;
    double dt;
    double prev_error;

    PDController(double Kp_, double Kd_, double dt_)
        : Kp(Kp_), Kd(Kd_), dt(dt_), prev_error(0.0) {}

    double compute(double desired, double measured) {
        double error = desired - measured;
        double dedt = (error - prev_error) / dt;  // discrete derivative
        prev_error = error;
        return Kp * error + Kd * dedt;
    }
};

int main() {
    double Kp = 16.0;
    double Kd = 4.0;
    double dt = 0.001; // 1 kHz control loop

    PDController pd(Kp, Kd, dt);

    double y = 0.0;      // joint position
    double ydot = 0.0;   // joint velocity
    double desired = 1.0;
    double M = 1.0, B = 0.5, K = 4.0;

    for (int k = 0; k < 10000; ++k) {
        double t = k * dt;
        double u = pd.compute(desired, y);

        // Simple forward-Euler integration of mass-spring-damper
        double yddot = (u - B * ydot - K * y) / M;
        ydot += yddot * dt;
        y   += ydot * dt;

        if (k % 1000 == 0) {
            std::cout << "t=" << t
                      << " y=" << y
                      << " u=" << u << std::endl;
        }
    }

    return 0;
}
      

In ROS-control or similar robotics frameworks, the function compute is invoked inside the controller update loop, and the output u is sent to the actuator. The choice of dt (loop frequency) interacts with the effective derivative gain and noise sensitivity.

7. Java Implementation — PD Controller Skeleton for Mechatronic Systems

Java-based control code appears in many educational and industrial robotics platforms. Below is a minimal PD controller for a single axis, which could be integrated into a robotics library (e.g., in a periodic callback similar to those in FIRST/WPILib or other Java-based robot APIs).


public class PDController {
    private double Kp;
    private double Kd;
    private double dt;
    private double prevError = 0.0;

    public PDController(double Kp, double Kd, double dt) {
        this.Kp = Kp;
        this.Kd = Kd;
        this.dt = dt;
    }

    public double compute(double reference, double measurement) {
        double error = reference - measurement;
        double dedt = (error - prevError) / dt;
        prevError = error;
        return Kp * error + Kd * dedt;
    }
}

// Example usage in a periodic control loop:
public class JointController {
    private final PDController pd;
    private double position = 0.0;
    private double velocity = 0.0;

    private final double M = 1.0;
    private final double B = 0.5;
    private final double K = 4.0;
    private final double dt = 0.001;

    public JointController() {
        pd = new PDController(16.0, 4.0, dt);
    }

    public void update(double reference) {
        double u = pd.compute(reference, position);

        // Simulate mass-spring-damper
        double accel = (u - B * velocity - K * position) / M;
        velocity += accel * dt;
        position += velocity * dt;
    }

    public double getPosition() {
        return position;
    }
}
      

Java platforms for robotics usually add sensor interfaces and real-time scheduling, but the core PD logic remains as above. Tuning Kp and Kd is guided by the same second-order analysis developed earlier.

8. MATLAB/Simulink Implementation

MATLAB and Simulink are standard tools in control engineering and robotics. The script below constructs the PD-controlled mass–spring–damper system and computes its step response using the Control System Toolbox. The same dynamics can be built graphically in Simulink using a PD Controller block connected to a second-order plant.


% Physical parameters
M = 1.0;
B = 0.5;
K = 4.0;

% PD gains
Kp = 16.0;
Kd = 4.0;

s = tf('s');

% Plant: 1 / (M s^2 + B s + K)
G = 1 / (M * s^2 + B * s + K);

% PD controller: C(s) = Kp + Kd s
C = Kp + Kd * s;

% Closed-loop transfer function
T = feedback(C * G, 1);

% Step response
figure;
step(T);
grid on;
title('PD-Controlled Mass-Spring-Damper Step Response');

% Compute effective natural frequency and damping ratio
omega_n = sqrt((K + Kp) / M);
zeta = (B + Kd) / (2 * sqrt(M * (K + Kp)));

disp(['Effective omega_n = ', num2str(omega_n)]);
disp(['Effective zeta    = ', num2str(zeta)]);

% In Simulink, a similar PD law is often used for robot joint control,
% possibly together with the Robotics System Toolbox to model manipulators.
      

In a Simulink model for a robot joint, the PD controller output would be applied to a joint-actuator block, and the resulting position fed back to the PD block. The analytical expressions for \( \omega_n \) and \( \zeta \) guide the selection of \( K_p \) and \( K_d \) before fine tuning.

9. Mathematica Implementation

Mathematica can symbolically or numerically solve the closed-loop dynamics. The next code snippet solves the differential equation derived in Section 2 and plots the step response.


(* Physical parameters *)
M  = 1.0;
B  = 0.5;
K  = 4.0;
Kp = 16.0;
Kd = 4.0;
r0 = 1.0;

(* Closed-loop differential equation:
   M y''(t) + (B + Kd) y'(t) + (K + Kp) y(t) == Kp r0 *)
eqn = M y''[t] + (B + Kd) y'[t] + (K + Kp) y[t] == Kp r0;

ics = {y[0] == 0, y'[0] == 0};

sol = NDSolve[{eqn, ics}, y, {t, 0, 10}];

Plot[Evaluate[y[t] /. sol], {t, 0, 10},
     PlotRange -> All,
     AxesLabel -> {"t", "y(t)"},
     GridLines -> Automatic,
     PlotLegends -> {"PD step response"}]
      

Mathematica is also useful for symbolic manipulation, e.g. deriving closed-form expressions for \( \zeta \), \( \omega_n \), or step responses, which can support more advanced theoretical analysis of PD-controlled systems.

10. Problems and Solutions

Problem 1 (Closed-Loop Dynamics with PD Control):
Consider the mass–spring–damper system \( M \ddot{y}(t) + B \dot{y}(t) + K y(t) = u(t) \) under unity feedback with PD control \( u(t) = K_p e(t) + K_d \dot{e}(t) \) and step reference \( r(t) = r_0 \). Derive the closed-loop differential equation in terms of \( y(t) \) and show that derivative action adds effective damping.

Solution:
We have \( e(t) = r(t) - y(t) = r_0 - y(t) \), so for the step input \( \dot{e}(t) = -\dot{y}(t) \). The control becomes

\[ u(t) = K_p (r_0 - y(t)) - K_d \dot{y}(t). \]

Substituting into the plant equation:

\[ M \ddot{y}(t) + B \dot{y}(t) + K y(t) = K_p (r_0 - y(t)) - K_d \dot{y}(t). \]

Rearranging terms,

\[ M \ddot{y}(t) + (B + K_d) \dot{y}(t) + (K + K_p) y(t) = K_p r_0. \]

Relative to the open-loop parameters \( B \) and \( K \), the PD controller effectively increases damping to \( B + K_d \) and stiffness to \( K + K_p \), confirming the damping interpretation of the derivative action.

Problem 2 (Derivative Gain for a Desired Damping Ratio):
Let \( M = 1 \), \( B = 0.5 \), \( K = 4 \), and \( K_p = 16 \). Design \( K_d \) so that the effective damping ratio is \( \zeta_d = 0.7 \).

Solution:
Using

\[ \zeta_d = \frac{B + K_d}{2 \sqrt{M (K + K_p)}}, \]

we solve

\[ K_d = 2 \zeta_d \sqrt{M (K + K_p)} - B. \]

Substituting the numerical values:

\[ M = 1, \quad K + K_p = 4 + 16 = 20, \quad \sqrt{M (K + K_p)} = \sqrt{20}. \]

\[ K_d = 2 \cdot 0.7 \cdot \sqrt{20} - 0.5 = 1.4 \sqrt{20} - 0.5. \]

Since \( \sqrt{20} \approx 4.4721 \),

\[ K_d \approx 1.4 \cdot 4.4721 - 0.5 \approx 6.261 - 0.5 = 5.761. \]

Thus, \( K_d \approx 5.76 \) should yield a damping ratio close to \( 0.7 \).

Problem 3 (Effect of Derivative Gain on Overshoot):
Using the same system as in Problem 2, argue qualitatively (without computing derivatives) that increasing \( K_d \) while holding \( K_p \) fixed will monotonically reduce percent overshoot \( M_p \) as long as \( 0 < \zeta < 1 \).

Solution:
From Section 3,

\[ \zeta = \frac{B + K_d}{2 \sqrt{M (K + K_p)}}. \]

For fixed \( M, B, K, K_p \), the denominator is constant while the numerator \( B + K_d \) is strictly increasing in \( K_d \). Hence \( \zeta \) increases monotonically with \( K_d \). On the interval \( 0 < \zeta < 1 \), the overshoot function

\[ M_p(\zeta) = \exp\!\left( -\frac{\pi \zeta}{\sqrt{1 - \zeta^2}} \right) \times 100\% \]

is strictly decreasing in \( \zeta \) (this can be shown by direct differentiation with respect to \( \zeta \)). Thus, as \( K_d \) increases, \( \zeta \) increases and \( M_p \) decreases, confirming that derivative action reduces overshoot in this underdamped regime.

Problem 4 (Approximate Settling Time with and without Derivative):
Consider a mass–spring–damper system with \( M = 1 \), \( B = 0.5 \), \( K = 4 \), and proportional gain \( K_p = 16 \). Compare the approximate settling times \( T_s \) for \( K_d = 0 \) and \( K_d = 4 \).

Solution:
Using

\[ T_s \approx \frac{4}{\zeta \omega_n} = \frac{8 M}{B + K_d}, \]

and \( M = 1 \), \( B = 0.5 \):

\[ T_s(K_d = 0) \approx \frac{8 \cdot 1}{0.5 + 0} = 16 \;\text{s}, \]

\[ T_s(K_d = 4) \approx \frac{8 \cdot 1}{0.5 + 4} = \frac{8}{4.5} \approx 1.78 \;\text{s}. \]

The addition of derivative action reduces the approximate settling time by almost an order of magnitude.

Problem 5 (Laplace-Domain Interpretation of PD as a Zero):
For the mass–spring–damper plant \( G(s) = \tfrac{1}{M s^2 + B s + K} \) and PD controller \( C(s) = K_p + K_d s \), show that the open-loop transfer function \( L(s) = C(s) G(s) \) can be viewed as placing a real zero at \( s = -\tfrac{K_p}{K_d} \) (assuming \( K_d \ne 0 \)) and discuss how this can improve transient response with respect to the system poles.

Solution:
The open-loop transfer function is

\[ L(s) = C(s)G(s) = \frac{K_d s + K_p}{M s^2 + B s + K} = \frac{K_d (s + K_p/K_d)}{M s^2 + B s + K}. \]

Thus there is a real zero at \( s = -K_p/K_d \). In root-locus terms (from earlier chapters), adding a zero attracts the locus toward that point and can increase the damping of the dominant poles if the zero is placed appropriately on the negative real axis. This matches the time-domain interpretation: derivative action introduces a zero that modifies the closed-loop pole locations, leading to reduced overshoot and improved settling behavior for a suitable choice of gains.

11. Summary

In this lesson we introduced derivative action as part of PID control and interpreted it mathematically and physically. For the mass–spring–damper model, we derived the closed-loop dynamics under PD control and showed that the derivative term increases the effective damping coefficient, leading to higher damping ratio, reduced overshoot, and shorter settling time. We obtained explicit formulas relating \( K_d \) to the desired damping ratio and performance specifications, and we illustrated practical implementations in Python, C++, Java, MATLAB/Simulink, and Mathematica with a robotics perspective. This sets the stage for the next lesson on PID structures and, later, for frequency-domain interpretations and filtered derivative implementations.

12. References

  1. Ziegler, J. G., & Nichols, N. B. (1942). Optimum settings for automatic controllers. Transactions of the ASME, 64, 759–768.
  2. Åström, K. J., & Hägglund, T. (1995). PID Controllers: Theory, Design, and Tuning. Research Triangle Park, NC: Instrument Society of America.
  3. Ho, W. K., Hang, C. C., & Cao, L. S. (1995). Tuning of PID controllers based on gain and phase margin specifications. IEE Proceedings - Control Theory and Applications, 142(5), 435–440.
  4. Åström, K. J., & Hägglund, T. (2001). The future of PID control. Control Engineering Practice, 9(11), 1163–1175.
  5. Middleton, R. H., & Goodwin, G. C. (1988). Improved finite word length characteristics in digital control using delta operators. IEEE Transactions on Automatic Control, 33(10), 947–958. (For insight into discrete-time implementations of derivative action.)
  6. Kessler, C. (1958). Über die Vorausberechnung des Reglers bei Verzögerungsgliedern. Regelungstechnik, 6, 66–72. (Early theoretical work related to derivative action and predictive behavior.)
  7. Levine, W. S. (Ed.). (1996). The Control Handbook. CRC Press. (Contains theoretical chapters on PID and PD controller design in linear systems.)