-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): introduce new LiDAR module (#440)
* feat: Added LidarData and LidarUpdates * feat: Added new LidarUpdates interaction to ApplicationAmbassador * feat(module): Added new DefaultLidarSensorModule and interaction functionality Note: to use this, a simulator which produces LiDAR point clouds is required, such as Carla or PHABMACS
- Loading branch information
Showing
6 changed files
with
237 additions
and
6 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -62,7 +62,7 @@ buildNumber.properties | |
|
||
# MOSAIC | ||
|
||
tmp/ | ||
*.log | ||
credentials.cached | ||
*.lcs | ||
*.lcs | ||
.tiles |
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
110 changes: 110 additions & 0 deletions
110
...pse/mosaic/fed/application/ambassador/simulation/perception/DefaultLidarSensorModule.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,110 @@ | ||
/* | ||
* 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: [email protected] | ||
*/ | ||
|
||
package org.eclipse.mosaic.fed.application.ambassador.simulation.perception; | ||
|
||
import org.eclipse.mosaic.fed.application.ambassador.SimulationKernel; | ||
import org.eclipse.mosaic.fed.application.app.api.perception.LidarSensorModule; | ||
import org.eclipse.mosaic.interactions.vehicle.VehicleSensorActivation; | ||
import org.eclipse.mosaic.lib.spatial.PointCloud; | ||
import org.eclipse.mosaic.rti.api.IllegalValueException; | ||
import org.eclipse.mosaic.rti.api.InternalFederateException; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
public class DefaultLidarSensorModule implements LidarSensorModule { | ||
|
||
private boolean enabled; | ||
private final String unitId; | ||
|
||
private PointCloud currentPointcloud; | ||
private final List<Consumer<PointCloud>> callbacks = new ArrayList<>(); | ||
|
||
public DefaultLidarSensorModule(String unitId) { | ||
this.unitId = unitId; | ||
} | ||
|
||
@Override | ||
public void enable(double range) { | ||
this.enabled = true; | ||
|
||
// Create a VehicleSensorActivation interaction to be sent to the RTI | ||
VehicleSensorActivation interaction = new VehicleSensorActivation( | ||
SimulationKernel.SimulationKernel.getCurrentSimulationTime(), | ||
unitId, | ||
range, | ||
VehicleSensorActivation.SensorType.LIDAR | ||
); | ||
|
||
// Send the interaction to the RTI, thereby enabling the LiDAR sensor | ||
try { | ||
SimulationKernel.SimulationKernel.getInteractable().triggerInteraction(interaction); | ||
} catch (IllegalValueException | InternalFederateException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
@Override | ||
public void disable() { | ||
this.enabled = false; | ||
|
||
// Create a VehicleSensorActivation interaction to be sent to the RTI that disables the LiDAR sensor | ||
VehicleSensorActivation interaction = new VehicleSensorActivation( | ||
SimulationKernel.SimulationKernel.getCurrentSimulationTime(), | ||
unitId, | ||
0, | ||
VehicleSensorActivation.SensorType.LIDAR | ||
); | ||
|
||
// Send the interaction to the RTI, thereby disabling the LiDAR sensor | ||
try { | ||
SimulationKernel.SimulationKernel.getInteractable().triggerInteraction(interaction); | ||
} catch (IllegalValueException | InternalFederateException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
|
||
@Override | ||
public void reactOnSensorUpdate(Consumer<PointCloud> callback) { | ||
this.callbacks.add(callback); | ||
} | ||
|
||
@Override | ||
public PointCloud getPointCloud() { | ||
if (!enabled) { | ||
return null; | ||
} | ||
return this.currentPointcloud; | ||
} | ||
|
||
/** | ||
* This method is called by the ApplicationAmbassador when it received new LidarUpdates from the federate. | ||
* It sets the most current pointcloud to the one received and triggers the callback for every application that set one. | ||
* @param pointCloud The most current pointcloud. | ||
*/ | ||
public void updatePointCloud(PointCloud pointCloud) { | ||
this.currentPointcloud = pointCloud; | ||
for (Consumer<PointCloud> callback : callbacks) { | ||
callback.accept(pointCloud); | ||
} | ||
} | ||
} |
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
91 changes: 91 additions & 0 deletions
91
...-interactions/src/main/java/org/eclipse/mosaic/interactions/environment/LidarUpdates.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,91 @@ | ||
/* | ||
* 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: [email protected] | ||
*/ | ||
|
||
package org.eclipse.mosaic.interactions.environment; | ||
|
||
import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE; | ||
|
||
import org.eclipse.mosaic.lib.spatial.PointCloud; | ||
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.io.Serializable; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class LidarUpdates extends Interaction implements Serializable { | ||
|
||
public record LidarUpdate(String unitId, PointCloud pointCloud) implements Serializable {} | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* String identifying the type of this interaction. | ||
*/ | ||
public final static String TYPE_ID = createTypeIdentifier(LidarUpdates.class); | ||
|
||
/** | ||
* List of {@link PointCloud} containing LiDAR data from the simulator. | ||
*/ | ||
private List<LidarUpdate> updated; | ||
|
||
public LidarUpdates(long time, List<LidarUpdate> updated) { | ||
super(time); | ||
this.updated = updated; | ||
} | ||
|
||
public List<LidarUpdate> getUpdated() { | ||
return this.updated; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder(5, 17) | ||
.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.updated, other.updated) | ||
.isEquals(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this, SHORT_PREFIX_STYLE) | ||
.appendSuper(super.toString()) | ||
.append("updated", "Updated LiDAR data for vehicles [" | ||
+ this.updated.stream().map(LidarUpdate::unitId).collect(Collectors.joining(", ")) + "]") | ||
.toString(); | ||
} | ||
|
||
} | ||
|