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-2017 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 <microsim/MSNet.h>
39 #include <microsim/MSVehicle.h>
42 #include "MSBatteryExport.h"
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 void
49 MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
51  of.setPrecision(precision);
52 
56  for (; it != end; ++it) {
57  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
58 
59  if (!veh->isOnRoad()) {
60  continue;
61  }
62 
63  std::string fclass = veh->getVehicleType().getID();
64  fclass = fclass.substr(0, fclass.find_first_of("@"));
65 
67 
68  if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != 0) {
69  MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
70  if (batteryToExport->getMaximumBatteryCapacity() > 0) {
71  // Open Row
73  // Write ID
74  of.writeAttr(SUMO_ATTR_ID, veh->getID());
75  // Write consum
76  of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
77  // Write Actual battery capacity
79  // Write Maximum battery capacity
81  // Write Charging Station ID
83  // Write Charge charged in the Battery
84  of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged());
85  // Write ChargeInTransit
86  if (batteryToExport->isChargingInTransit()) {
88  } else {
90  }
91  // Write ChargingStopped
92  if (batteryToExport->isChargingStopped()) {
94  } else {
96  }
97  // Write Speed
99  // Write Acceleration
101  // Write pos x
102  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
103  // Write pos y
104  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
105  // Write Lane ID
106  of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
107  // Write vehicle position in the lane
109  // Write Time stopped (In all cases)
110  of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
111  // Close Row
112  of.closeTag();
113  }
114  }
115  }
116  of.closeTag();
117 }
double getConsum() const
Get consum.
bool isChargingStopped() const
Get true if Vehicle is charging, false if not.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:261
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:83
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
double getActualBatteryCapacity() const
Get the actual vehicle&#39;s Battery Capacity in kWh.
double x() const
Returns the x-position.
Definition: Position.h:63
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
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:169
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:460
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:806
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:375
int getVehicleStopped() const
Get number of timestep that vehicle is stopped.
Position on lane.
std::string getChargingStationID() const
Get current Charging Station ID.
double getMaximumBatteryCapacity() const
Get the total vehicle&#39;s Battery Capacity in kWh.
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:305
double y() const
Returns the y-position.
Definition: Position.h:68
Energy charged in transit.
double getEnergyCharged() const
Get charged energy.
bool isChargingInTransit() const
Get true if Vehicle it&#39;s charging, false if not.
trigger: the time of the step
Battery device for electric vehicles.
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
Energy charged stopped.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
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.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
description of a vehicle
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
long long int SUMOTime
Definition: TraCIDefs.h:52
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:521
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:499
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const std::string & getID() const
Returns the name of the vehicle.
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:443