function [sys,x0]=furutaanim(t,x,u,flag,ts);
%pendubotanim S-function for animating the motion of the Pendubot.

%   Ned Gulley, 6-21-93
%   Copyright (c) 1990-1998 by The MathWorks, Inc. All Rights Reserved.
%   $Revision: 5.6 $
%   Editted by Dan Block

global PendAnim2

if flag==2,
  if any(get(0,'Children')==PendAnim2),
    if strcmp(get(PendAnim2,'Name'),'Furuta Animation'),
      set(0,'currentfigure',PendAnim2);
      hndl=get(gca,'UserData');
      b=0.75; c=1.5;
      xSFP=0; ySFP=0;
      xBFP=xSFP-b*cos(u(1)); yBFP=ySFP;
%      xBFP=xSFP+b*sin(u(1)); yBFP=ySFP-0.85*b*cos(u(1));
%      xMC=xBFP+c*sin(u(2)); yMC=yBFP-c*cos(u(2));
      xMC=xBFP+c*sin(u(1))*cos(u(2)); yMC=yBFP-c*sin(u(2));
      x=[xSFP xBFP NaN xBFP xMC];
      y=[ySFP yBFP NaN yBFP yMC];
      set(hndl,'XData',x,'YData',y);
      drawnow;
    end
  end
  sys=[];

elseif flag==0,
  % Initialize the figure for use with this simulation
  animinit('Furuta Animation');
  [flag,PendAnim2] = figflag('Furuta Animation');
  axis([-2 2 -3 2]);
  hold on;

  % Set up the geometry for the problem
  % SFP=Space Fixed Pivot
  % BFP=Body Fixed Pivot
  b=0.75; c=1.5;
  xSFP=0; ySFP=0;
%  xBFP=xSFP; yBFP=ySFP-0.85*b;
  xBFP=xSFP; yBFP=ySFP;
%  xMC=xBFP; yMC=yBFP-c;
  xMC=xBFP; yMC=yBFP-c;
  x=[xSFP xBFP NaN xBFP xMC];
  y=[ySFP yBFP NaN yBFP yMC];
  hndl=plot(x,y, ...
           'EraseMode','background', ...
           'LineWidth',8, ...
           'Marker','.', ...
           'MarkerSize',18);
  set(gca,'DataAspectRatio',[1 1 1]);
  set(gca,'UserData',hndl);

  sys=[0 0 0 2 0 0];
  x0=[];

end

