Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSBatteryExport.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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/****************************************************************************/
20// Realises dumping Battery Data
21/****************************************************************************/
22#include <config.h>
23
25#include <microsim/MSEdge.h>
26#include <microsim/MSLane.h>
27#include <microsim/MSGlobals.h>
29#include <microsim/MSNet.h>
30#include <microsim/MSVehicle.h>
33#include "MSBatteryExport.h"
34
35
36// ===========================================================================
37// method definitions
38// ===========================================================================
39void
40MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
42 of.setPrecision(precision);
43
47 for (; it != end; ++it) {
48 const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
49
50 if (!(veh->isOnRoad() || veh->isParking() || veh->isRemoteControlled())) {
51 continue;
52 }
53
54 if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != nullptr) {
55 MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery)));
56 if (batteryToExport->getMaximumBatteryCapacity() > 0) {
57 // Open Row
59 // Write ID
60 of.writeAttr(SUMO_ATTR_ID, veh->getID());
61 // Write consum
62 of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum());
63 // Write total consumption
65 // Write total regeneration
67 // Write Actual battery capacity
69 // Write Maximum battery capacity
71 // Write Charging Station ID
73 // Write Charge charged in the Battery
75 // Write ChargeInTransit
76 if (batteryToExport->isChargingInTransit()) {
78 } else {
80 }
81 // Write ChargingStopped
82 if (batteryToExport->isChargingStopped()) {
84 } else {
86 }
87 // Write Speed
89 // Write Acceleration
91
92 Position pos = veh->getPosition();
93 of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
94 of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
95
96 // Write Lane ID / edge ID
99 } else {
100 of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID());
101 }
102 // Write vehicle position in the lane
104 // Write Time stopped (In all cases)
105 of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped());
106 // Close Row
107 of.closeTag();
108 }
109 }
110 }
111 of.closeTag();
112}
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_LANE
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_ENERGYCONSUMED
Energy consumed.
@ SUMO_ATTR_ENERGYCHARGEDSTOPPED
Energy charged stopped.
@ SUMO_ATTR_Y
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_POSONLANE
Position on lane.
@ SUMO_ATTR_X
@ SUMO_ATTR_MAXIMUMBATTERYCAPACITY
Maxium battery capacity.
@ SUMO_ATTR_CHARGINGSTATIONID
Charging Station ID.
@ SUMO_ATTR_ACCELERATION
@ SUMO_ATTR_ACTUALBATTERYCAPACITY
@ SUMO_ATTR_ENERGYCHARGEDINTRANSIT
Energy charged in transit.
@ SUMO_ATTR_ENERGYCHARGED
tgotal of Energy charged
@ SUMO_ATTR_ID
@ SUMO_ATTR_TOTALENERGYREGENERATED
Total energy regenerated.
@ SUMO_ATTR_TOTALENERGYCONSUMED
Total energy consumed.
@ SUMO_ATTR_TIMESTOPPED
Time stopped.
@ SUMO_ATTR_TIME
trigger: the time of the step
bool isParking() const
Returns whether the vehicle is parking.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists, nullptr otherwise.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
Battery device for electric vehicles.
double getActualBatteryCapacity() const
Get the actual vehicle's Battery Capacity in Wh.
int getVehicleStopped() const
Get number of timestep that vehicle is stopped.
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in Wh.
double getConsum() const
Get consum.
bool isChargingInTransit() const
Get true if Vehicle it's charging, false if not.
double getTotalRegenerated() const
Get total regenerated.
double getTotalConsumption() const
Get total consumption.
double getEnergyCharged() const
Get charged energy.
std::string getChargingStationID() const
Get current Charging Station ID.
bool isChargingStopped() const
Get true if Vehicle is charging, false if not.
static bool gUseMesoSim
Definition MSGlobals.h:106
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
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition MSVehicle.h:605
bool isRemoteControlled() const
Returns the information whether the vehicle is fully controlled via TraCI.
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:514
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
double getSpeed() const
Returns the vehicle's current speed.
Definition MSVehicle.h:490
double getPositionOnLane() const
Get the vehicle's position along the lane.
Definition MSVehicle.h:374
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.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:55
double y() const
Returns the y-position.
Definition Position.h:60