Code covered by the BSD License  

Highlights from
SAE Paper Demo: Model-Based Design of Hybrid Electric Vehicles

image thumbnail

SAE Paper Demo: Model-Based Design of Hybrid Electric Vehicles

by

 

07 Nov 2010 (Updated )

Demo files to accompany the paper by the same name

guiInterface(block)
function guiInterface(block)
% Level-2 M file S-Function for times two demo.
%   Copyright 1990-2004 The MathWorks, Inc.
%   $Revision: 1.1.6.1 $ 

  setup(block);
  
%endfunction

function setup(block)
  
  %% Register number of input and output ports
  block.NumInputPorts  = 1;
  block.NumOutputPorts = 0;

  %% Setup functional port properties to dynamically
  %% inherited.
  block.SetPreCompInpPortInfoToDynamic;
  block.SetPreCompOutPortInfoToDynamic;
 
  block.InputPort(1).DirectFeedthrough = true;
  
  %% Set block sample time to inherited
  block.SampleTimes = [1 0];
  
  %% Run accelerator on TLC
  block.SetAccelRunOnTLC(true);
  
  %% Register methods
  block.RegBlockMethod('Outputs',                 @Output);  
  block.RegBlockMethod('Start',                 @Start);  
  block.RegBlockMethod('InitializeConditions',                 @InitConditions);  
  block.RegBlockMethod('PostPropagationSetup',    @DoPostPropSetup);
  block.RegBlockMethod('Terminate', @Terminate);
  block.RegBlockMethod('Update', @Update);
  
%endfunction

function DoPostPropSetup(block)

  %% Setup Dwork
  block.NumDworks = 1;
  block.Dwork(1).Name = 'GUI_Handle'; 
  block.Dwork(1).Dimensions      = 1;
  block.Dwork(1).DatatypeID      = 0;
  block.Dwork(1).Complexity      = 'Real';
  block.Dwork(1).UsedAsDiscState = false;
  
%   block.Dwork(2).Name = 'Velocity'; 
%   block.Dwork(2).Dimensions      = 1;
%   block.Dwork(2).DatatypeID      = 0;
%   block.Dwork(2).Complexity      = 'Real';
%   block.Dwork(2).UsedAsDiscState = false;
% 
%   block.Dwork(3).Name = 'Acceleration'; 
%   block.Dwork(3).Dimensions      = 1;
%   block.Dwork(3).DatatypeID      = 0;
%   block.Dwork(3).Complexity      = 'Real';
%   block.Dwork(3).UsedAsDiscState = false;
%   
%   block.Dwork(4).Name = 'FuelConsumption'; 
%   block.Dwork(4).Dimensions      = 1;
%   block.Dwork(4).DatatypeID      = 0;
%   block.Dwork(4).Complexity      = 'Real';
%   block.Dwork(4).UsedAsDiscState = false;
%   
%   block.Dwork(5).Name = 'Time'; 
%   block.Dwork(5).Dimensions      = 1;
%   block.Dwork(5).DatatypeID      = 0;
%   block.Dwork(5).Complexity      = 'Real';
%   block.Dwork(5).UsedAsDiscState = false;
%endfunction


function Output(block)

global prevPowerFlow
global velocity
global acceleration;
global fuelconsumption;
global mpg;
global time;
global tf;
global pause_time;

velocity  = [velocity block.InputPort(1).Data(11)];
acceleration = [acceleration block.InputPort(1).Data(12)];
fuelconsumption = [fuelconsumption block.InputPort(1).Data(10)];
mpg= [mpg block.InputPort(1).Data(13)];
time = [time block.InputPort(1).Data(9)];

Eng_Planet_Power = block.InputPort(1).Data(1); 
Sun_Gen_Power = block.InputPort(1).Data(2);
Gen_Bat_Power = block.InputPort(1).Data(3);
Bat_Mot_Power = block.InputPort(1).Data(4);
Bat_Power = block.InputPort(1).Data(5);
Mot_Ring_Power = block.InputPort(1).Data(6);
Ring_Diff_Power = block.InputPort(1).Data(7);
guiHandle = block.Dwork(1).Data;
anim_rate = 15 ;% Hz

updateVelocity(guiHandle,velocity,time, str2num(tf));
updateAcceleration(guiHandle,acceleration,time,  str2num(tf));
updateFuelConsump(guiHandle,fuelconsumption,time,  str2num(tf));
updateMPG(guiHandle,mpg,time,  str2num(tf));

powerFlow = determinePowerFlow(Eng_Planet_Power, Sun_Gen_Power, Gen_Bat_Power,...
                  Bat_Mot_Power, Bat_Power, Mot_Ring_Power,...
                  Ring_Diff_Power, pause_time);
              
if(~isequal(powerFlow,prevPowerFlow))
    startAnimation(guiHandle, powerFlow.arr, powerFlow.dir, anim_rate);
end

prevPowerFlow = powerFlow;

%endfunction

function Start(block)

%endfunction

function InitConditions(block)

%Initializing the Plots
XData = 1:1:30;
YData = zeros(1,30);
block.Dwork(1).Data = evalin('base','hcar');
guiHandles = guidata(block.Dwork(1).Data);

guiHandles.velH = plot(guiHandles.velAxis,XData,YData,'white'); set(guiHandles.velH,'erasemode','background','linewidth',1)
guiHandles.accelH = plot(guiHandles.accelAxis,XData,YData,'white'); set(guiHandles.accelH,'erasemode','background','linewidth',1)
guiHandles.fuelH = plot(guiHandles.fuelAxis,XData,YData,'white'); set(guiHandles.fuelH,'erasemode','background','linewidth',1)
guiHandles.MPGH = plot(guiHandles.MPGAxis,XData,YData,'white'); set(guiHandles.MPGH,'erasemode','background','linewidth',1)
set(guiHandles.velAxis,'color',[0 0 0])
set(guiHandles.accelAxis,'color',[0 0 0])
set(guiHandles.fuelAxis,'color',[0 0 0])
set(guiHandles.MPGAxis,'color',[0 0 0])
title(guiHandles.velAxis,'Gas Pedal input','fontsize',12,'fontweight','bold')
title(guiHandles.accelAxis,'Brake input','fontsize',12,'fontweight','bold')
title(guiHandles.fuelAxis,'Velocity (mph)','fontsize',12,'fontweight','bold')
title(guiHandles.MPGAxis,'mpg','fontsize',12,'fontweight','bold')
guidata(block.Dwork(1).Data,guiHandles)
%endfunction

function Update(block)

%endfunction

function Terminate(block)

global prevPowerFlow
global velocity
global acceleration
global fuelconsumption
global time
global mpg
global tf;
global pause_time;

velocity = [];
acceleration = [];
fuelconsumption = [];
mpg=[];
time = [];
tf=[];
pause_time=[];
prevPowerFlow = {};

stopAnimation()
%endfunction

Contact us