LCOV - code coverage report
Current view: top level - src/microsim/devices - MSDevice_Battery.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 3 3
Test Date: 2025-12-06 15:35:27 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2013-2025 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/LinearApproxHelpers.h>
      29              : #include <utils/common/SUMOTime.h>
      30              : 
      31              : 
      32              : // ===========================================================================
      33              : // class declarations
      34              : // ===========================================================================
      35              : class SUMOVehicle;
      36              : class MSDevice_Emissions;
      37              : class MSDevice_StationFinder;
      38              : 
      39              : 
      40              : // ===========================================================================
      41              : // class definitions
      42              : // ===========================================================================
      43              : /**
      44              :  * @class MSDevice_Battery
      45              :  * @brief Battery device for electric vehicles
      46              :  */
      47              : class MSDevice_Battery : public MSVehicleDevice {
      48              : public:
      49              : 
      50              :     /** @brief Inserts MSDevice_Example-options
      51              :     * @param[filled] oc The options container to add the options to
      52              :     */
      53              :     static void insertOptions(OptionsCont& oc);
      54              : 
      55              :     /** @brief Build devices for the given vehicle, if needed
      56              :     *
      57              :     * The options are read and evaluated whether a example-device shall be built
      58              :     *  for the given vehicle.
      59              :     *
      60              :     * The built device is stored in the given vector.
      61              :     *
      62              :     * @param[in] v The vehicle for which a device may be built
      63              :     * @param[filled] into The vector to store the built device in
      64              :     */
      65              :     static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into, MSDevice_StationFinder* sf);
      66              : 
      67              : public:
      68              :     /// @brief Destructor.
      69              :     ~MSDevice_Battery();
      70              : 
      71              :     /// @name Methods called on vehicle movement / state change, overwriting MSDevice
      72              :     /// @{
      73              :     /** @brief Checks for waiting steps when the vehicle moves
      74              :     *
      75              :     * @param[in] veh Vehicle that asks this reminder.
      76              :     * @param[in] oldPos Position before move.
      77              :     * @param[in] newPos Position after move with newSpeed.
      78              :     * @param[in] newSpeed Moving speed.
      79              :     *
      80              :     * @return True (always).
      81              :     */
      82              :     bool notifyMove(SUMOTrafficObject& veh, double oldPos,  double newPos, double newSpeed) override;
      83              :     /// @}
      84              : 
      85              :     /// @brief return the name for this type of device
      86          885 :     const std::string deviceName() const override {
      87          885 :         return "battery";
      88              :     }
      89              : 
      90              :     /** @brief Saves the state of the device
      91              :      *
      92              :      * @param[in] out The OutputDevice to write the information into
      93              :      */
      94              :     void saveState(OutputDevice& out) const override;
      95              : 
      96              :     /** @brief Loads the state of the device from the given description
      97              :      *
      98              :      * @param[in] attrs XML attributes describing the current state
      99              :      */
     100              :     void loadState(const SUMOSAXAttributes& attrs) override;
     101              : 
     102              :     /// @brief try to retrieve the given parameter from this device. Throw exception for unsupported key
     103              :     std::string getParameter(const std::string& key) const override;
     104              : 
     105              :     /// @brief try to set the given parameter for this device. Throw exception for unsupported key
     106              :     void setParameter(const std::string& key, const std::string& value) override;
     107              : 
     108              :     /// @brief called to update state for parking vehicles
     109              :     void notifyParking() override;
     110              : 
     111              :     /// @brief Called on vehicle deletion to extend tripinfo
     112              :     void generateOutput(OutputDevice* tripinfoOut) const override;
     113              : 
     114              : private:
     115              :     /** @brief Constructor
     116              :     *
     117              :     * @param[in] holder The vehicle that holds this device
     118              :     * @param[in] id The ID of the device
     119              :     * @param[in] actualBatteryCapacity The current battery capacity
     120              :     * @param[in] maximumBatteryCapacity The maximum battery capacity
     121              :     * @param[in] stoppingThreshold The speed below which charging may happen
     122              :     * @param[in] maximumChargeRate The maximum charging rate allowed by the battery control
     123              :     * @param[in] chargeLevelTable The axis values of the charge curve
     124              :     * @param[in] chargeCurveTable The charge curve state of charge values
     125              :     */
     126              :     MSDevice_Battery(SUMOVehicle& holder, const std::string& id, const double actualBatteryCapacity, const double maximumBatteryCapacity,
     127              :                      const double stoppingThreshold, const double maximumChargeRate, const std::string& chargeLevelTable, const std::string& chargeCurveTable);
     128              : 
     129              : public:
     130              :     /// @brief Get the actual vehicle's Battery Capacity in Wh
     131              :     double getActualBatteryCapacity() const;
     132              : 
     133              :     /// @brief Get the total vehicle's Battery Capacity in Wh
     134              :     double getMaximumBatteryCapacity() const;
     135              : 
     136              :     /// @brief Get the maximum power when accelerating
     137              :     double getMaximumPower() const;
     138              : 
     139              :     /// @brief Get true if Vehicle is charging, false if not.
     140              :     bool isChargingStopped() const;
     141              : 
     142              :     /// @brief Get true if Vehicle it's charging, false if not.
     143              :     bool isChargingInTransit() const;
     144              : 
     145              :     /// @brief Get charging start time.
     146              :     SUMOTime getChargingStartTime() const;
     147              : 
     148              :     /// @brief Estimate the charging duration given the current battery state
     149              :     SUMOTime estimateChargingDuration(const double toCharge, const double csPower) const;
     150              : 
     151              :     /// @brief Get consum
     152              :     double getConsum() const;
     153              : 
     154              :     /// @brief Get total consumption
     155              :     double getTotalConsumption() const;
     156              : 
     157              :     /// @brief Get total regenerated
     158              :     double getTotalRegenerated() const;
     159              : 
     160              :     /// @brief Get current Charging Station ID
     161              :     std::string getChargingStationID() const;
     162              : 
     163              :     MSChargingStation* getChargingStation() const {
     164        94072 :         return myActChargingStation;
     165              :     }
     166              : 
     167              :     /// @brief Get charged energy
     168              :     double getEnergyCharged() const;
     169              : 
     170              :     /// @brief Get number of timestep that vehicle is stopped
     171              :     int getVehicleStopped() const;
     172              : 
     173              :     /// @brief Get stopping threshold
     174              :     double getStoppingThreshold() const;
     175              : 
     176              :     /// @brief Get current charge rate in W depending on the state of charge
     177              :     double getMaximumChargeRate() const;
     178              : 
     179              :     /// @brief Whether the battery device is actually used as a tank of a combustion vehicle
     180              :     bool tracksFuel() const;
     181              : 
     182              :     /// @brief Get the charge type
     183              :     MSChargingStation::ChargeType getChargeType() const;
     184              : 
     185              :     /// @brief Set actual vehicle's Battery Capacity in kWh
     186              :     void setActualBatteryCapacity(const double actualBatteryCapacity);
     187              : 
     188              :     /// @brief Set total vehicle's Battery Capacity in kWh
     189              :     void setMaximumBatteryCapacity(const double maximumBatteryCapacity);
     190              : 
     191              :     /// @brief Set vehicle's stopping threshold
     192              :     void setStoppingThreshold(const double stoppingThreshold);
     193              : 
     194              :     /// @brief Set vehicle's stopping threshold
     195              :     void setMaximumChargeRate(const double chargeRate);
     196              : 
     197              :     /// @brief Set (temporary) charge limit
     198              :     void setChargeLimit(const double limit);
     199              : 
     200              :     /// @brief Reset charging start time
     201              :     void resetChargingStartTime();
     202              : 
     203              :     /// @brief Increase Charging Start time
     204              :     void increaseChargingStartTime();
     205              : 
     206              :     /// @brief Reset myVehicleStopped
     207              :     void resetVehicleStoppedTimer();
     208              : 
     209              :     /// @brief Increase myVehicleStopped
     210              :     void increaseVehicleStoppedTimer();
     211              : 
     212              :     /// @brief Set Energy Charged in Wh
     213              :     void setEnergyCharged(const double energyCharged);
     214              : 
     215              : protected:
     216              :     /// @brief Read device parameters from input
     217              :     static double readParameterValue(SUMOVehicle& v, const SumoXMLAttr& attr, const std::string& paramName, double defaultVal);
     218              : 
     219              :     /// @brief Parameter, The actual vehicles's Battery Capacity in Wh, [myActualBatteryCapacity <= myMaximumBatteryCapacity]
     220              :     double myActualBatteryCapacity;
     221              : 
     222              :     /// @brief Parameter, The total vehicles's Battery Capacity in Wh, [myMaximumBatteryCapacity >= 0]
     223              :     double myMaximumBatteryCapacity;
     224              : 
     225              :     /// @brief Parameter, stopping vehicle threshold [myStoppingThreshold >= 0]
     226              :     double myStoppingThreshold;
     227              : 
     228              :     /// @brief Parameter, maximum charge rate in W
     229              :     double myMaximumChargeRate;
     230              : 
     231              :     /// @brief (Temporary) limitation in W of the maximum charge rate = charging strategy result
     232              :     double myChargeLimit;
     233              : 
     234              :     /// @brief Parameter, Vehicle's last angle
     235              :     double myLastAngle;
     236              : 
     237              :     /// @brief Parameter, Flag: Vehicles it's charging stopped (by default is false)
     238              :     bool myChargingStopped;
     239              : 
     240              :     /// @brief Parameter, Flag: Vehicles it's charging in transit (by default is false)
     241              :     bool myChargingInTransit;
     242              : 
     243              :     /// @brief Parameter, Moment, which the vehicle has beging to charging
     244              :     SUMOTime myChargingStartTime;
     245              : 
     246              :     /// @brief Parameter, Vehicle consum during a time step (by default is 0.)
     247              :     double myConsum;
     248              : 
     249              :     /// @brief Parameter, total vehicle energy consumption
     250              :     double myTotalConsumption;
     251              : 
     252              :     /// @brief Parameter, total vehicle energy regeneration
     253              :     double myTotalRegenerated;
     254              : 
     255              :     /// @brief Charge curve data points storage
     256              :     LinearApproxHelpers::LinearApproxMap myChargeCurve;
     257              : 
     258              :     /// @brief Parameter, Pointer to current charging station in which vehicle is placed (by default is NULL)
     259              :     MSChargingStation* myActChargingStation;
     260              : 
     261              :     /// @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)
     262              :     MSChargingStation* myPreviousNeighbouringChargingStation;
     263              : 
     264              :     /// @brief Parameter, Energy charged in each timestep
     265              :     double myEnergyCharged;
     266              : 
     267              :     /// @brief Parameter, How many timestep the vehicle is stopped
     268              :     int myVehicleStopped;
     269              : 
     270              :     /// @brief Count how many times the vehicle experienced a depleted battery
     271              :     int myDepletedCount;
     272              : 
     273              :     /// @brief whether to track fuel consumption instead of electricity
     274              :     bool myTrackFuel;
     275              : 
     276              :     /// @brief the accepted charge type
     277              :     MSChargingStation::ChargeType myChargeType;
     278              : 
     279              : 
     280              : private:
     281              :     /// @brief Invalidated copy constructor.
     282              :     MSDevice_Battery(const MSDevice_Battery&);
     283              : 
     284              :     /// @brief Invalidated assignment operator.
     285              :     MSDevice_Battery& operator=(const MSDevice_Battery&);
     286              : };
        

Generated by: LCOV version 2.0-1