SLACCEL S-function for robot acceleration This is the S-function for computing robot acceleration. It assumes input data u to be the state vector [q qd]. Implemented as an S-function to get around vector sizing problem with Simulink 4.
0001 %SLACCEL S-function for robot acceleration 0002 % 0003 % This is the S-function for computing robot acceleration. It assumes input 0004 % data u to be the state vector [q qd]. 0005 % 0006 % Implemented as an S-function to get around vector sizing problem with 0007 % Simulink 4. 0008 0009 function [sys,x0,str,ts] = slaccel(t,x,u,flag, robot) 0010 switch flag, 0011 0012 case 0 0013 % initialize the robot graphics 0014 [sys,x0,str,ts] = mdlInitializeSizes(robot); % Init 0015 0016 case {3} 0017 % come here to calculate derivitives 0018 sys = accel(robot, u); 0019 case {1, 2, 4, 9} 0020 sys = []; 0021 end 0022 % 0023 %============================================================================= 0024 % mdlInitializeSizes 0025 % Return the sizes, initial conditions, and sample times for the S-function. 0026 %============================================================================= 0027 % 0028 function [sys,x0,str,ts]=mdlInitializeSizes(robot) 0029 0030 % 0031 % call simsizes for a sizes structure, fill it in and convert it to a 0032 % sizes array. 0033 % 0034 % Note that in this example, the values are hard coded. This is not a 0035 % recommended practice as the characteristics of the block are typically 0036 % defined by the S-function parameters. 0037 % 0038 sizes = simsizes; 0039 0040 sizes.NumContStates = 0; 0041 sizes.NumDiscStates = 0; 0042 sizes.NumOutputs = robot.n; 0043 sizes.NumInputs = 3*robot.n; 0044 sizes.DirFeedthrough = 1; 0045 sizes.NumSampleTimes = 1; % at least one sample time is needed 0046 0047 sys = simsizes(sizes); 0048 0049 % 0050 % initialize the initial conditions 0051 % 0052 x0 = []; 0053 0054 % 0055 % str is always an empty matrix 0056 % 0057 str = []; 0058 0059 % 0060 % initialize the array of sample times 0061 % 0062 ts = [0 0]; 0063 0064 % end mdlInitializeSizes