Lab 3 Pid Mecha
Lab 3 Pid Mecha
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.
TITLE: CLOSED LOOP ANGULAR POSITION CONTROL SYSTEM USING PID CONTROLLER
ABSTRACT
INTRODUCTION
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]
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]
2
OBJECTIVE:
THEORY
𝒕 𝒅𝒆(𝒕)
𝒖(𝒕) = 𝑲𝒑 𝒆(𝒕) + 𝑲𝒊 ∫𝟎 𝒆(𝝉)𝒅𝝉 + 𝑲𝒅 (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.
1. Computer
• Arduino Software
2. Sensor Actuator Closed Loop Control
• DC motor
• Stepper motor
• Arduino MEGA (as controller)
5
THEORETICAL COMPUTATION
SAMPLE CALCULATIONS
𝜃
𝑃𝑊𝑀 = ∗ 500
360
90
𝑃𝑊𝑀 = ∗ 500
360
𝑃𝑊𝑀 = 125
Kp, Ki, Kd Calculation
Pcr
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
7
RESULTS
• 1st Result
160
140
120
100
Amplitude
80
60
40
20
0
0 100 200 300 400 500 600
-20
Time (sec)
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
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.
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.
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.
11
CONCLUSION
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
[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§ion=Cont
rolPID#1
[6] K. K. K. Sailan, “DC Motor Angular Position Control using PID Controller for the
purpose of controlling the Hydraulic Pump”, 2013.
13
APPENDICES
//
//
***********************************************************************************************
******* //
/* constant declaration */
#define Kp 0.78
#define Ki 20.526
#define Kd 0.00741
/****************************************************/
/variables declaration/
typedef struct
14
{
}ProcessControl;
ProcessControl CVar = {
{ 0, 0, 0 }, //dRef
{ 0, 0, 0 }, //dFeedback
{ 0, 0, 0 }, //Output Error
{ 0, 0, 0 }, //dControlOut
};
typedef struct
15
}Time;
0, //Sampling time ms
0, //Samping time s
0,
};
/****************************************************/
typedef struct
}PlantParas;
PlantParas PVar;
/****************************************************/
16
/PID Controller's parameters/
typedef struct
}DPID;
DPID PIDVar;
/****************************************************/
/* Hardware's IO Definitions*/
#define encoder0PinA 2
#define encoder0PinB 4
/****************************************************/
void setup()
pinMode(encoder0PinA, INPUT);
pinMode(encoder0PinB, INPUT);
17
digitalWrite(encoder0PinB, HIGH); // turn on pullup resistor
Serial.begin (115200);
SystemConfig();
MainLoop();
GetProcessingTime();
/****************************************************/
void MainLoop()
long lCountLoops;
18
lCountLoops = 0;
TimeVar.dTs_start = millis();
CVar.dFback[1][0] = CVar.dFback[0][0];
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;
CVar.dOutErr[2][0] = CVar.dOutErr[1][0];
CVar.dOutErr[1][0] = CVar.dOutErr[0][0];
19
refSigGenerate(TimeVar.dTsec*lCountLoops);
CVar.dCOut[0][0] = standardPID();
//CVar.dCOut[0][0] = CVar.dRef[0][0];
dacWrite(CVar.dCOut[0][0]);
TimeVar.dTs_past = TimeVar.dTs_start;
// Serial.print (CVar.dCOut[0][0]);
// Serial.print ("\t");
20
Serial.print (TimeVar.dTs_start);
Serial.print(",");
Serial.print (CVar.dRef[0][0]);
Serial.print(",");
Serial.println (CVar.dFback[0][0]);
// Serial.println ("\t");
void GetProcessingTime()
21
// Put your print function in here
Serial.println(TimeVar.dProcessTime_ms);
//Serial.print(" sec");
/****************************************************/
int k;
CVar.dRef[k][0] = SETPOINT;
return CVar.dRef[0][0];
float dVcOut;
dVcOut = Vout;
22
Vout = UMAX;
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
}
digitalWrite(M1,HIGH);
{analogWrite (E1,a);
digitalWrite(M1,LOW);
void doEncoder()
if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
encoder0Pos++;
} else {
encoder0Pos--;
24
/****************************************************/
float secondOrderSystem(void)
float fTemp;
+ 0.8*PVar.fb1*CVar.dCOut[1][0] + 0.9*PVar.fb2*CVar.dCOut[2][0];
return fTemp;
/****************************************************/
float standardPID(void)
25
return Uktemp;
float SystemConfig(void)
/Plant's Parameters/
Delta1 = Alpha1;
PIDVar.fUpperLimit = 40;
PIDVar.fLowerLimit = -40;
26
}
27