Commit 207c7d24 authored by Tobias Meuser's avatar Tobias Meuser Committed by Jose Ignacio Monreal Bailey
Browse files

Fixed vertically mirrored vehicles bug

    - Introduced function for getting the bounardies of a scenario
        in the SimulationSetupExtractor.
    - Currently only a dummy implementation in the xml-based
        extractor, correct implementation in the TraCI based one
parent d844c6d1
......@@ -34,6 +34,7 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.network.routed.RoutedNetLayer;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.SimulationSetupExtractor;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleController;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController;
......@@ -72,9 +73,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
private final int width;
private final int height;
private double scenarioWidth = 0;
private double scenarioHeight = 0;
private final String sumoExe;
private final String sumoConfigFile;
private final String sumoTrace;
private String sumoIntersections;
private final long timestepConversion = Time.SECOND;
......@@ -84,8 +89,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
private List<Position> intersections;
private String sumoIntersections;
/**
* Constructor for the movement model using the sumo TraCI API
......@@ -221,6 +224,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
if (!initialized) {
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0);
SimulationSetupExtractor extractor;
if (sumoExe != null) {
TraciSimulationController simulationController = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile);
_controller = simulationController;
......@@ -228,7 +232,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_controller.nextStep();
intersections = simulationController.getAllIntersections(true);
extractor = simulationController;
} else {
XMLSimulationController simulationController;
if (sumoIntersections == null || sumoIntersections.equals("")) {
......@@ -242,8 +246,12 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
_controller.init();
_controller.nextStep();
intersections = simulationController.getAllIntersections(true);
extractor = simulationController;
}
intersections = extractor.getAllIntersections(true);
scenarioWidth = extractor.getScenarioWidth();
scenarioHeight = extractor.getScenarioHeight();
System.out.println("Initialization: done.");
}
......@@ -280,7 +288,12 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
}
SimLocationActuator component = requestSimActuator(vehicle);
if (scenarioHeight != -1) {
component.updateCurrentLocation(new PositionVector(position.getX() / SCALING_FACTOR, scenarioHeight - position.getY() / SCALING_FACTOR));
} else {
// This would be vertically mirrored
component.updateCurrentLocation(new PositionVector(position.getX() / SCALING_FACTOR, position.getY() / SCALING_FACTOR));
}
component.setMovementSpeed(position.getSpeed() / SCALING_FACTOR);
......
......@@ -8,6 +8,9 @@ public interface SimulationSetupExtractor {
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
void init();
List<Position> getAllIntersections(boolean pCluster);
double getScenarioWidth();
double getScenarioHeight();
}
......@@ -16,6 +16,7 @@ import de.tudresden.sumo.cmd.Junction;
import de.tudresden.sumo.cmd.Simulation;
import de.tudresden.sumo.cmd.Vehicle;
import de.tudresden.sumo.util.SumoCommand;
import de.tudresden.ws.container.SumoBoundingBox;
import de.tudresden.ws.container.SumoPosition2D;
import de.tudresden.ws.container.SumoStringList;
import it.polito.appeal.traci.SumoTraciConnection;
......@@ -328,4 +329,32 @@ public class TraciSimulationController implements VehicleController, SimulationS
_observedAreaSet = true;
}
@Override
public double getScenarioWidth() {
SumoCommand netBoundaryCommand = Simulation.getNetBoundary();
try {
SumoBoundingBox netBoundary = (SumoBoundingBox) _connection.do_job_get(netBoundaryCommand);
return netBoundary.x_max + netBoundary.x_min;
} catch (Exception e) {
//Nothing to do
}
return -1;
}
@Override
public double getScenarioHeight() {
SumoCommand netBoundaryCommand = Simulation.getNetBoundary();
try {
SumoBoundingBox netBoundary = (SumoBoundingBox) _connection.do_job_get(netBoundaryCommand);
System.out.println(netBoundary.y_max);
System.out.println(netBoundary.y_min);
return netBoundary.y_max + netBoundary.y_min;
} catch (Exception e) {
//Nothing to do
}
return -1;
}
}
......@@ -155,4 +155,14 @@ public class XMLSimulationController implements VehicleController, SimulationSet
return _roadSideUnitInformationHandler.getIntersections();
}
@Override
public double getScenarioWidth() {
return -1;
}
@Override
public double getScenarioHeight() {
return -1;
}
}
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