Code covered by the BSD License  

Highlights from
Safety Critical Control Elements Examples

image thumbnail

Safety Critical Control Elements Examples

by

Chethan C U

 

The files contained have the examples for safety critical control elements.

IntegratorTest.m
% Safety Critical Control Design.
% Control element Simulation and testing Examples.
% Based on requirements available at
% http://www.mathworks.in/matlabcentral/fileexchange/39047-testing-of-safet
% y-critical-control-systems
%
% Copyright Chethan CU - chethan.cu@gmail.com 
% Jan 2013

clear all 
DT = 0.01;
Tmax = 10;
t=0:DT:Tmax;


% Define Inputs here -----------------------------------------------
input = ones(length(t),1)*5;

input((Tmax/2)/0.02:end)=-5;
IC = 5;
LL= ones(length(t),1)*-10;
UL= ones(length(t),1)*10;
prevo=0;
previ=0;
output=[];
% Start of Algorithm -----------------------------------------------
% Forward Euler method of Integration
for i = 1:length(t)
    if i==1
        out=IC;
        prevo=IC;
        previ=input(i);
    else
        out=prevo + DT*input(i);
    end
    %----
    %prevo=out;
    %----
    if(out>UL(i))
        out=UL(i);
    elseif(out<LL(i))
        out=LL(i);
    end
    output=[output;out]; 
    previ=input(i);
    % Move the below line of code to the commented section above to see the
    % winding of the integrator
    prevo=out;
    %---------    
  
end
% End of Algorithm -----------------------------------------------

% simulate the simulink model --------------------------------------
sim('Integrator');

% plot results -----------------------------------------------------
 subplot(211)
 plot(t,input,t,output,t,o);
 title('Input Vs. Outputs')
 legend('Input','CodeOutput','SimulinkOutput');
 subplot(212)
 plot(t,output-o);
 shg;

Contact us