Commit a6b7b583 authored by Jose Ignacio Monreal Bailey's avatar Jose Ignacio Monreal Bailey
Browse files

Starting to change dinamically the lights time

parent 019d1168
...@@ -194,6 +194,30 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -194,6 +194,30 @@ public class TraciSimulationController implements VehicleController, SimulationS
return result; return result;
} }
@Override
public int getPhase(String trafficLightId) {
SumoCommand phaseCommand = Trafficlight.getPhase(trafficLightId);
Object phaseObject = requestObject(phaseCommand);
int phase = (int)phaseObject;
return phase;
}
@Override
public void setPhase(String trafficLightId, int phase) {
SumoCommand phaseCommand = Trafficlight.setPhase(trafficLightId, phase);
execute(phaseCommand);
}
@Override
public long getRemainingPhaseTime(String trafficLightId) {
SumoCommand nextSwitchCommand = Trafficlight.getNextSwitch(trafficLightId);
Object nextSwitchObject = requestObject(nextSwitchCommand);
long remaingPhaseTime = (long) (((int)nextSwitchObject) - (Simulator.getCurrentTime()/1000.0));
return remaingPhaseTime;
}
@Override @Override
public boolean nextStep() { public boolean nextStep() {
if (Simulator.getEndTime() == Simulator.getCurrentTime()) { if (Simulator.getEndTime() == Simulator.getCurrentTime()) {
......
...@@ -211,6 +211,21 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -211,6 +211,21 @@ public class XMLSimulationController implements VehicleController, SimulationSet
} }
@Override @Override
public int getPhase(String trafficLightId) {
return -1;
}
@Override
public void setPhase(String trafficLightId, int phase) {
}
@Override
public long getRemainingPhaseTime(String trafficLightId) {
return 0;
}
@Override
public double getScenarioWidth() { public double getScenarioWidth() {
return -1; return -1;
} }
......
...@@ -4,10 +4,13 @@ import de.tudarmstadt.maki.simonstrator.api.Host; ...@@ -4,10 +4,13 @@ import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.TrafficLightController; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.TrafficLightController;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkLink;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.trafficlights.TrafficLight; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.trafficlights.TrafficLight;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.trafficlights.TrafficLightInformationComponent; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.trafficlights.TrafficLightInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.trafficlights.TrafficLightState;
import java.util.List; import java.util.List;
import java.util.Map;
public class DefaultTrafficLightInformationComponent implements TrafficLightInformationComponent { public class DefaultTrafficLightInformationComponent implements TrafficLightInformationComponent {
private Host host; private Host host;
...@@ -69,6 +72,26 @@ public class DefaultTrafficLightInformationComponent implements TrafficLightInfo ...@@ -69,6 +72,26 @@ public class DefaultTrafficLightInformationComponent implements TrafficLightInfo
return controller.getControlledEdges(pTrafficLightId); return controller.getControlledEdges(pTrafficLightId);
} }
@Override
public Map<RoadNetworkLink, TrafficLightState> getTrafficLightStateForEachLane() {
return controller.getTrafficLightStateForEachLane(trafficLightId);
}
@Override
public int getPhase() {
return controller.getPhase(trafficLightId);
}
@Override
public void setPhase(int phase) {
controller.setPhase(trafficLightId, phase);
}
@Override
public long getRemainingPhaseTime() {
return controller.getRemainingPhaseTime(trafficLightId);
}
@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