Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Realises dumping Battery Data
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <microsim/MSEdgeControl.h>
26 #include <microsim/MSEdge.h>
27 #include <microsim/MSLane.h>
28 #include <microsim/MSGlobals.h>
30 #include <microsim/MSNet.h>
31 #include <microsim/MSVehicle.h>
34 #include "MSBatteryExport.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 void
41 MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
43  of.setPrecision(precision);
44 
48  for (; it != end; ++it) {
49  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
50 
51  if (!veh->isOnRoad()) {
52  continue;
53  }
54 
55  std::string fclass = veh->getVehicleType().getID();
56  fclass = fclass.substr(0, fclass.find_first_of("@"));
57 
58  if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != nullptr) {
59  MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
60  if (batteryToExport->getMaximumBatteryCapacity() > 0) {
61  // Open Row
63  // Write ID
64  of.writeAttr(SUMO_ATTR_ID, veh->getID());
65  // Write consum
66  of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
67  // Write Actual battery capacity
69  // Write Maximum battery capacity
71  // Write Charging Station ID
73  // Write Charge charged in the Battery
74  of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged());
75  // Write ChargeInTransit
76  if (batteryToExport->isChargingInTransit()) {
78  } else {
80  }
81  // Write ChargingStopped
82  if (batteryToExport->isChargingStopped()) {
84  } else {
86  }
87  // Write Speed
89  // Write Acceleration
91 
92  Position pos = veh->getPosition();
93  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
94  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
95 
96  // Write Lane ID / edge ID
98  of.writeAttr(SUMO_ATTR_EDGE, veh->getEdge()->getID());
99  } else {
100  of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
101  }
102  // Write vehicle position in the lane
104  // Write Time stopped (In all cases)
105  of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
106  // Close Row
107  of.closeTag();
108  }
109  }
110  }
111  of.closeTag();
112 }
SUMO_ATTR_ENERGYCHARGEDSTOPPED
@ SUMO_ATTR_ENERGYCHARGEDSTOPPED
Energy charged stopped.
Definition: SUMOXMLDefinitions.h:523
MSDevice_Battery::getMaximumBatteryCapacity
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in kWh.
Definition: MSDevice_Battery.cpp:353
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:93
SUMO_ATTR_ACCELERATION
@ SUMO_ATTR_ACCELERATION
Definition: SUMOXMLDefinitions.h:892
MSDevice_Battery::getChargingStationID
std::string getChargingStationID() const
Get current Charging Station ID.
Definition: MSDevice_Battery.cpp:389
MSNet.h
SUMO_ATTR_ENERGYCHARGEDINTRANSIT
@ SUMO_ATTR_ENERGYCHARGEDINTRANSIT
Energy charged in transit.
Definition: SUMOXMLDefinitions.h:521
MSVehicle::isOnRoad
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:582
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSDevice_Battery::getEnergyCharged
double getEnergyCharged() const
Get charged energy.
Definition: MSDevice_Battery.cpp:398
SUMO_ATTR_CHARGINGSTATIONID
@ SUMO_ATTR_CHARGINGSTATIONID
Charging Station ID.
Definition: SUMOXMLDefinitions.h:517
MSDevice_Battery::getActualBatteryCapacity
double getActualBatteryCapacity() const
Get the actual vehicle's Battery Capacity in kWh.
Definition: MSDevice_Battery.cpp:347
SUMO_ATTR_TIMESTOPPED
@ SUMO_ATTR_TIMESTOPPED
Time stopped.
Definition: SUMOXMLDefinitions.h:527
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:221
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMO_ATTR_EDGE
@ SUMO_ATTR_EDGE
Definition: SUMOXMLDefinitions.h:423
MSGlobals::gUseMesoSim
static bool gUseMesoSim
Definition: MSGlobals.h:90
SUMO_ATTR_MAXIMUMBATTERYCAPACITY
@ SUMO_ATTR_MAXIMUMBATTERYCAPACITY
Maxium battery capacity.
Definition: SUMOXMLDefinitions.h:483
SUMO_ATTR_SPEED
@ SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:384
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
MSEdge.h
SUMO_ATTR_LANE
@ SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:637
MSDevice_Battery.h
MSVehicleControl::constVehIt
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Definition: MSVehicleControl.h:74
SUMO_ATTR_ENERGYCONSUMED
@ SUMO_ATTR_ENERGYCONSUMED
Energy consumed.
Definition: SUMOXMLDefinitions.h:515
MSVehicle.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
MSBaseVehicle::getEdge
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
Definition: MSBaseVehicle.cpp:181
MSVehicle::getPosition
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:1269
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
MSVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:392
MSVehicleControl::loadedVehEnd
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Definition: MSVehicleControl.h:185
SUMO_ATTR_ACTUALBATTERYCAPACITY
@ SUMO_ATTR_ACTUALBATTERYCAPACITY
Definition: SUMOXMLDefinitions.h:481
OutputDevice.h
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSGlobals.h
SUMO_ATTR_Y
@ SUMO_ATTR_Y
Definition: SUMOXMLDefinitions.h:399
MSDevice_Battery
Battery device for electric vehicles.
Definition: MSDevice_Battery.h:45
MSBaseVehicle::getVehicleType
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:123
MSBatteryExport::write
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
Definition: MSBatteryExport.cpp:41
SUMO_TAG_VEHICLE
@ SUMO_TAG_VEHICLE
description of a vehicle
Definition: SUMOXMLDefinitions.h:119
SUMO_ATTR_TIME
@ SUMO_ATTR_TIME
trigger: the time of the step
Definition: SUMOXMLDefinitions.h:676
SUMO_ATTR_POSONLANE
@ SUMO_ATTR_POSONLANE
Position on lane.
Definition: SUMOXMLDefinitions.h:525
MSDevice_Battery::getConsum
double getConsum() const
Get consum.
Definition: MSDevice_Battery.cpp:365
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:560
MSEdgeControl.h
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
SUMO_TAG_TIMESTEP
@ SUMO_TAG_TIMESTEP
Definition: SUMOXMLDefinitions.h:320
MSBaseVehicle::getID
const std::string & getID() const
Returns the name of the vehicle.
Definition: MSBaseVehicle.cpp:138
MSVehicle::getAcceleration
double getAcceleration() const
Returns the vehicle's acceleration in m/s (this is computed as the last step's mean acceleration in c...
Definition: MSVehicle.h:493
MSBatteryExport.h
MSDevice_Battery::isChargingInTransit
bool isChargingInTransit() const
Get true if Vehicle it's charging, false if not.
Definition: MSDevice_Battery.cpp:377
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:71
MSVehicle::getSpeed
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:476
SUMO_ATTR_ENERGYCHARGED
@ SUMO_ATTR_ENERGYCHARGED
tgotal of Energy charged
Definition: SUMOXMLDefinitions.h:519
MSDevice_Battery::isChargingStopped
bool isChargingStopped() const
Get true if Vehicle is charging, false if not.
Definition: MSDevice_Battery.cpp:371
MSVehicleControl::loadedVehBegin
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Definition: MSVehicleControl.h:177
MSLane.h
MSBaseVehicle::getDevice
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
Definition: MSBaseVehicle.cpp:564
MSVehicleControl.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
SUMO_ATTR_X
@ SUMO_ATTR_X
Definition: SUMOXMLDefinitions.h:398
MSDevice_Battery::getVehicleStopped
int getVehicleStopped() const
Get number of timestep that vehicle is stopped.
Definition: MSDevice_Battery.cpp:404
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:336
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79