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

Generated by: LCOV version 2.0-1