Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 37 ยท Getting Started

The Control Design Workflow and Python Toolkit

Follow the standard control design workflow from specifications to testing, and build a small Python toolkit for simulating systems with SciPy and RK4.

Control design is a loop of its own: you rarely get a controller right on the first try. This lesson lays out the standard workflow, then builds the small Python toolkit we reuse through the rest of the track. By the end you can simulate a linear system two ways, with SciPy and with your own integrator, and check that they agree.

The design workflow

  1. Specify. Say what "good" means in numbers: rise time, overshoot, settling time, steady-state error, disturbance rejection, actuator limits.
  2. Model. Derive equations from physics (Chapter 2) or identify them from measured data. Decide what to ignore.
  3. Analyse the plant. Is it stable? How fast is it? Which specifications are even achievable?
  4. Design. Choose a controller structure and tune it with the tools of Chapters 5 to 8: root locus, frequency response, PID, state feedback.
  5. Simulate. Test against the model, then against a more detailed model, with noise, delays and saturation.
  6. Implement and test. Discretise for a microcontroller (Chapter 8), test on hardware, and iterate.

The control design loop

Specify Numbers for speed and accuracy.
Model Equations from physics or data.
Design Choose and tune a controller.
Simulate Test before building.

Failing a test sends you back a step.

1 / 2

Models you will meet

Three forms describe the same linear system, and later chapters convert between them.

Form Example Used for
Differential equation 5 y' + y = 2 u Physics, intuition
Transfer function G(s) = 2 / (5s + 1) Classical design (Chapters 2 to 6)
State space x' = A x + B u, y = C x Modern design (Chapter 7)

Simulating with SciPy

scipy.signal provides a TransferFunction class and functions that compute the step, impulse and general-input response. They integrate the model exactly (for linear systems), so they are the reference we compare other methods against.

Python Step response with scipy.signal

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The poles line shows -0.2: a first-order system with time constant 1/0.2 = 5 s. At t = 5 the output is 2(1 - e^-1) = 1.264.

Writing your own simulator

SciPy is convenient, but you should know what it does. The simplest approach is to convert the differential equation to first-order form and take small steps. The Euler method (y += dt * f(y)) is easy but inaccurate. Runge-Kutta 4 (RK4) uses four slope samples per step and is accurate enough for almost everything in this track.

For a general first-order vector system x' = f(x, u):

Text
k1 = f(x, u)
k2 = f(x + dt/2 * k1, u)
k3 = f(x + dt/2 * k2, u)
k4 = f(x + dt * k3, u)
x_next = x + dt/6 * (k1 + 2 k2 + 2 k3 + k4)
Python A tiny RK4 simulator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The two methods agree to many decimal places. We will reuse rk4-style loops whenever a plant is nonlinear or a controller has saturation, which no transfer function can capture.

Measuring a step response

Specifications are about numbers, so write one function that extracts them. Rise time here means the 10% to 90% time, and settling time is the last time the response is outside a 2% band around the final value.

Python A step_info helper

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For a first-order system the theory says rise time is 2.2 T = 11 s, settling time (2%) is about 3.9 T = 19.6 s, and overshoot is 0. The numbers printed should match closely; you will derive them in Test Signals and First-Order Response.

Good habits

  • Always simulate the nominal plant first, then perturb parameters by 20% and check again.
  • Plot or print the control signal u too. A design that needs a motor ten times stronger than yours is useless.
  • Keep the time step much smaller than the fastest time constant (a tenth or less).
  • Save each model and result so you can compare designs.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which step of the workflow should come first?

    Without specifications you cannot tell whether a design succeeded. Specification comes before modelling, design and testing.
  2. 2. Why is RK4 preferred over Euler for simulation?

    RK4 samples four slopes per step and has far smaller error than Euler at the same step size. It handles nonlinear systems, and it does not guarantee stability of the real system.
  3. 3. The transfer function 2/(5s+1) has what pole?

    The denominator 5s + 1 is zero at s = -1/5 = -0.2. The time constant is 1/0.2 = 5 s.
  4. 4. What is a sensible rule for the simulation time step?

    The step must be small enough to resolve the fastest dynamics; a tenth of the fastest time constant is a common starting point.

Summary

  • Control design repeats: specify, model, analyse, design, simulate, implement, and iterate.
  • A linear system can be written as a differential equation, a transfer function or a state-space model.
  • scipy.signal simulates transfer functions exactly; RK4 handles anything, including nonlinear systems.
  • A step_info function turns a response into rise time, overshoot and settling time.
  • Test with perturbed parameters and always examine the control effort.

Next: Modelling Physical Systems