Eclipse SUMO - Simulation of Urban MObility
MSBatteryExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-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 // Realises dumping Battery Data
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <microsim/MSEdgeControl.h>
25 #include <microsim/MSEdge.h>
26 #include <microsim/MSLane.h>
27 #include <microsim/MSGlobals.h>
29 #include <microsim/MSNet.h>
30 #include <microsim/MSVehicle.h>
33 #include "MSBatteryExport.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 void
40 MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
42  of.setPrecision(precision);
43 
47  for (; it != end; ++it) {
48  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
49 
50  if (!(veh->isOnRoad() || veh->isParking() || veh->isRemoteControlled())) {
51  continue;
52  }
53 
54  std::string fclass = veh->getVehicleType().getID();
55  fclass = fclass.substr(0, fclass.find_first_of("@"));
56 
57  if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != nullptr) {
58  MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
59  if (batteryToExport->getMaximumBatteryCapacity() > 0) {
60  // Open Row
62  // Write ID
63  of.writeAttr(SUMO_ATTR_ID, veh->getID());
64  // Write consum
65  of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
66  // Write total consumption
68  // Write total regeneration
70  // Write Actual battery capacity
72  // Write Maximum battery capacity
74  // Write Charging Station ID
76  // Write Charge charged in the Battery
77  of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged());
78  // Write ChargeInTransit
79  if (batteryToExport->isChargingInTransit()) {
81  } else {
83  }
84  // Write ChargingStopped
85  if (batteryToExport->isChargingStopped()) {
87  } else {
89  }
90  // Write Speed
92  // Write Acceleration
94 
95  Position pos = veh->getPosition();
96  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
97  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
98 
99  // Write Lane ID / edge ID
101  of.writeAttr(SUMO_ATTR_EDGE, veh->getEdge()->getID());
102  } else {
103  of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
104  }
105  // Write vehicle position in the lane
107  // Write Time stopped (In all cases)
108  of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
109  // Close Row
110  of.closeTag();
111  }
112  }
113  }
114  of.closeTag();
115 }
long long int SUMOTime
Definition: GUI.h:35
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
@ SUMO_TAG_TIMESTEP
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_ATTR_LANE
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_ENERGYCONSUMED
Energy consumed.
@ SUMO_ATTR_ENERGYCHARGEDSTOPPED
Energy charged stopped.
@ SUMO_ATTR_Y
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_POSONLANE
Position on lane.
@ SUMO_ATTR_X
@ SUMO_ATTR_MAXIMUMBATTERYCAPACITY
Maxium battery capacity.
@ SUMO_ATTR_CHARGINGSTATIONID
Charging Station ID.
@ SUMO_ATTR_ACCELERATION
@ SUMO_ATTR_ACTUALBATTERYCAPACITY
@ SUMO_ATTR_ENERGYCHARGEDINTRANSIT
Energy charged in transit.
@ SUMO_ATTR_ENERGYCHARGED
tgotal of Energy charged
@ SUMO_ATTR_ID
@ SUMO_ATTR_TOTALENERGYREGENERATED
Total energy regenerated.
@ SUMO_ATTR_TOTALENERGYCONSUMED
Total energy consumed.
@ SUMO_ATTR_TIMESTOPPED
Time stopped.
@ SUMO_ATTR_TIME
trigger: the time of the step
bool isParking() const
Returns whether the vehicle is parking.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists, nullptr otherwise.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
Battery device for electric vehicles.
double getActualBatteryCapacity() const
Get the actual vehicle's Battery Capacity in Wh.
int getVehicleStopped() const
Get number of timestep that vehicle is stopped.
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in Wh.
double getConsum() const
Get consum.
bool isChargingInTransit() const
Get true if Vehicle it's charging, false if not.
double getTotalRegenerated() const
Get total regenerated.
double getTotalConsumption() const
Get total consumption.
double getEnergyCharged() const
Get charged energy.
std::string getChargingStationID() const
Get current Charging Station ID.
bool isChargingStopped() const
Get true if Vehicle is charging, false if not.
static bool gUseMesoSim
Definition: MSGlobals.h:103
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:182
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:378
The class responsible for building and deletion of vehicles.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:608
bool isRemoteControlled() const
Returns the information whether the vehicle is fully controlled via TraCI.
Definition: MSVehicle.cpp:7271
double getAcceleration() const
Returns the vehicle's acceleration in m/s (this is computed as the last step's mean acceleration in c...
Definition: MSVehicle.h:517
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:1242
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:493
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:377
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:584
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:91
const std::string & getID() const
Returns the id.
Definition: Named.h:74
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.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60