Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2013-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 MSDevice_Battery.h 15 : /// @author Tamas Kurczveil 16 : /// @author Pablo Alvarez Lopez 17 : /// @author Mirko Barthauer 18 : /// @date 20-12-13 19 : /// 20 : // The Battery parameters for the vehicle 21 : /****************************************************************************/ 22 : #pragma once 23 : #include <config.h> 24 : 25 : #include <microsim/devices/MSVehicleDevice.h> 26 : #include <microsim/MSVehicle.h> 27 : #include <microsim/trigger/MSChargingStation.h> 28 : #include <utils/common/SUMOTime.h> 29 : 30 : 31 : // =========================================================================== 32 : // class declarations 33 : // =========================================================================== 34 : class SUMOVehicle; 35 : class MSDevice_Emissions; 36 : class MSDevice_StationFinder; 37 : 38 : 39 : // =========================================================================== 40 : // class definitions 41 : // =========================================================================== 42 : /** 43 : * @class MSDevice_Battery 44 : * @brief Battery device for electric vehicles 45 : */ 46 : class MSDevice_Battery : public MSVehicleDevice { 47 : public: 48 : /** @brief Inserts MSDevice_Example-options 49 : * @param[filled] oc The options container to add the options to 50 : */ 51 : static void insertOptions(OptionsCont& oc); 52 : 53 : /** @brief Build devices for the given vehicle, if needed 54 : * 55 : * The options are read and evaluated whether a example-device shall be built 56 : * for the given vehicle. 57 : * 58 : * The built device is stored in the given vector. 59 : * 60 : * @param[in] v The vehicle for which a device may be built 61 : * @param[filled] into The vector to store the built device in 62 : */ 63 : static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into, MSDevice_StationFinder* sf); 64 : 65 : public: 66 : /// @brief Destructor. 67 : ~MSDevice_Battery(); 68 : 69 : /// @name Methods called on vehicle movement / state change, overwriting MSDevice 70 : /// @{ 71 : /** @brief Checks for waiting steps when the vehicle moves 72 : * 73 : * @param[in] veh Vehicle that asks this reminder. 74 : * @param[in] oldPos Position before move. 75 : * @param[in] newPos Position after move with newSpeed. 76 : * @param[in] newSpeed Moving speed. 77 : * 78 : * @return True (always). 79 : */ 80 : bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed); 81 : /// @} 82 : 83 : /// @brief return the name for this type of device 84 960 : const std::string deviceName() const { 85 960 : return "battery"; 86 : } 87 : 88 : /** @brief Saves the state of the device 89 : * 90 : * @param[in] out The OutputDevice to write the information into 91 : */ 92 : void saveState(OutputDevice& out) const; 93 : 94 : /** @brief Loads the state of the device from the given description 95 : * 96 : * @param[in] attrs XML attributes describing the current state 97 : */ 98 : void loadState(const SUMOSAXAttributes& attrs); 99 : 100 : /// @brief try to retrieve the given parameter from this device. Throw exception for unsupported key 101 : std::string getParameter(const std::string& key) const; 102 : 103 : /// @brief try to set the given parameter for this device. Throw exception for unsupported key 104 : void setParameter(const std::string& key, const std::string& value); 105 : 106 : /// @brief called to update state for parking vehicles 107 : void notifyParking(); 108 : 109 : private: 110 : /** @brief Constructor 111 : * 112 : * @param[in] holder The vehicle that holds this device 113 : * @param[in] id The ID of the device 114 : * @param[in] period The period with which a new route shall be searched 115 : * @param[in] preInsertionPeriod The route search period before insertion 116 : */ 117 : MSDevice_Battery(SUMOVehicle& holder, const std::string& id, const double actualBatteryCapacity, const double maximumBatteryCapacity, 118 : const double stoppingThreshold); 119 : 120 : public: 121 : /// @brief Get the actual vehicle's Battery Capacity in Wh 122 : double getActualBatteryCapacity() const; 123 : 124 : /// @brief Get the total vehicle's Battery Capacity in Wh 125 : double getMaximumBatteryCapacity() const; 126 : 127 : /// @brief Get the maximum power when accelerating 128 : double getMaximumPower() const; 129 : 130 : /// @brief Get true if Vehicle is charging, false if not. 131 : bool isChargingStopped() const; 132 : 133 : /// @brief Get true if Vehicle it's charging, false if not. 134 : bool isChargingInTransit() const; 135 : 136 : /// @brief Get charging start time. 137 : SUMOTime getChargingStartTime() const; 138 : 139 : /// @brief Get consum 140 : double getConsum() const; 141 : 142 : /// @brief Get total consumption 143 : double getTotalConsumption() const; 144 : 145 : /// @brief Get total regenerated 146 : double getTotalRegenerated() const; 147 : 148 : /// @brief Get current Charging Station ID 149 : std::string getChargingStationID() const; 150 : 151 : /// @brief Get charged energy 152 : double getEnergyCharged() const; 153 : 154 : /// @brief Get number of timestep that vehicle is stopped 155 : int getVehicleStopped() const; 156 : 157 : /// @brief Get stopping threshold 158 : double getStoppingThreshold() const; 159 : 160 : /// @brief Set actual vehicle's Battery Capacity in kWh 161 : void setActualBatteryCapacity(const double actualBatteryCapacity); 162 : 163 : /// @brief Set total vehicle's Battery Capacity in kWh 164 : void setMaximumBatteryCapacity(const double maximumBatteryCapacity); 165 : 166 : /// @brief Set vehicle's stopping threshold 167 : void setStoppingThreshold(const double stoppingThreshold); 168 : 169 : /// @brief Reset charging start time 170 : void resetChargingStartTime(); 171 : 172 : /// @brief Increase Charging Start time 173 : void increaseChargingStartTime(); 174 : 175 : /// @brief Reset myVehicleStopped 176 : void resetVehicleStoppedTimer(); 177 : 178 : /// @brief Increase myVehicleStopped 179 : void increaseVehicleStoppedTimer(); 180 : 181 : protected: 182 : /// @brief Read device parameters from input 183 : static double readParameterValue(SUMOVehicle& v, const SumoXMLAttr& attr, const std::string& paramName, double defaultVal); 184 : 185 : /// @brief Parameter, The actual vehicles's Battery Capacity in Wh, [myActualBatteryCapacity <= myMaximumBatteryCapacity] 186 : double myActualBatteryCapacity; 187 : 188 : /// @brief Parameter, The total vehicles's Battery Capacity in Wh, [myMaximumBatteryCapacity >= 0] 189 : double myMaximumBatteryCapacity; 190 : 191 : /// @brief Parameter, stopping vehicle threshold [myStoppingThreshold >= 0] 192 : double myStoppingThreshold; 193 : 194 : /// @brief Parameter, Vehicle's last angle 195 : double myLastAngle; 196 : 197 : /// @brief Parameter, Flag: Vehicles it's charging stopped (by default is false) 198 : bool myChargingStopped; 199 : 200 : /// @brief Parameter, Flag: Vehicles it's charging in transit (by default is false) 201 : bool myChargingInTransit; 202 : 203 : /// @brief Parameter, Moment, wich the vehicle has beging to charging 204 : SUMOTime myChargingStartTime; 205 : 206 : /// @brief Parameter, Vehicle consum during a time step (by default is 0.) 207 : double myConsum; 208 : 209 : /// @brief Parameter, total vehicle energy consumption 210 : double myTotalConsumption; 211 : 212 : /// @brief Parameter, total vehicle energy regeneration 213 : double myTotalRegenerated; 214 : 215 : /// @brief Parameter, Pointer to current charging station in which vehicle is placed (by default is NULL) 216 : MSChargingStation* myActChargingStation; 217 : 218 : /// @brief Parameter, Pointer to charging station neighbouring with myActChargingStation in which vehicle was placed previously (by default is NULL), i.e. auxiliar pointer for disabling charging vehicle from previous (not current) ChargingStation (if there is no gap between two different chargingStations) 219 : MSChargingStation* myPreviousNeighbouringChargingStation; 220 : 221 : /// @brief Parameter, Energy charged in each timestep 222 : double myEnergyCharged; 223 : 224 : /// @brief Parameter, How many timestep the vehicle is stopped 225 : int myVehicleStopped; 226 : 227 : /// @brief whether to track fuel consumption instead of electricity 228 : bool myTrackFuel; 229 : 230 : private: 231 : /// @brief Invalidated copy constructor. 232 : MSDevice_Battery(const MSDevice_Battery&); 233 : 234 : /// @brief Invalidated assignment operator. 235 : MSDevice_Battery& operator=(const MSDevice_Battery&); 236 : };