Commit 9c61f815 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Merge branch 'tm/sumo-integration' into tm/vehicular-services

parents 120c157a 9bd14638
......@@ -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 final Location DEFAULT_LOCATION = new PositionVector(Double.NaN, Double.NaN);
......@@ -95,7 +86,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
private VehicleController _controller;
private SimulationSetupExtractor _extractor;
private List<Position> intersections;
private List<Location> intersections;
/**
* Constructor for the movement model using the sumo TraCI API
......@@ -302,7 +293,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--);
......@@ -311,10 +302,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());
......@@ -420,22 +411,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,7 +11,7 @@ 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();
......@@ -25,11 +25,11 @@ public class SimulationSetupInformationProvider {
return ONLY_INSTANCE;
}
public Position getUpperLeft() {
public Location getUpperLeft() {
return _handler.getUpperLeft();
}
public Position getLowerRight() {
public Location getLowerRight() {
return _handler.getLowerRight();
}
......
/*
* 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,11 +7,12 @@ 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;
......@@ -19,15 +20,15 @@ public class RoadSideUnitInformationHandler {
private double _endX = -1;
private double _endY = -1;
public List<Position> getIntersections() {
public List<Location> getIntersections() {
if (!_observedAreaSet) {
return _positions;
} else {
List<Position> result = new ArrayList<>();
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));
}
}
......@@ -49,7 +50,7 @@ public class RoadSideUnitInformationHandler {
if (split.length == 2) {
double x = Double.parseDouble(split[0]);
double y = Double.parseDouble(split[1]);
_positions.add(new Position(x, y, 0, 0));
_positions.add(new PositionVector(x, y, 0));
}
}
}
......
......@@ -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;
......@@ -47,11 +47,19 @@ import de.tudresden.ws.container.SumoPosition2D;
import de.tudresden.ws.container.SumoStringList;
import it.polito.appeal.traci.SumoTraciConnection;
/**
*
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 06.11.2017
*
*/
public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController, SimulatorObserver {
private static final File TEMP_FILE = new File(new File(System.getProperty("java.io.tmpdir")), "road_network.tmp");
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 +77,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;
......@@ -141,20 +150,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 +178,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;
}
......@@ -217,14 +226,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);
}
}
}
......@@ -245,7 +259,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;
......@@ -255,20 +269,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) {
......@@ -293,10 +301,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);
......@@ -318,7 +366,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,12 +4,13 @@ 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)
......@@ -18,18 +19,18 @@ public class SimulationSetupInformationHandler extends DefaultHandler {
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);
_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() {
public Location getLowerRight() {
return _lowerRight;
}
public Position getUpperLeft() {
public Location getUpperLeft() {
return _upperLeft;
}
}
......@@ -6,12 +6,13 @@ 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 HashMap<String, VehicleInformationContainer> _vehiclePositions = new HashMap<>();
private double _currentStep = -1;
private boolean _observedAreaSet = false;
......@@ -20,7 +21,7 @@ public class VehicleDataInformationHandler extends DefaultHandler {
private double _endX = -1;
private double _endY = -1;
private HashMap<String, Position> _nextVehiclePositions = new HashMap<>();
private HashMap<String, VehicleInformationContainer> _nextVehiclePositions = new HashMap<>();
private double _nextStep = -1;
private static final String doublePattern = "-?[0-9]*\\.?[0-9]+";
......@@ -57,10 +58,10 @@ public class VehicleDataInformationHandler extends DefaultHandler {
if (_observedAreaSet) {
if (_startX <= lon && lon <= _endX && _startY <= lat && lat <= _endY) {
_nextVehiclePositions.put(id, new Position(lon - _startX, lat - _startY, 0, heading, speed));
_nextVehiclePositions.put(id, new VehicleInformationContainer(new PositionVector(lon - _startX, lat - _startY, 0), heading, speed));
}
} else {
_nextVehiclePositions.put(id, new Position(lon, lat, 0, heading, speed));
_nextVehiclePositions.put(id, new VehicleInformationContainer(new PositionVector(lon, lat, 0), heading, speed));
}
}
}
......@@ -97,7 +98,7 @@ public class VehicleDataInformationHandler extends DefaultHandler {
return _terminated;
}
public HashMap<String, Position> getVehiclePositions() {
public HashMap<String, VehicleInformationContainer> getVehiclePositions() {
return _vehiclePositions;
}
......
......@@ -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