SLPLOTBOT S-function for robot animation This is the S-function for animating the robot. It assumes input data u to be the joint angles q. Implemented as an S-function so as to update display at the end of each Simulink major integration step.
0001 %SLPLOTBOT S-function for robot animation 0002 % 0003 % This is the S-function for animating the robot. It assumes input 0004 % data u to be the joint angles q. 0005 % 0006 % Implemented as an S-function so as to update display at the end of 0007 % each Simulink major integration step. 0008 0009 function [sys,x0,str,ts] = splotbot(t,x,u,flag, robot) 0010 switch flag, 0011 0012 case 0 0013 % initialize the robot graphics 0014 [sys,x0,str,ts] = mdlInitializeSizes; % Init 0015 plot(robot, zeros(1, robot.n)) 0016 0017 case 2 0018 % come here on update 0019 if ~isempty(u), 0020 plot(robot, u'); 0021 drawnow 0022 end 0023 ret = []; 0024 case {1, 4, 9} 0025 ret = []; 0026 end 0027 % 0028 %============================================================================= 0029 % mdlInitializeSizes 0030 % Return the sizes, initial conditions, and sample times for the S-function. 0031 %============================================================================= 0032 % 0033 function [sys,x0,str,ts]=mdlInitializeSizes 0034 0035 % 0036 % call simsizes for a sizes structure, fill it in and convert it to a 0037 % sizes array. 0038 % 0039 % Note that in this example, the values are hard coded. This is not a 0040 % recommended practice as the characteristics of the block are typically 0041 % defined by the S-function parameters. 0042 % 0043 sizes = simsizes; 0044 0045 sizes.NumContStates = 0; 0046 sizes.NumDiscStates = 0; 0047 sizes.NumOutputs = 0; 0048 sizes.NumInputs = -1; 0049 sizes.DirFeedthrough = 1; 0050 sizes.NumSampleTimes = 1; % at least one sample time is needed 0051 0052 sys = simsizes(sizes); 0053 0054 % 0055 % initialize the initial conditions 0056 % 0057 x0 = []; 0058 0059 % 0060 % str is always an empty matrix 0061 % 0062 str = []; 0063 0064 % 0065 % initialize the array of sample times 0066 % 0067 ts = [0 0]; 0068 0069 % end mdlInitializeSizes