Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 : #include <utils/xml/SUMOSAXAttributes.h>
34 :
35 : // ===========================================================================
36 : // class declarations
37 : // ===========================================================================
38 : class MSVehicle;
39 : class MSVehicleType;
40 :
41 : // ===========================================================================
42 : // class definitions
43 : // ===========================================================================
44 : /** @class MSCFModel_CACC
45 : * @brief The CACC car-following model
46 : * @see MSCFModel
47 : */
48 : class MSCFModel_CACC : public MSCFModel {
49 : public:
50 : /** @brief Constructor
51 : * @param[in] vtype the type for which this model is built and also the parameter object to configure this model
52 : */
53 :
54 : MSCFModel_CACC(const MSVehicleType* vtype);
55 :
56 : /// @brief Destructor
57 : ~MSCFModel_CACC();
58 :
59 :
60 : /// @name Implementations of the MSCFModel interface
61 : /// @{
62 :
63 : /** @brief Computes the vehicle's safe speed without a leader
64 : *
65 : * Returns the velocity of the vehicle in dependence to the length of the free street and the target
66 : * velocity at the end of the free range. If onInsertion is true, the vehicle may still brake
67 : * before the next movement.
68 : * XXX: Currently only needed to (re-)set "caccVehicleMode" parameter to default value.
69 : *
70 : * @param[in] veh The vehicle (EGO)
71 : * @param[in] speed The vehicle's speed
72 : * @param[in] seen The look ahead distance
73 : * @param[in] maxSpeed The maximum allowed speed
74 : * @param[in] onInsertion whether speed at insertion is asked for
75 : * @return EGO's safe speed
76 : */
77 : double freeSpeed(const MSVehicle* const veh, double speed, double seen,
78 : double maxSpeed, const bool onInsertion = false, const CalcReason usage = CalcReason::CURRENT) const;
79 :
80 : /** @brief Computes the vehicle's safe speed (no dawdling)
81 : * @param[in] veh The vehicle (EGO)
82 : * @param[in] speed The vehicle's speed
83 : * @param[in] gap2pred The (net) distance to the LEADER
84 : * @param[in] predSpeed The speed of LEADER
85 : * @return EGO's safe speed
86 : * @see MSCFModel::ffeV
87 : */
88 : double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed,
89 : double predMaxDecel, const MSVehicle* const pred = 0, const CalcReason usage = CalcReason::CURRENT) const;
90 :
91 :
92 : /** @brief Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
93 : * @param[in] veh The vehicle (EGO)
94 : * @param[in] gap2pred The (net) distance to the obstacle
95 : * @return EGO's safe speed for approaching a non-moving obstacle
96 : * @see MSCFModel::ffeS
97 : * @todo generic Interface, models can call for the values they need
98 : */
99 : double stopSpeed(const MSVehicle* const veh, const double speed, double gap2pred, double decel, const CalcReason usage = CalcReason::CURRENT) const;
100 :
101 :
102 : /** @brief Returns the a gap such that the gap mode acceleration of the follower is zero
103 : * @param[in] veh The vehicle itself, for obtaining other values
104 : * @param[in] pred The leader vehicle, for obtaining other values
105 : * @param[in] speed EGO's speed
106 : * @param[in] leaderSpeed LEADER's speed
107 : * @param[in] leaderMaxDecel LEADER's max. deceleration rate
108 : */
109 : double getSecureGap(const MSVehicle* const veh, const MSVehicle* const pred, const double speed, const double leaderSpeed, const double leaderMaxDecel) const;
110 :
111 : /** @brief Computes the vehicle's acceptable speed at insertion
112 : * @param[in] veh The vehicle (EGO)
113 : * @param[in] speed The vehicle's speed
114 : * @param[in] gap2pred The (net) distance to the LEADER
115 : * @param[in] predSpeed The speed of LEADER
116 : * @return EGO's safe speed
117 : */
118 : double insertionFollowSpeed(const MSVehicle* const v, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
119 :
120 :
121 : /** @brief Returns the maximum gap at which an interaction between both vehicles occurs
122 : *
123 : * "interaction" means that the LEADER influences EGO's speed.
124 : * @param[in] veh The EGO vehicle
125 : * @param[in] vL LEADER's speed
126 : * @return The interaction gap
127 : * @todo evaluate signature
128 : * @see MSCFModel::interactionGap
129 : */
130 : double interactionGap(const MSVehicle* const, double vL) const;
131 :
132 : /** @brief Sets a new value for desired headway [s]
133 : * @param[in] headwayTime The new desired headway (in s)
134 : */
135 912 : void setHeadwayTime(double headwayTime) {
136 912 : myHeadwayTime = headwayTime;
137 912 : myHeadwayTimeACC = headwayTime;
138 : acc_CFM.setHeadwayTime(headwayTime);
139 912 : }
140 :
141 : /**
142 : * @brief try to get the given parameter for this carFollowingModel
143 : *
144 : * @param[in] veh the vehicle from which the parameter must be retrieved
145 : * @param[in] key the key of the parameter
146 : * @return the value of the requested parameter
147 : */
148 : virtual std::string getParameter(const MSVehicle* veh, const std::string& key) const;
149 :
150 :
151 : /**
152 : * @brief try to set the given parameter for this carFollowingModel
153 : *
154 : * @param[in] veh the vehicle for which the parameter must be set
155 : * @param[in] key the key of the parameter
156 : * @param[in] value the value to be set for the given parameter
157 : */
158 : virtual void setParameter(MSVehicle* veh, const std::string& key, const std::string& value) const;
159 :
160 :
161 : /** @brief Returns the model's name
162 : * @return The model's name
163 : * @see MSCFModel::getModelName
164 : */
165 34503766 : int getModelID() const {
166 34503766 : return SUMO_TAG_CF_CACC;
167 : }
168 :
169 : /** @brief Returns the maximum velocity the CF-model wants to achieve in the next step
170 : * @param[in] maxSpeed The maximum achievable speed in the next step
171 : * @param[in] maxSpeedLane The maximum speed the vehicle wants to drive on this lane (Speedlimit*SpeedFactor)
172 : */
173 4057322 : double maximumLaneSpeedCF(const MSVehicle* const veh, double maxSpeed, double maxSpeedLane) const {
174 4057322 : double result = MIN2(maxSpeed, maxSpeedLane);
175 4057322 : if (myApplyDriverstate) {
176 22481 : applyOwnSpeedPerceptionError(veh, result);
177 : }
178 4057322 : return result;
179 : }
180 : /// @}
181 :
182 :
183 :
184 : /** @brief Duplicates the car-following model
185 : * @param[in] vtype The vehicle type this model belongs to (1:1)
186 : * @return A duplicate of this car-following model
187 : */
188 : MSCFModel* duplicate(const MSVehicleType* vtype) const;
189 :
190 7131 : virtual MSCFModel::VehicleVariables* createVehicleVariables() const {
191 7131 : CACCVehicleVariables* ret = new CACCVehicleVariables();
192 7131 : ret->ACC_ControlMode = 0;
193 : ret->CACC_ControlMode = 0;
194 : ret->CACC_CommunicationsOverrideMode = CACC_NO_OVERRIDE;
195 7131 : ret->lastUpdateTime = 0;
196 7131 : return ret;
197 : }
198 :
199 :
200 : private:
201 : enum CommunicationsOverrideMode {
202 : CACC_NO_OVERRIDE = 0,
203 : CACC_MODE_NO_LEADER = 1,
204 : CACC_MODE_LEADER_NO_CAV = 2,
205 : CACC_MODE_LEADER_CAV = 3
206 : };
207 :
208 : static std::map<std::string, CommunicationsOverrideMode> CommunicationsOverrideModeMap;
209 :
210 : /// @brief Vehicle mode (default is CACC)
211 : /// Switch to ACC mode if CACC_ControlMode = 1 (gap control mode) _and_ leader's CFModel != CACC
212 : enum VehicleMode {
213 : CC_MODE = 0,
214 : ACC_MODE,
215 : CACC_GAP_MODE,
216 : CACC_GAP_CLOSING_MODE,
217 : CACC_COLLISION_AVOIDANCE_MODE
218 : };
219 :
220 : /// @brief Vehicle mode name map
221 : static std::map<VehicleMode, std::string> VehicleModeNames;
222 :
223 : class CACCVehicleVariables : public MSCFModel_ACC::ACCVehicleVariables {
224 : public:
225 7131 : CACCVehicleVariables() : CACC_ControlMode(0), CACC_CommunicationsOverrideMode(CACC_NO_OVERRIDE) {}
226 : /// @brief The vehicle's CACC precious time step gap error
227 : int CACC_ControlMode;
228 : CommunicationsOverrideMode CACC_CommunicationsOverrideMode;
229 :
230 : /** @brief Saves the vehicle variables
231 : * @param[in] out The OutputDevice to write the information into
232 : */
233 : void saveState(OutputDevice& out, const MSCFModel& cfm) const;
234 :
235 : /** @brief Loads the state of the vehicle variables from the given description
236 : * @param[in] attrs XML attributes describing the current state
237 : */
238 : void loadState(const SUMOSAXAttributes& attrs);
239 : };
240 :
241 : private:
242 : double _v(const MSVehicle* const veh, const MSVehicle* const pred, const double gap2pred, const double mySpeed,
243 : const double predSpeed, const double desSpeed, const bool respectMinGap, const CalcReason usage = CalcReason::CURRENT) const;
244 :
245 : double speedSpeedControl(const double speed, double vErr, VehicleMode& vehMode) const;
246 : double speedGapControl(const MSVehicle* const veh, const double gap2pred,
247 : const double speed, const double predSpeed, const double desSpeed, double vErr,
248 : const MSVehicle* const pred, VehicleMode& vehMode) const;
249 :
250 : private:
251 : MSCFModel_ACC acc_CFM;
252 : double mySpeedControlGain;
253 : double myGapClosingControlGainGap;
254 : double myGapClosingControlGainGapDot;
255 : double myGapControlGainGap;
256 : double myGapControlGainGapDot;
257 : double myCollisionAvoidanceGainGap;
258 : double myCollisionAvoidanceGainGapDot;
259 : double myHeadwayTimeACC;
260 : double myApplyDriverstate;
261 : double myEmergencyThreshold;
262 : double mySpeedControlMinGap;
263 :
264 : private:
265 : /// @brief Invalidated assignment operator
266 : MSCFModel_CACC& operator=(const MSCFModel_CACC& s);
267 : };
|