From 8d35be632b17215a653c65641dfbe8d2c0d24b9b Mon Sep 17 00:00:00 2001 From: Finn Schneider Date: Tue, 21 May 2024 10:11:51 +0200 Subject: [PATCH 1/9] wip(mosaic): Started decoupling the sending of lidar data and vehicle updates --- .../ambassador/ApplicationAmbassador.java | 3 + .../environment/LidarUpdates.java | 107 ++++++++++++++++++ .../lib/objects/vehicle/sensor/LidarData.java | 88 ++++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java create mode 100644 lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java index c431b037a..43a62fd43 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java @@ -36,6 +36,7 @@ import org.eclipse.mosaic.interactions.electricity.VehicleBatteryUpdates; import org.eclipse.mosaic.interactions.electricity.VehicleChargingDenial; import org.eclipse.mosaic.interactions.environment.EnvironmentSensorUpdates; +import org.eclipse.mosaic.interactions.environment.LidarUpdates; import org.eclipse.mosaic.interactions.mapping.ChargingStationRegistration; import org.eclipse.mosaic.interactions.mapping.RsuRegistration; import org.eclipse.mosaic.interactions.mapping.ServerRegistration; @@ -306,6 +307,8 @@ protected void processInteraction(final Interaction interaction) throws Internal this.process((VehicleTypesInitialization) interaction); } else if (interaction.getTypeId().startsWith(ApplicationInteraction.TYPE_ID)) { this.process((ApplicationInteraction) interaction); + } else if (interaction.getTypeId().startsWith(LidarUpdates.TYPE_ID)) { + log.info("LIDAR UPDATES RECEIVED!!!!!!"); } else { log.warn("Unknown interaction received with time {} : {}", TIME.format(interaction.getTime()), interaction.getTypeId()); } diff --git a/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java b/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java new file mode 100644 index 000000000..f53e8bfd9 --- /dev/null +++ b/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2024 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.interactions.environment; + +import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE; + +import org.eclipse.mosaic.lib.objects.UnitData; +import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; +import org.eclipse.mosaic.lib.objects.vehicle.sensor.LidarData; +import org.eclipse.mosaic.rti.api.Interaction; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import java.util.List; +import java.util.stream.Collectors; + +public class LidarUpdates extends Interaction { + //TODO what is this? + private static final long serialVersionUID = 1L; + + /** + * String identifying the type of this interaction. + */ + public final static String TYPE_ID = createTypeIdentifier(LidarUpdates.class); + + /** + * Time at which the next sensor update will be sent. + */ + private long nextUpdate; + + + /** + * List of {@link VehicleData} identifying vehicles with updated positions. + */ + private final List updated; + + + + public LidarUpdates(long time, List updated) { + super(time); + this.updated = updated; + } + + public List getUpdated() { + return this.updated; + } + + public long getNextUpdate() { + return this.nextUpdate; + } + + public void setNextUpdate(long nextUpdate) { + this.nextUpdate = nextUpdate; + } + + @Override + public int hashCode() { + return new HashCodeBuilder(5, 17) + .append(nextUpdate) + .append(updated) + .toHashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj == this) { + return true; + } + if (obj.getClass() != getClass()) { + return false; + } + + LidarUpdates other = (LidarUpdates) obj; + return new EqualsBuilder() + .append(this.nextUpdate, other.nextUpdate) + .append(this.updated, other.updated) + .isEquals(); + } + + @Override + public String toString() { + return new ToStringBuilder(this, SHORT_PREFIX_STYLE) + .appendSuper(super.toString()) + .append("updated", updated.stream().map(UnitData::getName).collect(Collectors.joining(","))) + .toString(); + } + +} + diff --git a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java new file mode 100644 index 000000000..d8c867a87 --- /dev/null +++ b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 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.lib.objects.vehicle.sensor; + +import org.eclipse.mosaic.lib.geo.GeoPoint; +import org.eclipse.mosaic.lib.objects.UnitData; +import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; +import org.eclipse.mosaic.lib.util.gson.PolymorphismTypeAdapterFactory; + +import com.google.gson.annotations.JsonAdapter; + +public class LidarData extends UnitData { + + @JsonAdapter(PolymorphismTypeAdapterFactory.class) + private final Object lidarData; + /** + * Creates a new {@link UnitData}. + * + * @param time time of the last update + * @param name name of the unit + * @param position position of the unit + */ + public LidarData(long time, String name, GeoPoint position, Object additionalData) { + super(time, name, position); + this.lidarData = additionalData; + } + + /** + * Returns additional vehicle data produced by the traffic or vehicle simulator. + * Can be of any arbitrary type, and is null if the producer has not been + * implemented in a way to add this additional data. + */ + public Object getLidarData() { + return lidarData; + } + + /** + * A builder for creating {@link VehicleData} objects without using the monstrous constructor. + */ + public static class Builder { + private final long time; + private final String name; + private GeoPoint geoPos; + private Object lidarData; + + /** + * Init the builder with the current simulation time [ns] and name of the vehicle. + */ + public Builder(long time, String name) { + this.time = time; + this.name = name; + } + + public LidarData.Builder geoPos(GeoPoint geoPos) { + this.geoPos = geoPos; + return this; + } + + /** + * Set position related values for the vehicle info. + */ + public LidarData.Builder lidarData(Object lidarData) { + this.lidarData = lidarData; + return this; + } + + /** + * Returns the final {@link LidarData} based on the properties given before. + */ + public LidarData create() { + return new LidarData( + time, name, geoPos,lidarData); + } + } +} From 9f11484580bcf71154b54d518a734544b5fc67fd Mon Sep 17 00:00:00 2001 From: Finn Schneider Date: Tue, 21 May 2024 15:08:50 +0200 Subject: [PATCH 2/9] wip(mosaic): Transfer data from ApplicationAmbassador to apps --- .../ambassador/ApplicationAmbassador.java | 16 +++++++++++++++- .../ambassador/simulation/VehicleUnit.java | 11 +++++++++++ .../application/app/api/VehicleApplication.java | 4 ++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java index 43a62fd43..440729d59 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java @@ -62,6 +62,7 @@ import org.eclipse.mosaic.lib.objects.vehicle.BatteryData; import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; import org.eclipse.mosaic.lib.objects.vehicle.VehicleDeparture; +import org.eclipse.mosaic.lib.objects.vehicle.sensor.LidarData; import org.eclipse.mosaic.lib.util.FileUtils; import org.eclipse.mosaic.lib.util.objects.ObjectInstantiation; import org.eclipse.mosaic.lib.util.scheduling.DefaultEventScheduler; @@ -308,7 +309,7 @@ protected void processInteraction(final Interaction interaction) throws Internal } else if (interaction.getTypeId().startsWith(ApplicationInteraction.TYPE_ID)) { this.process((ApplicationInteraction) interaction); } else if (interaction.getTypeId().startsWith(LidarUpdates.TYPE_ID)) { - log.info("LIDAR UPDATES RECEIVED!!!!!!"); + this.process((LidarUpdates) interaction); } else { log.warn("Unknown interaction received with time {} : {}", TIME.format(interaction.getTime()), interaction.getTypeId()); } @@ -695,6 +696,19 @@ private void process(final VehicleUpdates vehicleUpdates) { addEvent(triggerGarbageCollection); } + private void process(final LidarUpdates lidarUpdates) { + for (LidarData data :lidarUpdates.getUpdated()) { + final AbstractSimulationUnit simulationUnit = UnitSimulator.UnitSimulator.getUnitFromId(data.getName()); + final Event event = new Event( + data.getTime(), + simulationUnit, + data, + EventNicenessPriorityRegister.VEHICLE_ADDED + ); + addEvent(event); + } + } + private void addVehicleIfNotYetAdded(long time, String unitName) { final VehicleRegistration vehicleRegistration = vehicleRegistrations.remove(unitName); if (vehicleRegistration != null) { 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 71ce0fa5d..2419950e1 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 @@ -45,6 +45,7 @@ import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; import org.eclipse.mosaic.lib.objects.vehicle.VehicleRoute; import org.eclipse.mosaic.lib.objects.vehicle.VehicleType; +import org.eclipse.mosaic.lib.objects.vehicle.sensor.LidarData; import org.eclipse.mosaic.lib.routing.database.DatabaseRouting; import org.eclipse.mosaic.lib.util.scheduling.Event; @@ -123,6 +124,12 @@ private void updateVehicleInfo(final VehicleData currentVehicleData) { } } + private void updateLidarInfo(final LidarData currentLidarData) { + for (VehicleApplication application : getApplicationsIterator(VehicleApplication.class)) { + application.onLidarUpdated(currentLidarData); + } + } + @Override public void processEvent(@Nonnull final Event event) throws Exception { // never remove the preProcessEvent call! @@ -155,6 +162,10 @@ protected boolean handleEventResource(Object resource, long eventType) { if (resource instanceof BatteryData) { throw new RuntimeException(ErrorRegister.VEHICLE_NotElectric.toString()); } + if (resource instanceof LidarData) { + updateLidarInfo((LidarData) resource); + return true; + } return false; } diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/VehicleApplication.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/VehicleApplication.java index cc2cd1771..94a9c539a 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/VehicleApplication.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/VehicleApplication.java @@ -16,6 +16,7 @@ package org.eclipse.mosaic.fed.application.app.api; import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; +import org.eclipse.mosaic.lib.objects.vehicle.sensor.LidarData; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -33,4 +34,7 @@ public interface VehicleApplication extends Application { * @param updatedVehicleData the updated state of the vehicle */ void onVehicleUpdated(@Nullable VehicleData previousVehicleData, @Nonnull VehicleData updatedVehicleData); + //TODO create new method onLidarUpdated here, that every application has to implement?? + + void onLidarUpdated(@Nonnull LidarData updatedLidarData); } From f5b77c41732837f56de76685e81e2f18a9e77af5 Mon Sep 17 00:00:00 2001 From: Finn Schneider Date: Tue, 21 May 2024 16:08:23 +0200 Subject: [PATCH 3/9] wip(mosaic): New Interface for Lidar Updates --- .../ambassador/simulation/VehicleUnit.java | 3 ++- .../application/app/api/LidarApplication.java | 24 +++++++++++++++++++ .../app/api/VehicleApplication.java | 4 ---- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/LidarApplication.java 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 2419950e1..ab0875192 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 @@ -24,6 +24,7 @@ import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.NopPerceptionModule; import org.eclipse.mosaic.fed.application.ambassador.simulation.perception.SimplePerceptionConfiguration; import org.eclipse.mosaic.fed.application.app.api.CommunicationApplication; +import org.eclipse.mosaic.fed.application.app.api.LidarApplication; import org.eclipse.mosaic.fed.application.app.api.VehicleApplication; import org.eclipse.mosaic.fed.application.app.api.os.VehicleOperatingSystem; import org.eclipse.mosaic.fed.application.app.api.perception.PerceptionModule; @@ -125,7 +126,7 @@ private void updateVehicleInfo(final VehicleData currentVehicleData) { } private void updateLidarInfo(final LidarData currentLidarData) { - for (VehicleApplication application : getApplicationsIterator(VehicleApplication.class)) { + for (LidarApplication application : getApplicationsIterator(LidarApplication.class)) { application.onLidarUpdated(currentLidarData); } } diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/LidarApplication.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/LidarApplication.java new file mode 100644 index 000000000..411822fca --- /dev/null +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/LidarApplication.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024 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.app.api; + +import org.eclipse.mosaic.lib.objects.vehicle.sensor.LidarData; + +import javax.annotation.Nonnull; + +public interface LidarApplication extends VehicleApplication { + void onLidarUpdated(@Nonnull LidarData updatedLidarData); +} diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/VehicleApplication.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/VehicleApplication.java index 94a9c539a..cc2cd1771 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/VehicleApplication.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/VehicleApplication.java @@ -16,7 +16,6 @@ package org.eclipse.mosaic.fed.application.app.api; import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; -import org.eclipse.mosaic.lib.objects.vehicle.sensor.LidarData; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -34,7 +33,4 @@ public interface VehicleApplication extends Application { * @param updatedVehicleData the updated state of the vehicle */ void onVehicleUpdated(@Nullable VehicleData previousVehicleData, @Nonnull VehicleData updatedVehicleData); - //TODO create new method onLidarUpdated here, that every application has to implement?? - - void onLidarUpdated(@Nonnull LidarData updatedLidarData); } From 57386f60362f739ccbe7aa0a27dc1ca31388a341 Mon Sep 17 00:00:00 2001 From: Finn Schneider Date: Wed, 22 May 2024 14:53:31 +0200 Subject: [PATCH 4/9] wip(mosaic): Refactoring --- .../ambassador/ApplicationAmbassador.java | 6 +-- .../util/EventNicenessPriorityRegister.java | 1 + .../application/app/api/LidarApplication.java | 2 +- .../lib/objects/vehicle/sensor/LidarData.java | 43 ++++++++++--------- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java index 440729d59..4d65b9942 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/ApplicationAmbassador.java @@ -300,6 +300,8 @@ protected void processInteraction(final Interaction interaction) throws Internal this.process((TrafficLightUpdates) interaction); } else if (interaction.getTypeId().startsWith(VehicleUpdates.TYPE_ID)) { this.process((VehicleUpdates) interaction); + } else if (interaction.getTypeId().startsWith(LidarUpdates.TYPE_ID)) { + this.process((LidarUpdates) interaction); } else if (interaction.getTypeId().startsWith(VehicleBatteryUpdates.TYPE_ID)) { this.process((VehicleBatteryUpdates) interaction); } else if (interaction.getTypeId().startsWith(VehicleRoutesInitialization.TYPE_ID)) { @@ -308,8 +310,6 @@ protected void processInteraction(final Interaction interaction) throws Internal this.process((VehicleTypesInitialization) interaction); } else if (interaction.getTypeId().startsWith(ApplicationInteraction.TYPE_ID)) { this.process((ApplicationInteraction) interaction); - } else if (interaction.getTypeId().startsWith(LidarUpdates.TYPE_ID)) { - this.process((LidarUpdates) interaction); } else { log.warn("Unknown interaction received with time {} : {}", TIME.format(interaction.getTime()), interaction.getTypeId()); } @@ -703,7 +703,7 @@ private void process(final LidarUpdates lidarUpdates) { data.getTime(), simulationUnit, data, - EventNicenessPriorityRegister.VEHICLE_ADDED + EventNicenessPriorityRegister.LIDAR_UPDATED ); addEvent(event); } diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/util/EventNicenessPriorityRegister.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/util/EventNicenessPriorityRegister.java index fccefab17..e0d8e8f8c 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/util/EventNicenessPriorityRegister.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/ambassador/util/EventNicenessPriorityRegister.java @@ -24,6 +24,7 @@ public class EventNicenessPriorityRegister { public final static long VEHICLE_ADDED = -99_999_900; public final static long VEHICLE_UPDATED = -99_999_800; public final static long VEHICLE_REMOVED = -99_999_700; + public final static long LIDAR_UPDATED = -99_999_650; // update traffic detectors public final static long UPDATE_TRAFFIC_DETECTORS = -99_999_600; diff --git a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/LidarApplication.java b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/LidarApplication.java index 411822fca..c42978de0 100644 --- a/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/LidarApplication.java +++ b/fed/mosaic-application/src/main/java/org/eclipse/mosaic/fed/application/app/api/LidarApplication.java @@ -19,6 +19,6 @@ import javax.annotation.Nonnull; -public interface LidarApplication extends VehicleApplication { +public interface LidarApplication extends Application { void onLidarUpdated(@Nonnull LidarData updatedLidarData); } diff --git a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java index d8c867a87..01e15027b 100644 --- a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java +++ b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java @@ -15,27 +15,27 @@ package org.eclipse.mosaic.lib.objects.vehicle.sensor; -import org.eclipse.mosaic.lib.geo.GeoPoint; -import org.eclipse.mosaic.lib.objects.UnitData; -import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; import org.eclipse.mosaic.lib.util.gson.PolymorphismTypeAdapterFactory; import com.google.gson.annotations.JsonAdapter; -public class LidarData extends UnitData { - +public class LidarData { @JsonAdapter(PolymorphismTypeAdapterFactory.class) private final Object lidarData; + + private final long time; + private final String name; /** - * Creates a new {@link UnitData}. + * Creates a new {@link LidarData}. * - * @param time time of the last update - * @param name name of the unit - * @param position position of the unit + * @param time time of the last update + * @param name name of the unit + * @param lidarData Object that contains the LidarFrame data */ - public LidarData(long time, String name, GeoPoint position, Object additionalData) { - super(time, name, position); - this.lidarData = additionalData; + public LidarData(long time, String name, Object lidarData) { + this.lidarData = lidarData; + this.time = time; + this.name = name; } /** @@ -47,13 +47,21 @@ public Object getLidarData() { return lidarData; } + public long getTime() { + return time; + } + + public String getName() { + return name; + } + + /** - * A builder for creating {@link VehicleData} objects without using the monstrous constructor. + * A builder for creating {@link LidarData} objects */ public static class Builder { private final long time; private final String name; - private GeoPoint geoPos; private Object lidarData; /** @@ -64,11 +72,6 @@ public Builder(long time, String name) { this.name = name; } - public LidarData.Builder geoPos(GeoPoint geoPos) { - this.geoPos = geoPos; - return this; - } - /** * Set position related values for the vehicle info. */ @@ -82,7 +85,7 @@ public LidarData.Builder lidarData(Object lidarData) { */ public LidarData create() { return new LidarData( - time, name, geoPos,lidarData); + time, name,lidarData); } } } From d361a5d27c4688d6299674d4065f80c01dff7d83 Mon Sep 17 00:00:00 2001 From: Finn Schneider Date: Thu, 23 May 2024 11:58:20 +0200 Subject: [PATCH 5/9] fix(mosaic): Use correct object type --- .../mosaic/interactions/environment/LidarUpdates.java | 3 +-- .../mosaic/lib/objects/vehicle/sensor/LidarData.java | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java b/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java index f53e8bfd9..07a296f36 100644 --- a/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java +++ b/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java @@ -17,7 +17,6 @@ import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE; -import org.eclipse.mosaic.lib.objects.UnitData; import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; import org.eclipse.mosaic.lib.objects.vehicle.sensor.LidarData; import org.eclipse.mosaic.rti.api.Interaction; @@ -99,7 +98,7 @@ public boolean equals(Object obj) { public String toString() { return new ToStringBuilder(this, SHORT_PREFIX_STYLE) .appendSuper(super.toString()) - .append("updated", updated.stream().map(UnitData::getName).collect(Collectors.joining(","))) + .append("updated", updated.stream().map(LidarData::getName).collect(Collectors.joining(","))) .toString(); } diff --git a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java index 01e15027b..7fd440f57 100644 --- a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java +++ b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java @@ -44,15 +44,15 @@ public LidarData(long time, String name, Object lidarData) { * implemented in a way to add this additional data. */ public Object getLidarData() { - return lidarData; + return this.lidarData; } public long getTime() { - return time; + return this.time; } public String getName() { - return name; + return this.name; } From 60d7ccc0e94e3e3a7134dad429e61ce945dce669 Mon Sep 17 00:00:00 2001 From: Finn Schneider Date: Fri, 24 May 2024 12:34:07 +0200 Subject: [PATCH 6/9] fix(mosaic): Made LidarData serializable --- .../eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java index 7fd440f57..fcccffe2e 100644 --- a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java +++ b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java @@ -19,7 +19,9 @@ import com.google.gson.annotations.JsonAdapter; -public class LidarData { +import java.io.Serializable; + +public class LidarData implements Serializable { @JsonAdapter(PolymorphismTypeAdapterFactory.class) private final Object lidarData; From b8632348514b47ed63d3ca1f0f4431603deb6d0b Mon Sep 17 00:00:00 2001 From: Finn Schneider Date: Wed, 29 May 2024 12:56:57 +0200 Subject: [PATCH 7/9] clean(interaction): added comments --- .../mosaic/interactions/environment/LidarUpdates.java | 8 +------- .../mosaic/lib/objects/vehicle/sensor/LidarData.java | 5 ++--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java b/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java index 07a296f36..d71923160 100644 --- a/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java +++ b/lib/mosaic-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.java @@ -17,7 +17,6 @@ import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE; -import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; import org.eclipse.mosaic.lib.objects.vehicle.sensor.LidarData; import org.eclipse.mosaic.rti.api.Interaction; @@ -29,7 +28,6 @@ import java.util.stream.Collectors; public class LidarUpdates extends Interaction { - //TODO what is this? private static final long serialVersionUID = 1L; /** @@ -44,7 +42,7 @@ public class LidarUpdates extends Interaction { /** - * List of {@link VehicleData} identifying vehicles with updated positions. + * List of {@link LidarData} containing LiDAR data from the simulator. */ private final List updated; @@ -59,10 +57,6 @@ public List getUpdated() { return this.updated; } - public long getNextUpdate() { - return this.nextUpdate; - } - public void setNextUpdate(long nextUpdate) { this.nextUpdate = nextUpdate; } diff --git a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java index fcccffe2e..61060eff6 100644 --- a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java +++ b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java @@ -41,9 +41,8 @@ public LidarData(long time, String name, Object lidarData) { } /** - * Returns additional vehicle data produced by the traffic or vehicle simulator. - * Can be of any arbitrary type, and is null if the producer has not been - * implemented in a way to add this additional data. + * Returns lidar data produced by the traffic or vehicle simulator. + * Should be of type LidarFrame. */ public Object getLidarData() { return this.lidarData; From 66c4b2035377c2276f2d2a0665fa02ffa82c88e0 Mon Sep 17 00:00:00 2001 From: Finn Schneider Date: Wed, 19 Jun 2024 14:39:44 +0200 Subject: [PATCH 8/9] fix(workshop): Enabled color changing of externally added vehicles in SUMO --- .../fed/sumo/ambassador/AbstractSumoAmbassador.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/ambassador/AbstractSumoAmbassador.java b/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/ambassador/AbstractSumoAmbassador.java index 4e2436454..e46299f6d 100644 --- a/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/ambassador/AbstractSumoAmbassador.java +++ b/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/ambassador/AbstractSumoAmbassador.java @@ -1045,6 +1045,7 @@ private void receiveInteraction(VehicleSensorActivation vehicleSensorActivation) */ private void receiveInteraction(VehicleParametersChange vehicleParametersChange) throws InternalFederateException { if (externalVehicles.containsKey(vehicleParametersChange.getVehicleId())) { + changeExternalParameters(vehicleParametersChange); return; } @@ -1286,6 +1287,18 @@ private void removeExternalVehiclesFromUpdates(VehicleUpdates updates) { updates.getRemovedNames().removeIf(vehicle -> externalVehicles.remove(vehicle) != null); } + public void changeExternalParameters(VehicleParametersChange vehicleParametersChange) throws InternalFederateException { + final String veh_id = vehicleParametersChange.getVehicleId(); + for (final VehicleParameter param : vehicleParametersChange.getVehicleParameters()) { + if (param.getParameterType() == VehicleParameter.VehicleParameterType.COLOR) { + final Color color = param.getValue(); + bridge.getVehicleControl().setColor(veh_id, color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); + } else { + log.warn("Parameter type {} is not supported for external vehicles", param.getParameterType().name()); + } + } + } + /** * This handles the case that sumo handles routing and creates new routes while doing so. * From b6a1ee7f19f8951e8cad40ebfc7c966bedd3eb0f Mon Sep 17 00:00:00 2001 From: Finn Schneider Date: Mon, 2 Sep 2024 11:31:13 +0200 Subject: [PATCH 9/9] feat: Hack for using PointClouds instead of LidarFrames. Changes on phabmacs may be nice --- .../mosaic/lib/objects/vehicle/sensor/LidarData.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java index 61060eff6..eab37cc27 100644 --- a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java +++ b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/objects/vehicle/sensor/LidarData.java @@ -15,6 +15,7 @@ package org.eclipse.mosaic.lib.objects.vehicle.sensor; +import org.eclipse.mosaic.lib.spatial.PointCloud; import org.eclipse.mosaic.lib.util.gson.PolymorphismTypeAdapterFactory; import com.google.gson.annotations.JsonAdapter; @@ -23,7 +24,7 @@ public class LidarData implements Serializable { @JsonAdapter(PolymorphismTypeAdapterFactory.class) - private final Object lidarData; + private final PointCloud lidarData; private final long time; private final String name; @@ -34,7 +35,7 @@ public class LidarData implements Serializable { * @param name name of the unit * @param lidarData Object that contains the LidarFrame data */ - public LidarData(long time, String name, Object lidarData) { + public LidarData(long time, String name, PointCloud lidarData) { this.lidarData = lidarData; this.time = time; this.name = name; @@ -63,7 +64,7 @@ public String getName() { public static class Builder { private final long time; private final String name; - private Object lidarData; + private PointCloud lidarData; /** * Init the builder with the current simulation time [ns] and name of the vehicle. @@ -76,7 +77,7 @@ public Builder(long time, String name) { /** * Set position related values for the vehicle info. */ - public LidarData.Builder lidarData(Object lidarData) { + public LidarData.Builder lidarData(PointCloud lidarData) { this.lidarData = lidarData; return this; } @@ -86,7 +87,7 @@ public LidarData.Builder lidarData(Object lidarData) { */ public LidarData create() { return new LidarData( - time, name,lidarData); + time, name, lidarData); } } }