SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) {
58  of.openTag("timestep").writeAttr("time", time2string(timestep));
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  // Get battery
78  MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
79 
80  // Open Row
81  of.openTag("vehicle");
82 
83  // Write ID
84  of.writeAttr("id", veh->getID());
85 
86  // Write consum
87  of.writeAttr("Consum", batteryToExport->getConsum());
88 
89  // Write ActBatKap
90  of.writeAttr("ActBatKap", batteryToExport->getActBatKap());
91 
92  // Write MaxBatKap
93  of.writeAttr("MaxBatKap", batteryToExport->getMaxBatKap());
94 
95  // Write Charging Station ID
96  of.writeAttr("ChrgStnId", batteryToExport->getChrgStnID());
97 
98  // Write Charge charged in the Battery
99  of.writeAttr("Charge", batteryToExport->getChrgEnergy());
100 
101  // Write ChargeInTransit
102  if (batteryToExport->isChargingInTransit()) {
103  of.writeAttr("ChargeInTransit", batteryToExport->getChrgEnergy());
104  } else {
105  of.writeAttr("ChargeInTransit", 0.00);
106  }
107 
108  // Write ChargingStopped
109  if (batteryToExport->isChargingStopped()) {
110  of.writeAttr("ChargeStopped", batteryToExport->getChrgEnergy());
111  } else {
112  of.writeAttr("ChargeStopped", 0.00);
113  }
114 
115  // Write Speed
116  of.writeAttr("speed", veh->getSpeed());
117 
118  // Write Acceleration
119  of.writeAttr("acceleration", veh->getAcceleration());
120 
121  // Write pos x
122  of.writeAttr("x", veh->getPosition().x());
123 
124  // Write pos y
125  of.writeAttr("y", veh->getPosition().y());
126 
127  // Write Lane ID
128  of.writeAttr("lane", veh->getLane()->getID());
129 
130  // Write vehicle position in the lane
131  of.writeAttr("posOnLane", veh->getPositionOnLane());
132 
133  // Write Time stopped (In all cases)
134  of.writeAttr("timeStopped", batteryToExport->getVehicleStopped());
135 
136  /*0
137  1
138  2
139  3
140  4
141  vehiclestoppedÜberein station
142 
143  wielangevehiceladen
144  */
145  // Close Row
146  of.closeTag();
147  }
148  }
149  of.closeTag();
150 
151 }
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
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:597
SUMOReal getActBatKap() const
Get parameter 01, the actual vehicles&#39; Battery Capacity in kWh.
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 getMaxBatKap() const
Get parameter 02, the total vehicles&#39; Battery Capacity in kWh.
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:60
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:304
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
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:90
const std::string & getChrgStnID() const
Get parameter 19, Charging Station I.
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.
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 & getID() const
Returns the name of the vehicle.