function [sys,x0,str,ts] = PID(t,x,u,flag)switch flag, case 0, [sys,x0,str,ts]=mdlInitializeSizes; case 3, sys=mdlOutputs(t,x,u); case{1,2,4,9} sys=[]; otherwise error('UnhandledFlag=', num2str(flag));endfunction [sys,x0,str,ts]=mdlInitializeSizessizes = simsizes;sizes.NumContStates = 0;sizes.NumDiscStates = 0;sizes.NumOutputs = 3;sizes.NumInputs = 7;sizes.DirFeedthrough = 1;sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);x0 = [];str = [];ts = [0 0];function sys=mdlOutputs(t,x,u)global kp ki kdkp=5;ki=0,0001;kd=50;ex=u(1);ey=u(2);tpex=u(3);tpey=u(4);dhex=u(5);dhey=u(6);pdthe=u(7);V=kp*[ex;ey]+ki*[tpex;tpey]+kd*[dhex;dhey];u1=V'*[0;1]+pdthe;u2=V'*[-sqrt(3)/2;-0,5]+pdthe;u3=V'*[-sqrt(3)/2;-0,5]+pdthe;%u4=V'*[-sqrt(3)/2;-0,5]+pdthe;
%u5=V'*[-sqrt(3)/2;-0,5]+pdthe;
sys(1)=u1;sys(2)=u2;sys(3)=u3;
I get a error like that: How can I solve?
An error occurred while running the simulation and the simulation was terminated
Caused by:
- Error in 'omnirobotcontrol/S-Function' while executing MATLAB S-function 'PID', flag = 3 (output), at time 0.0.
- Dimensions of arrays being concatenated are not consistent.
Best Answer