Chapter 03 · Dynamics and feedback
Today in the field story
One problem, then the next
With feedback sign proven, the Cold-Storage Door Tuning can add three limited opinions: present error, accumulated bias, and changing error. Calculate one discrete update by hand, log P, I, and D separately, then reproduce it in the starter. Change only one gain at a time and keep units and sample period visible so copied ‘magic gains’ cannot enter the report.
- Why now
The mission needs an implementable controller whose internal cause is visible in every command.
- Ignore today
Ignore automated tuning and complex plant identification.
- Unlocks next
Controlled experiments on sampling, noise, delay, saturation, and recovery.
Understand
Build the physical picture first
A PID controller combines three limited opinions about error: P reacts to the error now, I accumulates a persistent bias, and D resists error changing too quickly.
The proportional term is Kp times current error. It acts like a software spring: a larger displacement from the setpoint requests a larger correction. Too little proportional action can feel weak; too much can overshoot or oscillate because the physical mechanism and measurement arrive after the command.
The derivative term uses the rate of error change. With a fixed setpoint it behaves like damping, opposing rapid motion toward or away from the goal. A discrete controller estimates that rate from two samples, so noisy measurements or an incorrect sample interval can make the derivative contribution jump sharply.
The integral term sums error over time. It can remove a persistent offset caused by gravity, friction, or model bias, but it adds memory to the controller. If the actuator is already at its limit, that stored error can grow into windup and cause a long recovery or large overshoot.
PID gains carry units and belong to one defined signal path. Tune in simulation with a bounded command: verify sign and timing, start with P, add D only when damping is needed, and add I only for a measured persistent bias with anti-windup. A good feedforward model may remove the need for much integral action.
Words you need
Name each idea precisely
- Proportional term
A command contribution proportional to current error.
Physical example:A larger joint-angle error requests a larger restoring torque.
- Integral term
A command contribution based on accumulated error over time.
Physical example:A small gravity-caused arm error gradually builds enough correction to hold the target.
- Derivative term
A command contribution based on how quickly error changes.
Physical example:Like a door closer, it resists a rapid approach and reduces overshoot.
- Gain
A scale factor with units that converts an error quantity into a command contribution.
Physical example:A speed-loop Kp might convert m/s of error into volts.
- Discrete update
One controller calculation using samples separated by a declared time step.
Physical example:A loop recalculates every 0.05 s at 20 Hz.
Math, one line at a time
Work through today’s relationship
Prerequisite rescue · optionalChange over time and feedback
Velocity, acceleration, and control error explain whether a robot settles, overshoots, or becomes unsafe.
- Δx/Δt
- change in position divided by elapsed timeUnit: metres per second (m/s)
- e = target − measured
- control errorUnit: same unit as the target
- u
- bounded actuator commandUnit: device-specific
A wheel moves from 1 m to 1.6 m in 0.2 s, so Δx = 0.6 m.
Average velocity is 0.6/0.2 = 3 m/s.
If the target is 2 m and measured position is 1.6 m, error e = 0.4 m; a controller converts that error into a limited command.
A feedback loop resembles an event loop that checks state repeatedly, but a missed deadline changes physical motion, not just screen responsiveness.
Position changes by 0.5 m in 0.25 s. What is average velocity?
0.5/0.25 = 2 m/s.
A discrete PID step is
Here,
before output clamping.
Calculate one discrete PID update with units visible
In a simulation, current error e=3 cm, previous error=2 cm, sample time Δt=0.1 s, stored integral before this step=0.4 cm·s, Kp=2 command/cm, Ki=1 command/(cm·s), and Kd=0.5 command·s/cm.
Compute P: 2×3=6 command units.
Update accumulated error: 0.4+(3×0.1)=0.7 cm·s.
Compute I: 1×0.7=0.7 command units.
Estimate error rate: (3-2)/0.1=10 cm/s.
Compute D: 0.5×10=5 command units.
Add the three requested contributions: 6+0.7+5=11.7 command units.
Mark this as an unconstrained request; a separate output limit must be applied before any actuator.
The requested PID output is 11.7 command units, with P=6, I=0.7, and D=5 shown separately.
Log each term independently; a surprisingly large D value or growing I value becomes visible immediately.
Physical examples
Where this appears in real life
Door closer as P plus D intuition
A spring pulls a door toward closed based on how far it is open, while the hydraulic closer resists fast motion.
The spring resembles proportional restoring action; the damper resembles derivative action for a fixed target.
Vertical arm holding a load
A joint can stop slightly below its setpoint because gravity requires continuing effort even when motion has stopped.
Integral action may reduce the remaining offset, but model-based gravity feedforward can supply the known holding effort more directly.
Hands-on exercise
Make the idea observable
Create a simple spreadsheet or Python simulation of a value y that updates as y_next=y+0.1u, with setpoint 1.0 and command clamped to [-2,2].
Run ten steps with Kp=0.5, Ki=0, Kd=0 and record y, error, P, and command.
Increase Kp to 2.0 and compare approach speed and overshoot.
Add Kd=0.2 while keeping Ki=0 and compare the response.
Introduce a small constant opposing bias in the simulated plant and observe steady-state error.
Add a small Ki with an integral bound and compare the offset and overshoot.
Plot setpoint, measurement, and applied command; change only one gain per trial.
P changes corrective strength, D changes damping, and I can remove bias while also storing error and increasing overshoot risk.
The notebook contains comparable plots, the exact gains and time step, and a written reason for each observed change.
Build today
Control a simulated pendulum or cart-pole; log setpoint, error, command, saturation, and settling time.
Evidence to save
DONE when the integrated “Implement and tune a PID controller” path is observable, cancelable, and leaves the prior baseline reproducible.
Common mistakes
Catch the wrong mental model
Tuning all three gains at once.
Verify sign and timing, establish a P baseline, then add one justified term at a time and compare fixed tests.
Treating gains as unitless magic numbers.
Record measurement unit, command unit, and time base; changing units changes the numeric gains.
Adding integral for every tracking problem.
Use it only for measured persistent bias and protect it from windup; prefer accurate feedforward for known physics when available.
Job connection
How this becomes employable evidence
Implement and review a velocity or joint controller whose logs expose setpoint, measurement, P/I/D contributions, clamped output, and loop period.
Relevant target roles
- Robotics Software Engineer — ROS 2 / AMR
- Robotics Application / ROS 2 Integration Engineer
Chapter 03 interview drill
Interview questions: Implement and tune a PID controller
Practise a 60–90 second answer: define the idea, connect it to a physical robot, state assumptions, frames, and units when relevant, then finish with the failure signal or evidence you would inspect.
Primary interview scenario
A controller oscillates after Kp was increased. Describe a safe tuning investigation and explain when you would add D, I, or feedforward.
Answer shape: clarify the situation → trace the physical and software path → test the most likely boundaries → name the evidence that would confirm the result.
Technical follow-up questions
Q1Which PID term responds directly to current error?
The proportional term responds directly: its contribution is K_p e(t), so it changes immediately when the current error changes.
Q2Why can the derivative contribution jump on noisy data?
It divides the difference between nearby error samples by the sample time, so small measurement changes can become a large estimated rate.
Q3What must be stated when sharing PID gains?
The controller form, signal and command units, sample period, derivative/integral implementation, and output limits.