PID regulator i strukturert tekst

Spurt 21:23 - 28.2.2024 av Trond|Siste svar 20:57 - 26.3.2024 av Stig Erling Benjaminsen

Trond

Hei

Jeg skal lage en funksjonsblokk med PID regulator i strukturert tekst.
Det jeg lurer på er om noen kan fortelle meg hvordan formellen for I - leddet blir ?

https://www.trainor.no/assets/forum/IMG_7360.jpeg
Helpful answer marked by forum leaderLøst

Svar (2)

PID

Postet 17:45 - 16.3.2024

Integralet er enkelt forklart arealet under grafen, og siden du ikke ønske rå benytte deg av noen av dei ferdige blokkene, så går jeg utifra at dette er for å lære seg å programmere i struktuert tekst.

En enkel måte vi gjorde det på, da med mikrokontroller, var bare å plusse sammen hver verdi en fikk, og det er jo arealet under grafen. Denne variabelen/verdien må jo deles på noe og du bør ikke ha evig med I-leddet da det blir stort over tid.

Stig Erling Benjaminsen

Postet 20:57 - 26.3.2024

Creating a PID controller program in Structured Text (ST), a high-level programming language used in PLC (Programmable Logic Controller) programming, involves defining the logic to compute the PID control's output based on the process error, integral, and derivative calculations. Below is an example of how such a program might be written in ST. This example assumes you have a basic understanding of PLC programming and the context in which this PID controller will operate.


```structuredtext


PROGRAM PID_Controller


VAR


Kp: REAL := 1.0; (* Proportional gain *)


Ki: REAL := 0.1; (* Integral gain *)


Kd: REAL := 0.01; (* Derivative gain *)


Setpoint: REAL := 100.0; (* Desired process value *)


MeasuredValue: REAL; (* Current process value *)


DeltaTime: REAL := 0.1; (* Time between calculations, in seconds *)


Error: REAL;


PreviousError: REAL := 0.0;


Integral: REAL := 0.0;


Derivative: REAL;


Output: REAL;


END_VAR


Error := Setpoint - MeasuredValue; (* Calculate current error *)


Integral := Integral + (Error * DeltaTime); (* Update integral *)


Derivative := (Error - PreviousError) / DeltaTime; (* Calculate derivative *)


Output := (Kp * Error) + (Ki * Integral) + (Kd * Derivative); (* Compute output *)


(* Update for next calculation *)


PreviousError := Error;


(* Your code to apply 'Output' to control the process goes here *)


```


### Key Components:


- **Kp, Ki, Kd:** These are the PID controller's tuning parameters. You'll need to adjust these based on your specific process to achieve stable and responsive control.


- **Setpoint:** The target value for the process variable you're trying to control (e.g., temperature, pressure, level).


- **MeasuredValue:** The current value of the process variable. This would typically be read from a sensor.


- **DeltaTime:** The time interval in seconds between successive PID calculations. This should match the cycle time of your control loop.


- **Error, PreviousError, Integral, Derivative, Output:** Variables used to compute the PID controller's output. `Error` is the current difference between the setpoint and the measured value, `Integral` accumulates the error over time, `Derivative` represents the rate of change of the error, and `Output` is the value applied to the process to drive the measured value towards the setpoint.


This ST code snippet is a basic implementation. Depending on your application, you might need additional logic to handle scenarios like integral windup or to scale the output to the specific requirements of your control element (e.g., a valve or a motor speed controller).

Legg til svaret ditt

Trainor logo

Registrer deg og bidra til Norges største fagforum for sikkerhet.
Allerede medlem? Logg inn

Registrer deg nå
Trainor logo
Opplæring for fagfolk. Av fagfolk.

Registrer deg og bidra til Norges største fagforum for sikkerhet.

Registrer deg

Allerede medlem? Logg inn

Relevante kurs

Trenger du sertifisering, opplæring eller kurs i elsikkerhet? Enten du velger e-læring, et webinar eller et instruktørledet kurs fra Trainor, er kurset laget av våre fremste eksperter. Alt til det beste for din læring og sikkerhet.