Skip to content

Controller Setup and Tuning ​

Learn to implement and tune PID controllers for dissolved oxygen, wastage, chemical dosing, and other process variables in wastewater treatment simulation.

Overview ​

Process control automates plant operation by continuously adjusting manipulated variables (pumps, valves, dosing) to maintain setpoints. ErgoPlanner supports PID (Proportional-Integral-Derivative) control for dynamic simulation.

In this tutorial you'll learn:

  • PID controller fundamentals and applications
  • Dissolved oxygen (DO) control setup and tuning
  • Waste activated sludge (WAS) flow control for SRT
  • Chemical dosing controllers (ferric, alum, methanol)
  • Cascade control systems
  • Auto-tuning procedures
  • Control loop troubleshooting

Estimated Time: 60 minutes

Difficulty: Advanced

Prerequisites ​

  • Completed Dynamic-Simulation
  • Understanding of Biokinetic-Models
  • Basic knowledge of control theory (PID concepts)
  • Familiarity with process control terminology
  • Project configured for dynamic simulation

Step 1: PID Controller Fundamentals ​

1.1 What is PID Control? ​

A PID controller continuously calculates an error value as the difference between a desired setpoint and a measured process variable, then applies a correction based on proportional, integral, and derivative terms.

Control Equation:

u(t) = Kp×e(t) + Ki×∫e(t)dt + Kd×de(t)/dt

Where:
u(t) = control output (manipulated variable)
e(t) = error (setpoint - measurement)
Kp = proportional gain
Ki = integral gain
Kd = derivative gain

Control Actions:

  • Proportional (P): Responds to current error magnitude
  • Integral (I): Responds to accumulated past errors (eliminates offset)
  • Derivative (D): Responds to rate of error change (anticipates future trend)

1.2 PID Terms Explained ​

Proportional (Kp):

  • Effect: Immediate response proportional to error
  • Higher Kp: Faster response, but more overshoot
  • Too high: Oscillation or instability
  • Too low: Slow, sluggish response

Integral (Ki):

  • Effect: Eliminates steady-state offset
  • Higher Ki: Faster offset elimination, but more overshoot
  • Too high: Oscillation, "integral windup"
  • Too low: Persistent offset

Derivative (Kd):

  • Effect: Dampens oscillations, anticipates changes
  • Higher Kd: Less overshoot, but sensitive to noise
  • Too high: Amplifies measurement noise
  • Often set to 0 in wastewater applications due to noisy signals

Tip: Many wastewater controllers use PI (no derivative) due to noisy measurements from online sensors.

1.3 Common WWTP Control Applications ​

ApplicationManipulated VariableControlled VariableTypical Setpoint
DO ControlAir flow rate, blower speedDissolved oxygen1.5-2.5 mg/L
SRT ControlWAS flow rateSolids retention time8-15 days
Chemical DosingChemical pump speedMetal:P ratio, alkalinityVariable
RAS ControlRAS pump speedMLSS or sludge blanket3,000-4,000 mg/L
Nutrient ControlCarbon source dosingEffluent TN< 10 mg/L
pH ControlAcid/base dosingpH6.5-7.5

Step 2: Dissolved Oxygen Control ​

2.1 Why Control DO? ​

Maintaining proper DO is critical:

  • Too low (< 1 mg/L): Incomplete nitrification, poor treatment
  • Too high (> 3 mg/L): Energy waste, potential filamentous bulking
  • Optimal (1.5-2.5 mg/L): Complete nitrification with minimal energy

DO control adjusts aeration to maintain setpoint despite varying:

  • Influent load (diurnal, storm events)
  • Temperature (seasonal)
  • MLSS concentration

Energy Savings: Proper DO control can reduce aeration energy by 20-30%.

2.2 Configure DO Controller ​

  1. Click on Aeration Tank in your process diagram
  2. Navigate to "Control" tab in properties panel
  3. Click "Add Controller"
  4. Select controller type: "DO PID Controller"

Screenshot placeholder: Aeration tank properties with Control tab selected, showing "Add Controller" button and dropdown menu with DO PID Controller option.

2.3 DO Controller Configuration ​

Configure the basic settings:

SettingValueDescription
Controlled VariableDissolved Oxygen (S_O)What to measure
Setpoint2.0 mg/LDesired DO level
Manipulated VariableAir Flow RateWhat to adjust
Measurement Interval1 minuteHow often to sample
Control Interval5 minutesHow often to adjust

Note: Control interval should be 5-10× the measurement interval to avoid control chatter.

Screenshot placeholder: DO controller configuration panel showing dropdowns for controlled variable, manipulated variable, and numeric inputs for setpoint and intervals.

2.4 PID Tuning Parameters ​

Set initial PID parameters (conservative starting values):

ParameterInitial ValueUnitsTypical Range
Kp (Proportional)20%/mg/L10-100
Ki (Integral)0.5%/mg/L/min0.1-2.0
Kd (Derivative)0%·min/mg/L0-10 (often 0)
Output Min20%Minimum aeration
Output Max100%Maximum aeration

Initial Settings Rationale:

  • Kp = 20: Moderate proportional action
  • Ki = 0.5: Slow integral to avoid overshoot
  • Kd = 0: Disabled due to measurement noise
  • Min = 20%: Maintain minimum mixing
  • Max = 100%: Full blower capacity

Tip: Start conservative, then tune. Aggressive tuning can cause oscillations.

Screenshot placeholder: PID tuning parameter table with input fields for Kp, Ki, Kd, and output limits.

2.5 Run Dynamic Simulation with DO Control ​

  1. Configure dynamic influent (see Dynamic-Simulation)
  2. Set simulation duration: 7 days
  3. Enable DO controller: ☑ "Controller Active"
  4. Click "Run Simulation"

Monitor during simulation:

  • DO should track setpoint (2.0 mg/L)
  • Air flow will vary with load
  • Some offset and overshoot is normal initially

Screenshot placeholder: Dynamic simulation results showing two time-series charts: Top - DO setpoint (red dashed line at 2.0 mg/L) and actual DO (blue line tracking setpoint). Bottom - Airflow rate varying from 40-80%.

2.6 Evaluate Controller Performance ​

Assess control quality using metrics:

Setpoint Tracking:

  • Mean error should be near zero
  • Standard deviation < 0.3 mg/L indicates good control
  • Peak deviations < 0.5 mg/L acceptable

Response Time:

  • Time to reach setpoint after disturbance: < 30 minutes ideal
  • Overshoot: < 20% of disturbance magnitude

Energy Efficiency:

  • Air flow should vary smoothly (no chattering)
  • Average air flow should be close to optimal

Example Good Performance:

DO Statistics (Days 3-7):
- Mean: 2.02 mg/L (setpoint: 2.00)
- Std Dev: 0.18 mg/L
- Min: 1.65 mg/L
- Max: 2.38 mg/L
- Time in range (1.5-2.5): 94%

Tip: Evaluate performance after equilibration (day 3+), not the first 1-2 days.

2.7 Tune for Better Performance ​

If control is poor, adjust PID parameters:

Problem: Sluggish Response (slow to reach setpoint)

  • Cause: Kp too low, Ki too low
  • Solution: Increase Kp by 50% (e.g., 20 → 30)
  • Re-test and iterate

Problem: Oscillations (DO swings above/below setpoint)

  • Cause: Kp too high, Ki too high
  • Solution: Reduce Kp and Ki by 30%
  • Consider: Increase control interval (5 → 10 min)

Problem: Steady-State Offset (DO consistently above or below setpoint)

  • Cause: Ki too low or zero
  • Solution: Increase Ki gradually (0.5 → 0.8 → 1.0)

Problem: Rapid Fluctuations (chattering)

  • Cause: Control interval too short, Kd too high
  • Solution: Increase control interval, set Kd = 0

Screenshot placeholder: Side-by-side comparison charts: "Before Tuning" showing oscillating DO, "After Tuning" showing smooth tracking of setpoint.

2.8 Auto-Tuning Procedure ​

ErgoPlanner includes automated tuning:

  1. In controller configuration, click "Auto-Tune"
  2. Select tuning method:
    • Ziegler-Nichols: Classic method, may be aggressive
    • Cohen-Coon: Better for systems with delay
    • Lambda Tuning: Conservative, smooth control
  3. Auto-tuning runs a test simulation:
    • Applies step changes to manipulated variable
    • Observes process response
    • Calculates optimal PID parameters
  4. Review suggested parameters
  5. Click "Apply" to use them

Screenshot placeholder: Auto-tune dialog showing method selection radio buttons and progress: "Testing step response... 45% complete". Preview chart shows DO response to step input.

Typical Auto-Tune Results:

Recommended Parameters (Lambda Tuning):
Kp: 25.3
Ki: 0.67
Kd: 0.0

Process Characteristics Identified:
- Process Gain: 1.85
- Time Constant: 8.3 min
- Dead Time: 2.1 min

Warning: Auto-tune parameters are starting points. Fine-tune based on actual performance.

Step 3: Waste Activated Sludge (WAS) Control ​

3.1 WAS Control Objectives ​

Control WAS flow to maintain:

  • SRT (Solids Retention Time): Target 10-15 days for nitrification
  • MLSS: Target 3,000-4,000 mg/L in reactor
  • Sludge Inventory: Prevent excessive accumulation

Control Strategy: Adjust WAS flow based on measured MLSS and target SRT.

3.2 Configure WAS Controller ​

  1. Click on WAS Pump in process diagram
  2. Control tab → "Add Controller"
  3. Select "SRT PID Controller"

Configuration:

SettingValue
Controlled VariableSRT (calculated)
Setpoint10 days
Manipulated VariableWAS Flow Rate
Measurement Interval1 hour
Control Interval6 hours

Note: SRT control is slower than DO control. Adjust every 6-24 hours, not every few minutes.

PID Parameters (conservative):

ParameterValueNotes
Kp50m³/day per day SRT error
Ki2Eliminates offset
Kd0Not needed
Min Flow50m³/day
Max Flow500m³/day

3.3 Alternative: MLSS Control ​

Instead of SRT, control MLSS directly:

Configuration:

  • Controlled Variable: MLSS in reactor
  • Setpoint: 3,500 mg/L
  • Manipulated Variable: WAS Flow Rate

Advantage: Direct measurement, faster response Disadvantage: Doesn't account for influent variations

Choice: Use SRT control for better process stability, MLSS control for simpler plants or when SRT measurement is unreliable.

Screenshot placeholder: WAS controller configuration showing two options: "SRT Control" and "MLSS Control" radio buttons with respective configuration panels.

Step 4: Chemical Dosing Control ​

4.1 Ferric Chloride Dosing for Phosphorus ​

Control ferric chloride (FeCl₃) dosing to achieve target effluent phosphorus.

Control Strategy: Maintain molar ratio Fe:P = 1.5-2.0

  1. Click on Chemical Dosing Pump (ferric)
  2. Control tab → "Add Controller"
  3. Select "Ratio Controller"

Configuration:

SettingValue
Controlled VariableFe:P Molar Ratio
Setpoint1.8 (molar ratio)
Measured VariablesInfluent TP, Influent Flow
Manipulated VariableFeCl₃ Dose (mg/L)
Control Interval15 minutes

Calculation:

FeCl₃ dose (mg/L) = TP × (MW_Fe/MW_P) × Ratio × (MW_FeCl₃/MW_Fe)
                   = TP × 1.8 × 1.8 × 2.9
                   = TP × 9.4 mg FeCl₃/mg P

For TP = 8 mg/L: FeCl₃ dose = 8 × 9.4 = 75 mg/L

Tip: Ratio control is feedforward - it responds to influent changes before they affect effluent.

4.2 Methanol Dosing for Denitrification ​

Control methanol dosing to achieve target effluent nitrate.

Feedback Control:

SettingValue
Controlled VariableEffluent NO₃-N
Setpoint8 mg/L
Manipulated VariableMethanol Dose
PID ParametersKp=5, Ki=0.3, Kd=0

Typical Dose: 3-4 mg methanol per mg NO₃-N removed

Feedforward Enhancement:

  • Measure influent TKN
  • Estimate NO₃ produced = TKN - Effluent NH₄
  • Pre-adjust methanol dose based on prediction

Screenshot placeholder: Chemical dosing controller showing feedforward and feedback components: Influent TKN measurement feeds into dose calculation, effluent NO3 feedback trims dose via PID.

Step 5: Cascade Control ​

5.1 What is Cascade Control? ​

Cascade control uses two controllers in series:

  • Primary (Master): Controls final objective (e.g., effluent NH₄)
  • Secondary (Slave): Controls intermediate variable (e.g., DO)

Advantage: Faster disturbance rejection, better performance

Example: Effluent NH₄ Control with DO Cascade

Primary: Effluent NH₄-N → adjusts DO setpoint Secondary: DO → adjusts air flow

This allows DO to respond quickly to load changes, while NH₄ provides overall guidance.

5.2 Configure Cascade Control ​

Step 1: Set up DO Controller (Secondary)

  1. Configure DO PID controller (as in Step 2)
  2. Set initial DO setpoint: 2.0 mg/L
  3. Enable "Setpoint from Master Controller" checkbox

Step 2: Set up NH₄ Controller (Primary)

  1. Click on process Effluent stream
  2. Control tab → "Add Controller"
  3. Select "NH4 Cascade Controller"

Configuration:

SettingValue
Controlled VariableEffluent NH₄-N
Setpoint1.0 mg/L
Manipulated VariableDO Setpoint (to secondary)
PID ParametersKp=0.5, Ki=0.05, Kd=0
DO Setpoint Range1.0 - 4.0 mg/L

How it works:

  • If Eff NH₄ > 1.0: Increase DO setpoint (more aeration)
  • If Eff NH₄ < 1.0: Decrease DO setpoint (save energy)
  • DO controller maintains whatever setpoint master specifies

Screenshot placeholder: Cascade control diagram showing two control loops: Primary (NH4 controller) outputs DO setpoint, Secondary (DO controller) adjusts airflow to track that setpoint.

5.3 Tune Cascade System ​

Tuning Sequence (always tune from inside out):

  1. First: Tune DO controller (secondary) with fixed setpoint
  2. Ensure DO control is stable and responsive
  3. Second: Tune NH₄ controller (primary) with DO cascade
  4. Use much slower integral time for primary (10-20× secondary)

Primary Controller Guidelines:

  • Kp low (0.3-1.0): Primary should be slow and smooth
  • Ki very low (0.01-0.1): Prevent windup and oscillations
  • Control interval 30-60 min: Much slower than secondary (5 min)

Expected Performance:

  • DO tracks varying setpoint smoothly (1.5-2.5 mg/L typical range)
  • Effluent NH₄ maintained near setpoint (< 1.5 mg/L)
  • Energy savings vs fixed DO: 15-25%

Step 6: Advanced Control Topics ​

6.1 Anti-Windup ​

Problem: During constraints (e.g., max airflow), integral term continues to accumulate, causing overshoot when constraint releases.

Solution: Enable anti-windup

  1. In controller configuration, check ☑ "Enable Anti-Windup"
  2. Select method:
    • Clamping: Stop integrator when output saturates
    • Back-Calculation: Reduce integral based on saturation

Screenshot placeholder: Controller advanced settings showing anti-windup options with Clamping/Back-Calculation radio buttons.

6.2 Feedforward Control ​

Complement feedback PID with feedforward compensation:

Example: DO Control with Flow Feedforward

  • Measure influent flow
  • When flow increases → anticipate higher oxygen demand
  • Immediately increase airflow (before DO drops)
  • PID provides final trimming

Configuration:

Total Airflow = Feedforward + PID Output

Feedforward = K_ff × (Flow - Nominal Flow)
K_ff = 0.5 m³ air/m³/day flow

If Flow increases from 10,000 to 14,000 m³/day:
FF increases by 0.5 × 4,000 = 2,000 m³ air/day

6.3 Gain Scheduling ​

Change PID parameters based on operating conditions:

Example: DO Control Gain Scheduling

At low MLSS (2,000 mg/L): Higher Kp needed (faster response) At high MLSS (4,000 mg/L): Lower Kp needed (slower process)

Configuration:

Kp = Kp_base × (MLSS_nominal / MLSS_actual)

If MLSS_nominal = 3,500, Kp_base = 20:
At MLSS = 2,500: Kp = 20 × (3500/2500) = 28
At MLSS = 4,500: Kp = 20 × (3500/4500) = 15.6

Step 7: Troubleshooting Control Issues ​

7.1 Common Problems ​

SymptomLikely CauseSolution
Persistent oscillationKp or Ki too highReduce by 30-50%
Slow to reach setpointKp too lowIncrease by 50%
Steady offsetKi too low or zeroIncrease Ki
Chattering (rapid changes)Control interval too shortIncrease to 5-10× measurement
Overshoot on step changeKp too high, no derivativeReduce Kp, consider adding Kd
Controller saturates oftenActuator too smallIncrease pump/blower capacity
Erratic behaviorMeasurement noiseFilter signal, increase control interval

7.2 Debugging Controllers ​

Check Configuration:

  1. Verify controlled variable is correct (e.g., DO sensor location)
  2. Confirm manipulated variable has authority (pump has capacity)
  3. Check setpoint is achievable (not asking for DO=5 with limited air)
  4. Verify measurement and control intervals are reasonable

Check Dynamic Response:

  1. Plot controlled variable and manipulated variable vs time
  2. Look for correlation: when manipulated variable changes, does controlled variable respond?
  3. Estimate time lag: How long from action to response?

Check for Constraints:

  1. Is manipulated variable often at min or max limit?
  2. If so, controller can't do more - need bigger actuator
  3. Check if constraints are realistic

Screenshot placeholder: Debugging dashboard showing three time-series plots stacked: 1) Controlled variable (DO) with setpoint, 2) Manipulated variable (Airflow), 3) Controller output before limits. Highlights show constraint periods.

7.3 Validating Control Performance ​

Compare controlled vs uncontrolled scenarios:

Run 1: No Control (fixed airflow) Run 2: With PID Control

Compare:

MetricNo ControlWith ControlImprovement
Avg Eff NH₄1.8 mg/L0.9 mg/L50% reduction
DO Std Dev0.8 mg/L0.2 mg/L75% reduction
Avg Airflow2,500 m³/day2,100 m³/day16% energy savings
Permit Violations12% of time0% of time100% reduction

Conclusion: Control significantly improves performance and reduces energy.

Step 8: Case Study - Full Plant Control ​

8.1 Multi-Loop Control System ​

Typical WWTP with integrated control:

Loops:

  1. DO Control: Aeration basin
  2. RAS Control: Maintain MLSS
  3. WAS Control: Maintain SRT
  4. Chemical Dosing: Ferric for phosphorus
  5. pH Control: Lime dosing if needed

8.2 Control Interaction ​

Controllers can interact (one affects another):

Example: WAS control changes MLSS → affects oxygen demand → DO controller must compensate

Best Practices:

  • Tune loops independently first
  • Then test together for interactions
  • Adjust tuning if necessary (typically slow down faster loops)
  • Prioritize critical loops (DO > WAS > pH)

8.3 Simulate 30-Day Operation ​

Scenario: Storm event on day 7, normal operation otherwise

Results with Full Control:

  • All setpoints maintained within 10%
  • No permit violations
  • Energy use reduced 18% vs no control
  • Chemical usage optimized to actual need

Screenshot placeholder: 30-day simulation results showing multiple controlled variables (DO, SRT, MLSS, pH) all tracking setpoints through normal and storm conditions.

Summary ​

You've learned to:

  • ✓ Understand PID control fundamentals
  • ✓ Configure and tune DO controllers
  • ✓ Set up WAS control for SRT management
  • ✓ Implement chemical dosing control
  • ✓ Build cascade control systems
  • ✓ Apply advanced techniques (anti-windup, feedforward, gain scheduling)
  • ✓ Troubleshoot and validate control performance

Common Issues ​

IssueSolution
Which variables to control?Start with DO, then add WAS/SRT, then chemical dosing
How to tune PID?Use auto-tune for starting point, then manual fine-tuning
Oscillations after tuningReduce Kp and Ki by 30-50%
Controller doesn't eliminate offsetIncrease Ki (integral gain)
Control too aggressiveIncrease control interval, reduce gains

Next Steps ​

Continue learning:

Advanced topics:

  • Advanced-Control - MPC, fuzzy logic, adaptive control
  • Advanced-Solvers - Numerical methods for stiff control systems

Last updated: December 2025Tutorial difficulty: AdvancedEstimated completion time: 60 minutes