Appearance
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 gainControl 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
| Application | Manipulated Variable | Controlled Variable | Typical Setpoint |
|---|---|---|---|
| DO Control | Air flow rate, blower speed | Dissolved oxygen | 1.5-2.5 mg/L |
| SRT Control | WAS flow rate | Solids retention time | 8-15 days |
| Chemical Dosing | Chemical pump speed | Metal:P ratio, alkalinity | Variable |
| RAS Control | RAS pump speed | MLSS or sludge blanket | 3,000-4,000 mg/L |
| Nutrient Control | Carbon source dosing | Effluent TN | < 10 mg/L |
| pH Control | Acid/base dosing | pH | 6.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
- Click on Aeration Tank in your process diagram
- Navigate to "Control" tab in properties panel
- Click "Add Controller"
- 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:
| Setting | Value | Description |
|---|---|---|
| Controlled Variable | Dissolved Oxygen (S_O) | What to measure |
| Setpoint | 2.0 mg/L | Desired DO level |
| Manipulated Variable | Air Flow Rate | What to adjust |
| Measurement Interval | 1 minute | How often to sample |
| Control Interval | 5 minutes | How 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):
| Parameter | Initial Value | Units | Typical Range |
|---|---|---|---|
| Kp (Proportional) | 20 | %/mg/L | 10-100 |
| Ki (Integral) | 0.5 | %/mg/L/min | 0.1-2.0 |
| Kd (Derivative) | 0 | %·min/mg/L | 0-10 (often 0) |
| Output Min | 20 | % | Minimum aeration |
| Output Max | 100 | % | 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
- Configure dynamic influent (see Dynamic-Simulation)
- Set simulation duration: 7 days
- Enable DO controller: ☑ "Controller Active"
- 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:
- In controller configuration, click "Auto-Tune"
- Select tuning method:
- Ziegler-Nichols: Classic method, may be aggressive
- Cohen-Coon: Better for systems with delay
- Lambda Tuning: Conservative, smooth control
- Auto-tuning runs a test simulation:
- Applies step changes to manipulated variable
- Observes process response
- Calculates optimal PID parameters
- Review suggested parameters
- 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 minWarning: 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
- Click on WAS Pump in process diagram
- Control tab → "Add Controller"
- Select "SRT PID Controller"
Configuration:
| Setting | Value |
|---|---|
| Controlled Variable | SRT (calculated) |
| Setpoint | 10 days |
| Manipulated Variable | WAS Flow Rate |
| Measurement Interval | 1 hour |
| Control Interval | 6 hours |
Note: SRT control is slower than DO control. Adjust every 6-24 hours, not every few minutes.
PID Parameters (conservative):
| Parameter | Value | Notes |
|---|---|---|
| Kp | 50 | m³/day per day SRT error |
| Ki | 2 | Eliminates offset |
| Kd | 0 | Not needed |
| Min Flow | 50 | m³/day |
| Max Flow | 500 | m³/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
- Click on Chemical Dosing Pump (ferric)
- Control tab → "Add Controller"
- Select "Ratio Controller"
Configuration:
| Setting | Value |
|---|---|
| Controlled Variable | Fe:P Molar Ratio |
| Setpoint | 1.8 (molar ratio) |
| Measured Variables | Influent TP, Influent Flow |
| Manipulated Variable | FeCl₃ Dose (mg/L) |
| Control Interval | 15 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 PFor 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:
| Setting | Value |
|---|---|
| Controlled Variable | Effluent NO₃-N |
| Setpoint | 8 mg/L |
| Manipulated Variable | Methanol Dose |
| PID Parameters | Kp=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)
- Configure DO PID controller (as in Step 2)
- Set initial DO setpoint: 2.0 mg/L
- Enable "Setpoint from Master Controller" checkbox
Step 2: Set up NH₄ Controller (Primary)
- Click on process Effluent stream
- Control tab → "Add Controller"
- Select "NH4 Cascade Controller"
Configuration:
| Setting | Value |
|---|---|
| Controlled Variable | Effluent NH₄-N |
| Setpoint | 1.0 mg/L |
| Manipulated Variable | DO Setpoint (to secondary) |
| PID Parameters | Kp=0.5, Ki=0.05, Kd=0 |
| DO Setpoint Range | 1.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):
- First: Tune DO controller (secondary) with fixed setpoint
- Ensure DO control is stable and responsive
- Second: Tune NH₄ controller (primary) with DO cascade
- 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
- In controller configuration, check ☑ "Enable Anti-Windup"
- 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/day6.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.6Step 7: Troubleshooting Control Issues
7.1 Common Problems
| Symptom | Likely Cause | Solution |
|---|---|---|
| Persistent oscillation | Kp or Ki too high | Reduce by 30-50% |
| Slow to reach setpoint | Kp too low | Increase by 50% |
| Steady offset | Ki too low or zero | Increase Ki |
| Chattering (rapid changes) | Control interval too short | Increase to 5-10× measurement |
| Overshoot on step change | Kp too high, no derivative | Reduce Kp, consider adding Kd |
| Controller saturates often | Actuator too small | Increase pump/blower capacity |
| Erratic behavior | Measurement noise | Filter signal, increase control interval |
7.2 Debugging Controllers
Check Configuration:
- Verify controlled variable is correct (e.g., DO sensor location)
- Confirm manipulated variable has authority (pump has capacity)
- Check setpoint is achievable (not asking for DO=5 with limited air)
- Verify measurement and control intervals are reasonable
Check Dynamic Response:
- Plot controlled variable and manipulated variable vs time
- Look for correlation: when manipulated variable changes, does controlled variable respond?
- Estimate time lag: How long from action to response?
Check for Constraints:
- Is manipulated variable often at min or max limit?
- If so, controller can't do more - need bigger actuator
- 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:
| Metric | No Control | With Control | Improvement |
|---|---|---|---|
| Avg Eff NH₄ | 1.8 mg/L | 0.9 mg/L | 50% reduction |
| DO Std Dev | 0.8 mg/L | 0.2 mg/L | 75% reduction |
| Avg Airflow | 2,500 m³/day | 2,100 m³/day | 16% energy savings |
| Permit Violations | 12% of time | 0% of time | 100% 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:
- DO Control: Aeration basin
- RAS Control: Maintain MLSS
- WAS Control: Maintain SRT
- Chemical Dosing: Ferric for phosphorus
- 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
| Issue | Solution |
|---|---|
| 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 tuning | Reduce Kp and Ki by 30-50% |
| Controller doesn't eliminate offset | Increase Ki (integral gain) |
| Control too aggressive | Increase control interval, reduce gains |
Next Steps
Continue learning:
- Dynamic-Simulation - Advanced dynamic scenarios with control
- Multi-Scenario - Compare controlled vs uncontrolled operation
- Carbon-Footprint - Use control to reduce energy and emissions
- Performance-Tips - Optimize control for large models
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