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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Realises dumping Battery Data
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <microsim/MSEdgeControl.h>
27 #include <microsim/MSEdge.h>
28 #include <microsim/MSLane.h>
29 #include <microsim/MSGlobals.h>
31 #include <microsim/MSNet.h>
32 #include <microsim/MSVehicle.h>
35 #include "MSBatteryExport.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 void
42 MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
44  of.setPrecision(precision);
45 
49  for (; it != end; ++it) {
50  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
51 
52  if (!veh->isOnRoad()) {
53  continue;
54  }
55 
56  std::string fclass = veh->getVehicleType().getID();
57  fclass = fclass.substr(0, fclass.find_first_of("@"));
58 
59  if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != nullptr) {
60  MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
61  if (batteryToExport->getMaximumBatteryCapacity() > 0) {
62  // Open Row
64  // Write ID
65  of.writeAttr(SUMO_ATTR_ID, veh->getID());
66  // Write consum
67  of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
68  // Write Actual battery capacity
70  // Write Maximum battery capacity
72  // Write Charging Station ID
74  // Write Charge charged in the Battery
75  of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged());
76  // Write ChargeInTransit
77  if (batteryToExport->isChargingInTransit()) {
79  } else {
81  }
82  // Write ChargingStopped
83  if (batteryToExport->isChargingStopped()) {
85  } else {
87  }
88  // Write Speed
90  // Write Acceleration
92 
93  Position pos = veh->getPosition();
94  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
95  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
96 
97  // Write Lane ID / edge ID
99  of.writeAttr(SUMO_ATTR_EDGE, veh->getEdge()->getID());
100  } else {
101  of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
102  }
103  // Write vehicle position in the lane
105  // Write Time stopped (In all cases)
106  of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
107  // Close Row
108  of.closeTag();
109  }
110  }
111  }
112  of.closeTag();
113 }
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
double getMaximumBatteryCapacity() const
Get the total vehicle&#39;s Battery Capacity in kWh.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:565
double getActualBatteryCapacity() const
Get the actual vehicle&#39;s Battery Capacity in kWh.
double y() const
Returns the y-position.
Definition: Position.h:62
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:403
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
double x() const
Returns the x-position.
Definition: Position.h:57
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
tgotal of Energy charged
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
std::string getChargingStationID() const
Get current Charging Station ID.
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:1126
const std::string & getID() const
Returns the id.
Definition: Named.h:78
int getVehicleStopped() const
Get number of timestep that vehicle is stopped.
bool isChargingStopped() const
Get true if Vehicle is charging, false if not.
Position on lane.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:587
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:316
Energy charged in transit.
double getEnergyCharged() const
Get charged energy.
trigger: the time of the step
Battery device for electric vehicles.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;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.
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
double getAcceleration() const
Returns the vehicle&#39;s acceleration in m/s (this is computed as the last step&#39;s mean acceleration in c...
Definition: MSVehicle.h:500
Energy charged stopped.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
description of a vehicle
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
bool isChargingInTransit() const
Get true if Vehicle it&#39;s charging, false if not.
double getConsum() const
Get consum.
The class responsible for building and deletion of vehicles.
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:483
const std::string & getID() const
Returns the name of the vehicle.
static bool gUseMesoSim
Definition: MSGlobals.h:91
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.