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 /****************************************************************************/
17 // Realises dumping Battery Data
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <microsim/MSEdgeControl.h>
27 #include <microsim/MSEdge.h>
28 #include <microsim/MSLane.h>
29 #include <microsim/MSGlobals.h>
31 #include <microsim/MSNet.h>
32 #include <microsim/MSVehicle.h>
35 #include "MSBatteryExport.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 void
42 MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
44  of.setPrecision(precision);
45 
49  for (; it != end; ++it) {
50  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
51 
52  if (!veh->isOnRoad()) {
53  continue;
54  }
55 
56  std::string fclass = veh->getVehicleType().getID();
57  fclass = fclass.substr(0, fclass.find_first_of("@"));
58 
59  if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != nullptr) {
60  MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
61  if (batteryToExport->getMaximumBatteryCapacity() > 0) {
62  // Open Row
64  // Write ID
65  of.writeAttr(SUMO_ATTR_ID, veh->getID());
66  // Write consum
67  of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
68  // Write Actual battery capacity
70  // Write Maximum battery capacity
72  // Write Charging Station ID
74  // Write Charge charged in the Battery
75  of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged());
76  // Write ChargeInTransit
77  if (batteryToExport->isChargingInTransit()) {
79  } else {
81  }
82  // Write ChargingStopped
83  if (batteryToExport->isChargingStopped()) {
85  } else {
87  }
88  // Write Speed
90  // Write Acceleration
92 
93  Position pos = veh->getPosition();
94  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
95  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
96 
97  // Write Lane ID / edge ID
99  of.writeAttr(SUMO_ATTR_EDGE, veh->getEdge()->getID());
100  } else {
101  of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
102  }
103  // Write vehicle position in the lane
105  // Write Time stopped (In all cases)
106  of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
107  // Close Row
108  of.closeTag();
109  }
110  }
111  }
112  of.closeTag();
113 }
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:94
SUMO_ATTR_ACCELERATION
Definition: SUMOXMLDefinitions.h:889
MSDevice_Battery::getChargingStationID
std::string getChargingStationID() const
Get current Charging Station ID.
Definition: MSDevice_Battery.cpp:389
MSNet.h
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:583
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
MSDevice_Battery::getEnergyCharged
double getEnergyCharged() const
Get charged energy.
Definition: MSDevice_Battery.cpp:398
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
Time stopped.
Definition: SUMOXMLDefinitions.h:527
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:222
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMO_ATTR_EDGE
Definition: SUMOXMLDefinitions.h:424
MSGlobals::gUseMesoSim
static bool gUseMesoSim
Definition: MSGlobals.h:91
SUMO_ATTR_MAXIMUMBATTERYCAPACITY
Maxium battery capacity.
Definition: SUMOXMLDefinitions.h:483
SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:385
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
MSEdge.h
SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:635
MSDevice_Battery.h
MSVehicleControl::constVehIt
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Definition: MSVehicleControl.h:75
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:254
MSBaseVehicle::getEdge
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
Definition: MSBaseVehicle.cpp:170
MSVehicle::getPosition
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
Definition: MSVehicle.cpp:1280
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
MSVehicle::getPositionOnLane
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:397
MSVehicleControl::loadedVehEnd
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Definition: MSVehicleControl.h:186
SUMO_ATTR_ACTUALBATTERYCAPACITY
Definition: SUMOXMLDefinitions.h:481
OutputDevice.h
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
MSGlobals.h
SUMO_ATTR_Y
Definition: SUMOXMLDefinitions.h:400
MSDevice_Battery
Battery device for electric vehicles.
Definition: MSDevice_Battery.h:46
MSBaseVehicle::getVehicleType
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:118
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:42
SUMO_TAG_VEHICLE
description of a vehicle
Definition: SUMOXMLDefinitions.h:120
SUMO_ATTR_TIME
trigger: the time of the step
Definition: SUMOXMLDefinitions.h:673
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:561
MSEdgeControl.h
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:240
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
SUMO_TAG_TIMESTEP
Definition: SUMOXMLDefinitions.h:321
MSBaseVehicle::getID
const std::string & getID() const
Returns the name of the vehicle.
Definition: MSBaseVehicle.cpp:137
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:494
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:72
MSVehicle::getSpeed
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:477
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:178
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:532
MSVehicleControl.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
SUMO_ATTR_X
Definition: SUMOXMLDefinitions.h:399
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:337
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80