Eclipse SUMO - Simulation of Urban MObility
MSElecHybridExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2012-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 // Realises dumping Electric hybrid vehicle data
20 /****************************************************************************/
21 #include <config.h>
22 
23 #include <microsim/MSEdgeControl.h>
24 #include <microsim/MSEdge.h>
25 #include <microsim/MSLane.h>
26 #include <microsim/MSGlobals.h>
28 #include <microsim/MSNet.h>
29 #include <microsim/MSVehicle.h>
32 #include "MSElecHybridExport.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 void
41  of.setPrecision(precision);
42 
44  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
45 
46  const SUMOVehicle* veh = it->second;
47  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
48 
49  if (!veh->isOnRoad()) {
50  continue;
51  }
52 
53  std::string fclass = veh->getVehicleType().getID();
54  fclass = fclass.substr(0, fclass.find_first_of("@"));
55 
56  if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != 0) {
57  MSDevice_ElecHybrid* elecHybridToExport = dynamic_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid)));
58  if (elecHybridToExport->getMaximumBatteryCapacity() > 0) {
59  // Open Row
61  // Write ID
62  of.writeAttr(SUMO_ATTR_ID, veh->getID());
63 
64  // Write Maximum battery capacity
66  // Write Actual battery capacity
68 
69  // Write consumed energy [Wh] (computed by HelpersEnergy::compute)
70  of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, elecHybridToExport->getConsum());
71  // Write Energy charged in the Battery [Wh] (drawn energy from overhead wire minus consumed energy)
72  of.writeAttr(SUMO_ATTR_ENERGYCHARGED, elecHybridToExport->getEnergyCharged());
73  // Write Power demand (requsted from overhed wire) [W]
74  of.writeAttr(SUMO_ATTR_CHARGINGPOWER, elecHybridToExport->getPowerWanted());
75 
76  // Write OverheadWire Segment ID
78  // Write Traction Substation ID
80 
81  // Write current from overheadwire
83  // Write voltage of overheadwire
85  // Write circuit alpha best (1 if the traction substation is not overloaded, number from interval [0,1) if the traction substation is overloaded, NAN if it is not applicable)
86  of.writeAttr(SUMO_ATTR_ALPHACIRCUITSOLVER, elecHybridToExport->getCircuitAlpha());
87 
88  // Write Speed
90  // Write Acceleration
92  // Write Distance
94  // Write pos x
95  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
96  // Write pos y
97  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
98  // Write pos z
99  of.writeAttr(SUMO_ATTR_Z, veh->getPosition().z());
100  // Write slope
101  of.writeAttr(SUMO_ATTR_SLOPE, veh->getSlope());
102  if (microVeh != nullptr) {
103  // Write Lane ID
104  of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
105  }
106  // Write vehicle position in the lane
108  // Close Row
109  of.closeTag();
110  }
111  }
112  }
113  of.closeTag();
114 }
115 
116 
117 void
118 MSElecHybridExport::write(OutputDevice& of, const SUMOVehicle* veh, SUMOTime timestep, int precision) {
120  of.setPrecision(precision);
121 
122  if (!veh->isOnRoad()) {
123  return;
124  }
125 
126  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
127 
128  if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != nullptr) {
129  MSDevice_ElecHybrid* elecHybridToExport = dynamic_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid)));
130  // Write Actual battery capacity
132 
133  // Write consumed energy [Wh] (computed by HelpersEnergy::compute)
134  of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, elecHybridToExport->getConsum());
135  // Write Energy charged in the Battery [Wh] (drawn energy from overhead wire minus consumed energy)
136  of.writeAttr(SUMO_ATTR_ENERGYCHARGED, elecHybridToExport->getEnergyCharged());
137  // Write Power demand (requsted from overhed wire) [W]
138  of.writeAttr(SUMO_ATTR_CHARGINGPOWER, elecHybridToExport->getPowerWanted());
139 
140  // Write OverheadWire Segment ID
142  // Write Traction Substation ID
144 
145  // Write current from overheadwire
147  // Write voltage of overheadwire
149  // Write circuit alpha best (1 if the traction substation is not overloaded, number from interval [0,1) if the traction substation is overloaded, NAN if it is not applicable)
150  of.writeAttr(SUMO_ATTR_ALPHACIRCUITSOLVER, elecHybridToExport->getCircuitAlpha());
151 
152  // Write Speed
153  of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed());
154  // Write Acceleration
156  // Write Distance
158  // Write pos x
159  of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
160  // Write pos y
161  of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
162  // Write pos z
163  of.writeAttr(SUMO_ATTR_Z, veh->getPosition().z());
164  // Write slope
165  of.writeAttr(SUMO_ATTR_SLOPE, veh->getSlope());
166  // Write Lane ID
167  if (microVeh != 0) {
168  of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
169  }
170  // Write vehicle position in the lane
172  }
173  of.closeTag();
174 }
long long int SUMOTime
Definition: GUI.h:35
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
@ SUMO_TAG_TIMESTEP
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_ATTR_TRACTIONSUBSTATIONID
@ SUMO_ATTR_LANE
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_ENERGYCONSUMED
Energy consumed.
@ SUMO_ATTR_Y
@ SUMO_ATTR_Z
@ SUMO_ATTR_POSONLANE
Position on lane.
@ SUMO_ATTR_X
@ SUMO_ATTR_MAXIMUMBATTERYCAPACITY
Maxium battery capacity.
@ SUMO_ATTR_SLOPE
@ SUMO_ATTR_ACCELERATION
@ SUMO_ATTR_ACTUALBATTERYCAPACITY
@ SUMO_ATTR_ENERGYCHARGED
tgotal of Energy charged
@ SUMO_ATTR_DISTANCE
@ SUMO_ATTR_CHARGINGPOWER
@ SUMO_ATTR_ID
@ SUMO_ATTR_OVERHEADWIREID
@ SUMO_ATTR_ALPHACIRCUITSOLVER
@ SUMO_ATTR_CURRENTFROMOVERHEADWIRE
@ SUMO_ATTR_VOLTAGEOFOVERHEADWIRE
@ SUMO_ATTR_TIME
trigger: the time of the step
A device which collects info on the vehicle trip (mainly on departure and arrival)
double getCircuitAlpha() const
double getVoltageOfOverheadWire() const
Get actual voltage on the overhead wire segment.
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in kWh.
double getCurrentFromOverheadWire() const
Get actual current in the overhead wire segment.
double getEnergyCharged() const
Get charged energy.
std::string getTractionSubstationID() const
Get actual traction substationn ID.
double getActualBatteryCapacity() const
Get the actual vehicle's Battery Capacity in kWh.
double getConsum() const
Get consum.
std::string getOverheadWireSegmentID() const
Get actual overhead wire segment ID.
static void writeAggregated(OutputDevice &of, SUMOTime timestep, int precision)
static void write(OutputDevice &of, const SUMOVehicle *veh, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:182
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:378
The class responsible for building and deletion of vehicles.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:584
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:91
const std::string & getID() const
Returns the id.
Definition: Named.h:74
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
double x() const
Returns the x-position.
Definition: Position.h:55
double z() const
Returns the z-position.
Definition: Position.h:65
double y() const
Returns the y-position.
Definition: Position.h:60
virtual double getAcceleration() const =0
Returns the object's acceleration.
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual double getSlope() const =0
Returns the slope of the road at object's position in degrees.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
virtual double getOdometer() const =0
Returns the distance that was already driven by this vehicle.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)