Commit 24efeba1 authored by jimonreal's avatar jimonreal Committed by Jose Ignacio Monreal Bailey
Browse files

Adding logic to extend traffic lights phase

parent a6b7b583
...@@ -213,12 +213,20 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -213,12 +213,20 @@ public class TraciSimulationController implements VehicleController, SimulationS
public long getRemainingPhaseTime(String trafficLightId) { public long getRemainingPhaseTime(String trafficLightId) {
SumoCommand nextSwitchCommand = Trafficlight.getNextSwitch(trafficLightId); SumoCommand nextSwitchCommand = Trafficlight.getNextSwitch(trafficLightId);
Object nextSwitchObject = requestObject(nextSwitchCommand); Object nextSwitchObject = requestObject(nextSwitchCommand);
long remaingPhaseTime = (long) (((int)nextSwitchObject) - (Simulator.getCurrentTime()/1000.0)); Object currentTime = requestObject(Simulation.getCurrentTime());
long remaingPhaseTime = (long)((int)nextSwitchObject - (int)currentTime);
return remaingPhaseTime; return remaingPhaseTime;
} }
@Override @Override
public void setPhaseDuration(String trafficLightId, int extraTime) {
SumoCommand phaseDurationCommand = Trafficlight.setPhaseDuration(trafficLightId, extraTime);
execute(phaseDurationCommand);
}
@Override
public boolean nextStep() { public boolean nextStep() {
if (Simulator.getEndTime() == Simulator.getCurrentTime()) { if (Simulator.getEndTime() == Simulator.getCurrentTime()) {
return false; return false;
......
...@@ -225,7 +225,12 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -225,7 +225,12 @@ public class XMLSimulationController implements VehicleController, SimulationSet
return 0; return 0;
} }
@Override @Override
public void setPhaseDuration(String trafficLightId, int extraTime) {
}
@Override
public double getScenarioWidth() { public double getScenarioWidth() {
return -1; return -1;
} }
......
...@@ -92,6 +92,11 @@ public class DefaultTrafficLightInformationComponent implements TrafficLightInfo ...@@ -92,6 +92,11 @@ public class DefaultTrafficLightInformationComponent implements TrafficLightInfo
return controller.getRemainingPhaseTime(trafficLightId); return controller.getRemainingPhaseTime(trafficLightId);
} }
@Override
public void setPhasaeDuration(String trafficLightId, int extraTime) {
controller.setPhaseDuration(trafficLightId, extraTime);
}
@Override @Override
public void initialize() { public void initialize() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment