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 "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 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 void
53 MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
55  of.setPrecision(precision);
56 
60  for (; it != end; ++it) {
61  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
62 
63  if (!veh->isOnRoad()) {
64  continue;
65  }
66 
67  std::string fclass = veh->getVehicleType().getID();
68  fclass = fclass.substr(0, fclass.find_first_of("@"));
69 
71 
72  if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != 0) {
73  MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
74  if (batteryToExport->getMaximumBatteryCapacity() > 0) {
75  // Open Row
77  // Write ID
78  of.writeAttr(SUMO_ATTR_ID, veh->getID());
79  // Write consum
80  of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
81  // Write Actual battery capacity
83  // Write Maximum battery capacity
85  // Write Charging Station ID
87  // Write Charge charged in the Battery
88  of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged());
89  // Write ChargeInTransit
90  if (batteryToExport->isChargingInTransit()) {
92  } else {
94  }
95  // Write ChargingStopped
96  if (batteryToExport->isChargingStopped()) {
98  } else {
100  }
101  // Write Speed
102  of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed());
103  // Write Acceleration
105  // Write pos x
106  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
107  // Write pos y
108  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
109  // Write Lane ID
110  of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
111  // Write vehicle position in the lane
113  // Write Time stopped (In all cases)
114  of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
115  // Close Row
116  of.closeTag();
117  }
118  }
119  }
120  of.closeTag();
121 }
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: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:488
double getActualBatteryCapacity() const
Get the actual vehicle&#39;s Battery Capacity in kWh.
double y() const
Returns the y-position.
Definition: Position.h:68
double getPositionOnLane() const
Get the vehicle&#39;s position along the lane.
Definition: MSVehicle.h:375
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:60
double x() const
Returns the x-position.
Definition: Position.h:63
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:158
std::string getChargingStationID() const
Get current Charging Station ID.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:777
const std::string & getID() const
Returns the id.
Definition: Named.h:66
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:510
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:310
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:459
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:71
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:52
The class responsible for building and deletion of vehicles.
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:442
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.