PID Controller Example
Overview
This example demonstrates the use of the Digital Control Library (DCL) Proportional-Integral-Derivative (PID) controller. The PID controller is the most commonly used feedback controller in industrial applications for:
Precision motor control
Temperature control systems
Robotic control
Flight control systems
Industrial process control
Position and velocity servos
What the Example Does
The example:
Initializes a Series PID controller with test case-specific parameters
Processes control loop iterations with reference, feedback, and clamp inputs
Computes control output (uk) based on error dynamics
Compares computed outputs against expected reference values
Measures and reports execution performance in CPU cycles
Validates correctness by comparing results with an error tolerance
Expected Output
The example prints:
Total execution cycles for all iterations
Average execution cycles per iteration
Number of errors detected (should be 0 for PASS)
Individual failure messages if any output differs from expected value
Usage Notes
Customization
You can modify the example by:
Selecting different test cases via
PID_TESTCASEmacroAdjusting controller gains (Kp, Ki, Kd, Kr) in
PID_updateParams()Changing output limits (Umax, Umin)
Modifying sample period (T) for different control frequencies
Adjusting derivative filter bandwidth via
DCL_setPIDfilterBW()Modifying
NUM_ELEMENTSto process more or fewer samplesReplacing test data files in the
data/directorySwitching between Series and Parallel PID forms
External Connections
None required. This is a software-only computational example.