LCOV - code coverage report
Current view: top level - src/microsim/cfmodels - MSCFModel_CACC.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 17 17 100.0 %
Date: 2024-05-04 15:27:10 Functions: 4 4 100.0 %

          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    MSCFModel_CACC.h
      15             : /// @author  Kallirroi Porfyri
      16             : /// @date    Nov 2018
      17             : ///
      18             : // CACC car-following model based on [1], [2].
      19             : // [1] Milanes, V., and S. E. Shladover. Handling Cut-In Vehicles in Strings
      20             : //    of Cooperative Adaptive Cruise Control Vehicles. Journal of Intelligent
      21             : //     Transportation Systems, Vol. 20, No. 2, 2015, pp. 178-191.
      22             : // [2] Xiao, L., M. Wang and B. van Arem. Realistic Car-Following Models for
      23             : //    Microscopic Simulation of Adaptive and Cooperative Adaptive Cruise
      24             : //     Control Vehicles. Transportation Research Record: Journal of the
      25             : //     Transportation Research Board, No. 2623, 2017. (DOI: 10.3141/2623-01).
      26             : /****************************************************************************/
      27             : #pragma once
      28             : #include <config.h>
      29             : 
      30             : #include "MSCFModel.h"
      31             : #include "MSCFModel_ACC.h"
      32             : #include <utils/xml/SUMOXMLDefinitions.h>
      33             : 
      34             : // ===========================================================================
      35             : // class declarations
      36             : // ===========================================================================
      37             : class MSVehicle;
      38             : class MSVehicleType;
      39             : 
      40             : // ===========================================================================
      41             : // class definitions
      42             : // ===========================================================================
      43             : /** @class MSCFModel_CACC
      44             : * @brief The CACC car-following model
      45             : * @see MSCFModel
      46             : */
      47             : class MSCFModel_CACC : public MSCFModel {
      48             : public:
      49             :     /** @brief Constructor
      50             :      *  @param[in] vtype the type for which this model is built and also the parameter object to configure this model
      51             :      */
      52             : 
      53             :     MSCFModel_CACC(const MSVehicleType* vtype);
      54             : 
      55             :     /// @brief Destructor
      56             :     ~MSCFModel_CACC();
      57             : 
      58             : 
      59             :     /// @name Implementations of the MSCFModel interface
      60             :     /// @{
      61             : 
      62             :     /** @brief Computes the vehicle's safe speed without a leader
      63             :      *
      64             :      * Returns the velocity of the vehicle in dependence to the length of the free street and the target
      65             :      *  velocity at the end of the free range. If onInsertion is true, the vehicle may still brake
      66             :      *  before the next movement.
      67             :      * XXX: Currently only needed to (re-)set "caccVehicleMode" parameter to default value.
      68             :      *
      69             :      * @param[in] veh The vehicle (EGO)
      70             :      * @param[in] speed The vehicle's speed
      71             :      * @param[in] seen The look ahead distance
      72             :      * @param[in] maxSpeed The maximum allowed speed
      73             :      * @param[in] onInsertion whether speed at insertion is asked for
      74             :      * @return EGO's safe speed
      75             :      */
      76             :     double freeSpeed(const MSVehicle* const veh, double speed, double seen,
      77             :                      double maxSpeed, const bool onInsertion = false, const CalcReason usage = CalcReason::CURRENT) const;
      78             : 
      79             :     /** @brief Computes the vehicle's safe speed (no dawdling)
      80             :     * @param[in] veh The vehicle (EGO)
      81             :     * @param[in] speed The vehicle's speed
      82             :     * @param[in] gap2pred The (netto) distance to the LEADER
      83             :     * @param[in] predSpeed The speed of LEADER
      84             :     * @return EGO's safe speed
      85             :     * @see MSCFModel::ffeV
      86             :     */
      87             :     double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed,
      88             :                        double predMaxDecel, const MSVehicle* const pred = 0, const CalcReason usage = CalcReason::CURRENT) const;
      89             : 
      90             : 
      91             :     /** @brief Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
      92             :     * @param[in] veh The vehicle (EGO)
      93             :     * @param[in] gap2pred The (netto) distance to the the obstacle
      94             :     * @return EGO's safe speed for approaching a non-moving obstacle
      95             :     * @see MSCFModel::ffeS
      96             :     * @todo generic Interface, models can call for the values they need
      97             :     */
      98             :     double stopSpeed(const MSVehicle* const veh, const double speed, double gap2pred, double decel, const CalcReason usage = CalcReason::CURRENT) const;
      99             : 
     100             : 
     101             :     /** @brief Returns the a gap such that the gap mode acceleration of the follower is zero
     102             :      * @param[in] veh The vehicle itself, for obtaining other values
     103             :      * @param[in] pred The leader vehicle, for obtaining other values
     104             :      * @param[in] speed EGO's speed
     105             :      * @param[in] leaderSpeed LEADER's speed
     106             :      * @param[in] leaderMaxDecel LEADER's max. deceleration rate
     107             :      */
     108             :     double getSecureGap(const MSVehicle* const veh, const MSVehicle* const pred, const double speed, const double leaderSpeed, const double leaderMaxDecel) const;
     109             : 
     110             :     /** @brief Computes the vehicle's acceptable speed at insertion
     111             :      * @param[in] veh The vehicle (EGO)
     112             :      * @param[in] speed The vehicle's speed
     113             :      * @param[in] gap2pred The (netto) distance to the LEADER
     114             :      * @param[in] predSpeed The speed of LEADER
     115             :      * @return EGO's safe speed
     116             :      */
     117             :     double insertionFollowSpeed(const MSVehicle* const v, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
     118             : 
     119             : 
     120             :     /** @brief Returns the maximum gap at which an interaction between both vehicles occurs
     121             :     *
     122             :     * "interaction" means that the LEADER influences EGO's speed.
     123             :     * @param[in] veh The EGO vehicle
     124             :     * @param[in] vL LEADER's speed
     125             :     * @return The interaction gap
     126             :     * @todo evaluate signature
     127             :     * @see MSCFModel::interactionGap
     128             :     */
     129             :     double interactionGap(const MSVehicle* const, double vL) const;
     130             : 
     131             :     /** @brief Sets a new value for desired headway [s]
     132             :      * @param[in] headwayTime The new desired headway (in s)
     133             :      */
     134        1170 :     void setHeadwayTime(double headwayTime) {
     135        1170 :         myHeadwayTime = headwayTime;
     136        1170 :         myHeadwayTimeACC = headwayTime;
     137             :         acc_CFM.setHeadwayTime(headwayTime);
     138        1170 :     }
     139             : 
     140             :     /**
     141             :      * @brief try to get the given parameter for this carFollowingModel
     142             :      *
     143             :      * @param[in] veh the vehicle from which the parameter must be retrieved
     144             :      * @param[in] key the key of the parameter
     145             :      * @return the value of the requested parameter
     146             :      */
     147             :     virtual std::string getParameter(const MSVehicle* veh, const std::string& key) const;
     148             : 
     149             : 
     150             :     /**
     151             :      * @brief try to set the given parameter for this carFollowingModel
     152             :      *
     153             :      * @param[in] veh the vehicle for which the parameter must be set
     154             :      * @param[in] key the key of the parameter
     155             :      * @param[in] value the value to be set for the given parameter
     156             :      */
     157             :     virtual void setParameter(MSVehicle* veh, const std::string& key, const std::string& value) const;
     158             : 
     159             : 
     160             :     /** @brief Returns the model's name
     161             :     * @return The model's name
     162             :     * @see MSCFModel::getModelName
     163             :     */
     164    49903765 :     int getModelID() const {
     165    49903765 :         return SUMO_TAG_CF_CACC;
     166             :     }
     167             : 
     168             :     /** @brief Returns the maximum velocity the CF-model wants to achieve in the next step
     169             :      * @param[in] maxSpeed The maximum achievable speed in the next step
     170             :      * @param[in] maxSpeedLane The maximum speed the vehicle wants to drive on this lane (Speedlimit*SpeedFactor)
     171             :      */
     172     3897657 :     double maximumLaneSpeedCF(const MSVehicle* const veh, double maxSpeed, double maxSpeedLane) const {
     173     3897657 :         double result = MIN2(maxSpeed, maxSpeedLane);
     174     3897657 :         if (myApplyDriverstate) {
     175       22492 :             applyOwnSpeedPerceptionError(veh, result);
     176             :         }
     177     3897657 :         return result;
     178             :     }
     179             :     /// @}
     180             : 
     181             : 
     182             : 
     183             :     /** @brief Duplicates the car-following model
     184             :     * @param[in] vtype The vehicle type this model belongs to (1:1)
     185             :     * @return A duplicate of this car-following model
     186             :     */
     187             :     MSCFModel* duplicate(const MSVehicleType* vtype) const;
     188             : 
     189        7127 :     virtual MSCFModel::VehicleVariables* createVehicleVariables() const {
     190        7127 :         CACCVehicleVariables* ret = new CACCVehicleVariables();
     191        7127 :         ret->ACC_ControlMode = 0;
     192             :         ret->CACC_ControlMode = 0;
     193             :         ret->CACC_CommunicationsOverrideMode = CACC_NO_OVERRIDE;
     194        7127 :         ret->lastUpdateTime = 0;
     195        7127 :         return ret;
     196             :     }
     197             : 
     198             : 
     199             : private:
     200             :     enum CommunicationsOverrideMode {
     201             :         CACC_NO_OVERRIDE = 0,
     202             :         CACC_MODE_NO_LEADER = 1,
     203             :         CACC_MODE_LEADER_NO_CAV = 2,
     204             :         CACC_MODE_LEADER_CAV = 3
     205             :     };
     206             : 
     207             :     static std::map<std::string, CommunicationsOverrideMode> CommunicationsOverrideModeMap;
     208             : 
     209             :     /// @brief Vehicle mode (default is CACC)
     210             :     /// Switch to ACC mode if CACC_ControlMode = 1 (gap control mode) _and_ leader's CFModel != CACC
     211             :     enum VehicleMode {
     212             :         CC_MODE = 0,
     213             :         ACC_MODE,
     214             :         CACC_GAP_MODE,
     215             :         CACC_GAP_CLOSING_MODE,
     216             :         CACC_COLLISION_AVOIDANCE_MODE
     217             :     };
     218             : 
     219             :     /// @brief Vehicle mode name map
     220             :     static std::map<VehicleMode, std::string> VehicleModeNames;
     221             : 
     222             :     class CACCVehicleVariables : public MSCFModel_ACC::ACCVehicleVariables {
     223             :     public:
     224        7127 :         CACCVehicleVariables() : CACC_ControlMode(0), CACC_CommunicationsOverrideMode(CACC_NO_OVERRIDE) {}
     225             :         /// @brief The vehicle's CACC  precious time step gap error
     226             :         int    CACC_ControlMode;
     227             :         CommunicationsOverrideMode CACC_CommunicationsOverrideMode;
     228             :     };
     229             : 
     230             : private:
     231             :     double _v(const MSVehicle* const veh, const MSVehicle* const pred, const double gap2pred, const double mySpeed,
     232             :               const double predSpeed, const double desSpeed, const bool respectMinGap, const CalcReason usage = CalcReason::CURRENT) const;
     233             : 
     234             :     double speedSpeedControl(const double speed, double vErr, VehicleMode& vehMode) const;
     235             :     double speedGapControl(const MSVehicle* const veh, const double gap2pred,
     236             :                            const double speed, const double predSpeed, const double desSpeed, double vErr,
     237             :                            const MSVehicle* const pred, VehicleMode& vehMode) const;
     238             : 
     239             : private:
     240             :     MSCFModel_ACC acc_CFM;
     241             :     double mySpeedControlGain;
     242             :     double myGapClosingControlGainGap;
     243             :     double myGapClosingControlGainGapDot;
     244             :     double myGapControlGainGap;
     245             :     double myGapControlGainGapDot;
     246             :     double myCollisionAvoidanceGainGap;
     247             :     double myCollisionAvoidanceGainGapDot;
     248             :     double myHeadwayTimeACC;
     249             :     double myApplyDriverstate;
     250             :     double myEmergencyThreshold;
     251             :     double mySpeedControlMinGap;
     252             : 
     253             : private:
     254             :     /// @brief Invalidated assignment operator
     255             :     MSCFModel_CACC& operator=(const MSCFModel_CACC& s);
     256             : };

Generated by: LCOV version 1.14