Eclipse SUMO - Simulation of Urban MObility
MSDevice_Battery.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2013-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // The Battery parameters for the vehicle
21 /****************************************************************************/
22 #include <algorithm>
23 
24 #include <config.h>
25 
29 #include <utils/common/SUMOTime.h>
30 #include <utils/geom/GeomHelper.h>
33 #include <microsim/MSNet.h>
34 #include <microsim/MSLane.h>
35 #include <microsim/MSEdge.h>
36 #include <microsim/MSVehicle.h>
37 #include "MSDevice_StationFinder.h"
38 #include "MSDevice_Emissions.h"
39 #include "MSDevice_Battery.h"
40 
41 #define DEFAULT_MAX_CAPACITY 35000
42 #define DEFAULT_CHARGE_RATIO 0.5
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 // ---------------------------------------------------------------------------
49 // static initialisation methods
50 // ---------------------------------------------------------------------------
51 void
53  insertDefaultAssignmentOptions("battery", "Battery", oc);
54  // custom options
55  oc.doRegister("device.battery.track-fuel", new Option_Bool(false));
56  oc.addDescription("device.battery.track-fuel", "Battery", TL("Track fuel consumption for non-electric vehicles"));
57 }
58 
59 
60 void
61 MSDevice_Battery::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into, MSDevice_StationFinder* sf) {
62  // Check if vehicle should get a battery
63  if (sf != nullptr || equippedByDefaultAssignmentOptions(OptionsCont::getOptions(), "battery", v, false)) {
64  // obtain parameter values
65  const double maximumBatteryCapacity = readParameterValue(v, SUMO_ATTR_MAXIMUMBATTERYCAPACITY, "battery.capacity", DEFAULT_MAX_CAPACITY);
66  const double actualBatteryCapacity = readParameterValue(v, SUMO_ATTR_ACTUALBATTERYCAPACITY, "battery.chargeLevel", maximumBatteryCapacity * DEFAULT_CHARGE_RATIO);
67  const double stoppingThreshold = readParameterValue(v, SUMO_ATTR_STOPPINGTHRESHOLD, "battery.stoppingThreshold", 0.1);
68  const double maximumChargeRate = readParameterValue(v, SUMO_ATTR_MAXIMUMCHARGERATE, "battery.maximumChargeRate", 150000.);
69  const std::string chargeLevelTable = v.getStringParam("device.battery.chargeLevelTable");
70  const std::string chargeCurveTable = v.getStringParam("device.battery.chargeCurveTable");
71 
72  // battery constructor
73  MSDevice_Battery* device = new MSDevice_Battery(v, "battery_" + v.getID(),
74  actualBatteryCapacity, maximumBatteryCapacity, stoppingThreshold, maximumChargeRate, chargeLevelTable, chargeCurveTable);
75 
76  // Add device to vehicle
77  into.push_back(device);
78 
79  if (sf != nullptr) {
80  sf->setBattery(device);
81  }
82  }
83 }
84 
85 
86 double
87 MSDevice_Battery::readParameterValue(SUMOVehicle& v, const SumoXMLAttr& attr, const std::string& paramName, double defaultVal) {
88  const std::string& oldParam = toString(attr);
89  const SUMOVTypeParameter& typeParams = v.getVehicleType().getParameter();
90  if (v.getParameter().hasParameter(oldParam) || typeParams.hasParameter(oldParam)) {
91  WRITE_WARNINGF(TL("Battery device in vehicle '%' still uses old parameter '%'. Please update to 'device.%'."), v.getID(), oldParam, paramName);
92  if (v.getParameter().getParameter(oldParam, "-") == "-") {
93  return typeParams.getDouble(oldParam, defaultVal);
94  }
95  return StringUtils::toDouble(v.getParameter().getParameter(oldParam, "0"));
96  }
97  return v.getFloatParam("device." + paramName, false, defaultVal);
98 }
99 
100 
101 // ---------------------------------------------------------------------------
102 // MSDevice_Battery-methods
103 // ---------------------------------------------------------------------------
104 MSDevice_Battery::MSDevice_Battery(SUMOVehicle& holder, const std::string& id, const double actualBatteryCapacity, const double maximumBatteryCapacity,
105  const double stoppingThreshold, const double maximumChargeRate, const std::string& chargeLevelTable, const std::string& chargeCurveTable) :
106  MSVehicleDevice(holder, id),
107  myActualBatteryCapacity(0), // [actualBatteryCapacity <= maximumBatteryCapacity]
108  myMaximumBatteryCapacity(0), // [maximumBatteryCapacity >= 0]
109  myStoppingThreshold(0), // [stoppingThreshold >= 0]
110  myMaximumChargeRate(0),
111  myChargeLimit(-1),
112  myLastAngle(std::numeric_limits<double>::infinity()),
113  myChargingStopped(false), // Initially vehicle don't charge stopped
114  myChargingInTransit(false), // Initially vehicle don't charge in transit
115  myChargingStartTime(0), // Initially charging start time (must be if the vehicle was launched at the charging station)
116  myConsum(0), // Initially the vehicle is stopped and therefore the consum is zero.
117  myTotalConsumption(0.0),
118  myTotalRegenerated(0.0),
119  myActChargingStation(nullptr), // Initially the vehicle isn't over a Charging Station
120  myPreviousNeighbouringChargingStation(nullptr), // Initially the vehicle wasn't over a Charging Station
121  myEnergyCharged(0), // Initially the energy charged is zero
122  myVehicleStopped(0) { // Initially the vehicle is stopped and the corresponding variable is 0
123 
124  if (maximumBatteryCapacity < 0) {
125  WRITE_WARNINGF(TL("Battery builder: Vehicle '%' doesn't have a valid value for parameter % (%)."), getID(), toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY), toString(maximumBatteryCapacity));
126  } else {
127  myMaximumBatteryCapacity = maximumBatteryCapacity;
128  }
129 
130  if (actualBatteryCapacity > maximumBatteryCapacity) {
131  WRITE_WARNINGF(TL("Battery builder: Vehicle '%' has a % (%) greater than its % (%). A max battery capacity value will be assigned."),
132  getID(), toString(SUMO_ATTR_ACTUALBATTERYCAPACITY), toString(actualBatteryCapacity), toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY), toString(maximumBatteryCapacity));
134  } else {
135  myActualBatteryCapacity = actualBatteryCapacity;
136  }
137 
138  if (stoppingThreshold < 0) {
139  WRITE_WARNINGF(TL("Battery builder: Vehicle '%' doesn't have a valid value for parameter % (%)."), getID(), toString(SUMO_ATTR_STOPPINGTHRESHOLD), toString(stoppingThreshold));
140  } else {
141  myStoppingThreshold = stoppingThreshold;
142  }
143 
144  myTrackFuel = PollutantsInterface::getFuel(holder.getVehicleType().getEmissionClass()) != "Electricity" && OptionsCont::getOptions().getBool("device.battery.track-fuel");
146  WRITE_WARNINGF(TL("The battery device is active for vehicle '%' but no emission class is set. "
147  "Please consider setting an explicit emission class or battery outputs might be inconsistent with emission outputs!"),
148  holder.getID());
149  }
150 
151  if (maximumChargeRate < 0) {
152  WRITE_WARNINGF(TL("Battery builder: Vehicle '%' doesn't have a valid value for parameter % (%)."), getID(), toString(SUMO_ATTR_MAXIMUMCHARGERATE), toString(maximumChargeRate));
153  } else {
154  if (!chargeLevelTable.empty() && !chargeCurveTable.empty()) {
155  LinearApproxHelpers::setPoints(myChargeCurve, chargeLevelTable, chargeCurveTable);
156  if (!myTrackFuel) {
158  }
160  } else {
161  myMaximumChargeRate = maximumChargeRate;
162  if (!myTrackFuel) {
163  myMaximumChargeRate /= 3600.;
164  }
165  }
166  }
167 }
168 
169 
171 }
172 
173 
174 bool MSDevice_Battery::notifyMove(SUMOTrafficObject& tObject, double /* oldPos */, double /* newPos */, double /* newSpeed */) {
175  if (!tObject.isVehicle()) {
176  return false;
177  }
178  SUMOVehicle& veh = static_cast<SUMOVehicle&>(tObject);
179  // Start vehicleStoppedTimer if the vehicle is stopped. In other case reset timer
180  if (veh.getSpeed() < myStoppingThreshold) {
181  // Increase vehicle stopped timer
183  } else {
184  // Reset vehicle Stopped
186  }
187 
188  // Update Energy from the battery
189  EnergyParams* const params = myHolder.getEmissionParameters();
190  if (getMaximumBatteryCapacity() != 0) {
191  params->setDouble(SUMO_ATTR_ANGLE, myLastAngle == std::numeric_limits<double>::infinity() ? 0. : GeomHelper::angleDiff(myLastAngle, veh.getAngle()));
193  // no explicit emission class, we fall back to the energy model; a warning has been issued on creation
195  veh.getSlope(), params) * TS;
196  } else {
199  veh.getSpeed(), veh.getAcceleration(),
200  veh.getSlope(), params) * TS;
201  }
202  if (veh.isParking()) {
203  // recuperation from last braking step is ok but further consumption should cease
204  myConsum = MIN2(myConsum, 0.0);
205  }
206 
207  // saturate between 0 and myMaximumBatteryCapacity [Wh]
209  WRITE_WARNINGF(TL("Battery of vehicle '%' is depleted, time=%."), veh.getID(), time2string(SIMSTEP));
210  }
211 
212  // Energy lost/gained from vehicle movement (via vehicle energy model) [Wh]
214 
215  // Track total energy consumption and regeneration
216  if (myConsum > 0.0) {
218  } else {
220  }
221 
222  myLastAngle = veh.getAngle();
223  }
224 
225  // Check if vehicle has under their position one charge Station
226  const std::string chargingStationID = MSNet::getInstance()->getStoppingPlaceID(veh.getLane(), veh.getPositionOnLane(), SUMO_TAG_CHARGING_STATION);
227 
228  // If vehicle is over a charging station
229  if (chargingStationID != "") {
230  // if the vehicle is almost stopped, or charge in transit is enabled, then charge vehicle
231  MSChargingStation* const cs = static_cast<MSChargingStation*>(MSNet::getInstance()->getStoppingPlace(chargingStationID, SUMO_TAG_CHARGING_STATION));
232  const MSParkingArea* pa = cs->getParkingArea();
233  if (((veh.getSpeed() < myStoppingThreshold) || cs->getChargeInTransit()) && (pa == nullptr || veh.isParking())) {
234  // Set Flags Stopped/intransit to
235  if (veh.getSpeed() < myStoppingThreshold) {
236  // vehicle ist almost stopped, then is charging stopped
237  myChargingStopped = true;
238 
239  // therefore isn't charging in transit
240  myChargingInTransit = false;
241  } else {
242  // vehicle is moving, and the Charging station allow charge in transit
243  myChargingStopped = false;
244 
245  // Therefore charge in transit
246  myChargingInTransit = true;
247  }
248 
249  // get pointer to charging station
251 
252  // Only update charging start time if vehicle allow charge in transit, or in other case
253  // if the vehicle not allow charge in transit but it's stopped.
255  // Update Charging start time
257  }
258 
259  // time it takes the vehicle at the station < charging station time delay?
261  // Enable charging vehicle
263 
264  // Calulate energy charged
266 
267  // Update Battery charge
269  }
270  // add charge value for output to myActChargingStation
272  }
273  // else disable charging vehicle
274  else {
275  cs->setChargingVehicle(false);
276  }
277  // disable charging vehicle from previous (not current) ChargingStation (reason: if there is no gap between two different chargingStations = the vehicle switches from used charging station to other one in a single timestap)
280  }
282  }
283  // In other case, vehicle will be not charged
284  else {
285  // Disable flags
286  myChargingInTransit = false;
287  myChargingStopped = false;
288 
289  // Disable charging vehicle
290  if (myActChargingStation != nullptr) {
292  }
293 
294  // Set charging station pointer to NULL
295  myActChargingStation = nullptr;
296 
297  // Set energy charged to 0
298  myEnergyCharged = 0.00;
299 
300  // Reset timer
302  }
303 
304  // Always return true.
305  return true;
306 }
307 
308 
309 void
312  out.writeAttr(SUMO_ATTR_ID, getID());
313  std::vector<std::string> internals;
314  internals.push_back(toString(myActualBatteryCapacity));
315  internals.push_back(toString(myLastAngle));
316  internals.push_back(toString(myChargingStopped));
317  internals.push_back(toString(myChargingInTransit));
318  internals.push_back(toString(myChargingStartTime));
319  internals.push_back(toString(myTotalConsumption));
320  internals.push_back(toString(myTotalRegenerated));
321  internals.push_back(toString(myEnergyCharged));
322  internals.push_back(toString(myVehicleStopped));
323  internals.push_back(getChargingStationID());
324  std::string prevChargingID = (myPreviousNeighbouringChargingStation == nullptr) ? "NULL" : myPreviousNeighbouringChargingStation->getID();
325  internals.push_back(prevChargingID);
326  internals.push_back(toString(myMaximumChargeRate));
327  out.writeAttr(SUMO_ATTR_STATE, toString(internals));
328  out.closeTag();
329 }
330 
331 
332 void
334  std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
336  bis >> myLastAngle;
337  bis >> myChargingStopped;
338  bis >> myChargingInTransit;
339  bis >> myChargingStartTime;
340  bis >> myTotalConsumption;
341  bis >> myTotalRegenerated;
342  bis >> myEnergyCharged;
343  bis >> myVehicleStopped;
344  std::string chargingID;
345  bis >> chargingID;
346  if (chargingID != "NULL") {
348  }
349  std::string prevChargingID;
350  bis >> prevChargingID;
351  if (prevChargingID != "NULL") {
353  }
354  bis >> myMaximumChargeRate;
355 }
356 
357 
358 void
359 MSDevice_Battery::setActualBatteryCapacity(const double actualBatteryCapacity) {
360  if (actualBatteryCapacity < 0) {
362  } else if (actualBatteryCapacity > myMaximumBatteryCapacity) {
364  } else {
365  myActualBatteryCapacity = actualBatteryCapacity;
366  }
367 }
368 
369 
370 void
371 MSDevice_Battery::setMaximumBatteryCapacity(const double maximumBatteryCapacity) {
372  if (myMaximumBatteryCapacity < 0) {
373  WRITE_WARNINGF(TL("Trying to set into the battery device of vehicle '%' an invalid % (%)."), getID(), toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY), toString(maximumBatteryCapacity));
374  } else {
375  myMaximumBatteryCapacity = maximumBatteryCapacity;
376  }
377 }
378 
379 
380 void
381 MSDevice_Battery::setStoppingThreshold(const double stoppingThreshold) {
382  if (stoppingThreshold < 0) {
383  WRITE_WARNINGF(TL("Trying to set into the battery device of vehicle '%' an invalid % (%)."), getID(), toString(SUMO_ATTR_STOPPINGTHRESHOLD), toString(stoppingThreshold));
384  } else {
385  myStoppingThreshold = stoppingThreshold;
386  }
387 }
388 
389 
390 void
391 MSDevice_Battery::setMaximumChargeRate(const double chargeRate) {
392  if (chargeRate < 0) {
393  WRITE_WARNINGF(TL("Trying to set into the battery device of vehicle '%' an invalid % (%)."), getID(), toString(SUMO_ATTR_MAXIMUMCHARGERATE), toString(chargeRate));
394  } else {
395  myMaximumChargeRate = chargeRate;
396  }
397 }
398 
399 
400 void
401 MSDevice_Battery::setChargeLimit(const double limit) {
402  myChargeLimit = limit;
403 }
404 
405 
406 void
409 }
410 
411 
412 void
415 }
416 
417 
418 void
420  myVehicleStopped = 0;
421 }
422 
423 
424 void
427 }
428 
429 
430 double
433 }
434 
435 
436 double
439 }
440 
441 
442 double
444  return myConsum;
445 }
446 
447 double
449  return myTotalConsumption;
450 }
451 
452 
453 double
455  return myTotalRegenerated;
456 }
457 
458 
459 bool
461  return myChargingStopped;
462 }
463 
464 
465 bool
467  return myChargingInTransit;
468 }
469 
470 
471 SUMOTime
473  return myChargingStartTime;
474 }
475 
476 
477 SUMOTime
478 MSDevice_Battery::estimateChargingDuration(const double toCharge, const double csPower) const {
479  //if (!myChargeCurve.empty()) {
480  // // TODO: integrate charge curve
481  //}
482  return TIME2STEPS(toCharge / MIN2(csPower, myMaximumChargeRate));
483 }
484 
485 
486 std::string
488  if (myActChargingStation != nullptr) {
489  return myActChargingStation->getID();
490  } else {
491  return "NULL";
492  }
493 }
494 
495 double
497  return myEnergyCharged;
498 }
499 
500 
501 int
503  return myVehicleStopped;
504 }
505 
506 
507 double
509  return myStoppingThreshold;
510 }
511 
512 
513 double
516  return (myChargeLimit < 0) ? baseVal : MIN2(myChargeLimit, baseVal);
517 }
518 
519 
520 std::string
521 MSDevice_Battery::getParameter(const std::string& key) const {
523  || key == toString(SUMO_ATTR_CHARGELEVEL)) {
525  } else if (key == toString(SUMO_ATTR_ENERGYCONSUMED)) {
526  return toString(getConsum());
527  } else if (key == toString(SUMO_ATTR_TOTALENERGYCONSUMED)) {
528  return toString(getTotalConsumption());
529  } else if (key == toString(SUMO_ATTR_TOTALENERGYREGENERATED)) {
530  return toString(getTotalRegenerated());
531  } else if (key == toString(SUMO_ATTR_ENERGYCHARGED)) {
532  return toString(getEnergyCharged());
533  } else if (key == toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY) || key == "capacity") {
535  } else if (key == toString(SUMO_ATTR_MAXIMUMCHARGERATE)) {
536  return toString(getMaximumChargeRate());
537  } else if (key == toString(SUMO_ATTR_CHARGINGSTATIONID)) {
538  return getChargingStationID();
539  } else if (key == toString(SUMO_ATTR_VEHICLEMASS)) {
540  WRITE_WARNING(TL("Getting the vehicle mass via parameters is deprecated, please use getMass for the vehicle or its type."));
542  }
543  throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
544 }
545 
546 
547 void
548 MSDevice_Battery::setParameter(const std::string& key, const std::string& value) {
549  double doubleValue;
550  try {
551  doubleValue = StringUtils::toDouble(value);
552  } catch (NumberFormatException&) {
553  throw InvalidArgument("Setting parameter '" + key + "' requires a number for device of type '" + deviceName() + "'");
554  }
556  setActualBatteryCapacity(doubleValue);
557  } else if (key == toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY) || key == "capacity") {
558  setMaximumBatteryCapacity(doubleValue);
559  } else if (key == toString(SUMO_ATTR_MAXIMUMCHARGERATE)) {
560  setMaximumChargeRate(doubleValue);
561  } else if (key == toString(SUMO_ATTR_VEHICLEMASS)) {
562  WRITE_WARNING(TL("Setting the vehicle mass via parameters is deprecated, please use setMass for the vehicle or its type."));
564  } else {
565  throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
566  }
567 }
568 
569 
570 void
572  // @note: only charing is performed but no energy is consumed
574  myConsum = 0;
575 }
576 
577 
578 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
#define DEFAULT_CHARGE_RATIO
#define DEFAULT_MAX_CAPACITY
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:295
#define TL(string)
Definition: MsgHandler.h:315
SUMOTime DELTA_T
Definition: SUMOTime.cpp:38
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
#define SIMSTEP
Definition: SUMOTime.h:61
#define TS
Definition: SUMOTime.h:42
#define TIME2STEPS(x)
Definition: SUMOTime.h:57
const long long int VTYPEPARS_EMISSIONCLASS_SET
@ SUMO_TAG_DEVICE
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_CHARGELEVEL
@ SUMO_ATTR_ENERGYCONSUMED
Energy consumed.
@ SUMO_ATTR_MAXIMUMBATTERYCAPACITY
Maxium battery capacity.
@ SUMO_ATTR_MASS
@ SUMO_ATTR_MAXIMUMCHARGERATE
Maximum Power.
@ SUMO_ATTR_STOPPINGTHRESHOLD
Stopping threshold.
@ SUMO_ATTR_CHARGINGSTATIONID
Charging Station ID.
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_ACTUALBATTERYCAPACITY
@ SUMO_ATTR_VEHICLEMASS
Vehicle mass.
@ SUMO_ATTR_ENERGYCHARGED
tgotal of Energy charged
@ SUMO_ATTR_ID
@ SUMO_ATTR_TOTALENERGYREGENERATED
Total energy regenerated.
@ SUMO_ATTR_TOTALENERGYCONSUMED
Total energy consumed.
@ SUMO_ATTR_STATE
The state of a link.
T MIN2(T a, T b)
Definition: StdDefs.h:76
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
An upper class for objects with additional parameters.
Definition: EnergyParams.h:43
double getDouble(SumoXMLAttr attr) const
void setDouble(SumoXMLAttr attr, double value)
Sets a parameter.
static double angleDiff(const double angle1, const double angle2)
Returns the difference of the second angle to the first angle in radiants.
Definition: GeomHelper.cpp:178
double compute(const SUMOEmissionClass c, const PollutantsInterface::EmissionType e, const double v, const double a, const double slope, const EnergyParams *param) const
Computes the emitted pollutant amount using the given speed and acceleration.
static double getInterpolatedValue(const LinearApproxMap &map, double axisValue)
Get interpolated value.
static void scaleValues(LinearApproxMap &map, const double factor)
Scale values.
static bool setPoints(LinearApproxMap &map, const std::string &axisString, const std::string &heightString)
Set data points.
static double getMaximumValue(const LinearApproxMap &map)
Get the largest height value.
double getChargingPower(bool usingFuel) const
Get charging station's charging power.
bool getChargeInTransit() const
Get chargeInTransit.
void setChargingVehicle(bool value)
enable or disable charging vehicle
void addChargeValueForOutput(double WCharged, MSDevice_Battery *battery)
add charge value for output
SUMOTime getChargeDelay() const
Get Charge Delay.
double getEfficency() const
Get efficiency of the charging station.
const MSParkingArea * getParkingArea() const
Get the parking area the charging station is placed on.
Battery device for electric vehicles.
SUMOTime getChargingStartTime() const
Get charging start time.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Example-options.
void notifyParking()
called to update state for parking vehicles
int myVehicleStopped
Parameter, How many timestep the vehicle is stopped.
bool myChargingInTransit
Parameter, Flag: Vehicles it's charging in transit (by default is false)
LinearApproxHelpers::LinearApproxMap myChargeCurve
Charge curve data points storage.
double getActualBatteryCapacity() const
Get the actual vehicle's Battery Capacity in Wh.
int getVehicleStopped() const
Get number of timestep that vehicle is stopped.
void setChargeLimit(const double limit)
Set (temporary) charge limit.
MSDevice_Battery(SUMOVehicle &holder, const std::string &id, const double actualBatteryCapacity, const double maximumBatteryCapacity, const double stoppingThreshold, const double maximumChargeRate, const std::string &chargeLevelTable, const std::string &chargeCurveTable)
Constructor.
double myMaximumBatteryCapacity
Parameter, The total vehicles's Battery Capacity in Wh, [myMaximumBatteryCapacity >= 0].
void increaseVehicleStoppedTimer()
Increase myVehicleStopped.
double myActualBatteryCapacity
Parameter, The actual vehicles's Battery Capacity in Wh, [myActualBatteryCapacity <= myMaximumBattery...
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks for waiting steps when the vehicle moves.
double getMaximumChargeRate() const
Get current charge rate in W depending on the state of charge.
void saveState(OutputDevice &out) const
Saves the state of the device.
void increaseChargingStartTime()
Increase Charging Start time.
MSChargingStation * myPreviousNeighbouringChargingStation
Parameter, Pointer to charging station neighbouring with myActChargingStation in which vehicle was pl...
void setStoppingThreshold(const double stoppingThreshold)
Set vehicle's stopping threshold.
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in Wh.
SUMOTime estimateChargingDuration(const double toCharge, const double csPower) const
Estimate the charging duration given the current battery state.
bool myChargingStopped
Parameter, Flag: Vehicles it's charging stopped (by default is false)
double getConsum() const
Get consum.
void setActualBatteryCapacity(const double actualBatteryCapacity)
Set actual vehicle's Battery Capacity in kWh.
bool myTrackFuel
whether to track fuel consumption instead of electricity
double myEnergyCharged
Parameter, Energy charged in each timestep.
double myLastAngle
Parameter, Vehicle's last angle.
void setMaximumChargeRate(const double chargeRate)
Set vehicle's stopping threshold.
double getStoppingThreshold() const
Get stopping threshold.
double myTotalRegenerated
Parameter, total vehicle energy regeneration.
double myMaximumChargeRate
Parameter, maximum charge rate in W.
SUMOTime myChargingStartTime
Parameter, Moment, wich the vehicle has beging to charging.
bool isChargingInTransit() const
Get true if Vehicle it's charging, false if not.
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
void resetChargingStartTime()
Reset charging start time.
double myTotalConsumption
Parameter, total vehicle energy consumption.
const std::string deviceName() const
return the name for this type of device
void resetVehicleStoppedTimer()
Reset myVehicleStopped.
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the device from the given description.
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key
double myChargeLimit
(Temporary) limitation in W of the maximum charge rate = charging strategy result
double getTotalRegenerated() const
Get total regenerated.
double getTotalConsumption() const
Get total consumption.
MSChargingStation * myActChargingStation
Parameter, Pointer to current charging station in which vehicle is placed (by default is NULL)
~MSDevice_Battery()
Destructor.
double myConsum
Parameter, Vehicle consum during a time step (by default is 0.)
double getEnergyCharged() const
Get charged energy.
std::string getChargingStationID() const
Get current Charging Station ID.
void setMaximumBatteryCapacity(const double maximumBatteryCapacity)
Set total vehicle's Battery Capacity in kWh.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into, MSDevice_StationFinder *sf)
Build devices for the given vehicle, if needed.
static double readParameterValue(SUMOVehicle &v, const SumoXMLAttr &attr, const std::string &paramName, double defaultVal)
Read device parameters from input.
double myStoppingThreshold
Parameter, stopping vehicle threshold [myStoppingThreshold >= 0].
bool isChargingStopped() const
Get true if Vehicle is charging, false if not.
A device which triggers rerouting to nearby charging stations.
void setBattery(MSDevice_Battery *battery)
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:155
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.h:195
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:184
std::string getStoppingPlaceID(const MSLane *lane, const double pos, const SumoXMLTag category) const
Returns the stop of the given category close to the given position.
Definition: MSNet.cpp:1394
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:1373
A lane area vehicles can halt at.
Definition: MSParkingArea.h:60
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
const SUMOVTypeParameter & getParameter() const
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
Definition: OptionsCont.cpp:76
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool hasParameter(const std::string &key) const
Returns whether the parameter is set.
double getDouble(const std::string &key, const double defaultValue) const
Returns the value for a given key converted to a double.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
static const HelpersEnergy & getEnergyHelper()
get energy helper
static std::string getFuel(const SUMOEmissionClass c)
Returns the fuel type of the given emission class.
static double compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const EnergyParams *param)
Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fue...
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
Representation of a vehicle, person, or container.
virtual bool isVehicle() const
Whether it is a vehicle.
virtual double getAcceleration() const =0
Returns the object's acceleration.
std::string getStringParam(const std::string &paramName, const bool required=false, const std::string &deflt="") const
Retrieve a string parameter for the traffic object.
virtual double getSlope() const =0
Returns the slope of the road at object's position in degrees.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
double getFloatParam(const std::string &paramName, const bool required=false, const double deflt=INVALID_DOUBLE) const
Retrieve a floating point parameter for the traffic object.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Structure representing possible vehicle parameter.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
Representation of a vehicle.
Definition: SUMOVehicle.h:62
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
virtual double getAngle() const =0
Get the vehicle's angle.
virtual EnergyParams * getEmissionParameters() const =0
Returns the vehicle's emission model parameter.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
Definition: json.hpp:4471