when i am trying to using raisimMatlab in matlab simulink s-function to simulate robot dynamics, it crashed.My s-function is
function [sys,x0,str,ts,simStateCompliance] = wlr4p_sim(t,x,u,flag, param)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes(param);
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1,
sys=mdlDerivatives(t,x,u);
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys=mdlUpdate(t,x,u,param);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u);
%%%%%%%%%%%%%%%%%%%%%%%
% GetTimeOfNextVarHit %
%%%%%%%%%%%%%%%%%%%%%%%
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
case 9,
sys=mdlTerminate(t,x,u);
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes(param)
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded. This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 27;
sizes.NumOutputs = 4;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%initialize raisim
addpath('/home/mr/raisim_ws/raisim/raisimLib/raisim/linux/lib');
raisim('license', '/home/mr/.raisim/activation.raisim');
raisim('init', '/home/mr/raisim_ws/world.xml', 8080);
raisim('addArticulatedSystem', 'wlr4p', strcat(pwd, '/../rsc/wlr4p/urdf/wlr4p.urdf'));
%
% initialize the initial conditions
%
q0 = [0.0, 0.0, 0.72, 1.0, 0.0, 0.0, 0.0, 0.0, 0.87, -1.54, 0.0, 0.87, -1.54, 0.0]';
v0 = zeros(13, 1);
x0 = [q0;v0];
raisim('setGeneralizedCoordinate','wlr4p',q0);
raisim('setGeneralizedVelocity','wlr4p',v0);
%set pd gains for raisim
raisim('setPGains','wlr4p',param.pGains);
raisim('setDGains','wlr4p',param.dGains);
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [param.dt 0];
% Specify the block simStateCompliance. The allowed values are:
% 'UnknownSimState', < The default setting; warn and assume DefaultSimState
% 'DefaultSimState', < Same sim state as a built-in block
% 'HasNoSimState', < No sim state
% 'DisallowSimState' < Error out when saving or restoring the model sim state
simStateCompliance = 'UnknownSimState';
% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u)
sys = [];
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u,param)
%lw velocity target
param.dTarget(10) = u(1);
%rw velocity target
param.dTarget(13) = u(2);
%set pd target
raisim('setPTarget','wlr4p',param.pTarget);
raisim('setDTarget','wlr4p',param.dTarget);
raisim('integrate1');
raisim('integrate2');
q1 = raisim('getGeneralizedCoordinate', 'wlr4p');
v1 = raisim('getGeneralizedVelocity', 'wlr4p');
sys = [q1;v1];
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
%output is Wz,Vx,pitch in body frame
R = raisim('getFrameOrientation','wlr4p','pelvic');
w = raisim('getFrameAngularVelocity','wlr4p','pelvic');
v = raisim('getFrameVelocity','wlr4p','pelvic');
w_B = R'*w;
v_B = R'*v;
pitch = getEulerYPR(R)
sys = [w_B(2);w_B(3);v_B(1);pitch];
% end mdlOutputs
%
%=============================================================================
% mdlGetTimeOfNextVarHit
% Return the time of the next hit for this block. Note that the result is
% absolute time. Note that this function is only used when you specify a
% variable discrete-time sample time [-2 0] in the sample time array in
% mdlInitializeSizes.
%=============================================================================
%
function sys=mdlGetTimeOfNextVarHit(t,x,u)
sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;
% end mdlGetTimeOfNextVarHit
%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%=============================================================================
%
function sys=mdlTerminate(t,x,u)
raisim('quit');
sys = [];
% end mdlTerminate
when i am trying to using raisimMatlab in matlab simulink s-function to simulate robot dynamics, it crashed.My s-function is
And this is crash logs
Is there anything wrong, or any way to use raisim in simulink properly? Thanks