Vous êtes sur la page 1sur 6

ME 581: Digital Control

HW #4







Benjamin Janicki


benjaj2@uw.edu
1031779




2/7/14









Figure 1: Simulink block diagram of analog continuous control system.




Figure 2: Simulink block diagram of discrete digital control system.

%% ME 581: HW #5
% Simulation of car speed control system w/ analog controller
% Benjamin Janicki, February 7th, 2014

clc
clear all
close all

disp(' ')
disp('********************')
disp('******* HW 5 *******')
disp('* Benjamin Janicki *')
disp('********************')

%% Define plant parameters
M=1670; % Mass of vehicle
B=0.5559; % Nonlinear aerodynamic drag coefficient
Ka=1599; % Actuator gain constant
taua=0.5; % Actuator time constant
v0=25; % Operating point velocity in m/sec
gravity=9.806; % Gravity constant in m/sec^2
T =.5; % Sampling time

% Set controller gains
Kp=0.6; % Proportional control gain
Ki=0.01; % Integral control gain
Kd=0.08; % Derivative control gain

vref=inptdf('\nEnter constant value for vref (typically 25 or 27) (m/sec)
[27]',27);
vreftxt=sprintf('v_{ref}(t)=%2.0f m/sec',vref);
grade=inptdf('\nEnter percent of uphill grade (typically 0 or 5) [0]',0)/100;
fd=-M*gravity*sin(atan(grade)); % gravity force that pushes car forward
gradetxt=sprintf('%2.0f percent uphill grade',100*grade);
titletxt=['Response to ' vreftxt ' and ' gradetxt];

tfinal=inptdf('\nEnter final time for simulations (typically 10 or 120) (sec)
[10]',10);

%% Compute simulations

% Simulation with analog controller:
simout=sim('spdcntrl','Solver','ode45','RelTol','1.e-5', ...
'StopTime','tfinal', ...
'SaveTime','on','TimeSaveName','timeoutNew', ...
'SaveOutput','on','OutputSaveName','youtNew');
time=simout.get('timeoutNew');
y=simout.get('youtNew');

% Simulation with digital controller:
simout=sim('discreteblock','Solver','ode45','RelTol','1.e-5', ...
'StopTime','tfinal', ...
'SaveTime','on','TimeSaveName','timeoutNew', ...
'SaveOutput','on','OutputSaveName','youtNew');
timediscrete=simout.get('timeoutNew');
ydiscrete=simout.get('youtNew')
%% Plot Responses

figure
hold on
% continuous:
plot([0 time(length(time))],[vref vref],'k--')
plot(time,y(:,1),'r-')
hold on
% discrete:
plot(timediscrete,ydiscrete(:,1),'b')
xlabel('t (sec)')
ylabel('v(t) (m/sec)')
title(titletxt)
legend('v_{ref}','v_{analog}','v_{digital}')

figure
% continuous:
plot(time,y(:,3),'b--',time,y(:,4),'r-')
hold on
% discrete:
plot(timediscrete,ydiscrete(:,3),'g--',timediscrete,ydiscrete(:,4),'b')
limits=axis;
axis([limits(1) limits(2) 0 limits(4)]);
xlabel('t (sec)')
ylabel('u_{limited}(t) and u(t) (dimensionless)')
title(titletxt)
legend('u_{analog}','u_{limited, analog}','u_{digital}','u_{limited,
digital}')

% Last Line



Responses plotted on following pages. All axis are labeled for convenience.

Vous aimerez peut-être aussi