Commit 4309100d authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Removed Position class

parent 3a0945f2
......@@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
......@@ -33,23 +32,14 @@ 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.sumo.simulation.controller.traci.TraciSimulationController;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.future_location.FutureLocationSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class RSUMovementModel implements MovementModel, FutureLocationSensor {
public class RSUMovementModel implements MovementModel {
private final List<SimLocationActuator> components;
......@@ -69,7 +59,7 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor {
private SimulationSetupExtractor _controller;
private List<Position> _intersections;
private List<Location> _intersections;
private int _currentIndex = 0;
private final Map<INodeID, Integer> hostIntersectionMatching = new HashMap<>();
......@@ -107,40 +97,6 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor {
@Override
public final void addComponent(SimLocationActuator comp) {
components.add(comp);
try {
final SiSComponent sis = comp.getHost().getComponent(SiSComponent.class);
sis.provide().nodeState(SiSTypes.FUTURE_PHY_LOCATION,
new SiSDataCallback<Location>() {
Set<INodeID> localID = INodeID
.getSingleIDSet(comp.getHost().getId());
@Override
public Location getValue(INodeID nodeID,
SiSProviderHandle providerHandle)
throws InformationNotAvailableException {
if (nodeID.equals(comp.getHost().getId())) {
return getFutureLocation(comp.getHost());
} else {
throw new InformationNotAvailableException();
}
}
@Override
public Set<INodeID> getObservedNodes() {
return localID;
}
@Override
public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties();
}
});
} catch (ComponentNotAvailableException e) {
// Nothing to do
}
}
@Override
......@@ -156,8 +112,8 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor {
}
if (_currentIndex < _intersections.size()) {
// Initial placement
Position intersection = _intersections.get(_currentIndex);
actuator.updateCurrentLocation(new PositionVector(intersection.getX(), intersection.getY()));
Location intersection = _intersections.get(_currentIndex);
actuator.updateCurrentLocation(new PositionVector(intersection.getLongitude(), intersection.getLatitude()));
hostIntersectionMatching.put(actuator.getHost().getId(), _currentIndex);
......@@ -198,17 +154,4 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor {
// System.out.println("Require " + _intersections.size() + " RSUs");
}
@Override
public Location getFutureLocation(Host pHost) {
if (hostIntersectionMatching.containsKey(pHost.getId())) {
int intersection = hostIntersectionMatching.get(pHost.getId());
Position intersectionPosition = _intersections.get(intersection);
if (intersectionPosition != null) {
return new PositionVector(intersectionPosition.getX(), intersectionPosition.getY());
}
}
return null;
}
}
\ No newline at end of file
......@@ -26,7 +26,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
......@@ -42,22 +41,14 @@ import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.future_location.FutureLocationSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class VehicleMovementModel implements MovementModel, EventHandler, FutureLocationSensor {
public class VehicleMovementModel implements MovementModel, EventHandler {
private static VehicleMovementModel MOVEMENT;
......@@ -91,7 +82,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
private VehicleController _controller;
private SimulationSetupExtractor _extractor;
private List<Position> intersections;
private List<Location> intersections;
/**
......@@ -188,39 +179,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
}
// Initial placement
actuator.updateCurrentLocation(new PositionVector(Double.NaN, Double.NaN));
try {
final SiSComponent sis = actuator.getHost().getComponent(SiSComponent.class);
sis.provide().nodeState(SiSTypes.FUTURE_PHY_LOCATION,
new SiSDataCallback<Location>() {
Set<INodeID> localID = INodeID
.getSingleIDSet(actuator.getHost().getId());
@Override
public Location getValue(INodeID nodeID,
SiSProviderHandle providerHandle)
throws InformationNotAvailableException {
if (nodeID.equals(actuator.getHost().getId())) {
return getFutureLocation(actuator.getHost());
} else {
throw new InformationNotAvailableException();
}
}
@Override
public Set<INodeID> getObservedNodes() {
return localID;
}
@Override
public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties();
}
});
} catch (ComponentNotAvailableException e) {
// Nothing to do
}
}
/**
......@@ -289,7 +247,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
for (int i = 0; i < allVehicles.size(); i++) {
String vehicle = allVehicles.get(i);
Position position = _controller.getVehiclePosition(vehicle);
Location position = _controller.getVehiclePosition(vehicle);
if (position == null) {
allVehicles.remove(i--);
......@@ -298,10 +256,10 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
SimLocationActuator component = requestSimActuator(vehicle);
if (scenarioHeight != -1) {
component.updateCurrentLocation(new PositionVector(position.getX(), Math.min(scenarioHeight, height) - position.getY()));
component.updateCurrentLocation(new PositionVector(position.getLongitude(), Math.min(scenarioHeight, height) - position.getLatitude()));
} else {
// This would be vertically mirrored
component.updateCurrentLocation(new PositionVector(position.getX(), position.getY()));
component.updateCurrentLocation(new PositionVector(position.getLongitude(), position.getLatitude()));
}
component.setMovementSpeed(position.getSpeed());
......@@ -400,22 +358,4 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
public static RoadNetwork getRoadNetwork() {
return MOVEMENT._extractor.getRoadNetwork();
}
/**
* Returns the future location of a certain host.
* @param pHost The host for which the location is being requested.
* @return The future location of the host.
*/
@Override
public Location getFutureLocation(Host pHost) {
if (hostVehicleIDMatching.containsKey(pHost.getId())) {
String vehicleID = hostVehicleIDMatching.get(pHost.getId());
Position vehiclePosition = _controller.getVehiclePosition(_controller.getMaximumAvailablePrediction(), vehicleID);
if (vehiclePosition != null) {
return new PositionVector(vehiclePosition.getX(), vehiclePosition.getY());
}
}
return null;
}
}
......@@ -11,36 +11,36 @@ import org.xml.sax.SAXException;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.CancelParsingSAXException;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.SimulationSetupInformationHandler;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class SimulationSetupInformationProvider {
private static final SimulationSetupInformationProvider ONLY_INSTANCE = new SimulationSetupInformationProvider();
private SimulationSetupInformationHandler _handler = new SimulationSetupInformationHandler();
private SimulationSetupInformationProvider() {
}
public static SimulationSetupInformationProvider getOnlyInstance() {
return ONLY_INSTANCE;
}
public Position getUpperLeft() {
return _handler.getUpperLeft();
}
public Position getLowerRight() {
return _handler.getLowerRight();
}
public static void init(String pNetFileLocation) {
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(new FileInputStream(pNetFileLocation), ONLY_INSTANCE._handler);
} catch (CancelParsingSAXException e) {
return;
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
}
}
private static final SimulationSetupInformationProvider ONLY_INSTANCE = new SimulationSetupInformationProvider();
private SimulationSetupInformationHandler _handler = new SimulationSetupInformationHandler();
private SimulationSetupInformationProvider() {
}
public static SimulationSetupInformationProvider getOnlyInstance() {
return ONLY_INSTANCE;
}
public Location getUpperLeft() {
return _handler.getUpperLeft();
}
public Location getLowerRight() {
return _handler.getLowerRight();
}
public static void init(String pNetFileLocation) {
try {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
parser.parse(new FileInputStream(pNetFileLocation), ONLY_INSTANCE._handler);
} catch (CancelParsingSAXException e) {
return;
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
}
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class VehicleInformationContainer {
private Location _position;
private double _heading;
private double _speed;
public VehicleInformationContainer(Location pPosition, double pHeading,
double pSpeed) {
_position = pPosition;
_heading = pHeading;
_speed = pSpeed;
}
public Location getPosition() {
return _position;
}
public double getHeading() {
return _heading;
}
public double getSpeed() {
return _speed;
}
}
\ No newline at end of file
......@@ -7,64 +7,65 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class RoadSideUnitInformationHandler {
private List<Position> _positions = new ArrayList<>();
private List<Location> _positions = new ArrayList<>();
private boolean _observedAreaSet = false;
private double _startX = -1;
private double _startY = -1;
private double _endX = -1;
private double _endY = -1;
private boolean _observedAreaSet = false;
private double _startX = -1;
private double _startY = -1;
private double _endX = -1;
private double _endY = -1;
public List<Position> getIntersections() {
if (!_observedAreaSet) {
return _positions;
} else {
List<Position> result = new ArrayList<>();
public List<Location> getIntersections() {
if (!_observedAreaSet) {
return _positions;
} else {
List<Location> result = new ArrayList<>();
for (Position position : _positions) {
if (_startX <= position.getX() && position.getX() <= _endX && _startY <= position.getY() && position.getY() <= _endY) {
result.add(new Position(position.getX() - _startX, position.getY() - _startY, 0, 0));
}
}
for (Location position : _positions) {
if (_startX <= position.getLongitude() && position.getLongitude() <= _endX && _startY <= position.getLatitude() && position.getLatitude() <= _endY) {
result.add(new PositionVector(position.getLongitude() - _startX, position.getLatitude() - _startY, 0));
}
}
return result;
}
}
return result;
}
}
public void parseIntersectionsFile(String pRoadSideUnitDataPath) {
File file = new File(pRoadSideUnitDataPath);
try {
FileInputStream inputStream = new FileInputStream(file);
Scanner scanner = new Scanner(inputStream);
public void parseIntersectionsFile(String pRoadSideUnitDataPath) {
File file = new File(pRoadSideUnitDataPath);
try {
FileInputStream inputStream = new FileInputStream(file);
Scanner scanner = new Scanner(inputStream);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.contains(";")) {
String[] split = line.split(";");
if (split.length == 2) {
double x = Double.parseDouble(split[0]);
double y = Double.parseDouble(split[1]);
_positions.add(new Position(x, y, 0, 0));
}
}
}
scanner.close();
} catch (FileNotFoundException e) {
throw new UnsupportedOperationException("Unable to read file", e);
}
}
if (line.contains(";")) {
String[] split = line.split(";");
if (split.length == 2) {
double x = Double.parseDouble(split[0]);
double y = Double.parseDouble(split[1]);
_positions.add(new PositionVector(x, y, 0));
}
}
}
scanner.close();
} catch (FileNotFoundException e) {
throw new UnsupportedOperationException("Unable to read file", e);
}
}
public void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY) {
_startX = pStartX;
_startY = pStartY;
_endX = pEndX;
_endY = pEndY;
public void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY) {
_startX = pStartX;
_startY = pStartY;
_endX = pEndX;
_endY = pEndY;
_observedAreaSet = true;
}
_observedAreaSet = true;
}
}
......@@ -16,14 +16,14 @@ import java.util.Random;
import de.tud.kom.p2psim.api.simengine.SimulatorObserver;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.EdgeController;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.LocationUtils;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkLane;
......@@ -52,6 +52,8 @@ public class TraciSimulationController implements VehicleController, SimulationS
private Random _random = Randoms.getRandom(getClass());
private List<RoadNetworkEdge> modifiedEdges = new ArrayList<>();
private static final Map<String, TraciSimulationController> CONTROLLER = new HashMap<>();
private static final double CLUSTERING_DISTANCE = 50;
......@@ -69,7 +71,8 @@ public class TraciSimulationController implements VehicleController, SimulationS
private double _endX;
private double _endY;
private Map<Double, Map<String, Position>> _positonsByTimestamp = new HashMap<>();
private Map<Double, Map<String, VehicleInformationContainer>> _positonsByTimestamp = new HashMap<>();
private int _futureInformation = 0;
private boolean _initalized = false;
......@@ -106,11 +109,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
// This will only work with the updated version of the TraaS API for sumo
// It is available for download at https://dev.kom.e-technik.tu-darmstadt.de/gitlab/tobiasm/TraaS.git
_connection = new SumoTraciConnection(_sumoExe, _configFile, random.nextInt());
/*
/*
* prevent vehicles form teleporting (http://sumo.dlr.de/wiki/Simulation/Why_Vehicles_are_teleporting)
*/
_connection.addOption("time-to-teleport", Integer.toString(-1));
try {
_connection.runServer();
......@@ -128,7 +131,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
_initalized = true;
}
}
@Override
public void simulationFinished() {
/*
......@@ -141,20 +144,20 @@ public class TraciSimulationController implements VehicleController, SimulationS
}
@Override
public Position getVehiclePosition(String pVehicleID) {
public Location getVehiclePosition(String pVehicleID) {
return getVehiclePosition(_step, pVehicleID);
}
@Override
public Position getVehiclePosition(double pStep, String pVehicleID) {
Map<String, Position> map = _positonsByTimestamp.get(pStep);
public Location getVehiclePosition(double pStep, String pVehicleID) {
Map<String, VehicleInformationContainer> map = _positonsByTimestamp.get(pStep);
return map.get(pVehicleID);
return map.get(pVehicleID).getPosition();
}
@Override
public List<Position> getAllIntersections(boolean pCluster) {
List<Position> result = new ArrayList<>();
public List<Location> getAllIntersections(boolean pCluster) {
List<Location> result = new ArrayList<>();
SumoCommand intersectionCommand = Junction.getIDList();
......@@ -169,21 +172,21 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (_observedAreaSet) {
if (_startX <= sumoPosition.x && sumoPosition.x <= _endX && _startY <= sumoPosition.y && sumoPosition.y <= _endY) {
result.add(new Position(sumoPosition.x - _startX, sumoPosition.y - _startY, 0, 0));
result.add(new PositionVector(sumoPosition.x - _startX, sumoPosition.y - _startY, 0));
}
} else {
result.add(new Position(sumoPosition.x, sumoPosition.y, 0, 0));
result.add(new PositionVector(sumoPosition.x, sumoPosition.y, 0));
}
}
if (pCluster) {
List<Position> tempResult = new ArrayList<>();
List<Location> tempResult = new ArrayList<>();
outer:for (int i = 0; i < result.size(); i++) {
Position position = result.get(i);
Location position = result.get(i);
for (int j = 0; j < tempResult.size(); j++) {
Position addedPosition = tempResult.get(j);
Location addedPosition = tempResult.get(j);
if (position != addedPosition && LocationUtils.calculateDistance(position, addedPosition) < CLUSTERING_DISTANCE / 1000.0) {
continue outer;
}
......@@ -204,13 +207,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
return false;
}
try {
// for (RoadNetworkEdge roadNetworkEdge : modifiedEdges) {
// SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(roadNetworkEdge.getEdgeID(), roadNetworkEdge.getOriginalMaxSpeed());
//
// execute(setMaxSpeedCommand);
// }
_connection.do_timestep();
try {
......@@ -224,14 +220,19 @@ public class TraciSimulationController implements VehicleController, SimulationS
double newStep = _step + _futureInformation;
if (!_positonsByTimestamp.containsKey(newStep)) {
Map<String, Position> vehiclePositions = new HashMap<>();
Map<String, VehicleInformationContainer> vehiclePositions = new HashMap<>();
_positonsByTimestamp.put(newStep, vehiclePositions);
List<String> allVehicles = requestAllVehicles();
for (String vehicle : allVehicles) {
Position vehiclePosition = requestVehiclePosition(vehicle);
if (vehiclePosition != null) {
vehiclePositions.put(vehicle, vehiclePosition);
Location position = requestVehiclePosition(vehicle);
if (position != null) {
double heading = requestVehicleHeading(vehicle);
double speed = requestVehicleSpeed(vehicle);
VehicleInformationContainer informationContainer = new VehicleInformationContainer(position, heading, speed);
vehiclePositions.put(vehicle, informationContainer);
}
}
}
......@@ -243,12 +244,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
e.printStackTrace();
}
// for (RoadNetworkEdge roadNetworkEdge : modifiedEdges) {
// SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(roadNetworkEdge.getEdgeID(), roadNetworkEdge.getMaxSpeed());
//
// execute(setMaxSpeedCommand);
// }
return true;
} catch (RuntimeException e) {
throw e;
......@@ -258,7 +253,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
return false;
}
private Position requestVehiclePosition(String pVehicleID) {
private Location requestVehiclePosition(String pVehicleID) {
if (_vehiclesOutOfRange.containsKey(pVehicleID)) {
if (_vehiclesOutOfRange.get(pVehicleID) < _step) {
return null;
......@@ -268,20 +263,14 @@ public class TraciSimulationController implements VehicleController, SimulationS
}
SumoCommand positionCommand = Vehicle.getPosition(pVehicleID);
SumoCommand angleCommand = Vehicle.getAngle(pVehicleID);
SumoCommand speedCommand = Vehicle.getSpeed(pVehicleID);
Object positionObject = requestObject(positionCommand);
Object angleObject = requestObject(angleCommand);
Object speedObject = requestObject(speedCommand);
SumoPosition2D sumoPosition = (SumoPosition2D) positionObject;
double angle = (Double) angleObject;
double speed = (Double) speedObject;
if (_observedAreaSet) {
if (_startX <= sumoPosition.x && sumoPosition.x <= _endX && _startY <= sumoPosition.y && sumoPosition.y <= _endY) {
return new Position(sumoPosition.x - _startX, sumoPosition.y - _startY, 0, angle, speed);
return new PositionVector(sumoPosition.x - _startX, sumoPosition.y - _startY, 0);
} else {
double diffX = _startX - sumoPosition.x;
if (diffX < 0 || sumoPosition.x - _endX < diffX) {
......@@ -306,10 +295,50 @@ public class TraciSimulationController implements VehicleController, SimulationS
return null;
}
} else {
return new Position(sumoPosition.x, sumoPosition.y, 0, angle);
return new PositionVector(sumoPosition.x, sumoPosition.y, 0);
}
}
private double requestVehicleHeading(String pVehicleID) {
if (_vehiclesOutOfRange.containsKey(pVehicleID)) {
if (_vehiclesOutOfRange.get(pVehicleID) < _step) {
return -1;
} else {
_vehiclesOutOfRange.remove(pVehicleID);
}
}
SumoCommand angleCommand = Vehicle.getAngle(pVehicleID);
Object angleObject = requestObject(angleCommand);
if (angleObject != null) {
return (Double) angleObject;
}
return -1;
}
private double requestVehicleSpeed(String pVehicleID) {
if (_vehiclesOutOfRange.containsKey(pVehicleID)) {
if (_vehiclesOutOfRange.get(pVehicleID) < _step) {
return -1;
} else {
_vehiclesOutOfRange.remove(pVehicleID);
}
}
SumoCommand speedCommand = Vehicle.getSpeed(pVehicleID);
Object speedObject = requestObject(speedCommand);
if (speedObject != null) {
return (Double) speedObject;
}
return -1;
}
private List<String> requestAllVehicles() {
SumoCommand idList = Vehicle.getIDList();
Object object = requestObject(idList);
......@@ -331,7 +360,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
@Override
public List<String> getAllVehicles(double pStep) {
Map<String, Position> map = _positonsByTimestamp.get(pStep);
Map<String, VehicleInformationContainer> map = _positonsByTimestamp.get(pStep);
return new ArrayList<>(map.keySet());
}
......
......@@ -4,32 +4,33 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class SimulationSetupInformationHandler extends DefaultHandler {
private Position _upperLeft;
private Position _lowerRight;
private Location _upperLeft;
private Location _lowerRight;
@Override
public void startElement(String pUri, String pLocalName, String pQName, Attributes pAttributes)
throws SAXException {
if (pQName.equals("location")) {
String meterBoundary = pAttributes.getValue("convBoundary");
if (meterBoundary != null) {
String[] edges = meterBoundary.split(",");
_upperLeft = new Position(Double.valueOf(edges[0]), Double.valueOf(edges[1]), 0, 0);
_lowerRight = new Position(Double.valueOf(edges[2]), Double.valueOf(edges[3]), 0, 0);
}
throw new CancelParsingSAXException();
}
}
@Override
public void startElement(String pUri, String pLocalName, String pQName, Attributes pAttributes)
throws SAXException {
if (pQName.equals("location")) {
String meterBoundary = pAttributes.getValue("convBoundary");
if (meterBoundary != null) {
String[] edges = meterBoundary.split(",");
_upperLeft = new PositionVector(Double.valueOf(edges[0]), Double.valueOf(edges[1]), 0);
_lowerRight = new PositionVector(Double.valueOf(edges[2]), Double.valueOf(edges[3]), 0);
}
throw new CancelParsingSAXException();
}
}
public Position getLowerRight() {
return _lowerRight;
}
public Location getLowerRight() {
return _lowerRight;
}
public Position getUpperLeft() {
return _upperLeft;
}
public Location getUpperLeft() {
return _upperLeft;
}
}
......@@ -6,123 +6,124 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer;
public class VehicleDataInformationHandler extends DefaultHandler {
private boolean _next = true;
private boolean _run = true;
private HashMap<String, Position> _vehiclePositions = new HashMap<>();
private double _currentStep = -1;
private boolean _observedAreaSet = false;
private double _startX = -1;
private double _startY = -1;
private double _endX = -1;
private double _endY = -1;
private HashMap<String, Position> _nextVehiclePositions = new HashMap<>();
private double _nextStep = -1;
private static final String doublePattern = "-?[0-9]*\\.?[0-9]+";
private boolean _terminated = false;
@Override
public void startElement(String pUri, String pLocalName, String pQName, Attributes pAttributes)
throws SAXException {
if (pQName.equals("timestep")) {
while (!_next) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
_next = false;
String value = pAttributes.getValue("time");
if (value.matches(doublePattern)) {
_nextStep = Double.valueOf(value);
}
} else if (pQName.equals("vehicle")) {
String id = pAttributes.getValue("id");
String lonString = pAttributes.getValue("x");
String latString = pAttributes.getValue("y");
String speedString = pAttributes.getValue("speed");
String headingString = pAttributes.getValue("angle");
if (lonString.matches(doublePattern) && latString.matches(doublePattern) && headingString.matches(doublePattern) && speedString.matches(doublePattern) ) {
double lon = Double.valueOf(lonString);
double lat = Double.valueOf(latString);
double heading = Double.valueOf(headingString);
double speed = Double.valueOf(speedString);
if (_observedAreaSet) {
if (_startX <= lon && lon <= _endX && _startY <= lat && lat <= _endY) {
_nextVehiclePositions.put(id, new Position(lon - _startX, lat - _startY, 0, heading, speed));
}
} else {
_nextVehiclePositions.put(id, new Position(lon, lat, 0, heading, speed));
}
}
}
}
@Override
public void endElement(String pUri, String pLocalName, String pQName) throws SAXException {
if (pQName.equals("timestep")) {
_run = false;
} else if (pQName.equals("fcd-export")) {
while (!_next) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
_next = false;
_run = false;
_terminated = true;
}
}
public void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY) {
_startX = pStartX;
_startY = pStartY;
_endX = pEndX;
_endY = pEndY;
_observedAreaSet = true;
}
public boolean isTerminated() {
return _terminated;
}
public HashMap<String, Position> getVehiclePositions() {
return _vehiclePositions;
}
public void readNext() {
while (_run) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
_vehiclePositions = _nextVehiclePositions;
_currentStep = _nextStep;
_nextStep = -1;
_nextVehiclePositions = new HashMap<>();
_run = true;
_next = true;
}
public boolean isRunning() {
return _run;
}
public double getStep() {
return _currentStep;
}
private boolean _next = true;
private boolean _run = true;
private HashMap<String, VehicleInformationContainer> _vehiclePositions = new HashMap<>();
private double _currentStep = -1;
private boolean _observedAreaSet = false;
private double _startX = -1;
private double _startY = -1;
private double _endX = -1;
private double _endY = -1;
private HashMap<String, VehicleInformationContainer> _nextVehiclePositions = new HashMap<>();
private double _nextStep = -1;
private static final String doublePattern = "-?[0-9]*\\.?[0-9]+";
private boolean _terminated = false;
@Override
public void startElement(String pUri, String pLocalName, String pQName, Attributes pAttributes)
throws SAXException {
if (pQName.equals("timestep")) {
while (!_next) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
_next = false;
String value = pAttributes.getValue("time");
if (value.matches(doublePattern)) {
_nextStep = Double.valueOf(value);
}
} else if (pQName.equals("vehicle")) {
String id = pAttributes.getValue("id");
String lonString = pAttributes.getValue("x");
String latString = pAttributes.getValue("y");
String speedString = pAttributes.getValue("speed");
String headingString = pAttributes.getValue("angle");
if (lonString.matches(doublePattern) && latString.matches(doublePattern) && headingString.matches(doublePattern) && speedString.matches(doublePattern) ) {
double lon = Double.valueOf(lonString);
double lat = Double.valueOf(latString);
double heading = Double.valueOf(headingString);
double speed = Double.valueOf(speedString);
if (_observedAreaSet) {
if (_startX <= lon && lon <= _endX && _startY <= lat && lat <= _endY) {
_nextVehiclePositions.put(id, new VehicleInformationContainer(new PositionVector(lon - _startX, lat - _startY, 0), heading, speed));
}
} else {
_nextVehiclePositions.put(id, new VehicleInformationContainer(new PositionVector(lon, lat, 0), heading, speed));
}
}
}
}
@Override
public void endElement(String pUri, String pLocalName, String pQName) throws SAXException {
if (pQName.equals("timestep")) {
_run = false;
} else if (pQName.equals("fcd-export")) {
while (!_next) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
_next = false;
_run = false;
_terminated = true;
}
}
public void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY) {
_startX = pStartX;
_startY = pStartY;
_endX = pEndX;
_endY = pEndY;
_observedAreaSet = true;
}
public boolean isTerminated() {
return _terminated;
}
public HashMap<String, VehicleInformationContainer> getVehiclePositions() {
return _vehiclePositions;
}
public void readNext() {
while (_run) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
_vehiclePositions = _nextVehiclePositions;
_currentStep = _nextStep;
_nextStep = -1;
_nextVehiclePositions = new HashMap<>();
_run = true;
_next = true;
}
public boolean isRunning() {
return _run;
}
public double getStep() {
return _currentStep;
}
}
......@@ -10,10 +10,11 @@ import java.util.Map;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv.RoadSideUnitInformationHandler;
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.VehicleController;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
......@@ -26,7 +27,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet
private List<String> _vehicles;
private Map<Double, Map<String, Position>> _positonsByTimestamp = new HashMap<>();
private Map<Double, Map<String, VehicleInformationContainer>> _positonsByTimestamp = new HashMap<>();
private int _futureInformation = 10;
private boolean _initalized = false;
......@@ -67,11 +68,11 @@ public class XMLSimulationController implements VehicleController, SimulationSet
}
@Override
public Position getVehiclePosition(String pVehicleID) {
public Location getVehiclePosition(String pVehicleID) {
return getVehiclePosition(_step, pVehicleID);
}
public Position requestVehiclePosition(String pVehicleID) {
public VehicleInformationContainer requestVehicleInformation(String pVehicleID) {
return _vehicleDataInformationHandler.getVehiclePositions().get(pVehicleID);
}
......@@ -86,12 +87,12 @@ public class XMLSimulationController implements VehicleController, SimulationSet
double newStep = _step + _futureInformation;
if (!_positonsByTimestamp.containsKey(newStep)) {
Map<String, Position> vehiclePositions = new HashMap<>();
Map<String, VehicleInformationContainer> vehiclePositions = new HashMap<>();
_positonsByTimestamp.put(newStep, vehiclePositions);
List<String> allVehicles = new ArrayList<>(_vehicleDataInformationHandler.getVehiclePositions().keySet());
for (String vehicle : allVehicles) {
Position vehiclePosition = requestVehiclePosition(vehicle);
VehicleInformationContainer vehiclePosition = requestVehicleInformation(vehicle);
if (vehiclePosition != null) {
vehiclePositions.put(vehicle, vehiclePosition);
}
......@@ -135,15 +136,15 @@ public class XMLSimulationController implements VehicleController, SimulationSet
}
@Override
public Position getVehiclePosition(double pStep, String pVehicleID) {
Map<String, Position> map = _positonsByTimestamp.get(pStep);
public Location getVehiclePosition(double pStep, String pVehicleID) {
Map<String, VehicleInformationContainer> map = _positonsByTimestamp.get(pStep);
return map.get(pVehicleID);
return map.get(pVehicleID).getPosition();
}
@Override
public List<String> getAllVehicles(double pStep) {
Map<String, Position> map = _positonsByTimestamp.get(pStep);
Map<String, VehicleInformationContainer> map = _positonsByTimestamp.get(pStep);
return new ArrayList<>(map.keySet());
}
......@@ -156,7 +157,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet
}
@Override
public List<Position> getAllIntersections(boolean pCluster) {
public List<Location> getAllIntersections(boolean pCluster) {
return _roadSideUnitInformationHandler.getIntersections();
}
......
......@@ -25,11 +25,10 @@ import java.util.List;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.VehicleMovementModel;
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;
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.information.Position;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
......@@ -48,7 +47,7 @@ public class RSUPlacement implements PlacementModel {
private SimulationSetupExtractor _controller;
private List<Position> _intersections;
private List<Location> _intersections;
private int _currentIndex = 0;
@XMLConfigurableConstructor({ "sumoExe", "sumoConfigFile", "offsetX", "offsetY", "width", "height" })
......@@ -107,9 +106,9 @@ public class RSUPlacement implements PlacementModel {
@Override
public PositionVector place(TopologyComponent comp) {
if (_currentIndex < _intersections.size()) {
Position intersection = _intersections.get(_currentIndex);
Location intersection = _intersections.get(_currentIndex);
_currentIndex++;
return new PositionVector(intersection.getX(), intersection.getY());
return new PositionVector(intersection.getLongitude(), intersection.getLatitude());
} else {
return new PositionVector(Double.NaN, Double.NaN);
}
......
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