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-2023 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 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)
87
88 // Write Speed
90 // Write Acceleration
92 // Write Distance
93 double distance = NAN;
94 const MSLane* vehicleLane = veh->getLane();
95 if (vehicleLane != nullptr) {
96 if (vehicleLane->isInternal()) {
97 // route edge still points to the edge before the intersection
98 const double normalEnd = (*veh->getCurrentRouteEdge())->getLength();
99 distance = (veh->getRoute().getDistanceBetween(veh->getDepartPos(), normalEnd,
100 veh->getRoute().begin(), veh->getCurrentRouteEdge())
101 + veh->getRoute().getDistanceBetween(normalEnd, veh->getPositionOnLane(),
102 *veh->getCurrentRouteEdge(), &veh->getLane()->getEdge()));
103 } else {
104 distance = veh->getRoute().getDistanceBetween(veh->getDepartPos(), veh->getPositionOnLane(),
105 veh->getRoute().begin(), veh->getCurrentRouteEdge());
106 }
107 }
108 of.writeAttr(SUMO_ATTR_DISTANCE, distance);
109 // Write pos x
110 of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
111 // Write pos y
112 of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
113 // Write pos z
114 of.writeAttr(SUMO_ATTR_Z, veh->getPosition().z());
115 // Write slope
117 if (microVeh != 0) {
118 // Write Lane ID
119 of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
120 }
121 // Write vehicle position in the lane
123 // Close Row
124 of.closeTag();
125 }
126 }
127 }
128 of.closeTag();
129}
130
131
132void
133MSElecHybridExport::write(OutputDevice& of, const SUMOVehicle* veh, SUMOTime timestep, int precision) {
135 of.setPrecision(precision);
136
137 if (!veh->isOnRoad()) {
138 return;
139 }
140
141 const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
142
143 if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != nullptr) {
144 MSDevice_ElecHybrid* elecHybridToExport = dynamic_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid)));
145 // Write Actual battery capacity
147
148 // Write consumed energy [Wh] (computed by HelpersEnergy::compute)
149 of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, elecHybridToExport->getConsum());
150 // Write Energy charged in the Battery [Wh] (drawn energy from overhead wire minus consumed energy)
151 of.writeAttr(SUMO_ATTR_ENERGYCHARGED, elecHybridToExport->getEnergyCharged());
152 // Write Power demand (requsted from overhed wire) [W]
153 of.writeAttr(SUMO_ATTR_CHARGINGPOWER, elecHybridToExport->getPowerWanted());
154
155 // Write OverheadWire Segment ID
157 // Write Traction Substation ID
159
160 // Write current from overheadwire
162 // Write voltage of overheadwire
164 // 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)
165 of.writeAttr(SUMO_ATTR_ALPHACIRCUITSOLVER, elecHybridToExport->getCircuitAlpha());
166
167 // Write Speed
169 // Write Acceleration
171 // Write Distance
172 double distance;
173 const MSLane* vehLane = veh->getLane();
174 if (vehLane) {
175 if (vehLane->isInternal()) {
176 // route edge still points to the edge before the intersection
177 const double normalEnd = (*veh->getCurrentRouteEdge())->getLength();
178 distance = (veh->getRoute().getDistanceBetween(veh->getDepartPos(), normalEnd,
179 veh->getRoute().begin(), veh->getCurrentRouteEdge())
180 + veh->getRoute().getDistanceBetween(normalEnd, veh->getPositionOnLane(),
181 *veh->getCurrentRouteEdge(), &vehLane->getEdge()));
182 } else {
183 distance = veh->getRoute().getDistanceBetween(veh->getDepartPos(), veh->getPositionOnLane(),
184 veh->getRoute().begin(), veh->getCurrentRouteEdge());
185 }
186 } else {
187 // typically a case of macroscopic simulation
188 // @todo Probably we should interpolate the vehicle position here?
189 // @todo Or write out something only in the case that the vehicle leaves the actual segment?
190 distance = NAN;
191 }
192 of.writeAttr(SUMO_ATTR_DISTANCE, distance);
193 // Write pos x
194 of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
195 // Write pos y
196 of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
197 // Write pos z
198 of.writeAttr(SUMO_ATTR_Z, veh->getPosition().z());
199 // Write slope
201 // Write Lane ID
202 if (microVeh != 0) {
203 of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
204 }
205 // Write vehicle position in the lane
207 }
208 of.closeTag();
209}
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 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.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
bool isInternal() const
Definition MSLane.cpp:2456
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:745
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:183
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:380
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes....
Definition MSRoute.cpp:311
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition MSRoute.cpp:73
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.
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 const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getSlope() const =0
Returns the slope of the road at object's position in degrees.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
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 bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual double getDepartPos() const =0
Returns this vehicle's real departure position.
virtual MSVehicleDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or 0.
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual const MSRoute & getRoute() const =0
Returns the current route.