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