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

hybridCar(varargin)
function varargout = hybridCar(varargin)
% HYBRIDCAR M-file for hybridCar.fig
%      HYBRIDCAR, by itself, creates a new HYBRIDCAR or raises the existing
%      singleton*.
%
%      H = HYBRIDCAR returns the handle to a new HYBRIDCAR or the handle to
%      the existing singleton*.
%
%      HYBRIDCAR('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in HYBRIDCAR.M with the given input arguments.
%
%      HYBRIDCAR('Property','Value',...) creates a new HYBRIDCAR or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before hybridCar_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to hybridCar_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%      
%       Connection ID's fo the GUI:
%       1 - Generator to Battery
%       2 - Battery to Motor
%       3 - Motor to Planetary Ring 
%       4 - Planetary Sun to Generator
%       5 - Engine to Planetary Carrier
%       6 - Planetary Ring to Differential
%       7 - Differential to Left Tire
%       8 - Differential to Right Tire
%       9 - Generator to Motor
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help hybridCar

% Last Modified by GUIDE v2.5 23-Apr-2006 15:27:23

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @hybridCar_OpeningFcn, ...
                   'gui_OutputFcn',  @hybridCar_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before hybridCar is made visible.
function hybridCar_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to hybridCar (see VARARGIN)

% Choose default command line output for hybridCar
handles.output = hObject;
modelname = varargin{1};
hws = get_param(modelname, 'modelworkspace');
hws.assignin('guiH',hObject);

%Reading the power flow image and displaying in the axis
I = imread('hybridCar.tif');
axes(handles.animAxis);
handles.image = image(I);
set(handles.animAxis,'xtick',[],'ytick',[],'xticklabel',[],'yticklabel',[]);
set(handles.image,'erasemode','normal')

%Creating titles for the plots
title(handles.velAxis,'Gas pedal input','fontsize',12,'fontweight','bold')
title(handles.accelAxis,'Brake input','fontsize',12,'fontweight','bold')
title(handles.fuelAxis,'Velocity (mph)','fontsize',12,'fontweight','bold')
title(handles.MPGAxis,'mpg','fontsize',12,'fontweight','bold')

%Properties of dots and arrows
guiObjProp.dots.width = 15;
guiObjProp.dots.height = 15;
%guiObjProp.arrow.width = 20;

%Arrow from Generator to Battery
guiObjProp.arr_gen_bat.XData = [326 256];
guiObjProp.arr_gen_bat.YData = [236 236];
guiObjProp.arr_gen_bat.color = [1 0 0];
h = generateArrow(guiObjProp.arr_gen_bat.XData,guiObjProp.arr_gen_bat.YData,guiObjProp.dots.width,guiObjProp.dots.height,guiObjProp.arr_gen_bat.color);
arrows.arr_gen_bat = arrow(h);

%Arrow from Battery to Motor
guiObjProp.arr_bat_mot.XData = [250 290 290 500];
guiObjProp.arr_bat_mot.YData = [280 280 440 440];
guiObjProp.arr_bat_mot.color = [1 0 0];
h = generateArrow(guiObjProp.arr_bat_mot.XData,guiObjProp.arr_bat_mot.YData,guiObjProp.dots.width,guiObjProp.dots.height,guiObjProp.arr_bat_mot.color);
arrows.arr_bat_mot = arrow(h);

%Motor to Ring Gear
guiObjProp.arr_mot_ring.XData = [548 548];
guiObjProp.arr_mot_ring.YData = [355 325];
guiObjProp.arr_mot_ring.color = [0 0 1];
h = generateArrow(guiObjProp.arr_mot_ring.XData,guiObjProp.arr_mot_ring.YData,guiObjProp.dots.width,guiObjProp.dots.height,guiObjProp.arr_mot_ring.color);
arrows.arr_mot_ring = arrow(h);

%Sun Gear to Generator
guiObjProp.arr_sun_gen.XData = [530 450];
guiObjProp.arr_sun_gen.YData = [265 265];
guiObjProp.arr_sun_gen.color = [0 0 1];
h = generateArrow(guiObjProp.arr_sun_gen.XData,guiObjProp.arr_sun_gen.YData,guiObjProp.dots.width,guiObjProp.dots.height,guiObjProp.arr_sun_gen.color);
arrows.arr_sun_gen = arrow(h);

%Engine to Planet Carrier
guiObjProp.arr_eng_pla.XData = [548 548];
guiObjProp.arr_eng_pla.YData = [138 218];
guiObjProp.arr_eng_pla.color = [0 0 1];
h = generateArrow(guiObjProp.arr_eng_pla.XData,guiObjProp.arr_eng_pla.YData,guiObjProp.dots.width,guiObjProp.dots.height,guiObjProp.arr_eng_pla.color);
arrows.arr_eng_pla = arrow(h);

%Ring Gear to Differential
guiObjProp.arr_ring_diff.XData = [610 750];
guiObjProp.arr_ring_diff.YData = [267 267];
guiObjProp.arr_ring_diff.color = [0 0 1];
h = generateArrow(guiObjProp.arr_ring_diff.XData,guiObjProp.arr_ring_diff.YData,guiObjProp.dots.width,guiObjProp.dots.height,guiObjProp.arr_ring_diff.color);
arrows.arr_ring_diff = arrow(h);

%Differential to Left Tire
guiObjProp.arr_diff_ltir.XData = [765 765];
guiObjProp.arr_diff_ltir.YData = [198 104];
guiObjProp.arr_diff_ltir.color = [0 0 1];
h = generateArrow(guiObjProp.arr_diff_ltir.XData,guiObjProp.arr_diff_ltir.YData,guiObjProp.dots.width,guiObjProp.dots.height,guiObjProp.arr_diff_ltir.color);
arrows.arr_diff_ltir = arrow(h);

%Differential to right tire
guiObjProp.arr_diff_rtir.XData = [765 765];
guiObjProp.arr_diff_rtir.YData = [309 420];
guiObjProp.arr_diff_rtir.color = [0 0 1];
h = generateArrow(guiObjProp.arr_diff_rtir.XData,guiObjProp.arr_diff_rtir.YData,guiObjProp.dots.width,guiObjProp.dots.height,guiObjProp.arr_diff_rtir.color);
arrows.arr_diff_rtir = arrow(h);

%Generator to Motor
%guiObjProp.arr_gen_mot.XData = [390 390 500];
%guiObjProp.arr_gen_mot.YData = [301 401 401];
%guiObjProp.arr_gen_mot.color = [0 0 0];
%h = generateArrow(guiObjProp.arr_gen_mot.XData,guiObjProp.arr_gen_mot.YData,guiObjProp.dots.width,guiObjProp.dots.height,guiObjProp.arr_gen_mot.color);
arrows.arr_gen_mot =arrow(h);



% Update handles structure
guidata(hObject, handles);
% Update APP Data
setappdata(hObject,'arrows',arrows);
setappdata(hObject,'modelname',modelname);

% UIWAIT makes hybridCar wait for user response (see UIRESUME)
% uiwait(handles.hybridCarGUI);


% --- Outputs from this function are returned to the command line.
function varargout = hybridCar_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = hObject;


function tfBox_Callback(hObject, eventdata, handles)
% hObject    handle to tfBox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of tfBox as text
%        str2double(get(hObject,'String')) returns contents of tfBox as a double


% --- Executes during object creation, after setting all properties.
function tfBox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tfBox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function pauseBox_Callback(hObject, eventdata, handles)
% hObject    handle to tfBox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of tfBox as text
%        str2double(get(hObject,'String')) returns contents of tfBox as a double


% --- Executes during object creation, after setting all properties.
function pauseBox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tfBox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in start.
function start_Callback(hObject, eventdata, handles)
% hObject    handle to start (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global tf;
global pause_time;
modelname = getappdata(handles.hybridCarGUI,'modelname');
tf = get(handles.tfBox,'String');
pause_time=get(handles.pauseBox,'String');
set_param(modelname,'stoptime',tf);
set_param(modelname,'simulationcommand','start');


% --- Executes on button press in stop.
function stop_Callback(hObject, eventdata, handles)
% hObject    handle to stop (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
modelname = getappdata(handles.hybridCarGUI,'modelname');
set_param(modelname,'simulationcommand','stop');

Contact us