-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo.m
318 lines (289 loc) · 11.2 KB
/
go.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
function go(varargin)
% GO starts ASM project.
%
% go (varargin)
%
% Arguments:
%
% parameter: 'simmode'
%
% value: 'PC' - for off-line simulation on PC under SIMULINK
% 'HIL' - for real-time simulation on Real-Time HW
% with ECU connected
% 'CPT' - for real-time simulation on Real-Time HW
% without ECU connected
%
% The first argument defines the simulation mode in which
% ASM should be used. Calling GO without 'simmode' initialzes
% the default simulation mode.
% The simmode influence the parameterization and controls the
% asm_switch_online_offline function.
% For VEOS it is always switched to offline independent from
% simmode
%
% ---------------------------------------------------------------
%
% parameter: <VARIANTLIST> - Name of variant definition list e.g. 'engine'
%
% value: <VARIANTNAME> - Name of variant e.g. 'EngineVariant2'
%
% The second argument defines the initialisation variant which
% should be loaded to the MATLAB workspace. You can easily add
% further variants by attaching other variant structures e.g.
%
% godata.variants.engine = { ...
% 'EngineVariant1',... <== Default engine variant
% 'EngineVariant2',...
% };
%
% godata.variants.drivetrain = { ...
% 'DrivetrainVariant1',... <== Default drivetrain variant
% 'DrivetrainVariant2',...,
% 'DrivetrainVariant3',...
% };
%
% ... append own variants in the same way.
%
% Calling GO without variant arguments initialzes the default
% variants. They are always on the first position of each
% variant definition list.
%
% ---------------------------------------------------------------
%
% parameter: drivingcycle
%
% value: <CYCLENAME>
% The second argument defines the cycle variant which
% should be loaded to the MATLAB workspace.
%
% Calling GO without drivingcycles arguments initialzes the default
% cycle. This are always on the first position of cycle definition list.
%
% ---------------------------------------------------------------
%
% parameter: platform
%
% value: 'RTI' - DS1005, DS1006, DS1007, DS1202
% 'SCALEXIO' - Simulator Hardware
% 'VEOS' - Offline Simulation Platform
%
% Platform controls the RTWSystemTargetFile and the
% asm_switch_online_offline function.
% For VEOS it is always switched to offline independent from
% simmode
% Calling GO without platform arguments initialzes the default
% platform. This is always on the first position of platform definition list.
%
% ---------------------------------------------------------------
%
% Examples:
%
% - Start of default variant 'Diesel4Cyl2p0l' with
% default simulation mode 'PC'
%
% go
%
% - Start of default variant 'Diesel4Cyl2p0l'
% with simulation mode 'PC'
%
% go PC
% go ('simmode','PC')
%
% - Start of user defined variant 'Diesel4Cyl2p0lAdvTurbo' with
% simulation mode 'PC'
%
% go ('simmode','PC','engine','Diesel4Cyl2p0lAdvTurbo')
%
% - Start of user defined variant 'TruckDiesel6Cyl12p0l' with
% simulation mode 'HIL'
%
% go ('simmode','HIL','engine','TruckDiesel6Cyl12p0l')
%
% See also:
%
%
% REMARKS
%
%
% AUTHOR(S): dSPACE
%
%
% Copyright 2005 - 2015 by dSPACE GmbH, GERMANY
% =========================================================================
% ===== DEFINE SETTINGS AND DEFAULTS =====
% =========================================================================
DefSimMode = 'PC'; % <== Default simulation mode
DefPlatform = {'SCALEXIO',... % <== Default platform (always first)
'RTI',...
'VEOS'};
SimulationModel = 'ASM_EngineDiesel';
% =========================================================================
% ===== INSERT YOUR VARIANTS HERE =====
% =========================================================================
godata.variants.engine = { ...
'Diesel4Cyl2p0l',... % <== Default variant (always first variant)
'Diesel4Cyl2p0lAdvTurbo',...
'TruckDiesel6Cyl12p0l',...
'TruckDiesel6Cyl12p0lSAETurbo',...
'TruckDiesel6cyl12p0lSCR',...
};
drivingcycles = {...
'Ftp_75',... % <== Default cycle (always first cycle)
'AC',...
'ESC',...
'ETC',...
'EUDC',...
'EUDC_with_6gear',...
'EUDC_with_gear',...
'FTP_Transient',...
'Ftp_75_short',...
'HIGHWAY',...
'JP_JE05',...
'JP_JE05_with_Gear',...
'Jap_10_15',...
'SC03',...
'US06',...
'WHTC',...
'ffe_city',...
'JP_JC08',...
'WLTC_Class1',...
'WLTC_Class2',...
'WLTC_Class3',...
};
% Apply defaults
CurPlatform = DefPlatform{1};
CycleName = drivingcycles{1};
try
% =========================================================================
%% ===== CHECK OF DSPACE AND HILTOOL INSTALLATION =====
% =========================================================================
home;
% check ASM Installation
i_checkdspaceinstallation
% Uncomment next lines if hiltools have been added to this project
% i_checkhiltoolsinstallation
% dspacehiltoolsrc;
%% Handle vargin calling
if(nargin==0)
varargin{1} = 'simmode';
varargin{2} = DefSimMode;
elseif(nargin==1)
varargin{2} = varargin{1};
varargin{1} = 'simmode';
elseif(any(strcmpi(varargin{1},{'hil','cpt','pc'})))
for k=nargin:-1:1
varargin{k+1} = varargin{k};
end
varargin{1} = 'simmode';
else
if ~strcmpi(varargin{1},'simmode')
for k=nargin:-1:1
varargin{k+2} = varargin{k};
end
varargin{1} = 'simmode';
varargin{2} = DefSimMode;
end
end
varargin{2} = upper(varargin{2});
%% Check for and get driving cycle and remove from varargin
indx = find(strcmpi(varargin(1:2:end),'drivingcycle'))*2;
if ~isempty(indx)
CycleName = varargin{indx};
end
%% Check for and get platform and remove from varargin
indx = find(strcmpi(varargin(1:2:end),'platform'))*2;
if ~isempty(indx)
CurPlatform = varargin{indx};
end
godata.excludepath = {};
% The following parameter are not an initialization variant and have to be ignored
godata.excludeparameter = {'simmode','drivingcycle','platform'};
% Add Simulation Model to godata
godata.CurrentSystem = {SimulationModel};
%% Start Initialization
fprintf(['Simulation Mode: ', varargin{2}, '\n\n']);
if ~SimulationInit(godata,varargin{:});
error('asm:SimulationInit','Model initialization failed.\nRefer to messages above for details.')
end
%% Initialize driving or engine cycle
asm_eng_drivingcycles('drivingcyclego','CycleList',drivingcycles,'CycleName', CycleName);
try
load_system(SimulationModel);
open_system(SimulationModel);
catch asm_error
fprintf('\n### ERROR opening model: %s.\n',SimulationModel)
rethrow(asm_error)
end
% Set the simulation platform
i_setplatform(SimulationModel,CurPlatform);
% ... switch of warning for ToWorkspace blocks in ForIterator subsystems
warning('off', 'Simulink:logLoadBlocks:ToWksInIteratorSystem')
fprintf('\n*** GO successfully executed.\n')
catch asm_error
asm_migrate_common('showerror','Exception',asm_error)
fprintf('\n*** GO failed.\n')
end
return
% =====================================================================================================================
function i_checkdspaceinstallation()
if ~exist('asmver','file')
error('asm:asmnotinstalled','dSPACE Automotive Simulation Models (ASM) Software is not installed for this MATLAB version.\n')
end
return % end of i_checkdspaceinstallation
% =====================================================================================================================
function i_checkhiltoolsinstallation() %#ok<DEFNU>
if ~exist('dspacehiltoolsrc','file')
error('asm:hiltoolsnotinstalled','dSPACE HILTools not installed for this MATLAB version.\n')
end
return % end of i_checkhiltoolsinstallation
% =====================================================================================================================
function check = i_setplatform(MdlName,platform)
% Check if model is open and make settings
if any(strcmp(find_system('type', 'block_diagram'),MdlName))
switch lower(platform)
case 'rti'
set_param(MdlName,'SimulationMode','normal');
Board='Offline';
if exist('rtiver','file')
% Get active RTI
Board = rtiver('Type');
else
% Return if RTI is not installed
check = 1;
return
end
% Get active system target file
SysTrgFile = get_param(MdlName,'RTWSystemTargetFile');
% Set model configuration parameters
% if system target file does not match to active RTI
if ~strncmpi(Board, SysTrgFile, 7)
asm_set_rti(MdlName,'EngineDiesel');
i_set_rti(MdlName);
end
case 'scalexio'
% do nothing
% settings are done by ConfigurationDesk
case 'veos'
asm_set_veos(MdlName);
otherwise
error('asm:go:invalidplatform','Platform %s is not supported. Valid platforms are ''RTI'', ''VEOS'' or ''SCALEXIO''.',platform)
end
else
error('asm:go:nomodel','Could not set platform ''%s'' for model ''%s''.\nThe model is not open',platform,MdlName)
end
check = 1;
return
% =====================================================================================================================
function i_set_rti(MdlName)
if any(strcmp(find_system('type','block_diagram'),MdlName))
% set further compiler options for DS1005 if set_rti was successful
SysTrgFile = get_param(MdlName,'RTWSystemTargetFile');
if strcmp(SysTrgFile,'rti1005.tlc')
rti_optionset(MdlName, ...
'CCompilerOptimizationOptsPopup','User-defined',...
'CCompilerOptimizationOpts','-O ');
end
else
fprintf(['### Warning: Could not set RTI settings for model ',upper(MdlName),'.\n'])
end
return