Functions |
| function | sfdrawrobot (block)%MSFUNTMPL A template for an M-file S-function%The M-file S-function is written as a MATLAB function with the%same name as the S-function.Replace 'msfuntmpl'with the name%of your S-function.%%It should be noted that the M-file S-function is very similar%to Level-2 C-Mex S-functions.You should be able to get more%information for each of the block methods by referring to the%documentation for C-Mex S-functions.%%Copyright 2003-2006 The MathWorks |
function Inc etc Do not add
any other calls to the main
body of the function | setup (block) |
| block | SetSimViewingDevice (1) |
Override input port properties
block | InputPort (1).DatatypeID=0 = 'Real' |
| Inhrited block | InputPort (2).DatatypeID=0 = 'Real' |
Inhrited Override output port
properties block | OutputPort (1).DatatypeID=0 = 'Real' |
| block | SetAccelRunOnTLC (false) |
| block | RegBlockMethod ('PostPropagationSetup',@DoPostPropSetup) |
| block | RegBlockMethod ('ProcessParameters',@ProcessPrms) |
| block | RegBlockMethod ('SetInputPortSampleTime',@SetInputPortSampleTime) |
| block | RegBlockMethod ('SetInputPortDimensions',@SetInpPortDims) |
| block | RegBlockMethod ('Start',@Start) |
| block | RegBlockMethod ('Update',@Update) |
| idx | di () |
| endfunction function | CheckPrms (block)%a |
| if | ~strcmp (class(a), 'double')%error('Invalid parameter') |
| end endfunction function | DoPostPropSetup (block) block.NumDworks |
| block | Dwork (1).Name |
| block | Dwork (2).Name |
| block | Dwork (3).Name = 1 |
| block | Dwork (4).Name = 5 |
| block | Dwork (5).Name = 1 |
| endfunction function | SetInputPortSampleTime (block, port, time) block.InputPort(port).SampleTime |
| endfunction function | Start (block) area |
| | set (hFig, 'Name', 'Robot') |
| | set (hFig, 'DoubleBuffer', 'on', 'Tag', 'robotScreen') |
| | set (fig, 'Renderer', 'painters') |
| | set (fig, 'Color', 'black') |
| | hold ('on') |
| if | axis ('equal') |
| | set (gca, 'XLim',[0, area.w]) |
| | set (gca, 'YLim',[0, area.h]) |
| | cla (fig_axes) |
| endfunction function | Update (block) x |
| if | length (y) |
| | mod (counter, 4)+1 |
| if | oldPlot (counter) |
| if | delete (oldPlot(counter)) |
| oldPlot(oldPlot~=0 | delete () |
| end if | any (y~=0) |
| | oldPlot (counter+i-1) |
| | if (block.CurrentTime< last_draw+1/20) |
| | set (0,'CurrentFigure', 1) desc |
| if | any (toDelete) |
| if | delete (oldPlot(toDelete)) |
| if | oldPlot (1) |
| | oldPlot (2) |
Variables |
| function Inc | $Revision |
| function Inc | parameters |
| endfunction | Function |
| block | NumOutputPorts = 0 |
Setup port properties to be
inherited or dynamic block | SetPreCompInpPortInfoToDynamic |
| Register parameters block | NumDialogPrms = 2 |
| block | DialogPrmsTunable = {'Tunable','Nontunable','SimOnlyTunable'} |
| | hFig = figure(1) |
| | fig_axes = get(hFig, 'CurrentAxes') |
| | drawStyle = block.DialogPrm(2).Data |
| hold on end endfunction function | hc |
| | y = block.InputPort(2).Data |
We need to detect changes in y
to properly find the time of a
new measurement | last_y = block.Dwork(4).Data(1:length(y)) |
| | robot = desc.robot |
| Transformations | trans |
| | oldPlot = block.Dwork(2).Data |
| | counter = block.Dwork(3).Data |
| | end |
| end if for | i = [1:length(y)] |
| end if for | beam |
| | line = beam*trans |
end Do not draw everything too
often | last_draw = block.Dwork(5).Data |
| | return |
| | outline = homog(desc.shape.outline) |
| | arrow = homog(desc.shape.arrow) |
| Transformations | mid |
| | toDelete = oldPlot ~= 0 |