Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/contributed/convertMapMat2XML.M
169674 views
1
% File: convertMapMat2XML.m
2
% Author: Lucas Koch ([email protected])
3
% Teaching and Research Area Mechatronics in Mobile Propulsion (MMP)
4
% RWTH Aachen University
5
% Copyright: Eclipse Public License v2.0
6
% (https://www.eclipse.org/legal/epl-2.0/)
7
% MATLAB script for conversion of powerloss maps generated with the electric
8
% machine design tool developed by Kalt et. al. (DOI: 10.1109/EVER.2019.8813601)
9
% into xml-format required for the MMPEVEM emission model in SUMO.
10
% If you use this model for academic research, you are highly encouraged to
11
% cite our paper "Accurate physics-based modeling of electric vehicle energy
12
% consumption in the SUMO traffic microsimulator"
13
% (DOI: 10.1109/ITSC48978.2021.9564463).
14
15
% After execution of the TUM Tool GUI,
16
% the results contains these three structs:
17
% Maschinendaten
18
% handles_Kennfeld
19
% handles
20
% For conversion of the motor's power loss map, only the Maschinendaten struct
21
% needs to be available in the workspace.
22
23
24
% Specify path and a filename for xml
25
savePath = fullfile(pwd,"export.xml");
26
27
if exist("Maschinendaten")
28
% struct Maschinendaten contains only data for Tq > 0 & n > 0
29
% Mirror losses to negative torque-axis
30
tq_axis_pos = Maschinendaten.Kennfeld.M_max_mesh(:,1);
31
pwrMotLoss_pos = Maschinendaten.Kennfeld.Verluste.P_vges_mesh;
32
tq_axis = [-flip(tq_axis_pos); tq_axis_pos(2:end)];
33
pwrMotLoss = [flip(pwrMotLoss_pos); pwrMotLoss_pos(2:end,:)];
34
35
%convert n_axis to rpm
36
n_max = Maschinendaten.Optionen.n_max; % [rpm]
37
n_axis = Maschinendaten.Kennfeld.omega_k_mesh(1,1:end);
38
n_axis = n_max/max(n_axis)*n_axis;
39
40
tmp = "2,1|";
41
% write n_axis-vector
42
for i = 1:length(n_axis)
43
tmp = append(tmp, num2str(n_axis(i)));
44
if i ~= length(n_axis)
45
tmp = append(tmp,",");
46
else
47
tmp = append(tmp,";");
48
end
49
end
50
51
% write tq_axis-vector
52
for i = 1:length(tq_axis)
53
tmp = append(tmp, num2str(tq_axis(i)));
54
if i ~= length(tq_axis)
55
tmp = append(tmp,",");
56
else
57
tmp = append(tmp,"|");
58
end
59
end
60
61
% fill NaNs with last non-NaN value on Tq-axis
62
for j = 1:length(n_axis)
63
if isnan(pwrMotLoss(1,j))
64
idx1 = find(~isnan(pwrMotLoss(:,j)),1,'first');
65
pwrMotLoss(1:idx1-1,j) = pwrMotLoss(idx1,j);
66
end
67
if isnan(pwrMotLoss(end,j))
68
idx2 = find(~isnan(pwrMotLoss(:,j)),1,'last');
69
pwrMotLoss(idx2+1:end,j) = pwrMotLoss(idx2,j);
70
end
71
end
72
73
74
%write powerloss-data
75
for i = 1:length(tq_axis)
76
for j = 1:length(n_axis)
77
if ~isnan(pwrMotLoss(i,j))
78
tmp = append(tmp,num2str(round(pwrMotLoss(i,j),2)));
79
if ~(i == length(tq_axis) && j == length(n_axis))
80
tmp = append(tmp,",");
81
end
82
end
83
end
84
end
85
86
%open docNode and append data
87
docNode = com.mathworks.xml.XMLUtils.createDocument('routes');
88
routes = docNode.getDocumentElement;
89
vType = docNode.createElement('vType');
90
routes.appendChild(vType);
91
param = docNode.createElement('param');
92
param.setAttribute('key','powerLossMap');
93
param.setAttribute('value',tmp);
94
vType.appendChild(param);
95
xmlwrite(savePath,docNode);
96
97
%open saved xml
98
winopen(savePath);
99
100
else
101
disp('Maschinendaten missing. Please load them into the workspace.');
102
end
103
104
105