Saturday, December 28, 2024

Understanding PID Control in SWMM5 for a Weir

Understanding PID Control in SWMM5 for a Weir

  • PID stands for Proportional-Integral-Derivative. It's a widely used control loop feedback mechanism that continuously calculates an "error" value as the difference between a desired setpoint and a measured process variable.1 The controller then applies a correction based on proportional, integral, and derivative terms.
  • Proportional (P): The output is proportional to the current error. A larger error produces a larger correction. kp is the gain.
  • Integral (I): The output is proportional to the accumulated error over time. This helps to eliminate steady-state errors (the difference between the setpoint and the actual value that might persist with P control alone). ki is the gain and is often expressed as an integral time (in minutes or seconds), representing the time it would take for the integral term to equal the proportional term for a constant error.
  • Derivative (D): The output is proportional to the rate of change of the error. This anticipates future error and dampens oscillations. kd is the gain and is often expressed as a derivative time (in minutes or seconds), representing the time it would take for the derivative term to equal the proportional term for a linearly changing error.

The SWMM 5 PID Rule

The provided rule effectively implements PID control to adjust the crest height of WEIR WEIR1@82309c-15009c to maintain a depth of 3 feet at NODE 82309c. Let's break it down:

RULE PID_Weir
; the PID controller adjusts the weir height to have a
;      depth of 3 feet in Node 82309e
IF NODE 82309c DEPTH 3
THEN WEIR WEIR1@82309c-15009c SETTING = PID 10 -.01 -.01
;                                         kp ki   kd
PRIORITY 1
  • RULE PID_Weir: Defines the name of the rule.
  • IF NODE 82309c DEPTH 3: This is the condition that triggers the rule. The error is the difference between the current depth and the target depth of 3 feet.
  • THEN WEIR WEIR1@82309c-15009c SETTING = PID 10 -.01 -.01: This is the action. It sets the weir's SETTING (which likely represents the crest height relative to a datum or the degree of opening) based on the output of the PID function.
    • PID: This keyword indicates that a PID controller is being used.
    • 10 -.01 -.01: These are the PID parameters:
      • kp = 10: Proportional gain. A relatively high value, suggesting a strong response to the error.
      • ki = -0.01: Integral time (in minutes). A negative value is unusual in PID controllers and might lead to unexpected behavior or instability in this example. An integral time should almost always be positive. A very small value indicates a very strong integral action.
      • kd = -0.01: Derivative time (in minutes). A negative value is also unusual and could cause problems. A very small value represents a weak derivative action.
  • PRIORITY 1: Assigns a priority to the rule. Lower numbers indicate higher priority.

Analysis and Recommendations

  1. Negative ki and kd: The negative values for ki and kd are highly suspect. In most PID implementations, these values should be positive. Negative values could lead to instability and oscillations, as you observed. It is important to use positive ki and kd values or you get an unstable oscillation around the target depth.

  2. Tuning the PID Parameters: Finding the optimal PID parameters often requires experimentation and tuning. The goal is to achieve a quick response to changes in water level while minimizing overshoot (going beyond the target depth) and oscillations.

    • High kp: The kp of 10 might be too high, potentially causing overreactions and oscillations.
    • Low or Negative ki: Try increasing the integral time (make it less negative or positive) to reduce oscillations and help the system settle at the target depth. Start with a small positive value, like 0.1 or 1, and adjust. For example, ki of 10 means an integral time of 10 minutes.
    • Low or Negative kd: Increase the derivative time (make it less negative or positive) to dampen oscillations. Start with a small positive value, like 0.01 or 0.1, and adjust. For example, a kd of 5 means a derivative time of 5 minutes.
  3. Weir Setting Interpretation: The model assumes that the weir SETTING directly corresponds to the crest height adjustment. You should verify how the SETTING parameter is defined for your specific weir type in SWMM 5. The default setting is a fraction of fully open from 0 to 1.

Improved PID Rule (Example)

Here's an example of a revised rule with more typical PID parameter values:

RULE PID_Weir
IF NODE 82309c DEPTH 3
THEN WEIR WEIR1@82309c-15009c SETTING = PID 2 10 1
;                                         kp ki kd
PRIORITY 1
  • kp = 2: Reduced proportional gain to lessen the initial response.
  • ki = 10: Integral time set to 10 minutes (a positive value).
  • kd = 1: Derivative time set to 1 minute (a positive value).

Tuning Process:

  1. Start with the revised rule.
  2. Run the simulation and observe the water level at NODE 82309c.
  3. Adjust the parameters iteratively:
    • If the response is too slow: Increase kp slightly.
    • If there's overshoot or oscillations: Increase kd to dampen the response.
    • If the system doesn't settle exactly at 3 feet: Adjust ki (increase it to make the integral action stronger).
  4. Repeat steps 2 and 3 until you achieve satisfactory performance.

In conclusion, the provided example demonstrates the powerful capability of SWMM 5 to implement PID control for regulating hydraulic structures. However, careful attention must be paid to the PID parameters to ensure stability and achieve the desired control objectives. The unusual negative values for ki and kd in the original rule should be corrected, and the parameters should be tuned iteratively to optimize the system's performance. You also need to make sure the Weir Setting in the THEN statement has the correct units of either fraction open or crest height.

 

 

No comments:

SWMM5 Delphi GUI Dabout.pas Summary

 The Dabout.pas unit is part of the EPA SWMM (Storm Water Management Model) project and contains the logic for the "About" dialo...