Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2026 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 <config.h>
23
24#include <algorithm>
32#include <microsim/MSNet.h>
33#include <microsim/MSLane.h>
34#include <microsim/MSEdge.h>
35#include <microsim/MSVehicle.h>
37#include "MSDevice_Emissions.h"
38#include "MSDevice_Battery.h"
39
40#define DEFAULT_MAX_CAPACITY 35000
41#define DEFAULT_CHARGE_RATIO 0.5
42
43
44// ===========================================================================
45// method definitions
46// ===========================================================================
47// ---------------------------------------------------------------------------
48// static initialisation methods
49// ---------------------------------------------------------------------------
50void
52 insertDefaultAssignmentOptions("battery", "Battery", oc);
53 // custom options
54 oc.doRegister("device.battery.track-fuel", new Option_Bool(false));
55 oc.addDescription("device.battery.track-fuel", "Battery", TL("Track fuel consumption for non-electric vehicles"));
56}
57
58
59void
60MSDevice_Battery::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into, MSDevice_StationFinder* sf) {
61 // Check if vehicle should get a battery
62 if (sf != nullptr || equippedByDefaultAssignmentOptions(OptionsCont::getOptions(), "battery", v, false)) {
63 // obtain parameter values
64 const double maximumBatteryCapacity = readParameterValue(v, SUMO_ATTR_MAXIMUMBATTERYCAPACITY, "battery.capacity", DEFAULT_MAX_CAPACITY);
65 const double actualBatteryCapacity = readParameterValue(v, SUMO_ATTR_ACTUALBATTERYCAPACITY, "battery.chargeLevel", maximumBatteryCapacity * DEFAULT_CHARGE_RATIO);
66 const double stoppingThreshold = readParameterValue(v, SUMO_ATTR_STOPPINGTHRESHOLD, "battery.stoppingThreshold", 0.1);
67 const double maximumChargeRate = readParameterValue(v, SUMO_ATTR_MAXIMUMCHARGERATE, "battery.maximumChargeRate", 150000.);
68 const std::string chargeLevelTable = v.getStringParam("device.battery.chargeLevelTable");
69 const std::string chargeCurveTable = v.getStringParam("device.battery.chargeCurveTable");
70
71 // battery constructor
72 MSDevice_Battery* device = new MSDevice_Battery(v, "battery_" + v.getID(),
73 actualBatteryCapacity, maximumBatteryCapacity, stoppingThreshold, maximumChargeRate, chargeLevelTable, chargeCurveTable);
74
75 // Add device to vehicle
76 into.push_back(device);
77
78 if (sf != nullptr) {
79 sf->setBattery(device);
80 }
81 // ensure that parameters are initialized
83 }
84}
85
86
87double
88MSDevice_Battery::readParameterValue(SUMOVehicle& v, const SumoXMLAttr& attr, const std::string& paramName, double defaultVal) {
89 const std::string& oldParam = toString(attr);
90 const SUMOVTypeParameter& typeParams = v.getVehicleType().getParameter();
91 if (v.getParameter().hasParameter(oldParam) || typeParams.hasParameter(oldParam)) {
92 WRITE_WARNINGF(TL("Battery device in vehicle '%' still uses old parameter '%'. Please update to 'device.%'."), v.getID(), oldParam, paramName);
93 if (v.getParameter().getParameter(oldParam, "-") == "-") {
94 return typeParams.getDouble(oldParam, defaultVal);
95 }
96 return StringUtils::toDouble(v.getParameter().getParameter(oldParam, "0"));
97 }
98 return v.getFloatParam("device." + paramName, false, defaultVal);
99}
100
101
102// ---------------------------------------------------------------------------
103// MSDevice_Battery-methods
104// ---------------------------------------------------------------------------
105MSDevice_Battery::MSDevice_Battery(SUMOVehicle& holder, const std::string& id, const double actualBatteryCapacity, const double maximumBatteryCapacity,
106 const double stoppingThreshold, const double maximumChargeRate, const std::string& chargeLevelTable, const std::string& chargeCurveTable) :
107 MSVehicleDevice(holder, id),
108 myActualBatteryCapacity(0), // [actualBatteryCapacity <= maximumBatteryCapacity]
109 myMaximumBatteryCapacity(0), // [maximumBatteryCapacity >= 0]
110 myStoppingThreshold(0), // [stoppingThreshold >= 0]
111 myMaximumChargeRate(0),
112 myChargeLimit(-1),
113 myLastAngle(std::numeric_limits<double>::infinity()),
114 myChargingStopped(false), // Initially vehicle don't charge stopped
115 myChargingInTransit(false), // Initially vehicle don't charge in transit
116 myChargingStartTime(0), // Initially charging start time (must be if the vehicle was launched at the charging station)
117 myConsum(0), // Initially the vehicle is stopped and therefore the consum is zero.
118 myTotalConsumption(0.0),
119 myTotalRegenerated(0.0),
120 myActChargingStation(nullptr), // Initially the vehicle isn't over a Charging Station
121 myPreviousNeighbouringChargingStation(nullptr), // Initially the vehicle wasn't over a Charging Station
122 myEnergyCharged(0), // Initially the energy charged is zero
123 myVehicleStopped(0),
124 myDepletedCount(0) {
125 // Initially the vehicle is stopped and the corresponding variable is 0
126
127 if (maximumBatteryCapacity < 0) {
128 WRITE_WARNINGF(TL("Battery builder: Vehicle '%' doesn't have a valid value for parameter % (%)."), getID(), toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY), toString(maximumBatteryCapacity));
129 } else {
130 myMaximumBatteryCapacity = maximumBatteryCapacity;
131 }
132
133 if (actualBatteryCapacity > maximumBatteryCapacity) {
134 WRITE_WARNINGF(TL("Battery builder: Vehicle '%' has a % (%) greater than its % (%). A max battery capacity value will be assigned."),
135 getID(), toString(SUMO_ATTR_ACTUALBATTERYCAPACITY), toString(actualBatteryCapacity), toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY), toString(maximumBatteryCapacity));
137 } else {
138 myActualBatteryCapacity = actualBatteryCapacity;
139 }
140
141 if (stoppingThreshold < 0) {
142 WRITE_WARNINGF(TL("Battery builder: Vehicle '%' doesn't have a valid value for parameter % (%)."), getID(), toString(SUMO_ATTR_STOPPINGTHRESHOLD), toString(stoppingThreshold));
143 } else {
144 myStoppingThreshold = stoppingThreshold;
145 }
146
147 myTrackFuel = PollutantsInterface::getFuel(holder.getVehicleType().getEmissionClass()) != "Electricity" && OptionsCont::getOptions().getBool("device.battery.track-fuel");
149 WRITE_WARNINGF(TL("The battery device is active for vehicle '%' but no emission class is set. "
150 "Please consider setting an explicit emission class or battery outputs might be inconsistent with emission outputs!"),
151 holder.getID());
152 }
154
155 if (maximumChargeRate < 0) {
156 WRITE_WARNINGF(TL("Battery builder: Vehicle '%' doesn't have a valid value for parameter % (%)."), getID(), toString(SUMO_ATTR_MAXIMUMCHARGERATE), toString(maximumChargeRate));
157 } else {
158 if (!chargeLevelTable.empty() && !chargeCurveTable.empty()) {
159 LinearApproxHelpers::setPoints(myChargeCurve, chargeLevelTable, chargeCurveTable);
161 } else {
162 myMaximumChargeRate = maximumChargeRate;
163 }
164 }
165}
166
167
170
171
172bool MSDevice_Battery::notifyMove(SUMOTrafficObject& tObject, double /* oldPos */, double /* newPos */, double newSpeed) {
173 if (!tObject.isVehicle()) {
174 return false;
175 }
176 notifyMoveInternal(tObject, 0., TS, 0., newSpeed, 0., 0., 0.);
177 return true;
178}
179
180
181void
183 const double /* frontOnLane */,
184 const double timeOnLane,
185 const double /* meanSpeedFrontOnLane */,
186 const double meanSpeedVehicleOnLane,
187 const double /* travelledDistanceFrontOnLane */,
188 const double /* travelledDistanceVehicleOnLane */,
189 const double /* meanLengthOnLane */) {
190 const SUMOVehicle& veh = static_cast<const SUMOVehicle&>(tObject);
191 // Start vehicleStoppedTimer if the vehicle is stopped. In other case reset timer
192 if (meanSpeedVehicleOnLane < myStoppingThreshold) {
193 // Increase vehicle stopped timer
195 } else {
196 // Reset vehicle Stopped
198 }
199
200 // Update Energy from the battery
202 if (getMaximumBatteryCapacity() != 0) {
204 // no explicit emission class, we fall back to the energy model; a warning has been issued on creation
206 veh.getSlope(), params) * timeOnLane;
207 } else {
210 meanSpeedVehicleOnLane, veh.getAcceleration(),
211 veh.getSlope(), params) * timeOnLane;
212 }
213 if (veh.isParking()) {
214 // recuperation from last braking step is ok but further consumption should cease
215 myConsum = MIN2(myConsum, 0.0);
216 }
217
218 // saturate between 0 and myMaximumBatteryCapacity [Wh]
221 if (myDepletedCount == 1) {
222 WRITE_WARNINGF(TL("Battery of vehicle '%' is depleted, time=%."), veh.getID(), time2string(SIMSTEP));
223 }
224 }
225
226 // Energy lost/gained from vehicle movement (via vehicle energy model) [Wh]
228
229 // Track total energy consumption and regeneration
230 if (myConsum > 0.0) {
232 } else {
234 }
235
236 myLastAngle = veh.getAngle();
237 }
238
239 // Check if vehicle has under their position one charge Station
240 const std::string chargingStationID = MSNet::getInstance()->getStoppingPlaceID(veh.getLane(), veh.getPositionOnLane(), SUMO_TAG_CHARGING_STATION);
241
242 // If vehicle is over a charging station
243 if (chargingStationID != "") {
244 // if the vehicle is almost stopped, or charge in transit is enabled, then charge vehicle
246 const MSParkingArea* pa = cs->getParkingArea();
247 if (((meanSpeedVehicleOnLane < myStoppingThreshold) || cs->getChargeInTransit()) && (pa == nullptr || veh.isParking()) && cs->getChargeType() == myChargeType) {
248 // Set Flags Stopped/intransit to
249 if (meanSpeedVehicleOnLane < myStoppingThreshold) {
250 // vehicle ist almost stopped, then is charging stopped
251 myChargingStopped = true;
252
253 // therefore isn't charging in transit
254 myChargingInTransit = false;
255 } else {
256 // vehicle is moving, and the Charging station allow charge in transit
257 myChargingStopped = false;
258
259 // Therefore charge in transit
260 myChargingInTransit = true;
261 }
262
263 // get pointer to charging station
265
266 // Only update charging start time if vehicle allow charge in transit, or in other case
267 // if the vehicle not allow charge in transit but it's stopped.
268 if ((myActChargingStation->getChargeInTransit()) || (meanSpeedVehicleOnLane < myStoppingThreshold)) {
269 // Update Charging start time
271 }
272
273 // time it takes the vehicle at the station < charging station time delay?
275 // Enable charging vehicle
277
278 // Calulate energy charged
280
281 // Update Battery charge
283 }
284 // add charge value for output to myActChargingStation
286 }
287 // else disable charging vehicle
288 else {
289 cs->setChargingVehicle(false);
290 }
291 // 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)
294 }
296 }
297 // In other case, vehicle will be not charged
298 else {
299 // Disable flags
300 myChargingInTransit = false;
301 myChargingStopped = false;
302
303 // Disable charging vehicle
304 if (myActChargingStation != nullptr) {
306 }
307
308 // Set charging station pointer to NULL
309 myActChargingStation = nullptr;
310
311 // Set energy charged to 0
312 myEnergyCharged = 0;
313
314 // Reset timer
316 }
317}
318
319
320void
324 std::vector<std::string> internals;
325 internals.push_back(toString(myActualBatteryCapacity));
326 internals.push_back(toString(myLastAngle));
327 internals.push_back(toString(myChargingStopped));
328 internals.push_back(toString(myChargingInTransit));
329 internals.push_back(toString(myChargingStartTime));
330 internals.push_back(toString(myTotalConsumption));
331 internals.push_back(toString(myTotalRegenerated));
332 internals.push_back(toString(myEnergyCharged));
333 internals.push_back(toString(myVehicleStopped));
334 internals.push_back(getChargingStationID());
335 std::string prevChargingID = (myPreviousNeighbouringChargingStation == nullptr) ? "NULL" : myPreviousNeighbouringChargingStation->getID();
336 internals.push_back(prevChargingID);
337 internals.push_back(toString(myMaximumChargeRate));
338 out.writeAttr(SUMO_ATTR_STATE, toString(internals));
339 out.closeTag();
340}
341
342
343void
345 std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
347 bis >> myLastAngle;
348 bis >> myChargingStopped;
349 bis >> myChargingInTransit;
350 bis >> myChargingStartTime;
351 bis >> myTotalConsumption;
352 bis >> myTotalRegenerated;
353 bis >> myEnergyCharged;
354 bis >> myVehicleStopped;
355 std::string chargingID;
356 bis >> chargingID;
357 if (chargingID != "NULL") {
359 }
360 std::string prevChargingID;
361 bis >> prevChargingID;
362 if (prevChargingID != "NULL") {
364 }
365 bis >> myMaximumChargeRate;
366}
367
368
369void
370MSDevice_Battery::setActualBatteryCapacity(const double actualBatteryCapacity) {
371 if (actualBatteryCapacity < 0) {
373 } else if (actualBatteryCapacity > myMaximumBatteryCapacity) {
375 } else {
376 myActualBatteryCapacity = actualBatteryCapacity;
377 }
378}
379
380
381void
382MSDevice_Battery::setMaximumBatteryCapacity(const double maximumBatteryCapacity) {
383 if (myMaximumBatteryCapacity < 0) {
384 WRITE_WARNINGF(TL("Trying to set into the battery device of vehicle '%' an invalid % (%)."), getID(), toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY), toString(maximumBatteryCapacity));
385 } else {
386 myMaximumBatteryCapacity = maximumBatteryCapacity;
387 }
388}
389
390
391void
392MSDevice_Battery::setStoppingThreshold(const double stoppingThreshold) {
393 if (stoppingThreshold < 0) {
394 WRITE_WARNINGF(TL("Trying to set into the battery device of vehicle '%' an invalid % (%)."), getID(), toString(SUMO_ATTR_STOPPINGTHRESHOLD), toString(stoppingThreshold));
395 } else {
396 myStoppingThreshold = stoppingThreshold;
397 }
398}
399
400
401void
403 if (chargeRate < 0) {
404 WRITE_WARNINGF(TL("Trying to set into the battery device of vehicle '%' an invalid % (%)."), getID(), toString(SUMO_ATTR_MAXIMUMCHARGERATE), toString(chargeRate));
405 } else {
406 myMaximumChargeRate = chargeRate;
407 }
408}
409
410
411void
413 myChargeLimit = limit;
414}
415
416
417void
421
422
423void
427
428
429void
433
434
435void
439
440
441void
442MSDevice_Battery::setEnergyCharged(const double energyCharged) {
443 myEnergyCharged = energyCharged;
444}
445
446
447double
451
452
453double
457
458
459double
461 return myConsum;
462}
463
464double
468
469
470double
474
475
476bool
480
481
482bool
486
487
492
493
495MSDevice_Battery::estimateChargingDuration(const double toCharge, const double csPower) const {
496 //if (!myChargeCurve.empty()) {
497 // // TODO: integrate charge curve
498 //}
499 return TIME2STEPS(toCharge / MIN2(csPower, myMaximumChargeRate));
500}
501
502
503std::string
505 if (myActChargingStation != nullptr) {
506 return myActChargingStation->getID();
507 } else {
508 return "NULL";
509 }
510}
511
512double
516
517
518int
522
523
524double
528
529
530double
535
536
537bool
539 return myTrackFuel;
540}
541
542
547
548
549std::string
550MSDevice_Battery::getParameter(const std::string& key) const {
552 || key == toString(SUMO_ATTR_CHARGELEVEL)) {
554 } else if (key == toString(SUMO_ATTR_ENERGYCONSUMED)) {
555 return toString(getConsum());
556 } else if (key == "chargePower") {
557 return toString(getEnergyCharged() * 3600.);
558 } else if (key == "usedAverage") {
560 } else if (key == toString(SUMO_ATTR_TOTALENERGYCONSUMED)) {
562 } else if (key == toString(SUMO_ATTR_TOTALENERGYREGENERATED)) {
564 } else if (key == toString(SUMO_ATTR_ENERGYCHARGED)) {
565 return toString(getEnergyCharged());
566 } else if (key == toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY) || key == "capacity") {
568 } else if (key == toString(SUMO_ATTR_MAXIMUMCHARGERATE)) {
570 } else if (key == toString(SUMO_ATTR_CHARGINGSTATIONID)) {
571 return getChargingStationID();
572 }
573 throw InvalidArgument("Parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
574}
575
576
577void
578MSDevice_Battery::setParameter(const std::string& key, const std::string& value) {
579 double doubleValue;
580 try {
581 doubleValue = StringUtils::toDouble(value);
582 } catch (NumberFormatException&) {
583 throw InvalidArgument("Setting parameter '" + key + "' requires a number for device of type '" + deviceName() + "'");
584 }
586 setActualBatteryCapacity(doubleValue);
587 } else if (key == toString(SUMO_ATTR_MAXIMUMBATTERYCAPACITY) || key == "capacity") {
588 setMaximumBatteryCapacity(doubleValue);
589 } else if (key == toString(SUMO_ATTR_MAXIMUMCHARGERATE)) {
590 setMaximumChargeRate(doubleValue);
591 } else {
592 throw InvalidArgument("Setting parameter '" + key + "' is not supported for device of type '" + deviceName() + "'");
593 }
594}
595
596
597void
599 // @note: only charing is performed but no energy is consumed
601 myConsum = 0;
602}
603
604
605void
607 if (tripinfoOut != nullptr) {
608 tripinfoOut->openTag("battery");
609 tripinfoOut->writeAttr("depleted", toString(myDepletedCount));
610 tripinfoOut->writeAttr("actualBatteryCapacity", toString(myActualBatteryCapacity));
611 tripinfoOut->writeAttr("totalEnergyConsumed", toString(myTotalConsumption));
612 tripinfoOut->writeAttr("totalEnergyRegenerated", toString(myTotalRegenerated));
613 tripinfoOut->closeTag();
614 }
615}
616
617
618/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define DEFAULT_CHARGE_RATIO
#define DEFAULT_MAX_CAPACITY
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define TL(string)
Definition MsgHandler.h:304
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:91
#define STEPS2TIME(x)
Definition SUMOTime.h:58
#define SIMSTEP
Definition SUMOTime.h:64
#define TS
Definition SUMOTime.h:45
#define TIME2STEPS(x)
Definition SUMOTime.h:60
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_MAXIMUMCHARGERATE
Maximum Power.
@ SUMO_ATTR_STOPPINGTHRESHOLD
Stopping threshold.
@ SUMO_ATTR_CHARGINGSTATIONID
Charging Station ID.
@ SUMO_ATTR_ACTUALBATTERYCAPACITY
@ 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:80
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
An upper class for objects with additional parameters.
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 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.
ChargeType getChargeType() const
Get charge type.
const MSParkingArea * getParkingArea() const
Get the parking area the charging station is placed on.
Battery device for electric vehicles.
void setEnergyCharged(const double energyCharged)
Set Energy Charged in Wh.
MSChargingStation::ChargeType getChargeType() const
Get the charge type.
SUMOTime getChargingStartTime() const
Get charging start time.
void saveState(OutputDevice &out) const override
Saves the state of the device.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Example-options.
void notifyMoveInternal(const SUMOTrafficObject &tObject, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double meanLengthOnLane) override
Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
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.
const std::string deviceName() const override
return the name for this type of device
double myActualBatteryCapacity
Parameter, The actual vehicles's Battery Capacity in Wh, [myActualBatteryCapacity <= myMaximumBattery...
double getMaximumChargeRate() const
Get current charge rate in W depending on the state of charge.
void setParameter(const std::string &key, const std::string &value) override
try to set the given parameter for this device. Throw exception for unsupported key
void increaseChargingStartTime()
Increase Charging Start time.
MSChargingStation * myPreviousNeighbouringChargingStation
Parameter, Pointer to charging station neighbouring with myActChargingStation in which vehicle was pl...
MSChargingStation::ChargeType myChargeType
the accepted charge type
void notifyParking() override
called to update state for parking vehicles
void loadState(const SUMOSAXAttributes &attrs) override
Loads the state of the device from the given description.
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.
void generateOutput(OutputDevice *tripinfoOut) const override
Called on vehicle deletion to extend tripinfo.
std::string getParameter(const std::string &key) const override
try to retrieve the given parameter from this device. Throw exception for unsupported key
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, which the vehicle has beging to charging.
bool isChargingInTransit() const
Get true if Vehicle it's charging, false if not.
void resetChargingStartTime()
Reset charging start time.
double myTotalConsumption
Parameter, total vehicle energy consumption.
bool notifyMove(SUMOTrafficObject &tObject, double oldPos, double newPos, double newSpeed) override
Checks for waiting steps when the vehicle moves.
void resetVehicleStoppedTimer()
Reset myVehicleStopped.
bool tracksFuel() const
Whether the battery device is actually used as a tank of a combustion vehicle.
int myDepletedCount
Count how many times the vehicle experienced a depleted battery.
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:157
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:200
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:187
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:1489
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition MSNet.cpp:1468
A lane area vehicles can halt at.
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.
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.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
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 const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
double getFloatParam(const std::string &paramName, const bool required=false, const double deflt=INVALID_DOUBLE, bool checkDist=true) const
Retrieve a floating point parameter for the traffic object.
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:63
virtual SUMOTime getDeparture() const =0
Returns this vehicle's real departure time.
virtual bool isParking() const =0
Returns the information whether the vehicle is parked.
virtual EnergyParams * getEmissionParameters() const =0
Returns the vehicle's emission model parameter.
virtual double getAngle() const =0
Get the vehicle's angle.
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