DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
control.h File Reference

Closed-loop control law (DETWS_ENABLE_CONTROL) - a zero-heap PID controller plus a handful of inline control-law primitives, for driving an actuator toward a setpoint. More...

#include "ServerConfig.h"

Go to the source code of this file.

Detailed Description

Closed-loop control law (DETWS_ENABLE_CONTROL) - a zero-heap PID controller plus a handful of inline control-law primitives, for driving an actuator toward a setpoint.

The PID is the textbook parallel form with the corrections that matter on real hardware:

  • derivative-on-measurement (the derivative acts on the measurement, not the error, so a step change in the setpoint does not produce a "derivative kick"),
  • an optional single-pole low-pass on the derivative (measurement noise otherwise dominates the D term),
  • output clamping to the actuator's range, and
  • anti-windup by conditional integration (the integrator is frozen while the output is saturated and integrating would push it deeper into the rail, so it never winds up past what the actuator can deliver), plus a hard integral clamp as a secondary bound,
  • a feed-forward term (kff * setpoint) for the part of the command known in advance.

pid_update() is defined inline (below): the whole law folds into the caller with no function- call overhead, and on the ESP32 / ESP32-S3 the single-precision-float math maps to the FPU (single-cycle add/mul + madd.s fused multiply-add, never the soft-float double path). Put your control loop in IRAM if you need deterministic latency free of flash-cache stalls.

Pure float arithmetic - no heap, no <math.h>. Pair it with a plant it can command (a CiA 402 drive via services/cia402, a dshot ESC, a heater PWM) and a sensor it can read back.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file control.h.