% speed.m - generate plots for speed controller
% RMM, 26 Aug 05

aminit;					% initialize MATALB

% Generate the torque curve
beta = 0.4;
Tmax = 190;
omegamax = 420;
omega = 0:1:700;
Tomega = Tmax * (1  - beta * (omega/omegamax - 1).^2);

figure(1); clf;
subplot(211); plot(omega, Tomega);
amaxis([0 700 0 200]);
a=gca; set(a,'FontSize',16); grid on;
xlabel('omega');
ylabel('T', 'Rotation', 90);
amprint('torque.eps');

%
% PI controller simulation
%

[t, x] = ode45('drivetrain', [0 20], [20 -1.1]);
vd = 20 * ones(length(t));
vert = [18; 22];			% vertical line

figure(2); clf; subplot(211);
plot(t, x(:,1), '-', t, vd, '--', [5, 5], vert, '--');
amaxis([0 20 18 22]);
a=gca; set(a,'FontSize',16);
xlabel('time (sec)');
ylabel('velocity (m/s)');

amprint('speedpi.eps');

