Skip to content
Physical AI
All experiments

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.

Loading simulation…

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

u(t)=Kp (x∗−x^(t−τ))−Kd x˙^(t−τ)u(t) = K_p\,\big(x^* - \hat{x}(t-\tau)\big) - K_d\,\hat{\dot x}(t-\tau)
F=clip⁡(u,−Fmax,Fmax)F = \operatorname{clip}(u, -F_{max}, F_{max})
mx¨=F+Fdist−μc sign⁡(x˙)−b x˙m\ddot{x} = F + F_{dist} - \mu_c\,\operatorname{sign}(\dot x) - b\,\dot x
x˙k+1=x˙k+x¨k Δt,xk+1=xk+x˙k+1 Δt\dot x_{k+1} = \dot x_k + \ddot x_k\,\Delta t, \quad x_{k+1} = x_k + \dot x_{k+1}\,\Delta t

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