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.org/sumo
3 // Copyright (C) 2001-2020 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 Actual battery capacity
68  // Write Maximum battery capacity
70  // Write Charging Station ID
72  // Write Charge charged in the Battery
73  of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged());
74  // Write ChargeInTransit
75  if (batteryToExport->isChargingInTransit()) {
77  } else {
79  }
80  // Write ChargingStopped
81  if (batteryToExport->isChargingStopped()) {
83  } else {
85  }
86  // Write Speed
88  // Write Acceleration
90 
91  Position pos = veh->getPosition();
92  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
93  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
94 
95  // Write Lane ID / edge ID
97  of.writeAttr(SUMO_ATTR_EDGE, veh->getEdge()->getID());
98  } else {
99  of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
100  }
101  // Write vehicle position in the lane
103  // Write Time stopped (In all cases)
104  of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
105  // Close Row
106  of.closeTag();
107  }
108  }
109  }
110  of.closeTag();
111 }
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:31
@ 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_TIMESTOPPED
Time stopped.
@ SUMO_ATTR_TIME
trigger: the time of the step
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
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.
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 kWh.
int getVehicleStopped() const
Get number of timestep that vehicle is stopped.
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in kWh.
double getConsum() const
Get consum.
bool isChargingInTransit() const
Get true if Vehicle it's charging, false if not.
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:88
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:171
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:371
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:580
bool isRemoteControlled() const
Returns the information whether the vehicle is fully controlled via TraCI.
Definition: MSVehicle.cpp:6112
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:483
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:1122
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:458
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:374
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:550
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:90
const std::string & getID() const
Returns the id.
Definition: Named.h:73
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
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:239
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59