Lab Report Control I
Lab Report Control I
Class : EMD6M2A
1
1.0 Introduction
Motor is a device which transforms the electrical energy into mechanical energy. The
working principle of the motor is the interaction between the magnetic field and the current to
produce a force within the motor which helps the motor to do work. The motor principle is
basically based on Faraday's Law,which states that, it is the conservation of electrical and
mechanical energy. DC motor is one type of motor that uses the DC current to convert
electrical energy into mechanical energy. When the electric current passes through a coil in a
magnetic field, a magnetic force will be generated,which produces a torque in the DC motor.
2
Figure 2 : DC Motor(Analog)
A stepper motor is a special type of electric motor that moves in increments, or steps,
rather than turning smoothly as a conventional motor does. The size of the increment is
measured in degrees and can vary depending on the application. Typical increments are 0.9 or
1.8 degrees, with 400 or 200 increments thus representing a full circle. The speed of the
motor is determined by the time delay between each incremental movement. Inside the
device, sets of coils produce magnetic fields that interact with the fields of permanent
magnets. The coils are switched on and off in a specific sequence to cause the motor shaft to
turn through the desired angle. The motor can operate in either direction (clockwise or
counterclockwise). When the coils of a stepper motor receive current, the rotor shaft turns to
a certain position and then stays there unless or until different coils are energized. Unlike a
conventional motor, the stepper motor resists external torque applied to the shaft once the
shaft has come to rest with current applied. This resistance is called holding torque. Stepper
motors have been used in computer hard drives because they can be moved and positioned
with precision. They have also been used in various robot ic devices and as antennarotators.
3
1.1 The Differences Between DC and Stepper Motor
DC motors are analog motors, we can only send power signals (two wire) to the motor
to drive them. This means that we can use predictions to figure out where the motor will be
located over time within a relative margin of error (3-8%). DC motor systems were relatively
easy to develop around so we were able to develop our DC controllers in a short period of
time (matter of months). DC motor systems are definitely a great for the
budget minded shooter.
While the Stepper motor, Stepper motors are digital motors, we actually send position
signals (four wire) to the motor to drive them. This means that we can know exactly where
they are at all times. So for example,we want the system to start and end at specific points
and then we want the same motion to happen in a different timeframe,this is all possible with
very precise accuracy. Digital stepper motor systems are more complex to develop and
require a high level of electronics,programming and software, it's taken a lot more time and
resources to develop our stepper controller (matter of years). Stepper motor systems will tend
to be a little more expensive because of these development costs, particularly due to the
increased software development costs (iOS, Android, OSX, Windows).
In the scope of a mechanical control system, several items can be used to study the
stability of a particular system. For the laboratory experiment, the stability of the system was
studied by varying the input for Proportional Integral Derivative (PID) controller through the
manipulation of the Proportional Gain(KP), Integral Gain(KI) and Derivative Gain(KD). The
stability of the system was observed through the form of graphical interpretation to identify
items such as Disturbance rejection, Steady-state error, Peak time, Settling time and
Percentage Overshoot.
The control design process begins by defining the performance requirements. Control
system performance is often measured by applying a step function as the set point command
variable, and then measuring the response of the process variable. Commonly, the response is
quantified by measuring defined waveform characteristics. Rise Time is the amount of time
the system takes to go from 10% to 90% of the steady-state, or final, value. Percent
Overshoot is the amount that the process variable overshoots the final value, expressed as a
4
percentage of the final value. Settling time is the time required for the process variable to
settle to within a certain percentage (commonly 5%) of the final value. Steady-State Error is
the final difference between the process variable and set point. Note that the exact definition
of these quantities will vary in industry and academia.
2.0 Objectives
In this lab, students will implement closed loop position control by using proportional–
integral–derivative controller. Students also need to :
1. To apply fundamental knowledge and principles of control system for the Angular
Position Control System under statically balance condition.
2. To analyse the performance of the PID controller of the system.
5
3.0 Methodology
6
START
Referring Rejected
graph on
Matlab
Accepted
END
Figure 7 : Flowchart of the PBL Project Closed Loop PID Position Control System
7
4.0 Result and Analysis
Arduino code :
#define encoder0PinA 2
#define encoder0PinB 3
int E1 = 10; //M1 Speed Control
int M1 = 11; //M1 Direction Control
void setup()
{
pinMode(E1, OUTPUT);
pinMode(M1, OUTPUT);
pinMode(encoder0PinA, INPUT);
8
digitalWrite(encoder0PinA, HIGH); //turn on pullup resistor
pinMode(encoder0PinB, INPUT);
digitalWrite(encoder0PinB, HIGH); //turn on pullup resistor
attachInterrupt(0, doEncoder, RISING); //encoDER ON PIN 2
Serial.begin(9600);
}
void loop()
{
newposition = encoder0Pos;
newtime = millis();
pos = (newposition);
oldposition = newposition;
oldtime = newtime;
delay(0);
//PID equation
error = setpoint - pos;
pTerm = Kp * error;
integrated_error += error;
iTerm = Ki * constrain(integrated_error, -GUARD_GAIN, GUARD_GAIN);
dTerm = Kd * (error - last_error);
last_error = error;
U = K * (pTerm + iTerm + dTerm);
speedX = constrain(U, -100, 100);
if (error == 0)
{
STOP();
}
else
{
Motors();
9
}
Serial.print("\t position=");
Serial.print(pos);
Serial.print("\t error=");
Serial.print(error);
// Serial.print("\t PID=");
// Serial.print(U);
Serial.print("\t Time=");
Serial.println(newtime);
//Serial.print("t Speed=");
//Serial.println(speedX);
}
void doEncoder()
{
if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB))
{
encoder0Pos++;
}
else
{
encoder0Pos--;
}
}
void STOP()
{
digitalWrite(E1, 0);
analogWrite(M1, 0);
}
void Motors()
{
if (speedX > 0)
{
10
//forward
digitalWrite(E1, 0);
analogWrite(M1, speedX);
}
else
{
//backward
speedX = map(speedX, 0, -100, 0, 100);
digitalWrite(E1, 1);
analogWrite(M1, speedX);
}
}
TRIAL 1
300
250
200
150
100
50
0
-50 0 100 200 300 400 500 600
Time (ms)
11
Table 1 : Trial 1 of time and angular position
From the graph it can be seen that the graph has overshoot and a little bit of vibration
before the stopper completely stops. This shows that the stability of the stopper system is not
the best to be obtained. The system is assumed as underdamp.
12
TRIAL 2
350
300
250
200
150
100
50
0
-50 0 100 200 300 400 500 600
Time (ms)
13
From the graph, it can be seen that the system have become more stable as the
vibrations of the system has decreases or eliminate. However, the system still has a little
overshoot which indicates that the system still not the most stable graph obtained. The system
is assumed near critically damped.
TRIAL 3
300
250
200
150
100
50
0
-50 0 100 200 300 400 500 600
Time (ms)
14
Table 3 : Trial 3 of time and angular position
From the graph, the system has been eliminated of overshoot and extra vibration.
However, the system has longer time to reach the peak. Hence, causes the stopper to slow
down early before stopping. The result obtained is consider as near best graph. The system is
critically damp.
15
TRIAL 4
300
250
200
150
100
50
0
-50 0 100 200 300 400 500 600
Time(ms)
16
From the graph, it is seen that the overshoot and vibration is eliminated and the time
for it to reach the peak is faster. The graph obtained is considered the best graph. The stopper
system is a critically damp system.
5.0 Discussion
In this experiment, there are four trials that have been done to determine the perfect
graph and result. To get the perfect graph, the values of proportional gain (kp), integral gain
(ki), and derivative gain (kd) need to be discovered properly and carefully.
For trial 1, there are several values that have been set into the three variables and the
variables are proportional gain (kp), integral gain (ki), and derivative gain (kd). The value of
proportional gain (kp) is 0.8, the value of integral gain (ki) is 0.1 and the value of derivative
gain (kd) is 0.6. After the values for the three variables have been set, the graph has been
obtained as shown in the result. From the graph obtained, it can be seen that the graph was
fluctuated after it had reached at one point. After fluctuated for a certain time, the graph
started to constant until the end of the graph. From the graph, it can be concluded that the
values of proportional gain (kp), integral gain (ki), and derivative gain (kd) that have been set
in this trial was not suitable.
For trial 2, the values for proportional gain (kp), integral gain (ki), and derivative gain
(kd) that have been set are 0.64, 0.05 and 0.6 respectively. After the values for the three
variables have been set, the graph has been obtained as shown in the result. From the graph
obtained, the shape of the graph was better than the graph in trial one. From the graph also
can be seen that the graph was increased immediately before it was decreasing a little bit and
then it started to constant until the end of the graph. From the graph, it can be concluded that
the values of proportional gain (kp), integral gain (ki), and derivative gain (kd) that have been
set in this trial was not suitable.
For trial 3, the values for proportional gain (kp), integral gain (ki), and derivative gain
(kd) that have been set are 0.5, 0.02 and 0.3 respectively. After the values for the three
variables have been set, the graph has been obtained as shown in the result. From the graph
obtained, the shape of the graph was better than the graph in trial two. The graph was
proportionally increased and slowly reached the peak of the graph and then started to constant
until the end of the graph. From the graph, it can be concluded that the values of proportional
17
gain (kp), integral gain (ki), and derivative gain (kd) that have been set in this trial was not
suitable.
For trial 4, the values for proportional gain (kp), integral gain (ki), and derivative gain
(kd) that have been set are 1.5, 0.6 and 0.7 respectively. After the values for the three
variables have been set, the graph has been obtained as shown in the result. From the graph
obtained, the shape of the graph was better than the other graphs. The graph was
proportionally increased and then immediately reached the peak. After reached the peak of
the graph, it started to constant until the end of the graph. From the graph, it can be concluded
that the values of proportional gain (kp), integral gain (ki), and derivative gain (kd) that have
been set in this trial was suitable and the best compared with others.
6.0 Conclusion
The PID control algorithm is a robust and simple algorithm that is widely used in the
industry. The algorithm has sufficient flexibility to yield excellent results in a wide variety of
applications and has been one of the main reasons for the continued use over the years. NI
LabVIEW and NI plug-in data acquisition devices offer higher accuracy and better
performance to make an excellent PID control system.
7.0 References
1. Retrieved from dynapar -
https://www.dynapar.com/technology/encoder_basics/motor_encoders/
2. Retrieved from citron - https://www.cytron.io/p-md10c
3. Retrieved from dynamic perception - https://support.dynamicperception.com/hc/en-
us/articles/202986595-What-is-the-difference-between-DC-motors-and-Stepper-
motors-
4. Retrieved from Chegg-Study - https://www.chegg.com/homework-
help/definitions/dc-motor-2
5. Retrieved from Tech Target - https://whatis.techtarget.com/definition/stepper-motor
6. Retrieved from Lab Sheet PBL Project I from i-Learn
18