A controller has a clock
A digital controller observes and updates at intervals while the physical plant keeps moving.
Compute one discrete integral update and explain what a held command means between samples.
The reference and feedback paths are defined. We now decide when a digital controller reads measurements and changes its command.
Review the previous lesson: Give tracking its own pathFirst, picture it
Imagine steering a cart after seeing a picture only every few moments. Between pictures you must keep the previous command. Longer gaps can make a once-gentle correction arrive too late.
Build the idea step by step
A digital controller reads a measurement, calculates a command, then waits for the next update. Holding the last command during that wait is called a zero-order hold. The physical motor continues to move. To approximate an integral, multiply each measured error by the time interval before adding it. Omitting this interval makes the effective controller depend on how often the code runs. Slower sampling can also add enough lag to change stability, so it is a design change rather than an animation setting.
Read the equations
Approximate the integral contribution by adding error times the sampling interval and integral gain. The plant keeps moving between updates even if the command is held.
What the symbols mean
- integral contribution at sample k, in actuator units
- error at that sample
- integral gain, input units per error unit per second
- time between controller updates, in seconds
- integer sample index
The motor lab changes the controller period only. Plot samples remain 20 ms apart and the physical integration step remains 5 ms. The cart controller and observer retain their fixed 20 ms design period. These three clocks serve different purposes.
Accumulate error for one second
Use constant normalized error 3, integral gain 2 volts per error-unit second, and sample period 0.1 seconds. Start the integral contribution at zero and assume no clipping.
Each update adds 0.6 volts.
Ten updates represent one second and add 6 volts. If the period is halved, each increment halves but there are twice as many updates. Omitting the period changes the controller when its clock changes.
More detail and model assumptions
Three clocks are not one clock
A physical motor evolves continuously. Its digital controller samples a measurement every Ts and holds one command between samples. The screen redraws on a separate schedule. In this Lab changing Ts changes the controller and its discrete frequency model; changing playback speed or dropping a display frame does not change the computed physics.
If Ts grows, the controller acts on older information for longer. The same numerical PID gains can then create a different response, so continuous-time intuition must be checked against the sampled loop. The Nyquist limit π/Ts bounds the frequencies represented without aliasing; it is not a suggested control bandwidth.
Test a timing assumption
Pin the 20 ms motor run and compare 10, 40 and 80 ms while keeping target, load and gains fixed. Read the time response and discrete Bode plot; the crossover and margin may change because both the sampled plant and controller depend on Ts. At 80 ms, the display can still look smooth because rendering interpolates a precomputed trace.
A real controller must also finish sensing and computation before its next update. This simulator models the selected sample/hold interval, not processor overruns, communication jitter or sensor quantization. Those are later implementation tests.
Connect the example to the lab
Pin a 20 ms motor run. Change only the controller period to 80 ms and then 10 ms; compare response, requested voltage and the discrete Bode curve.
Compare sample periodsMake a prediction before moving a control.
- PREDICTCan animation speed change physical stability?
- CHANGE ONE THINGPin a 20 ms run. Change playback to 2×, then change Ts to 80 ms at 1×.
- OBSERVECompare saved metrics and the discrete loop plots across the two changes.
- EXPLAINExplain which clock changed physics and which only changed viewing time.
Faster sampling cannot remove actuator limits or sensor noise. A chosen sample rate must also fit computation and the plant bandwidth.
Check your understanding+
What changes when only Ts changes in this motor lab?
Controller update and hold times, discrete PID terms and frequency analysis change; the continuous motor equations do not.Why the next lesson follows
The state now advances one sample at a time. Discrete poles describe whether those successive values shrink or grow.