A PID controller reads a (noisy) position sensor, compares it to the target, and drives a motor to correct the error — the same control loop used in insulin pumps, prosthetic joints, and surgical-robot actuators.
measured = position + noise·rand()
error = target − measured
force = Kp·error + Kd·d(error)/dt − load·friction·sign(velocity)
accel = force / mass ; velocity += accel·dt ; position += velocity·dt
- Target position — the setpoint the actuator is commanded to reach.
- Kp / Kd gains — proportional gain drives speed toward the target; derivative gain damps oscillation and overshoot.
- Sensor noise — random error added to the position sensor reading, shown as a flickering ghost marker beside the true rod.
- Tissue load resistance — friction-like opposing force representing resistance from surrounding tissue or a joint.
- Random step test — jumps the target instantly to a new value so you can watch the classic step-response overshoot/settle behaviour.
Real-world relevance: getting Kp/Kd tuning right is exactly what separates a smooth prosthetic knee or a stable insulin-delivery actuator from one that oscillates or overshoots dangerously.