Code covered by the BSD License  

Highlights from
Reliable and Roubst Design

image thumbnail

Reliable and Roubst Design

by

 

21 Jan 2008 (Updated )

MATLAB Code used in the Jan 2008 Digest Article

myCostFcnRR(x,simParms)
function mycost = myCostFcnRR(x,simParms)

%% Unpack simParms sturcutre for Simulink Use
struct2var(simParms)

%% Extract suspension variables
kf = x(1); cf = x(2);
kr = x(3); cr = x(4);

%% Run Simulink model
% Start Monte Carlo
for ii = 1:nRuns
    % Change the model parameters due to mass distribution change
    Iyy = mcIyy(ii);
    Mb  = mcMb(ii);
    Lf  = mcLf(ii);
    Lr  = mcLr(ii);
    rf  = mcrf(ii);
    rr  = mcrr(ii);
    rt  = mcrt(ii);
    
    % Initial Conditions for Simulink Model
    theta0 = 0;                 % initial pitch (rad)
    thetadot0 = 0;              % initial pitch rate (rad/s)
    Z0 = -0.5*Mb*g/(kf+kr);     % initial equilibrium position, assumes full car (m)
    Zdot0 = 0;                  % initial bounce rate (m/s)
    simTime = [0 8];
    sim('mldemo_suspnfast.mdl',simTime,simset('SrcWorkspace', 'current', 'DstWorkspace', 'current'))
    
    %% Compute cost
    totalAccel = (Zdotdot + rf * thetadotdot).^2 + (Zdotdot - rr * thetadotdot).^2;

    %% Return final value
    ta(ii) = sum(totalAccel);
    tm(ii) = max(totalAccel);
end

mycost = (mean(ta) + std(ta))/904 * 0.5 + (mean(tm) + std(tm))/56 * 0.5;

assignin('base','totAccel',ta);
assignin('base','pkAccel',tm);

Contact us