0% found this document useful (0 votes)
324 views

Lab 3 Pid Mecha

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
324 views

Lab 3 Pid Mecha

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

SCHOOL OF MECHANICAL ENGINEERING

MEC 680 - MECHANICS OF COMPOSITE MATERIALS

PRACTICAL & LABWORK REPORT

LABWORK 3
CLOSED LOOP ANGULAR POSITION CONTROL SYSTEM USING PID CONTROLLER

PLAGIARISM STATEMENT
I/We certify that this assignment/report is my/our own work, based on my personal study
and/or research and that I/we have acknowledged all material and sources used in its
preparation, whether they be books, articles, reports, lecture notes, and any other kind of
document, electronic or personal communication. I also certify that this assignment/report
has not previously been submitted for assessment in any other unit, except where specific
permission has been granted from all unit coordinators involved, or at any other time in
this unit, and that I/we have not copied in part or whole or otherwise plagiarized the work
of other students and/or persons.

Name Student ID No. Signature

DG NURAZEQA AZWA BINTI AG SALLEH 2021832714

JAS MOHD SHAMIR BIN NIZAM 2021492462

MOHAMAD IRSYAD HAKIM BIN


2021823788
MOHAMAD ZAHAIR

NUR HANANI BINTI MOHD RADZUAN 2021606758

Date start: Date of submission: 28/7/2023

Report Reception Lecturer’s signature:


Date:

MEC 680: MECHANICS OF COMPOSITE MATERIALS

TITLE: CLOSED LOOP ANGULAR POSITION CONTROL SYSTEM USING PID CONTROLLER
ABSTRACT

The experiment focuses on developing and testing a PID-based Closed-Loop Angular


Position Control System. The objective is to develop mathematical models and
principles for control systems, propose solutions, and analyse the performance of the
PID controller. The setup includes an angular position sensor, PID controller, and
actuator. The experiment evaluates performance by considering variables like
accuracy, reaction time, overshoot, stability, and resistance to external disruptions.
The findings demonstrate the system's stability when Kp and Kcr changes using
different angle.

INTRODUCTION

A closed-loop system, often known as a feedback control system, is a fundamental


idea in engineering and control theory. It is critical in a variety of industries, from
aerospace and automotive to robotics and industrial automation. The closed-loop
control concept comprises continuously monitoring and adjusting a system's output
in response to changes in its environment using feedback information. This feedback
loop enables the system to retain the correct setpoint, reduce disturbances, and
increase overall performance and stability.[1] A significant advantage of closed-loop
systems is their ability to maintain accurate and precise control even in the presence
of uncertainties and disturbances. A control algorithm continuously monitors the
system's output through sensors and compares it to the desired setpoint, generating
an error signal. This error signal is then processed by a controller, such as a
Proportional-Integral-Derivative (PID) controller, which computes the appropriate
control action. [1]

PID (Proportional, Integral, Derivative) controllers are tools used by control engineers
in industrial control systems to control temperature, flow, pressure, speed, and other
process variables. The most precise and reliable controllers are PID controllers,
which use a control loop feedback mechanism to control process variables. An

1
effective way of guiding a system towards a desired position or set of control
parameters is PID control. It is nearly always used to regulate temperature and has
a wide range of applications in automation, chemistry, and other sciences. PID control
keeps a process's real output as close as feasible to the target or setpoint output.[2]

Figure 1: Unity feedback system [3]

The tracking error, or the discrepancy between the desired output (r) and the actual
output (y), is represented by the variable (e). The PID controller receives this error
signal (e), which it then uses to compute the integral and derivative of in terms of
time. The proportional gain (𝐾 𝑝 ) times the magnitude of the error, the integral gain
(𝐾 𝑖 ) times t integral of the error, and the derivative gain (𝐾 𝑑 ) times the derivative of
the error combines to form the control signal (u) to the plant. The plant receives this
control signal (u), and the new output (y) is produced. The new error signal (e) is then
determined by feeding back the new output (y) and comparing it to the reference. The
controller computes an update of the control input using this new error signal. While
the controller is functioning, this procedure maintains. [3]

Numerous studies have proved the effectiveness of closed-loop systems in a variety


of fields. Closed-loop control is widely used in the aerospace industry to stabilize
aircraft in flight and maintain exact trajectories. In automobile applications, it provides
active safety features such as anti-lock braking systems (ABS) and electronic stability
control (ESC). Furthermore, in the realm of robotics, closed-loop control guarantees
accurate movement and manipulation, allowing robots to complete difficult tasks with
precision. [4] This paper seeks to provide a thorough grasp of closed-loop systems
and their practical applications. We will look at the ideas and components of closed-
loop control, with a special emphasis on PID controllers, which are frequently used in
many closed-loop applications. We will investigate the components that contribute to
the effective deployment of closed-loop systems through a survey of the literature
and analysis of relevant research papers.

2
OBJECTIVE:

1. To develop mathematical models and principles of control systems for the


angular position control system.
2. To propose appropriate solutions and analyse the performance of the PID
controller of the system.

THEORY

The Closed-Loop Angular Position Control System with a PID (Proportional-Integral-


Derivative) controller is a strong and frequently used control approach for preserving
an angular position in mechanical and electrical systems. A closed-loop design is
used in this system, with constant feedback from an angular position sensor used to
monitor the actual location of the controlled mechanism. The error is then calculated
as the difference between the planned setpoint and the actual location by the PID
controller, allowing it to make real-time modifications to reduce the error. The
Proportional (P) term, the Integral (I) term, and the Derivative (D) term make up the
PID controller. Each term is important in calculating the control signal that powers the
actuator and leads the system to the desired angular position.

The Closed-Loop Angular Position Control System is made up of important


components that work together to provide accurate control. To begin, an angular
position sensing device, such as an encoder or resolver, measures the actual position
of the controlled mechanism in real time. The user specifies the intended angular
position as the setpoint, which serves as the system's goal position. The error (e) is
calculated by the PID controller as the difference between the setpoint (SP) and the
sensor feedback (FB): e = SP - FB. The P term reacts to present mistakes, the I term
removes steady-state errors, and the D term predicts future errors and prevents
overshooting.

𝒕 𝒅𝒆(𝒕)
𝒖(𝒕) = 𝑲𝒑 𝒆(𝒕) + 𝑲𝒊 ∫𝟎 𝒆(𝝉)𝒅𝝉 + 𝑲𝒅 (1)
𝒅𝒕

The PID controller architecture for this control system is shown in Figure 2. The PID
equation is used to determine the control signal for a DC motor. e(t) is the position
error value difference between the set angle and the output measured angle (actual
angle), u(t) is the PWM signal for the DC motor, and y(t) is the actual angle. Kp, Ki,
and Kd were proportional, integral, and differential coefficient values, respectively. [5]

3
Figure 2: Closed Loop Position Control of the DC Motor using PID Controller [6]

The actuator is the physical link between the PID controller's control signal, and the
mechanism being regulated. Its function is to translate an electrical or digital control
signal into a mechanical action that alters the angular position of the system. A motor,
a hydraulic or pneumatic actuator, or any other device capable of imparting motion
might be used as the actuator. The closed-loop control is based on constant data
from the angular position sensor. While the system is in this closed-loop mode, the
PID controller compares the current location to the setpoint and modifies the control
signal accordingly. This iterative procedure guarantees that the system corrects itself
in real time, altering the actuator's output to minimize the difference between the
desired and actual locations. The system's continuous feedback loop allows it to
retain accurate and steady angular position control while correcting for disturbances,
uncertainties, and external effects.[6]

Tuning the PID gains (Kp, Ki, and Kd) is an important part of the Closed-Loop Angular
Position Control System employing a PID controller. It is critical to properly tune these
improvements to achieve optimal system performance. The tuning procedure
involves modifying the gains to obtain desirable system response characteristics such
as quick response, low overshoot, and short settling time.

For the first experiment 90˚ of angle is set. The angle must be converted to Pulse
Width Modulation (PWM).

500
𝑃𝑜𝑤𝑒𝑟 𝑊𝑖𝑑𝑡ℎ 𝑀𝑜𝑑𝑢𝑙𝑎𝑡𝑖𝑜𝑛 (𝑃𝑊𝑀) = 𝑎𝑛𝑔𝑙𝑒 ×
360
After the graph has been plotted by the Arduino software, peak to peak (Pcr) of the
graph must be identified to calculate the value of Kp, Ki and Kd by using the formula
below:

4
Pcr = x2 − x1
1000
𝐾𝑝 = 0.6𝐾𝑐𝑟
Ki = K p /0.5(Pcr)
Kd = K p (0.125(Pcr))

The PID controller is a common option in engineering and industrial settings due to
its versatility, simplicity, and efficacy in a wide range of applications. Its capacity to
manage a wide range of control scenarios, as well as its resistance to disturbances,
contribute to its extensive use. Furthermore, the closed-loop architecture allows the
system to continually adapt to changes while maintaining precise angular position
control, making the PID controller an essential tool for precision motion control
applications.

MATERIALS AND METHODS

These are some apparatuses used for the experiment:

1. Computer
• Arduino Software
2. Sensor Actuator Closed Loop Control

• DC motor
• Stepper motor
• Arduino MEGA (as controller)

5
THEORETICAL COMPUTATION

SAMPLE CALCULATIONS

Using Ziegler-Nichols Tuning 2nd Method,

Determining Pulse Width Modulation (PMW)


Using Ɵ = 90°

𝜃
𝑃𝑊𝑀 = ∗ 500
360
90
𝑃𝑊𝑀 = ∗ 500
360
𝑃𝑊𝑀 = 125
Kp, Ki, Kd Calculation

An initial value of 𝐾𝑝 ≈ 𝐾𝑐𝑟 = 1.7 is selected to get sustained oscillation

Pcr

At (x,y) ≈ (444,129) and (507,129)


When y = 129
Pcr = x2 − x1
1000
Pcr = (507 − 444)/1000
= 0.063

After getting the value of Pcr, the values for Kp, Ki and Kd can be calculated.

Note that the initial value of Kp is now considered as Kcr as it allows steady-state
oscillation to occur.

6
𝐾𝑐𝑟 = 1.7
𝐾𝑝 = 0.6𝐾𝑐𝑟
= (0.6)(1.7)
= 1.02
After we get the value of Kp, we then can find the value of Ki and Kd

Ki = K p /0.5(Pcr)
Ki = 1.02/0.5(0.063)
= 32.38

Kd = K p (0.125(Pcr))
= 1.02 × (0.125(0.063))
= 0.0080325

EXPERIMENTAL PROCEDURE

1. The control system's and computer's wiring connections have been


confirmed.
2. The control system has been initiated, and the Arduino software has been
installed on the computer.
3. In the Arduino program, the Kcr value was set to 1.7 with an angle of 90°,
while the Ki and Kd values were initially set to zero.
4. The PID system was modified and stored in the program.
5. The system was operated, and the motor's motion changed when the system
was adjusted to a given value and seen by the students.
6. After watching the system's movements, the graph is analysed via software.
7. Step 3 until step 6 being repeated until the result obtained was optimum in the
graph by changing the value of Kcr into another value.
8. After getting the optimum result, the data being saved and analysed by the
students.

7
RESULTS

• 1st Result

160
140
120
100
Amplitude

80
60
40
20
0
0 100 200 300 400 500 600
-20
Time (sec)

Setpoint Process Variable

Figure 3: The graph shown the Kcr oscillation with Kp = 1.7, Ki = 0.0, and Kd = 0.0.

After applying Ziegler-Nichols Tuning with Kp, Ki and Kd values gathered through
specific calculations.

• 2nd Result

140

120

100

80
Axis Title

60

40

20

0
0 100 200 300 400 500 600
-20
Axis Title

Setpoint Process Variable

Figure 3: The graph shown the Kcr oscillation After applying Ziegler-Nichols Tuning
with Kp = 1.2, Ki = 23.61, and Kd = 0.00549.

8
To alter the control signal, the PID controller employs three main control strategies:
proportional, integral, and derivative control. The control signal is modified by the
proportional control technique in response to the discrepancy between the actual and
intended locations. The integral control technique alters the control signal based on
the accumulated error over time. The derivative control approach alters the control
signal based on the error's rate of change. The three PID controller parameters that
regulate the system's behavior are proportional gain, integral gain, and derivative
gain.

A PID controller's three parameters (proportional gain, integral gain, and derivative
gain) are interconnected and impact the control system's behavior in distinct ways.
The proportional gain (Kp) controls the intensity of the controller's response to the
difference between the intended and actual location. The integral gain (Ki) is the
strength of the controller's reaction to the integral of the error over time. The derivative
gain (Kd) controls the intensity of the controller's response to the rate of change of
the error. The appropriate values for the PID parameters are determined by the
application and the features of the system under control. To achieve the intended
performance, the ideal values for each parameter were determined through careful
tweaking and testing.

DISCUSSION AND FINDINGS

This experiment's purpose was to construct mathematical models and principles of


control systems for an Angular Position Control System and to propose suitable
solutions. Based on the system's response, the efficiency of a Proportional-Integral-
Derivative (PID) controller was analysed and evaluated. Modifying the PID
algorithm’s proportional, integral, and derivative coefficients produces the optimal
response. The proportional control technique modifies the control signal according to
the difference between the intended and actual positions. Integral control modifies
the control signal based on the error accumulation over time. The derivative control
strategy modulates the control signal in accordance with the error rate of change. The
three parameters of the PID controller, proportional gain (Kp), integral gain (Ki), and
derivative gain (Kd), perform crucial roles in determining the control system's
behaviors. This experiment uses the Ziegler-Nichols (Z-N) second method, which is
designed for tuning outputs with sustained oscillations.

9
In this PID experiment, the output angle versus time graph shows the behavior and
response of the closed-loop Angular Position Control System. The graph shows
variation of the output angle over time due to varying PID parameter settings.
Calculations were performed to determine the PID parameters required for the
controller to fine-tune the output. Having determined the value of Kcr, the values of
Kp, Ki, and Kd are calculated using the Z-N 2nd method's formulas. The results of
this experiment showed that Kp = 1.02, Ki = 32.38, and Kd = 0.0080325. When all
the values are applied to the PID controller, the output can be seen to change
dramatically, corresponding to the tuned output graph that represents the desired
output.

Figure 4: The graph shown the Kcr oscillation with Kp = 1.7

In this scenario, the system showed a response that was sufficiently rapid to
changes in the reference angle with a proportional gain (Kp) of 1.7 and without any
integral or derivative gain (Ki = 0, Kd = 0). In other words, the system did not show
any integral or derivative gain. Oscillations were seen around the setpoint by the
output angle, which indicated that precision monitoring and oscillation suppression
were not possible. Overshoot and errors in the steady state were produced as a result
of the absence of integral and derivative operations. Regardless of these constraints,
the system behaved in a way that was consistent with the expected direction.

10
Figure 5: The graph shown the Kcr oscillation After applying Ziegler-Nichols with Kp
= 1.2

To enhance the system's response, the proportional gain (Kp) was decreased
to 1.2 and non-zero integral and derivative gains (Ki = 22.61, Kd = 0.00549) were
incorporated. In comparison to the previous result, the system's efficacy has
significantly increased. The integral operation minimized steady-state error, resulting
in a better fit between the output angle and the intended direction. The derivative
action reduced oscillations, resulting in a shortened settling time and fewer
oscillations. With these parameter values, the system showed improved
responsiveness, precision, and stability.

Consequently, the lower proportional gain led to a more conservative


response with less overshoot and oscillations. This result obtained a greater
proportion of responsiveness, precision, and stability than previous results. The
output angle followed the intended direction more precisely, showing improved
performance characteristics. However, a few potential errors might occur during the
experiment. Instrumental errors may be one of the errors that may occur during this
experiment. The apparatus, which is the DC Motor, may be used frequently, and the
apparatus may contain damage or errors that prevent it from operating optimally,
thereby affecting the experiment's results.

11
CONCLUSION

In conclusion, this experiment was a success because all of the objectives


were accomplished. The closed-loop angular position control system that made use
of the PID controller displayed exceptionally high levels of efficacy and stability in the
process of establishing accurate and exact angular positioning. Robustness was
delivered against disturbances and uncertainties by way of the different performance
of the PID controller, which, when combined with the closed-loop architecture,
delivered to the system. The transient responsiveness of the system as well as the
amount of time it takes to adjust may both be further optimized with some careful PID
tuning and consideration of the system's mechanical features. This research provides
a solid foundation for the creation of high-precision control systems that can be used
in a broad variety of different applications. It makes an important contribution by
offering significant insights into the implementation of closed-loop control systems in
the domain of Mechanics of Composite Materials.

12
REFERENCES

[1] Johanåström, K., Murray, R., & And, P. (n.d.). Feedback Systems.
https://www.cds.caltech.edu/~murray/books/AM08/pdf/am08-
complete_28Sep12.pdf

[2] What is a PID Controller? (2019). Https://Www.omega.com/En-Us/.


https://www.omega.com/en-us/resources/pid-controllers

[3] Control Tutorials for MATLAB and Simulink - Introduction: PID Controller Design.
(n.d.). Ctms.engin.umich.edu.
https://ctms.engin.umich.edu/CTMS/index.php?example=Introduction&section=Cont
rolPID#1

[4] Modern Control Systems Thirteenth edition. (n.d.).


https://files.crazt.moe/temp/Modern%20Control%20Systems%2013th.pdf

[5] L. M. Surhone, M. T. Timpledon, and S. F. Marseken, Eds., PID Controller. 2010.

[6] K. K. K. Sailan, “DC Motor Angular Position Control using PID Controller for the
purpose of controlling the Hydraulic Pump”, 2013.

13
APPENDICES

// Copyright (c) 2019 MEC624. All rights reserved.

//

//
***********************************************************************************************
******* //

/* constant declaration */

#define PI 3.14159 // value of Pi

#define PREV 3 // number of stored data

#define UMAX 100.0

#define UMIN -100.0

/*Define Your PWM Setpoint (0 ~ 511)*/

#define SETPOINT 125 // angle 90

/Set time for experiment/

#define SIM_TIME 2.5

#define RUNTIME SIM_TIME * 1000UL

/PID Constants: Change them accordingly/

#define Kp 0.78

#define Ki 20.526

#define Kd 0.00741

/****************************************************/

/variables declaration/

typedef struct

14
{

float dRef[PREV][1]; //micromet ref(k), ref(k+1) and ref(k+2)

float dFback[PREV][1]; //micromet

float dOutErr[PREV][1]; //micromet

float dCOut[PREV][1]; //Control Signal

}ProcessControl;

ProcessControl CVar = {

{ 0, 0, 0 }, //dRef

{ 0, 0, 0 }, //dFeedback

{ 0, 0, 0 }, //Output Error

{ 0, 0, 0 }, //dControlOut

};

/Definition of timing variables/

typedef struct

unsigned long dProcessTime_ms; //ms

float dTms; //ms

float dTsec; //second

long lSetLoop; //Number of loops

unsigned long dTs_start; //second

unsigned long dTs_past;

unsigned long newtime;

15
}Time;

Time TimeVar = {0, //Process Time

0, //Sampling time ms

0, //Samping time s

10000, //Num of Loops

0,

};

/****************************************************/

/Definition of model constants/

typedef struct

/*Descrete Time Equation : yk = -a1*y(k-1) - a2*y(k-2) + b1*u(k-1) + b2*u(k-2) */

float fa1, fa2; //Denominator

float fb1, fb2; //Nummerator

float fPole1, fPole2;

}PlantParas;

PlantParas PVar;

/****************************************************/

16
/PID Controller's parameters/

typedef struct

float fKP, fKI;

float fUpperLimit, fLowerLimit;

float fUs[2], fEs[2];

}DPID;

DPID PIDVar;

/****************************************************/

/* Hardware's IO Definitions*/

#define encoder0PinA 2

#define encoder0PinB 4

//declaration of dcmotor parameters

#define E1 11 //M1 Speed Control

#define M1 3 //M1 Direction Control

volatile long encoder0Pos=0;

/****************************************************/

void setup()

//encoderassigment for encoder parameters

pinMode(encoder0PinA, INPUT);

digitalWrite(encoder0PinA, HIGH); // turn on pullup resistor

pinMode(encoder0PinB, INPUT);

17
digitalWrite(encoder0PinB, HIGH); // turn on pullup resistor

attachInterrupt(0, doEncoder, RISING); // encoDER ON PIN 2

Serial.begin (115200);

/pin Assigments for dcmotor parameters/

pinMode (E1, OUTPUT);

pinMode (M1, OUTPUT);

/Enter experimental environment/

SystemConfig();

MainLoop();

/Record experiment time/

GetProcessingTime();

void loop (void)

//--Nothing runs HERE

/****************************************************/

void MainLoop()

long lCountLoops;

18
lCountLoops = 0;

//while (lCountLoops < TimeVar.lSetLoop) {

for (lCountLoops = 0; lCountLoops < TimeVar.lSetLoop; lCountLoops++)

TimeVar.dTs_start = millis();

CVar.dFback[2][0] = CVar.dFback[1][0]; //y(k-2) = y(k-1)

CVar.dFback[1][0] = CVar.dFback[0][0];

//--Get control input instances

CVar.dCOut[2][0] = CVar.dCOut[1][0];

CVar.dCOut[1][0] = CVar.dCOut[0][0];

//--Simulation Output

//CVar.dFback[0][0] = secondOrderSystem();

//--Experimental Output

CVar.dFback[0][0] = encoder0Pos;

//--Update Error instances

CVar.dOutErr[2][0] = CVar.dOutErr[1][0];

CVar.dOutErr[1][0] = CVar.dOutErr[0][0];

CVar.dOutErr[0][0] = CVar.dRef[0][0] - CVar.dFback[0][0];

//--Generate Reference Signal

19
refSigGenerate(TimeVar.dTsec*lCountLoops);

//--CLOSED-LOOP: Standard PID Controller

CVar.dCOut[0][0] = standardPID();

//--OPEN-LOOP: Control input-->SETPOINT

//CVar.dCOut[0][0] = CVar.dRef[0][0];

//--Send Control Signal to Hardware

dacWrite(CVar.dCOut[0][0]);

TimeVar.dTs_past = TimeVar.dTs_start;

// Publish data to serial monitor

//Serial.print ("C_out =");

// Serial.print (CVar.dCOut[0][0]);

// Serial.print ("\t");

//Serial.print (",Desired_Out =");

//Serial.print ("time = ");

20
Serial.print (TimeVar.dTs_start);

Serial.print(",");

Serial.print (CVar.dRef[0][0]);

Serial.print(",");

//Serial.print (",Real_Out =");

Serial.println (CVar.dFback[0][0]);

// Serial.println ("\t");

//Serial.print ("\t ");

/Definition of SUBROUTINES AND FUNCTIONS/

void GetProcessingTime()

TimeVar.dProcessTime_ms = TimeVar.dTs_past /1000;

//Serial.print("Elapsed time = ");

21
// Put your print function in here

Serial.println(TimeVar.dProcessTime_ms);

//Serial.print(" sec");

/****************************************************/

/Input Function Generators: Start/

float refSigGenerate(float dTsec)

int k;

for (k = 0; k < 3; k++)

CVar.dRef[k][0] = SETPOINT;

return CVar.dRef[0][0];

/Input Function Generators: End/

void dacWrite(float Vout)

float dVcOut;

/*Compute real control output applied to DAC */

dVcOut = Vout;

if ( Vout > UMAX)

22
Vout = UMAX;

if ( Vout < UMIN)

Vout = UMIN;

if(Vout >= 0) {

backward(Vout);

// delay (1000);

// stop();

//delay (2000);

if(Vout < 0) {

forward (Vout);

// delay (1000);

void stop(void)//Stop

digitalWrite(E1,LOW);

23
}

void forward(float a) //Move forward

analogWrite (E1,a); //PWM Speed Control

digitalWrite(M1,HIGH);

void backward (float a) //Move backward

{analogWrite (E1,a);

digitalWrite(M1,LOW);

void doEncoder()

if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {

encoder0Pos++;

} else {

encoder0Pos--;

24
/****************************************************/

/Discrete Second Order System Model: Start/

float secondOrderSystem(void)

// yk = -a1*y(k - 1) - a2*y(k - 2) + b1*u(k - 1) + b2*u(k - 2)

float fTemp;

fTemp = - 1.0*PVar.fa1*CVar.dFback[1][0] - 1.1*PVar.fa2*CVar.dFback[2][0]

+ 0.8*PVar.fb1*CVar.dCOut[1][0] + 0.9*PVar.fb2*CVar.dCOut[2][0];

return fTemp;

/Discrete Second Order System Model : End/

/****************************************************/

/Continuous time PID controller with anti-windup: Start/

float standardPID(void)

{ float Uktemp, DErr, InErr;

DErr = (CVar.dOutErr[0][0] - CVar.dOutErr[1][0])/ (TimeVar.dTs_past);//Derivative


Errors

InErr = 1/2 * ((CVar.dOutErr[0][0] + CVar.dOutErr[1][0])* (TimeVar.dTs_past));//


Integral Errors

Uktemp = Kp * CVar.dOutErr[1][0] + Ki * InErr + Kd * DErr; //Integral is the


summation of all error

25
return Uktemp;

float SystemConfig(void)

/Set number iterations to run experiment/

TimeVar.lSetLoop = RUNTIME; //Set number of control loops

TimeVar.dTms = 0.5; //Set sampling time - ms

TimeVar.dTsec = TimeVar.dTms / 1000;

float Alpha1, Alpha2, Beta1, Delta1, TI, Vs;

/Plant's Parameters/

PVar.fb1 = 0.02623; PVar.fb2 = 0.007647;

PVar.fa1 = -0.9549; PVar.fa2 = 0.01666;

PVar.fPole1 = 0.0178; PVar.fPole2 = 0.9372;

/PID Controller's Parameters/

Vs = PVar.fb1; Beta1 = (PVar.fb2 / Vs);

Alpha1 = -PVar.fPole1; Alpha2 = -PVar.fPole2;

PIDVar.fKP = 20*(1 + Alpha2)(1 + Alpha2) / (Vs(1 + 3 * Beta1 + Alpha2*(-1 +


Beta1)));

Delta1 = Alpha1;

TI = TimeVar.dTsec / (Delta1 + 1);

PIDVar.fKI = PIDVar.fKP / (TI*1);

PIDVar.fUpperLimit = 40;

PIDVar.fLowerLimit = -40;

26
}

27

You might also like