声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2862|回复: 0

[控制系统类] 请教SIMULINK仿真:during flag=3 call must be a real vector of length 3.

[复制链接]
发表于 2008-3-31 10:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我用SIMULINK仿真三关节机器手,用的是拉格朗日动力学方程建模、滑模控制算法,模型中的矩阵给一些简单的值时仿真程序可以调的通,但是当把实际推导出来的公式代入模型中的矩阵时,程序调不通。
出现的错误为:
Output returned by S-function 'sgj_s' in 'sgj/S-Function' during flag=3 call must be a real vector of length 3.
还有
Warning: Unable to reduce the step size without violating minimum step size of 1.028677501121793e-015 at time 0.2895469756710336.  Continuing simulation with the step size restricted to 1.028677501121793e-015 and using an effective relative error tolerance of 1.845523258936908, which is greater than the specified relative error tolerance of 0.1.
S函数如下:(望高手指点,不胜感激)
function [sys,x0,str,ts] = s_function(t,x,u,flag)
switch flag,
  
  case 0,
    [sys,x0,str,ts]=mdlInitializeSizes;
    case 3,
    sys=mdlOutputs(t,x,u);
  
  case {2,4,9}
    sys=[];
  
  otherwise
    error(['Unhandled flag = ',num2str(flag)]);
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes

sizes = simsizes;
sizes.NumContStates  = 0;
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 3;
sizes.NumInputs      = 15;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 0;   % at least one sample time is needed
sys = simsizes(sizes);

x0  = [];

str = [];

ts  = [];
% end mdlInitializeSizes

%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
q1d=sin(pi*t);
dq1d=pi*cos(pi*t);
ddq1d=-pi^2*sin(pi*t);
dddq1d=-pi^3*cos(pi*t);
q2d=cos(pi*t);
dq2d=-pi*sin(pi*t);
ddq2d=-pi^2*cos(pi*t);
dddq2d=pi^3*sin(pi*t);
q3d=sin(pi*t);
dq3d=pi*cos(pi*t);
ddq3d=-pi^2*sin(pi*t);
dddq3d=-pi^3*cos(pi*t);
ddqd=[ddq1d;ddq2d;ddq3d];
dddqd=[dddq1d;dddq2d;dddq3d];
x=[u(4);u(5);u(6);u(7);u(8);u(9)];
dx=[u(10);u(11);u(12);u(13);u(14);u(15)];
e1=x(1)-q1d;
de1=x(2)-dq1d;
dde1=dx(2)-ddq1d;
e2=x(3)-q2d;
de2=x(4)-dq2d;
dde2=dx(4)-ddq2d;
e3=x(5)-q3d;
de3=x(6)-dq3d;
dde3=dx(6)-ddq3d;
e=[e1;e2;e3];
de=[de1;de2;de3];
dde=[dde1;dde2;dde3];
n1=[5 0 0;0 5 0;0 0 5];
n2=[10 0 0;0 10 0;0 0 10];
n=[25 0 0;0 25 0;0 0 25];
s=dde+n1*de+n2*e;
g=9.8;
M11=3.67+3*cos(x(3))+cos(x(5))+cos(x(3)+x(5));
M12=2.33+1.5*cos(x(3))+cos(x(5))+0.5*cos(x(3)+x(5));
M13=0.33+0.5*cos(x(5))+0.5*cos(x(3)+x(5));
M21=M12;
M22=1.67+cos(x(5));
M23=0.33+0.5*cos(x(5));
M31=M13;
M32=M23;
M33=0.33;
M=[M11 M12 M13;M21 M22 M23;M31 M32 M33];
dM11=-3*sin(x(3))*x(4)-sin(x(5))*x(6)-sin(x(3)+x(5))*(x(4)+x(6));
dM12=-1.5*sin(x(3))*x(4)-sin(x(5))*x(6)-0.5*sin(x(3)+x(5))*(x(4)+x(6));
dM13=-0.5*sin(x(5))*x(6)-0.5*sin(x(3)+x(5))*(x(4)+x(6));
dM21=dM12;
dM22=-sin(x(5))*x(6);
dM23=-0.5*sin(x(5))*x(6);
dM31=dM13;
dM32=dM23;
dM33=0;
dM=[dM11 dM12 dM13;dM21 dM22 dM23;dM31 dM32 dM33];

C11=-(3*sin(x(3))-sin(x(3)+x(5)))*x(4);
C12=-(1.5*sin(x(3))+0.5*sin(x(3)+x(5)))*x(3)-(sin(x(5))+sin(x(3)+x(5)))*x(6);
C13=-0.5*(sin(x(5))+sin(x(3)+x(5)))*x(6);
C21=(0.5*sin(x(3)+x(5))+sin(x(3)))*x(2);
C22=-0.5*sin(x(5))*x(4);
C23=-0.5*sin(x(5))*x(6)-sin(x(5))*x(2);
C31=0.5*(sin(x(5))+sin(x(3)+x(5)))*x(2)+sin(x(5))*x(4);
C32=0.5*sin(x(5))*x(4);
C33=0;
C=[C11 C12 C13;C21 C22 C23;C31 C32 C33];

dC11=-(3*cos(x(3))*x(4)+cos(x(3)+x(5))*(x(4)+x(6)))*x(4)-(sin(x(3))+sin(x(3)+x(5)))*dx(4);
dC12=-(1.5*cos(x(3))*x(4)+0.5*cos(x(3)+x(5))*(x(4)+x(6)))*x(3)-(1.5*sin(x(3))+0.5*sin(x(3)+x(5)))*x(4)-(cos(x(5))*x(6)+cos(x(3)+x(5))*(x(4)+x(6)))*x(6)-(sin(x(5))+sin(x(3)+x(5)))*dx(6);
dC13=-0.5*(cos(x(5))*x(6)+cos(x(3)+x(5))*(x(4)+x(6)))*x(6)-0.5*(sin(x(5))+sin(x(3)+x(5)))*dx(6);
dC21=(0.5*cos(x(3)+x(5))*(x(4)+x(6))+cos(x(3))*x(4))*x(2)+(0.5*sin(x(3)+x(5))+sin(x(3)))*dx(2);
dC22=-0.5*(cos(x(5))*x(6)*x(4)-0.5*sin(x(5))*dx(4));
dC23=-0.5*(cos(x(5))*x(6)*x(6)+sin(x(5))*dx(6))-(cos(x(5))*x(6)*x(2)+sin(x(5))*dx(2));
dC31=0.5*(cos(x(5))*x(6)+cos(x(3)+x(5))*(x(4)+x(6)))*x(2)+0.5*(sin(x(5))+sin(x(3)+x(5)))*dx(2)+cos(x(5))*x(6)*x(4)+sin(x(5))*dx(4);
dC32=0.5*(cos(x(5))*x(6)*x(4)+sin(5)*dx(4));
dC33=0;
dC=[dC11 dC12 dC13;dC21 dC22 dC23;dC31 dC32 dC33];

G1=2.5*g*cos(x(1))+0.5*g*cos(x(1)+x(3))+0.5*g*cos(x(1)+x(3)+x(5));
G2=1.5*g*cos(x(1)+x(3))+0.5*g*cos(x(1)+x(3)+x(5));
G3=0.5*g*cos(x(1)+x(3)+x(5));
G=[G1;G2;G3];
dG1=-2.5*g*sin(x(1))*x(2)-0.5*g*sin(x(1)+x(3))*(x(2)+x(4))-0.5*g*sin(x(1)+x(3)+x(5))*(x(2)+x(4)+x(6));
dG2=-1.5*g*sin(x(1)+x(3))*(x(2)+x(4))-0.5*g*sin(x(1)+x(3)+x(5))*(x(2)+x(4)+x(6));
dG3=-0.5*g*sin(x(1)+x(3)+x(5))*(x(2)+x(4)+x(6));
dG=[dG1;dG2;dG3];

H0=M*(n1*dde+n2*de-dddqd)+C*(n1*de+n2*e-ddqd)-(dM+n*M)*[dx(2);dx(4);dx(6)]-(dC+n*C)*[x(2);x(4);x(6)]-(dG+n*G);
xite=[5 0 0;0 5 0;0 0 5];
ut=-inv(n)*(H0+xite*sign(s));
sys(1)=ut(1);
sys(2)=ut(2);
sys(3)=ut(3);

% end mdlOutputs
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-29 06:45 , Processed in 0.049195 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表