Line data Source code
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 : /****************************************************************************/ 14 : /// @file MSBatteryExport.cpp 15 : /// @author Mario Krumnow 16 : /// @author Tamas Kurczveil 17 : /// @author Pablo Alvarez Lopez 18 : /// @date 20-12-13 19 : /// 20 : // Realises dumping Battery Data 21 : /****************************************************************************/ 22 : #include <config.h> 23 : 24 : #include <microsim/MSEdgeControl.h> 25 : #include <microsim/MSEdge.h> 26 : #include <microsim/MSLane.h> 27 : #include <microsim/MSGlobals.h> 28 : #include <utils/iodevices/OutputDevice.h> 29 : #include <microsim/MSNet.h> 30 : #include <microsim/MSVehicle.h> 31 : #include <microsim/MSVehicleControl.h> 32 : #include <microsim/devices/MSDevice_Battery.h> 33 : #include "MSBatteryExport.h" 34 : 35 : 36 : // =========================================================================== 37 : // method definitions 38 : // =========================================================================== 39 : void 40 97299 : MSBatteryExport::write(OutputDevice& of, SUMOTime timestep, int precision) { 41 97299 : of.openTag(SUMO_TAG_TIMESTEP).writeAttr(SUMO_ATTR_TIME, time2string(timestep)); 42 97299 : of.setPrecision(precision); 43 : 44 97299 : MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl(); 45 : MSVehicleControl::constVehIt it = vc.loadedVehBegin(); 46 : MSVehicleControl::constVehIt end = vc.loadedVehEnd(); 47 361440 : for (; it != end; ++it) { 48 264141 : const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second); 49 : 50 264141 : if (!(veh->isOnRoad() || veh->isParking() || veh->isRemoteControlled())) { 51 924 : continue; 52 : } 53 : 54 263217 : std::string fclass = veh->getVehicleType().getID(); 55 263217 : fclass = fclass.substr(0, fclass.find_first_of("@")); 56 : 57 263217 : if (static_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))) != nullptr) { 58 263217 : MSDevice_Battery* batteryToExport = dynamic_cast<MSDevice_Battery*>(veh->getDevice(typeid(MSDevice_Battery))); 59 263217 : if (batteryToExport->getMaximumBatteryCapacity() > 0) { 60 : // Open Row 61 263217 : of.openTag(SUMO_TAG_VEHICLE); 62 : // Write ID 63 : of.writeAttr(SUMO_ATTR_ID, veh->getID()); 64 : // Write consum 65 263217 : of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, batteryToExport->getConsum()); 66 : // Write total consumption 67 263217 : of.writeAttr(SUMO_ATTR_TOTALENERGYCONSUMED, batteryToExport->getTotalConsumption()); 68 : // Write total regeneration 69 263217 : of.writeAttr(SUMO_ATTR_TOTALENERGYREGENERATED, batteryToExport->getTotalRegenerated()); 70 : // Write Actual battery capacity 71 263217 : of.writeAttr(SUMO_ATTR_ACTUALBATTERYCAPACITY, batteryToExport->getActualBatteryCapacity()); 72 : // Write Maximum battery capacity 73 263217 : of.writeAttr(SUMO_ATTR_MAXIMUMBATTERYCAPACITY, batteryToExport->getMaximumBatteryCapacity()); 74 : // Write Charging Station ID 75 263217 : of.writeAttr(SUMO_ATTR_CHARGINGSTATIONID, batteryToExport->getChargingStationID()); 76 : // Write Charge charged in the Battery 77 263217 : of.writeAttr(SUMO_ATTR_ENERGYCHARGED, batteryToExport->getEnergyCharged()); 78 : // Write ChargeInTransit 79 263217 : if (batteryToExport->isChargingInTransit()) { 80 1662 : of.writeAttr(SUMO_ATTR_ENERGYCHARGEDINTRANSIT, batteryToExport->getEnergyCharged()); 81 : } else { 82 524772 : of.writeAttr(SUMO_ATTR_ENERGYCHARGEDINTRANSIT, 0.00); 83 : } 84 : // Write ChargingStopped 85 263217 : if (batteryToExport->isChargingStopped()) { 86 10138 : of.writeAttr(SUMO_ATTR_ENERGYCHARGEDSTOPPED, batteryToExport->getEnergyCharged()); 87 : } else { 88 516296 : of.writeAttr(SUMO_ATTR_ENERGYCHARGEDSTOPPED, 0.00); 89 : } 90 : // Write Speed 91 263217 : of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed()); 92 : // Write Acceleration 93 263217 : of.writeAttr(SUMO_ATTR_ACCELERATION, veh->getAcceleration()); 94 : 95 263217 : Position pos = veh->getPosition(); 96 526434 : of.writeAttr(SUMO_ATTR_X, veh->getPosition().x()); 97 526434 : of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y()); 98 : 99 : // Write Lane ID / edge ID 100 263217 : if (MSGlobals::gUseMesoSim) { 101 62282 : of.writeAttr(SUMO_ATTR_EDGE, veh->getEdge()->getID()); 102 : } else { 103 200935 : of.writeAttr(SUMO_ATTR_LANE, veh->getLane()->getID()); 104 : } 105 : // Write vehicle position in the lane 106 263217 : of.writeAttr(SUMO_ATTR_POSONLANE, veh->getPositionOnLane()); 107 : // Write Time stopped (In all cases) 108 263217 : of.writeAttr(SUMO_ATTR_TIMESTOPPED, batteryToExport->getVehicleStopped()); 109 : // Close Row 110 526434 : of.closeTag(); 111 : } 112 : } 113 : } 114 97299 : of.closeTag(); 115 97299 : }