sfdrawrobot.m

00001 function sfdrawrobot(block)
00002 %MSFUNTMPL A template for an M-file S-function
00003 %   The M-file S-function is written as a MATLAB function with the
00004 %   same name as the S-function. Replace 'msfuntmpl' with the name
00005 %   of your S-function.  
00006 %
00007 %   It should be noted that the M-file S-function is very similar
00008 %   to Level-2 C-Mex S-functions. You should be able to get more 
00009 %   information for each of the block methods by referring to the
00010 %   documentation for C-Mex S-functions.
00011 %  
00012 %   Copyright 2003-2006 The MathWorks, Inc.
00013 %   $Revision: 1.1.6.10 $  
00014   
00015 %%
00016 %% The setup method is used to setup the basic attributes of the
00017 %% S-function such as ports, parameters, etc. Do not add any other
00018 %% calls to the main body of the function.  
00019 %%   
00020 setup(block);
00021   
00022 %endfunction
00023 
00024 %% Function: setup ===================================================
00025 %% Abstract:
00026 %%   Set up the S-function block's basic characteristics such as:
00027 %%   - Input ports
00028 %%   - Output ports
00029 %%   - Dialog parameters
00030 %%   - Options
00031 %% 
00032 %%   Required         : Yes
00033 %%   C-Mex counterpart: mdlInitializeSizes
00034 %%
00035 function setup(block)
00036 
00037   % Register number of ports
00038   block.NumInputPorts  = 2;
00039   block.NumOutputPorts = 0;
00040   
00041   % Setup port properties to be inherited or dynamic
00042   block.SetPreCompInpPortInfoToDynamic;
00043   block.SetSimViewingDevice(1);
00044 
00045   % Override input port properties
00046   block.InputPort(1).DatatypeID  = 0;  % double
00047   block.InputPort(1).Complexity  = 'Real';
00048   
00049   block.InputPort(2).DatatypeID  = 0;  % double
00050   block.InputPort(2).Complexity  = 'Real';
00051   
00052   % Override output port properties
00053   %block.OutputPort(1).DatatypeID  = 0; % double
00054   %block.OutputPort(1).Complexity  = 'Real';
00055 
00056   % Register parameters
00057   block.NumDialogPrms     = 2;
00058   %block.DialogPrmsTunable = {'Tunable','Nontunable','SimOnlyTunable'};
00059 
00060   block.SetAccelRunOnTLC(false);
00061   
00062   block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
00063   block.RegBlockMethod('ProcessParameters', @ProcessPrms);
00064   block.RegBlockMethod('Start', @Start);
00065   block.RegBlockMethod('Update', @Update);
00066 %endfunction
00067 
00068 %% -------------------------------------------------------------------
00069 %% The local functions below are provided for illustrative purposes
00070 %% to show how you may implement the various block methods listed
00071 %% above.
00072 %% -------------------------------------------------------------------
00073 
00074 function CheckPrms(block)
00075   
00076 %   a = block.DialogPrm(1).Data;
00077 %   if ~strcmp(class(a), 'double')
00078 %     error('Invalid parameter');
00079 %   end
00080   
00081 %endfunction
00082 
00083 function DoPostPropSetup(block)
00084   block.NumDworks             = 1;
00085   block.Dwork(1).Name         = 'plothandle';
00086   block.Dwork(1).Dimensions   = 5;
00087   block.Dwork(1).DatatypeID   = 0;
00088   block.Dwork(1).Complexity   = 'Real';
00089 %endfunction
00090 
00091 function Start(block)
00092     area = block.DialogPrm(1).Data.area;
00093     hFig = figure(1);
00094     set(hFig, 'Name', 'Robot');
00095     set(hFig, 'DoubleBuffer', 'on', 'Tag', 'robotScreen');
00096     %set(fig, 'Renderer', 'painters');
00097     %set(fig, 'Color', 'black');
00098     hold('on');
00099     fig_axes = get(hFig, 'CurrentAxes');
00100     block.Dwork(1).Data = zeros(size(block.Dwork(1).Data));
00101     drawStyle = block.DialogPrm(2).Data;
00102     if drawStyle==0,
00103         axis('equal');
00104         set(gca, 'XLim', [0,area.w]);
00105         set(gca, 'YLim', [0,area.h]);
00106         cla(fig_axes);
00107         hold on
00108     end
00109 %endfunction
00110 
00111 function hc = homog(coords)
00112     hc=[coords ones(size(coords, 1), 1)];
00113 %endfunction
00114 
00115 function Update(block)
00116     figure(1);
00117     desc = block.DialogPrm(1).Data;
00118     robot = desc.robot;
00119     x = block.InputPort(1).Data;
00120     y = block.InputPort(2).Data;
00121     
00122     outline=homog(desc.shape.outline);
00123     arrow=homog(desc.shape.arrow);
00124     
00125 % Transformations
00126     mid = [
00127         1 0 -robot.cx
00128         0 1 -robot.cy
00129         0 0 1]';
00130     trans = [
00131         cos(x(3)) -sin(x(3)) x(1)
00132         sin(x(3))  cos(x(3)) x(2)
00133         0 0 1]';
00134 
00135     oldPlot = block.Dwork(1).Data;
00136     if any(oldPlot~=0), delete(oldPlot(oldPlot~=0)); end;
00137     
00138     outline=outline*mid*trans;
00139     arrow=arrow*mid*trans;
00140     drawStyle = block.DialogPrm(2).Data;
00141     if drawStyle==0,
00142         oldPlot(1) = fill(outline(:,1), outline(:,2), 'c');
00143         oldPlot(2) = plot(arrow(:,1), arrow(:,2), 'k');
00144     else
00145         oldPlot(1) = plot(outline(:,1), outline(:,2), drawStyle);
00146         oldPlot(2) = plot(arrow(:,1), arrow(:,2), drawStyle);
00147     end
00148     if any(y~=0),
00149         dir1 = homog(3*[robot.laserx robot.lasery; cos(y(1)) sin(y(1))]);
00150         dir2 = homog(3*[robot.laserx robot.lasery; cos(y(2)) sin(y(2))]);
00151         dir3 = homog(3*[robot.laserx robot.lasery; cos(y(3)) sin(y(3))]);
00152         d = [dir1*trans;
00153             dir2*trans;
00154             dir3*trans];
00155         oldPlot(3) = plot(d(:,1), d(:,2), 'r');
00156     end
00157     drawnow
00158     block.Dwork(1).Data = oldPlot;
00159     %endfunction
00160 

Generated on Thu Sep 13 11:28:28 2007 for DCE-Eurobot by  doxygen 1.5.3