You are on page 1of 7

Andini Vira Salsabilla Z.

P
5023201065
Biocybernetics Q

For two different plants of certain control systems with following differentian equations in
equation (1) and equation (2)

Create computer codes of:


1. A Function of the second order differential equation that models each plant.

//Function code of plant #1 model


function Tform1.PlantA(t, y, v, x: Double): Double;
begin
PlantA := -0.5*v-y+x;
end;

//Function code of plant #2 model


function Tform1.PlantB(t, y, v, x, xdot: Double): Double;
begin
PlantB := -1.5*v-y+2*xdot+x;
end;

2. A function of 4th order Runge-Kutta method to integrate to differential equation of the


model.

// Use Runge-Kutta to integrate the system


if RadioButton3.Checked then
begin
// Runge-Kutta for Plant 1
k1 := DT * Derivative2(T, ProcessVariable, 0, Output);
k2 := DT * Derivative2(T + 0.5 * DT, ProcessVariable + 0.5 *
k1, 0, Output);
k3 := DT * Derivative2(T + 0.5 * DT, ProcessVariable + 0.5 *
k2, 0, Output);
k4 := DT * Derivative2(T + DT, ProcessVariable + k3, 0,
Output);

ProcessVariable := ProcessVariable + (1 / 6) * (k1 + 2 * k2 +


2 * k3 + k4);

end;
//Plant 2
if RadioButton4.Checked then
begin
k1 := DT * Derivative3(T, ProcessVariable, Output, 0, xdot2);
k2 := DT * Derivative3(T + 0.5 * DT, ProcessVariable + 0.5 *
k1, 0, Output, xdot2);
k3 := DT * Derivative3(T + 0.5 * DT, ProcessVariable + 0.5 *
k2, 0, Output, xdot2);
k4 := DT * Derivative3(T + DT, ProcessVariable + k3, 0,
Output, xdot2);

ProcessVariable := ProcessVariable + (1 / 6) * (k1 + 2 * k2 +


2 * k3 + k4)

The output result for this program is,


3. A main program to simulate PID controller parameters determination using Zeigler-
Nichols (ZN) Method 1, and Method2.
//Ziegler Nichols Method 1
begin

ScrollBar1.Min := 1;
K := ScrollBar1.Position / 10.0;

Tau := strtofloat(Edit2.Text);

L := strtofloat(Edit1.Text);

Ku := ScrollBar5.Position / 10.0;

Pu := strtofloat(Edit3.Text);

Label1.Caption := Format('K : %.2f', [K]);


Label4.Caption := Format('Ku : %.2f', [Ku]);

R := K/Tau;

if RadioButton1.Checked then
begin

Kp := 1.2 / (R * L);
Ki := 0.6 / (R * L * L);
Kd := 0.6 / R;

Memo1.Clear;
Memo1.Lines.Add(Format('Kp := %.2f', [Kp]));
Memo1.Lines.Add(Format('Ki := %.2f', [Ki]));
Memo1.Lines.Add(Format('Kd := %.2f', [Kd]));

SimulatePID(Kp, Ki, Kd);


end;
/Ziegler Nichols Method 2

if RadioButton2.Checked then
begin

Kp := 0.6 * Ku;
Ki := 1.2 * Ku / Pu;
Kd := 0.075 * Ku * Pu;

Memo1.Clear;
Memo1.Lines.Add(Format('Kp := %.2f', [Kp]));
Memo1.Lines.Add(Format('Ki := %.2f', [Ki]));
Memo1.Lines.Add(Format('Kd := %.2f', [Kd]));

SimulatePID(Kp, Ki, Kd);


end;
end;

procedure Tform1.SimulatePID(Kp, Ki, Kd: Double);


var
ResultText: string;
y1, v1 , x1, y2, v2, x2, xdot, k1, k2, k3, k4, xdot2: Double;
begin
Setpoint := 1.0;
ProcessVariable := 0.0;
Integral := 0.0;
T := 0;
DT := 0.001; // Time step
xdot2 := 0;

while T <= 10 do
Plant A (Step Response)

Plant A (Impulse Response)

Plant B (Step Response)

Plant B (Impulse Response)


The interface of this program can be seen below,

You might also like