-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(perception): simplified configuration for perception index #351
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c0af3d
feat: simplified configuration for perception index
kschrab 3e84dd0
fix: remove unused configuration option
kschrab 2b6a029
feat: add example perception config for Barnim
kschrab 698e0af
clean: cleanup before review
kschrab 7df219a
fix: resolve spotbugs warning
kschrab 51a57d6
feat: add perception modifier for heading and dimensions
kschrab b516676
clean: work PR review
kschrab 3e3e743
clean: removed unused variable
kschrab 178a1d6
clean: use convenient order of dimension attributes
kschrab d72ee5f
clean: work PR review
kschrab e46a365
feat: enable vehicle index by default
kschrab 8f65f07
clean: format code
kschrab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
bundle/src/assembly/resources/scenarios/Barnim/application/application_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"messageCacheTime": "30s", | ||
"encodePayloads": true, | ||
"eventSchedulerThreads": 1, | ||
"navigationConfiguration": { | ||
"type": "database" | ||
}, | ||
"perceptionConfiguration": { | ||
"vehicleIndex": { | ||
"enabled": true | ||
}, | ||
"trafficLightIndex": { | ||
"enabled": true | ||
}, | ||
"wallIndex": { | ||
"enabled": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...saic/fed/application/ambassador/simulation/perception/errormodels/DimensionsModifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: [email protected] | ||
*/ | ||
|
||
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 { | ||
schwepmo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List<T> 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 | ||
); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We lost the validation of the
scenarioBounds
here, but maybe this isn't really necessary in the first placeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I also didn't see the reason for this check.