Skip to content

Commit

Permalink
tls state output and phase names are now working. refs #9520
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Nov 12, 2021
1 parent 19f6564 commit f2812ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/microsim/traffic_lights/NEMAController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ NEMALogic::NEMALogic(MSTLLogicControl& tlcontrol,
int step, SUMOTime delay,
const std::map<std::string, std::string>& parameter,
const std::string& basePath) :
MSSimpleTrafficLightLogic(tlcontrol, id, programID, TrafficLightType::NEMA, phases, step, delay, parameter)
{
MSSimpleTrafficLightLogic(tlcontrol, id, programID, TrafficLightType::NEMA, phases, step, delay, parameter),
myPhase(phases[0]->duration, phases[0]->getState())
{
myDetectorLength = StringUtils::toDouble(getParameter("detector-length", "20"));
myDetectorLengthLeftTurnLane = StringUtils::toDouble(getParameter("detector-length-leftTurnLane", "20"));
myCycleLength = (StringUtils::toDouble(getParameter("total-cycle-length", "60")));
Expand Down Expand Up @@ -554,17 +555,20 @@ bool NEMALogic::isDetectorActivated(int phaseIndex) {
return false;
}

const MSPhaseDefinition&
NEMALogic::getCurrentPhaseDef() const {
return myPhase;
}

SUMOTime
NEMALogic::trySwitch() {
std::string state = NEMA_control();
for (int i = 0; i < (int)myLinks.size(); i++) {
const LinkVector& currGroup = myLinks[i];
LinkState ls = (LinkState) state[i];
for (MSLink* link : currGroup) {
link->setTLState(ls, SIMSTEP);
}
const std::string newState = NEMA_control();
if (newState != myPhase.getState()) {
myPhase.setState(newState);
// ensure that SwitchCommand::execute notices a change
myStep = 1 - myStep;
}
//std::cout << SIMTIME << " " << myPhase.getState() << "\n";
return TIME2STEPS(1);
}

Expand Down Expand Up @@ -727,6 +731,7 @@ NEMALogic::NEMA_control() {
}

}
myPhase.setName(toString(R1Phase) + "+" + toString(R2Phase));
return outputState;
}

Expand Down
12 changes: 12 additions & 0 deletions src/microsim/traffic_lights/NEMAController.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ class NEMALogic : public MSSimpleTrafficLightLogic {

SUMOTime trySwitch();

/// @name Dynamic Information Retrieval
/// @{

/** @brief Returns the definition of the current phase
* @return The current phase
*/
const MSPhaseDefinition& getCurrentPhaseDef() const;
/// @}

/// @brief called when switching programs
void activateProgram();
void deactivateProgram();
Expand Down Expand Up @@ -271,4 +280,7 @@ class NEMALogic : public MSSimpleTrafficLightLogic {
std::string outputStateFilePath;
std::ofstream outputStateFile;
bool coordinateMode;

/// @brief virtual phase that holds the current state
MSPhaseDefinition myPhase;
};

0 comments on commit f2812ec

Please sign in to comment.