SUMO - Simulation of Urban MObility
MSCFModel_ACC.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // ACC car-following model based on [1], [2].
16 // [1] Milanes, V., and S. E. Shladover. Handling Cut-In Vehicles in Strings
17 // of Cooperative Adaptive Cruise Control Vehicles. Journal of Intelligent
18 // Transportation Systems, Vol. 20, No. 2, 2015, pp. 178-191.
19 // [2] Xiao, L., M. Wang and B. van Arem. Realistic Car-Following Models for
20 // Microscopic Simulation of Adaptive and Cooperative Adaptive Cruise
21 // Control Vehicles. Transportation Research Record: Journal of the
22 // Transportation Research Board, No. 2623, 2017. (DOI: 10.3141/2623-01).
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #include <config.h>
30 
31 #include <stdio.h>
32 #include <iostream>
33 
34 #include "MSCFModel_ACC.h"
35 #include <microsim/MSVehicle.h>
36 #include <microsim/MSLane.h>
38 #include <utils/common/SUMOTime.h>
40 #include <math.h>
41 #include <microsim/MSNet.h>
42 
43 // ===========================================================================
44 // debug flags
45 // ===========================================================================
46 #define DEBUG_ACC
47 #define DEBUG_COND (veh->isSelected())
48 
49 
50 // ===========================================================================
51 // defaults
52 // ===========================================================================
53 #define DEFAULT_SC_GAIN -0.4
54 #define DEFAULT_GCC_GAIN_SPEED 0.8
55 #define DEFAULT_GCC_GAIN_SPACE 0.04
56 #define DEFAULT_GC_GAIN_SPEED 0.07
57 #define DEFAULT_GC_GAIN_SPACE 0.23
58 #define DEFAULT_CA_GAIN_SPACE 0.8
59 #define DEFAULT_CA_GAIN_SPEED 0.23
60 
61 // override followSpeed when deemed unsafe by the given margin (the value was selected to reduce the number of necessary interventions)
62 #define DEFAULT_EMERGENCY_OVERRIDE_THRESHOLD 2.0
63 
65 
66 // ===========================================================================
67 // method definitions
68 // ===========================================================================
70  MSCFModel(vtype),
71  mySpeedControlGain(vtype->getParameter().getCFParam(SUMO_ATTR_SC_GAIN, DEFAULT_SC_GAIN)),
72  myGapClosingControlGainSpeed(vtype->getParameter().getCFParam(SUMO_ATTR_GCC_GAIN_SPEED, DEFAULT_GCC_GAIN_SPEED)),
73  myGapClosingControlGainSpace(vtype->getParameter().getCFParam(SUMO_ATTR_GCC_GAIN_SPACE, DEFAULT_GCC_GAIN_SPACE)),
74  myGapControlGainSpeed(vtype->getParameter().getCFParam(SUMO_ATTR_GC_GAIN_SPEED, DEFAULT_GC_GAIN_SPEED)),
75  myGapControlGainSpace(vtype->getParameter().getCFParam(SUMO_ATTR_GC_GAIN_SPACE, DEFAULT_GC_GAIN_SPACE)),
76  myCollisionAvoidanceGainSpeed(vtype->getParameter().getCFParam(SUMO_ATTR_CA_GAIN_SPEED, DEFAULT_CA_GAIN_SPEED)),
77  myCollisionAvoidanceGainSpace(vtype->getParameter().getCFParam(SUMO_ATTR_CA_GAIN_SPACE, DEFAULT_CA_GAIN_SPACE)) {
78  // ACC does not drive very precise and often violates minGap
80 }
81 
83 
84 
85 double
86 MSCFModel_ACC::followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const /*pred*/) const {
87  const double desSpeed = MIN2(veh->getLane()->getSpeedLimit(), veh->getMaxSpeed());
88  const double vACC = _v(veh, gap2pred, speed, predSpeed, desSpeed, true);
89  const double vSafe = maximumSafeFollowSpeed(gap2pred, speed, predSpeed, predMaxDecel);
90  if (vSafe + DEFAULT_EMERGENCY_OVERRIDE_THRESHOLD < vACC) {
91  //ACCVehicleVariables* vars = (ACCVehicleVariables*)veh->getCarFollowVariables();
92  //std::cout << SIMTIME << " veh=" << veh->getID() << " v=" << speed << " vL=" << predSpeed << " gap=" << gap2pred << " vACC=" << vACC << " vSafe=" << vSafe << " cm=" << vars->ACC_ControlMode << "\n";
94  }
95  return vACC;
96 }
97 
98 
99 double
100 MSCFModel_ACC::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
101  // NOTE: This allows return of smaller values than minNextSpeed().
102  // Only relevant for the ballistic update: We give the argument headway=TS, to assure that
103  // the stopping position is approached with a uniform deceleration also for tau!=TS.
104  return MIN2(maximumSafeStopSpeed(gap, speed, false, veh->getActionStepLengthSecs()), maxNextSpeed(speed, veh));
105 }
106 
107 
109 double
110 MSCFModel_ACC::interactionGap(const MSVehicle* const /* veh */, double /* vL */) const {
111  /*maximum radar range is ACC is enabled*/
112  return 250;
113 }
114 
115 double MSCFModel_ACC::accelSpeedControl(double vErr) const {
116  // Speed control law
117  return mySpeedControlGain * vErr;
118 }
119 
120 double MSCFModel_ACC::accelGapControl(const MSVehicle* const veh, const double gap2pred, const double speed, const double predSpeed, double vErr) const {
121 
122 #ifdef DEBUG_ACC
123  if DEBUG_COND {
124  std::cout << " applying gapControl" << std::endl;
125 }
126 #endif
127 
128 // Gap control law
129 double gclAccel = 0.0;
130 double desSpacing = myHeadwayTime * speed;
131 // The argument gap2pred does not consider minGap -> substract minGap!!
132 // XXX: It does! (Leo)
133 double gap = gap2pred - veh->getVehicleType().getMinGap();
134  double spacingErr = gap - desSpacing;
135  double deltaVel = predSpeed - speed;
136 
137 
138  if (fabs(spacingErr) < 0.2 && fabs(vErr) < 0.1) {
139  // gap mode
140  gclAccel = myGapControlGainSpeed * deltaVel + myGapControlGainSpace * spacingErr;
141  } else if (spacingErr < 0) {
142  // collision avoidance mode
143  gclAccel = myCollisionAvoidanceGainSpeed * deltaVel + myCollisionAvoidanceGainSpace * spacingErr;
144  } else {
145  // gap closing mode
146  gclAccel = myGapClosingControlGainSpeed * deltaVel + myGapClosingControlGainSpace * spacingErr;
147  }
148 
149  return gclAccel;
150 }
151 
152 
153 double
154 MSCFModel_ACC::_v(const MSVehicle* const veh, const double gap2pred, const double speed,
155  const double predSpeed, const double desSpeed, const bool /* respectMinGap */) const {
156 
157  double accelACC = 0;
158  double gapLimit_SC = 120; // lower gap limit in meters to enable speed control law
159  double gapLimit_GC = 100; // upper gap limit in meters to enable gap control law
160 
161 #ifdef DEBUG_ACC
162  if DEBUG_COND {
163  std::cout << SIMTIME << " MSCFModel_ACC::_v() for veh '" << veh->getID() << "'\n"
164  << " gap=" << gap2pred << " speed=" << speed << " predSpeed=" << predSpeed
165  << " desSpeed=" << desSpeed << std::endl;
166  }
167 #endif
168 
169 
170  /* Velocity error */
171  double vErr = speed - desSpeed;
172  int setControlMode = 0;
176  setControlMode = 1;
177  }
178  if (gap2pred > gapLimit_SC) {
179 
180 #ifdef DEBUG_ACC
181  if DEBUG_COND {
182  std::cout << " applying speedControl" << std::endl;
183  }
184 #endif
185  // Find acceleration - Speed control law
186  accelACC = accelSpeedControl(vErr);
187  // Set cl to vehicle parameters
188  if (setControlMode) {
189  vars->ACC_ControlMode = 0;
190  }
191  } else if (gap2pred < gapLimit_GC) {
192  // Find acceleration - Gap control law
193  accelACC = accelGapControl(veh, gap2pred, speed, predSpeed, vErr);
194  // Set cl to vehicle parameters
195  if (setControlMode) {
196  vars->ACC_ControlMode = 1;
197  }
198  } else {
199  // Follow previous applied law
200  int cm = vars->ACC_ControlMode;
201  if (!cm) {
202 
203 #ifdef DEBUG_ACC
204  if DEBUG_COND {
205  std::cout << " applying speedControl" << std::endl;
206  }
207 #endif
208  accelACC = accelSpeedControl(vErr);
209  } else {
210  accelACC = accelGapControl(veh, gap2pred, speed, predSpeed, vErr);
211  }
212 
213  }
214 
215  double newSpeed = speed + ACCEL2SPEED(accelACC);
216 
217 #ifdef DEBUG_ACC
218  if DEBUG_COND {
219  std::cout << " result: accel=" << accelACC << " newSpeed=" << newSpeed << std::endl;
220 }
221 #endif
222 
223 return MAX2(0., newSpeed);
224 }
225 
226 
227 MSCFModel*
229  return new MSCFModel_ACC(vtype);
230 }
#define DEFAULT_GCC_GAIN_SPEED
double myGapControlGainSpeed
#define DEFAULT_GCC_GAIN_SPACE
double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
Definition: MSCFModel.cpp:854
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle&#39;s car following model variables.
Definition: MSVehicle.h:909
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:54
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:565
#define DEFAULT_SC_GAIN
#define DEFAULT_GC_GAIN_SPEED
double myGapClosingControlGainSpace
double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred) const
Computes the vehicle&#39;s safe speed for approaching a non-moving obstacle (no dawdling) ...
The car-following model abstraction.
Definition: MSCFModel.h:57
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:239
#define DEFAULT_EMERGENCY_OVERRIDE_THRESHOLD
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
T MAX2(T a, T b)
Definition: StdDefs.h:76
~MSCFModel_ACC()
Destructor.
double myCollisionAvoidanceGainSpace
The car-following model and parameter.
Definition: MSVehicleType.h:66
#define SIMTIME
Definition: SUMOTime.h:65
double getMaxSpeed() const
Returns the maximum speed.
#define DEBUG_COND
double getActionStepLengthSecs() const
Returns the vehicle&#39;s action step length in secs, i.e. the interval between two action points...
Definition: MSVehicle.h:517
double interactionGap(const MSVehicle *const, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
MSCFModel_ACC(const MSVehicleType *vtype)
Constructor.
#define DEFAULT_GC_GAIN_SPACE
double getSpeedLimit() const
Returns the lane&#39;s maximum allowed speed.
Definition: MSLane.h:506
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:263
T MIN2(T a, T b)
Definition: StdDefs.h:70
double getMinGap() const
Get the free space in front of vehicles of this class.
double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
Definition: MSCFModel.cpp:709
double mySpeedControlGain
const SUMOVTypeParameter & getParameter() const
double getCFParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
double accelGapControl(const MSVehicle *const veh, const double gap2pred, const double speed, const double predSpeed, double vErr) const
double accelSpeedControl(double vErr) const
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
int ACC_ControlMode
The vehicle&#39;s ACC control mode. 0 for speed control and 1 for gap control.
double myCollisionAvoidanceGainSpeed
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle&#39;s safe speed (no dawdling)
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:599
double _v(const MSVehicle *const veh, const double gap2pred, const double mySpeed, const double predSpeed, const double desSpeed, const bool respectMinGap=true) const
#define DEFAULT_CA_GAIN_SPEED
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:602
const std::string & getID() const
Returns the name of the vehicle.
double myGapClosingControlGainSpeed
double myGapControlGainSpace
#define DEFAULT_CA_GAIN_SPACE