我在simulink中进行了设计,使用嵌入式matlab函数实现PID。 我的职责是:
function [u,integral,previous_error] = fcn(Kp,Td,Ti,error,previous_error1,integral1)
dt = 1;
Ki= Kp/Ti;
Kd=Kp*Td;
integral = integral1 + error*dt; % integral term
derivative = (error-previous_error1)/dt; % derivative term
u = Kp*error+Ki*integral+Kd*derivative; % action of control
previous_error=error;
%integral=integral;
end
这就是我的模型的样子:(整个模型的一部分)
我收到以下错误:
Simulink cannot solve the algebraic loop containing 'pid_block1/MATLAB Function' at time 2.2250754336053813E-8 using the TrustRegion-based algorithm due to one of the following reasons: the model is ill-defined i.e., the system equations do not have a solution; or the nonlinear equation solver failed to converge due to numerical issues.
To rule out solver convergence as the cause of this error, either
a) switch to LineSearch-based algorithm using
set_param('pid_block1','AlgebraicLoopSolver','LineSearch')
b) reducing the ode45 solver RelTol parameter so that the solver takes smaller time steps.
If the error persists in spite of the above changes, then the model is likely ill-defined and requires modification.
任何想法,为什么我得到它?
我应该在integral
和previous_error
使用全局变量吗?
提前谢谢。
答案 0 :(得分:0)
Erm ..除非您在此表单中有需要的具体原因,否则我强烈建议您使用Simulink块替换MATLAB功能块,例如:
等...
我发现代数循环问题真的很难摆脱,通常最好避免。我上面建议的方法可以用于大多数控制器类型,并且在过去对我来说非常好用。
如果问题是整洁的,您可以随时创建自己的“PID控制器”子系统或库部件。
如果您需要更多详细信息或关于如何执行此操作的图表,请与我们联系。