0% found this document useful (0 votes)
24 views6 pages

PID Control

Uploaded by

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

PID Control

Uploaded by

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

3.

4 PID Controller in Arduino-Based Stepper Motor System

1. Introduction to PID Control

The Proportional-Integral-Derivative (PID) controller is a control loop mechanism widely


used in industrial systems for maintaining a desired setpoint by adjusting system inputs. In
the context of this Arduino-based stepper motor system, the PID controller adjusts the
movement of two stepper motors (one controlling the X-axis and the other the Y-axis) to
achieve precise positioning.

Định nghĩa PID: chị cho vào cho em cái định nghĩa này tóm gọn lại nhé, chỉ giữ lại ảnh và
công thức để cho vào báo cao thôi ạ

PID Basics

The PID circuit is often utilized as a control loop feedback controller and is commonly used for many
forms of servo circuits. The letters making up the acronym PID correspond to Proportional (P), Integral (I),
and Derivative (D), which represents the three control settings of a PID circuit. The purpose of any servo
circuit is to hold the system at a predetermined value (set point) for long periods of time. The PID circuit
actively controls the system so as to hold it at the set point by generating an error signal that is
essentially the difference between the set point and the current value. The three controls relate to the
time-dependent error signal. At its simplest, this can be thought of as follows: Proportional is dependent
upon the present error, Integral is dependent upon the accumulation of past error, and Derivative is the
prediction of future error. The results of each of the controls are then fed into a weighted sum, which
then adjusts the output of the circuit, u(t). This output is fed into a control device, its value is fed back
into the circuit, and the process is allowed to actively stabilize the circuit’s output to reach and hold at
the set point value. The block diagram below illustrates the action of a PID circuit. One or more of the
controls can be utilized in any servo circuit depending on system demand and requirement (i.e., P, I, PI,
PD, or PID).

Through proper setting of the controls in a PID circuit, relatively quick response with minimal overshoot
(passing the set point value) and ringing (oscillation about the set point value) can be achieved. Let’s
take as an example a temperature servo, such as that for temperature stabilization of a laser diode. The
PID circuit will ultimately servo the current to a Thermo Electric Cooler (TEC) (often times through control
of the gate voltage on an FET). Under this example, the current is referred to as the Manipulated Variable
(MV). A thermistor is used to monitor the temperature of the laser diode, and the voltage over the
thermistor is used as the Process Variable (PV). The Set Point (SP) voltage is set to correspond to the
desired temperature. The error signal, e(t), is then the difference between the SP and PV. A PID controller
will generate the error signal and then change the MV to reach the desired result. For example, if e(t)
states that the laser diode is too hot, the circuit will allow more current to flow through the TEC
(proportional control). Since proportional control is proportional to e(t), it may not cool the laser diode
quickly enough. In that event, the circuit will further increase the amount of current through the TEC
(integral control) by looking at the previous errors and adjusting the output to reach the desired value.
As the SP is reached (e(t) approaches zero), the circuit will decrease the current through the TEC in
anticipation of reaching the SP (derivative control).

Please note that a PID circuit will not guarantee optimal control. Improper setting of the PID controls can
cause the circuit to oscillate significantly and lead to instability in control. It is up to the user to properly
adjust the PID gains to ensure proper performance.

PID Theory

The output of the PID control circuit, u(t), is given as

where
Kp= Proportional Gain
Ki = Integral Gain
Kd = Derivative Gain
e(t) = SP - PV(t)

From here we can define the control units through their mathematical definition and discuss each in a
little more detail. Proportional control is proportional to the error signal; as such, it is a direct response to
the error signal generated by the circuit:

Larger proportional gain results in larger changes in response to the error, and thus affects the speed at
which the controller can respond to changes in the system. While a high proportional gain can cause a
circuit to respond swiftly, too high a value can cause oscillations about the SP value. Too low a value and
the circuit cannot efficiently respond to changes in the system.

Integral control goes a step further than proportional gain, as it is proportional to not just the magnitude
of the error signal but also the duration of the error.

Integral control is highly effective at increasing the response time of a circuit along with eliminating the
steady-state error associated with purely proportional control. In essence integral control sums over the
previous error, which was not corrected, and then multiplies that error by K i to produce the integral
response. Thus, for even small sustained error, a large aggregated integral response can be realized.
However, due to the fast response of integral control, high gain values can cause significant overshoot of
the SP value and lead to oscillation and instability. Too low, and the circuit will be significantly slower in
responding to changes in the system.

Derivative control attempts to reduce the overshoot and ringing potential from proportional and integral
control. It determines how quickly the circuit is changing over time (by looking at the derivative of the
error signal) and multiplies it by Kd to produce the derivative response.
Unlike proportional and integral control, derivative control will slow the response of the circuit. In doing
so, it is able to partially compensate for the overshoot as well as damp out any oscillations caused by
integral and proportional control. High gain values cause the circuit to respond very slowly and can leave
one susceptible to noise and high frequency oscillation (as the circuit becomes too slow to respond
quickly). Too low and the circuit is prone to overshooting the SP value. However, in some cases
overshooting the SP value by any significant amount must be avoided and thus a higher derivative gain
(along with lower proportional gain) can be used. The chart below explains the effects of increasing the
gain of any one of the parameters independently.

Parameter Settling Steady-State


Increased Rise Time Overshoot Time Error Stability
Kp Decrease Increase Small Change Decrease Degrade
Decrease
Ki Decrease Increase Increase Degrade
Significantly
Minor Minor Minor Improve (for small
Kd No Effect
Decrease Decrease Decrease Kd)

This report will cover how the PID controller is implemented in the robot code, starting with
the role of error, desired position, and actual position. We will then discuss manual tuning
and compare it to the Ziegler–Nichols method for PID tuning.

2. Error and Desired Position

The fundamental idea behind PID control is that the controller adjusts the output based on the
error — the difference between the desired position (setpoint) and the actual position
(current state of the system). In this code:

 Setpoint (Desired Position): The variables setpoint_X and setpoint_Y represent


the target positions for the X and Y axes, respectively. These positions are updated
when new commands are received via serial input.

cpp
Copy code
setpoint_X = x_mm;
setpoint_Y = y_mm;

 Actual Position: The current positions of the X and Y stepper motors are retrieved
from the Step_X and Step_Y stepper motor objects.

cpp
Copy code
actual_X = Step_X.currentPosition() / mm_to_steps;
actual_Y = Step_Y.currentPosition() / mm_to_steps;
 Error: The error is calculated as the difference between the desired position and the
actual position.

cpp
Copy code
double error_X = setpoint_X - actual_X;
double error_Y = setpoint_Y - actual_Y;

3. PID Control Components

The controller in this system computes the control output by combining the following terms:

 Proportional (P): Adjusts the control output in direct proportion to the current error.
A higher proportional gain (kp) results in a stronger response to the error. However, if
set too high, it can lead to oscillation.

cpp
Copy code
double output_X = kp * error_X;

 Integral (I): Accumulates past errors over time. This helps eliminate steady-state
errors but can lead to overshoot if set too high. Integral action is particularly useful in
systems where the error persists over long periods.

cpp
Copy code
integral_X += error_X * dt;
double output_X = kp * error_X + ki * integral_X;

 Derivative (D): Predicts future error based on the rate of change of the error. This
term is useful for reducing overshooting by dampening the control action. The
derivative gain (kd) moderates how much the system reacts to fast changes in error.

cpp
Copy code
double derivative_X = (error_X - previous_X) / dt;
double output_X = kp * error_X + ki * integral_X + kd * derivative_X;

The total control signal is:

cpp
Copy code
double output_X = kp * error_X + ki * integral_X + kd * derivative_X;

4. Manual PID Tuning

Manual tuning of the PID controller is often used when there are no precise mathematical
models of the system. The following steps can be followed for manual tuning:

1. Set initial gains: Start with ki = 0 and kd = 0, and increase kp until the system
starts responding but without excessive oscillation.
2. Tuning Proportional Gain (P): Adjust the proportional gain so that the system
reaches the desired position quickly. Too high of a value can cause oscillation; too
low can lead to a slow response. In this code, kp = 8:

cpp
Copy code
double kp = 8;

3. Adding Integral Action (I): Once the proportional gain is set, slowly increase the
integral gain (ki) to reduce steady-state error (persistent difference between the
setpoint and actual position). In the provided code, ki = 0, which implies no integral
action has been added yet. This could be because the system has minimal steady-state
error without it.
4. Tuning Derivative Action (D): Finally, introduce derivative gain (kd) to dampen the
system's response, preventing overshoot and improving stability. In this system, kd =
2 helps in reducing overshooting by anticipating changes in the error.

cpp
Copy code
double kd = 2;

Manual tuning provides flexibility but requires experimentation and observation to reach an
optimal configuration.

5. Ziegler–Nichols Tuning Method

The Ziegler–Nichols method is an empirical method used for tuning PID controllers, based
on testing the system to identify critical values of proportional gain and oscillations. It is a
systematic approach and consists of the following steps:

1. Set ki = 0 and kd = 0: This reduces the controller to a proportional controller (P-


only).
2. Increase kp: Gradually increase kp until the system enters continuous oscillations,
which means it reaches the ultimate gain (Ku).
3. Record the period of oscillations (Pu): Measure the time period between oscillations
when the system is at the critical gain.
4. Calculate PID values: Once Ku and Pu are known, the PID gains can be set
according to the following table: (vẽ lại cái bảng giúp em nhé)

Control Type Kp Ki Kd
P 0.5 Ku — —
PI 0.45 Ku 1.2 Ku / Pu —
Control Type Kp Ki Kd
PID 0.6 Ku 2 Ku / Pu Ku Pu / 8

For example, if after experimenting, the Ku is found to be 10, and the Pu is 5 seconds, the
PID gains would be calculated as:

 Kp = 0.6 × Ku = 0.6 × 10 = 6
 Ki = 2 × Ku / Pu = 2 × 10 / 5 = 4
 Kd = Ku × Pu / 8 = 10 × 5 / 8 = 6.25

Using Ziegler–Nichols provides a more structured approach compared to manual tuning,


which is based on trial and error.

6. Manual Tuning vs. Ziegler–Nichols

Both tuning methods are commonly used, but they serve different purposes:

 Manual Tuning: Provides more flexibility and is generally easier to apply for
systems where the response is well-understood by the operator. It is especially useful
for non-linear systems or those with unknown dynamics. However, manual tuning is
slower and may not result in optimal gains.
 Ziegler–Nichols: A more structured approach, ideal for systems that can tolerate
oscillation during tuning. It is quicker and provides a solid starting point for fine-
tuning. However, it assumes the system can undergo continuous oscillation, which
might not be suitable for all applications.

In this particular code, manual tuning is applied. The PID gains (kp = 8, ki = 0, kd =
2) were likely chosen based on observed behavior rather than through a systematic approach
like Ziegler–Nichols.

7. Conclusion

The provided code implements a PID controller to manage the precise movement of stepper
motors in an Arduino-based system. Manual tuning of the controller was used to set
proportional, integral, and derivative gains. This method, although time-consuming, allows
the system to achieve smooth and responsive behavior, especially when combined with
derivative action to reduce overshooting. Compared to the Ziegler–Nichols method, manual
tuning offers more flexibility but requires careful observation to achieve the desired response.

You might also like