Convertitore Cicli/km
Durante l’analisi dei dati della PV si `
e manifestata l’esigenza di convertire il numero di cicli
con cui si misurano le prove di durata in un’unit`
a di misura pi`
u adatta alla trattazione dei
ritorni in garanzia: il chilometro.
In questo ambito `
e stata realizzata una piccola applicazione utilizzando l’ambiente di
sviluppo offerto da Matlab
®. Per facilitare l’impiego del programma si `e inoltre convenuto
di realizzarne una interfaccia grafica per aiutare l’utente inesperto nella fase di inserimento
dei dati necessari al calcolo o all’aggiornamento del valore di conversione richiesto.
A.1
Interfaccia grafica
Figura A.1: Il convertitore cicli/km
Figura A.2: GUI per il calcolo del fattore di conversione
Il convertitore (Figura A.1) `
e costituito da due caselle di testo editabili. Al momento del
caricamento, il programma ricerca nella cartella di lavoro un file di configurazione contenente
il fattore di conversione e, qualora tale file non venga trovato, viene assunto come valore di
default 1,600.
La modifica del fattore di conversione pu`
o essere realizzata in due modi:
• modificando manualmente il file di configurazione;
• lanciando l’apposita utility.
Il secondo metodo `
e preferibile in quanto consente di impostare in modo pi`
u intuitivo i dati
del problema. Lo stesso convertitore rende disponibile un pulsante che, se premuto, lancia
in esecuzione l’applicativo di configurazione.
La GUI di configurazione si presenta suddivisa in diversi pannelli (Figura A.2) in cui
l’utente `
e chiamato a specificare i rapporti delle marce, la velocit`
a a cui presumibilmente il
guidatore effettuer`
a i cambi marcia, la velocit`
a del motore al minimo, le caratteristiche del
pneumatico montato sulla vettura e il numero di iniezioni per ciclo di combustione
1Il pannello riservato alla definizione dei profili di velocit`
a riveste una notevole
impor-tanza: l’utente deve selezionare quali devono essere i profili da utilizzare per il calcolo dei
chilometri percorsi e quante volte essi debbano essere ripetuti. Appositi pulsanti consentono
di visualizzare i profili con annessa l’indicazione dell’istante in cui avviene il cambio di
mar-cia (Figura A.3). I profili sono memorizzati sia in file .txt che .xls. Se quest’ultimo formato
`
e di pi`
u facile modifica, il primo `
e preferibile dal punto di vista della velocit`
a di esecuzione
in quanto i tempi di caricamento risultano notevolmente ridotti.
Il contenuto del file relativo all’attuale ciclo di riferimento urbano `
e
0
0
15
0
20
15
25
15
30
0
45
0
60
30
75
30
90
0
105
0
135
50
150
50
165
35
180
35
195
0
dove la prima colonna contiene la scala temporale (in secondi) e la seconda la velocit`
a
raggiunta (in km/h). Il profilo extra-urbano `
e strutturato, similmente, come
1In un normale motore a 4 tempi `e prevista una sola iniezione ogni due giri del motore, in corrispondenza
della fase di aspirazione. I moderni motori a iniezione diretta, invece, ricorrono ad un maggior numero di iniezioni, di durata minore, eseguite in rapida successione.
0
0
15
0
60
70
105
70
120
50
195
50
210
70
270
70
300
100
330
100
345
120
360
120
390
0
400
0
Si confrontino le Figure 5.21 e 5.22 per una visualizzazione grafica dei profili sopra descritti.
A.2
Esempio d’uso
Figura A.4: Dal numero dei cicli realizzati si ottiene la stima dei chilometri percorsi
Le due applicazioni sono state sviluppate per essere il pi`
u intuitive possibile. Il
conver-titore si compone di due caselle di testo editabili: una `
e relativa al numero di cicli, l’altra
al numero di chilometri. Entrambe sono in realzione reciproca, in modo che modificando il
valore di una di esse si ha automaticamente l’aggiornamento del valore contenuto nell’altra in
Figura A.5: Dai chilometri si ricavano le attuazioni necessarie per coprirli
funzione del fattore di conversione caricato in memoria all’avvio. Ad esempio, inserendo nel
box dei cicli il numero 600,000,000 e premendo il pulsante INVIO si avr`
a l’aggiornamento del
valore dei chilometri percorsi che, in caso di fattore di conversione pari a 1,600, sar`
a uguale
a 375,000 (Figura A.4). Allo stesso modo, inserendo nella casella di testo dei chilometri il
numero 100,000, si otterr`
a, sempre ricorrendo allo stesso fattore di conversione, un numero
di cicli pari a 160,000,000 ricorrendo al medesimo fattore di conversione (Figura A.5).
L’utility di configurazione richiede un maggior apprendimento facilitato dalla presenza di
messaggi di aiuto che compaiono su tutti i componenti che richiedono interazione da parte
dell’utente. La pressione del pulsante EVAL A NEW CONVERSION FACTOR manda
in esecuzione la routine di aggiornamento del fattore di conversione: essa, in base ai dati
riportati nelle varie caselle di testo della GUI, calcola la velocit`
a del motore in rpm ad ogni
istante di ciascuno dei cicli di riferimento attivati. Data la stima del numero di giri totali
richiesti per compiere ogni profilo, si esegue un semplice rapporto con il totale dei chilometri
percorsi. Tenendo conto di una maggiorazione di circa il 10% per cautelativit`
a, il fattore di
conversione calcolato viene mostrato in alto e salvato, assieme a tutti i dati utilizzati, in un
apposito file condiviso con l’altra applicazione sviluppata (Figura A.6). In ogni momento,
tramite il pulsante DEFAULT, `
e possibile ripristinare i dati iniziali.
Da notare che nel caso in cui non sia selezionato nessuno dei due profili e nel caso in
cui entrambi i file .txt e .xls contenenti i dati relativi all’andamento delle velocit`
a nel tempo
siano inesistenti o privi di dati, il programma restituisce un messaggio di errore comunicando
all’utente l’impossibilit`
a di proseguire nella valutazione del fattore di conversione.
Il pulsante CALL CONVERTER consente di caricare direttamente il convertitore.
A.3
Codice sorgente
Nelle pagine seguenti si riportano i codici sorgenti delle due applicazioni sviluppate. Ad essi
vanno aggiunti i files Converter.fig e convconfig.fig contenenti la grafica delle due GUI. Nel
file logoetinfo.mat `
e memorizzato il logo aziendale di Siemens VDO Automotive riportato
in calce nell’angolo inferiore sinistro di entrambe le interfacce: una sua eventuale mancanza
nella directory di lavoro non pregiudica il corretto funzionamento dei programmi.
A.3.1
Converter.m
function varargout = Converter(varargin)
% File: Converter.m
% Ver: 1.0
% Project: BMW PPQ5 % Authors: Teo
% Created: 19 May 07 % Last modified: 21 May 07
% Comments: File to convert # of actuating cycles to kilometers
% and viceversa
%
% To do list: Debugging and optimization %
% Known bugs: %
% History: 05/21/2007 Ver. 1.0
% + − First version issued
% % Dependencies: % − Converter.fig; % − logoetinfo.mat; % − convconfig.m; % − convconfig.fig. % % Use: Converter %
% This file produces a GUI to be used as a front−end for converting % # of actuating cycles into kilometers and viceversa.
% %
% Copyright (C) 2006−2007 Matteo Masi %
% This program is free software; you can redistribute it and/or % modify it under the terms of the GNU General Public License % as published by the Free Software Foundation; either version 2 % of the License, or any later version.
%
% This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License % along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA % 02110−1301, USA.
% CONVERTER M−file for Converter.fig
% CONVERTER, by itself, creates a new CONVERTER or raises the % existing singleton*.
% H = CONVERTER returns the handle to a new CONVERTER or the % handle to the existing singleton*.
%
% CONVERTER('CALLBACK',hObject,eventData,handles,...) calls the % local function named CALLBACK in CONVERTER.M with the given % input arguments.
%
% CONVERTER('Property','Value',...) creates a new CONVERTER or % raises the existing singleton*. Starting from the left, % property value pairs are applied to the GUI before
% Converter OpeningFunction gets called. An unrecognized
% property name or invalid value makes property application stop. % All inputs are passed to Converter OpeningFcn via varargin. %
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows % only one instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002−2003 The MathWorks, Inc.
% Edit the above text to modify the response to help Converter % Last Modified by GUIDE v2.5 19−May−2007 19:36:13
% Begin initialization code − DO NOT EDIT
gui Singleton = 1;
gui State = struct('gui Name', mfilename, ...
'gui Singleton', gui Singleton, ...
'gui OpeningFcn', @Converter OpeningFcn, ...
'gui OutputFcn', @Converter 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
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % OPENING FUNCTION %
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % −−− Executes just before Converter is made visible.
function Converter 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 Converter (see VARARGIN) % Choose default command line output for Converter
handles.output = hObject;
%If file exists, display LOGO
set(handles.Axes logo,'Units','pixels');
if exist('logoetinfo.mat','file')
temp = load('−mat', 'logoetinfo.mat'); handles.logo = temp.logo;
handles.info = temp.info; axes(handles.Axes logo); cla;
image(handles.logo);
set(handles.Axes logo,'Visible','off', ...
'Units','pixels', ...
'Position',[20 20 handles.info.Width handles.info.Height]);
else
set(handles.Axes logo,'Visible','off');
end
%Default conversion factor
default = 1600;
%Check if a configuration file exists and load it
if exist('Cfg.teo','file')
status = loadfile('Cfg.teo',1,'double');
if isnumeric(status)
handles.conv factor = abs(round(status));
else
handles.conv factor = default;
end else
handles.conv factor = default;
end
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes convconfig wait for user response (see UIRESUME) % uiwait(handles.convconf);
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % CLOSING FUNCTIONS %
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % −−− Outputs from this function are returned to the command line.
function varargout = Converter OutputFcn(hObject, eventdata, handles)
% 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} = handles.output;
% −−− Executes when user attempts to close Converter.
function Converter CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to Converter (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
delete(hObject);
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % TEXT FUNCTIONS %
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
function Txt km Callback(hObject, eventdata, handles)
% hObject handle to Txt km (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg('Please insert a numeric value','Bad Input','modal') temp = '';
end
if temp < 0 temp = 0;
end
[s, errmsg] = sprintf('%15.2f',temp); set(handles.Txt km,'String',s);
%Eval number of kilometers
num cyc = temp * handles.conv factor; [s, errmsg] = sprintf('%15.0f',num cyc); set(handles.Txt cycles,'String',s);
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt km CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt km (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt cycles Callback(hObject, eventdata, handles)
% hObject handle to Txt cycles (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg('Please insert a numeric value','Bad Input','modal') temp = ''; end if temp < 0 temp = 0; end temp = round(temp);
[s, errmsg] = sprintf('%15.0f',temp); set(handles.Txt cycles,'String',s);
%Eval number of kilometers
num km = temp / handles.conv factor; [s, errmsg] = sprintf('%15.2f',num km); set(handles.Txt km,'String',s);
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt cycles CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt cycles (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % PUSH BUTTON FUNCTION %
% −−− Executes on button press in Push callconfig.
function Push callconfig Callback(hObject, eventdata, handles)
% hObject handle to Push callconfig (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = gcf;
Converter CloseRequestFcn(temp, eventdata, handles); convconfig;
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % SUPPORTING FUNCTIONS %
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
function status = loadfile(string,dim,type)
%Load file (note: cross−control of goodness of loaded data should be %executed within the function that calls this routine)
status = 0;
if exist(string,'file')
file id = fopen(string,'r'); status = fread(file id,dim,type); fclose(file id);
end
%End of Function
A.3.2
Convconfig.m
function varargout = convconfig(varargin)
% File: convconfig.m
% Ver: 1.0
% Project: BMW PPQ5 % Authors: Teo
% Created: 15 May 07 % Last modified: 14 Jun 07
% Comments: File to evaluate conversion factor from # of % actuating cycles of a fuel injector and # of
% covered kilometers
%
% To do list: Debug and optimization %
% Known bugs: %
% History: 06/14/2007 Ver. 1.0
% + − First version issued
% % Dependencies: % − Converter.m; % − logoetinfo.mat; % − urban.txt or urban.xls; % − extra.txt or extra.xls; % − convconfig.fig; % − Converter.fig. % % Use: convconfig %
% This file produces a GUI to be used as a front−end for creating a % configuration file in order to eval the proper conversion factor % from # of actuating cycles to # of covered kilometers.
%
% This application relies on two external files, urban.txt and % extra.txt, which contains info about speed profile for an urban % cycle and an extra−urban one respectively. These files must be % organized as follows: % % es. % 0 0 % 15 20 % 20 15 % 50 65 % ... ... %
% where elements from the first column are seconds and others are % km/h. DO NOT insert text and space values with a simple tabulation. %
% You can also use urban.xls and extra.xls. In this case, Excel files % should be written in two columns: the first one will contains time % intervals while the second will be fitted with speed data. Note
% that use of .txt format is preferable because greater loading speed % and less CPU cycles.
%
% Actually there is not any cross check about the data contained in % loaded files so corrupt data will mean unreliable behaviour from the % application. Hope to fix this soon.
% %
% Copyright (C) 2006−2007 Matteo Masi %
% This program is free software; you can redistribute it and/or % modify it under the terms of the GNU General Public License % as published by the Free Software Foundation; either version 2 % of the License, or any later version.
%
% This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License % along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA % 02110−1301, USA.
% CONVCONFIG M−file for convconfig.fig
% CONVCONFIG, by itself, creates a new CONVCONFIG or raises the % existing singleton*.
%
% H = CONVCONFIG returns the handle to a new CONVCONFIG or the % handle to the existing singleton*.
%
% CONVCONFIG('CALLBACK',hObject,eventData,handles,...) calls the % local function named CALLBACK in CONVCONFIG.M with the given % input arguments.
%
% CONVCONFIG('Property','Value',...) creates a new CONVCONFIG or % raises the existing singleton*. Starting from the left,
% property value pairs are applied to the GUI before % convconfig OpeningFunction gets called. Anunrecognized
% property name or invalid value makes property application stop. % All inputs are passed to convconfig OpeningFcn via varargin. %
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows % only one instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002−2003 The MathWorks, Inc.
% Edit the above text to modify the response to help convconfig % Last Modified by GUIDE v2.5 21−May−2007 18:22:55
% Begin initialization code − DO NOT EDIT
gui Singleton = 1;
gui State = struct('gui Name', mfilename, ...
'gui Singleton', gui Singleton, ...
'gui OpeningFcn', @convconfig OpeningFcn, ...
'gui OutputFcn', @convconfig 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
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % OPENING FUNCTION %
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % −−− Executes just before convconfig is made visible.
function convconfig 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 convconfig (see VARARGIN) % Choose default command line output for convconfig
handles.output = hObject;
disp(' ')
disp('Cycles/Km converter − CONFIGURATION MANAGER') disp(' ')
disp('Copyright (C) 2006/2007 Matteo Masi')
disp('This software comes with ABSOLUTELY NO WARRANTY.')
disp('This is free software, and you are welcome to redistribuite it') disp('under certain conditions (see LICENSE.TXT for more details).') disp(' ')
%If file exists, display LOGO
set(handles.Axes logo,'Units','pixels');
if exist('logoetinfo.mat','file')
temp = load('−mat', 'logoetinfo.mat'); handles.logo = temp.logo;
handles.info = temp.info; axes(handles.Axes logo); cla;
image(handles.logo);
set(handles.Axes logo,'Visible','off', ...
'Units','pixels', ...
'Position',[20 20 handles.info.Width handles.info.Height]);
else
set(handles.Axes logo,'Visible','off');
end
%Clear profile axis
axes(handles.profile axis); cla;
set(handles.profile axis,'Visible','off');
%Set Strings in POP−UPs
string = strvcat('125','135','140','145','150','155','165','175',...
'185', '195','205','215','220','225','230','235','245','255',...
'265','275', '285','295','305','315','325','335','345','355'); set(handles.pop dim,'String',string);
string = strvcat('25','30','35','40','45','50','55','60','65','70',...
'75','80','85','90');
set(handles.pop tyre,'String',string);
string = strvcat('10','12','13','14','15','16','16.5','17','17.5',...
'18','19','20','21','22','23','24','25','39'); set(handles.pop R,'String',string);
%Set default values
handles.def.rapp.I = 3.35; handles.def.rapp.II = 2.13; handles.def.rapp.III = 1.44; handles.def.rapp.IV = 1.06; handles.def.rapp.V = 0.83; handles.def.rapp.bridge = 3.79; handles.def.speed.I = 15; handles.def.speed.II = 30; handles.def.speed.III = 50; handles.def.speed.IV = 75;
%Values in this structure are referred to the position of the real %value in the array of strings used to build pop−menu
handles.def.tyre.dim = 8; handles.def.tyre.tyre = 8; handles.def.tyre.R = 5;
%Set default value for idle's rpms
handles.def.misc.idle = 850; handles.def.misc.num cyc = 1;
%Set default number of profiles that will be executed to cover a %certain number of kilometers
handles.def.times.urban = 4; handles.def.times.extra = 1;
handles.def.lenght.urban = 1.1; handles.def.lenght.extra = 7.02;
%Set default conversion factor
handles.def.conv = 1600;
%Refresh handles & GUI
set(handles.Chk urban,'Value',get(handles.Chk urban,'Max')); set(handles.Chk extra,'Value',get(handles.Chk extra,'Max'));
handles = set default(handles);
%Refresh total kms or current profile
handles = eval km(hObject,handles);
%Refresh current conversion factor
handles = print conversion(handles);
%Set strings to be used if an error occurs
handles.string.error numvalue = 'Bad numeric data!';
handles.string.error = ['An error occurred while evaluating rpms.'...
' temp(i,3) out of limits. Application will be terminated!']; handles.string.saved error = ['An error occurred during saving.'...
' Maybe you do not own writing permissions on this drive or'...
' disk is full.'];
handles.string.saved ok = 'File successfully saved!';
handles.string.quest overwrite = ['File is already existing.'...
' Do you want to overwrite?'];
handles.string.quest reload = ['Values in edit boxes will be'...
' overwritten. Continue?'];
handles.string.warn missingfile = ['Requested file doesn''t exist!'...
' Operation aborted!'];
handles.string.warn badfile = 'Loaded file is corrupted!';
handles.string.atleastaprofile = ['At least a profile is needed in'...
' order to evaluate the correct conversion factor.'...
' Please select one of the two Check Boxes'];
%Enable all buttons except for DEFAULT one %set(handles.Push default,'Enable','off');
enable buttons(handles,'off');
%Disable call−for−converter
set(handles.Push converter,'Enable','off');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes convconfig wait for user response (see UIRESUME) % uiwait(handles.convconf);
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % CLOSING FUNCTIONS %
% −−− Executes when user attempts to close convconf.
function convconf CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to convconf (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
disp('Thanks for using this configuration manager!') disp(' ')
delete(hObject);
% −−− Outputs from this function are returned to the command line.
function varargout = convconfig 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} = handles.output;
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % TEXT FUNCTIONS %
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
function Txt 1st Callback(hObject, eventdata, handles)
% hObject handle to Txt 1st (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.rapp.I;
set(handles.Txt 1st,'String',temp);
end
if (temp ≤ handles.rapp.II) | | (temp > 10)
set(handles.Txt 1st,'String',handles.rapp.I);
else
handles.rapp.I = temp;
end
set(handles.Push default,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt 1st CreateFcn(hObject, eventdata, handles)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt 2nd Callback(hObject, eventdata, handles)
% hObject handle to Txt 2nd (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.rapp.II;
set(handles.Txt 2nd,'String',temp);
end
if (temp ≤ handles.rapp.III) | | (temp ≥ handles.rapp.I)
set(handles.Txt 2nd,'String',handles.rapp.II);
else
handles.rapp.II = temp;
end
set(handles.Push default,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt 2nd CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt 2nd (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt 3rd Callback(hObject, eventdata, handles)
% hObject handle to Txt 3rd (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.rapp.III;
set(handles.Txt 3rd,'String',temp);
end
if (temp ≤ handles.rapp.IV) | | (temp ≥ handles.rapp.II)
set(handles.Txt 3rd,'String',handles.rapp.III);
else
handles.rapp.III = temp;
end
set(handles.Push default,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt 3rd CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt 3rd (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt 4th Callback(hObject, eventdata, handles)
% hObject handle to Txt 4th (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.rapp.IV;
set(handles.Txt 4th,'String',temp);
end
if (temp ≤ handles.rapp.V) | | (temp ≥ handles.rapp.III) set(handles.Txt 4th,'String',handles.rapp.IV);
else
handles.rapp.IV = temp;
end
set(handles.Push default,'Enable','on');
% Update handles structure
% −−− Executes during object creation, after setting all properties.
function Txt 4th CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt 4th (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt 5th Callback(hObject, eventdata, handles)
% hObject handle to Txt 5th (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.rapp.V;
set(handles.Txt 5th,'String',temp);
end
if (temp ≤ 0.1) | | (temp ≥ handles.rapp.IV)
set(handles.Txt 5th,'String',handles.rapp.V);
else
handles.rapp.V = temp;
end
set(handles.Push default,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt 5th CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt 5th (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt bridge Callback(hObject, eventdata, handles)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.rapp.bridge;
set(handles.Txt bridge,'String',temp);
end
if (temp < 0.1) | | (temp ≥ 50)
set(handles.Txt bridge,'String',handles.rapp.bridge);
else
handles.rapp.bridge = temp;
end
set(handles.Push default,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt bridge CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt bridge (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt 1 2 Callback(hObject, eventdata, handles)
% hObject handle to Txt 1 2 (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.speed.I;
set(handles.Txt 1 2,'String',temp);
end
if (temp ≤ 0) | | (temp > 300) | | (temp ≥ handles.speed.II)
set(handles.Txt 1 2,'String',handles.speed.I);
else
handles.speed.I = temp;
end
shift refresh(handles);
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt 1 2 CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt 1 2 (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt 2 3 Callback(hObject, eventdata, handles)
% hObject handle to Txt 2 3 (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.speed.II;
set(handles.Txt 2 3,'String',temp);
end
if (temp ≤ handles.speed.I) | | (temp > 350) | |...
(temp ≥ handles.speed.III)
set(handles.Txt 2 3,'String',handles.speed.II);
else
handles.speed.II = temp;
end
shift refresh(handles);
set(handles.Push default,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt 2 3 CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt 2 3 (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt 3 4 Callback(hObject, eventdata, handles)
% hObject handle to Txt 3 4 (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.speed.III;
set(handles.Txt 3 4,'String',temp);
end
if (temp ≤ handles.speed.II) | | (temp > 400) | |...
(temp ≥ handles.speed.IV)
set(handles.Txt 3 4,'String',handles.speed.III);
else
handles.speed.III = temp;
end
shift refresh(handles);
set(handles.Push default,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt 3 4 CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt 3 4 (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt 4 5 Callback(hObject, eventdata, handles)
% hObject handle to Txt 4 5 (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.speed.IV;
end
if (temp ≤ handles.speed.III) | | (temp > 500)
set(handles.Txt 4 5,'String',handles.speed.IV);
else
handles.speed.IV = temp;
end
shift refresh(handles);
set(handles.Push default,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt 4 5 CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt 4 5 (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt idle Callback(hObject, eventdata, handles)
% hObject handle to Txt idle (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.misc.idle;
set(handles.Txt idle,'String',temp);
end
if (temp ≤ 0) | | (temp > 20000)
set(handles.Txt idle,'String',handles.misc.idle);
else
handles.misc.idle = temp;
end
set(handles.Push default,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt idle CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt idle (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt urban times Callback(hObject, eventdata, handles)
% hObject handle to Txt urban times (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.times.urban;
set(handles.Txt urban times,'String',temp);
end
temp = round(temp); %I have to be sure that I have an integer!!
if (temp ≤ 0) | | (temp > 500)
set(handles.Txt urban times,'String',handles.times.urban);
else
set(handles.Txt urban times,'String',temp); handles.times.urban = temp;
end
set(handles.Push default,'Enable','on'); handles = eval km(hObject,handles);
get(hObject,'String') handles.times.urban
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt urban times CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt urban times (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
function Txt extra times Callback(hObject, eventdata, handles)
% hObject handle to Txt extra times (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.times.extra;
set(handles.Txt extra times,'String',temp);
end
temp = round(temp); %I have to be sure that I have an integer!!
if (temp ≤ 0) | | (temp > 500)
set(handles.Txt extra times,'String',handles.times.extra);
else
set(handles.Txt extra times,'String',temp); handles.times.extra = temp;
end
set(handles.Push default,'Enable','on'); handles = eval km(hObject,handles);
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt extra times CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt extra times (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
function Txt cyc Callback(hObject, eventdata, handles)
% hObject handle to Txt cyc (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'String'); temp = str2double(temp);
if isnan(temp)
errordlg(handles.string.error numvalue,'Bad Input','modal') temp = handles.misc.num cyc;
set(handles.Txt cyc,'String',temp);
end
if (temp < 1) | | (temp > 100)
else
handles.misc.num cyc = temp;
end
shift refresh(handles);
set(handles.Push default,'Enable','on');
% Update handles structure
guidata(hObject, handles);
% −−− Executes during object creation, after setting all properties.
function Txt cyc CreateFcn(hObject, eventdata, handles)
% hObject handle to Txt cyc (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else set(hObject,'BackgroundColor',... get(0,'defaultUicontrolBackgroundColor')); end % * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % POP−UPs FUNCTIONS % % * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % −−− Executes on selection change in pop dim.
function pop dim Callback(hObject, eventdata, handles)
% hObject handle to pop dim (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
handles.tyre.dim = get(hObject,'Value'); set(handles.Push default,'Enable','on');
% Save the handles structure.
guidata(hObject,handles)
% −−− Executes during object creation, after setting all properties.
function pop dim CreateFcn(hObject, eventdata, handles)
% hObject handle to pop dim (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
% −−− Executes on selection change in pop tyre.
function pop tyre Callback(hObject, eventdata, handles)
% hObject handle to pop tyre (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
handles.tyre.tyre = get(hObject,'Value'); set(handles.Push default,'Enable','on');
% Save the handles structure.
guidata(hObject,handles)
% −−− Executes during object creation, after setting all properties.
function pop tyre CreateFcn(hObject, eventdata, handles)
% hObject handle to pop tyre (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
end
% −−− Executes on selection change in pop R.
function pop R Callback(hObject, eventdata, handles)
% hObject handle to pop R (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
handles.tyre.R = get(hObject,'Value'); set(handles.Push default,'Enable','on');
% Save the handles structure.
guidata(hObject,handles)
% −−− Executes during object creation, after setting all properties.
function pop R CreateFcn(hObject, eventdata, handles)
% hObject handle to pop R (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles empty − handles not created until after all CreateFcns
% called
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',...
get(0,'defaultUicontrolBackgroundColor'));
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % CHECK BOXES FUNCTIONS %
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % −−− Executes on button press in Chk urban.
function Chk urban Callback(hObject, eventdata, handles)
% hObject handle to Chk urban (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'Value');
if temp == get(hObject,'Min')
set(handles.Txt urban times,'Enable','off'); set(handles.text28,'Enable','off');
handles.times.urban = 0;
handles = eval km(hObject,handles);
else
set(handles.Txt urban times,'Enable','on'); set(handles.text28,'Enable','on');
value = get(handles.Txt urban times,'String'); handles.times.urban = str2double(value);
handles = eval km(hObject,handles);
end
% Update handles structure
guidata(hObject, handles);
% −−− Executes on button press in Chk extra.
function Chk extra Callback(hObject, eventdata, handles)
% hObject handle to Chk extra (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = get(hObject,'Value');
if temp == get(hObject,'Min')
set(handles.Txt extra times,'Enable','off'); set(handles.text29,'Enable','off');
handles.times.extra = 0;
handles = eval km(hObject,handles);
else
set(handles.Txt extra times,'Enable','on'); set(handles.text29,'Enable','on');
value = get(handles.Txt extra times,'String'); handles.times.extra = str2double(value);
handles = eval km(hObject,handles);
end
% Update handles structure
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % PUSH BUTTONS FUNCTIONS %
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % −−− Executes on button press in Push edit urban.
function Push edit urban Callback(hObject, eventdata, handles)
% hObject handle to Push edit urban (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
axes(handles.profile axis);
if exist('urban.txt','file')
num = textread('urban.txt','','emptyvalue',NaN);
elseif exist('urban.xls','file') num = xlsread('urban.xls');
else
warndlg(handles.string.warn missingfile,'urban.txt is missing');
return end [m,n] = size(num); if (n == 2) && (m > 1) cla; handles.urban.profile = num; handles.current.profile = num;
set(handles.profile axis,'Visible','on'); shifts = shift gear(num,handles.speed); plot(num(:,1),num(:,2)); hold on plot(shifts(:,1),shifts(:,2),'r*'); xlabel('Time [s]'); ylabel('Speed [km/h]'); y min = 0;
y max = max(num(:,2)) + round(max(num(:,2))/10); ylim([y min y max]);
legend('Speed profile','Gears'' shifts','Location','NorthWest'); title('Urban speed profile');
else
warndlg(handles.string.warn badfile,'File urban.* is not valid');
end
% Update handles structure
guidata(hObject, handles);
% −−− Executes on button press in Push edit extra.
function Push edit extra Callback(hObject, eventdata, handles)
% hObject handle to Push edit extra (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
axes(handles.profile axis);
if exist('extra.txt','file')
elseif exist('extra.xls','file') num = xlsread('extra.xls');
else
warndlg(handles.string.warn missingfile,'extra.txt is missing');
return end [m,n] = size(num); if (n == 2) && (m > 1) cla; handles.extra.profile = num; handles.current.profile = num;
set(handles.profile axis,'Visible','on'); shifts = shift gear(num,handles.speed); plot(num(:,1),num(:,2)); hold on plot(shifts(:,1),shifts(:,2),'r*'); xlabel('Time [s]'); ylabel('Speed [km/h]'); y min = 0;
y max = max(num(:,2)) + round(max(num(:,2))/10); ylim([y min y max]);
legend('Speed profile','Gears'' shifts','Location','NorthWest'); title('Extra−urban speed profile');
else
warndlg(handles.string.warn badfile,'File extra.* is not valid');
end
% Update handles structure
guidata(hObject, handles);
% −−− Executes on button press in Push default.
function Push default Callback(hObject, eventdata, handles)
% hObject handle to Push default (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
set(handles.Chk urban,'Value',get(handles.Chk urban,'Max')); set(handles.Chk extra,'Value',get(handles.Chk extra,'Max'));
handles = set default(handles);
set(handles.Push default,'Enable','off');
%Refresh total kms or current profile
handles = eval km(hObject,handles);
%Refresh current conversion factor
handles = print conversion(handles);
%Eventually update gears' shifts on plot
shift refresh(handles);
% Update handles structure
guidata(hObject, handles);
function Push load Callback(hObject, eventdata, handles)
% hObject handle to Push load (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %Number of parameters to be loaded
num param = 20;
%Ask for overwrite of infos in dialog boxes
user response = questdlg(handles.string.quest reload,...
'Confirm Load','No');
switch user response
case 'Yes'
status = loadfile('Cfg.teo',num param,'double');
if status == 0
warndlg(handles.string.warn missingfile,'File error');
else
[m, n] = size(status);
if (m ≥ n) && (m == num param)
handles.conv = status(1); handles.rapp.I = status(2); handles.rapp.II = status(3); handles.rapp.III = status(4); handles.rapp.IV = status(5); handles.rapp.V = status(6); handles.rapp.bridge = status(7); handles.speed.I = status(8); handles.speed.II = status(9); handles.speed.III = status(10); handles.speed.IV = status(11); handles.misc.idle = status(12); handles.times.urban = status(13); handles.times.extra = status(14);
set(handles.Chk urban,'Value',status(15)); set(handles.Chk extra,'Value',status(16)); handles.tyre.dim = status(17);
handles.tyre.tyre = status(18); handles.tyre.R = status(19);
handles.misc.num cyc = status(20); refresh gui(handles);
set(handles.Push default,'Enable','on');
%Refresh total kms or current profile
if (status(18) == get(handles.Chk urban,'Min')) handles.times.urban = 0;
end
if (status(19) == get(handles.Chk urban,'Min')) handles.times.extra = 0;
end
handles = eval km(hObject,handles);
%Refresh current conversion factor
handles = print conversion(handles);
%Eventually refresh geras' shifts
shift refresh(handles);
warndlg(handles.string.warn badfile,'Invalid file'); end end otherwise %do nothing end
% Update handles structure
guidata(hObject, handles);
% −−− Executes on button press in Push save.
function Push save Callback(hObject, eventdata, handles)
% hObject handle to Push save (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
%First of all we generate a vector that contains all data to be saved
conf = [handles.conv; handles.rapp.I; handles.rapp.II;...
handles.rapp.III; handles.rapp.IV; handles.rapp.V;...
handles.rapp.bridge; handles.speed.I; handles.speed.II;...
handles.speed.III; handles.speed.IV; handles.misc.idle;...
str2double(get(handles.Txt urban times,'String'));...
str2double(get(handles.Txt extra times,'String'));...
get(handles.Chk urban,'Value');...
get(handles.Chk extra,'Value');...
get(handles.pop dim,'Value'); get(handles.pop tyre,'Value');...
get(handles.pop R,'Value')];
%Saving...
status = savefile(handles,'Cfg.teo',conf,'double');
if status == 0
errordlg(handles.string.saved error,'Saving failed')
elseif status == 1
helpdlg(handles.string.saved ok,'File saved')
end
% −−− Executes on button press in Push main.
function Push main Callback(hObject, eventdata, handles)
% hObject handle to Push main (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %This function takes all relevant data contanined in the GUI and %produce a conversion factor. After that, it save all this stuff %into a config file.
%Collect all useful data
%handles.speed %Contains speed of gears' shifts %handles.rapp %Contains gears' ratios
%handles.tyre %Contains info about tyres
%handles.misc.idle %Contains engine idle speed
%handles.lenght %Contains lenghts of driving profiles %handles.conv %Contains conversion factor
temp urban = get(handles.Chk urban,'Value'); temp extra = get(handles.Chk extra,'Value');
if (temp urban == get(handles.Chk urban,'Min')) && ...
(temp extra == get(handles.Chk extra,'Min'))
warndlg(handles.string.atleastaprofile,'A profile is needed');
return end
%Disable all buttons
handles.status = get(handles.Push default,'Enable'); disable buttons(handles);
%Disable call−for−converter
set(handles.Push converter,'Enable','off');
%First of all: get all profiles and gears' shifts
if temp urban == get(handles.Chk urban,'Max')
if exist('urban.txt','file')
num = textread('urban.txt','','emptyvalue',NaN);
elseif exist('urban.xls','file') num = xlsread('urban.xls');
else warndlg(handles.string.warn missingfile,... 'urban.txt is missing'); enable buttons(handles,handles.status); return end [m,n] = size(num); if (n == 2) && (m > 1) handles.urban.profile = num;
urbanshifts = shift gear(num,handles.speed);
else
warndlg(handles.string.warn badfile,...
'File urban.* is not valid');
enable buttons(handles,handles.status);
return end
end
if temp extra == get(handles.Chk extra,'Max')
if exist('extra.txt','file')
num = textread('extra.txt','','emptyvalue',NaN);
elseif exist('extra.xls','file') num = xlsread('extra.xls');
else warndlg(handles.string.warn missingfile,... 'extra.txt is missing'); enable buttons(handles,handles.status); return end [m,n] = size(num); if (n == 2) && (m > 1)
handles.extra.profile = num;
extrashifts = shift gear(num,handles.speed);
else
warndlg(handles.string.warn badfile,...
'File extra.* is not valid');
enable buttons(handles,handles.status);
return end
end
%Tyre dimensions
string list = get(handles.pop dim,'String'); dim = string list(handles.tyre.dim,:);
dim = str2double(dim);
string list = get(handles.pop tyre,'String'); tyre = string list(handles.tyre.tyre,:); tyre = str2double(tyre);
string list = get(handles.pop R,'String'); R = string list(handles.tyre.R,:);
R = str2double(R);
handles.circ = ((R * 25.4 + dim * (tyre / 100) * 2) * pi) / 1000; a = handles.circ;
%Eval number of rounds for urban cycle
if temp urban == get(handles.Chk urban,'Max')
urban = format profile(handles.urban.profile,urbanshifts,...
handles);
[m,n] = size(urban); temp = urban(m,n);
urban round = ceil(temp) * handles.times.urban;
else
urban round = 0;
end
%Eval number of rounds for extra cycle
if temp extra == get(handles.Chk extra,'Max')
extra = format profile(handles.extra.profile,extrashifts,...
handles);
[m,n] = size(extra); temp = extra(m,n);
extra round = ceil(temp) * handles.times.extra;
else
extra round = 0;
end
%Total engine rounds
tot rounds = urban round + extra round;
%Total number of cycles
%Note: # rounds per actuation = 2 / # actuations.
%"2" because I assume to work on Four−stroke cycle engine.
cycles = (tot rounds / 2) * handles.misc.num cyc;
conv = cycles / handles.tot km;
conv = ceil(conv + 0.05 * conv); % +5% because of all hypotheses
handles.conv = round(conv/100) * 100; % Round to next hundreds
%Then we generate a vector that contains all data to be saved
conf = [handles.conv; handles.rapp.I; handles.rapp.II;...
handles.rapp.III; handles.rapp.IV; handles.rapp.V;...
handles.rapp.bridge; handles.speed.I; handles.speed.II;...
handles.speed.III; handles.speed.IV; handles.misc.idle;...
str2double(get(handles.Txt urban times,'String'));...
str2double(get(handles.Txt extra times,'String'));...
get(handles.Chk urban,'Value');...
get(handles.Chk extra,'Value');...
get(handles.pop dim,'Value'); get(handles.pop tyre,'Value');...
get(handles.pop R,'Value')];
%Saving without asking for overwriting
status = savefile(handles,'Cfg.teo',conf,'double',1);
%Print new conversion factor
print conversion(handles);
%Restore GUI
enable buttons(handles,handles.status);
if (status == 1)
%Enable call−for−converter
set(handles.Push converter,'Enable','on');
else
errordlg(handles.string.saved error,'Saving failed')
end
% Update handles structure
guidata(hObject, handles);
% −−− Executes on button press in Push converter.
function Push converter Callback(hObject, eventdata, handles)
% hObject handle to Push converter (see GCBO)
% eventdata reserved − to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
temp = gcf;
convconf CloseRequestFcn(temp, eventdata, handles); Converter;
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * % % SUPPORTING FUNCTIONS %
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
function handles = set default(handles)
%Refresh handles handles.rapp.I = handles.def.rapp.I; handles.rapp.II = handles.def.rapp.II; handles.rapp.III = handles.def.rapp.III; handles.rapp.IV = handles.def.rapp.IV; handles.rapp.V = handles.def.rapp.V; handles.rapp.bridge = handles.def.rapp.bridge; handles.speed.I = handles.def.speed.I; handles.speed.II = handles.def.speed.II; handles.speed.III = handles.def.speed.III; handles.speed.IV = handles.def.speed.IV; %handles.misc.tyres = handles.def.misc.tyres; handles.tyre.dim = handles.def.tyre.dim; handles.tyre.tyre = handles.def.tyre.tyre; handles.tyre.R = handles.def.tyre.R; handles.misc.idle = handles.def.misc.idle;
handles.misc.num cyc = handles.def.misc.num cyc;
handles.times.urban = handles.def.times.urban; handles.times.extra = handles.def.times.extra; handles.lenght.urban = handles.def.lenght.urban; handles.lenght.extra = handles.def.lenght.extra; handles.conv = handles.def.conv; refresh gui(handles); %End of Function
function refresh gui(handles)
%This function refreshes GUI with values contained in handles %Refresh GUI
set(handles.Txt 1st,'String',handles.rapp.I); set(handles.Txt 2nd,'String',handles.rapp.II); set(handles.Txt 3rd,'String',handles.rapp.III); set(handles.Txt 4th,'String',handles.rapp.IV); set(handles.Txt 5th,'String',handles.rapp.V);
set(handles.Txt bridge,'String',handles.rapp.bridge);
set(handles.Txt 1 2,'String',handles.speed.I); set(handles.Txt 2 3,'String',handles.speed.II); set(handles.Txt 3 4,'String',handles.speed.III); set(handles.Txt 4 5,'String',handles.speed.IV);
set(handles.Txt idle,'String',handles.misc.idle); set(handles.Txt cyc,'String',handles.misc.num cyc);
set(handles.Txt urban times,'String',handles.times.urban); set(handles.Txt extra times,'String',handles.times.extra);
set(handles.pop dim,'Value',handles.tyre.dim); set(handles.pop tyre,'Value',handles.tyre.tyre); set(handles.pop R,'Value',handles.tyre.R);
%Set checkboxes
if (get(handles.Chk urban,'Value') == get(handles.Chk urban,'Max')) set(handles.Txt urban times,'Enable','on');
set(handles.text28,'Enable','on');
else
set(handles.Txt urban times,'Enable','off'); set(handles.text28,'Enable','off');
end
if (get(handles.Chk extra,'Value') == get(handles.Chk extra,'Max')) set(handles.Txt extra times,'Enable','on');
set(handles.text29,'Enable','on');
else
set(handles.Txt extra times,'Enable','off'); set(handles.text29,'Enable','off');
end
%End of Function
function handles = eval km(hObject,handles)
%Eval total kms to be covered during test
%Total km = # urban cycles * urban cycle lenght + # extra−urban %cycles * extra−urban cycle lenght
handles.tot km = handles.times.urban * handles.lenght.urban + ...
handles.times.extra * handles.lenght.extra;
%Print result on GUI
set(handles.Txt km tot,'String',handles.tot km);
% Update handles structure
guidata(hObject, handles);
%End of Function
function handles = print conversion(handles)
%Buid a string like this: #cycles + cycles + / + km
string = [num2str(handles.conv) ' cycles/km']; set(handles.Txt conversion,'String',string);
%End of Function
function status = savefile(handles,string,conf,type,overwrite)
%Save file
status = 0;
user response = questdlg(handles.string.quest overwrite, ...
'Confirm Overwriting','No');
switch user response
case 'Yes' %go on otherwise status = 2; return end end file id = fopen(string,'w'); temp = fwrite(file id,conf,type); fclose(file id);
if temp > 0 status = 1;
end
%End of Function
function status = loadfile(string,dim,type)
%Load file (note: cross−control of goodness of loaded data should be %executed within the function that calls this routine)
status = 0;
if exist(string,'file')
file id = fopen(string,'r'); status = fread(file id,dim,type); fclose(file id);
end
%End of Function
function shifts = shift gear(profile,speed)
%Finds gears' shifts during urban and extra−urban profiles (depending %on input argument)
temp = zeros(1,3); [m,n] = size(profile);
%inside TEMP vector we can find 3 values: time of shift, speed of %shift, inserted gear
i = 1;
for j = 1:(m−1)
%Line from profile(j) to profile(j+1)
coeff = (profile(j+1,2)−profile(j,2))/(profile(j+1,1) − ... profile(j,1)); cost = (profile(j,2)*(profile(j+1,1)−profile(j,1)) − ... profile(j,1)*(profile(j+1,2)−profile(j,2)))/ ... (profile(j+1,1)−profile(j,1)); %Inverse function x = @(y)((y−cost)/coeff);
if (speed.I < profile(j+1,2))
%A change from I to II gear may have occurred
time s = x(speed.I);
if (time s > profile(j,1)) && (time s < profile(j+1,1)) [temp, i] = refresh temp(temp, i, ...
[time s speed.I 2]);
end end
if (speed.II < profile(j+1,2))
%A change from II to III gear may have occurred
time s = x(speed.II);
if (time s > profile(j,1)) && (time s < profile(j+1,1)) [temp, i] = refresh temp(temp, i, ...
[time s speed.II 3]);
end end
if (speed.III < profile(j+1,2))
%A change from III to IV gear may have occurred
time s = x(speed.III);
if (time s > profile(j,1)) && (time s < profile(j+1,1)) [temp, i] = refresh temp(temp, i, ...
[time s speed.III 4]);
end end
if (speed.IV < profile(j+1,2))
%A change from IV to V gear may have occurred
time s = x(speed.IV);
if (time s > profile(j,1)) && (time s < profile(j+1,1)) [temp, i] = refresh temp(temp, i, ...
[time s speed.IV 5]);
end end
elseif (profile(j+1,2) < profile(j,2)) %gear down
if (i − 1 == 0) k = 1;
else
k = i − 1;
end
if (speed.III > profile(j+1,2)) && (temp(k,3) == 5)
%A change from V to IV gear may have occurred
time s = x(speed.III);
if (time s ≥ profile(j,1)) && (time s ≤ profile(j+1,1)) [temp, i, k] = refresh temp(temp,i,...
[time s speed.III 4],k);
end end
if (speed.II > profile(j+1,2)) && (temp(k,3) == 4)
%A change from IV to III gear may have occurred
time s = x(speed.II);
if (time s ≥ profile(j,1)) && (time s ≤ profile(j+1,1))
[temp, i, k] = refresh temp(temp,i,...
[time s speed.II 3],k);
end end
if (speed.I > profile(j+1,2)) && (temp(k,3) == 3)
%A change from III to II gear may have occurred
time s = x(speed.I);
if (time s ≥ profile(j,1)) && (time s ≤ profile(j+1,1))
[temp, i, k] = refresh temp(temp,i,...
[time s speed.I 2],k);
end end
if (profile(j+1,2) == 0) && (temp(k,3) == 2)
%A change from II to I gear is occurred
[temp, i] = refresh temp(temp, i, [profile(j+1,1) 0 1]);
end end end
temp shift = sortrows(temp); [m,n] = size(temp shift); i = 2;
while (i<m)
if temp shift(i,3) == temp shift(i−1,3)
temp shift = [temp shift(1:(i−1),:) ; temp shift((i+1):m,:)]; m = m − 1;
i = i − 1;
end
i = i + 1;
end
shifts = temp shift;
%End of Function
function [temp, i, k] = refresh temp(temp, i, info, k)
%Used to store data in a TEMP vector
temp(i,:) = info; i = i + 1;
k = i − 1;
%End of Function
function shift refresh(handles)
%This function evals gears' shifts and eventually refreshes %profile axis
temp = get(handles.profile axis,'Visible');
if strcmpi(temp,'On')
shifts = shift gear(handles.current.profile,handles.speed); axis(handles.profile axis); cla; plot(handles.current.profile(:,1),... handles.current.profile(:,2)); hold on plot(shifts(:,1),shifts(:,2),'r*');
xlabel('Time [s]'); ylabel('Speed [km/h]'); y min = 0;
y max = max(handles.current.profile(:,2)) + ...
round(max(handles.current.profile(:,2))/10); ylim([y min y max]);
legend('Speed profile','Gears'' shifts','Location',...
'NorthWest');
end
%End of Function
function disable buttons(handles)
%Disable all buttons
set(handles.Push default,'Enable','off'); set(handles.Push load,'Enable','off');
set(handles.Push edit urban,'Enable','off'); set(handles.Push edit extra,'Enable','off'); set(handles.Push main,'Enable','off');
%End of Function
function enable buttons(handles,status)
%Enable all buttons
set(handles.Push default,'Enable',status); set(handles.Push load,'Enable','on');
set(handles.Push edit urban,'Enable','on'); set(handles.Push edit extra,'Enable','on'); set(handles.Push main,'Enable','on');
%End of Function
function matrix = format profile(profile,shifts,handles)
%Formats profile and gears' shifts' data
[m,n] = size(profile);
profile = [profile zeros(m,1)]; temp = [profile; shifts];
temp = sortrows(temp); [m,n] = size(temp); i = 1;
while (i<m)
if (temp(i,1) == temp(i+1,1)) && (temp(i,3) == 0) temp = [temp(1:(i−1),:) ; temp((i+1):m,:)]; m = m − 1;
i = i − 1;
end
i = i + 1;