Skip to content
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 12 commits into from
Oct 4, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public void registerTrafficLight(TrafficLightRegistration trafficLightRegistrati
// 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) {
if (!trafficLightRegistration.getMapping().hasApplication() && !isTrafficLightIndexEnabled) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,43 @@
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 heightOffset;
private final double widthOffset;
private final double lengthOffset;
private final double heightDeviation;
private final double widthDeviation;
private final double lengthDeviation;

private final RandomNumberGenerator rng;


public DimensionsModifier(RandomNumberGenerator rng, double heightOffset, double widthOffset, double lengthOffset) {
public DimensionsModifier(RandomNumberGenerator rng, double heightDeviation, double widthDeviation, double lengthDeviation) {
this.rng = rng;
this.heightOffset = heightOffset;
this.widthOffset = widthOffset;
this.lengthOffset = lengthOffset;
this.heightDeviation = heightDeviation;
this.widthDeviation = widthDeviation;
this.lengthDeviation = lengthDeviation;
}

public DimensionsModifier(RandomNumberGenerator rng) {
this.rng = rng;
this.heightOffset = SIGMA_HEIGHT_OFFSET;
this.widthOffset = SIGMA_WIDTH_OFFSET;
this.lengthOffset = SIGMA_LENGTH_OFFSET;
this.heightDeviation = SIGMA_HEIGHT_OFFSET;
this.widthDeviation = SIGMA_WIDTH_OFFSET;
this.lengthDeviation = SIGMA_LENGTH_OFFSET;
}

@Override
Expand All @@ -62,10 +69,29 @@ public <T extends SpatialObject> List<T> apply(PerceptionModuleOwner owner, List
}

private void adjustDimensionsOfVehicle(VehicleObject vehicleObject) {

double oldLength = vehicleObject.getLength();

vehicleObject.setDimensions(
Math.abs(rng.nextGaussian(vehicleObject.getLength(), lengthOffset)),
Math.abs(rng.nextGaussian(vehicleObject.getHeight(), heightOffset)),
Math.abs(rng.nextGaussian(vehicleObject.getWidth(), widthOffset))
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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
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;
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 {
schwepmo marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand Down Expand Up @@ -53,6 +60,9 @@ public HeadingModifier(RandomNumberGenerator rng) {
}

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;
schwepmo marked this conversation as resolved.
Show resolved Hide resolved
this.headingStandardDeviation = headingStandardDeviation;
this.chanceOfWrongDirection = chanceOfWrongDirection;
Expand All @@ -74,12 +84,19 @@ private void adjustHeadingOfVehicle(Vector3d ownerPosition, VehicleObject vehicl
double oldHeading = vehicleObject.getHeading();

if (rng.nextDouble() < chanceOfWrongDirection) {
vehicleObject.setHeading(rotatedVehicleHeading(vehicleObject.getHeading()));
vehicleObject.setHeading((vehicleObject.getHeading() + 180) % 360);
kschrab marked this conversation as resolved.
Show resolved Hide resolved
}
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

kschrab marked this conversation as resolved.
Show resolved Hide resolved
Vector3d oldHeadingVector = VectorUtils.getDirectionVectorFromHeading(oldHeading, new Vector3d());
Vector3d newHeadingVector = VectorUtils.getDirectionVectorFromHeading(newHeading, new Vector3d());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,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));
Expand All @@ -112,8 +111,6 @@ public void setup() {
routeMap.put("123", new VehicleRoute("123", Collections.singletonList("edgeID"), Collections.singletonList("nodeID"), 0.0));
when(cncMock.getRouteMap()).thenReturn(routeMap);
when(cncMock.getTargetPositionOfRoute(ArgumentMatchers.anyString())).thenReturn(GeoPoint.latLon(30, 40));


}

@Test
Expand Down