Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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
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// ===========================================================================
38void
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 if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != 0) {
54 MSDevice_ElecHybrid* elecHybridToExport = dynamic_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid)));
55 if (elecHybridToExport->getMaximumBatteryCapacity() > 0) {
56 // Open Row
58 // Write ID
59 of.writeAttr(SUMO_ATTR_ID, veh->getID());
60
61 // Write Maximum battery capacity
63 // Write Actual battery capacity
65
66 // Write consumed energy [Wh] (computed by HelpersEnergy::compute)
67 of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, elecHybridToExport->getConsum());
68 // Write Energy charged in the Battery [Wh] (drawn energy from overhead wire minus consumed energy)
69 of.writeAttr(SUMO_ATTR_ENERGYCHARGED, elecHybridToExport->getEnergyCharged());
70 // Write Power demand (requsted from overhed wire) [W]
71 of.writeAttr(SUMO_ATTR_CHARGINGPOWER, elecHybridToExport->getPowerWanted());
72
73 // Write OverheadWire Segment ID
75 // Write Traction Substation ID
77
78 // Write current from overheadwire
80 // Write voltage of overheadwire
82 // 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)
84
85 // Write Speed
87 // Write Acceleration
89 // Write Distance
91 // Write pos x
92 of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
93 // Write pos y
94 of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
95 // Write pos z
96 of.writeAttr(SUMO_ATTR_Z, veh->getPosition().z());
97 // Write slope
99 if (microVeh != nullptr) {
100 // Write Lane ID
101 of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
102 }
103 // Write vehicle position in the lane
105 // Close Row
106 of.closeTag();
107 }
108 }
109 }
110 of.closeTag();
111}
112
113
114void
115MSElecHybridExport::write(OutputDevice& of, const SUMOVehicle* veh, SUMOTime timestep, int precision) {
117 of.setPrecision(precision);
118
119 if (!veh->isOnRoad()) {
120 return;
121 }
122
123 const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
124
125 if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != nullptr) {
126 MSDevice_ElecHybrid* elecHybridToExport = dynamic_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid)));
127 // Write Actual battery capacity
129
130 // Write consumed energy [Wh] (computed by HelpersEnergy::compute)
131 of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, elecHybridToExport->getConsum());
132 // Write Energy charged in the Battery [Wh] (drawn energy from overhead wire minus consumed energy)
133 of.writeAttr(SUMO_ATTR_ENERGYCHARGED, elecHybridToExport->getEnergyCharged());
134 // Write Power demand (requsted from overhed wire) [W]
135 of.writeAttr(SUMO_ATTR_CHARGINGPOWER, elecHybridToExport->getPowerWanted());
136
137 // Write OverheadWire Segment ID
139 // Write Traction Substation ID
141
142 // Write current from overheadwire
144 // Write voltage of overheadwire
146 // 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)
147 of.writeAttr(SUMO_ATTR_ALPHACIRCUITSOLVER, elecHybridToExport->getCircuitAlpha());
148
149 // Write Speed
151 // Write Acceleration
153 // Write Distance
155 // Write pos x
156 of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
157 // Write pos y
158 of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
159 // Write pos z
160 of.writeAttr(SUMO_ATTR_Z, veh->getPosition().z());
161 // Write slope
163 // Write Lane ID
164 if (microVeh != 0) {
165 of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
166 }
167 // Write vehicle position in the lane
169 }
170 of.closeTag();
171}
long long int SUMOTime
Definition GUI.h:36
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 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 substation 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:185
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:581
const std::string & getID() const
Returns the id.
Definition Named.h:74
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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 double getSlope() const =0
Returns the slope of the road at object's position in degrees.
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 getSpeed() const =0
Returns the object's current speed.
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:62
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)