필터 지우기
필터 지우기

Algebraic loop in MRAC discrete model

조회 수: 47 (최근 30일)
Yovel
Yovel 2024년 7월 8일 16:04
댓글: Umar 2024년 7월 15일 23:58
Hello everyone.
I have this system I built that represents an RMAC model
After the system worked continuously as it should, I converted it to discrete with a sampling time of 0.01
I get an error that the system enters an algebraic loop and I am unable to converge to the desired values. (The output of the system is increased to very, very high values)
I tried to put a unit delay but it neither helps nor leads to entertainment
what can be done? I would really appreciate some help.. I tried everything possible
Also, should I change the sampling time of each block to 0.01 or is it ok to leave -1?
Many thanks to everyone who helps
errors:
Error:'sim2/discrete plant2' or the model referenced by it contains a block that updates persistent or state variables while computing outputs and is not supported in an algebraic loop. It is in an algebraic loop with the following blocks.
Error:Input ports (1) of 'sim2/Adaptive Mechanism_known parameters_ discrete2/MATLAB Function1' are involved in the loop.
and more..

답변 (1개)

Umar
Umar 2024년 7월 8일 16:12
편집: Walter Roberson 2024년 7월 14일 18:52
Hi Yovel,
When dealing with algebraic loop errors in a discrete RMAC model, it is crucial to understand the nature of the problem and implement appropriate solutions. Algebraic loops occur when a block updates persistent or state variables while computing outputs, creating a dependency loop that disrupts the system's stability and convergence.
To address the algebraic loop issue in your discrete RMAC model, consider the following steps:
1. Break the Algebraic Loop
One effective approach is to break the algebraic loop by introducing a discrete-time delay element in the loop. While you mentioned that using a unit delay did not resolve the problem, you may need to carefully analyze the loop structure and identify the specific blocks causing the loop. Try introducing delays at strategic points within the loop to break the dependency chain.
% Example of introducing a delay to break the algebraic loop
delayBlock = dsp.Delay(1); % Create a one-sample delay block
2. Check Block Dependencies
Review the blocks involved in the algebraic loop, especially those updating persistent or state variables. Ensure that the dependencies are correctly defined and that no block is inadvertently causing the loop by updating variables at inappropriate times.
3. Adjust Sampling Time
Regarding the sampling time for each block in your model, it is generally advisable to maintain consistency with the overall system sampling time. In your case, setting a sampling time of 0.01 for all blocks should help ensure synchronization and proper functioning of the discrete RMAC model.
% Set sampling time for a block to 0.01
block.SampleTime = 0.01;
4. Debugging and Validation
Perform thorough debugging and validation of your model to identify any other potential issues that may be contributing to the algebraic loop error. Check for data dependencies, signal flows, and block configurations to ensure the model's correctness.
By following these steps and carefully analyzing the structure of your discrete RMAC model, you can effectively troubleshoot and resolve the algebraic loop error. Remember to test the modified model iteratively to verify its stability and convergence under different scenarios.
If you encounter further challenges or need additional assistance, feel free to provide more details about your model's specific components for a more tailored solution. Good luck with resolving the algebraic loop error in your discrete RMAC model!
  댓글 수: 13
Umar
Umar 2024년 7월 15일 18:14
Hi Yovel,
It seems that Walter edited my code because I do recall inserting code with fixing your error observed in your recent code and now it’s gone. You asked,if yiu have another idea how to rush the controller to overcome the delay. I already mentioned in my previous post but I will post the same comments verbatim.
Suggested solution to your problem
Going back to your comments about “The reference model and the controller are sampled every 0.3 seconds and the plant's system is sampled continuously. I was asked to think of an idea to improve performance in a discrete time Is it possible to add something to the controller \ to the system to reduce the error resulting from the delay besides changing the sampling time” and implementing it into your code, there are several approaches to improve the performance of the discrete time control system and reduce the error resulting from the delay. Please see solutions to your mentioned issues by updating your code. Predictive Control:In your provided code, there is already a reference model (y_mk) that represents the desired output. To reduce the error resulting from the delay, you can update the control input (uk) using the predictive model. % Update control input using predictive model uk = h_hat * ddy_rk - k * zk + a1_hat * dy_pk + a2_hat * y_pk + b1_hat * (dy_pk^2) + b2_hat * (y_pk^2); By incorporating the predictive model into the control input calculation, the controller can anticipate the future behavior of the system and adjust the control action accordingly Adaptive Control: In your provided code, there are adaptive controller parameters (h_hat, a1_hat, a2_hat, b1_hat, b2_hat) that are updated based on the error (ek) and its derivatives. To reduce the error resulting from the delay, you can update these parameters using adaptive control techniques. % Adaptive controller parameters - Update dh_hat = -gamma * zk * ddy_rk; da1_hat = -gamma * zk * dy_pk; da2_hat = -gamma * zk * y_pk; db1_hat = -gamma * zk * dy_pk^2; db2_hat = -gamma * zk * y_pk^2; % Update adaptive controller parameters h_hat = h_hat + dh_hat * T; a1_hat = a1_hat + da1_hat * T; a2_hat = a2_hat + da2_hat * T; b1_hat = b1_hat + db1_hat * T; b2_hat = b2_hat + db2_hat * T; By updating the adaptive controller parameters based on the error and its derivatives, the controller can continuously adjust its behavior to reduce the error resulting from the delay. Error Compensation: Another approach is to directly compensate for the error resulting from the delay. This can be achieved by introducing additional terms in the control input calculation that specifically target the delay-related error. In the provided code, you can add a compensation term to the control input calculation. % Add error compensation term to control input uk = h_hat * ddy_rk - k * zk + a1_hat * dy_pk + a2_hat * y_pk + b1_hat * (dy_pk^2) + b2_hat * (y_pk^2) - 4 * dy_pk + 5 * y_pk; By adding the error compensation term (- 4 * dy_pk + 5 * y_pk) to the control input calculation, the controller can directly compensate for the error resulting from the delay. By implementing these approaches, you can enhance the performance of the control system and reduce the error resulting from the delay. Please let me know if you have any further questions.
Umar
Umar 2024년 7월 15일 23:58

Hi Yovel,

I do understand your frustration not having this problem resolved. Could you provide details about what you want your code to do, I demonstrated examples in my previous code to help you understand the concept of implementing predictor or an observer in the control loop to reduce the error resulting from the delay because they can estimate the system's current state based on past information, compensating for delays. Predictors on one hand use past inputs and outputs to forecast the system's behavior, while observers on the other hand estimate the system's internal state. These tools help in making real-time adjustments, reducing errors caused by delays and enhancing system performance. When you wrote a lengthy code with no comments incorporated, it made my job little difficult to analyze your code but I still tried my best to analyze your code and provided my comments to improve your code. I do appreciate your efforts implementing an adaptive control algorithm, trying to calculate control inputs based on the error between a reference model and a plant model, and updating adaptive controller parameters to improve the control performance. To reduce the error in control loop, I will help you understand by providing example snippet code which will help you to implement this concept in your code to resolve the issue. So, I implemented an adaptive control algorithm in Matlab. The algorithm calculates control inputs based on the error between a reference model and a plant model. It then updates adaptive controller parameters to enhance control performance. Pay close attention to part of the snippet code below, “Calculate control input based on error”

% Adaptive Control Algorithm Implementation

% Define plant model parameters

A = [0.5, 0.2; 0.1, 0.3]; B = [1; 0]; C = [1, 0]; D = 0;

% Define reference model parameters

Am = [0.4, 0.1; 0.05, 0.35]; Bm = [1; 0]; Cm = [1, 0]; Dm = 0;

% Initialize adaptive controller parameters

theta = zeros(4, 1); % [theta1; theta2; theta3; theta4]

% Simulation loop

for k = 1:100

    % Calculate control input based on error
    e = ym(k) - y(k); % Calculate error between plant output y and reference model output ym
    u(k) = -theta(1)*e - theta(2)*y(k) - theta(3)*u(k-1); % Calculate control input u
    % Update adaptive controller parameters
    theta_dot = 0.1 * [e; y(k); u(k-1); u(k)] * e'; % Update rule for theta
    theta = theta + theta_dot; % Update theta parameters
end

You probably already know what is the above code snippet doing but I still want you to understand about the simulation loop where the code calculates the control input 'u' based on the error 'e' between the plant output 'y' and the reference model output 'ym'. The control input is updated using a linear combination of the error and previous control inputs.

Hopefully, now, following these steps and suggestions should help you answer your question, “ Is it possible to add something to the controller \ to the system to reduce the error resulting from the delay?”

Please let me know if you have any further questions.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Additional Math and Discrete에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by