%% Yo-Yo Control of Satellites
%
% This example shows how to model the controil system in a tethered
% satellite system. The satellite system consists of a small satellite
% attached by a long tether to an orbiting platform. When the tethered
% satellite oscillates, it behaves like a pendulum that exhibits too much
% libration. To stabilize the pendulum, the control system changes the
% length of the tether by reeling it out to its maximum length when the
% satellite is in the middle of its arc (which decreases its angular
% acceleration) and by reeling it in when the satellite has an angular
% velocity equal to zero.

% Copyright 2000-2020 The MathWorks, Inc.

%%

model = 'sf_yoyo';

load_system(model)

% Delete all annotations at the top level of the model
ah = find_system(model, 'FindAll', 'on', 'type', 'annotation');
for i = 1:length(ah)
   ao = get_param(ah(i), 'Object');
   ao.delete;
end

open_system(model);
close_system([model '/Energy scope']);
close_system([model '/Length scope']);
close_system([model '/Theta scope']);

%% 
% Stateflow(R) is used to control when the tether is reeled in or reeled
% out using input events from Simulink(R).  When the satellite is in the
% middle of its swing ($$ \theta = 0 $$), the state |ReelOut| becomes
% active.  When the satellite has been reeled out as far as it can, the
% state |ReelStop| becomes active.  When the angular velocity of the
% satellite reaches zero, the |ReelIn| state becomes active. When the
% tether is as short as possible, the |ReelStop| state becomes active once
% again. Finally, if the total energy of the satellite is too low,
% the system is deactivated by entering the |Inactive| state.

open_system([model '/Chart']);

%%

sim(model);
open_system([model '/Theta scope']);

%% Reference
% Dabney, James B. and Harman, Thomas L. _Mastering Simulink_, 2003.
