Perception–action feedback loop
How sensing, observation, control, actuation and the physical environment form a closed loop, and what happens when the loop is broken, delayed or noisy.
What it demonstrates
How sensing, observation, control, actuation and the physical environment form a closed loop, and what happens when the loop is broken, delayed or noisy.
How it works
A 1 kg point mass slides on a rail with dry (Coulomb) and viscous friction. Every 2 ms the simulated sensor measures its position with Gaussian noise and timestamps the reading. The controller only receives the reading from `latency` seconds ago, as a real robot would after sensing, filtering and bus transmission.
A proportional-derivative (PD) controller converts the position error into a force command. The actuator clips the command to ±6 N, and Newton's second law (with friction and any push you apply) is integrated with semi-implicit Euler. With the loop open, the controller sends a fixed command and ignores the sensors.
Adjustable parameters
- Closed / open loop
- Target position (−1 to 1 m)
- Proportional gain Kp (0–80 N/m)
- Damping gain Kd (0–20 N·s/m)
- Sensor noise σ (0–5 cm)
- Latency (0–250 ms)
- External push (25 N for 80 ms)
Known limitations
- One degree of freedom. Real robots have many coupled joints.
- The latency is a pure delay. Real systems also have jitter and occasional dropped messages.
- Friction uses a simple Coulomb + viscous model with a crude stiction band.
Equations
Core update rule
// One 2 ms tick of the loop (lib/sim/feedback.ts)
buffer.push({ t, x: x + noise * gaussian() }); // 1. sense
while (buffer[1]?.t <= t - latency) buffer.shift();
const obs = buffer[0].x; // 2. observe (delayed)
const u = closedLoop
? kp * (target - obs) - kd * obsVel // 3. decide
: openLoopForce;
const F = clamp(u, -maxForce, maxForce); // 4. actuate
const a = (F + disturbance + friction(v, F)) / mass; // 5. physics
v += a * dt; // semi-implicit Euler
x += v * dt;Explained in Chapter 1: Physical AI