SUMO - Simulation of Urban MObility
MSBatteryExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Realises dumping Battery Data
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <microsim/MSEdgeControl.h>
34 #include <microsim/MSEdge.h>
35 #include <microsim/MSLane.h>
36 #include <microsim/MSGlobals.h>
38 #include "MSBatteryExport.h"
39 #include <microsim/MSNet.h>
40 #include <microsim/MSVehicle.h>
42 
43 #ifdef HAVE_MESOSIM
44 #include <mesosim/MELoop.h>
45 #include <mesosim/MESegment.h>
46 #endif
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 void
57 MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
59  of.setPrecision(precision);
60 
64  for (; it != end; ++it) {
65  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
66 
67  if (!veh->isOnRoad()) {
68  continue;
69  }
70 
71  std::string fclass = veh->getVehicleType().getID();
72  fclass = fclass.substr(0, fclass.find_first_of("@"));
73 
75 
76  if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != 0) {
77 
78  MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
79 
80  if (batteryToExport->getMaximumBatteryCapacity() > 0) {
81  // Open Row
82  of.openTag("vehicle");
83 
84  // Write ID
85  of.writeAttr("id", veh->getID());
86 
87  // Write consum
88  of.writeAttr("energyConsumed", batteryToExport->getConsum());
89 
90  // Write ActBatKap
91  of.writeAttr("actualBatteryCapacity", batteryToExport->getActualBatteryCapacity());
92 
93  // Write MaxBatKap
94  of.writeAttr("maximumBatteryCapacity", batteryToExport->getMaximumBatteryCapacity());
95 
96  // Write Charging Station ID
97  of.writeAttr("chargingStationId", batteryToExport->getChargingStationID());
98 
99  // Write Charge charged in the Battery
100  of.writeAttr("energyCharged", batteryToExport->getChrgEnergy());
101 
102  // Write ChargeInTransit
103  if (batteryToExport->isChargingInTransit()) {
104  of.writeAttr("energyChargedInTransit", batteryToExport->getChrgEnergy());
105  } else {
106  of.writeAttr("energyChargedInTransit", 0.00);
107  }
108 
109  // Write ChargingStopped
110  if (batteryToExport->isChargingStopped()) {
111  of.writeAttr("energyChargedStopped", batteryToExport->getChrgEnergy());
112  } else {
113  of.writeAttr("energyChargedStopped", 0.00);
114  }
115 
116  // Write Speed
117  of.writeAttr("speed", veh->getSpeed());
118 
119  // Write Acceleration
120  of.writeAttr("acceleration", veh->getAcceleration());
121 
122  // Write pos x
123  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
124 
125  // Write pos y
126  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
127 
128  // Write Lane ID
129  of.writeAttr("lane", veh->getLane()->getID());
130 
131  // Write vehicle position in the lane
132  of.writeAttr("posOnLane", veh->getPositionOnLane());
133 
134  // Write Time stopped (In all cases)
135  of.writeAttr("timeStopped", batteryToExport->getVehicleStopped());
136 
137  // Close Row
138  of.closeTag();
139  }
140  }
141  }
142  of.closeTag();
143 }
bool isChargingStopped() const
Get parameter 15, true if Vehicle it&#39;s charging, false if not.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOReal getConsum() const
Get parameter 18, consum (Strange error with linker)
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Position getPosition(const SUMOReal offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:617
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:162
int getVehicleStopped() const
Get parameter 20, charging energy.
SUMOReal getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:286
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
const std::string & getID() const
Returns the id.
Definition: Named.h:65
void setPrecision(unsigned int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:308
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
SUMOReal getActualBatteryCapacity() const
Get parameter 01, the actual vehicles&#39; Battery Capacity in kWh.
bool isChargingInTransit() const
Get parameter 16, true if Vehicle it&#39;s charging, false if not.
SUMOReal getChrgEnergy() const
Get parameter 20, charging energy.
The battery parametereter.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
SUMOReal getAcceleration() const
Returns the vehicle&#39;s acceleration in m/s.
Definition: MSVehicle.h:302
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
Definition: MSBaseVehicle.h:93
const std::string & getID() const
Returns the name of the vehicle type.
SUMOReal getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:294
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:323
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
The class responsible for building and deletion of vehicles.
SUMOReal getMaximumBatteryCapacity() const
Get parameter 02, the total vehicles&#39; Battery Capacity in kWh.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:339
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:331
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const std::string & getChargingStationID() const
Get parameter 19, Charging Station I.
const std::string & getID() const
Returns the name of the vehicle.