SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSDevice_Battery.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // The Battery parameters for the vehicle
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2013-2015 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
34 #include <utils/common/SUMOTime.h>
35 #include <microsim/MSNet.h>
36 #include <microsim/MSLane.h>
37 #include <microsim/MSEdge.h>
38 #include <microsim/MSVehicle.h>
39 #include "MSDevice_Tripinfo.h"
40 #include "MSDevice_Battery.h"
41 
42 #define PI 3.141592654
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 // ---------------------------------------------------------------------------
53 // static initialisation methods
54 // ---------------------------------------------------------------------------
55 void
57  insertDefaultAssignmentOptions("battery", "Battery", oc);
58 }
59 
60 
61 void
62 MSDevice_Battery::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
64  return;
65  }
66 
67  // Declare default parameters
68  SUMOReal new_ActBatKap = 0;
69  SUMOReal new_MaxBatKap = 0;
70  SUMOReal new_PowerMax = 100;
71  SUMOReal new_Mass = 1000;
72  SUMOReal new_FrontSurfaceArea = 2;
73  SUMOReal new_AirDragCoefficient = 0.4;
74  SUMOReal new_InternalMomentOfInertia = 10;
75  SUMOReal new_RadialDragCoefficient = 1;
76  SUMOReal new_RollDragCoefficient = 0.5;
77  SUMOReal new_ConstantPowerIntake = 10;
78  SUMOReal new_PropulsionEfficiency = 0.5;
79  SUMOReal new_RecuperationEfficiency = 0;
80  SUMOReal new_LastAngle = 0;
81  SUMOReal new_LastEnergy = 0;
82 
83  // MaxBatKap
84  new_MaxBatKap = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("MaxBatKap", "0").c_str());
85 
86  // ActBatKap
87  if (v.getParameter().getParameter("ActBatKap", "-") == "-") {
88  new_ActBatKap = new_MaxBatKap / 2.0;
89  } else {
90  new_ActBatKap = TplConvert::_2SUMOReal(v/*.getVehicleType()*/.getParameter().getParameter("ActBatKap", "0").c_str());
91  }
92 
93  // Power
94  new_PowerMax = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("PowerMax", "100").c_str());
95 
96  // Mass
97  new_Mass = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("Mass", "1000").c_str());
98 
99  // FrontSurfaceArea
100  new_FrontSurfaceArea = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("FrontSurfaceArea", "2").c_str());
101 
102  // AirDragCoefficient
103  new_AirDragCoefficient = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("AirDragCoefficient", "0.4").c_str());
104 
105  // InternalMomentOfInertia
106  new_InternalMomentOfInertia = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("InternalMomentOfInertia", "10").c_str());
107 
108  // Radial Drag Coefficient
109  new_RadialDragCoefficient = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("RadialDragCoefficient", "1").c_str());
110 
111  // RollDragCoefficient
112  new_RollDragCoefficient = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("RollDragCoefficient", "0.5").c_str());
113 
114  // ConstantPowerIntake
115  new_ConstantPowerIntake = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("ConstantPowerIntake", "10").c_str());
116 
117  // PropulsionEfficiency
118  new_PropulsionEfficiency = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("PropulsionEfficiency", "0.5").c_str());
119 
120  // RecuperationEfficiency
121  new_RecuperationEfficiency = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("RecuperationEfficiency", "0").c_str());
122 
123  // constructor
124  MSDevice_Battery* device = new MSDevice_Battery(v, "battery_" + v.getID(),
125  new_ActBatKap, new_MaxBatKap, new_PowerMax, new_Mass, new_FrontSurfaceArea, new_AirDragCoefficient,
126  new_InternalMomentOfInertia, new_RadialDragCoefficient, new_RollDragCoefficient,
127  new_ConstantPowerIntake, new_PropulsionEfficiency, new_RecuperationEfficiency,
128  new_LastAngle, new_LastEnergy);
129 
130  into.push_back(device);
131 }
132 
133 
134 bool MSDevice_Battery::notifyMove(SUMOVehicle& veh, SUMOReal /* oldPos */, SUMOReal /* newPos */, SUMOReal /* newSpeed */) {
135  // Start vehicleStoppedTimer if the vehicle is stopped (that's mean, speed is < 0.2). In other case reset timer
136  if (veh.getSpeed() < 0.2) {
137  // Increase vehicle stopped timer
139  } else {
140  // Reset vehicle Stopped
142  }
143 
144  // Update Energy from the battery
145  if (getMaxBatKap() != 0) {
146  Consum = getPropEnergy(veh);
147 
148  // Energy lost/gained from vehicle movement (via vehicle energy model) [kWh]
150 
151  // saturate between 0 and MaxBatKap [kWh]
152  if (getActBatKap() < 0) {
153  setActBatKap(0);
154 
155  if (getMaxBatKap() > 0) {
156  WRITE_WARNING("Battery from vehicle with ID = '" + veh.getID() + "' is depleted.");
157  }
158 
159  } else if (getActBatKap() > getMaxBatKap()) {
161  }
162 
163  setLastAngle(veh.getAngle());
164  }
165 
166  // Check if vehicle has under their position one charge Station
167  std::string ChargingStationID = MSNet::getInstance()->getChrgStnID(veh.getLane(), veh.getPositionOnLane());
168 
169  // If vehicle is over a charging station
170  if (ChargingStationID != "") {
171  // Declare a pointer to the charging station
172  MSChrgStn* ChargingStationPointer = MSNet::getInstance()->getChrgStn(ChargingStationID);
173 
174  // if the vehicle is almost stopped, or charge in transit is enabled, then charge vehicle
175  if ((veh.getSpeed() < 0.2) || (ChargingStationPointer->getChargeInTransit() == 1)) {
176  // Set Flags Stopped/intransit to
177  if (veh.getSpeed() < 0.2) {
178  // vehicle ist almost stopped, then is charging stopped
179  ItsChargingStopped = true;
180 
181  // therefore isn't charging in transit
182  ItsChargingInTransit = false;
183  } else {
184  // vehicle is moving, and the Charging station allow charge in transit
185  ItsChargingStopped = false;
186 
187  // Therefore charge in transit
188  ItsChargingInTransit = true;
189  }
190 
191  // Set actChrgStn parameter
192  actChrgStn = ChargingStationID;
193 
194  // Only update charging start time if vehicle allow charge in transit, or in other case
195  // if the vehicle not allow charge in transit but it's stopped.
196  if (ChargingStationPointer->getChargeInTransit() == 1 || veh.getSpeed() < 0.2) {
197  // Update Charging start time
199  }
200 
201  // time it takes the vehicle at the station < charging station time delay?
202  if (getChargingStartTime() > ChargingStationPointer->getChargeDelay()) {
203  // Calulate energy charged (Fix);
204  energyCharged = ChargingStationPointer->getChrgPower() * ChargingStationPointer->getEfficency();
205 
206  // Convert from [kWs] to [kWh] (3600s / 1h):
207  energyCharged /= 3600;
208 
209  // Update Battery charge
210  if ((energyCharged + getActBatKap()) > getMaxBatKap()) {
212  } else {
214  }
215  }
216  }
217  }
218  // In other case, vehicle will be not charged
219  else {
220  // Disable flags
221  ItsChargingInTransit = false;
222  ItsChargingStopped = false;
223 
224  // Disable charging station
225  actChrgStn = "NULL";
226 
227  // Set energy charged to 0
228  energyCharged = 0.00;
229 
230  // Reset timer
232  }
233 
234  // Always return true.
235  return true;
236 }
237 
238 
240  // Set last Energy ONLY when the vehicle is introduced in the simulation (That's mean, that the reason is 0)
241  if (reason == 0) {
242  setLastEnergy(getMass() * veh.getSpeed() * veh.getSpeed() / 2 + getMass() * 9.81 * veh.getLane()->getShape().front().z() + getInternalMomentOfInertia() * 0.5 * veh.getSpeed() * veh.getSpeed());
243  setLastAngle(veh.getLane()->getShape().beginEndAngle() * 180 / PI);
244  }
245 
246  // This function return always true
247  return true;
248 }
249 
250 
252  //Function implemented in MSBatteryExport
253  /*if (OptionsCont::getOptions().isSet("tripinfo-output"))
254  {
255  OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
256 
257  os.openTag("Battery");
258  os.writeAttr("Act Bat Kap", toString(ActBatKap));
259  os.writeAttr("Max Bat Kap", toString(MaxBatKap));
260  os.writeAttr("Power Max", toString(PowerMax));
261  os.writeAttr("Mass", toString(Mass));
262  os.writeAttr("Front Surface Area", toString(FrontSurfaceArea));
263  os.writeAttr("Air Drag Coefficient", toString(AirDragCoefficient));
264  os.writeAttr("Radial Drag Coefficient", toString(RadialDragCoefficient));
265  os.writeAttr("RollDrag Coefficient", toString(RollDragCoefficient));
266  os.writeAttr("Constant Power Intake", toString(ConstantPowerIntake));
267  os.writeAttr("Propulsion Efficiency", toString(PropulsionEfficiency));
268  os.writeAttr("Recuperation Efficiency", toString(RecuperationEfficiency));
269  os.writeAttr("Last Angle", toString(LastAngle));
270  os.writeAttr("Last Energy", toString(LastEnergy));
271  os.closeTag();
272  }*/
273 }
274 
275 
276 // ---------------------------------------------------------------------------
277 // MSDevice_Battery-methods
278 // ---------------------------------------------------------------------------
279 MSDevice_Battery::MSDevice_Battery(SUMOVehicle& holder, const std::string& id, const SUMOReal new_ActBatKap, const SUMOReal new_MaxBatKap, const SUMOReal new_PowerMax, const SUMOReal new_Mass, const SUMOReal new_FrontSurfaceArea, const SUMOReal new_AirDragCoefficient, const SUMOReal new_InternalMomentOfInertia, const SUMOReal new_RadialDragCoefficient, const SUMOReal new_RollDragCoefficient, const SUMOReal new_ConstantPowerIntake, const SUMOReal new_PropulsionEfficiency, const SUMOReal new_RecuperationEfficiency, const SUMOReal new_LastAngle, const SUMOReal new_LastEnergy)
280  :
281  MSDevice(holder, id),
282  ActBatKap(new_ActBatKap), // [ActBatKap <= MaxBatKap]
283  MaxBatKap(new_MaxBatKap), // [MaxBatKap >= 0]
284  PowerMax(new_PowerMax), // [PowerMax >= 0]
285  Mass(new_Mass), // [Mass >= 0]
286  FrontSurfaceArea(new_FrontSurfaceArea), // [FrontSurfaceArea >= 0]
287  AirDragCoefficient(new_AirDragCoefficient), // [AirDragCoefficient >=0]
288  InternalMomentOfInertia(new_InternalMomentOfInertia), // [InternalMomentOfInertia >= 0]
289  RadialDragCoefficient(new_RadialDragCoefficient), // [RadialDragCoefficient >=0]
290  RollDragCoefficient(new_RollDragCoefficient), // [RollDragCoefficient >= 0]
291  ConstantPowerIntake(new_ConstantPowerIntake), // [ConstantPowerIntake >= 0]
292  PropulsionEfficiency(new_PropulsionEfficiency), // [1 >= PropulsionEfficiency >= 0]
293  RecuperationEfficiency(new_RecuperationEfficiency), // [1 >= RecuperationEfficiency >= 0]
294  LastAngle(new_LastAngle), // Limit not needed
295  LastEnergy(new_LastEnergy) { // Limit not needed
296  // Initially the Vehicle is not charging and is not in a Chargin Station
297  ItsChargingStopped = false;
298  ItsChargingInTransit = false;
299 
300  // Initially the energy charged is null
301  energyCharged = 0;
302 
303  // Initially the Vehicle stopped and the consum is cero.
304  Consum = 0;
305 
306  // Initially the vehicle is stopped and the corresponding variable is 0
307  vehicleStopped = 0;
308 
309  // Initially the Vehicle are not over a Charging Station
310  actChrgStn = "NULL";
311 
312  if (ActBatKap > MaxBatKap) {
313  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has a actual battery capacity (" + SUMOReal_str(ActBatKap) + ") greater than it's max battery capacity(" + SUMOReal_str(MaxBatKap) + ").");
314  }
315 
316  if (MaxBatKap < 0) {
317  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid battery capacity (" + SUMOReal_str(MaxBatKap) + ").");
318  }
319 
320  if (PowerMax < 0) {
321  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid power max (" + SUMOReal_str(PowerMax) + ").");
322  }
323 
324  if (Mass < 0) {
325  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid mass (" + SUMOReal_str(Mass) + ").");
326  }
327 
328  if (FrontSurfaceArea < 0) {
329  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid front surface Area (" + SUMOReal_str(FrontSurfaceArea) + ").");
330  }
331 
332  if (AirDragCoefficient < 0) {
333  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid drag coefficient (" + SUMOReal_str(AirDragCoefficient) + ").");
334  }
335 
336  if (InternalMomentOfInertia < 0) {
337  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid internal moment of inertia (" + SUMOReal_str(InternalMomentOfInertia) + ").");
338  }
339 
340  if (RadialDragCoefficient < 0) {
341  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid radial friction coefficient (" + SUMOReal_str(RadialDragCoefficient) + ").");
342  }
343 
344  if (RollDragCoefficient < 0) {
345  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid roll friction coefficient (" + SUMOReal_str(RollDragCoefficient) + ").");
346  }
347 
348  if (ConstantPowerIntake < 0) {
349  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid constant power intake (" + SUMOReal_str(ConstantPowerIntake) + ").");
350  }
351 
352  if (PropulsionEfficiency < 0 || PropulsionEfficiency > 1) {
353  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid propulsion efficiency (" + SUMOReal_str(PropulsionEfficiency) + ").");
354  }
355 
356  if (RecuperationEfficiency < 0 || RecuperationEfficiency > 1) {
357  WRITE_WARNING("Battery builder: Vehicle with id = " + getID() + " has not a valid Recuparation efficiency (" + SUMOReal_str(RecuperationEfficiency) + ").");
358  }
359 }
360 
361 
363 {}
364 
365 
366 // SET FUNCTIONS
367 
368 void MSDevice_Battery::setActBatKap(const SUMOReal new_ActBatKap) {
369  ActBatKap = new_ActBatKap;
370 
371  if (ActBatKap > MaxBatKap) {
372  WRITE_WARNING("Function setActBatKap: Actual battery capacity (" + SUMOReal_str(ActBatKap) + ") from Vehicle with id = " + getID() + " is greater than it's max battery capacity(" + SUMOReal_str(MaxBatKap) + ").");
373  }
374 }
375 
376 
377 void MSDevice_Battery::setMaxBatKap(const SUMOReal new_MaxBatKap) {
378  MaxBatKap = new_MaxBatKap;
379 
380  if (MaxBatKap < 0) {
381  WRITE_WARNING("Function setMaxBatKap: Vehicle with id = " + getID() + " has not a valid battery capacity (" + SUMOReal_str(MaxBatKap) + ").");
382  }
383 }
384 
385 
386 void MSDevice_Battery::setMass(const SUMOReal new_Mass) {
387  Mass = new_Mass;
388 
389  if (Mass < 0) {
390  WRITE_WARNING("Function setMass: Vehicle with id = " + getID() + " has not a valid mass (" + SUMOReal_str(Mass) + ").");
391  }
392 }
393 
394 
395 void MSDevice_Battery::setPowerMax(const SUMOReal new_PowerMax) {
396  PowerMax = new_PowerMax;
397 
398  if (PowerMax < 0) {
399  WRITE_WARNING("Function setPowerMax: Vehicle with id = " + getID() + " has not a valid power max (" + SUMOReal_str(PowerMax) + ").");
400  }
401 }
402 
403 void MSDevice_Battery::setFrontSurfaceArea(const SUMOReal new_FrontSurfaceArea) {
404  FrontSurfaceArea = new_FrontSurfaceArea;
405 
406  if (FrontSurfaceArea < 0) {
407  WRITE_WARNING("Function setFrontSurfaceArea: Vehicle with id = " + getID() + " has not a valid front surface Area (" + SUMOReal_str(FrontSurfaceArea) + ").");
408  }
409 }
410 
411 
412 void MSDevice_Battery::setAirDragCoefficient(const SUMOReal new_AirDragCoefficient) {
413  AirDragCoefficient = new_AirDragCoefficient;
414 
415  if (AirDragCoefficient < 0) {
416  WRITE_WARNING("Function setAirDragCoefficient: Vehicle with id = " + getID() + " has not a valid drag coefficient (" + SUMOReal_str(AirDragCoefficient) + ").");
417  }
418 }
419 
420 
421 void MSDevice_Battery::setInternalMomentOfInertia(const SUMOReal new_InternalMomentOfInertia) {
422  InternalMomentOfInertia = new_InternalMomentOfInertia;
423 
424  if (InternalMomentOfInertia < 0) {
425  WRITE_WARNING("Function setInternalMomentOfInertia: Vehicle with id = " + getID() + " has not a valid internal moment of inertia (" + SUMOReal_str(InternalMomentOfInertia) + ").");
426  }
427 }
428 
429 
430 void MSDevice_Battery::setRadialDragCoefficient(const SUMOReal new_RadialDragCoefficient) {
431  RadialDragCoefficient = new_RadialDragCoefficient;
432 
433  if (RadialDragCoefficient < 0) {
434  WRITE_WARNING("Function setRadialDragCoefficient: Vehicle with id = " + getID() + " has not a valid radial friction coefficient (" + SUMOReal_str(RadialDragCoefficient) + ").");
435  }
436 }
437 
438 
439 void MSDevice_Battery::setRollDragCoefficient(const SUMOReal new_RollDragCoefficient) {
440  RollDragCoefficient = new_RollDragCoefficient;
441 
442  if (RollDragCoefficient < 0) {
443  WRITE_WARNING("Function setRollDragCoefficient: Vehicle with id = " + getID() + " has not a valid roll friction coefficient (" + SUMOReal_str(RollDragCoefficient) + ").");
444  }
445 }
446 
447 
448 void MSDevice_Battery::setConstantPowerIntake(const SUMOReal new_ConstantPowerIntake) {
449  ConstantPowerIntake = new_ConstantPowerIntake;
450 
451  if (ConstantPowerIntake < 0) {
452  WRITE_WARNING("Function setConstantPowerIntake: Vehicle with id = " + getID() + " has not a valid constant power intake (" + SUMOReal_str(ConstantPowerIntake) + ").");
453  }
454 }
455 
456 
457 void MSDevice_Battery::setPropulsionEfficiency(const SUMOReal new_PropulsionEfficiency) {
458  PropulsionEfficiency = new_PropulsionEfficiency;
459 
460  if (PropulsionEfficiency < 0 || PropulsionEfficiency > 1) {
461  WRITE_WARNING("Function setPropulsionEfficiency: Vehicle with id = " + getID() + " has not a valid propulsion efficiency (" + SUMOReal_str(PropulsionEfficiency) + ").");
462  }
463 }
464 
465 
466 void MSDevice_Battery::setRecuperationEfficiency(const SUMOReal new_RecuperationEfficiency) {
467  RecuperationEfficiency = new_RecuperationEfficiency;
468 
469  if (RecuperationEfficiency < 0 || RecuperationEfficiency > 1) {
470  WRITE_WARNING("Function setRecuperationEfficiency: Vehicle with id = " + getID() + " has not a valid recuparation efficiency (" + SUMOReal_str(RecuperationEfficiency) + ").");
471  }
472 }
473 
474 
475 void MSDevice_Battery::setLastAngle(const SUMOReal new_LastAngle) {
476  LastAngle = new_LastAngle;
477 }
478 
479 
480 void MSDevice_Battery::setLastEnergy(const SUMOReal new_LastEnergy) {
481  LastEnergy = new_LastEnergy ;
482 }
483 
485  ChargingStartTime = 0;
486 }
487 
490 }
491 
493  vehicleStopped = 0;
494 }
495 
497  vehicleStopped++;
498 }
499 
500 //GET FUNCTIONS
501 
503  return ActBatKap;
504 }
505 
507  return MaxBatKap;
508 }
509 
511  return PowerMax;
512 }
513 
515  return Mass;
516 }
517 
519  return FrontSurfaceArea;
520 }
521 
523  return AirDragCoefficient;
524 }
525 
528 }
529 
531  return RadialDragCoefficient;
532 }
533 
535  return RollDragCoefficient;
536 }
537 
539  return ConstantPowerIntake;
540 }
541 
543  return PropulsionEfficiency;
544 }
545 
547  return RecuperationEfficiency;
548 }
549 
551  return LastAngle;
552 }
553 
555  return LastEnergy;
556 }
557 
559  return Consum;
560 }
561 
563  return ItsChargingStopped;
564 }
565 
567  return ItsChargingInTransit;
568 }
569 
571  return ChargingStartTime;
572 }
573 
574 const std::string& MSDevice_Battery::getChrgStnID() const {
575  return actChrgStn;
576 }
577 
579  return energyCharged;
580 }
581 
582 
584  return vehicleStopped;
585 }
586 
587 
589  // calculate current kinetic energy
590  SUMOReal height_cur = veh.getPositionOnLane() / veh.getLane()->getLength() * (veh.getLane()->getShape().back().z() - veh.getLane()->getShape().front().z());
591 
592  // kinetic energy of vehicle with current velocity
593  SUMOReal currentEnergy = 0.5 * getMass() * veh.getSpeed() * veh.getSpeed();
594 
595  // add current potential energy of vehicle at current position
596  currentEnergy += getMass() * 9.81 * height_cur;
597 
598  // Calculate the radius of the vehicle's current path if is distintc (r = ds / dphi)
599  SUMOReal radius = 0;
600 
601  if (getLastAngle() != veh.getAngle())
602  radius = veh.getSpeed() * 180 / (PI * (
603  (fabs(getLastAngle() - veh.getAngle()) < fabs(veh.getAngle() - getLastAngle())) ?
604  fabs(getLastAngle() - veh.getAngle()) :
605  fabs(veh.getAngle() - getLastAngle())));
606 
607  // add current rotational energy of internal rotating elements
608  currentEnergy += getInternalMomentOfInertia() * veh.getSpeed() * veh.getSpeed();
609 
610  // kinetic + potential + rotational energy gain [Ws] (MODIFICATED LAST ANGLE)
611  SUMOReal EnergyLoss = (currentEnergy - getLastEnergy());
612 
613  // save current total energy for next time step
614  setLastEnergy(currentEnergy);
615 
616  // Calculate energy losses:
617  // EnergyLoss,Air = 1/2 * rho_air [kg/m^3] * FrontSurfaceArea [m^2] * AirDragCoefficient [-] * v_Veh^2 [m/s] * s [m]
618  // ... with rho_air [kg/m^3] = 1,2041 kg/m^3 (at T = 20°C)
619  // ... with s [m] = v_Veh [m/s] * 1 [s]
620  EnergyLoss += 0.5 * 1.2041 * getFrontSurfaceArea() * getAirDragCoefficient() * fabs(veh.getSpeed() * veh.getSpeed() * veh.getSpeed());
621 
622  // Energy loss through Air resistance [Ws]
623  // EnergyLoss,Tire = c_R [-] * F_N [N] * s [m]
624  // ... with c_R = ~0.012 (car tire on asphalt)
625  // ... with F_N [N] = Mass [kg] * g [m/s^2]
626  EnergyLoss += getRollDragCoefficient() * 9.81 * getMass() * fabs(veh.getSpeed());
627 
628  // Energy loss through Roll resistance [Ws]
629  // ... (fabs(veh.getSpeed())>=0.01) = 0, if vehicle isn't moving
630  // EnergyLoss,internalFrictionRadialForce = c [m] * F_rad [N];
631  if (getLastAngle() != veh.getAngle()) {
632  // Energy loss through friction by radial force [Ws]
633  EnergyLoss += getRadialDragCoefficient() * getMass() * veh.getSpeed() * veh.getSpeed() / radius;
634  }
635 
636  // EnergyLoss,constantConsumers
637  // Energy loss through constant loads (e.g. A/C) [Ws]
638  EnergyLoss += getConstantPowerIntake();
639 
640  //E_Bat = E_kin_pot + EnergyLoss;
641  if (EnergyLoss > 0) {
642  // Assumption: Efficiency of PropulsionEfficiency when accelerating
643  EnergyLoss = EnergyLoss / getPropulsionEfficiency();
644  } else {
645  // Assumption: Efficiency of RecuperationEfficiency when recuperating
646  EnergyLoss = EnergyLoss * getRecuperationEfficiency();
647  }
648 
649  // convert from [Ws] to [kWh] (3600s / 1h):
650  EnergyLoss = EnergyLoss / 3600 ; // EnergyLoss[Ws] * 1[h]/3600[s] * 1[k]/1000
651 
652 
653  // original EnergyLoss = EnergyLoss / 3600 / 1000 ; // EnergyLoss[Ws] * 1[h]/3600[s] * 1[k]/1000
654 
655  //BATTERYS CAPACITY CHANGE !!
656 
657  return(EnergyLoss);
658 }
659 
660 
661 // Private methods
662 
663 std::string MSDevice_Battery::SUMOReal_str(const SUMOReal& var) {
664  std::ostringstream convert;
665  convert << var;
666  return convert.str();
667 }
bool isChargingStopped() const
Get parameter 15, true if Vehicle it&#39;s charging, false if not.
SUMOReal getPropEnergy(SUMOVehicle &veh)
get propulsion energy
void setFrontSurfaceArea(const SUMOReal new_FrontSurfaceArea)
Set parameter 05, vehicle&#39;s front surface Area.
SUMOReal getFrontSurfaceArea() const
Get parameter 05, vehicle&#39;s front surface Area.
SUMOReal getConsum() const
Get parameter 18, consum (Strange error with linker)
void setPowerMax(const SUMOReal new_Pmax)
Set parameter 03, The maximum power when accelerating.
SUMOReal ActBatKap
Parameter 01, The actual vehicles&#39; Battery Capacity in kWh [ActBatKap &lt;= MaxBatKap].
SUMOReal getEfficency() const
Get parameter 02, efficiency of the charging station.
Definition: MSChrgStn.cpp:85
SUMOReal getChargeDelay() const
Get parameter 03, get Charge Delay.
Definition: MSChrgStn.cpp:95
void increaseVehicleStoppedTimer()
Set parameter 21a, increase vehicleStopped.
static SUMOReal _2SUMOReal(const E *const data)
Definition: TplConvert.h:242
SUMOReal ChargingStartTime
Parameter 17, Moment, wich the vehicle has beging to charging none.
SUMOReal getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:376
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
virtual SUMOReal getAngle() const =0
Get the vehicle&#39;s angle.
Notification
Definition of a vehicle state.
SUMOReal getActBatKap() const
Get parameter 01, the actual vehicles&#39; Battery Capacity in kWh.
SUMOReal energyCharged
Parameter 20, Energy charged in each timestep.
std::string getChrgStnID(const MSLane *lane, const SUMOReal pos) const
Returns the charging station close to the given position.
Definition: MSNet.cpp:829
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:162
SUMOReal getChrgPower() const
Get parameter 01, charging station&#39;s charging power.
Definition: MSChrgStn.cpp:80
void setConstantPowerIntake(const SUMOReal new_ConstantPowerIntake)
Set parameter 10, vehicles&#39; constant power intake.
SUMOReal getRadialDragCoefficient() const
Get parameter 08, vehicles&#39; radial friction coefficient.
int getVehicleStopped() const
Get parameter 20, charging energy.
SUMOReal getMaxBatKap() const
Get parameter 02, the total vehicles&#39; Battery Capacity in kWh.
MSChrgStn * getChrgStn(const std::string &id) const
Returns the named charging station.
Definition: MSNet.cpp:823
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks for waiting steps when the vehicle moves // IMPLEMENTADA!!
SUMOReal getRollDragCoefficient() const
Get parameter 09, vehicles&#39; roll friction coefficient.
SUMOReal MaxBatKap
Parameter 02, The total vehicles&#39; Battery Capacity in kWh [MaxBatKap &gt;= 0].
SUMOReal getAirDragCoefficient() const
Get parameter 06, vehicle&#39;s drag coefficient.
SUMOReal beginEndAngle() const
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
const std::string & getID() const
Returns the id.
Definition: Named.h:60
SUMOReal getConstantPowerIntake() const
Get parameter 10, vehicles&#39; constant power intake.
void resetVehicleStoppedTimer()
Set parameter 21a, reset vehicleStopped.
int vehicleStopped
Parameter 21, How many timestep the vehicle is stopped.
std::string SUMOReal_str(const SUMOReal &var)
convert from SUMOReal to String
const SUMOVTypeParameter & getParameter() const
Representation of a vehicle.
Definition: SUMOVehicle.h:65
SUMOReal getChargeInTransit() const
Get parameter 03, get chargeInTransit.
Definition: MSChrgStn.cpp:90
SUMOReal PowerMax
Parameter 03, The Maximum Power when accelerating [PowerMax &gt;= 0].
SUMOReal getLastAngle() const
Get parameter 13, vehicles&#39; last angle.
SUMOReal RollDragCoefficient
Parameter 09, Vehicles&#39; roll friction coefficient [RollDragCoefficient &gt;= 0].
bool ItsChargingStopped
Parameter 15, Flag: Vehicles it&#39;s charging stopped by default is false.
void resetChargingStartTime()
Set parameter 17a, reset charging start time.
void setMass(const SUMOReal new_Mass)
Set parameter 04, vehicle&#39;s Mass.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:88
SUMOReal LastEnergy
Parameter 14, Vehicles&#39; last energy none.
SUMOReal getPropulsionEfficiency() const
Get parameter 11, vehicles&#39; Propulsion efficiency.
bool isChargingInTransit() const
Get parameter 16, true if Vehicle it&#39;s charging, false if not.
SUMOReal LastAngle
Parameter 13, Vehicles&#39; last angle none.
SUMOReal getChrgEnergy() const
Get parameter 20, charging energy.
SUMOReal getChargingStartTime() const
Get parameter 17, charging start time.
SUMOReal PropulsionEfficiency
Parameter 11, Vehicles&#39; propulsion efficiency [1 &gt;= PropulsionEfficiency &gt;= 0].
bool ItsChargingInTransit
Parameter 16, Flag: Vehicles it&#39;s charging in transit by default is false.
MSDevice_Battery(SUMOVehicle &holder, const std::string &id, const SUMOReal new_ActBatKap, const SUMOReal new_MaxBatKap, const SUMOReal new_PowerMax, const SUMOReal new_Mass, const SUMOReal new_FrontSurfaceArea, const SUMOReal new_AirDragCoefficient, const SUMOReal new_InternalMomentOfInertia, const SUMOReal new_RadialDragCoefficient, const SUMOReal new_RollDragCoefficient, const SUMOReal new_ConstantPowerIntake, const SUMOReal new_PropulsionEfficiency, const SUMOReal new_RecuperationEfficiency, const SUMOReal new_LastAngle, const SUMOReal new_LastEnergy)
Constructor.
SUMOReal getRecuperationEfficiency() const
Get parameter 12, vehicles&#39; Recuparation efficiency.
void setRadialDragCoefficient(const SUMOReal new_RadialDragCoefficient)
Set parameter 08, Vehicles&#39; radial friction coefficient.
SUMOReal Consum
Parameter 18, Vehicle consum during a time step by default is 0.
std::string actChrgStn
Parameter 19, Vehicle consum during a time step by default is &quot;&quot;.
Abstract in-vehicle device.
Definition: MSDevice.h:69
void setRollDragCoefficient(const SUMOReal new_RollDragCoefficient)
Set parameter 09, vehicles&#39; roll friction coefficient.
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:102
void setRecuperationEfficiency(const SUMOReal new_RecuperationEfficiency)
Set parameter 12, vehicles&#39; Recuparation efficiency.
SUMOReal getPowerMax() const
Get parameter 03, the maximum power when accelerating.
virtual SUMOReal getSpeed() const =0
Returns the vehicle&#39;s current speed.
The battery parametereter.
SUMOReal getLastEnergy() const
Get parameter 14, vehicles&#39; last Energy.
SUMOReal InternalMomentOfInertia
Parameter 07, Vehicles&#39; internal moment of inertia [InternalMomentOfInertia &gt;= 0].
SUMOReal RadialDragCoefficient
Parameter 08, Vehicles&#39; radial friction coefficient [RadialDragCoefficient &gt;=0]. ...
SUMOReal Mass
Parameter 04, Vehicle&#39;s Mass [Mass &gt;= 0].
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
void increaseChargingStartTime()
Set parameter 17b, increase Charging Start time.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle&#39;s parameter (including departure definition)
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Example-options.
void setPropulsionEfficiency(const SUMOReal new_PropulsionEfficiency)
Set parameter 11, vehicles&#39; Propulsion efficiency.
void setInternalMomentOfInertia(const SUMOReal new_InternalMomentOfInertia)
Set parameter 07, vehicles&#39; internal moment of inertia.
A storage for options typed value containers)
Definition: OptionsCont.h:108
void setMaxBatKap(const SUMOReal new_MaxBatKap)
Set parameter 02, The total vehicles&#39; Battery Capacity in kWh.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Saves departure info on insertion.
const std::string & getChrgStnID() const
Get parameter 19, Charging Station I.
SUMOReal AirDragCoefficient
Parameter 06, Vehicle&#39;s drag coefficient [AirDragCoefficient &gt;=0].
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:323
void setLastEnergy(const SUMOReal new_LastEnergy)
Set parameter 14, vehicles&#39; last Energy.
#define SUMOReal
Definition: config.h:215
SUMOReal FrontSurfaceArea
Parameter 05, Vehicle&#39;s front surface Area [FrontSurfaceArea &gt;= 0].
SUMOReal ConstantPowerIntake
Parameter 10, Vehicles&#39; constant power intake [ConstantPowerIntake &gt;= 0].
SUMOReal RecuperationEfficiency
Parameter 12, Vehicles&#39; recuparation efficiency [1 &gt;= RecuperationEfficiency &gt;= 0].
void setAirDragCoefficient(const SUMOReal new_C_Veh)
Set parameter 06, vehicle&#39;s drag coefficient.
void generateOutput() const
Called on writing tripinfo output.
SUMOReal getInternalMomentOfInertia() const
Get parameter 07, vehicles&#39; internal moment of inertia.
void setActBatKap(const SUMOReal new_ActBatKap)
Set parameter 01, The actual vehicles&#39; Battery Capacity in kWh.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
void setLastAngle(const SUMOReal new_LastAngle)
Set parameter 13, vehicles&#39; last Angle.
SUMOReal getMass() const
Get parameter 04, vehicle&#39;s Mass.
~MSDevice_Battery()
Destructor.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
#define PI