Commit 02e300e9 authored by Tobias Meuser's avatar Tobias Meuser Committed by Jose Ignacio Monreal Bailey
Browse files

Added vehicle component to access information about the vehicle

parent 297b5534
...@@ -38,6 +38,7 @@ import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.contro ...@@ -38,6 +38,7 @@ import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.contro
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.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.traci.TraciSimulationController;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController;
import de.tud.kom.p2psim.impl.vehicular.DefaultVehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
...@@ -52,6 +53,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties; ...@@ -52,6 +53,7 @@ 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.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException; 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.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class VehicleMovementModel implements MovementModel, EventHandler, FutureLocationSensor { public class VehicleMovementModel implements MovementModel, EventHandler, FutureLocationSensor {
...@@ -88,6 +90,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -88,6 +90,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
private boolean initialized = false; private boolean initialized = false;
private VehicleController _controller; private VehicleController _controller;
private SimulationSetupExtractor _extractor;
private List<Position> intersections; private List<Position> intersections;
...@@ -226,7 +229,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -226,7 +229,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
if (!initialized) { if (!initialized) {
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0); Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0);
SimulationSetupExtractor extractor;
if (sumoExe != null) { if (sumoExe != null) {
TraciSimulationController simulationController = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile); TraciSimulationController simulationController = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile);
_controller = simulationController; _controller = simulationController;
...@@ -234,7 +236,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -234,7 +236,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
_controller.init(); _controller.init();
_controller.nextStep(); _controller.nextStep();
extractor = simulationController; _extractor = simulationController;
} else { } else {
XMLSimulationController simulationController; XMLSimulationController simulationController;
if (sumoIntersections == null || sumoIntersections.equals("")) { if (sumoIntersections == null || sumoIntersections.equals("")) {
...@@ -248,12 +250,12 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -248,12 +250,12 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
_controller.init(); _controller.init();
_controller.nextStep(); _controller.nextStep();
extractor = simulationController; _extractor = simulationController;
} }
intersections = extractor.getAllIntersections(true); intersections = _extractor.getAllIntersections(true);
scenarioWidth = extractor.getScenarioWidth(); scenarioWidth = _extractor.getScenarioWidth();
scenarioHeight = extractor.getScenarioHeight(); scenarioHeight = _extractor.getScenarioHeight();
System.out.println("Initialization: done."); System.out.println("Initialization: done.");
} }
...@@ -299,6 +301,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -299,6 +301,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
component.setMovementSpeed(position.getSpeed() / SCALING_FACTOR); component.setMovementSpeed(position.getSpeed() / SCALING_FACTOR);
try {
VehicleInformationComponent vehicularHostComponent = component.getHost().getComponent(VehicleInformationComponent.class);
System.out.println(vehicularHostComponent.getCurrentRoute());
} catch (ComponentNotAvailableException e) {
// Nothing to do here
}
try { try {
RoutedNetLayer routedNetLayer = component.getHost().getComponent(RoutedNetLayer.class); RoutedNetLayer routedNetLayer = component.getHost().getComponent(RoutedNetLayer.class);
for (SimNetInterface netInterface : routedNetLayer.getSimNetworkInterfaces()) { for (SimNetInterface netInterface : routedNetLayer.getSimNetworkInterfaces()) {
...@@ -347,6 +356,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -347,6 +356,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
if (idComponentMatcher.containsKey(vehicleID)) { if (idComponentMatcher.containsKey(vehicleID)) {
SimLocationActuator simLocationActuator = idComponentMatcher.remove(vehicleID); SimLocationActuator simLocationActuator = idComponentMatcher.remove(vehicleID);
if (simLocationActuator != null) { if (simLocationActuator != null) {
try {
VehicleInformationComponent vehicularHostComponent = simLocationActuator.getHost().getComponent(VehicleInformationComponent.class);
vehicularHostComponent.resetVehicleID();
} catch (ComponentNotAvailableException e) {
// Nothing to do here
}
freeComponents.add(simLocationActuator); freeComponents.add(simLocationActuator);
hostVehicleIDMatching.remove(simLocationActuator.getHost().getId()); hostVehicleIDMatching.remove(simLocationActuator.getHost().getId());
} }
...@@ -362,6 +378,17 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -362,6 +378,17 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
private SimLocationActuator requestSimActuator(String vehicle) { private SimLocationActuator requestSimActuator(String vehicle) {
if (!idComponentMatcher.containsKey(vehicle)) { if (!idComponentMatcher.containsKey(vehicle)) {
SimLocationActuator simLocationActuator = freeComponents.poll(); SimLocationActuator simLocationActuator = freeComponents.poll();
VehicleInformationComponent vehicularHostComponent;
try {
vehicularHostComponent = simLocationActuator.getHost().getComponent(VehicleInformationComponent.class);
} catch (ComponentNotAvailableException e) {
Host host = simLocationActuator.getHost();
vehicularHostComponent = new DefaultVehicleInformationComponent(host, _controller, _extractor);
host.registerComponent(vehicularHostComponent);
}
vehicularHostComponent.setVehicleID(vehicle);
if (simLocationActuator != null) { if (simLocationActuator != null) {
idComponentMatcher.put(vehicle, simLocationActuator); idComponentMatcher.put(vehicle, simLocationActuator);
hostVehicleIDMatching.put(simLocationActuator.getHost().getId(), vehicle); hostVehicleIDMatching.put(simLocationActuator.getHost().getId(), vehicle);
......
...@@ -3,6 +3,7 @@ package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.contr ...@@ -3,6 +3,7 @@ package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.contr
import java.util.List; import java.util.List;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position; import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
public interface VehicleController { public interface VehicleController {
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY); void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
...@@ -15,6 +16,8 @@ public interface VehicleController { ...@@ -15,6 +16,8 @@ public interface VehicleController {
List<String> getAllVehicles(); List<String> getAllVehicles();
List<String> getAllVehicles(double pStep); List<String> getAllVehicles(double pStep);
RoadNetworkRoute getCurrentRoute(String pVehicleID);
double getMaximumAvailablePrediction(); double getMaximumAvailablePrediction();
double getStep(); double getStep();
...@@ -22,4 +25,5 @@ public interface VehicleController { ...@@ -22,4 +25,5 @@ public interface VehicleController {
void init(); void init();
} }
...@@ -288,17 +288,34 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -288,17 +288,34 @@ public class TraciSimulationController implements VehicleController, SimulationS
return new ArrayList<>(map.keySet()); return new ArrayList<>(map.keySet());
} }
public RoadNetworkRoute getRoute(String pVehicleID) { @Override
public RoadNetworkRoute getCurrentRoute(String pVehicleID) {
SumoCommand routeCommand = Vehicle.getRoute(pVehicleID); SumoCommand routeCommand = Vehicle.getRoute(pVehicleID);
Object object = requestObject(routeCommand); Object object = requestObject(routeCommand);
SumoStringList streetList = (SumoStringList) object; SumoStringList streetList = (SumoStringList) object;
SumoCommand roadIDCommand = Vehicle.getRoadID(pVehicleID);
String currentRoadID = (String) requestObject(roadIDCommand);
obtainRoadNetwork(); obtainRoadNetwork();
List<RoadNetworkEdge> streets = new ArrayList<>(); List<RoadNetworkEdge> streets = new ArrayList<>();
boolean add = false;
for (String street : streetList) {
if (street.equals(currentRoadID)) {
add = true;
}
if (add) {
streets.add(_roadNetwork.getEdge(street));
}
}
if (streets.size() == 0) {
for (String street : streetList) { for (String street : streetList) {
streets.add(_roadNetwork.getEdge(street)); streets.add(_roadNetwork.getEdge(street));
} }
}
return new RoadNetworkRoute(streets); return new RoadNetworkRoute(streets);
} }
...@@ -383,7 +400,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -383,7 +400,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
} }
public RoadNetworkEdge getVehicleDestination(String pVehicleID) { public RoadNetworkEdge getVehicleDestination(String pVehicleID) {
RoadNetworkRoute roadNetworkRoute = getRoute(pVehicleID); RoadNetworkRoute roadNetworkRoute = getCurrentRoute(pVehicleID);
return roadNetworkRoute.getDestination(); return roadNetworkRoute.getDestination();
} }
...@@ -396,7 +413,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -396,7 +413,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
public RoadNetworkRoute findNewRoute(String pVehicle) throws NoAdditionalRouteAvailableException { public RoadNetworkRoute findNewRoute(String pVehicle) throws NoAdditionalRouteAvailableException {
List<RoadNetworkRoute> routes = new ArrayList<>(); List<RoadNetworkRoute> routes = new ArrayList<>();
RoadNetworkRoute route = getRoute(pVehicle); RoadNetworkRoute route = getCurrentRoute(pVehicle);
routes.add(route); routes.add(route);
RoadNetworkRoute findRoute = _algorithm.findRoute(_roadNetwork, route.getStart(), route.getDestination(), routes); RoadNetworkRoute findRoute = _algorithm.findRoute(_roadNetwork, route.getStart(), route.getDestination(), routes);
if (findRoute == null) { if (findRoute == null) {
...@@ -408,7 +425,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -408,7 +425,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
public RoadNetworkRoute findNewRoute(String pVehicle, List<RoadNetworkEdge> pEdgesToAvoid, boolean pKeepDestination) throws NoAdditionalRouteAvailableException, NoExitAvailableException { public RoadNetworkRoute findNewRoute(String pVehicle, List<RoadNetworkEdge> pEdgesToAvoid, boolean pKeepDestination) throws NoAdditionalRouteAvailableException, NoExitAvailableException {
if (pKeepDestination) { if (pKeepDestination) {
List<RoadNetworkRoute> routes = new ArrayList<>(); List<RoadNetworkRoute> routes = new ArrayList<>();
RoadNetworkRoute route = getRoute(pVehicle); RoadNetworkRoute route = getCurrentRoute(pVehicle);
routes.add(route); routes.add(route);
RoadNetworkRoute findRoute = _algorithm.findRoute(_roadNetwork, route.getStart(), route.getDestination(), routes, pEdgesToAvoid); RoadNetworkRoute findRoute = _algorithm.findRoute(_roadNetwork, route.getStart(), route.getDestination(), routes, pEdgesToAvoid);
...@@ -417,7 +434,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -417,7 +434,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
} }
return findRoute; return findRoute;
} else { } else {
RoadNetworkRoute route = getRoute(pVehicle); RoadNetworkRoute route = getCurrentRoute(pVehicle);
List<RoadNetworkEdge> routeList = route.getRoute(); List<RoadNetworkEdge> routeList = route.getRoute();
RoadNetworkEdge lastEdge = null; RoadNetworkEdge lastEdge = null;
......
...@@ -14,6 +14,7 @@ import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position; ...@@ -14,6 +14,7 @@ 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.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.VehicleController;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv.RoadSideUnitInformationHandler; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv.RoadSideUnitInformationHandler;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
public class XMLSimulationController implements VehicleController, SimulationSetupExtractor, Runnable { public class XMLSimulationController implements VehicleController, SimulationSetupExtractor, Runnable {
private String _vehicleDataPath; private String _vehicleDataPath;
...@@ -165,4 +166,9 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -165,4 +166,9 @@ public class XMLSimulationController implements VehicleController, SimulationSet
return -1; return -1;
} }
@Override
public RoadNetworkRoute getCurrentRoute(String pVehicleID) {
throw new UnsupportedOperationException("This method is not supported for " + getClass().getSimpleName());
}
} }
/*
* 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.vehicular;
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.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
public class DefaultVehicleInformationComponent implements VehicleInformationComponent {
private Host host;
private VehicleController controller;
private SimulationSetupExtractor extractor;
private String vehicleID;
public DefaultVehicleInformationComponent(Host host, VehicleController controller, SimulationSetupExtractor extractor) {
this.host = host;
this.controller = controller;
this.extractor = extractor;
}
@Override
public void setVehicleID(String pVehicleID) {
vehicleID = pVehicleID;
}
@Override
public void resetVehicleID() {
vehicleID = null;
}
@Override
public void initialize() {
// TODO Auto-generated method stub
}
@Override
public void shutdown() {
// TODO Auto-generated method stub
}
@Override
public Host getHost() {
return host;
}
@Override
public RoadNetworkRoute getCurrentRoute() {
return controller.getCurrentRoute(vehicleID);
}
}
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