Skip to content

Commit

Permalink
MSCFModel_CC: properly handle leader role
Browse files Browse the repository at this point in the history
  • Loading branch information
michele-segata authored and namdre committed May 2, 2024
1 parent 073b489 commit dab4eeb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/microsim/cfmodels/CC_VehicleVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CC_VehicleVariables::CC_VehicleVariables() :
controllerAcceleration(0), frontSpeed(0), frontAcceleration(0),
frontControllerAcceleration(0), frontDataReadTime(0), frontAngle(0), frontInitialized(false),
autoFeed(false), leaderVehicle(0), frontVehicle(0),
isLeader(true),
accHeadwayTime(1.5), accLambda(0.1),
useControllerAcceleration(true), leaderSpeed(0),
leaderAcceleration(0), leaderControllerAcceleration(0), leaderDataReadTime(0), leaderAngle(0),
Expand Down
3 changes: 3 additions & 0 deletions src/microsim/cfmodels/CC_VehicleVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class CC_VehicleVariables : public MSCFModel::VehicleVariables {
MSVehicle* leaderVehicle;
/// @brief front sumo id, used for auto feeding
MSVehicle* frontVehicle;
/// @brief whether this vehicle is leader of a platoon or not. This is mainly used by the lane change logic.
/// By default this is true as a single vehicle is treated as a 1-vehicle platoon
bool isLeader;

/// @brief headway time for ACC
double accHeadwayTime;
Expand Down
9 changes: 7 additions & 2 deletions src/microsim/cfmodels/MSCFModel_CC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ void
MSCFModel_CC::setLeader(MSVehicle* veh, MSVehicle* const leader) const {
auto* vars = (CC_VehicleVariables*) veh->getCarFollowVariables();
vars->leaderVehicle = leader;
if (leader != nullptr)
vars->isLeader = false;
else
// if we are removing our leader, then this vehicle must become a leader of itself until being member of another platoon
vars->isLeader = true;
}

int
Expand Down Expand Up @@ -818,6 +823,7 @@ void MSCFModel_CC::setParameter(MSVehicle* veh, const std::string& key, const st
throw libsumo::TraCIException("Adding " + id + " as member but " + id + " is not using MSCFModel_CC");
}
cfm->setLeader(vehicle, veh);
vars->isLeader = true;
return;
}
if (key.compare(PAR_REMOVE_MEMBER) == 0) {
Expand Down Expand Up @@ -1170,6 +1176,5 @@ MSCFModel_CC::duplicate(const MSVehicleType* vtype) const {
bool
MSCFModel_CC::isLeader(const MSVehicle *veh) const {
auto vars = (CC_VehicleVariables*)veh->getCarFollowVariables();
// TODO: this condition might not be enough
return vars->activeController == Plexe::ACC;
return vars->isLeader;
}

0 comments on commit dab4eeb

Please sign in to comment.