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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Realises dumping Battery Data
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <microsim/MSEdgeControl.h>
33 #include <microsim/MSEdge.h>
34 #include <microsim/MSLane.h>
35 #include <microsim/MSGlobals.h>
37 #include <microsim/MSNet.h>
38 #include <microsim/MSVehicle.h>
41 #include "MSBatteryExport.h"
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 void
48 MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
50  of.setPrecision(precision);
51 
55  for (; it != end; ++it) {
56  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
57 
58  if (!veh->isOnRoad()) {
59  continue;
60  }
61 
62  std::string fclass = veh->getVehicleType().getID();
63  fclass = fclass.substr(0, fclass.find_first_of("@"));
64 
66 
67  if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != 0) {
68  MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
69  if (batteryToExport->getMaximumBatteryCapacity() > 0) {
70  // Open Row
72  // Write ID
73  of.writeAttr(SUMO_ATTR_ID, veh->getID());
74  // Write consum
75  of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
76  // Write Actual battery capacity
78  // Write Maximum battery capacity
80  // Write Charging Station ID
82  // Write Charge charged in the Battery
83  of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged());
84  // Write ChargeInTransit
85  if (batteryToExport->isChargingInTransit()) {
87  } else {
89  }
90  // Write ChargingStopped
91  if (batteryToExport->isChargingStopped()) {
93  } else {
95  }
96  // Write Speed
98  // Write Acceleration
100  // Write pos x
101  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
102  // Write pos y
103  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
104  // Write Lane ID
105  of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
106  // Write vehicle position in the lane
108  // Write Time stopped (In all cases)
109  of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
110  // Close Row
111  of.closeTag();
112  }
113  }
114  }
115  of.closeTag();
116 }
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
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:564
double getActualBatteryCapacity() const
Get the actual vehicle&#39;s Battery Capacity in kWh.
double y() const
Returns the y-position.
Definition: Position.h:67
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:402
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
double x() const
Returns the x-position.
Definition: Position.h:62
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:167
std::string getChargingStationID() const
Get current Charging Station ID.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:439
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:901
const std::string & getID() const
Returns the id.
Definition: Named.h:65
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:586
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
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:499
Energy charged stopped.
const std::string & getID() const
Returns the name of the vehicle type.
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:70
bool closeTag()
Closes the most recently opened tag.
bool isChargingInTransit() const
Get true if Vehicle it&#39;s charging, false if not.
double getConsum() const
Get consum.
long long int SUMOTime
Definition: TraCIDefs.h:51
The class responsible for building and deletion of vehicles.
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:482
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.