Hello, I have problem with my s-function

10 vues (au cours des 30 derniers jours)
Santosh Kumar Choudhary
Santosh Kumar Choudhary le 3 Sep 2021
The errors are:
Error in 'Quad4/s-function' while executing MATLAB S-function 'quadrotor_sfcn', flag = 1 (derivatives), at time 0.0.
Dimensions of arrays being concatenated are not consistent.
And this is my s-function:
function [sys,x0,str,ts] = quadrotor_sfcn(t,x,u,flag)
switch flag
% Initialization %
case 0
sizes = simsizes;
sizes.NumContStates = 6;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 3;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = [30 0 -20 0 10 0];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [0 0];
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1
sys=quadrotor(t,x,u);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3
sys = [x(1) x(3) x(5)];
case{2,4,9}
sys=[];
otherwise
error(['unhandledFlag=', num2str(flag)]);
end
% systems details
function xdot=quadrotor(t,x,u)
Jx=4.856*10^-3;
Jy=Jx;
Jz=8.801*10^-3;
Jr=3.357*10^-5;
m=0.468;l=0.225;
g=9.81;a1=(Jy-Jz)/Jx;
a2=Jr/Jx;a3=(Jz-Jx)/Jy;
a4=Jr/Jy;a5=(Jx-Jy)/Jz;
b1=l/Jx;b2=l/Jy;b3=1/Jz;
x1dot=x(2);
x2dot=x(4)*x(6)*a1-x(4)*a2*g+u;
x3dot=x(4);
x4dot=x(2)*x(6)*a3+x(2)*a4*g+u;
x5dot=x(6);
x6dot=x(4)*x(2)*a5+u;
xdot = [x1dot x2dot x3dot x4dot x5dot x6dot];

Réponse acceptée

Chunru
Chunru le 4 Sep 2021
Try the following:
xdot = [x1dot x2dot x3dot x4dot x5dot x6dot]';

Plus de réponses (0)

Catégories

En savoir plus sur Prepare Model Inputs and Outputs dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by