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 
60 
61  if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != 0) {
62  MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
63  if (batteryToExport->getMaximumBatteryCapacity() > 0) {
64  // Open Row
66  // Write ID
67  of.writeAttr(SUMO_ATTR_ID, veh->getID());
68  // Write consum
69  of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
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  // Write pos x
95  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
96  // Write pos y
97  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
98  // Write Lane ID
99  of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
100  // Write vehicle position in the lane
102  // Write Time stopped (In all cases)
103  of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
104  // Close Row
105  of.closeTag();
106  }
107  }
108  }
109  of.closeTag();
110 }
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:561
double getActualBatteryCapacity() const
Get the actual vehicle&#39;s Battery Capacity in kWh.
double y() const
Returns the y-position.
Definition: Position.h:61
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:399
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
double x() const
Returns the x-position.
Definition: Position.h:56
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:160
std::string getChargingStationID() const
Get current Charging Station ID.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:449
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:932
const std::string & getID() const
Returns the id.
Definition: Named.h:69
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:583
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:309
Energy charged in transit.
double getEnergyCharged() const
Get charged energy.
trigger: the time of the step
Battery device for electric vehicles.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
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.
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:496
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:479
const std::string & getID() const
Returns the name of the vehicle.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.