libstp
Robotics library for Botball
Loading...
Searching...
No Matches
libstp::foundation::PidConfig Struct Reference

#include <pid.hpp>

Public Member Functions

 PidConfig ()=default
 PidConfig (double kp, double ki, double kd, double integral_max=10.0, double integral_deadband=0.01, double derivative_lpf_alpha=0.1, double output_min=-10.0, double output_max=10.0)
 PidConfig (const PidGains &g)

Public Attributes

double kp {1.0}
double ki {0.0}
double kd {0.0}
double integral_max {10.0}
double integral_min {std::numeric_limits<double>::quiet_NaN()}
double integral_deadband {0.01}
 Error magnitude below which the integrator ignores the sample.
double derivative_lpf_alpha {0.1}
 IIR weight on new derivative samples; clamped to [0, 1] at runtime.
double output_min {-10.0}
double output_max {10.0}

Detailed Description

Full PID configuration including anti-windup, derivative filtering, and output limits.

Units: error and the controller output are in whatever units the caller chose. PidController is unit-agnostic — pass it errors in rad/s, m, or normalised speed-scale, and the same units come back as output. The defaults below are sized for the legacy "drive in normalised [-1, 1] command space" use case from libstp; new integrations should override them.

Defaults rationale:

  • kp = 1.0, ki = 0, kd = 0 — proportional-only baseline; the user is expected to tune the gains, not inherit them.
  • integral_max = 10.0 — integrator clamp in output units. The default assumes output is roughly bounded to ±10 (matches output_min/max below). If your output range is normalised speed ([-1, 1]), set this to ~1.0 instead, or the integrator can take seconds to recover from saturation.
  • integral_deadband = 0.01 — error magnitudes below this don't accumulate into the integrator. In the legacy "normalised speed" convention this is 1% of full output.
  • derivative_lpf_alpha = 0.1 — IIR weight on the new derivative sample (0 = use only history, 1 = no filter). 0.1 corresponds to a ~10-sample moving-average response, suitable for ~10 ms control loops with noisy feedback.
  • output_min/max = ±10 — output saturation in caller units. Override when feeding a downstream controller with a different scale.

Definition at line 35 of file pid.hpp.

Constructor & Destructor Documentation

◆ PidConfig() [1/3]

libstp::foundation::PidConfig::PidConfig ( )
default

◆ PidConfig() [2/3]

libstp::foundation::PidConfig::PidConfig ( double kp,
double ki,
double kd,
double integral_max = 10.0,
double integral_deadband = 0.01,
double derivative_lpf_alpha = 0.1,
double output_min = -10.0,
double output_max = 10.0 )
inline

Definition at line 53 of file pid.hpp.

◆ PidConfig() [3/3]

libstp::foundation::PidConfig::PidConfig ( const PidGains & g)
inline

Definition at line 64 of file pid.hpp.

Member Data Documentation

◆ derivative_lpf_alpha

double libstp::foundation::PidConfig::derivative_lpf_alpha {0.1}

IIR weight on new derivative samples; clamped to [0, 1] at runtime.

Definition at line 47 of file pid.hpp.

◆ integral_deadband

double libstp::foundation::PidConfig::integral_deadband {0.01}

Error magnitude below which the integrator ignores the sample.

Definition at line 46 of file pid.hpp.

◆ integral_max

double libstp::foundation::PidConfig::integral_max {10.0}

Upper integrator clamp, in output units.

Definition at line 40 of file pid.hpp.

◆ integral_min

double libstp::foundation::PidConfig::integral_min {std::numeric_limits<double>::quiet_NaN()}

Lower integrator clamp, in output units. NaN (the default) means "mirror the upper clamp", i.e. clamp to [-integral_max, integral_max] — the classic symmetric anti-windup. Set it explicitly to make the windup band asymmetric (e.g. integral_min=0 for a one-sided integrator).

Definition at line 45 of file pid.hpp.

◆ kd

double libstp::foundation::PidConfig::kd {0.0}

Definition at line 39 of file pid.hpp.

◆ ki

double libstp::foundation::PidConfig::ki {0.0}

Definition at line 38 of file pid.hpp.

◆ kp

double libstp::foundation::PidConfig::kp {1.0}

Definition at line 37 of file pid.hpp.

◆ output_max

double libstp::foundation::PidConfig::output_max {10.0}

Definition at line 49 of file pid.hpp.

◆ output_min

double libstp::foundation::PidConfig::output_min {-10.0}

Definition at line 48 of file pid.hpp.


The documentation for this struct was generated from the following file:
  • /home/runner/work/raccoon-lib/raccoon-lib/modules/libstp-foundation/include/foundation/pid.hpp