SUMO - Simulation of Urban MObility
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-2016 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 <utils/geom/GeomHelper.h>
36 #include <microsim/MSNet.h>
37 #include <microsim/MSLane.h>
38 #include <microsim/MSEdge.h>
39 #include <microsim/MSVehicle.h>
40 #include "MSDevice_Tripinfo.h"
41 #include "MSDevice_Battery.h"
42 
43 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 // ---------------------------------------------------------------------------
52 // static initialisation methods
53 // ---------------------------------------------------------------------------
54 void
56  insertDefaultAssignmentOptions("battery", "Battery", oc);
57 }
58 
59 
60 void
61 MSDevice_Battery::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
63  return;
64  }
65 
66  // Declare default parameters
67  SUMOReal new_ActBatKap = 0;
68  SUMOReal new_MaxBatKap = 0;
69  SUMOReal new_PowerMax = 100;
70  SUMOReal new_Mass = 1000;
71  SUMOReal new_FrontSurfaceArea = 2;
72  SUMOReal new_AirDragCoefficient = 0.4;
73  SUMOReal new_InternalMomentOfInertia = 10;
74  SUMOReal new_RadialDragCoefficient = 1;
75  SUMOReal new_RollDragCoefficient = 0.5;
76  SUMOReal new_ConstantPowerIntake = 10;
77  SUMOReal new_PropulsionEfficiency = 0.5;
78  SUMOReal new_RecuperationEfficiency = 0;
79  SUMOReal new_LastAngle = 0;
80  SUMOReal new_LastEnergy = 0;
81 
82  // MaxBatKap
83  new_MaxBatKap = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("maximumBatteryCapacity", "0").c_str());
84 
85  // ActBatKap
86  if (v.getParameter().getParameter("actualBatteryCapacity", "-") == "-") {
87  new_ActBatKap = new_MaxBatKap / 2.0;
88  } else {
89  new_ActBatKap = TplConvert::_2SUMOReal(v.getParameter().getParameter("actualBatteryCapacity", "0").c_str());
90  }
91 
92  // Power
93  new_PowerMax = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("maximumPower", "100").c_str());
94 
95  // Mass
96  new_Mass = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("vehicleMass", "1000").c_str());
97 
98  // FrontSurfaceArea
99  new_FrontSurfaceArea = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("frontSurfaceArea", "2").c_str());
100 
101  // AirDragCoefficient
102  new_AirDragCoefficient = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("airDragCoefficient", "0.4").c_str());
103 
104  // InternalMomentOfInertia
105  new_InternalMomentOfInertia = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("internalMomentOfInertia", "10").c_str());
106 
107  // Radial Drag Coefficient
108  new_RadialDragCoefficient = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("radialDragCoefficient", "1").c_str());
109 
110  // RollDragCoefficient
111  new_RollDragCoefficient = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("rollDragCoefficient", "0.5").c_str());
112 
113  // ConstantPowerIntake
114  new_ConstantPowerIntake = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("constantPowerIntake", "10").c_str());
115 
116  // PropulsionEfficiency
117  new_PropulsionEfficiency = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("propulsionEfficiency", "0.5").c_str());
118 
119  // RecuperationEfficiency
120  new_RecuperationEfficiency = TplConvert::_2SUMOReal(v.getVehicleType().getParameter().getParameter("recuperationEfficiency", "0").c_str());
121 
122  // constructor
123  MSDevice_Battery* device = new MSDevice_Battery(v, "battery_" + v.getID(),
124  new_ActBatKap, new_MaxBatKap, new_PowerMax, new_Mass, new_FrontSurfaceArea, new_AirDragCoefficient,
125  new_InternalMomentOfInertia, new_RadialDragCoefficient, new_RollDragCoefficient,
126  new_ConstantPowerIntake, new_PropulsionEfficiency, new_RecuperationEfficiency,
127  new_LastAngle, new_LastEnergy);
128 
129  into.push_back(device);
130 }
131 
132 
133 bool MSDevice_Battery::notifyMove(SUMOVehicle& veh, SUMOReal /* oldPos */, SUMOReal /* newPos */, SUMOReal /* newSpeed */) {
134  // Start vehicleStoppedTimer if the vehicle is stopped. In other case reset timer
135  if (veh.getSpeed() < SUMO_const_haltingSpeed) {
136  // Increase vehicle stopped timer
138  } else {
139  // Reset vehicle Stopped
141  }
142 
143  // Update Energy from the battery
144  if (getMaximumBatteryCapacity() != 0) {
145  Consum = getPropEnergy(veh);
146 
147  // Energy lost/gained from vehicle movement (via vehicle energy model) [kWh]
149 
150  // saturate between 0 and MaxBatKap [kWh]
151  if (getActualBatteryCapacity() < 0) {
153 
154  if (getMaximumBatteryCapacity() > 0) {
155  WRITE_WARNING("Battery of vehicle '" + veh.getID() + "' is depleted.");
156  }
157 
160  }
161 
162  setLastAngle(veh.getAngle());
163  }
164 
165  // Check if vehicle has under their position one charge Station
166  std::string ChargingStationID = MSNet::getInstance()->getChargingStationID(veh.getLane(), veh.getPositionOnLane());
167 
168  // If vehicle is over a charging station
169  if (ChargingStationID != "") {
170  // Declare a pointer to the charging station
171  MSChargingStation* ChargingStationPointer = MSNet::getInstance()->getChargingStation(ChargingStationID);
172 
173  // if the vehicle is almost stopped, or charge in transit is enabled, then charge vehicle
174  if ((veh.getSpeed() < SUMO_const_haltingSpeed) || (ChargingStationPointer->getChargeInTransit() == 1)) {
175  // Set Flags Stopped/intransit to
176  if (veh.getSpeed() < SUMO_const_haltingSpeed) {
177  // vehicle ist almost stopped, then is charging stopped
178  ItsChargingStopped = true;
179 
180  // therefore isn't charging in transit
181  ItsChargingInTransit = false;
182  } else {
183  // vehicle is moving, and the Charging station allow charge in transit
184  ItsChargingStopped = false;
185 
186  // Therefore charge in transit
187  ItsChargingInTransit = true;
188  }
189 
190  // Set actChargingStation parameter
191  actChargingStation = ChargingStationID;
192 
193  // Only update charging start time if vehicle allow charge in transit, or in other case
194  // if the vehicle not allow charge in transit but it's stopped.
195  if (ChargingStationPointer->getChargeInTransit() == 1 || veh.getSpeed() < SUMO_const_haltingSpeed) {
196  // Update Charging start time
198  }
199 
200  // time it takes the vehicle at the station < charging station time delay?
201  if (getChargingStartTime() > ChargingStationPointer->getChargeDelay()) {
202  // Calulate energy charged (Fix);
203  energyCharged = ChargingStationPointer->getChrgPower() * ChargingStationPointer->getEfficency();
204 
205  // Convert from [kWs] to [kWh] (3600s / 1h):
206  energyCharged /= 3600;
207 
208  // Update Battery charge
211  } else {
213  }
214  }
215  }
216  }
217  // In other case, vehicle will be not charged
218  else {
219  // Disable flags
220  ItsChargingInTransit = false;
221  ItsChargingStopped = false;
222 
223  // Disable charging station
224  actChargingStation = "NULL";
225 
226  // Set energy charged to 0
227  energyCharged = 0.00;
228 
229  // Reset timer
231  }
232 
233  // Always return true.
234  return true;
235 }
236 
237 
239  // Set last Energy ONLY when the vehicle is introduced in the simulation
241  setLastEnergy(getMass() * veh.getSpeed() * veh.getSpeed() / 2 + getMass() * 9.81 * veh.getLane()->getShape().front().z() + getInternalMomentOfInertia() * 0.5 * veh.getSpeed() * veh.getSpeed());
243  }
244 
245  // This function return always true
246  return true;
247 }
248 
249 
251  //Function implemented in MSBatteryExport
252 }
253 
254 
255 // ---------------------------------------------------------------------------
256 // MSDevice_Battery-methods
257 // ---------------------------------------------------------------------------
258 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)
259  :
260  MSDevice(holder, id),
261  ActBatKap(new_ActBatKap), // [actualBatteryCapacity <= maximumBatteryCapacity]
262  MaxBatKap(new_MaxBatKap), // [maximumBatteryCapacity >= 0]
263  PowerMax(new_PowerMax), // [maximumPower >= 0]
264  Mass(new_Mass), // [vehicleMass >= 0]
265  FrontSurfaceArea(new_FrontSurfaceArea), // [frontSurfaceArea >= 0]
266  AirDragCoefficient(new_AirDragCoefficient), // [airDragCoefficient >=0]
267  InternalMomentOfInertia(new_InternalMomentOfInertia), // [internalMomentOfInertia >= 0]
268  RadialDragCoefficient(new_RadialDragCoefficient), // [radialDragCoefficient >=0]
269  RollDragCoefficient(new_RollDragCoefficient), // [rollDragCoefficient >= 0]
270  ConstantPowerIntake(new_ConstantPowerIntake), // [constantPowerIntake >= 0]
271  PropulsionEfficiency(new_PropulsionEfficiency), // [1 >= propulsionEfficiency >= 0]
272  RecuperationEfficiency(new_RecuperationEfficiency), // [1 >= recuperationEfficiency >= 0]
273  LastAngle(new_LastAngle), // Limit not needed
274  LastEnergy(new_LastEnergy) { // Limit not needed
275  // Initially the Vehicle is not charging and is not in a Chargin Station
276  ItsChargingStopped = false;
277  ItsChargingInTransit = false;
278 
279  // Initially the energy charged is null
280  energyCharged = 0;
281 
282  // Initially the Vehicle stopped and the consum is zero.
283  Consum = 0;
284 
285  // Initially the vehicle is stopped and the corresponding variable is 0
286  vehicleStopped = 0;
287 
288  // Initially the Vehicle are not over a Charging Station
289  actChargingStation = "NULL";
290 
291  if (ActBatKap > MaxBatKap) {
292  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has a actual battery capacity (" + SUMOReal_str(ActBatKap) + ") greater than it's max battery capacity(" + SUMOReal_str(MaxBatKap) + ").");
293  ActBatKap = MaxBatKap; //TAMAS!!!
294  }
295 
296  if (MaxBatKap < 0) {
297  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid maximum battery capacity (" + SUMOReal_str(MaxBatKap) + ").");
298  }
299 
300  if (PowerMax < 0) {
301  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid maximum power (" + SUMOReal_str(PowerMax) + ").");
302  }
303 
304  if (Mass < 0) {
305  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid mass (" + SUMOReal_str(Mass) + ").");
306  }
307 
308  if (FrontSurfaceArea < 0) {
309  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid front surface Area (" + SUMOReal_str(FrontSurfaceArea) + ").");
310  }
311 
312  if (AirDragCoefficient < 0) {
313  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid drag coefficient (" + SUMOReal_str(AirDragCoefficient) + ").");
314  }
315 
316  if (InternalMomentOfInertia < 0) {
317  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid internal moment of inertia (" + SUMOReal_str(InternalMomentOfInertia) + ").");
318  }
319 
320  if (RadialDragCoefficient < 0) {
321  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid radial friction coefficient (" + SUMOReal_str(RadialDragCoefficient) + ").");
322  }
323 
324  if (RollDragCoefficient < 0) {
325  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid roll friction coefficient (" + SUMOReal_str(RollDragCoefficient) + ").");
326  }
327 
328  if (ConstantPowerIntake < 0) {
329  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid constant power intake (" + SUMOReal_str(ConstantPowerIntake) + ").");
330  }
331 
332  if (PropulsionEfficiency < 0 || PropulsionEfficiency > 1) {
333  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid propulsion efficiency (" + SUMOReal_str(PropulsionEfficiency) + ").");
334  }
335 
336  if (RecuperationEfficiency < 0 || RecuperationEfficiency > 1) {
337  WRITE_WARNING("Battery builder: Vehicle '" + getID() + "' has not a valid Recuparation efficiency (" + SUMOReal_str(RecuperationEfficiency) + ").");
338  }
339 }
340 
341 
343 }
344 
345 
346 // SET FUNCTIONS
347 
349  ActBatKap = new_ActBatKap;
350 
351  if (ActBatKap > MaxBatKap) {
352  WRITE_WARNING("Function setActualBatteryCapacity: Actual battery capacity (" + SUMOReal_str(ActBatKap) + ") from Vehicle '" + getID() + "' is greater than it's max battery capacity(" + SUMOReal_str(MaxBatKap) + ").");
353  }
354 }
355 
356 
358  MaxBatKap = new_MaxBatKap;
359 
360  if (MaxBatKap < 0) {
361  WRITE_WARNING("Function setMaximumBatteryCapacity: Vehicle '" + getID() + "' has not a valid battery capacity (" + SUMOReal_str(MaxBatKap) + ").");
362  }
363 }
364 
365 
366 void MSDevice_Battery::setMass(const SUMOReal new_Mass) {
367  Mass = new_Mass;
368 
369  if (Mass < 0) {
370  WRITE_WARNING("Function setMass: Vehicle '" + getID() + "' has not a valid mass (" + SUMOReal_str(Mass) + ").");
371  }
372 }
373 
374 
375 void MSDevice_Battery::setPowerMax(const SUMOReal new_PowerMax) {
376  PowerMax = new_PowerMax;
377 
378  if (PowerMax < 0) {
379  WRITE_WARNING("Function setPowerMax: Vehicle '" + getID() + "' has not a valid power max (" + SUMOReal_str(PowerMax) + ").");
380  }
381 }
382 
383 void MSDevice_Battery::setFrontSurfaceArea(const SUMOReal new_FrontSurfaceArea) {
384  FrontSurfaceArea = new_FrontSurfaceArea;
385 
386  if (FrontSurfaceArea < 0) {
387  WRITE_WARNING("Function setFrontSurfaceArea: Vehicle '" + getID() + "' has not a valid front surface Area (" + SUMOReal_str(FrontSurfaceArea) + ").");
388  }
389 }
390 
391 
392 void MSDevice_Battery::setAirDragCoefficient(const SUMOReal new_AirDragCoefficient) {
393  AirDragCoefficient = new_AirDragCoefficient;
394 
395  if (AirDragCoefficient < 0) {
396  WRITE_WARNING("Function setAirDragCoefficient: Vehicle '" + getID() + "' has not a valid drag coefficient (" + SUMOReal_str(AirDragCoefficient) + ").");
397  }
398 }
399 
400 
401 void MSDevice_Battery::setInternalMomentOfInertia(const SUMOReal new_InternalMomentOfInertia) {
402  InternalMomentOfInertia = new_InternalMomentOfInertia;
403 
404  if (InternalMomentOfInertia < 0) {
405  WRITE_WARNING("Function setInternalMomentOfInertia: Vehicle '" + getID() + "' has not a valid internal moment of inertia (" + SUMOReal_str(InternalMomentOfInertia) + ").");
406  }
407 }
408 
409 
410 void MSDevice_Battery::setRadialDragCoefficient(const SUMOReal new_RadialDragCoefficient) {
411  RadialDragCoefficient = new_RadialDragCoefficient;
412 
413  if (RadialDragCoefficient < 0) {
414  WRITE_WARNING("Function setRadialDragCoefficient: Vehicle '" + getID() + "' has not a valid radial friction coefficient (" + SUMOReal_str(RadialDragCoefficient) + ").");
415  }
416 }
417 
418 
419 void MSDevice_Battery::setRollDragCoefficient(const SUMOReal new_RollDragCoefficient) {
420  RollDragCoefficient = new_RollDragCoefficient;
421 
422  if (RollDragCoefficient < 0) {
423  WRITE_WARNING("Function setRollDragCoefficient: Vehicle '" + getID() + "' has not a valid roll friction coefficient (" + SUMOReal_str(RollDragCoefficient) + ").");
424  }
425 }
426 
427 
428 void MSDevice_Battery::setConstantPowerIntake(const SUMOReal new_ConstantPowerIntake) {
429  ConstantPowerIntake = new_ConstantPowerIntake;
430 
431  if (ConstantPowerIntake < 0) {
432  WRITE_WARNING("Function setConstantPowerIntake: Vehicle '" + getID() + "' has not a valid constant power intake (" + SUMOReal_str(ConstantPowerIntake) + ").");
433  }
434 }
435 
436 
437 void MSDevice_Battery::setPropulsionEfficiency(const SUMOReal new_PropulsionEfficiency) {
438  PropulsionEfficiency = new_PropulsionEfficiency;
439 
440  if (PropulsionEfficiency < 0 || PropulsionEfficiency > 1) {
441  WRITE_WARNING("Function setPropulsionEfficiency: Vehicle '" + getID() + "' has not a valid propulsion efficiency (" + SUMOReal_str(PropulsionEfficiency) + ").");
442  }
443 }
444 
445 
446 void MSDevice_Battery::setRecuperationEfficiency(const SUMOReal new_RecuperationEfficiency) {
447  RecuperationEfficiency = new_RecuperationEfficiency;
448 
449  if (RecuperationEfficiency < 0 || RecuperationEfficiency > 1) {
450  WRITE_WARNING("Function setRecuperationEfficiency: Vehicle '" + getID() + "' has not a valid recuparation efficiency (" + SUMOReal_str(RecuperationEfficiency) + ").");
451  }
452 }
453 
454 
455 void MSDevice_Battery::setLastAngle(const SUMOReal new_LastAngle) {
456  LastAngle = new_LastAngle;
457 }
458 
459 
460 void MSDevice_Battery::setLastEnergy(const SUMOReal new_LastEnergy) {
461  LastEnergy = new_LastEnergy ;
462 }
463 
465  ChargingStartTime = 0;
466 }
467 
470 }
471 
473  vehicleStopped = 0;
474 }
475 
477  vehicleStopped++;
478 }
479 
480 //GET FUNCTIONS
481 
483  return ActBatKap;
484 }
485 
487  return MaxBatKap;
488 }
489 
491  return PowerMax;
492 }
493 
495  return Mass;
496 }
497 
499  return FrontSurfaceArea;
500 }
501 
503  return AirDragCoefficient;
504 }
505 
508 }
509 
511  return RadialDragCoefficient;
512 }
513 
515  return RollDragCoefficient;
516 }
517 
519  return ConstantPowerIntake;
520 }
521 
523  return PropulsionEfficiency;
524 }
525 
527  return RecuperationEfficiency;
528 }
529 
531  return LastAngle;
532 }
533 
535  return LastEnergy;
536 }
537 
539  return Consum;
540 }
541 
543  return ItsChargingStopped;
544 }
545 
547  return ItsChargingInTransit;
548 }
549 
551  return ChargingStartTime;
552 }
553 
554 const std::string& MSDevice_Battery::getChargingStationID() const {
555  return actChargingStation;
556 }
557 
559  return energyCharged;
560 }
561 
562 
564  return vehicleStopped;
565 }
566 
567 
569  // calculate current kinetic energy
570  SUMOReal height_cur = veh.getPositionOnLane() / veh.getLane()->getLength() * (veh.getLane()->getShape().back().z() - veh.getLane()->getShape().front().z());
571 
572  // kinetic energy of vehicle with current velocity
573  SUMOReal currentEnergy = 0.5 * getMass() * veh.getSpeed() * veh.getSpeed();
574 
575  // add current potential energy of vehicle at current position
576  currentEnergy += getMass() * 9.81 * height_cur;
577 
578  // Calculate the radius of the vehicle's current path if is distintc (r = ds / dphi)
579  SUMOReal radius = 0;
580 
581  // If angle of vehicle was changed
582  if (getLastAngle() != veh.getAngle()) {
583  // Compute new radio
584  radius = SPEED2DIST(veh.getSpeed()) / fabs(GeomHelper::angleDiff(getLastAngle(), veh.getAngle()));
585 
586  // Check if radius is in the interval [0.0001 - 10000] (To avoid overflow and division by zero)
587  if (radius < 0.0001) {
588  radius = 0.0001;
589  } else if (radius > 10000) {
590  radius = 10000;
591  }
592  }
593 
594  // add current rotational energy of internal rotating elements
595  currentEnergy += getInternalMomentOfInertia() * veh.getSpeed() * veh.getSpeed();
596 
597  // kinetic + potential + rotational energy gain [Ws] (MODIFICATED LAST ANGLE)
598  SUMOReal EnergyLoss = (currentEnergy - getLastEnergy());
599 
600  // save current total energy for next time step
601  setLastEnergy(currentEnergy);
602 
603  // Calculate energy losses:
604  // EnergyLoss,Air = 1/2 * rho_air [kg/m^3] * FrontSurfaceArea [m^2] * AirDragCoefficient [-] * v_Veh^2 [m/s] * s [m]
605  // ... with rho_air [kg/m^3] = 1,2041 kg/m^3 (at T = 20C)
606  // ... with s [m] = v_Veh [m/s] * 1 [s]
607  EnergyLoss += 0.5 * 1.2041 * getFrontSurfaceArea() * getAirDragCoefficient() * fabs(veh.getSpeed() * veh.getSpeed() * veh.getSpeed());
608 
609  // Energy loss through Air resistance [Ws]
610  // EnergyLoss,Tire = c_R [-] * F_N [N] * s [m]
611  // ... with c_R = ~0.012 (car tire on asphalt)
612  // ... with F_N [N] = Mass [kg] * g [m/s^2]
613  EnergyLoss += getRollDragCoefficient() * 9.81 * getMass() * fabs(veh.getSpeed());
614 
615  // Energy loss through Roll resistance [Ws]
616  // ... (fabs(veh.getSpeed())>=0.01) = 0, if vehicle isn't moving
617  // EnergyLoss,internalFrictionRadialForce = c [m] * F_rad [N];
618  if (getLastAngle() != veh.getAngle()) {
619  // Energy loss through friction by radial force [Ws]
620  EnergyLoss += getRadialDragCoefficient() * getMass() * veh.getSpeed() * veh.getSpeed() / radius;
621  }
622 
623  // EnergyLoss,constantConsumers
624  // Energy loss through constant loads (e.g. A/C) [Ws]
625  EnergyLoss += getConstantPowerIntake();
626 
627  //E_Bat = E_kin_pot + EnergyLoss;
628  if (EnergyLoss > 0) {
629  // Assumption: Efficiency of PropulsionEfficiency when accelerating
630  EnergyLoss = EnergyLoss / getPropulsionEfficiency();
631  } else {
632  // Assumption: Efficiency of RecuperationEfficiency when recuperating
633  EnergyLoss = EnergyLoss * getRecuperationEfficiency();
634  }
635 
636  // convert from [Ws] to [kWh] (3600s / 1h):
637  EnergyLoss = EnergyLoss / 3600 ; // EnergyLoss[Ws] * 1[h]/3600[s] * 1[k]/1000
638 
639  // Return calculated energy
640  return (EnergyLoss);
641 }
642 
643 
644 // Private methods
645 
646 std::string MSDevice_Battery::SUMOReal_str(const SUMOReal& var) {
647  std::ostringstream convert;
648  convert << var;
649  return convert.str();
650 }
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)
#define SPEED2DIST(x)
Definition: SUMOTime.h:55
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 <= MaxBatKap].
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:375
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 energyCharged
Parameter 20, Energy charged in each timestep.
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
MSChargingStation * getChargingStation(const std::string &id) const
Returns the named charging station.
Definition: MSNet.cpp:828
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
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.
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 >= 0].
SUMOReal getAirDragCoefficient() const
Get parameter 06, vehicle&#39;s drag coefficient.
SUMOReal beginEndAngle() const
returns the angle in radians of the line connecting the first and the last position ...
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
static SUMOReal angleDiff(const SUMOReal angle1, const SUMOReal angle2)
Returns the difference of the second angle to the first angle in radiants.
Definition: GeomHelper.cpp:178
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
SUMOReal getMaximumPower() const
Get parameter 03, the maximum power when accelerating.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
void setMaximumBatteryCapacity(const SUMOReal new_MaxBatKap)
Set parameter 02, The total vehicles&#39; Battery Capacity in kWh.
const std::string & getID() const
Returns the id.
Definition: Named.h:65
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 getChrgPower() const
Get parameter 01, charging station&#39;s charging power.
SUMOReal PowerMax
Parameter 03, The Maximum Power when accelerating [PowerMax >= 0].
SUMOReal getLastAngle() const
Get parameter 13, vehicles&#39; last angle.
SUMOReal RollDragCoefficient
Parameter 09, Vehicles&#39; roll friction coefficient [RollDragCoefficient >= 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.
SUMOReal getActualBatteryCapacity() const
Get parameter 01, the actual vehicles&#39; Battery Capacity in kWh.
SUMOReal getEfficency() const
Get parameter 02, efficiency of the charging station.
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:86
SUMOReal LastEnergy
Parameter 14, Vehicles&#39; last energy none.
SUMOReal getChargeInTransit() const
Get parameter 03, get chargeInTransit.
SUMOReal getChargeDelay() const
Get parameter 03, get Charge Delay.
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 >= PropulsionEfficiency >= 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.
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:100
void setRecuperationEfficiency(const SUMOReal new_RecuperationEfficiency)
Set parameter 12, vehicles&#39; Recuparation efficiency.
The vehicle has departed (was inserted into the network)
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 >= 0].
SUMOReal RadialDragCoefficient
Parameter 08, Vehicles&#39; radial friction coefficient [RadialDragCoefficient >=0]. ...
SUMOReal Mass
Parameter 04, Vehicle&#39;s Mass [Mass >= 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
std::string actChargingStation
Parameter 19, Vehicle consum during a time step by default is "".
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Saves departure info on insertion.
const SUMOReal SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition: StdDefs.h:57
SUMOReal AirDragCoefficient
Parameter 06, Vehicle&#39;s drag coefficient [AirDragCoefficient >=0].
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:322
void setLastEnergy(const SUMOReal new_LastEnergy)
Set parameter 14, vehicles&#39; last Energy.
#define SUMOReal
Definition: config.h:213
SUMOReal FrontSurfaceArea
Parameter 05, Vehicle&#39;s front surface Area [FrontSurfaceArea >= 0].
void setActualBatteryCapacity(const SUMOReal new_ActBatKap)
Set parameter 01, The actual vehicles&#39; Battery Capacity in kWh.
std::string getChargingStationID(const MSLane *lane, const SUMOReal pos) const
Returns the charging station close to the given position.
Definition: MSNet.cpp:834
SUMOReal ConstantPowerIntake
Parameter 10, Vehicles&#39; constant power intake [ConstantPowerIntake >= 0].
SUMOReal getMaximumBatteryCapacity() const
Get parameter 02, the total vehicles&#39; Battery Capacity in kWh.
SUMOReal RecuperationEfficiency
Parameter 12, Vehicles&#39; recuparation efficiency [1 >= RecuperationEfficiency >= 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.
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.
const std::string & getChargingStationID() const
Get parameter 19, Charging Station I.
~MSDevice_Battery()
Destructor.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.