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(interaction): Added LidarUpdates interaction and LidarData object #391

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -61,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;
Expand Down Expand Up @@ -298,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)) {
Expand Down Expand Up @@ -692,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.LIDAR_UPDATED
);
addEvent(event);
}
}

private void addVehicleIfNotYetAdded(long time, String unitName) {
final VehicleRegistration vehicleRegistration = vehicleRegistrations.remove(unitName);
if (vehicleRegistration != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +46,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;

Expand Down Expand Up @@ -123,6 +125,12 @@ private void updateVehicleInfo(final VehicleData currentVehicleData) {
}
}

private void updateLidarInfo(final LidarData currentLidarData) {
for (LidarApplication application : getApplicationsIterator(LidarApplication.class)) {
application.onLidarUpdated(currentLidarData);
}
}

@Override
public void processEvent(@Nonnull final Event event) throws Exception {
// never remove the preProcessEvent call!
Expand Down Expand Up @@ -155,6 +163,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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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: [email protected]
*/

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 Application {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class needs to be documented before being merged.

void onLidarUpdated(@Nonnull LidarData updatedLidarData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ private void receiveInteraction(VehicleSensorActivation vehicleSensorActivation)
*/
private void receiveInteraction(VehicleParametersChange vehicleParametersChange) throws InternalFederateException {
if (externalVehicles.containsKey(vehicleParametersChange.getVehicleId())) {
changeExternalParameters(vehicleParametersChange);
return;
}

Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class needs some more documentation before being merged

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 LidarData} containing LiDAR data from the simulator.
*/
private final List<LidarData> updated;



public LidarUpdates(long time, List<LidarData> updated) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it isn't clear what exactly the list of updated LidarData is made-up of.

  • Is it lidar data for all ego-vehicles at time?
  • Is it lidar data for one ego-vehicle at time?

This kind of stuff should be documented.

As far as I get, each ego-vehicle has a LidarData-Object for each lidar-collection-time, which contains the measured point clouds, right?

super(time);
this.updated = updated;
}

public List<LidarData> getUpdated() {
return this.updated;
}

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(LidarData::getName).collect(Collectors.joining(",")))
.toString();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.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;

import java.io.Serializable;

public class LidarData implements Serializable {
@JsonAdapter(PolymorphismTypeAdapterFactory.class)
private final PointCloud lidarData;

private final long time;
private final String name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document the fields and maybe rename name to vehicleId or something that better describes it.

/**
* Creates a new {@link LidarData}.
*
* @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, PointCloud lidarData) {
this.lidarData = lidarData;
this.time = time;
this.name = name;
}

/**
* Returns lidar data produced by the traffic or vehicle simulator.
* Should be of type LidarFrame.
*/
public Object getLidarData() {
return this.lidarData;
}

public long getTime() {
return this.time;
}

public String getName() {
return this.name;
}


/**
* A builder for creating {@link LidarData} objects
*/
public static class Builder {
private final long time;
private final String name;
private PointCloud 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;
}

/**
* Set position related values for the vehicle info.
*/
public LidarData.Builder lidarData(PointCloud 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, lidarData);
}
}
}
Loading