-
Notifications
You must be signed in to change notification settings - Fork 151
Description
Greetings, Dr. MT. Firstly,This is a great job for you.
Secondly, I am going to replace the default following model(IDM and ACC model), I added the CACC code in the model.js file, but I'm not sure if I configured it correctly in the other files and enabled it successfully.
I am preparing to implement the vehicle CACC model in the ring.js file. Below is my configured CACC model code, I hope I can get your answer. Thanks!
//#################################
// CACC model
//#################################
/**
CACC (Cooperative Adaptive Cruise Control) constructor
@param v0: desired speed [m/s]
@param T: desired time gap [s]
@param s0: minimum gap [m]
@param a: maximum acceleration [m/s^2]
@param b: comfortable deceleration [m/s^2]
@param delta: headway time constant [s]
@param alpha: cooperative parameter [1/s]
@return: CACC instance (constructor)
*/
function CACC(v0, T, s0, a, b, delta, alpha) {
this.QnoiseAccel = QnoiseAccel; // m^2/s^3
this.driverfactor = 1; // if no transfer of driver individuality from master veh
this.v0 = v0;
this.T = T;
this.s0 = s0;
this.a = a;
this.b = b;
this.delta = delta;
this.alpha = alpha;
this.alpha_v0 = 1; // multiplicator for temporary reduction
// possible restrictions (value 1000 => initially no restriction)
this.speedlimit = 1000; // if effective speed limits, speedlimit<v0
this.speedmax = 1000; // if engine restricts speed, speedmax<speedlimit, v0
this.bmax = 18; // (2022) was=16
}
/**
CACC acceleration function
@param s: actual gap [m]
@param v: actual speed [m/s]
@param vl: leading speed [m/s]
@param al: leading acceleration [m/s^2] (only for common interface; ignored)
@return: acceleration [m/s^2]
*/
CACC.prototype.calcAcc = function (s, v, vl, al) {
var accRnd = s < this.s0 ? 0 : Math.sqrt(this.QnoiseAccel / dt) * (Math.random() - 0.5);
return accRnd + this.calcAccDet(s, v, vl, al);
};
CACC.prototype.calcAccDet = function (s, v, vl, al) {
var v0eff = this.v0 * this.driverfactor * this.alpha_v0; // (MT 2023-11)
v0eff = Math.min(v0eff, this.speedlimit, this.speedmax);
var aeff = this.a * this.driverfactor;
var accFree = v < v0eff ? aeff * (1 - Math.pow(v / v0eff, 4)) : aeff * (1 - v / v0eff);
var sstar = this.s0 + Math.max(0, v * this.T + 0.5 * v * (v - vl) / Math.sqrt(aeff * this.b));
var accInt = -aeff * Math.pow(sstar / Math.max(s, this.s0), 2);
return v0eff < 0.00001 ? 0 : Math.max(-this.bmax, accFree + accInt);
};
// Example Usage:
// var caccModel = new CACC(30, 1.5, 2, 2, 1, 1, 0.1);
// var acceleration = caccModel.calcAcc(s, v, vl, al);