% FerrisWhell_script.m -->  with FerrisWheel.mdl
% script for Simulink tutorial from mass-spring-damper example from
% Christopher Lum, University of Washington

% constants
J = 1500000;  % kg.m^2
b = 200000;   % Nm/s
k = 4000000;  % Nm

% A, B, C, D system matrices
% x1 = omega, angular velocity;  x2 = Tk, spring torque
% The system starts with stored energy in the mass and spring
A = [-b/J -1/J; k 0];  
B = [0; 0];     % if not using initial conditions, then B = [1; 1]
C = [0 1/k];
D = [0];

% initial conditions, part of state space block in Simulink
% set to 1 simply to test system behavior...oscillatory, overdamped...
omega_0 = 1;
Tk_0 = 1;

figure
hold on

% run the simulink model, mass_spring.mdl
sim('FerrisWheel');

% define data vectors written to Matlab workspace by Simulink 'To
% Workspace' block
t = sim_u.time;
u = sim_u.signals.values;
y = sim_y.signals.values;

% plot the data
plot(t, y, 'r-', 'LineWidth', 2)
plot(t, u, 'c-', 'LineWidth', 2)
title('Response of Braking Ferris Wheel')
xlabel('t (sec)')
ylabel('theta (radians)')
legend('y, theta ', 'u', 'Location', 'SouthWest')
grid
hold off