Skip to content

Commit

Permalink
refactor(application): move navigation module interface to api package
Browse files Browse the repository at this point in the history
  • Loading branch information
kschrab committed Nov 21, 2024
1 parent 1c94711 commit d10adf5
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

package org.eclipse.mosaic.app.examples.commuter;

import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.INavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.RoadPositionFactory;
import org.eclipse.mosaic.fed.application.ambassador.util.UnitLogger;
import org.eclipse.mosaic.fed.application.app.AbstractApplication;
import org.eclipse.mosaic.fed.application.app.api.Application;
import org.eclipse.mosaic.fed.application.app.api.VehicleApplication;
import org.eclipse.mosaic.fed.application.app.api.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.app.api.os.VehicleOperatingSystem;
import org.eclipse.mosaic.lib.enums.VehicleStopMode;
import org.eclipse.mosaic.lib.geo.GeoPoint;
Expand Down Expand Up @@ -106,7 +106,7 @@ public void onVehicleUpdated(@Nullable VehicleData previousVehicleData, @Nonnull
* @param event the event to process
*/
private void driveBack(DriveBackEvent event) {
final INavigationModule navigationModule = getOs().getNavigationModule();
final NavigationModule navigationModule = getOs().getNavigationModule();
final RoutingPosition targetPosition = new RoutingPosition(event.getTargetPosition());
final RoutingParameters routingParameters =
new RoutingParameters().vehicleClass(getOs().getInitialVehicleType().getVehicleClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedAcknowledgement;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedV2xMessage;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.INavigationModule;
import org.eclipse.mosaic.fed.application.app.AbstractApplication;
import org.eclipse.mosaic.fed.application.app.api.CommunicationApplication;
import org.eclipse.mosaic.fed.application.app.api.VehicleApplication;
import org.eclipse.mosaic.fed.application.app.api.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.app.api.os.VehicleOperatingSystem;
import org.eclipse.mosaic.interactions.communication.V2xMessageTransmission;
import org.eclipse.mosaic.lib.enums.AdHocChannel;
Expand Down Expand Up @@ -270,7 +270,7 @@ private void circumnavigateAffectedRoad(Denm denm, final String affectedRoadId)
* The vehicle on which this application has been deployed has a navigation module
* that we need to retrieve in order to switch routes.
*/
INavigationModule navigationModule = getOs().getNavigationModule();
NavigationModule navigationModule = getOs().getNavigationModule();

/*
* Routing parameters are used for route calculation. In our case, we want a specific cost function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.eclipse.mosaic.fed.application.ambassador.simulation.VehicleParameters;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.AdHocModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedV2xMessage;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.RoutingNavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.util.UnitLogger;
import org.eclipse.mosaic.fed.application.app.api.os.VehicleOperatingSystem;
import org.eclipse.mosaic.fed.application.app.api.perception.BasicSensorModule;
Expand Down Expand Up @@ -63,7 +63,7 @@ public class WeatherWarningAppTest {
private VehicleData vehicleData;

@Mock
private NavigationModule navigationModuleMock;
private RoutingNavigationModule navigationModuleMock;

@Mock
private AdHocModule adHocModuleMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import org.eclipse.mosaic.fed.application.ambassador.ErrorRegister;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.IRoutingModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.RoutingNavigationModule;
import org.eclipse.mosaic.fed.application.app.api.CommunicationApplication;
import org.eclipse.mosaic.fed.application.app.api.navigation.RoutingModule;
import org.eclipse.mosaic.fed.application.app.api.os.RoadSideUnitOperatingSystem;
import org.eclipse.mosaic.lib.enums.RsuType;
import org.eclipse.mosaic.lib.geo.GeoPoint;
Expand All @@ -33,7 +33,7 @@
*/
public class RoadSideUnit extends AbstractSimulationUnit implements RoadSideUnitOperatingSystem {

private final IRoutingModule routingModule;
private final RoutingModule routingModule;

/**
* Creates a new Road Side simulation Unit.
Expand All @@ -44,7 +44,7 @@ public class RoadSideUnit extends AbstractSimulationUnit implements RoadSideUnit
public RoadSideUnit(String rsuName, GeoPoint rsuPosition) {
super(rsuName, rsuPosition);
setRequiredOperatingSystem(RoadSideUnitOperatingSystem.class);
routingModule = new NavigationModule(this);
routingModule = new RoutingNavigationModule(this);
}

@Override
Expand All @@ -53,7 +53,7 @@ public GeoPoint getPosition() {
}

@Override
public IRoutingModule getRoutingModule() {
public RoutingModule getRoutingModule() {
return routingModule;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import org.eclipse.mosaic.fed.application.ambassador.ErrorRegister;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.IRoutingModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.RoutingNavigationModule;
import org.eclipse.mosaic.fed.application.app.api.navigation.RoutingModule;
import org.eclipse.mosaic.fed.application.app.api.os.ServerOperatingSystem;
import org.eclipse.mosaic.lib.objects.mapping.ServerMapping;
import org.eclipse.mosaic.lib.util.scheduling.Event;
Expand All @@ -28,7 +28,7 @@
*/
public class ServerUnit extends AbstractSimulationUnit implements ServerOperatingSystem {

private final IRoutingModule routingModule;
private final RoutingModule routingModule;

/**
* Constructor for {@link ServerUnit}, sets the operating system.
Expand All @@ -38,7 +38,7 @@ public class ServerUnit extends AbstractSimulationUnit implements ServerOperatin
public ServerUnit(final ServerMapping serverMapping) {
super(serverMapping.getName(), null);
setRequiredOperatingSystem(ServerOperatingSystem.class);
routingModule = new NavigationModule(this);
routingModule = new RoutingNavigationModule(this);
}

/**
Expand All @@ -49,7 +49,7 @@ public ServerUnit(final ServerMapping serverMapping) {
*/
public ServerUnit(String unitName) {
super(unitName, null);
routingModule = new NavigationModule(this);
routingModule = new RoutingNavigationModule(this);
}

@Override
Expand All @@ -58,7 +58,7 @@ public final CamBuilder assembleCamMessage(CamBuilder camBuilder) {
}

@Override
public IRoutingModule getRoutingModule() {
public RoutingModule getRoutingModule() {
return routingModule;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
import org.eclipse.mosaic.fed.application.ambassador.ErrorRegister;
import org.eclipse.mosaic.fed.application.ambassador.SimulationKernel;
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.INavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.RoadPositionFactory;
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.RoutingNavigationModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.EnvironmentBasicSensorModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.NopPerceptionModule;
import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.PerceptionModuleOwner;
import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.SimplePerceptionConfiguration;
import org.eclipse.mosaic.fed.application.app.api.CommunicationApplication;
import org.eclipse.mosaic.fed.application.app.api.VehicleApplication;
import org.eclipse.mosaic.fed.application.app.api.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.app.api.os.VehicleOperatingSystem;
import org.eclipse.mosaic.fed.application.app.api.perception.BasicSensorModule;
import org.eclipse.mosaic.fed.application.app.api.perception.LidarSensorModule;
Expand Down Expand Up @@ -61,7 +61,7 @@
public class VehicleUnit extends AbstractSimulationUnit implements VehicleOperatingSystem, PerceptionModuleOwner {

@Nonnull
private final NavigationModule navigationModule;
private final RoutingNavigationModule navigationModule;

@Nonnull
private final PerceptionModule<SimplePerceptionConfiguration> perceptionModule;
Expand All @@ -83,7 +83,7 @@ public VehicleUnit(String vehicleName, VehicleType vehicleType, final GeoPoint i
super(vehicleName, initialPosition);
setRequiredOperatingSystem(VehicleOperatingSystem.class);
vehicleParameters = new VehicleParameters(vehicleType);
navigationModule = new NavigationModule(this);
navigationModule = new RoutingNavigationModule(this);
navigationModule.setCurrentPosition(initialPosition);

Database database = null;
Expand Down Expand Up @@ -356,7 +356,7 @@ public void activateVehicleSensors(double sensorRange, SensorType... sensorTypes
}

@Override
public INavigationModule getNavigationModule() {
public NavigationModule getNavigationModule() {
return this.navigationModule;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import org.eclipse.mosaic.fed.application.ambassador.SimulationKernel;
import org.eclipse.mosaic.fed.application.ambassador.simulation.AbstractSimulationUnit;
import org.eclipse.mosaic.fed.application.app.api.navigation.NavigationModule;
import org.eclipse.mosaic.fed.application.app.api.navigation.RoutingModule;
import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.road.IConnection;
import org.eclipse.mosaic.lib.objects.road.INode;
Expand All @@ -33,14 +35,12 @@
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

/**
* Implementation of the interface to access the central navigation component.
* This class provides implementation for both {@link NavigationModule} and {@link RoutingModule}, as
* they are very close related with each other from a functional perspective.
*/
public class NavigationModule implements INavigationModule, IRoutingModule {
public class RoutingNavigationModule implements NavigationModule, RoutingModule {

private static final int POSITION_DIFFERENCE_THRESHOLD = 10;

Expand All @@ -51,7 +51,7 @@ public class NavigationModule implements INavigationModule, IRoutingModule {
private VehicleRoute currentRoute;
private GeoPoint currentPosition;

public NavigationModule(AbstractSimulationUnit owner) {
public RoutingNavigationModule(AbstractSimulationUnit owner) {
this.belongingUnit = owner;
}

Expand Down Expand Up @@ -101,7 +101,7 @@ public boolean switchRoute(CandidateRoute newRoute) {
VehicleRoute route;
try {
route = SimulationKernel.SimulationKernel.getCentralNavigationComponent().switchRoute(
this.vehicleData, newRoute, currentRoute, belongingUnit.getSimulationTime()
vehicleData, newRoute, currentRoute, belongingUnit.getSimulationTime()
);

boolean switched = route != null && (getCurrentRoute() == null || !route.getId().equals(getCurrentRoute().getId()));
Expand Down Expand Up @@ -173,7 +173,7 @@ public void setCurrentRoute(VehicleRoute currentRoute) {
public void refineRoadPosition(IRoadPosition roadPosition) {
final IRoadPosition newRoadPosition =
SimulationKernel.SimulationKernel.getCentralNavigationComponent().refineRoadPosition(roadPosition);
if (newRoadPosition != null) {
if (newRoadPosition != null && getVehicleData() != null) {
setVehicleData(
new VehicleData.Builder(getVehicleData().getTime(), getVehicleData().getName())
.copyFrom(getVehicleData())
Expand All @@ -182,36 +182,9 @@ public void refineRoadPosition(IRoadPosition roadPosition) {
}
}

@Override
public Collection<CandidateRoute> retrieveAllValidRoutesToTarget(RoutingPosition targetPosition) {
return retrieveAllValidExistingRoutesToTargetHelper(targetPosition);
}

@Override
public Collection<CandidateRoute> retrieveAllValidRoutesToTarget(GeoPoint targetGeoPoint) {
RoutingPosition targetPosition = new RoutingPosition(targetGeoPoint);
return retrieveAllValidExistingRoutesToTargetHelper(targetPosition);
}

private Collection<CandidateRoute> retrieveAllValidExistingRoutesToTargetHelper(RoutingPosition targetPosition) {
CentralNavigationComponent centNavComp = SimulationKernel.SimulationKernel.getCentralNavigationComponent();
ArrayList<CandidateRoute> candidateRoutes = new ArrayList<>();
for (Map.Entry<String, VehicleRoute> entry : centNavComp.getAllRoutes().entrySet()) {
VehicleRoute route = entry.getValue();
if (targetQuery(targetPosition, route, centNavComp.getTargetPositionOfRoute(route.getId())) && onRouteQuery(route)) {
// length and time are no valid values at this point
candidateRoutes.add(new CandidateRoute(route.getConnectionIds(), 0, 0));
belongingUnit.getOsLog().debug(
"NavigationModule#retrieveAllValidExistingRoutesToTarget found valid existing candidate route {} ", route.getId()
);
}
}
return candidateRoutes;
}

@VisibleForTesting
boolean onRouteQuery(VehicleRoute route) {
return route.getConnectionIds().contains(this.getVehicleData().getRoadPosition().getConnectionId());
return route.getConnectionIds().contains(getVehicleData().getRoadPosition().getConnectionId());
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Contact: [email protected]
*/

package org.eclipse.mosaic.fed.application.ambassador.simulation.navigation;
package org.eclipse.mosaic.fed.application.app.api.navigation;

import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.road.IConnection;
Expand All @@ -26,13 +26,14 @@
import org.eclipse.mosaic.lib.routing.RoutingPosition;
import org.eclipse.mosaic.lib.routing.RoutingResponse;

import java.util.Collection;
import javax.annotation.Nullable;

/**
* Interface to access the central navigation component from vehicle applications.
* Interface to access navigational functions of the vehicle.
* As one part, it offers methods to calculate routes from the current position of
* the vehicle to a provided target location.
*/
public interface INavigationModule {
public interface NavigationModule {

/**
* Calculates one or more routes from the position of the vehicle to the given target location.
Expand All @@ -52,22 +53,6 @@ public interface INavigationModule {
*/
RoutingResponse calculateRoutes(GeoPoint targetGeoPoint, RoutingParameters routingParameters);

/**
* Returns all existing routes that can be taken to target position using {@link RoutingPosition}.
*
* @param targetPosition The target position to calculate routes for.
* @return All valid routes to target position.
*/
Collection<CandidateRoute> retrieveAllValidRoutesToTarget(RoutingPosition targetPosition);

/**
* Returns all existing routes that can be taken to target position using {@link GeoPoint}.
*
* @param targetGeoPoint The target position to calculate routes for.
* @return All valid routes to target position.
*/
Collection<CandidateRoute> retrieveAllValidRoutesToTarget(GeoPoint targetGeoPoint);

/**
* Switch to a specific route.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Contact: [email protected]
*/

package org.eclipse.mosaic.fed.application.ambassador.simulation.navigation;
package org.eclipse.mosaic.fed.application.app.api.navigation;

import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.road.IConnection;
Expand All @@ -24,9 +24,14 @@
import org.eclipse.mosaic.lib.routing.RoutingResponse;

/**
* Interface to access the central navigation component from road side units.
* Interface to access road routing functionalities for server or road side units.
* The offered methods, for example, provide route calculation from a provided source to
* a provided target location.<br>
* In contrast to {@link NavigationModule}, a {@link RoutingModule} can only calculate routes,
* but is not able to switch to calculated routes. Thus, the {@link RoutingModule} can be used
* in server units to emulate central routíng service functionalities.
*/
public interface IRoutingModule {
public interface RoutingModule {

/**
* Calculates one or more routes from the position of the vehicle to the given target location.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@

package org.eclipse.mosaic.fed.application.app.api.os.modules;

import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.INavigationModule;
import org.eclipse.mosaic.fed.application.app.api.navigation.NavigationModule;

/**
* Interface to mark an {@link org.eclipse.mosaic.fed.application.app.api.os.OperatingSystem} as
* an owner of a {@link INavigationModule} to calculate routes from its current position to any target,
* an owner of a {@link NavigationModule} to calculate routes from its current position to any target,
* thus making it navigable.
*/
public interface Navigable extends Locatable {

/**
* Returns a navigation module to calculate and switch routes to any target.
*
* @return the {@link INavigationModule} of this unit.
* @return the {@link NavigationModule} of this unit.
*/
INavigationModule getNavigationModule();
NavigationModule getNavigationModule();
}
Loading

0 comments on commit d10adf5

Please sign in to comment.