From 35518905a89c2ac1ca0d9f06d1d50a5047c92735 Mon Sep 17 00:00:00 2001 From: Karl Schrab Date: Wed, 4 Oct 2023 15:42:01 +0200 Subject: [PATCH] feat(perception): simplified configuration for perception index (#351) * feat: simplified configuration for perception index * use separate configuration class instead of inferring index implementations with configuration * removed simple index implementation based on for-loops, keep tree,grid,sumo as vehicle index implementations * removed measurement of index performance * simplified configuration of indexes, e.g. by enabling/disabling them via config option * use tree implementation for vehicle index by default * all indexes are disabled by default * use parametrized test instead of repeating test methods in SimplePerceptionModuleTest * fix: remove unused configuration option * feat: add example perception config for Barnim * fix: resolve spotbugs warning * feat: add perception modifier for heading and dimensions * clean: use convenient order of dimension attributes * feat: enable vehicle index by default --- .../application/application_config.json | 19 ++ .../application/ambassador/UnitSimulator.java | 6 +- .../ambassador/simulation/VehicleUnit.java | 7 +- .../CentralPerceptionComponent.java | 109 +------- .../errormodels/DimensionsModifier.java | 96 +++++++ .../errormodels/HeadingModifier.java | 107 ++++++++ .../errormodels/PositionModifier.java | 3 + .../perception/index/TrafficObjectIndex.java | 11 + .../index/providers/TrafficLightIndex.java | 4 - .../index/providers/TrafficLightMap.java | 43 ---- .../index/providers/TrafficLightTree.java | 9 +- .../index/providers/VehicleGrid.java | 13 +- .../index/providers/VehicleIndex.java | 3 - .../index/providers/VehicleMap.java | 68 ----- .../index/providers/VehicleTree.java | 14 +- .../perception/index/providers/WallIndex.java | 4 - .../perception/index/providers/WallTree.java | 9 +- .../TrafficLightIndexTypeAdapterFactory.java | 34 --- .../util/VehicleIndexTypeAdapterFactory.java | 34 --- .../util/WallIndexTypeAdapterFactory.java | 34 --- .../config/CApplicationAmbassador.java | 40 --- .../fed/application/config/CPerception.java | 199 +++++++++++++++ .../CApplicationAmbassadorScheme.json | 144 +++++------ .../ambassador/UnitSimulatorTest.java | 2 +- .../navigation/NavigationModuleTest.java | 4 +- .../perception/PerceptionModifierTest.java | 65 ++++- .../SimplePerceptionModuleTest.java | 239 +++--------------- .../config/CApplicationAmbassadorTest.java | 1 - .../lib/gson/GeoAreaAdapterFactory.java | 2 +- ...Factory.java => TypeFieldTypeAdapter.java} | 30 ++- .../util/gson/PackageSpecificTypeAdapter.java | 4 +- ...IndexesIT.java => PerceptionModuleIT.java} | 4 +- ...l.json => application_config_default.json} | 6 +- .../application/application_config_grid.json | 7 +- .../application_config_quadtree.json | 7 +- .../application/application_config_sumo.json | 7 +- 36 files changed, 672 insertions(+), 716 deletions(-) create mode 100644 bundle/src/assembly/resources/scenarios/Barnim/application/application_config.json create mode 100644 fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/DimensionsModifier.java create mode 100644 fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/HeadingModifier.java delete mode 100644 fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightMap.java delete mode 100644 fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleMap.java delete mode 100644 fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/TrafficLightIndexTypeAdapterFactory.java delete mode 100644 fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/VehicleIndexTypeAdapterFactory.java delete mode 100644 fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/WallIndexTypeAdapterFactory.java create mode 100644 fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/config/CPerception.java rename lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/{AbstractTypeAdapterFactory.java => TypeFieldTypeAdapter.java} (77%) rename test/mosaic-integration-tests/src/test/java/org/eclipse/mosaic/test/{PerceptionModuleMapIndexesIT.java => PerceptionModuleIT.java} (82%) rename test/scenarios/perception-module/application/{application_config_trivial.json => application_config_default.json} (60%) diff --git a/bundle/src/assembly/resources/scenarios/Barnim/application/application_config.json b/bundle/src/assembly/resources/scenarios/Barnim/application/application_config.json new file mode 100644 index 000000000..9c9a5c6f6 --- /dev/null +++ b/bundle/src/assembly/resources/scenarios/Barnim/application/application_config.json @@ -0,0 +1,19 @@ +{ + "messageCacheTime": "30s", + "encodePayloads": true, + "eventSchedulerThreads": 1, + "navigationConfiguration": { + "type": "database" + }, + "perceptionConfiguration": { + "vehicleIndex": { + "enabled": true + }, + "trafficLightIndex": { + "enabled": true + }, + "wallIndex": { + "enabled": false + } + } +} \ No newline at end of file diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/UnitSimulator.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/UnitSimulator.java index 3c652db25..1952b4b1a 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/UnitSimulator.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/UnitSimulator.java @@ -369,8 +369,10 @@ this, new StartApplications(chargingStationUnit.getId(), chargingStationRegistra * @param trafficLightRegistration traffic light */ public void registerTrafficLight(TrafficLightRegistration trafficLightRegistration) { - if (!trafficLightRegistration.getMapping().hasApplication() - && SimulationKernel.SimulationKernel.getConfiguration().perceptionConfiguration.trafficLightIndex == null) { + // if traffic light index is enabled, we need traffic light state information for all traffic lights via subscriptions + boolean isTrafficLightIndexEnabled = SimulationKernel.SimulationKernel.getConfiguration().perceptionConfiguration.trafficLightIndex != null && + SimulationKernel.SimulationKernel.getConfiguration().perceptionConfiguration.trafficLightIndex.enabled; + if (!trafficLightRegistration.getMapping().hasApplication() && !isTrafficLightIndexEnabled) { return; } diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/VehicleUnit.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/VehicleUnit.java index 4c47027d1..71ce0fa5d 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/VehicleUnit.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/VehicleUnit.java @@ -85,12 +85,13 @@ public VehicleUnit(String vehicleName, VehicleType vehicleType, final GeoPoint i .getCentralNavigationComponent().getRouting()).getScenarioDatabase(); } - if (SimulationKernel.SimulationKernel.getConfiguration().perceptionConfiguration.vehicleIndex != null) { - perceptionModule = SimulationKernel.SimulationKernel.getConfiguration().perceptionConfiguration.vehicleIndex - .createPerceptionModule(this, database, getOsLog()); + if (SimulationKernel.SimulationKernel.getCentralPerceptionComponent().getTrafficObjectIndex() != null) { + perceptionModule = SimulationKernel.SimulationKernel.getCentralPerceptionComponent() + .getTrafficObjectIndex().createPerceptionModule(this, database, getOsLog()); } else { perceptionModule = new NopPerceptionModule(this, database, getOsLog()); } + } @Override diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/CentralPerceptionComponent.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/CentralPerceptionComponent.java index 43749923c..6807090c9 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/CentralPerceptionComponent.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/CentralPerceptionComponent.java @@ -17,23 +17,14 @@ import org.eclipse.mosaic.fed.application.ambassador.SimulationKernel; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.TrafficObjectIndex; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.TrafficLightObject; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.VehicleObject; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.TrafficLightMap; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleMap; -import org.eclipse.mosaic.fed.application.config.CApplicationAmbassador; +import org.eclipse.mosaic.fed.application.config.CPerception; import org.eclipse.mosaic.interactions.traffic.TrafficLightUpdates; import org.eclipse.mosaic.interactions.traffic.VehicleUpdates; import org.eclipse.mosaic.lib.database.Database; import org.eclipse.mosaic.lib.geo.CartesianRectangle; -import org.eclipse.mosaic.lib.math.Vector3d; import org.eclipse.mosaic.lib.objects.trafficlight.TrafficLightGroup; -import org.eclipse.mosaic.lib.objects.trafficlight.TrafficLightGroupInfo; -import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; import org.eclipse.mosaic.lib.objects.vehicle.VehicleType; import org.eclipse.mosaic.lib.routing.Routing; -import org.eclipse.mosaic.lib.spatial.Edge; -import org.eclipse.mosaic.lib.util.PerformanceMonitor; import org.eclipse.mosaic.rti.api.InternalFederateException; import com.google.common.collect.Iterables; @@ -41,10 +32,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Collection; -import java.util.List; -import java.util.Map; - /** * The {@link CentralPerceptionComponent} is responsible for keeping a spatial index of all vehicles, * which allows fast querying of nearby vehicles. @@ -57,7 +44,7 @@ public class CentralPerceptionComponent { /** * Configuration containing parameters for setting up the spatial indexes. */ - private final CApplicationAmbassador.CPerception configuration; + private final CPerception configuration; /** * The spatial index used to store and find objects by their positions. @@ -84,7 +71,7 @@ public class CentralPerceptionComponent { */ private boolean updateTrafficLightIndex = false; - public CentralPerceptionComponent(CApplicationAmbassador.CPerception perceptionConfiguration) { + public CentralPerceptionComponent(CPerception perceptionConfiguration) { this.configuration = Validate.notNull(perceptionConfiguration, "perceptionConfiguration must not be null"); } @@ -99,38 +86,21 @@ public void initialize() throws InternalFederateException { // evaluate bounding box for perception scenarioBounds = configuration.perceptionArea == null ? routing.getScenarioBounds() : configuration.perceptionArea.toCartesian(); - // see what backends are configured - boolean vehicleIndexConfigured = configuration.vehicleIndex != null; - boolean trafficLightIndexConfigured = configuration.trafficLightIndex != null; TrafficObjectIndex.Builder indexBuilder = new TrafficObjectIndex.Builder(LOG); - if (scenarioBounds.getArea() <= 0) { - LOG.warn("The bounding area of the scenario could not be determined. Defaulting to low performance spatial index."); - if (vehicleIndexConfigured) { // if configured default to map index - indexBuilder.withVehicleIndex(new VehicleMap()); - } - if (trafficLightIndexConfigured) { // if configured default to map index - indexBuilder.withTrafficLightIndex(new TrafficLightMap()); - } - } else { - if (vehicleIndexConfigured) { - indexBuilder.withVehicleIndex(configuration.vehicleIndex); - } - if (trafficLightIndexConfigured) { - indexBuilder.withTrafficLightIndex(configuration.trafficLightIndex); - } + if (configuration.vehicleIndex != null) { + indexBuilder.withVehicleIndex(configuration.vehicleIndex.create()); + } + if (configuration.trafficLightIndex != null) { + indexBuilder.withTrafficLightIndex(configuration.trafficLightIndex.create()); } if (routing instanceof Database) { Database dbRouting = (Database) routing; - if (!dbRouting.getBuildings().isEmpty()) { - indexBuilder.withWallIndex(configuration.wallIndex, (Database) routing); + if (!dbRouting.getBuildings().isEmpty() && configuration.wallIndex != null) { + indexBuilder.withWallIndex(configuration.wallIndex.create(), (Database) routing); } } trafficObjectIndex = indexBuilder.build(); - - if (configuration.measurePerformance) { - trafficObjectIndex = new MonitoringTrafficObjectIndexProvider(trafficObjectIndex, PerformanceMonitor.getInstance()); - } } catch (Exception e) { throw new InternalFederateException("Couldn't initialize CentralPerceptionComponent", e); } @@ -212,63 +182,4 @@ public void updateTrafficLights(TrafficLightUpdates trafficLightUpdates) { updateTrafficLightIndex = true; } - /** - * Wrapper class to measure atomic calls of update, search and remove of the used spatial index. - */ - static class MonitoringTrafficObjectIndexProvider extends TrafficObjectIndex { - private final PerformanceMonitor monitor; - - MonitoringTrafficObjectIndexProvider(TrafficObjectIndex parent, PerformanceMonitor monitor) { - super(parent); - this.monitor = monitor; - } - - @Override - public List getVehiclesInRange(PerceptionModel searchRange) { - try (PerformanceMonitor.Measurement m = monitor.start("search-vehicle")) { - m.setProperties(getNumberOfVehicles(), SimulationKernel.SimulationKernel.getCurrentSimulationTime()).restart(); - return super.getVehiclesInRange(searchRange); - } - } - - @Override - public void removeVehicles(Iterable vehiclesToRemove) { - try (PerformanceMonitor.Measurement m = monitor.start("remove-vehicle")) { - m.setProperties(getNumberOfVehicles(), SimulationKernel.SimulationKernel.getCurrentSimulationTime()).restart(); - super.removeVehicles(vehiclesToRemove); - } - } - - @Override - public void updateVehicles(Iterable vehiclesToUpdate) { - try (PerformanceMonitor.Measurement m = monitor.start("update-vehicle")) { - m.setProperties(getNumberOfVehicles(), SimulationKernel.SimulationKernel.getCurrentSimulationTime()).restart(); - super.updateVehicles(vehiclesToUpdate); - } - } - - @Override - public List getTrafficLightsInRange(PerceptionModel perceptionModel) { - try (PerformanceMonitor.Measurement m = monitor.start("search-traffic-light")) { - m.setProperties(SimulationKernel.SimulationKernel.getCurrentSimulationTime()).restart(); - return super.getTrafficLightsInRange(perceptionModel); - } - } - - @Override - public void updateTrafficLights(Map trafficLightsToUpdate) { - try (PerformanceMonitor.Measurement m = monitor.start("update-traffic-light")) { - m.setProperties(SimulationKernel.SimulationKernel.getCurrentSimulationTime()).restart(); - super.updateTrafficLights(trafficLightsToUpdate); - } - } - - @Override - public Collection> getSurroundingWalls(PerceptionModel perceptionModel) { - try (PerformanceMonitor.Measurement m = monitor.start("search-walls")) { - m.setProperties(SimulationKernel.SimulationKernel.getCurrentSimulationTime()).restart(); - return super.getSurroundingWalls(perceptionModel); - } - } - } } diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/DimensionsModifier.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/DimensionsModifier.java new file mode 100644 index 000000000..920a961b0 --- /dev/null +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/DimensionsModifier.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 Fraunhofer FOKUS and others. All rights reserved. + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contact: mosaic@fokus.fraunhofer.de + */ + +package org.eclipse.mosaic.fed.application.ambassador.simulation.perception.errormodels; + +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.PerceptionModuleOwner; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.SpatialObject; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.VehicleObject; +import org.eclipse.mosaic.lib.math.MathUtils; +import org.eclipse.mosaic.lib.math.RandomNumberGenerator; +import org.eclipse.mosaic.lib.math.Vector3d; +import org.eclipse.mosaic.lib.math.VectorUtils; + +import java.util.List; + +/** + * Adjusts the dimensions of perceived {@link VehicleObject}s. Since the position + * of vehicles is assumed to refer to their front bumper instead of bounding box center, + * their position is adjusted accordingly when the length of the vehicle was changed. + */ +public class DimensionsModifier implements PerceptionModifier { + + private static final double SIGMA_WIDTH_OFFSET = 0.2; // given in m + private static final double SIGMA_HEIGHT_OFFSET = 0.2; // given in m + private static final double SIGMA_LENGTH_OFFSET = 0.5; // given in m + + private final double heightDeviation; + private final double widthDeviation; + private final double lengthDeviation; + + private final RandomNumberGenerator rng; + + + public DimensionsModifier(RandomNumberGenerator rng, double lengthDeviation, double widthDeviation, double heightDeviation) { + this.rng = rng; + this.lengthDeviation = lengthDeviation; + this.widthDeviation = widthDeviation; + this.heightDeviation = heightDeviation; + } + + public DimensionsModifier(RandomNumberGenerator rng) { + this.rng = rng; + this.lengthDeviation = SIGMA_LENGTH_OFFSET; + this.widthDeviation = SIGMA_WIDTH_OFFSET; + this.heightDeviation = SIGMA_HEIGHT_OFFSET; + } + + @Override + public List apply(PerceptionModuleOwner owner, List spatialObjects) { + spatialObjects.stream() + .filter(o -> o instanceof VehicleObject) + .forEach(o -> adjustDimensionsOfVehicle((VehicleObject) o)); + return spatialObjects; + } + + private void adjustDimensionsOfVehicle(VehicleObject vehicleObject) { + + double oldLength = vehicleObject.getLength(); + + vehicleObject.setDimensions( + Math.abs(rng.nextGaussian(vehicleObject.getLength(), lengthDeviation)), + Math.abs(rng.nextGaussian(vehicleObject.getWidth(), widthDeviation)), + Math.abs(rng.nextGaussian(vehicleObject.getHeight(), heightDeviation)) + ); + + double newLength = vehicleObject.getLength(); + + if (MathUtils.isFuzzyEqual(newLength, oldLength)) { + return; + } + + // move position of vehicle based on length difference since vehicle position is assumed to refer to front bumper and we want to + // squeeze the length around bounding box center + Vector3d direction = VectorUtils.getDirectionVectorFromHeading(vehicleObject.getHeading(), new Vector3d()) + .multiply((newLength - oldLength) / 2); + vehicleObject.setPosition( + vehicleObject.getPosition().x + direction.x, + vehicleObject.getPosition().y + direction.y, + vehicleObject.getPosition().z + direction.z + ); + } + +} + diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/HeadingModifier.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/HeadingModifier.java new file mode 100644 index 000000000..4fca0a68b --- /dev/null +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/HeadingModifier.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2022 Fraunhofer FOKUS and others. All rights reserved. + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contact: mosaic@fokus.fraunhofer.de + */ + +package org.eclipse.mosaic.fed.application.ambassador.simulation.perception.errormodels; + +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.PerceptionModuleOwner; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.SpatialObject; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.VehicleObject; +import org.eclipse.mosaic.lib.math.MathUtils; +import org.eclipse.mosaic.lib.math.RandomNumberGenerator; +import org.eclipse.mosaic.lib.math.Vector3d; +import org.eclipse.mosaic.lib.math.VectorUtils; + +import org.apache.commons.lang3.Validate; + +import java.util.List; + +/** + * Adjusts the heading of perceived {@link VehicleObject}s. Since the position + * of vehicles is assumed to refer to their front bumper and instead bounding box center, + * their position is adjusted accordingly when the heading of the vehicle was changed. + */ +public class HeadingModifier implements PerceptionModifier { + + /** + * Default standard deviation for heading error + */ + private static final double SIGMA_HEADING_OFFSET = 4; // given in degree + + /** + * Default chance of the car being perceived heading in the complete other direction (180° error) + */ + private static final double DEFAULT_CHANCE_WRONG_DIR = 0.01; + + private final RandomNumberGenerator rng; + + /** + * Standard deviation for heading error. + */ + private final double headingStandardDeviation; + + private final double chanceOfWrongDirection; + + public HeadingModifier(RandomNumberGenerator rng) { + this.rng = rng; + this.headingStandardDeviation = SIGMA_HEADING_OFFSET; + this.chanceOfWrongDirection = DEFAULT_CHANCE_WRONG_DIR; + } + + public HeadingModifier(RandomNumberGenerator rng, double headingStandardDeviation, double chanceOfWrongDirection) { + Validate.inclusiveBetween(0, 360, headingStandardDeviation, "Heading deviation should lie between 0 and 360"); + Validate.inclusiveBetween(0, 1, chanceOfWrongDirection, "Wrong direction probability should lie between 0 and 1"); + + this.rng = rng; + this.headingStandardDeviation = headingStandardDeviation; + this.chanceOfWrongDirection = chanceOfWrongDirection; + } + + @Override + public List apply(PerceptionModuleOwner owner, List spatialObjects) { + final Vector3d ownerPosition = owner.getVehicleData().getProjectedPosition().toVector3d(); + + spatialObjects.stream() + .filter(o -> o instanceof VehicleObject) + .forEach(o -> adjustHeadingOfVehicle(ownerPosition, (VehicleObject) o)); + + return spatialObjects; + } + + private void adjustHeadingOfVehicle(Vector3d ownerPosition, VehicleObject vehicleObject) { + + double oldHeading = vehicleObject.getHeading(); + + if (rng.nextDouble() < chanceOfWrongDirection) { + vehicleObject.setHeading((vehicleObject.getHeading() + 180) % 360); + } + vehicleObject.setHeading(rng.nextGaussian(vehicleObject.getHeading(), headingStandardDeviation) % 360); + + double newHeading = vehicleObject.getHeading(); + + if (MathUtils.isFuzzyEqual(oldHeading, newHeading)) { + return; + } + + // move position of vehicle based on heading diff since vehicle position is assumed to refer to front bumper and we want to + // rotate around bounding box center + Vector3d oldHeadingVector = VectorUtils.getDirectionVectorFromHeading(oldHeading, new Vector3d()); + Vector3d newHeadingVector = VectorUtils.getDirectionVectorFromHeading(newHeading, new Vector3d()); + + Vector3d newPosition = new Vector3d(vehicleObject.getPosition()) + .subtract(oldHeadingVector.multiply(vehicleObject.getLength() / 2)) + .add(newHeadingVector.multiply(vehicleObject.getLength() / 2)); + vehicleObject.setPosition(newPosition.x, newPosition.y, newPosition.z); + } +} diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/PositionModifier.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/PositionModifier.java index bceb99b9e..bd716209b 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/PositionModifier.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/errormodels/PositionModifier.java @@ -33,6 +33,7 @@ * orientation of the ego vehicle, and after error calculation re-transformed. */ public class PositionModifier implements PerceptionModifier { + /** * Default standard deviation for longitudinal error. (Taken from referenced source) */ @@ -42,10 +43,12 @@ public class PositionModifier implements PerceptionModifier { * Default standard deviation for lateral error. (Taken from referenced source) */ private static final double SIGMA_LAT_OFFSET = 0.390; // [m] + /** * Standard deviation for longitudinal error. */ private final double longitudinalStandardDeviation; + /** * Standard deviation for lateral error. */ diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/TrafficObjectIndex.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/TrafficObjectIndex.java index f4f500d5e..202773984 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/TrafficObjectIndex.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/TrafficObjectIndex.java @@ -15,12 +15,16 @@ package org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index; +import org.eclipse.mosaic.fed.application.ambassador.simulation.VehicleUnit; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.NopPerceptionModule; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.PerceptionModel; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.SimplePerceptionConfiguration; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.TrafficLightObject; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.VehicleObject; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.TrafficLightIndex; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleIndex; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.WallIndex; +import org.eclipse.mosaic.fed.application.app.api.perception.PerceptionModule; import org.eclipse.mosaic.lib.database.Database; import org.eclipse.mosaic.lib.math.Vector3d; import org.eclipse.mosaic.lib.objects.trafficlight.TrafficLightGroup; @@ -189,6 +193,13 @@ public Collection> getSurroundingWalls(PerceptionModel perception return wallIndex.getSurroundingWalls(perceptionModel); } + public PerceptionModule createPerceptionModule(VehicleUnit vehicleUnit, Database database, Logger osLog) { + if (vehicleIndex != null) { + return vehicleIndex.createPerceptionModule(vehicleUnit, database, log); + } + return new NopPerceptionModule(vehicleUnit, database, log); + } + public static class Builder { private final Logger log; private VehicleIndex vehicleIndex = null; diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightIndex.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightIndex.java index 075449a3c..62078febb 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightIndex.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightIndex.java @@ -19,18 +19,14 @@ import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.PerceptionModel; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.TrafficObjectIndex; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.TrafficLightObject; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.util.TrafficLightIndexTypeAdapterFactory; import org.eclipse.mosaic.lib.objects.trafficlight.TrafficLightGroup; import org.eclipse.mosaic.lib.objects.trafficlight.TrafficLightGroupInfo; import org.eclipse.mosaic.lib.objects.trafficlight.TrafficLightState; -import com.google.gson.annotations.JsonAdapter; - import java.util.HashMap; import java.util.List; import java.util.Map; -@JsonAdapter(TrafficLightIndexTypeAdapterFactory.class) public abstract class TrafficLightIndex { /** diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightMap.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightMap.java deleted file mode 100644 index 7a44cac6f..000000000 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightMap.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022 Fraunhofer FOKUS and others. All rights reserved. - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contact: mosaic@fokus.fraunhofer.de - */ - -package org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers; - -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.PerceptionModel; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.TrafficLightObject; - -import java.util.List; -import java.util.stream.Collectors; - -public class TrafficLightMap extends TrafficLightIndex { - - @Override - public void initialize() { - // nothing to initialize - } - - @Override - public List getTrafficLightsInRange(PerceptionModel perceptionModel) { - return indexedTrafficLights.values().stream() - .filter(perceptionModel::isInRange) - .collect(Collectors.toList()); - } - - @Override - public void onTrafficLightsUpdate() { - // nothing to do on update - } - -} diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightTree.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightTree.java index 7ed0636b8..e189b5146 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightTree.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/TrafficLightTree.java @@ -21,8 +21,6 @@ import org.eclipse.mosaic.lib.spatial.KdTree; import org.eclipse.mosaic.lib.spatial.SpatialTreeTraverser; -import com.google.gson.annotations.Expose; - import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -32,13 +30,16 @@ */ public class TrafficLightTree extends TrafficLightIndex { - @Expose - public int bucketSize = 20; + private final int bucketSize; private KdTree trafficLightTree; private SpatialTreeTraverser.InRadius treeTraverser; + public TrafficLightTree(int bucketSize) { + this.bucketSize = bucketSize; + } + @Override public void initialize() { // initialization at first update diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleGrid.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleGrid.java index 40902d6fe..951184027 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleGrid.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleGrid.java @@ -27,26 +27,27 @@ import org.eclipse.mosaic.lib.geo.CartesianRectangle; import org.eclipse.mosaic.lib.spatial.BoundingBox; import org.eclipse.mosaic.lib.spatial.Grid; -import org.eclipse.mosaic.lib.util.gson.UnitFieldAdapter; -import com.google.gson.annotations.JsonAdapter; import org.slf4j.Logger; import java.util.List; public class VehicleGrid extends VehicleIndex { - @JsonAdapter(UnitFieldAdapter.DistanceMeters.class) - public double cellWidth = 200; + private final double cellWidth; - @JsonAdapter(UnitFieldAdapter.DistanceMeters.class) - public double cellHeight = 200; + private final double cellHeight; /** * The Grid to be used for spatial search of {@link VehicleObject}s. */ private Grid vehicleGrid; + public VehicleGrid(double cellWidth, double cellHeight) { + this.cellWidth = cellWidth; + this.cellHeight = cellHeight; + } + /** * Configures a grid as a spatial index for vehicles. */ diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleIndex.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleIndex.java index ee5281a7f..9c4997e54 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleIndex.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleIndex.java @@ -21,21 +21,18 @@ import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.SimplePerceptionConfiguration; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.TrafficObjectIndex; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.VehicleObject; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.util.VehicleIndexTypeAdapterFactory; import org.eclipse.mosaic.fed.application.app.api.perception.PerceptionModule; import org.eclipse.mosaic.lib.database.Database; import org.eclipse.mosaic.lib.geo.CartesianPoint; import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; import org.eclipse.mosaic.lib.objects.vehicle.VehicleType; -import com.google.gson.annotations.JsonAdapter; import org.slf4j.Logger; import java.util.HashMap; import java.util.List; import java.util.Map; -@JsonAdapter(VehicleIndexTypeAdapterFactory.class) public abstract class VehicleIndex { /** diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleMap.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleMap.java deleted file mode 100644 index b4fd78b45..000000000 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleMap.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2022 Fraunhofer FOKUS and others. All rights reserved. - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contact: mosaic@fokus.fraunhofer.de - */ - -package org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers; - -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.PerceptionModel; -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.ambassador.simulation.perception.SimplePerceptionModule; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.TrafficObjectIndex; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.VehicleObject; -import org.eclipse.mosaic.fed.application.app.api.perception.PerceptionModule; -import org.eclipse.mosaic.lib.database.Database; - -import org.slf4j.Logger; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * Trivial implementation of {@link TrafficObjectIndex}, which uses a for loop to solve the range query. - */ -public class VehicleMap extends VehicleIndex { - - @Override - public void initialize() { - // nothing to initialize - } - - @Override - public List getVehiclesInRange(PerceptionModel searchRange) { - return indexedVehicles.values().stream() - .filter(searchRange::isInRange) - .collect(Collectors.toList()); - } - - @Override - void onVehicleAdded(VehicleObject vehicleObject) { - // do nothing - } - - @Override - void onIndexUpdate() { - // do nothing - } - - @Override - void onVehicleRemoved(VehicleObject vehicleObject) { - // do nothing - } - - @Override - public PerceptionModule createPerceptionModule(PerceptionModuleOwner owner, Database database, Logger log) { - return new SimplePerceptionModule(owner, database, log); - } -} diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleTree.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleTree.java index 52b56b2bb..e25b136c0 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleTree.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/VehicleTree.java @@ -28,7 +28,6 @@ import org.eclipse.mosaic.lib.spatial.BoundingBox; import org.eclipse.mosaic.lib.spatial.QuadTree; -import com.google.gson.annotations.Expose; import org.slf4j.Logger; import java.util.ArrayList; @@ -40,23 +39,24 @@ public class VehicleTree extends VehicleIndex { /** * The maximum amount of vehicles in one leaf before it gets split into four sub-leaves. - * Filled by gson. */ - @Expose() - public int splitSize = 20; + private final int splitSize; /** * Maximum depth of the quad tree. - * Filled by gson. */ - @Expose() - public int maxDepth = 12; + private final int maxDepth; /** * The Quad-Tree to be used for spatial search of {@link VehicleObject}s. */ private QuadTree vehicleTree; + public VehicleTree(int splitSize, int maxDepth) { + this.splitSize = splitSize; + this.maxDepth = maxDepth; + } + /** * Configures a QuadTree as spatial index for vehicles on first use. */ diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/WallIndex.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/WallIndex.java index c9e99e5bd..ecb4d55ec 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/WallIndex.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/WallIndex.java @@ -16,16 +16,12 @@ package org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.PerceptionModel; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.util.WallIndexTypeAdapterFactory; import org.eclipse.mosaic.lib.database.Database; import org.eclipse.mosaic.lib.math.Vector3d; import org.eclipse.mosaic.lib.spatial.Edge; -import com.google.gson.annotations.JsonAdapter; - import java.util.Collection; -@JsonAdapter(WallIndexTypeAdapterFactory.class) public abstract class WallIndex { private Database database = null; diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/WallTree.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/WallTree.java index fd0e96df4..496453b73 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/WallTree.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/index/providers/WallTree.java @@ -24,21 +24,20 @@ import org.eclipse.mosaic.lib.spatial.SpatialItemAdapter; import org.eclipse.mosaic.lib.spatial.SpatialTreeTraverser; -import com.google.gson.annotations.Expose; - import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; public class WallTree extends WallIndex { - @Expose - public int bucketSize = 20; + private final int bucketSize; private KdTree> wallTree; private SpatialTreeTraverser.InRadius> wallTraverser; + public WallTree(int bucketSize) { + this.bucketSize = bucketSize; + } @Override public void initialize() { diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/TrafficLightIndexTypeAdapterFactory.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/TrafficLightIndexTypeAdapterFactory.java deleted file mode 100644 index d57972de7..000000000 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/TrafficLightIndexTypeAdapterFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2022 Fraunhofer FOKUS and others. All rights reserved. - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contact: mosaic@fokus.fraunhofer.de - */ - -package org.eclipse.mosaic.fed.application.ambassador.simulation.perception.util; - -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.TrafficLightIndex; -import org.eclipse.mosaic.lib.util.gson.PackageSpecificTypeAdapter; - -import com.google.gson.Gson; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; -import com.google.gson.reflect.TypeToken; - -public class TrafficLightIndexTypeAdapterFactory implements TypeAdapterFactory { - - @Override - public TypeAdapter create(Gson gson, TypeToken typeToken) { - return new PackageSpecificTypeAdapter(this, gson) - .searchInPackageOfClass(TrafficLightIndex.class) - .nullSafe(); - } -} diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/VehicleIndexTypeAdapterFactory.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/VehicleIndexTypeAdapterFactory.java deleted file mode 100644 index aa143446f..000000000 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/VehicleIndexTypeAdapterFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2022 Fraunhofer FOKUS and others. All rights reserved. - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contact: mosaic@fokus.fraunhofer.de - */ - -package org.eclipse.mosaic.fed.application.ambassador.simulation.perception.util; - -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleIndex; -import org.eclipse.mosaic.lib.util.gson.PackageSpecificTypeAdapter; - -import com.google.gson.Gson; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; -import com.google.gson.reflect.TypeToken; - -public class VehicleIndexTypeAdapterFactory implements TypeAdapterFactory { - - @Override - public TypeAdapter create(Gson gson, TypeToken typeToken) { - return new PackageSpecificTypeAdapter(this, gson) - .searchInPackageOfClass(VehicleIndex.class) - .nullSafe(); - } -} \ No newline at end of file diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/WallIndexTypeAdapterFactory.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/WallIndexTypeAdapterFactory.java deleted file mode 100644 index f58633675..000000000 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/util/WallIndexTypeAdapterFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2023 Fraunhofer FOKUS and others. All rights reserved. - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contact: mosaic@fokus.fraunhofer.de - */ - -package org.eclipse.mosaic.fed.application.ambassador.simulation.perception.util; - -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.WallIndex; -import org.eclipse.mosaic.lib.util.gson.PackageSpecificTypeAdapter; - -import com.google.gson.Gson; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; -import com.google.gson.reflect.TypeToken; - -public class WallIndexTypeAdapterFactory implements TypeAdapterFactory { - - @Override - public TypeAdapter create(Gson gson, TypeToken typeToken) { - return new PackageSpecificTypeAdapter(this, gson) - .searchInPackageOfClass(WallIndex.class) - .nullSafe(); - } -} diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/config/CApplicationAmbassador.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/config/CApplicationAmbassador.java index ac2e34f5a..c03116e4c 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/config/CApplicationAmbassador.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/config/CApplicationAmbassador.java @@ -15,11 +15,6 @@ package org.eclipse.mosaic.fed.application.config; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.TrafficLightIndex; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleIndex; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.WallIndex; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.WallTree; -import org.eclipse.mosaic.lib.geo.GeoRectangle; import org.eclipse.mosaic.lib.routing.config.CRouting; import org.eclipse.mosaic.lib.util.gson.TimeFieldAdapter; import org.eclipse.mosaic.lib.util.scheduling.MultiThreadedEventScheduler; @@ -42,11 +37,6 @@ public class CApplicationAmbassador implements Serializable { @JsonAdapter(TimeFieldAdapter.NanoSeconds.class) public long messageCacheTime = 30 * TIME.SECOND; - /** - * The minimal size which the payload of any ETSI message (CAM, DENM, IVIM) pay should have. Unit: [bytes]. - */ - public int minimalPayloadLength = 200; - /** * If set to {@code true}, messages (e.g. CAMs, DENMs, or SPATMs) will be encoded * into a byte array. If set to {@code false}, only there length is stored which @@ -89,34 +79,4 @@ public static class CRoutingByType extends CRouting implements Serializable { * to determine surrounding vehicles. */ public CPerception perceptionConfiguration = new CPerception(); - - public static class CPerception implements Serializable { - - /** - * Backend for the spatial index providing vehicle information. - */ - public VehicleIndex vehicleIndex; - - /** - * Backend for the spatial index providing traffic light information. - */ - public TrafficLightIndex trafficLightIndex; - - /** - * Backend for the spatial index providing information about building walls. - */ - public WallIndex wallIndex = new WallTree(); - - /** - * Area defining the section of the map in which traffic lights should be held in the index. - * This is useful if only part of your network contains vehicles. - */ - public GeoRectangle perceptionArea; - - /** - * If set to {@code true}, a PerceptionPerformance.csv is generated with detailed information about execution calls - * of the perception backend. - */ - public boolean measurePerformance = false; - } } diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/config/CPerception.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/config/CPerception.java new file mode 100644 index 000000000..49df682ad --- /dev/null +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/config/CPerception.java @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2023 Fraunhofer FOKUS and others. All rights reserved. + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contact: mosaic@fokus.fraunhofer.de + */ + +package org.eclipse.mosaic.fed.application.config; + +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.SumoIndex; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.TrafficLightIndex; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.TrafficLightTree; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleGrid; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleIndex; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleTree; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.WallIndex; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.WallTree; +import org.eclipse.mosaic.lib.geo.GeoRectangle; +import org.eclipse.mosaic.lib.gson.TypeFieldTypeAdapter; +import org.eclipse.mosaic.lib.util.gson.UnitFieldAdapter; + +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.annotations.JsonAdapter; +import com.google.gson.reflect.TypeToken; + +import java.io.Serializable; + +/** + * Configuration for the perception backend used in the ApplicationSimulator + * to determine surrounding vehicles, traffic lights, and buildings. + */ +public class CPerception implements Serializable { + + /** + * Backend for the spatial index providing vehicle information. + */ + public CVehicleIndex vehicleIndex = new CVehicleIndex.Tree(); + + /** + * Backend for the spatial index providing traffic light information. + */ + public CTrafficLightIndex trafficLightIndex = new CTrafficLightIndex(); + + /** + * Backend for the spatial index providing information about building walls. + */ + public CWallIndex wallIndex = new CWallIndex(); + + /** + * Area defining the section of the map in which traffic objects (traffic lights, vehicles) should be held in the index. + * This is useful if only part of your network contains vehicles. + */ + public GeoRectangle perceptionArea; + + /** + * A base class for configuring the VehicleIndex implementation to use during perception. Based on a hidden "type" parameter, + * JSON deserialization chooses from Tree, Grid, or SUMO configuration. Possible type values are: "tree", "grid", "sumo" + */ + @JsonAdapter(CVehicleIndexTypeAdapterFactory.class) + public static abstract class CVehicleIndex implements Serializable { + + /** + * Defines if the vehicle index is enabled. Default: false + */ + public boolean enabled = true; + + /** + * Creates the specific {@link VehicleIndex} instance based on the present configuration. + */ + public abstract VehicleIndex create(); + + /** + * Class for configuring a {@link VehicleTree} index. + */ + private static class Tree extends CVehicleIndex { + + public int splitSize = 20; + public int maxDepth = 12; + + @Override + public VehicleIndex create() { + return enabled ? new VehicleTree(splitSize, maxDepth) : null; + } + } + + /** + * Class for configuring a {@link VehicleGrid} index. + */ + private static class Grid extends CVehicleIndex { + + @JsonAdapter(UnitFieldAdapter.DistanceMeters.class) + public double cellWidth = 200; + + @JsonAdapter(UnitFieldAdapter.DistanceMeters.class) + public double cellHeight = 200; + + @Override + public VehicleIndex create() { + return enabled ? new VehicleGrid(cellWidth, cellHeight) : null; + } + + } + + /** + * Class for configuring a vehicle index based on SUMO context subscriptions. + */ + private static class Sumo extends CVehicleIndex { + + @Override + public VehicleIndex create() { + return enabled ? new SumoIndex() : null; + } + } + } + + public static class CTrafficLightIndex implements Serializable { + + /** + * Defines if the traffic index is enabled. Default: false + */ + public boolean enabled = false; + public int bucketSize = 20; + + public TrafficLightIndex create() { + return enabled ? new TrafficLightTree(bucketSize) : null; + } + } + + public static class CWallIndex implements Serializable { + + /** + * Defines if the wall index is enabled. Default: false + */ + public boolean enabled = false; + public int bucketSize = 20; + + public WallIndex create() { + return enabled ? new WallTree(bucketSize) : null; + } + } + + static class CVehicleIndexTypeAdapterFactory implements TypeAdapterFactory { + + static class CVehicleIndexTypeAdapter extends TypeFieldTypeAdapter { + + protected CVehicleIndexTypeAdapter(TypeAdapterFactory parentFactory, Gson gson) { + super(parentFactory, gson); + allowNullType(); + } + + @Override + protected Class fromTypeName(String type) { + if (type == null) { + return CVehicleIndex.Tree.class; + } + switch (type.toLowerCase()) { + case "grid": + return CVehicleIndex.Grid.class; + case "sumo": + return CVehicleIndex.Sumo.class; + case "tree": + return CVehicleIndex.Tree.class; + default: + throw new IllegalArgumentException("Unknown index type " + type + ". Known types are: grid, tree, sumo."); + } + } + + @Override + protected String toTypeName(Class typeClass) { + if (typeClass.equals(CVehicleIndex.Tree.class)) { + return "tree"; + } else if (typeClass.equals(CVehicleIndex.Grid.class)) { + return "grid"; + } else if (typeClass.equals(CVehicleIndex.Sumo.class)) { + return "sumo"; + } + return null; + } + } + + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken typeToken) { + return (TypeAdapter) new CVehicleIndexTypeAdapter(this, gson).nullSafe(); + } + } + + +} diff --git a/fed/mosaic-application/src/main/resources/CApplicationAmbassadorScheme.json b/fed/mosaic-application/src/main/resources/CApplicationAmbassadorScheme.json index 24d613a20..8cabada77 100644 --- a/fed/mosaic-application/src/main/resources/CApplicationAmbassadorScheme.json +++ b/fed/mosaic-application/src/main/resources/CApplicationAmbassadorScheme.json @@ -65,10 +65,6 @@ "description": "The underlying data structure for the spatial index for building walls", "$ref": "#/definitions/wallIndex" }, - "measurePerformance": { - "description": "If set to true, a PerceptionPerformance.csv is generated with detailed information about execution calls of the perception backend.", - "type": "boolean" - }, "perceptionArea": { "description": "Area used to define the bounds of the perception index. Useful if only part of your scenario needs to evaluate perception.", "$ref": "#/definitions/geoRectangle" @@ -80,34 +76,53 @@ "description": "Class providing the spatial index for the perception of vehicles.", "type": "object", "oneOf": [ - { "$ref": "#/definitions/vehicleMap" }, { "$ref": "#/definitions/vehicleTree" }, { "$ref": "#/definitions/vehicleGrid" }, { "$ref": "#/definitions/sumoIndex" } ] }, - "vehicleMap": { - "title": "vehicleMap", - "description": "Trivial spatial vehicle index using a hash map to store vehicles.", + "vehicleTree": { + "title": "vehicleTree", + "description": "Spatial vehicle index using a quad tree structure to store vehicles.", "type": "object", "properties": { + "enabled": { + "description": "Defines, if the vehicle index is enabled.", + "default": false, + "type": "boolean" + }, "type": { "description": "The type of the spatial index.", "type": "string", - "enum": [ "VehicleMap" ] + "enum": [ "tree" ] + }, + "splitSize": { + "description": "The maximum amount of vehicles in one leaf before it gets split into four sub-leaves.", + "type": "number", + "minimum": 0 + }, + "maxDepth": { + "description": "Maximum depth of the quad tree.", + "type": "number", + "minimum": 0 } }, - "required": [ "type" ] + "additionalProperties": false }, "vehicleGrid": { "title": "vehicleGrid", "description": "Spatial vehicle index using a grid structure to store vehicles.", "type": "object", "properties": { + "enabled": { + "description": "Defines, if the vehicle index is enabled.", + "default": false, + "type": "boolean" + }, "type": { "description": "The type of the spatial index.", "type": "string", - "enum": [ "VehicleGrid" ] + "enum": [ "grid" ] }, "cellWidth": { "description": "Width of a grid cell. [m]", @@ -124,108 +139,63 @@ ] } }, - "required": [ "type" ] - }, - "vehicleTree": { - "title": "vehicleTree", - "description": "Spatial vehicle index using a quad tree structure to store vehicles.", - "type": "object", - "properties": { - "type": { - "description": "The type of the spatial index.", - "type": "string", - "enum": [ "VehicleTree" ] - }, - "splitSize": { - "description": "The maximum amount of vehicles in one leaf before it gets split into four sub-leaves.", - "type": "number", - "minimum": 0 - }, - "maxDepth": { - "description": "Maximum depth of the quad tree.", - "type": "number", - "minimum": 0 - } - }, - "required": [ "type" ] + "required": [ "type" ], + "additionalProperties": false }, "sumoIndex": { "title": "sumoIndex", "description": "Class setting the index provider to use SUMO's built-in functions (see context subscription)", "type": "object", "properties": { + "enabled": { + "description": "Defines, if the vehicle index is enabled.", + "default": false, + "type": "boolean" + }, "type": { "description": "The type of the spatial index.", "type": "string", - "enum": [ "SumoIndex" ] + "enum": [ "sumo" ] } - } + }, + "required": [ "type" ], + "additionalProperties": false }, "trafficLightIndex": { "title": "trafficLightIndex", "description": "Class providing the spatial index for the perception of traffic lights.", "type": "object", - "oneOf": [ - { "$ref": "#/definitions/trafficLightMap" }, - { "$ref": "#/definitions/trafficLightTree" } - ] - }, - "trafficLightMap": { - "title": "trafficLightMap", - "description": "Trivial spatial index using a hash map to store traffic lights.", - "type": "object", "properties": { - "type": { - "description": "The type of the spatial index.", - "type": "string", - "enum": [ "TrafficLightMap" ] - } - }, - "required": [ "type" ] - }, - "trafficLightTree": { - "title": "trafficLightTree", - "description": "Spatial index using a kd-tree structure to store traffic lights.", - "type": "object", - "properties": { - "type": { - "description": "The type of the spatial index.", - "type": "string", - "enum": [ "TrafficLightTree" ] + "enabled": { + "description": "Defines, if the traffic light index is enabled.", + "default": false, + "type": "boolean" + }, + "bucketSize": { + "description": "The maximum amount of traffic lights in one leaf before it gets split.", + "type": "number", + "minimum": 0 } }, - "bucketSize": { - "description": "The maximum amount of traffic lights in one leaf before it gets split.", - "type": "number", - "minimum": 0 - }, - "required": [ "type" ] + "additionalProperties": false }, "wallIndex": { "title": "wallIndex", "description": "Class providing the spatial index for the perception of building walls.", "type": "object", - "oneOf": [ - { "$ref": "#/definitions/wallTree" } - ] - }, - "wallTree": { - "title": "wallTree", - "description": "Spatial index using a kd-tree structure to store building walls.", - "type": "object", "properties": { - "type": { - "description": "The type of the spatial index.", - "type": "string", - "enum": [ "WallTree" ] + "enabled": { + "description": "Defines, if the wall index is enabled.", + "default": false, + "type": "boolean" + }, + "bucketSize": { + "description": "The maximum amount of building walls in one leaf before it gets split.", + "type": "number", + "minimum": 0 } }, - "bucketSize": { - "description": "The maximum amount of building walls in one leaf before it gets split.", - "type": "number", - "minimum": 0 - }, - "required": [ "type" ] + "additionalProperties": false }, "geoPoint": { "title": "geoPoint", diff --git a/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/UnitSimulatorTest.java b/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/UnitSimulatorTest.java index 964c78039..fe94798d0 100644 --- a/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/UnitSimulatorTest.java +++ b/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/UnitSimulatorTest.java @@ -362,8 +362,8 @@ public void addTrafficLightWithoutApplication() { TrafficLightRegistration trafficLightRegistration = InteractionTestHelper.createTrafficLightRegistration("tl_0", 0, false); sim.registerTrafficLight(trafficLightRegistration); - assertEquals(0, sim.getAllUnits().size()); assertEquals(0, sim.getTrafficLights().size()); + assertEquals(0, sim.getAllUnits().size()); } /** diff --git a/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/navigation/NavigationModuleTest.java b/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/navigation/NavigationModuleTest.java index 269ad8b1b..68f767a38 100644 --- a/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/navigation/NavigationModuleTest.java +++ b/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/navigation/NavigationModuleTest.java @@ -32,6 +32,7 @@ import org.eclipse.mosaic.fed.application.ambassador.SimulationKernel; import org.eclipse.mosaic.fed.application.ambassador.SimulationKernelRule; import org.eclipse.mosaic.fed.application.ambassador.simulation.VehicleUnit; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.CentralPerceptionComponent; import org.eclipse.mosaic.fed.application.config.CApplicationAmbassador; import org.eclipse.mosaic.lib.geo.GeoPoint; import org.eclipse.mosaic.lib.junit.IpResolverRule; @@ -80,7 +81,7 @@ public class NavigationModuleTest { @InjectMocks @Rule - public SimulationKernelRule kernelRule = new SimulationKernelRule(eventMngMock, null, cncMock, null); + public SimulationKernelRule kernelRule = new SimulationKernelRule(eventMngMock, null, cncMock, mock(CentralPerceptionComponent.class)); @Rule public IpResolverRule ipResolverRule = new IpResolverRule(); @@ -97,7 +98,6 @@ public void setup() { navigationModule = Mockito.spy(new NavigationModule(vehicle)); navigationModule.setVehicleData(vehicleDataMock); - when(vehicleDataMock.getHeading()).thenReturn(45.0d); when(vehicleDataMock.getPosition()).thenReturn(GeoPoint.latLon(10, 10)); when(vehicleDataMock.getRoadPosition()).thenReturn(mock(IRoadPosition.class)); diff --git a/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/PerceptionModifierTest.java b/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/PerceptionModifierTest.java index 8b04d65c0..3c375712b 100644 --- a/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/PerceptionModifierTest.java +++ b/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/PerceptionModifierTest.java @@ -17,8 +17,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -29,14 +29,16 @@ import org.eclipse.mosaic.fed.application.ambassador.navigation.CentralNavigationComponent; import org.eclipse.mosaic.fed.application.ambassador.simulation.VehicleUnit; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.errormodels.BoundingBoxOcclusion; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.errormodels.DimensionsModifier; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.errormodels.DistanceFilter; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.errormodels.HeadingModifier; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.errormodels.PositionModifier; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.errormodels.SimpleOcclusion; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.errormodels.WallOcclusion; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.TrafficObjectIndex; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.SpatialObject; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.VehicleObject; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleMap; +import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleTree; import org.eclipse.mosaic.fed.application.config.CApplicationAmbassador; import org.eclipse.mosaic.lib.geo.CartesianPoint; import org.eclipse.mosaic.lib.geo.CartesianRectangle; @@ -111,7 +113,7 @@ public void setup() { when(vehicleType.getWidth()).thenReturn(2.5d); when(vehicleType.getHeight()).thenReturn(10d); trafficObjectIndex = new TrafficObjectIndex.Builder(mock(Logger.class)) - .withVehicleIndex(new VehicleMap()) + .withVehicleIndex(new VehicleTree(20, 12)) .build(); // setup cpc when(cpcMock.getTrafficObjectIndex()).thenReturn(trafficObjectIndex); @@ -174,6 +176,57 @@ public void testPositionErrorModifier() { assertEquals("The position error filter shouldn't remove vehicles", VEHICLE_AMOUNT, perceivedVehicles.size()); } + @Test + public void testHeadingModifier() { + HeadingModifier headingModifier = new HeadingModifier(rng, 10, 0); + simplePerceptionModule.enable( + new SimplePerceptionConfiguration.Builder(VIEWING_ANGLE, VIEWING_RANGE).addModifier(headingModifier).build() + ); + + // RUN + List perceivedVehicles = simplePerceptionModule.getPerceivedVehicles(); + if (PRINT_POSITIONS) { + printBoundingBoxes(perceivedVehicles); + } + assertEquals("The position error filter shouldn't remove vehicles", VEHICLE_AMOUNT, perceivedVehicles.size()); + + // ASSERT if headings differ from ground truth + for (VehicleObject realVehicle : getAllVehicles()) { + for (VehicleObject perceivedVehicle: perceivedVehicles) { + if (realVehicle.getId().equals(perceivedVehicle.getId())) { + assertNotEquals(realVehicle.getHeading(), perceivedVehicle.getHeading(), 0.0001); + // when adjusting heading the position should change too, since it currently points to the front bumper of the vehicle + assertNotEquals(realVehicle.getPosition(), perceivedVehicle.getPosition()); + } + } + } + } + + @Test + public void testDimensionsModifier() { + DimensionsModifier dimensionsModifier = new DimensionsModifier(rng, 1.0, 0.0, 0.0); + simplePerceptionModule.enable( + new SimplePerceptionConfiguration.Builder(VIEWING_ANGLE, VIEWING_RANGE).addModifier(dimensionsModifier).build() + ); + + List perceivedVehicles = simplePerceptionModule.getPerceivedVehicles(); + if (PRINT_POSITIONS) { + printBoundingBoxes(perceivedVehicles); + } + assertEquals("The position error filter shouldn't remove vehicles", VEHICLE_AMOUNT, perceivedVehicles.size()); + + // ASSERT if headings differ from ground truth + for (VehicleObject realVehicle : getAllVehicles()) { + for (VehicleObject perceivedVehicle: perceivedVehicles) { + if (realVehicle.getId().equals(perceivedVehicle.getId())) { + assertNotEquals(realVehicle.getLength(), perceivedVehicle.getLength(), 0.0001); + // when adjusting length the position should change too, since it currently points to the front bumper of the vehicle + assertNotEquals(realVehicle.getPosition(), perceivedVehicle.getPosition()); + } + } + } + } + @Test public void testWallOcclusionModifier() { List> surroundingWalls = Lists.newArrayList( @@ -206,16 +259,14 @@ public void testIndexedObjectsNotChanged() { ); // collect positions of perceived objects BEFORE applying modifier - PerceptionModel godView = mock(PerceptionModel.class); - when(godView.isInRange(isA(SpatialObject.class))).thenReturn(true); - Map allVehiclesInIndexPre = trafficObjectIndex.getVehiclesInRange(godView) + Map allVehiclesInIndexPre = getAllVehicles() .stream().collect(Collectors.toMap(VehicleObject::getId, v -> new Vector3d(v.getPosition()))); // RUN perceived objects and modify positions List perceivedAndAlteredObjects = simplePerceptionModule.getPerceivedVehicles(); // collect positions of perceived objects AFTER applying modifier - Map allVehiclesInIndexPost = trafficObjectIndex.getVehiclesInRange(godView) + Map allVehiclesInIndexPost = getAllVehicles() .stream().collect(Collectors.toMap(VehicleObject::getId, v -> new Vector3d(v.getPosition()))); // ASSERT that all positions in the index are still the same as before applying modifier diff --git a/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/SimplePerceptionModuleTest.java b/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/SimplePerceptionModuleTest.java index 4e8b6cae4..f438855c5 100644 --- a/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/SimplePerceptionModuleTest.java +++ b/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/ambassador/simulation/perception/SimplePerceptionModuleTest.java @@ -27,10 +27,8 @@ import org.eclipse.mosaic.fed.application.ambassador.simulation.VehicleUnit; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.TrafficObjectIndex; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.objects.VehicleObject; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.TrafficLightMap; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.TrafficLightTree; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleGrid; -import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleMap; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.index.providers.VehicleTree; import org.eclipse.mosaic.fed.application.config.CApplicationAmbassador; import org.eclipse.mosaic.lib.geo.CartesianPoint; @@ -51,24 +49,28 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoRule; import org.slf4j.Logger; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; -@RunWith(MockitoJUnitRunner.class) +@RunWith(Parameterized.class) public class SimplePerceptionModuleTest { + private final String vehicleIndexType; private final EventManager eventManagerMock = mock(EventManager.class); private final CentralPerceptionComponent cpcMock = mock(CentralPerceptionComponent.class); private final CentralNavigationComponent cncMock = mock(CentralNavigationComponent.class); + @Rule public MockitoRule initRule = MockitoJUnit.rule(); @@ -87,6 +89,17 @@ public class SimplePerceptionModuleTest { private SimplePerceptionModule simplePerceptionModule; + public SimplePerceptionModuleTest(String vehicleIndexType) { + this.vehicleIndexType = vehicleIndexType; + } + + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList(new Object[][]{ + {"grid"}, {"tree"} + }); + } + @Before public void setup() { when(cpcMock.getScenarioBounds()) @@ -94,8 +107,11 @@ public void setup() { SimulationKernel.SimulationKernel.setConfiguration(new CApplicationAmbassador()); trafficObjectIndex = new TrafficObjectIndex.Builder(mock((Logger.class))) - .withVehicleIndex(new VehicleMap()) - .withTrafficLightIndex(new TrafficLightMap()) + .withVehicleIndex( + vehicleIndexType.equals("tree") ? new VehicleTree(20, 12) : + vehicleIndexType.equals("grid") ? new VehicleGrid(5, 5) : null + ) + .withTrafficLightIndex(new TrafficLightTree(20)) .build(); // setup cpc when(cpcMock.getTrafficObjectIndex()).thenReturn(trafficObjectIndex); @@ -111,89 +127,13 @@ public void setup() { } @Test - public void vehicleCanBePerceived_TrivialIndex() { - setupVehicles(new MutableCartesianPoint(110, 100, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_includesDimensions_TrivialIndex() { - setupVehicles(new MutableCartesianPoint(110, 100, 0)); - List perceivedVehicles = simplePerceptionModule.getPerceivedVehicles(); - assertEquals(1, perceivedVehicles.size()); - VehicleObject perceivedVehicle = perceivedVehicles.get(0); - assertEquals(5d, perceivedVehicle.getLength(), 0.01); - assertEquals(2.5d, perceivedVehicle.getWidth(), 0.01); - assertEquals(10d, perceivedVehicle.getHeight(), 0.01); - } - - @Test - public void vehicleCannotBePerceived_outOfRange_TrivialIndex() { - setupVehicles(new MutableCartesianPoint(310, 100, 0)); - assertEquals(0, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_OnLeftBoundVector_TrivialIndex() { - setupVehicles(new MutableCartesianPoint(110, 110, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCannotBePerceived_OnLeftBoundVector_OppositeDirection_TrivialIndex() { - setupVehicles(new MutableCartesianPoint(90, 90, 0)); - assertEquals(0, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_OnRightBoundVector_TrivialIndex() { - setupVehicles(new MutableCartesianPoint(110, 90, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCannotBePerceived_tooFarLeft_TrivialIndex() { - setupVehicles(new MutableCartesianPoint(105, 115, 0)); - assertEquals(0, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCannotBePerceived_tooFarRight_TrivialIndex() { - setupVehicles(new MutableCartesianPoint(105, 90, 0)); - assertEquals(0, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_270viewingAngle_VehicleOnDirectionVector_TrivialIndex() { - simplePerceptionModule.enable(new SimplePerceptionConfiguration.Builder(270d, 200d).build()); // overwrite config + public void vehicleCanBePerceived() { setupVehicles(new MutableCartesianPoint(110, 100, 0)); assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); } @Test - public void vehicleCanBePerceived_FarLeft_270viewingAngle_TrivialIndex() { - simplePerceptionModule.enable(new SimplePerceptionConfiguration.Builder(270d, 200d).build()); // overwrite config - setupVehicles(new MutableCartesianPoint(105, 115, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_FarRight_270viewingAngle_TrivialIndex() { - simplePerceptionModule.enable(new SimplePerceptionConfiguration.Builder(270d, 200d).build()); // overwrite config - setupVehicles(new MutableCartesianPoint(105, 90, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_QuadTree() { - useQuadTree(); - setupVehicles(new MutableCartesianPoint(110, 100, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_includesDimensions_QuadTree() { - useQuadTree(); + public void vehicleCanBePerceived_includesDimensions() { setupVehicles(new MutableCartesianPoint(110, 100, 0)); List perceivedVehicles = simplePerceptionModule.getPerceivedVehicles(); assertEquals(1, perceivedVehicles.size()); @@ -204,137 +144,51 @@ public void vehicleCanBePerceived_includesDimensions_QuadTree() { } @Test - public void vehicleCannotBePerceived_outOfRange_QuadTree() { - useQuadTree(); + public void vehicleCannotBePerceived_outOfRange() { setupVehicles(new MutableCartesianPoint(310, 100, 0)); assertEquals(0, simplePerceptionModule.getPerceivedVehicles().size()); } @Test - public void vehicleCanBePerceived_OnLeftBoundVector_QuadTree() { - useQuadTree(); + public void vehicleCanBePerceived_OnLeftBoundVector() { setupVehicles(new MutableCartesianPoint(110, 110, 0)); assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); } @Test - public void vehicleCanBePerceived_OnRightBoundVector_QuadTree() { - useQuadTree(); + public void vehicleCanBePerceived_OnRightBoundVector() { setupVehicles(new MutableCartesianPoint(110, 90, 0)); assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); } @Test - public void vehicleCannotBePerceived_tooFarLeft_QuadTree() { - useQuadTree(); + public void vehicleCannotBePerceived_tooFarLeft() { setupVehicles(new MutableCartesianPoint(105, 115, 0)); assertEquals(0, simplePerceptionModule.getPerceivedVehicles().size()); } @Test - public void vehicleCannotBePerceived_tooFarRight_QuadTree() { - useQuadTree(); + public void vehicleCannotBePerceived_tooFarRight() { setupVehicles(new MutableCartesianPoint(105, 90, 0)); assertEquals(0, simplePerceptionModule.getPerceivedVehicles().size()); } @Test - public void vehicleCanBePerceived_FarLeft_270viewingAngle_QuadTree() { - useQuadTree(); + public void vehicleCanBePerceived_FarLeft_270viewingAngle() { simplePerceptionModule.enable(new SimplePerceptionConfiguration.Builder(270d, 200d).build()); // overwrite config setupVehicles(new MutableCartesianPoint(105, 115, 0)); assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); } @Test - public void vehicleCanBePerceived_FarRight_270viewingAngle_QuadTree() { - useQuadTree(); + public void vehicleCanBePerceived_FarRight_270viewingAngle() { simplePerceptionModule.enable(new SimplePerceptionConfiguration.Builder(270d, 200d).build()); // overwrite config setupVehicles(new MutableCartesianPoint(105, 90, 0)); assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); } @Test - public void vehicleCanBePerceived_Grid() { - useGrid(); - setupVehicles(new MutableCartesianPoint(110, 100, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_includesDimensions_Grid() { - useQuadTree(); - setupVehicles(new MutableCartesianPoint(110, 100, 0)); - List perceivedVehicles = simplePerceptionModule.getPerceivedVehicles(); - assertEquals(1, perceivedVehicles.size()); - VehicleObject perceivedVehicle = perceivedVehicles.get(0); - assertEquals(5d, perceivedVehicle.getLength(), 0.01); - assertEquals(2.5d, perceivedVehicle.getWidth(), 0.01); - assertEquals(10d, perceivedVehicle.getHeight(), 0.01); - } - - @Test - public void vehicleCannotBePerceived_outOfRange_Grid() { - useGrid(); - setupVehicles(new MutableCartesianPoint(310, 100, 0)); - assertEquals(0, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_OnLeftBoundVector_Grid() { - useGrid(); - setupVehicles(new MutableCartesianPoint(110, 110, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_OnRightBoundVector_Grid() { - useGrid(); - setupVehicles(new MutableCartesianPoint(110, 90, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCannotBePerceived_tooFarLeft_Grid() { - useGrid(); - setupVehicles(new MutableCartesianPoint(105, 115, 0)); - assertEquals(0, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCannotBePerceived_tooFarRight_Grid() { - useGrid(); - setupVehicles(new MutableCartesianPoint(105, 90, 0)); - assertEquals(0, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_FarLeft_270viewingAngle_Grid() { - useGrid(); - simplePerceptionModule.enable(new SimplePerceptionConfiguration.Builder(270d, 200d).build()); // overwrite config - setupVehicles(new MutableCartesianPoint(105, 115, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void vehicleCanBePerceived_FarRight_270viewingAngle_Grid() { - useGrid(); - simplePerceptionModule.enable(new SimplePerceptionConfiguration.Builder(270d, 200d).build()); // overwrite config - setupVehicles(new MutableCartesianPoint(105, 90, 0)); - assertEquals(1, simplePerceptionModule.getPerceivedVehicles().size()); - } - - @Test - public void trafficLightsCanBePerceived_TrivialIndex() { - setupTrafficLights(new MutableCartesianPoint(110, 100, 0)); - - assertEquals(1, simplePerceptionModule.getTrafficLightsInRange().size()); - assertEquals(TrafficLightState.GREEN, simplePerceptionModule.getTrafficLightsInRange().get(0).getTrafficLightState()); - } - - @Test - public void trafficLightsCanBePerceived_TrafficLightTree() { - useTlTree(); + public void trafficLightsCanBePerceived() { setupTrafficLights(new MutableCartesianPoint(110, 100, 0)); trafficObjectIndex.updateTrafficLights(mock(Map.class)); // update needs to be called to initialize tree @@ -379,33 +233,4 @@ private void setupTrafficLights(CartesianPoint... positions) { TrafficLightGroup trafficLightGroup = new TrafficLightGroup("tls", trafficLightProgramsMocks, trafficLightMocks); trafficObjectIndex.addTrafficLightGroup(trafficLightGroup); } - - private void useQuadTree() { - VehicleTree vehicleTree = new VehicleTree(); - vehicleTree.splitSize = 20; - vehicleTree.maxDepth = 12; - trafficObjectIndex = new TrafficObjectIndex.Builder((mock(Logger.class))) - .withVehicleIndex(vehicleTree) - .build(); - when(cpcMock.getTrafficObjectIndex()).thenReturn(trafficObjectIndex); - } - - private void useGrid() { - VehicleGrid vehicleGrid = new VehicleGrid(); - vehicleGrid.cellHeight = 5; - vehicleGrid.cellWidth = 5; - trafficObjectIndex = new TrafficObjectIndex.Builder((mock(Logger.class))) - .withVehicleIndex(vehicleGrid) - .build(); - when(cpcMock.getTrafficObjectIndex()).thenReturn(trafficObjectIndex); - } - - private void useTlTree() { - TrafficLightTree trafficLightTree = new TrafficLightTree(); - trafficObjectIndex = new TrafficObjectIndex.Builder((mock(Logger.class))) - .withTrafficLightIndex(trafficLightTree) - .build(); - - when(cpcMock.getTrafficObjectIndex()).thenReturn(trafficObjectIndex); - } } diff --git a/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/config/CApplicationAmbassadorTest.java b/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/config/CApplicationAmbassadorTest.java index bd059a628..3fc41ab5d 100644 --- a/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/config/CApplicationAmbassadorTest.java +++ b/fed/mosaic-application/src/test/java/org/eclipse/mosaic/fed/application/config/CApplicationAmbassadorTest.java @@ -57,7 +57,6 @@ public void readValidConfig_assertProperties() throws InstantiationException { // ASSERT assertNotNull(applicationAmbassadorConfiguration); // assert that configuration is created assertEquals(40 * TIME.SECOND, applicationAmbassadorConfiguration.messageCacheTime); - assertEquals(1500L, applicationAmbassadorConfiguration.minimalPayloadLength); assertTrue(applicationAmbassadorConfiguration.encodePayloads); assertNull(applicationAmbassadorConfiguration.navigationConfiguration); diff --git a/lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/GeoAreaAdapterFactory.java b/lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/GeoAreaAdapterFactory.java index c7e56e7f0..cb46c9001 100644 --- a/lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/GeoAreaAdapterFactory.java +++ b/lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/GeoAreaAdapterFactory.java @@ -27,7 +27,7 @@ public final class GeoAreaAdapterFactory implements TypeAdapterFactory { - public static class GeoAreaAdapter extends AbstractTypeAdapterFactory { + public static class GeoAreaAdapter extends TypeFieldTypeAdapter { private final static String TYPE_RECTANGLE = "rectangle"; private final static String TYPE_CIRCLE = "circle"; diff --git a/lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/AbstractTypeAdapterFactory.java b/lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/TypeFieldTypeAdapter.java similarity index 77% rename from lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/AbstractTypeAdapterFactory.java rename to lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/TypeFieldTypeAdapter.java index dd170909f..e7c8e2678 100644 --- a/lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/AbstractTypeAdapterFactory.java +++ b/lib/mosaic-geomath/src/main/java/org/eclipse/mosaic/lib/gson/TypeFieldTypeAdapter.java @@ -30,18 +30,35 @@ import java.io.IOException; import java.util.Map; -public abstract class AbstractTypeAdapterFactory extends TypeAdapter { +/** + * A type adapter which creates an object of a specific type based on a hidden "type" field. + * An implementation of this abstract class must specify which type name translates to which target class. + * + * @param the base type of which objects are created during deserialization + */ +public abstract class TypeFieldTypeAdapter extends TypeAdapter { private final static String TYPE_FIELD = "type"; private final Gson gson; private final TypeAdapterFactory parentFactory; - protected AbstractTypeAdapterFactory(TypeAdapterFactory parentFactory, Gson gson) { + private boolean allowNullType = false; + + protected TypeFieldTypeAdapter(TypeAdapterFactory parentFactory, Gson gson) { this.parentFactory = parentFactory; this.gson = gson; } + /** + * By default, a missing "type" field in the input JSON string leads to an error. + * By calling this method any proceeding deserialization processes allow this missing field by + * passing {@code null} to {@link #fromTypeName} instead of throwing an exception. + */ + protected void allowNullType() { + this.allowNullType = true; + } + /** * Translates the name of the type to the class to deserialize. * @@ -62,10 +79,15 @@ protected AbstractTypeAdapterFactory(TypeAdapterFactory parentFactory, Gson gson public T read(JsonReader in) { JsonElement jsonElement = Streams.parse(in); JsonElement typeJsonElement = jsonElement.getAsJsonObject().remove(TYPE_FIELD); - if (typeJsonElement == null) { + + final String typeName; + if (typeJsonElement != null) { + typeName = typeJsonElement.getAsString(); + } else if (allowNullType) { + typeName = null; + } else { throw new JsonParseException("cannot deserialize because it does not define a field named " + TYPE_FIELD); } - String typeName = typeJsonElement.getAsString(); @SuppressWarnings("unchecked") TypeAdapter delegate = (TypeAdapter) gson.getDelegateAdapter(parentFactory, TypeToken.get(fromTypeName(typeName))); diff --git a/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/gson/PackageSpecificTypeAdapter.java b/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/gson/PackageSpecificTypeAdapter.java index f6c296bec..b80f81be9 100644 --- a/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/gson/PackageSpecificTypeAdapter.java +++ b/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/gson/PackageSpecificTypeAdapter.java @@ -15,7 +15,7 @@ package org.eclipse.mosaic.lib.util.gson; -import org.eclipse.mosaic.lib.gson.AbstractTypeAdapterFactory; +import org.eclipse.mosaic.lib.gson.TypeFieldTypeAdapter; import com.google.gson.Gson; import com.google.gson.JsonParseException; @@ -32,7 +32,7 @@ * with simple class names only, a search space of possible packages need to be defined, which * are used to resolve the actual class. */ -public final class PackageSpecificTypeAdapter extends AbstractTypeAdapterFactory { +public final class PackageSpecificTypeAdapter extends TypeFieldTypeAdapter { /** * Holds all package names which are used to search for suitable classes to instantiate based on the given type name. diff --git a/test/mosaic-integration-tests/src/test/java/org/eclipse/mosaic/test/PerceptionModuleMapIndexesIT.java b/test/mosaic-integration-tests/src/test/java/org/eclipse/mosaic/test/PerceptionModuleIT.java similarity index 82% rename from test/mosaic-integration-tests/src/test/java/org/eclipse/mosaic/test/PerceptionModuleMapIndexesIT.java rename to test/mosaic-integration-tests/src/test/java/org/eclipse/mosaic/test/PerceptionModuleIT.java index 47496bac0..b234a1dd8 100644 --- a/test/mosaic-integration-tests/src/test/java/org/eclipse/mosaic/test/PerceptionModuleMapIndexesIT.java +++ b/test/mosaic-integration-tests/src/test/java/org/eclipse/mosaic/test/PerceptionModuleIT.java @@ -17,11 +17,11 @@ import org.junit.BeforeClass; -public class PerceptionModuleMapIndexesIT extends AbstractPerceptionModuleIT { +public class PerceptionModuleIT extends AbstractPerceptionModuleIT { @BeforeClass public static void runSimulation() { - simulationRule.federateConfigurationManipulator("application", (conf) -> conf.configuration = "application_config_trivial.json"); + simulationRule.federateConfigurationManipulator("application", (conf) -> conf.configuration = "application_config_default.json"); simulationResult = simulationRule.executeTestScenario("perception-module"); } } diff --git a/test/scenarios/perception-module/application/application_config_trivial.json b/test/scenarios/perception-module/application/application_config_default.json similarity index 60% rename from test/scenarios/perception-module/application/application_config_trivial.json rename to test/scenarios/perception-module/application/application_config_default.json index e60543375..41bec5647 100644 --- a/test/scenarios/perception-module/application/application_config_trivial.json +++ b/test/scenarios/perception-module/application/application_config_default.json @@ -1,13 +1,13 @@ { "perceptionConfiguration": { "vehicleIndex": { - "type": "VehicleMap" + "enabled": true }, "trafficLightIndex": { - "type": "TrafficLightMap" + "enabled": true }, "wallIndex": { - "type": "WallTree" + "enabled": true } } } diff --git a/test/scenarios/perception-module/application/application_config_grid.json b/test/scenarios/perception-module/application/application_config_grid.json index 6515d7800..e257abf2c 100644 --- a/test/scenarios/perception-module/application/application_config_grid.json +++ b/test/scenarios/perception-module/application/application_config_grid.json @@ -1,15 +1,16 @@ { "perceptionConfiguration": { "vehicleIndex": { - "type": "VehicleGrid", + "enabled": true, + "type": "grid", "cellWidth": "5m", "cellHeight": "5m" }, "trafficLightIndex": { - "type": "TrafficLightMap" + "enabled": true }, "wallIndex": { - "type": "WallTree" + "enabled": true } } } diff --git a/test/scenarios/perception-module/application/application_config_quadtree.json b/test/scenarios/perception-module/application/application_config_quadtree.json index 3f120a821..32ed270e1 100644 --- a/test/scenarios/perception-module/application/application_config_quadtree.json +++ b/test/scenarios/perception-module/application/application_config_quadtree.json @@ -1,15 +1,16 @@ { "perceptionConfiguration": { "vehicleIndex": { - "type": "VehicleTree", + "enabled": true, + "type": "tree", "splitSize": 10, "maxDepth": 2 }, "trafficLightIndex": { - "type": "TrafficLightTree" + "enabled": true }, "wallIndex": { - "type": "WallTree" + "enabled": true } } } diff --git a/test/scenarios/perception-module/application/application_config_sumo.json b/test/scenarios/perception-module/application/application_config_sumo.json index 314ecf266..606a30382 100644 --- a/test/scenarios/perception-module/application/application_config_sumo.json +++ b/test/scenarios/perception-module/application/application_config_sumo.json @@ -1,13 +1,14 @@ { "perceptionConfiguration": { "vehicleIndex": { - "type": "SumoIndex" + "enabled": true, + "type": "sumo" }, "trafficLightIndex": { - "type": "TrafficLightMap" + "enabled": true }, "wallIndex": { - "type": "WallTree" + "enabled": true } } }