47#define DEBUG_CACC_INSERTION_FOLLOW_SPEED 0
48#define DEBUG_CACC_SECURE_GAP 0
49#define DEBUG_COND (veh->isSelected())
57#define DEFAULT_SC_GAIN_CACC -0.4
58#define DEFAULT_GCC_GAIN_GAP_CACC 0.005
59#define DEFAULT_GCC_GAIN_GAP_DOT_CACC 0.05
60#define DEFAULT_GC_GAIN_GAP_CACC 0.45
61#define DEFAULT_GC_GAIN_GAP_DOT_CACC 0.0125
62#define DEFAULT_CA_GAIN_GAP_CACC 0.45
63#define DEFAULT_CA_GAIN_GAP_DOT_CACC 0.05
64#define DEFAULT_HEADWAYTIME_ACC 1.0
65#define DEFAULT_SC_MIN_GAP 1.66
68#define DEFAULT_EMERGENCY_OVERRIDE_THRESHOLD 2.0
71 {
"0", CACC_NO_OVERRIDE},
72 {
"1", CACC_MODE_NO_LEADER},
73 {
"2", CACC_MODE_LEADER_NO_CAV},
74 {
"3", CACC_MODE_LEADER_CAV}
80 {CACC_GAP_CLOSING_MODE,
"CACC_GAP_CL"},
81 {CACC_GAP_MODE,
"CACC_GAP"},
82 {CACC_COLLISION_AVOIDANCE_MODE,
"CACC_CA"}
112 std::ostringstream internals;
123 const std::string cfmID = attrs.
get<std::string>(
SUMO_ATTR_ID,
nullptr, ok);
124 if (cfmID !=
"CACC") {
125 throw ProcessError(
TLF(
"incompatible carFollowModel '%' when loading state for CACC", cfmID));
153 const double vCACC =
_v(veh, pred, gap2pred, speed, predSpeed, desSpeed,
true, usage);
160 <<
" v=" << speed <<
" vL=" << predSpeed <<
" gap=" << gap2pred
161 <<
" predDecel=" << predMaxDecel <<
" vCACC=" << vCACC <<
" vSafe=" << vSafe <<
"\n";
167 if (vSafe + speedOverride < vCACC) {
170 std::cout <<
"Apply Safe speed, override=" << speedOverride <<
"\n";
173 return MAX2(0.0, vSafe + speedOverride);
203#if DEBUG_CACC_SECURE_GAP == 1
204 std::cout <<
SIMTIME <<
"MSCFModel_ACC::getSecureGap speed=" << speed <<
" leaderSpeed=" << leaderSpeed
205 <<
" desSpacing=" << desSpacing <<
" desSpacingDefault=" << desSpacingDefault <<
"\n";
207 return MAX2(desSpacing, desSpacingDefault);
213#if DEBUG_CACC_INSERTION_FOLLOW_SPEED == 1
215 std::cout <<
"MSCFModel_ACC::insertionFollowSpeed(), speed=" << speed <<
" gap2pred=" << gap2pred <<
" predSpeed=" << predSpeed <<
"\n";
220 const int max_iter = 50;
222 const double tol = 0.1;
223 double damping = 0.8;
226 while (n_iter < max_iter) {
228 const double vCACC =
_v(veh, pred, gap2pred, res, predSpeed, speed,
true);
230 const double a =
MIN2(vCACC, vSafe) - res;
231 res = res + damping * a;
232#if DEBUG_CACC_INSERTION_FOLLOW_SPEED == 1
234 std::cout <<
" n_iter=" << n_iter <<
" vSafe=" << vSafe <<
" vCACC=" << vCACC <<
" a=" << a <<
" damping=" << damping <<
" res=" << res << std::endl;
262 if (key.compare(
"caccCommunicationsOverrideMode") == 0) {
275 if (key.compare(
"caccCommunicationsOverrideMode") == 0) {
295 const double speed,
const double predSpeed,
const double desSpeed,
double vErr,
298 double newSpeed = 0.0;
300 if (pred !=
nullptr) {
303 newSpeed =
acc_CFM._v(veh, gap2pred, speed, predSpeed, desSpeed,
true);
306 std::cout <<
" acc control mode" << std::endl;
312 std::cout <<
" CACC control mode" << std::endl;
316 double spacingErr = gap2pred - desSpacing;
320 if ((spacingErr > 0 && spacingErr < 0.2) && (vErr < 0.1)) {
325 std::cout <<
" applying gap control: err=" << spacingErr <<
" speedErr=" << speedErr << std::endl;
331 }
else if (spacingErr < 0) {
336 std::cout <<
" applying collision avoidance: err=" << spacingErr <<
" speedErr=" << speedErr <<
"\n";
345 std::cout <<
" applying gap closing err=" << spacingErr <<
" speedErr=" << speedErr <<
" predSpeed=" << predSpeed <<
" speed=" << speed <<
" accel=" << accel <<
"\n";
357 std::cout <<
" no leader" << std::endl;
368 const double predSpeed,
const double desSpeed,
const bool ,
const CalcReason usage)
const {
369 double newSpeed = 0.0;
374 std::cout <<
SIMTIME <<
" MSCFModel_CACC::_v() for veh '" << veh->
getID()
375 <<
" gap=" << gap2pred <<
" speed=" << speed <<
" predSpeed=" << predSpeed
376 <<
" desSpeed=" << desSpeed << std::endl;
381 double vErr = speed - desSpeed;
382 bool setControlMode =
false;
386 setControlMode =
true;
394 double time_gap = gap2pred /
MAX2(NUMERICAL_EPS, speed);
400 std::cout <<
" applying speedControl" <<
" time_gap=" << time_gap << std::endl;
406 if (setControlMode) {
409 }
else if (time_gap < 1.5) {
413 std::cout <<
" speedGapControl" <<
" time_gap=" << time_gap << std::endl;
417 newSpeed =
speedGapControl(veh, gap2pred, speed, predSpeed, desSpeed, vErr, pred, vehMode);
419 if (setControlMode) {
430 std::cout <<
" applying speedControl (previous)" <<
" time_gap=" << time_gap << std::endl;
438 std::cout <<
" previous speedGapControl (previous)" <<
" time_gap=" << time_gap << std::endl;
441 newSpeed =
speedGapControl(veh, gap2pred, speed, predSpeed, desSpeed, vErr, pred, vehMode);
447 newSpeed =
acc_CFM._v(veh, gap2pred, speed, predSpeed, desSpeed,
true);
451 double spacingErr = gap2pred - desSpacing;
455 if ((spacingErr > 0 && spacingErr < 0.2) && (vErr < 0.1)) {
459 std::cout <<
" applying CACC_GAP_MODE " << std::endl;
463 }
else if (spacingErr < 0) {
467 std::cout <<
" applying CACC_COLLISION_AVOIDANCE_MODE " << std::endl;
474 std::cout <<
" applying CACC_GAP_CLOSING_MODE " << std::endl;
490 double newSpeedScaled = newSpeed;
492 const double accel01 = (newSpeed - speed) * 10;
498 std::cout <<
" result: rawAccel=" <<
SPEED2ACCEL(newSpeed - speed) <<
" newSpeed=" << newSpeed <<
" newSpeedScaled=" << newSpeedScaled <<
"\n";
502 return MAX2(0., newSpeedScaled);
#define DEFAULT_EMERGENCY_OVERRIDE_THRESHOLD
#define DEFAULT_GC_GAIN_GAP_DOT_CACC
#define DEFAULT_CA_GAIN_GAP_DOT_CACC
#define DEFAULT_SC_GAIN_CACC
#define DEFAULT_GC_GAIN_GAP_CACC
#define DEFAULT_SC_MIN_GAP
#define DEFAULT_HEADWAYTIME_ACC
#define DEFAULT_CA_GAIN_GAP_CACC
#define DEFAULT_GCC_GAIN_GAP_CACC
#define DEFAULT_GCC_GAIN_GAP_DOT_CACC
const std::string invalid_return< std::string >::value
@ SUMO_ATTR_GCC_GAIN_GAP_DOT_CACC
@ SUMO_ATTR_CA_GAIN_GAP_CACC
@ SUMO_ATTR_GC_GAIN_GAP_DOT_CACC
@ SUMO_ATTR_CA_GAIN_GAP_DOT_CACC
@ SUMO_ATTR_HEADWAY_TIME_CACC_TO_ACC
@ SUMO_ATTR_GC_GAIN_GAP_CACC
@ SUMO_ATTR_COLLISION_MINGAP_FACTOR
@ SUMO_ATTR_APPLYDRIVERSTATE
@ SUMO_ATTR_GCC_GAIN_GAP_CACC
@ SUMO_ATTR_STATE
The state of a link.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition).
The ACC car-following model.
CommunicationsOverrideMode CACC_CommunicationsOverrideMode
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the vehicle variables from the given description.
int CACC_ControlMode
The vehicle's CACC precious time step gap error.
void saveState(OutputDevice &out, const MSCFModel &cfm) const
Saves the vehicle variables.
virtual std::string getParameter(const MSVehicle *veh, const std::string &key) const
try to get the given parameter for this carFollowingModel
double getSecureGap(const MSVehicle *const veh, const MSVehicle *const pred, const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the a gap such that the gap mode acceleration of the follower is zero.
double freeSpeed(const MSVehicle *const veh, double speed, double seen, double maxSpeed, const bool onInsertion=false, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed without a leader.
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed (no dawdling).
MSCFModel_CACC(const MSVehicleType *vtype)
Constructor.
double myGapControlGainGap
double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred, double decel, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling).
double myApplyDriverstate
virtual void setParameter(MSVehicle *veh, const std::string &key, const std::string &value) const
try to set the given parameter for this carFollowingModel
double myGapClosingControlGainGap
double _v(const MSVehicle *const veh, const MSVehicle *const pred, const double gap2pred, const double mySpeed, const double predSpeed, const double desSpeed, const bool respectMinGap, const CalcReason usage=CalcReason::CURRENT) const
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double speedSpeedControl(const double speed, double vErr, VehicleMode &vehMode) const
double myEmergencyThreshold
double insertionFollowSpeed(const MSVehicle *const v, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle's acceptable speed at insertion.
double myGapClosingControlGainGapDot
static std::map< std::string, CommunicationsOverrideMode > CommunicationsOverrideModeMap
double mySpeedControlGain
double myCollisionAvoidanceGainGapDot
double speedGapControl(const MSVehicle *const veh, const double gap2pred, const double speed, const double predSpeed, const double desSpeed, double vErr, const MSVehicle *const pred, VehicleMode &vehMode) const
double myGapControlGainGapDot
~MSCFModel_CACC()
Destructor.
VehicleMode
Vehicle mode (default is CACC) Switch to ACC mode if CACC_ControlMode = 1 (gap control mode) and lead...
@ CACC_COLLISION_AVOIDANCE_MODE
double mySpeedControlMinGap
static std::map< VehicleMode, std::string > VehicleModeNames
Vehicle mode name map.
double myCollisionAvoidanceGainGap
double interactionGap(const MSVehicle *const, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
CommunicationsOverrideMode
@ CACC_MODE_LEADER_NO_CAV
The car-following model abstraction.
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
virtual double freeSpeed(const MSVehicle *const veh, double speed, double seen, double maxSpeed, const bool onInsertion=false, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed without a leader.
void applyHeadwayPerceptionError(const MSVehicle *const veh, double speed, double &gap) const
Overwrites gap by the perceived value obtained from the vehicle's driver state.
void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle *const veh, double speed, double &gap, double &predSpeed, double predMaxDecel, const MSVehicle *const pred) const
Overwrites gap2pred and predSpeed by the perceived values obtained from the vehicle's driver state,...
double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
CalcReason
What the return value of stop/follow/free-Speed is used for.
@ CURRENT
the return value is used for calculating the next speed
virtual double getSecureGap(const MSVehicle *const veh, const MSVehicle *const, const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0).
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
MSCFModel(const MSVehicleType *vtype)
Constructor.
virtual int getModelID() const =0
Returns the model's ID; the XML-Tag number is used.
double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1, bool relaxEmergency=true) const
Returns the maximum next velocity for stopping within gap.
double myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
static bool gComputeLC
whether the simulationLoop is in the lane changing phase
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Representation of a vehicle in the micro simulation.
double getActionStepLengthSecs() const
Returns the vehicle's action step length in secs, i.e. the interval between two action points.
double getAcceleration() const
Returns the vehicle's acceleration in m/s (this is computed as the last step's mean acceleration in c...
const MSLane * getLane() const
Returns the lane the vehicle is on.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle's car following model variables.
The car-following model and parameter.
const SUMOVTypeParameter & getParameter() const
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
const std::string & getID() const
Returns the id.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
Structure representing possible vehicle parameter.
#define UNUSED_PARAMETER(x)