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 
62 
63 // ===========================================================================
64 // method definitions
65 // ===========================================================================
67  MSCFModel(vtype),
68  mySpeedControlGain(vtype->getParameter().getCFParam(SUMO_ATTR_SC_GAIN, DEFAULT_SC_GAIN)),
69  myGapClosingControlGainSpeed(vtype->getParameter().getCFParam(SUMO_ATTR_GCC_GAIN_SPEED, DEFAULT_GCC_GAIN_SPEED)),
70  myGapClosingControlGainSpace(vtype->getParameter().getCFParam(SUMO_ATTR_GCC_GAIN_SPACE, DEFAULT_GCC_GAIN_SPACE)),
71  myGapControlGainSpeed(vtype->getParameter().getCFParam(SUMO_ATTR_GC_GAIN_SPEED, DEFAULT_GC_GAIN_SPEED)),
72  myGapControlGainSpace(vtype->getParameter().getCFParam(SUMO_ATTR_GC_GAIN_SPACE, DEFAULT_GC_GAIN_SPACE)),
73  myCollisionAvoidanceGainSpeed(vtype->getParameter().getCFParam(SUMO_ATTR_CA_GAIN_SPEED, DEFAULT_CA_GAIN_SPEED)),
74  myCollisionAvoidanceGainSpace(vtype->getParameter().getCFParam(SUMO_ATTR_CA_GAIN_SPACE, DEFAULT_CA_GAIN_SPACE)) {
75 }
76 
78 
79 
80 double
81 MSCFModel_ACC::finalizeSpeed(MSVehicle* const veh, double vPos) const {
82  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
83  const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
84  // we need the acceleration for emission computation;
85  // in this case, we neglect dawdling, nonetheless, using
86  // vSafe does not incorporate speed reduction due to interaction
87  // on lane changing
88 // const double vMin = getSpeedAfterMaxDecel(oldV);
89  const double vMin = minNextSpeed(oldV); // maybe minNextSpeedEmergency() ? Why is a custom finalizeSpeed function needed anyway?
90  const double vMax = MAX2(vMin, MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe));
91 #ifdef _DEBUG
92  //if (vMin > vMax) {
93  // WRITE_WARNING("Maximum speed of vehicle '" + veh->getID() + "' is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ").");
94  //}
95 #endif
96  return veh->getLaneChangeModel().patchSpeed(vMin, MAX2(vMin, vMax), vMax, *this);
97 
98 }
99 
100 
101 double
102 MSCFModel_ACC::followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double /* predMaxDecel */, const MSVehicle* const /* pred */) const {
103  const double desSpeed = MIN2(veh->getLane()->getSpeedLimit(), veh->getMaxSpeed());
104  return _v(veh, gap2pred, speed, predSpeed, desSpeed, true);
105 }
106 
107 
108 double
109 MSCFModel_ACC::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
110  // NOTE: This allows return of smaller values than minNextSpeed().
111  // Only relevant for the ballistic update: We give the argument headway=TS, to assure that
112  // the stopping position is approached with a uniform deceleration also for tau!=TS.
113  return MIN2(maximumSafeStopSpeed(gap, speed, false, veh->getActionStepLengthSecs()), maxNextSpeed(speed, veh));
114 }
115 
116 
118 double
119 MSCFModel_ACC::interactionGap(const MSVehicle* const /* veh */, double /* vL */) const {
120  /*maximum radar range is ACC is enabled*/
121  return 250;
122 }
123 
124 double MSCFModel_ACC::accelSpeedControl(double vErr) const {
125  // Speed control law
126  return mySpeedControlGain * vErr;
127 }
128 
129 double MSCFModel_ACC::accelGapControl(const MSVehicle* const veh, const double gap2pred, const double speed, const double predSpeed, double vErr) const {
130 
131 #ifdef DEBUG_ACC
132  if DEBUG_COND {
133  std::cout << " applying gapControl" << std::endl;
134 }
135 #endif
136 
137 // Gap control law
138 double gclAccel = 0.0;
139 double desSpacing = myHeadwayTime * speed;
140 // The argument gap2pred does not consider minGap -> substract minGap!!
141 // XXX: It does! (Leo)
142 double gap = gap2pred - veh->getVehicleType().getMinGap();
143  double spacingErr = gap - desSpacing;
144  double deltaVel = predSpeed - speed;
145 
146 
147  if (fabs(spacingErr) < 0.2 && fabs(vErr) < 0.1) {
148  // gap mode
149  gclAccel = myGapControlGainSpeed * deltaVel + myGapControlGainSpace * spacingErr;
150  } else if (spacingErr < 0) {
151  // collision avoidance mode
152  gclAccel = myCollisionAvoidanceGainSpeed * deltaVel + myCollisionAvoidanceGainSpace * spacingErr;
153  } else {
154  // gap closing mode
155  gclAccel = myGapClosingControlGainSpeed * deltaVel + myGapClosingControlGainSpace * spacingErr;
156  }
157 
158  return gclAccel;
159 }
160 
161 
162 double
163 MSCFModel_ACC::_v(const MSVehicle* const veh, const double gap2pred, const double speed,
164  const double predSpeed, const double desSpeed, const bool /* respectMinGap */) const {
165 
166  double accelACC = 0;
167  double gapLimit_SC = 120; // lower gap limit in meters to enable speed control law
168  double gapLimit_GC = 100; // upper gap limit in meters to enable gap control law
169 
170 #ifdef DEBUG_ACC
171  if DEBUG_COND {
172  std::cout << SIMTIME << " MSCFModel_ACC::_v() for veh '" << veh->getID() << "'\n"
173  << " gap=" << gap2pred << " speed=" << speed << " predSpeed=" << predSpeed
174  << " desSpeed=" << desSpeed << std::endl;
175  }
176 #endif
177 
178 
179  /* Velocity error */
180  double vErr = speed - desSpeed;
181  int setControlMode = 0;
185  setControlMode = 1;
186  }
187  if (gap2pred > gapLimit_SC) {
188 
189 #ifdef DEBUG_ACC
190  if DEBUG_COND {
191  std::cout << " applying speedControl" << std::endl;
192  }
193 #endif
194  // Find acceleration - Speed control law
195  accelACC = accelSpeedControl(vErr);
196  // Set cl to vehicle parameters
197  if (setControlMode) {
198  vars->ACC_ControlMode = 0;
199  }
200  } else if (gap2pred < gapLimit_GC) {
201  // Find acceleration - Gap control law
202  accelACC = accelGapControl(veh, gap2pred, speed, predSpeed, vErr);
203  // Set cl to vehicle parameters
204  if (setControlMode) {
205  vars->ACC_ControlMode = 1;
206  }
207  } else {
208  // Follow previous applied law
209  int cm = vars->ACC_ControlMode;
210  if (!cm) {
211 
212 #ifdef DEBUG_ACC
213  if DEBUG_COND {
214  std::cout << " applying speedControl" << std::endl;
215  }
216 #endif
217  accelACC = accelSpeedControl(vErr);
218  } else {
219  accelACC = accelGapControl(veh, gap2pred, speed, predSpeed, vErr);
220  }
221 
222  }
223 
224  double newSpeed = speed + ACCEL2SPEED(accelACC);
225 
226 #ifdef DEBUG_ACC
227  if DEBUG_COND {
228  std::cout << " result: accel=" << accelACC << " newSpeed=" << newSpeed << std::endl;
229 }
230 #endif
231 
232 return MAX2(0., newSpeed);
233 }
234 
235 
236 MSCFModel*
238  return new MSCFModel_ACC(vtype);
239 }
#define DEFAULT_GCC_GAIN_SPEED
double myGapControlGainSpeed
#define DEFAULT_GCC_GAIN_SPACE
double getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane&#39;s maximum speed, given a vehicle&#39;s speed limit adaptation.
Definition: MSLane.h:485
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:905
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:54
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
#define DEFAULT_SC_GAIN
virtual double minNextSpeed(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed given the current speed (depends on the numerical update scheme and its ste...
Definition: MSCFModel.cpp:239
#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:233
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
T MAX2(T a, T b)
Definition: StdDefs.h:68
~MSCFModel_ACC()
Destructor.
double myCollisionAvoidanceGainSpace
The car-following model and parameter.
Definition: MSVehicleType.h:66
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:4027
#define SIMTIME
Definition: SUMOTime.h:65
virtual double patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)=0
Called to adapt the speed in order to allow a lane change. It uses information on LC-related desired ...
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:513
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:499
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:256
T MIN2(T a, T b)
Definition: StdDefs.h:62
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:703
double mySpeedControlGain
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.
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1446
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
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 _v(const MSVehicle *const veh, const double gap2pred, const double mySpeed, const double predSpeed, const double desSpeed, const bool respectMinGap=true) const
T MIN3(T a, T b, T c)
Definition: StdDefs.h:75
#define DEFAULT_CA_GAIN_SPEED
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:594
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:479
const std::string & getID() const
Returns the name of the vehicle.
double myGapClosingControlGainSpeed
double myGapControlGainSpace
#define DEFAULT_CA_GAIN_SPACE