Positioning a linear servo motor using a PID controller

Now we can implement discrete time PID control function.In the sample C code (See code sheet below)The names of variables and constants closely match the corresponding elements in mathematical equations. This code can be executed on each iteration of the PID firmware, typically within a timer interrupt configured to trigger each iteration. time millisecond.

/* Current Error - Proportional term */
e = r - y;

/* Accumulated Error - Integral term */
totalError += e;

/* Difference of Error - Derivative term */
deltaError = e - previousError;

/* PID control */
u = Kp * e + Ki * (totalError * T) + Kd * (deltaError / T);

/* Also prepare for next iteration – set previous to Current Error */
previousError = e;

All that’s left to do is assign an appropriate value to the PID gain Kp, KI, and Kd So that the system performs correctly when asked to move to the selected set point. We will manually select different values ​​for these gains to study their effect on position control, and in the process demonstrate a general approach to tuning them. We’ll also take a closer look at the purpose of each item in the control function.

PID gain tuning

There are several criteria for evaluating system performance, including time to die, Rise Time, overshoot, stable scheduleand Steady-state error. Although performance expectations should be defined based on these criteria before adjusting PID gains, such expectations depend on the requirements of the application. Therefore, for the purposes of this article, it will suffice to provide some sense of when adjustments to different gains affect various criteria.

Every Kp, KI, and Kd Given the selected setpoint, the gains will be adjusted individually, and in that order. More specifically, the code will set one of the gains to a different value each time it is executed, and set the value of r to 700.

As for the relevance of this value of 700, the reader should remember Current position is a digital value representing the voltage obtained from the actuator potentiometer, and Current position Now represented by the variable y in our code.this Set location–represent The variable r in our code is a numeric value in the same range, as mentioned before, between 0 and 1023 if the ADC has 10-bit resolution. Therefore, a setpoint value of 700 is reasonable, albeit arbitrary.

Tuning Kp Close to target location

Kp is the proportional gain. The proportional term of the control function compensates for the current error by moving the linear actuator with a signal proportional to the current error. It makes sense to use a proportional term to bring the current position closer to the target, since the error is the difference between the actuator’s set position and its current position. The proportional term causes the control function to seek to reduce it to zero.

In the first step of tuning, we set the integral and differential gains KI and Kd Zero and increase proportional gain Kp until the actuator stabilizes near the target position (700). Proportional gain that is too high can cause oscillation.

chart in Figure 5 Shows how the actuator’s current position changes over time for different values Kp.we will choose Kp = 1, it is observed that it causes the current position to stabilize near the target with the fastest stabilization time.

Source link


Your email address will not be published. Required fields are marked *