Commit 8a484e4e authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Added vehicle component to access information about the vehicle

parent 69aa8c41
......@@ -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.traci.TraciSimulationController;
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.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Host;
......@@ -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.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.util.XMLConfigurableConstructor;
public class VehicleMovementModel implements MovementModel, EventHandler, FutureLocationSensor {
......@@ -88,6 +90,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
private boolean initialized = false;
private VehicleController _controller;
private SimulationSetupExtractor _extractor;
private List<Position> intersections;
......@@ -226,7 +229,6 @@ 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;
......@@ -234,7 +236,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
_controller.init();
_controller.nextStep();
extractor = simulationController;
_extractor = simulationController;
} else {
XMLSimulationController simulationController;
if (sumoIntersections == null || sumoIntersections.equals("")) {
......@@ -248,12 +250,12 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
_controller.init();
_controller.nextStep();
extractor = simulationController;
_extractor = simulationController;
}
intersections = extractor.getAllIntersections(true);
intersections = _extractor.getAllIntersections(true);
scenarioWidth = extractor.getScenarioWidth();
scenarioHeight = extractor.getScenarioHeight();
scenarioWidth = _extractor.getScenarioWidth();
scenarioHeight = _extractor.getScenarioHeight();
System.out.println("Initialization: done.");
}
......@@ -299,6 +301,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
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 {
RoutedNetLayer routedNetLayer = component.getHost().getComponent(RoutedNetLayer.class);
for (SimNetInterface netInterface : routedNetLayer.getSimNetworkInterfaces()) {
......@@ -347,6 +356,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
if (idComponentMatcher.containsKey(vehicleID)) {
SimLocationActuator simLocationActuator = idComponentMatcher.remove(vehicleID);
if (simLocationActuator != null) {
try {
VehicleInformationComponent vehicularHostComponent = simLocationActuator.getHost().getComponent(VehicleInformationComponent.class);
vehicularHostComponent.resetVehicleID();
} catch (ComponentNotAvailableException e) {
// Nothing to do here
}
freeComponents.add(simLocationActuator);
hostVehicleIDMatching.remove(simLocationActuator.getHost().getId());
}
......@@ -362,6 +378,17 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
private SimLocationActuator requestSimActuator(String vehicle) {
if (!idComponentMatcher.containsKey(vehicle)) {
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) {
idComponentMatcher.put(vehicle, simLocationActuator);
hostVehicleIDMatching.put(simLocationActuator.getHost().getId(), vehicle);
......
......@@ -3,23 +3,27 @@ package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.contr
import java.util.List;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
public interface VehicleController {
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
Position getVehiclePosition(String pVehicleID);
Position getVehiclePosition(double pStep, String pVehicleID);
Position getVehiclePosition(String pVehicleID);
Position getVehiclePosition(double pStep, String pVehicleID);
boolean nextStep();
boolean nextStep();
List<String> getAllVehicles();
List<String> getAllVehicles(double pStep);
List<String> getAllVehicles();
List<String> getAllVehicles(double pStep);
double getMaximumAvailablePrediction();
RoadNetworkRoute getCurrentRoute(String pVehicleID);
double getStep();
double getStart();
double getMaximumAvailablePrediction();
double getStep();
double getStart();
void init();
void init();
}
......@@ -288,16 +288,33 @@ public class TraciSimulationController implements VehicleController, SimulationS
return new ArrayList<>(map.keySet());
}
public RoadNetworkRoute getRoute(String pVehicleID) {
@Override
public RoadNetworkRoute getCurrentRoute(String pVehicleID) {
SumoCommand routeCommand = Vehicle.getRoute(pVehicleID);
Object object = requestObject(routeCommand);
SumoStringList streetList = (SumoStringList) object;
SumoCommand roadIDCommand = Vehicle.getRoadID(pVehicleID);
String currentRoadID = (String) requestObject(roadIDCommand);
obtainRoadNetwork();
List<RoadNetworkEdge> streets = new ArrayList<>();
boolean add = false;
for (String street : streetList) {
streets.add(_roadNetwork.getEdge(street));
if (street.equals(currentRoadID)) {
add = true;
}
if (add) {
streets.add(_roadNetwork.getEdge(street));
}
}
if (streets.size() == 0) {
for (String street : streetList) {
streets.add(_roadNetwork.getEdge(street));
}
}
return new RoadNetworkRoute(streets);
......@@ -383,7 +400,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
}
public RoadNetworkEdge getVehicleDestination(String pVehicleID) {
RoadNetworkRoute roadNetworkRoute = getRoute(pVehicleID);
RoadNetworkRoute roadNetworkRoute = getCurrentRoute(pVehicleID);
return roadNetworkRoute.getDestination();
}
......@@ -396,7 +413,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
public RoadNetworkRoute findNewRoute(String pVehicle) throws NoAdditionalRouteAvailableException {
List<RoadNetworkRoute> routes = new ArrayList<>();
RoadNetworkRoute route = getRoute(pVehicle);
RoadNetworkRoute route = getCurrentRoute(pVehicle);
routes.add(route);
RoadNetworkRoute findRoute = _algorithm.findRoute(_roadNetwork, route.getStart(), route.getDestination(), routes);
if (findRoute == null) {
......@@ -408,7 +425,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
public RoadNetworkRoute findNewRoute(String pVehicle, List<RoadNetworkEdge> pEdgesToAvoid, boolean pKeepDestination) throws NoAdditionalRouteAvailableException, NoExitAvailableException {
if (pKeepDestination) {
List<RoadNetworkRoute> routes = new ArrayList<>();
RoadNetworkRoute route = getRoute(pVehicle);
RoadNetworkRoute route = getCurrentRoute(pVehicle);
routes.add(route);
RoadNetworkRoute findRoute = _algorithm.findRoute(_roadNetwork, route.getStart(), route.getDestination(), routes, pEdgesToAvoid);
......@@ -417,7 +434,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
}
return findRoute;
} else {
RoadNetworkRoute route = getRoute(pVehicle);
RoadNetworkRoute route = getCurrentRoute(pVehicle);
List<RoadNetworkEdge> routeList = route.getRoute();
RoadNetworkEdge lastEdge = null;
......
......@@ -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.VehicleController;
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 {
private String _vehicleDataPath;
......@@ -165,4 +166,9 @@ public class XMLSimulationController implements VehicleController, SimulationSet
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