Ticket #5400: myEVpkg.mo

File myEVpkg.mo, 17.0 KB (added by massimo ceraolo, 7 years ago)
Line 
1package myEVpkg
2 model DragForce "Vehicle rolling and aerodinamical drag force"
3 import Modelica.Constants.g_n;
4 extends Modelica.Mechanics.Translational.Interfaces.PartialElementaryOneFlangeAndSupport2;
5 extends Modelica.Mechanics.Translational.Interfaces.PartialFriction;
6 Modelica.SIunits.Force f "Total drag force";
7 Modelica.SIunits.Velocity v "vehicle velocity";
8 Modelica.SIunits.Acceleration a "Absolute acceleration of flange";
9 Real Sign;
10 parameter Modelica.SIunits.Mass m "vehicle mass";
11 parameter Modelica.SIunits.Density rho(start = 1.226) "air density";
12 parameter Modelica.SIunits.Area S "vehicle cross area";
13 parameter Real fc(start = 0.01) "rolling friction coefficient";
14 parameter Real Cx "aerodinamic drag coefficient";
15 protected
16 parameter Real A = fc * m * g_n;
17 parameter Real B = 1 / 2 * rho * S * Cx;
18 // Constant auxiliary variable
19 equation
20// s = flange.s;
21 v = der(s);
22 a = der(v);
23// Le seguenti definizioni seguono l'ordine e le richieste del modello "PartialFriction" di
24// Modelica.Mechanics.Translational.Interfaces"
25 v_relfric = v;
26 a_relfric = a;
27 f0 = A "forza a velocita' 0 ma con scorrimento";
28 f0_max = A "massima forza velocita' 0 e senza scorrimento ";
29 free = false "sarebbe true quando la ruota si stacca dalla strada";
30// Ora il calcolo di f, e la sua attribuzione alla flangia:
31 flange.f - f = 0;
32// friction force
33 if v > 0 then
34 Sign = 1;
35 else
36 Sign = -1;
37 end if;
38 f - B * v ^ 2 * Sign = if locked then sa * unitForce else f0 * (if startForward then Modelica.Math.tempInterpol1(v, [0, 1], 2) else if startBackward then -Modelica.Math.tempInterpol1(-v, [0, 1], 2) else if pre(mode) == Forward then Modelica.Math.tempInterpol1(v, [0, 1], 2) else -Modelica.Math.tempInterpol1(-v, [0, 1], 2));
39 annotation(
40 Documentation(info = "<html>
41 <p>This component models the total (rolling and aerodynamic vehicle drag resistance: </p>
42 <p>F=fc*m*g+(1/2)*rho*Cx*S*v^2</p>
43 <p>It models reliably the stuck phase. Based on Modelica-Intrerfaces.PartialFriction model</p>
44 </html>"),
45 Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Polygon(points = {{-98, 10}, {22, 10}, {22, 41}, {92, 0}, {22, -41}, {22, -10}, {-98, -10}, {-98, 10}}, lineColor = {0, 127, 0}, fillColor = {215, 215, 215}, fillPattern = FillPattern.Solid), Line(points = {{-42, -50}, {87, -50}}, color = {0, 0, 0}), Polygon(points = {{-72, -50}, {-41, -40}, {-41, -60}, {-72, -50}}, lineColor = {0, 0, 0}, fillColor = {128, 128, 128}, fillPattern = FillPattern.Solid), Line(points = {{-90, -90}, {-70, -88}, {-50, -82}, {-30, -72}, {-10, -58}, {10, -40}, {30, -18}, {50, 8}, {70, 38}, {90, 72}, {110, 110}}, color = {0, 0, 255}, thickness = 0.5), Text(extent = {{-82, 90}, {80, 50}}, lineColor = {0, 0, 255}, textString = "%name")}),
46 Diagram(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics));
47 end DragForce;
48
49 model PropDriver "Simple Proportional controller driver"
50 parameter String CycleFileName = "MyCycleName.txt" "Drive Cycle Name ex: \"sort1.txt\"";
51 parameter Real k(unit = "N.m/(m/s)") "Controller gain";
52 parameter Real yMax(unit = "N.m") = 1000000.0 "Max output value (absolute)";
53 parameter Modelica.Blocks.Types.Extrapolation extrapolation = Modelica.Blocks.Types.Extrapolation.HoldLastPoint;
54 Modelica.Blocks.Interfaces.RealInput V annotation(
55 Placement(transformation(extent = {{-14, -14}, {14, 14}}, rotation = 90, origin = {0, -114}), iconTransformation(extent = {{-12, -12}, {12, 12}}, rotation = 90, origin = {0, -112})));
56 Modelica.Blocks.Interfaces.RealOutput tauRef(unit = "N.m") annotation(
57 Placement(transformation(extent = {{100, -10}, {120, 10}}), iconTransformation(extent = {{100, -10}, {120, 10}})));
58 Modelica.Blocks.Sources.CombiTimeTable driveCyc(columns = {2}, extrapolation = extrapolation, fileName = CycleFileName, tableName = "Cycle", tableOnFile = true) annotation(
59 Placement(transformation(extent = {{-86, -10}, {-66, 10}})));
60 // fileName=Modelica.Utilities.Files.loadResource("modelica://EVPkg1718eng/"+CycleFileName)) annotation (
61 Modelica.Blocks.Math.UnitConversions.From_kmh from_kmh annotation(
62 Placement(transformation(extent = {{-48, -10}, {-28, 10}})));
63 Modelica.Blocks.Math.Feedback feedback annotation(
64 Placement(transformation(extent = {{-10, -10}, {10, 10}})));
65 Modelica.Blocks.Math.Gain gain(k = k) annotation(
66 Placement(transformation(extent = {{32, -10}, {52, 10}})));
67 Modelica.Blocks.Nonlinear.Limiter limiter(uMax = yMax) annotation(
68 Placement(transformation(extent = {{70, -10}, {90, 10}})));
69 equation
70 connect(from_kmh.u, driveCyc.y[1]) annotation(
71 Line(points = {{-50, 0}, {-65, 0}}, color = {0, 0, 127}, smooth = Smooth.None));
72 connect(from_kmh.y, feedback.u1) annotation(
73 Line(points = {{-27, 0}, {-8, 0}}, color = {0, 0, 127}, smooth = Smooth.None));
74 connect(feedback.u2, V) annotation(
75 Line(points = {{0, -8}, {0, -114}, {1.77636e-015, -114}}, color = {0, 0, 127}, smooth = Smooth.None));
76 connect(feedback.y, gain.u) annotation(
77 Line(points = {{9, 0}, {30, 0}}, color = {0, 0, 127}, smooth = Smooth.None));
78 connect(gain.y, limiter.u) annotation(
79 Line(points = {{53, 0}, {68, 0}}, color = {0, 0, 127}, smooth = Smooth.None));
80 connect(tauRef, limiter.y) annotation(
81 Line(points = {{110, 0}, {91, 0}}, color = {0, 0, 127}, smooth = Smooth.None));
82 annotation(
83 Diagram(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics),
84 Documentation(info = "<html>
85 <p>Modello semplice di pilota.</p>
86 <p>Esso contiene al suo interno il ciclo di riferimento, che insegue attraverso un regolatore solo proporzionale.</p>
87 </html>"),
88 Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = false, initialScale = 0.1, grid = {2, 2}), graphics = {Rectangle(fillColor = {255, 255, 255}, fillPattern = FillPattern.Solid, extent = {{-100, 100}, {100, -100}}), Ellipse(fillColor = {255, 213, 170}, fillPattern = FillPattern.Solid, extent = {{-23, 26}, {-12, 0}}, endAngle = 360), Text(origin = {0, 1.81063}, lineColor = {0, 0, 255}, extent = {{-104, 142.189}, {98, 104}}, textString = "%name"), Polygon(fillColor = {215, 215, 215}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-22, -56}, {-42, -84}, {-16, -84}, {16, -84}, {-22, -56}}), Polygon(fillColor = {135, 135, 135}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-32, 44}, {-62, -48}, {-30, -48}, {-30, -48}, {-32, 44}}, smooth = Smooth.Bezier), Polygon(fillColor = {135, 135, 135}, pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-68, -32}, {-14, -86}, {10, -46}, {0, -46}, {-68, -32}}, smooth = Smooth.Bezier), Polygon(fillColor = {175, 175, 175}, fillPattern = FillPattern.Solid, points = {{-22, 14}, {-30, 10}, {-40, -44}, {2, -42}, {2, -30}, {0, 6}, {-22, 14}}, smooth = Smooth.Bezier), Ellipse(fillColor = {255, 213, 170}, fillPattern = FillPattern.Solid, extent = {{-30, 48}, {-3, 14}}, endAngle = 360), Polygon(pattern = LinePattern.None, fillPattern = FillPattern.Solid, points = {{-38, 38}, {-16, 54}, {-2, 40}, {4, 40}, {6, 40}, {-38, 38}}, smooth = Smooth.Bezier), Polygon(fillColor = {95, 95, 95}, fillPattern = FillPattern.Solid, points = {{30, -40}, {-32, -24}, {-36, -40}, {-24, -54}, {30, -40}}, smooth = Smooth.Bezier), Polygon(fillPattern = FillPattern.Solid, points = {{42, -66}, {36, -80}, {48, -74}, {52, -68}, {50, -64}, {42, -66}}, smooth = Smooth.Bezier), Line(points = {{48, -10}, {26, 4}, {26, 4}}, thickness = 0.5), Line(points = {{20, -6}, {34, 14}, {34, 14}}, thickness = 0.5), Polygon(fillColor = {255, 213, 170}, fillPattern = FillPattern.Solid, points = {{28, 8}, {32, 12}, {28, 6}, {34, 10}, {30, 6}, {34, 8}, {30, 4}, {26, 6}, {34, 4}, {26, 4}, {26, 6}, {28, 8}, {28, 8}, {26, 6}, {26, 6}, {26, 6}, {28, 12}, {28, 10}, {28, 8}}, smooth = Smooth.Bezier), Polygon(fillColor = {175, 175, 175}, fillPattern = FillPattern.Solid, points = {{-18, 4}, {28, 10}, {26, 2}, {-16, -12}, {-20, -12}, {-24, -2}, {-18, 4}}, smooth = Smooth.Bezier), Polygon(fillColor = {215, 215, 215}, fillPattern = FillPattern.Solid, points = {{72, -2}, {48, -2}, {36, -22}, {58, -82}, {72, -82}, {72, -2}}), Polygon(fillColor = {95, 95, 95}, fillPattern = FillPattern.Solid, points = {{49, -90}, {17, -36}, {7, -40}, {-1, -46}, {49, -90}}, smooth = Smooth.Bezier), Line(points = {{-7, 35}, {-3, 33}}), Line(points = {{-9, 22}, {-5, 22}}), Line(points = {{-7, 35}, {-3, 35}}), Text(extent = {{-82, 98}, {94, 58}}, lineColor = {238, 46, 47}, textString = "%CycleFileName")}));
89 end PropDriver;
90
91 package WithRecord
92 record Car
93 parameter Real m = 1300;
94 parameter Real ratio = 3.905;
95 parameter Real radius = 0.31;
96 parameter Real J = 1.5;
97 parameter Real Cx = 0.26;
98 parameter Real S = 2.2;
99 parameter Real fc = 0.014;
100 parameter Real rho = 1.226;
101 parameter Real kContr = 100;
102 annotation(
103 Diagram(coordinateSystem(extent = {{-100, -80}, {100, 80}})),
104 Icon(graphics = {Text(origin = {-3, 4}, lineColor = {170, 0, 0}, extent = {{-93, 22}, {93, -22}}, textString = "Car"), Rectangle(lineColor = {170, 0, 0}, extent = {{-100, 100}, {100, -100}}), Text(origin = {2, -48}, lineColor = {0, 0, 255}, extent = {{-48, 14}, {48, -14}}, textString = "%name")}));
105 end Car;
106
107 model EVbasicMB
108 Modelica.SIunits.Energy enP1, enDrag, enP1Pos, enP1Neg, enDC;
109 myEVpkg.PropDriver driver(CycleFileName = "AccBrake.txt", k = data.kContr) annotation(
110 Placement(visible = true, transformation(origin = {-120, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
111 Modelica.Mechanics.Rotational.Components.IdealRollingWheel wheel(radius = data.radius) annotation(
112 Placement(visible = true, transformation(origin = {2, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
113 Modelica.Mechanics.Rotational.Components.IdealGear gear(ratio = data.ratio) annotation(
114 Placement(visible = true, transformation(origin = {-26, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
115 Modelica.Mechanics.Rotational.Sensors.SpeedSensor motSpeed annotation(
116 Placement(visible = true, transformation(origin = {-42, -26}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
117 Modelica.Mechanics.Translational.Sensors.PowerSensor mP1 annotation(
118 Placement(visible = true, transformation(origin = {42, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
119 Modelica.Mechanics.Translational.Components.Mass mass(m = data.m) annotation(
120 Placement(visible = true, transformation(origin = {70, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
121 Modelica.Mechanics.Translational.Sensors.PowerSensor mPDrag annotation(
122 Placement(visible = true, transformation(origin = {106, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
123 Modelica.Mechanics.Translational.Sensors.SpeedSensor velSens annotation(
124 Placement(visible = true, transformation(origin = {88, -40}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
125 Modelica.Blocks.Nonlinear.Limiter to_mP1Neg(limitsAtInit = true, uMax = 0, uMin = -1e99) annotation(
126 Placement(visible = true, transformation(origin = {12, -32}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
127 Modelica.Blocks.Nonlinear.Limiter to_mP1Pos(limitsAtInit = true, uMax = 1e99, uMin = 0) annotation(
128 Placement(visible = true, transformation(origin = {56, -32}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
129 myEVpkg.DragForce dragForce(Cx = data.Cx, S = data.S, fc = data.fc, m = mass.m, rho(displayUnit = "kg/m3") = data.rho) annotation(
130 Placement(visible = true, transformation(origin = {132, 0}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
131 wbEHPTlib.MapBased.OneFlange powertrain(J = data.J, effTable = [0, 0, 1; 0, 0.8, 0.8; 1, 0.8, 0.8], effTableName = "effTable", mapsFileName = "EVmaps.txt", mapsOnFile = false, powMax = 50e3, tauMax = 200, uDcNom = 100, wMax = 1000) annotation(
132 Placement(visible = true, transformation(origin = {-70, 0}, extent = {{-10, -8}, {10, 10}}, rotation = 0)));
133 Modelica.Electrical.Analog.Basic.Ground ground annotation(
134 Placement(visible = true, transformation(origin = {-140, 6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
135 Modelica.Electrical.Analog.Sensors.PowerSensor pSensor annotation(
136 Placement(visible = true, transformation(origin = {-104, 46}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
137 Modelica.Electrical.Analog.Sources.ConstantVoltage batt(V = 500) annotation(
138 Placement(visible = true, transformation(origin = {-140, 36}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
139 myEVpkg.WithRecord.Car data annotation(
140 Placement(visible = true, transformation(origin = {90, 50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
141 equation
142 connect(pSensor.pv, pSensor.pc) annotation(
143 Line(points = {{-104, 56}, {-114, 56}, {-114, 46}, {-114, 46}}, color = {0, 0, 255}));
144 connect(pSensor.nv, batt.n) annotation(
145 Line(points = {{-104, 36}, {-104, 36}, {-104, 26}, {-140, 26}, {-140, 26}}, color = {0, 0, 255}));
146 connect(powertrain.pin_n, batt.n) annotation(
147 Line(points = {{-80, -4}, {-96, -4}, {-96, 26}, {-140, 26}, {-140, 26}}, color = {0, 0, 255}));
148 connect(pSensor.nc, powertrain.pin_p) annotation(
149 Line(points = {{-94, 46}, {-86, 46}, {-86, 4}, {-80, 4}, {-80, 4}}, color = {0, 0, 255}));
150 connect(batt.p, pSensor.pc) annotation(
151 Line(points = {{-140, 46}, {-114, 46}}, color = {0, 0, 255}));
152 connect(batt.n, ground.p) annotation(
153 Line(points = {{-140, 26}, {-140, 26}, {-140, 16}, {-140, 16}}, color = {0, 0, 255}));
154 connect(powertrain.tauRef, driver.tauRef) annotation(
155 Line(points = {{-81.4, 0}, {-110, 0}, {-110, 0}, {-109, 0}}, color = {0, 0, 127}));
156 connect(powertrain.flange_a, gear.flange_a) annotation(
157 Line(points = {{-60, 0}, {-36, 0}, {-36, 0}, {-36, 0}}));
158 connect(motSpeed.flange, gear.flange_a) annotation(
159 Line(points = {{-42, -16}, {-42, 4.47036e-07}, {-36, 4.47036e-07}}));
160 connect(mPDrag.flange_b, dragForce.flange) annotation(
161 Line(points = {{116, 0}, {122, 0}}, color = {0, 127, 0}));
162 connect(mass.flange_b, mPDrag.flange_a) annotation(
163 Line(points = {{80, 0}, {96, 0}}, color = {0, 127, 0}));
164 connect(velSens.v, driver.V) annotation(
165 Line(points = {{88, -51}, {-120, -51}, {-120, -11.2}}, color = {0, 0, 127}));
166 connect(velSens.flange, mass.flange_b) annotation(
167 Line(points = {{88, -30}, {88, 0}, {80, 0}}, color = {0, 127, 0}));
168 connect(mP1.flange_b, mass.flange_a) annotation(
169 Line(points = {{52, 0}, {60, 0}}, color = {0, 127, 0}));
170 connect(gear.flange_b, wheel.flangeR) annotation(
171 Line(points = {{-16, 0}, {-8, 0}}));
172 connect(mP1.power, to_mP1Neg.u) annotation(
173 Line(points = {{34, -11}, {34, -32}, {24, -32}}, color = {0, 0, 127}));
174 connect(to_mP1Pos.u, mP1.power) annotation(
175 Line(points = {{44, -32}, {34, -32}, {34, -11}, {34, -11}}, color = {0, 0, 127}));
176 connect(wheel.flangeT, mP1.flange_a) annotation(
177 Line(points = {{12, 0}, {32, 0}, {32, 0}, {32, 0}}, color = {0, 127, 0}));
178 der(enDrag) = mPDrag.power;
179 der(enP1) = mP1.power;
180 der(enP1Pos) = to_mP1Pos.y;
181 der(enP1Neg) = -to_mP1Neg.y;
182 der(enDC) = pSensor.power;
183 annotation(
184 Diagram(coordinateSystem(extent = {{-150, -60}, {150, 60}}), graphics = {Text(origin = {-14, 52}, extent = {{-30, 2}, {66, -6}}, textString = "Sort1: 150s NEDC: 1184s WLTC3: 1800s")}),
185 Icon(coordinateSystem(extent = {{-150, -60}, {150, 60}})),
186 __OpenModelica_commandLineOptions = "",
187 experiment(StartTime = 0, StopTime = 80, Tolerance = 1e-06, Interval = 0.04));
188 end EVbasicMB;
189
190 record Bus
191 parameter Real m = 160000;
192 parameter Real ratio = 6;
193 parameter Real radius = 0.5715;
194 parameter Real J = 5;
195 parameter Real Cx = 0.65;
196 parameter Real S = 6;
197 parameter Real fc = 0.013;
198 parameter Real rho = 1.226;
199 parameter Real kContr = 1000;
200 annotation(
201 Diagram(coordinateSystem(extent = {{-100, -80}, {100, 80}})),
202 Icon(graphics = {Text(origin = {-3, 4}, lineColor = {170, 0, 0}, extent = {{-93, 22}, {93, -22}}, textString = "Bus"), Rectangle(lineColor = {170, 0, 0}, extent = {{-100, 100}, {100, -100}}), Text(origin = {2, -48}, lineColor = {0, 0, 255}, extent = {{-48, 14}, {48, -14}}, textString = "%name")}, coordinateSystem(initialScale = 0.1)));
203 end Bus;
204 annotation(
205 Diagram(coordinateSystem(extent = {{-100, -80}, {100, 80}})));
206 end WithRecord;
207 annotation(
208 Diagram(coordinateSystem(extent = {{-100, -80}, {100, 80}})),
209 uses(Modelica(version = "3.2.2")));
210end myEVpkg;