pub struct PidGains {
pub kp: f64,
pub ki: f64,
pub kd: f64,
pub integral_max: f64,
}Expand description
PID controller gains for frame time regulation.
§Mathematical Model
Let e_t = frame_time_t − target be the error signal at frame t.
The PID control output is:
u_t = Kp * e_t + Ki * Σ_{j=0..t} e_j + Kd * (e_t − e_{t−1})The output u_t maps to degradation level adjustments:
u_t > degrade_threshold→ degrade one level (if e-process permits)u_t < -upgrade_threshold→ upgrade one level- otherwise → hold current level
§Gain Selection Rationale
For a 16ms target (60fps):
Kp = 0.5: Proportional response. Moderate gain avoids oscillation while still reacting to single-frame overruns.Ki = 0.05: Integral term. Low gain eliminates steady-state error over ~20 frames without integral windup issues.Kd = 0.2: Derivative term. Provides anticipatory damping to reduce overshoot when frame times are trending upward.
§Stability Analysis
For a first-order plant model G(s) = 1/(τs + 1) with τ ≈ 1 frame:
- Phase margin > 45° with these gains
- Gain margin > 6dB
- Settling time ≈ 8-12 frames for a step disturbance
Anti-windup: integral term is clamped to [-integral_max, +integral_max]
to prevent runaway accumulation during sustained overload.
Fields§
§kp: f64Proportional gain. Reacts to current error magnitude.
ki: f64Integral gain. Eliminates steady-state error over time.
kd: f64Derivative gain. Dampens oscillations by reacting to error rate.
integral_max: f64Maximum absolute value of the integral accumulator (anti-windup).
Trait Implementations§
impl StructuralPartialEq for PidGains
Auto Trait Implementations§
impl Freeze for PidGains
impl RefUnwindSafe for PidGains
impl Send for PidGains
impl Sync for PidGains
impl Unpin for PidGains
impl UnsafeUnpin for PidGains
impl UnwindSafe for PidGains
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more