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.org/sumo
3 // Copyright (C) 2012-2022 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
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
116  of.writeAttr(SUMO_ATTR_SLOPE, veh->getSlope());
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 
132 void
133 MSElecHybridExport::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
168  of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed());
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
200  of.writeAttr(SUMO_ATTR_SLOPE, veh->getSlope());
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 }
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:32
@ 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.
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
bool isInternal() const
Definition: MSLane.cpp:2122
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:674
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:376
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:291
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:69
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:75
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:552
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:90
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:248
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 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 const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
virtual const MSRoute & getRoute() const =0
Returns the current route.
virtual MSVehicleDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or 0.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual double getDepartPos() const =0
Returns this vehicle's real departure position.