How to update PID after system identification with closed loop PID Autotuner?

In the literature, system identification can be performed using various techniques like RLS, ARX, ARMAX, Kalman Filter, or frequency domain methods. In quadcopter systems, PX4 uses an autotune mode with the RLS method, and after that, GMVC law is applied to find optimal PID parameters. Similarly, Simulink has a 'Closed-loop PID autotuner' block.
What I'm confused about is the process of updating the PID parameters after system identification, which is typically done in a closed-loop setup. For example, let’s say I have an active PID with P: 3, I: 4, D: 2.8. If we use GMVC or another method to identify new PID parameters based on the closed-loop system response, how do we update these PID values?
Directly replacing the old parameters with the new ones seems problematic because the system identification itself was based on the current closed-loop response. I’m considering that we might need to combine the old and new PID parameters into a series configuration, which implies having two different PIDs in sequence. However, this doesn't seem ideal.
Would it make more sense to extract the transfer function of the closed-loop system, remove the contribution of the current PID, and then apply the new PID parameters based on the open-loop transfer function by adding the old ones and test?

 Respuesta aceptada

Umar
Umar el 7 de Oct. de 2024

Hi @Cem ,

After going through your comments, when you identify new PID parameters based on closed-loop performance, you are essentially analyzing how the entire system (including the current PID controller) responds to disturbances and setpoint changes. Therefore, the identified parameters reflect not just the dynamics of the plant but also the influence of the existing controller. So, directly replacing old PID parameters with newly identified values can lead to instability or degraded performance because the new parameters are tuned based on a different closed-loop configuration, which includes the effects of your current PID settings. My recommended approach would extracting the transfer function of your closed-loop system. This will give you a mathematical representation of how your system behaves with the current PID controller. Also, from this transfer function, remove the contribution of your existing PID controller. This allows you to understand how the underlying plant behaves without any control influence. After decoupling, apply your new PID parameters derived from system identification to this open-loop model. You can then reintroduce feedback to see how well these new parameters perform in combination with your plant's dynamics. While combining old and new parameters into a series configuration may seem tempting, it complicates control logic and may not yield desirable results. Instead, consider using techniques such as gain scheduling or incremental tuning where new parameters gradually replace old ones based on performance metrics. Below is an example using MATLAB to illustrate how you might approach this problem programmatically:

% Given initial PID parameters
Kp_old = 3;
Ki_old = 4;
Kd_old = 2.8;
% Create a transfer function for the existing closed-loop system
s = tf('s');
G = 1/(s^2 + 5*s + 6); % Example plant transfer function
C_old = pid(Kp_old, Ki_old, Kd_old);
T_old = feedback(G * C_old, 1); % Closed-loop transfer function
% Extracting open-loop characteristics
G_open_loop = G * C_old;
% Perform system identification here (using GMVC or other)
% Assume new identified PID parameters are:
Kp_new = 5;
Ki_new = 3;
Kd_new = 1;
% Create a new PID controller with identified parameters
C_new = pid(Kp_new, Ki_new, Kd_new);
% Simulate both controllers for comparison
t = 0:0.01:10; % Time vector
u = ones(size(t)); % Step input
y_old = lsim(T_old, u, t);
y_new = lsim(feedback(G * C_new, 1), u, t);
% Plot results for analysis
figure;
plot(t, y_old, 'b', t, y_new, 'r--');
title('Closed-Loop Response Comparison');
xlabel('Time (s)');
ylabel('Output');
legend('Old PID', 'New PID');
grid on;

Please see attached.

After implementing new PID parameters based on your identified model, continuously monitor performance metrics such as overshoot, settling time, and steady-state error. Also, consider employing adaptive control strategies that allow for dynamic adjustments of PID parameters based on real-time performance feedback.

Remember always to simulate changes in a controlled environment before deploying them to real systems to avoid potential instability or failure.

Hope this helps.

Please let me know if you have any further questions.

6 comentarios

I have some questions. It is not entirely clear (from @Cem) how the PID gains were identified. However, I am unsure why you suggested the following configuration. Is this common in your practice of system identification? My professor never taught me system identification during my undergraduate studies, but I feel that something is off (two cascading PID controllers?), similar to how @Cem felt about updating the PID gains.

Dear @Sam Chak,

Thank you for your inquiry regarding the identification and application of PID parameters in control systems. I appreciate your engagement in this technical discussion, and I will address your concerns step by step to clarify the concepts involved.

Understanding PID Parameter Identification

PID (Proportional-Integral-Derivative) controller gains are typically identified through various methods, including system identification techniques, where the closed-loop response of a system is analyzed to derive optimal control parameters. The process involves observing how the system reacts to disturbances and setpoint changes, allowing for the tuning of PID parameters that best suit the dynamics of the plant.

Concerns About Cascading PID Controllers

Your observation about cascading two PID controllers is valid and warrants further explanation. The approach of directly combining old and new PID parameters in a series configuration can lead to complexities and potential instability. This method is generally not recommended unless there is a specific justification rooted in system dynamics or performance improvement strategies, such as gain scheduling or incremental tuning. These techniques allow for a more controlled adjustment of PID parameters based on real-time feedback without introducing significant complexity.

Common Practices in System Identification

The methodology suggested—extracting the transfer function from the closed-loop system to analyze its behavior without the existing controller—is a standard practice in control engineering. By decoupling the plant dynamics from the control influence, one can better understand how to apply new parameters effectively. This process ensures that the new PID gains are tuned specifically to the plant’s characteristics rather than being influenced by potentially outdated control strategies.

Simulation and Testing Before Deployment

As emphasized in my previous message, it is crucial to simulate any changes in a controlled environment prior to real-world implementation. This step helps identify potential issues such as instability or performance degradation that may arise from newly applied parameters. Continuous monitoring of performance metrics like overshoot, settling time, and steady-state error is also essential after implementation to ensure that the controller behaves as expected.

In nutshell, while the identification of new PID parameters is a critical aspect of control systems design, it requires careful consideration of existing configurations and potential interactions between old and new settings. The goal should always be to achieve stability and optimal performance while minimizing unnecessary complexity.

As I always mentioned you are extremely knowledgeable and I do learn a lot from you and rest of staff who are also technical experts such as @Robert Waterson, @Torsten, @Star Strider, @John D’Errico, and @dpb etc.

Hope this helps.

Hi @Umar,
To be more precise, the entire structure is defined in discrete time since the RLS method is used during the system identification processes. In the quadcopter system, I use the velocity reference, which is the input of the velocity controller for the axes, and the IMU sensor data, which is the output. This allows me to obtain the transfer function of a closed-loop system that includes a PID controller. By removing the PID controller from this process, I can find the plant transfer function. However, here's the problem: when using the inverse method to find the plant dynamics, the second-order system we initially obtained(by RLS) increases in order. I couldn’t apply a PID autotune method like GMVC on the plant transfer function because the complexity of PID tune increases. The current method I am working on only helps find PID parameters for a second-order discrete transfer function.
I’ve been reviewing different academic studies, but I haven’t found a solution yet. The main problem is that I am using GMVC based on the second-order transfer function I obtained. This leads us to the core issue—how to approach the implementation after obtaining the PID. As you mentioned, I tried the old and new PID parameters separately, but GMVC tends to give more minimal values, unlike the older PID structure, when determining the PIDs for a closed-loop system. This brought the idea of a cascade structure with two PIDs to my mind. Then, with two consecutive controllers, the results in Simulink became more reasonable. However, real-time tests of the quadcopter structure are still necessary to validate the controller design. Thanks for dynamic adjustment suggestion.
According to the results, it seems that a better PID autotuner method could be tried, or GMVC needs to be optimized based on the drone structure I am working on. Besides, as @Sam Chak asked about how I define the PID parameters, I am tuning the parameters based on flight tests in manual flight mode. I'm just analyzing the logs and checking the system responses based on parameters like rise time, settling time, and error deviation. That is why I am trying to automate this PID process.
%% Roll Axis System Identification
Ts = 0.005; %200 Hz
% PID parameters
Kp_r = 2.5; %rate p
Ki_r = 7.2; %rate i
Kd_r = 0.07; %rate gd
Tf = 20; %derivative filter time
% Controller design
Cz_r1 = pid(Kp_r,Ki_r,Kd_r,Tf,Ts); %Roll PID
% The Flight data obtained from tests
t = time_r; u = RRIR_R; y = RRIS_R; T = Ts;
Gz_r2 = RecursiveLeastSquare( u, y, 2, 2, 1, T);
% GMVC Law requires desired closed loop rise time, damping coefficient
rise_time = 0.13; %parameters are for testing only
damping_coeff = 0.8;
[Gp, Gi, Gd] = gmvcPid(Gz_r2, rise_time, damping_coeff);
%Gp:1.89 Gi:2.23 Gd:0.01
Cz_r2 = pid(Gp,Gi,Gd,Tf,Ts); %GMVC PID
% Open loop without realization
Gz_r2_r = minreal(Gz_r2/(Cz_r1*(1-Gz_r2))); %Plant Transfer Function
Cz_r3 = series(Cz_r1,Cz_r2);
Gz_r3_closed = feedback(Cz_r3*Gz_r2_r,1); %Roll PID - GMVC PID - Plant
Gz_r4_closed = feedback(Cz_r2*Gz_r2_r,1); %GMVC PID - Plant
figure;
step(Gz_r2,Gz_r3_closed,Gz_r4_closed);
legend('Closed Loop RLS Response','Cascaded PID Response','GMVC PID Response');
title('Closed-Loop Step Response');
xlim([0 1]);

Hi @Cem,

After going through your comments, your primary challenge seems to stem from the transition from a second-order system identified via RLS to a more complex plant transfer function. This complexity arises when you attempt to implement GMVC for PID tuning on a higher-order system, which can lead to difficulties in maintaining control stability and performance.

Identifying the Plant Dynamics: To effectively derive the plant transfer function, it’s crucial to ensure that your RLS implementation accurately captures the dynamics of your quadcopter. Given that you’re observing an increase in order, consider these strategies:

Model Order Reduction: After obtaining your higher-order model, you could apply techniques such as balanced truncation or Hankel norm approximation to reduce its order while retaining essential dynamics.

Validation of Data: Ensure that the input-output data used for system identification is representative of actual flight conditions. Noise or disturbances in the data can lead to misleading dynamics.

Tuning with GMVC:Given that GMVC parameters are derived based on your identified model, ensure that your rise time and damping coefficient align with practical performance expectations for quadcopter maneuvers. You mentioned that GMVC yields minimal values; this could indicate over-tuning or sensitivity to noise:

  • Parameter Adjustment: Experiment with slightly varying the rise time and damping coefficients within realistic bounds to observe changes in performance.
  • Iterative Tuning: Use a systematic approach where you iteratively refine parameters based on simulation results before applying them in real-time tests.

Cascade PID Structure: Implementing a cascade structure with two PID controllers can indeed enhance control performance by allowing one controller to manage fast dynamics (like roll rate) while another manages slower dynamics (like roll angle):

Controller Design: Ensure that each PID controller is tuned independently before integrating them into a cascade structure. This will help isolate issues related to each control loop.

Simulation Testing: Use Simulink extensively to simulate different scenarios and evaluate how each controller responds under various conditions.

Here are some considerations for you to help you out further.

Since you are analyzing logs based on flight tests, consider implementing an automated tuning algorithm like Ziegler-Nichols or even more advanced optimization algorithms such as Genetic Algorithms or Particle Swarm Optimization for adaptive PID tuning.

When transitioning from simulation to real-time application, ensure robust testing under varied environmental conditions (e.g., wind, payload changes). It might be useful to have a fallback mode where you can revert to manual tuning if automated methods fail.

Continue logging parameters like rise time, settling time, and error deviation during flight tests. This data will provide invaluable insights into how well your tuned parameters perform under real-world conditions.

Here are some suggestions for your existing code:

% Suggestion: Validate Gz_r2 before proceeding with GMVC
if rank(Gz_r2) < 2
  error('Identified model Gz_r2 is not valid for GMVC.');
end
% Use try-catch for robust error handling during GMVC
try
  [Gp, Gi, Gd] = gmvcPid(Gz_r2, rise_time, damping_coeff);
catch ME
  disp('Error during GMVC tuning:');
  disp(ME.message);
end
% Suggestion: Visualize response comparison more effectively
figure;
step(Gz_r2,Gz_r3_closed,Gz_r4_closed);
grid on;
legend('Closed Loop RLS Response','Cascaded PID Response','GMVC 
PID Response'); 
title('Closed-Loop Step Response');
xlabel('Time (seconds)');
ylabel('Response');
xlim([0 1]);

Hope this helps.

Hi @Umar,
I appreciate for your response. I will consider your clear explanations. In terms of GMVC adaptation, I will be trying model order reduction after obtainin open loop transfer function. I will also search for Genetic Algorithms and other methods like Neural Network methods.
For now, I am examining the RLS method and PID effects to see how reliable the system and how correct the obtained transfer function. I am trying to simulate open loop dynamics by adding PID with different parameters and try to observe effects in real time. Also I am logging the flight data and check system response.
For those who are interested in this method, PX4 has open source code already, you can also check the detailed structure linked in below.
https://www.youtube.com/watch?v=Yzhjlo5FnCU&ab_channel=PX4Autopilot-OpenSourceFlightControl.
Hi @Cem,
Thank you for your thoughtful response. I appreciate your willingness to consider the explanations provided and your proactive approach towards GMVC adaptation.
It is great to hear that you are planning to implement model order reduction following the acquisition of the open-loop transfer function. Exploring Genetic Algorithms and Neural Network methods will undoubtedly enhance your research, and I look forward to seeing how these approaches unfold in your work.
Your examination of the RLS method and PID effects sounds promising, particularly as you aim to evaluate the reliability of the system and validate the accuracy of the obtained transfer function. Simulating open-loop dynamics with varying PID parameters should yield valuable insights into system behavior, and logging flight data will be instrumental in assessing system responses effectively.
Thank you for sharing the link to PX4’s open-source code; it will certainly be a helpful resource for those interested in this methodology.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

Cem
el 27 de Sept. de 2024

Comentada:

el 17 de Oct. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by