40#define DEFAULT_MAX_CAPACITY 35000
41#define DEFAULT_CHARGE_RATIO 0.5
55 oc.
addDescription(
"device.battery.track-fuel",
"Battery",
TL(
"Track fuel consumption for non-electric vehicles"));
68 const std::string chargeLevelTable = v.
getStringParam(
"device.battery.chargeLevelTable");
69 const std::string chargeCurveTable = v.
getStringParam(
"device.battery.chargeCurveTable");
73 actualBatteryCapacity, maximumBatteryCapacity, stoppingThreshold, maximumChargeRate, chargeLevelTable, chargeCurveTable);
76 into.push_back(device);
87 const std::string& oldParam =
toString(attr);
90 WRITE_WARNINGF(
TL(
"Battery device in vehicle '%' still uses old parameter '%'. Please update to 'device.%'."), v.
getID(), oldParam, paramName);
92 return typeParams.
getDouble(oldParam, defaultVal);
96 return v.
getFloatParam(
"device." + paramName,
false, defaultVal);
104 const double stoppingThreshold,
const double maximumChargeRate,
const std::string& chargeLevelTable,
const std::string& chargeCurveTable) :
106 myActualBatteryCapacity(0),
107 myMaximumBatteryCapacity(0),
108 myStoppingThreshold(0),
109 myMaximumChargeRate(0),
111 myLastAngle(
std::numeric_limits<double>::infinity()),
112 myChargingStopped(false),
113 myChargingInTransit(false),
114 myChargingStartTime(0),
116 myTotalConsumption(0.0),
117 myTotalRegenerated(0.0),
118 myActChargingStation(nullptr),
119 myPreviousNeighbouringChargingStation(nullptr),
125 if (maximumBatteryCapacity < 0) {
131 if (actualBatteryCapacity > maximumBatteryCapacity) {
132 WRITE_WARNINGF(
TL(
"Battery builder: Vehicle '%' has a % (%) greater than its % (%). A max battery capacity value will be assigned."),
139 if (stoppingThreshold < 0) {
147 WRITE_WARNINGF(
TL(
"The battery device is active for vehicle '%' but no emission class is set. "
148 "Please consider setting an explicit emission class or battery outputs might be inconsistent with emission outputs!"),
152 if (maximumChargeRate < 0) {
155 if (!chargeLevelTable.empty() && !chargeCurveTable.empty()) {
233 if (chargingStationID !=
"") {
317 std::vector<std::string> internals;
329 internals.push_back(prevChargingID);
348 std::string chargingID;
350 if (chargingID !=
"NULL") {
353 std::string prevChargingID;
354 bis >> prevChargingID;
355 if (prevChargingID !=
"NULL") {
364 if (actualBatteryCapacity < 0) {
386 if (stoppingThreshold < 0) {
396 if (chargeRate < 0) {
544 WRITE_WARNING(
TL(
"Getting the vehicle mass via parameters is deprecated, please use getMass for the vehicle or its type."));
566 WRITE_WARNING(
TL(
"Setting the vehicle mass via parameters is deprecated, please use setMass for the vehicle or its type."));
584 if (tripinfoOut !=
nullptr) {
585 tripinfoOut->
openTag(
"battery");
#define DEFAULT_CHARGE_RATIO
#define DEFAULT_MAX_CAPACITY
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
const long long int VTYPEPARS_EMISSIONCLASS_SET
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ 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_VEHICLEMASS
Vehicle mass.
@ SUMO_ATTR_ENERGYCHARGED
tgotal of Energy charged
@ SUMO_ATTR_TOTALENERGYREGENERATED
Total energy regenerated.
@ SUMO_ATTR_TOTALENERGYCONSUMED
Total energy consumed.
@ SUMO_ATTR_STATE
The state of a link.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
An upper class for objects with additional parameters.
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.
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.
void saveState(OutputDevice &out) const override
Saves the state of the device.
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 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...
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.
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.
const std::string deviceName() const
return the name for this type of device
void resetVehicleStoppedTimer()
Reset myVehicleStopped.
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)
void generateOutput(OutputDevice *tripinfoOut) const
Called on vehicle deletion to extend tripinfo.
~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 ¶mName, 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.
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.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
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.
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
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.
A storage for options typed value containers)
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 ¶mName, 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 ¶mName, const bool required=false, const double deflt=INVALID_DOUBLE) 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.
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