PID Control in SCL
Kenneth Jensen
Automation, Integration, & Controls Engineer / Electrical Engineer / Power Coordinator / Drive Engineer
Introduction
PID control (Proportional, Integral, Derivative) is a fundamental control technique in automation. It allows for precise control of processes by reacting to rapid changes, sluggish operations, and adjusting control based on the difference between setpoints and feedbacks. In this article, we'll delve into the basics of PID control, how to implement it in SCL, and practical tips for tuning and troubleshooting.
Basics of PID Control
PID control works by continuously calculating an error value as the difference between a desired setpoint (SP) and a measured process variable (PV). The controller attempts to minimize this error by adjusting the control variable (CV) through three terms:
- Proportional (P): Reacts to the current error.
- Integral (I): Reacts to the accumulation of past errors.
- Derivative (D): Reacts to the rate of change of the error.
The combined effect of these three terms ensures that the PID controller can handle rapid changes, eliminate steady-state errors, and anticipate future errors.
Implementing a Basic PID Controller in SCL
Here’s a step-by-step guide to creating a basic PID controller in SCL:
Example: Basic PID Controller
FUNCTION_BLOCK FB_PIDController
VAR_INPUT
Setpoint : REAL; // Desired setpoint
ProcessVariable : REAL; // Current process variable
Kp : REAL; // Proportional gain
Ki : REAL; // Integral gain
Kd : REAL; // Derivative gain
TimeInterval : REAL; // Time interval for PID calculation
END_VAR
VAR_OUTPUT
ControlVariable : REAL; // Output control variable
END_VAR
VAR
Error : REAL; // Error between setpoint and process variable
Integral : REAL; // Integral term
Derivative : REAL; // Derivative term
PreviousError : REAL; // Previous error value
Output : REAL; // PID output
END_VAR
BEGIN
// Calculate error
Error := Setpoint - ProcessVariable;
// Calculate integral
Integral := Integral + (Error * TimeInterval);
// Calculate derivative
Derivative := (Error - PreviousError) / TimeInterval;
// Calculate PID output
Output := (Kp * Error) + (Ki * Integral) + (Kd * Derivative);
// Set control variable
ControlVariable := Output;
// Update previous error
PreviousError := Error;
END_FUNCTION_BLOCK
Tuning PID Parameters
Tuning PID parameters is crucial for optimal performance. Here’s how to approach tuning:
1. Calculate Initial Parameters: Start by calculating initial PID parameters based on the process.
2. Proportional Only: Begin with proportional control only. Adjust the proportional gain (Kp) until the system responds adequately.
3. Add Integral and Derivative: Gradually introduce the integral (Ki) and derivative (Kd) terms. Adjust them based on the system's behavior.
Practical Example: PID Control for Temperature Regulation
Temperature control is a common application for PID controllers. Here’s an example:
FUNCTION_BLOCK FB_TemperatureControl
VAR_INPUT
DesiredTemperature : REAL; // Desired temperature setpoint
CurrentTemperature : REAL; // Current temperature
Kp : REAL; // Proportional gain
Ki : REAL; // Integral gain
Kd : REAL; // Derivative gain
TimeInterval : REAL; // Time interval for PID calculation
END_VAR
VAR_OUTPUT
HeaterOutput : REAL; // Output to heater
END_VAR
VAR
Error : REAL; // Error between setpoint and temperature
Integral : REAL; // Integral term
Derivative : REAL; // Derivative term
PreviousError : REAL; // Previous error value
Output : REAL; // PID output
END_VAR
BEGIN
// Calculate error
Error := DesiredTemperature - CurrentTemperature;
// Calculate integral
Integral := Integral + (Error * TimeInterval);
// Calculate derivative
Derivative := (Error - PreviousError) / TimeInterval;
// Calculate PID output
Output := (Kp * Error) + (Ki * Integral) + (Kd * Derivative);
// Set heater output
HeaterOutput := Output;
// Update previous error
PreviousError := Error;
END_FUNCTION_BLOCK
领英推荐
Troubleshooting Common PID Control Issues
1. Derivative Too High: If the derivative term is too high, you may experience constant hunting. Reduce the derivative gain to stabilize the system.
2. Integral Windup: High integral gain can cause windup. Limit the output, reduce the integral term, or use external reset feedback to mitigate windup.
3. Oscillation and Sluggishness: Ensure the terms are properly adjusted to find the balance between oscillation and sluggish behavior.
Real-World Application: Smoothing Gantry Movements
One challenging project involved a gantry-mounted piece of equipment experiencing consistent screwjack failures. By implementing PID control and ramp functions based on position, the gantry movements were smoothed, reducing mechanical stress and failures.
Very Simple Example of the Gantry Traverse Control
There is a lot missing from this, as it is a quick example.
FUNCTION_BLOCK FB_GantryPIDControl
VAR_INPUT
CurrentPosition : REAL; // Current position from laser feedback
DownPosition : REAL; // Position indicating equipment is down
ArmClosed : BOOL; // Proximity feedback indicating arm is closed
Pos1 : REAL; // Position 1 setpoint
Pos2 : REAL; // Position 2 setpoint
Pos3 : REAL; // Position 3 setpoint
Home : REAL; // Home position setpoint
Setpoint : REAL; // Desired setpoint position
Tolerance : REAL := 0.1; // Tolerance for position accuracy
Kp : REAL := 1.0; // Proportional gain for PID control
Ki : REAL := 0.1; // Integral gain for PID control
Kd : REAL := 0.05; // Derivative gain for PID control
RampTime : INT := 10; // Time for the ramp to complete in seconds
END_VAR
VAR_OUTPUT
DriveControl : REAL; // Drive control signal
InPosition : BOOL; // Indication that gantry is in position
Alarm : BOOL; // Alarm if conditions are not met
END_VAR
VAR
Error : REAL; // Position error
Integral : REAL; // Integral term for PID control
Derivative : REAL; // Derivative term for PID control
PreviousError : REAL; // Previous error value for PID control
PIDOutput : REAL; // PID controller output
RampStep : REAL; // Incremental step for the ramp
TimeCounter : INT := 0; // Counter for time
RampValue : REAL; // Ramp value for position control
END_VAR
BEGIN
// Ensure equipment is down and arm is closed before moving
IF (CurrentPosition = DownPosition) AND ArmClosed THEN
// Ramp up to the setpoint
RampStep := (Setpoint - CurrentPosition) / RampTime;
TimeCounter := TimeCounter + 1;
IF TimeCounter < RampTime THEN
RampValue := CurrentPosition + (RampStep * TimeCounter);
ELSE
RampValue := Setpoint;
END_IF;
// Calculate position error for PID control
Error := RampValue - CurrentPosition;
// Calculate integral term
Integral := Integral + (Error * 0.1); // Assume time interval of 0.1s
// Calculate derivative term
Derivative := (Error - PreviousError) / 0.1; // Assume time interval of 0.1s
// Calculate PID output
PIDOutput := (Kp * Error) + (Ki * Integral) + (Kd * Derivative);
// Set drive control signal based on PID output
IF ABS(Error) > Tolerance THEN
DriveControl := PIDOutput;
InPosition := FALSE;
ELSE
DriveControl := 0.0;
InPosition := TRUE;
END_IF;
// Update previous error
PreviousError := Error;
ELSE
// Stop movement and raise alarm if conditions are not met
DriveControl := 0.0;
Alarm := TRUE;
END_IF;
END_FUNCTION_BLOCK
Explanation
Usage
Tips for Effective PID Control
1. Understand Time Propagation: Different processes have different CV to PV time propagation. Develop PID behavior based on system delays and behaviors.
2. Start Simple: Begin with simple PID control. Proportional (linear) term is the easiest to understand. Derivative controls the change over a short period (slope), and integral addresses mean error over time.
3. Adjust Based on Testing: Calculate initial PID parameters, then adjust during testing. Start with proportional control and add integral and derivative terms as needed.
Conclusion
Mastering PID control in SCL is key to developing robust and efficient control systems. By implementing these techniques, you can improve system reliability, reduce mechanical stress, and optimize process performance.
---
About the Author
Ken Jensen brings over 24 years of experience in electrical, automation, and controls engineering across diverse industries like nuclear, steel, and glass. He is a highly skilled problem-solver with expertise in electrical systems, PLCs, SCADA, and Industry 4.0 technologies. He is adept at leading projects, driving innovation, and fostering collaboration.