Skip to content

Commit

Permalink
feat: change VMS state via OS methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hoelger committed Jan 9, 2025
1 parent ece5f06 commit 4ac3808
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.eclipse.mosaic.interactions.traffic.LaneAreaDetectorSubscription;
import org.eclipse.mosaic.interactions.traffic.LanePropertyChange;
import org.eclipse.mosaic.interactions.traffic.TrafficDetectorUpdates;
import org.eclipse.mosaic.interactions.trafficsigns.TrafficSignLaneAssignmentChange;
import org.eclipse.mosaic.interactions.trafficsigns.TrafficSignSpeedLimitChange;
import org.eclipse.mosaic.lib.enums.VehicleClass;
import org.eclipse.mosaic.lib.objects.mapping.TmcMapping;
import org.eclipse.mosaic.lib.objects.traffic.InductionLoopInfo;
Expand Down Expand Up @@ -112,6 +114,11 @@ public ChangeLaneState changeLaneState(String edge, int laneIndex) {
return new ChangeLaneStateImpl(edge, laneIndex, this);
}

@Override
public ChangeLaneState changeVmsLaneState(String signId, int laneIndex) {
return new ChangeVmsLaneStateImpl(signId, laneIndex, this);
}

@Override
public void processEvent(Event event) throws Exception {
// never remove the preProcessEvent call!
Expand Down Expand Up @@ -234,4 +241,83 @@ private void sendMessageQuietly(Interaction interaction) {
}
}
}

private static class ChangeVmsLaneStateImpl implements ChangeLaneState {

private final AbstractSimulationUnit unit;

private final String signId;
private final int laneIndex;

private ChangeVmsLaneStateImpl(String signId, int laneIndex, AbstractSimulationUnit unit) {
this.signId = signId;
this.laneIndex = laneIndex;
this.unit = unit;
}

@Override
public ChangeLaneState openOnlyForVehicleClasses(VehicleClass... allowVehicleClasses) {
if (laneIndex < 0) {
throw new IllegalArgumentException("With negative lane index you can only use speed assignments, then addressing all lanes.");
}
sendMessageQuietly(new TrafficSignLaneAssignmentChange(
unit.getSimulationTime(),
signId,
laneIndex,
Lists.newArrayList(allowVehicleClasses)
)
);
return this;
}

@Override
public ChangeLaneState closeOnlyForVehicleClasses(VehicleClass... disallowVehicleClasses) {
ArrayList<VehicleClass> remaining = Lists.newArrayList(VehicleClass.values());
for (VehicleClass removeme : disallowVehicleClasses) {
remaining.remove(removeme);
}
return openOnlyForVehicleClasses(remaining.toArray(new VehicleClass[remaining.size()]));
}

@Override
public ChangeLaneState closeForAll() {
return closeOnlyForVehicleClasses(VehicleClass.values());
}

@Override
public ChangeLaneState openForAll() {
return openOnlyForVehicleClasses(VehicleClass.values());
}

@Override
public ChangeLaneState setMaxSpeed(double maxSpeedMs) {
if (laneIndex < 0) {
sendMessageQuietly(
new TrafficSignSpeedLimitChange(
unit.getSimulationTime(),
signId,
maxSpeedMs
)
);
} else {
sendMessageQuietly(
new TrafficSignSpeedLimitChange(
unit.getSimulationTime(),
signId,
laneIndex,
maxSpeedMs
)
);
}
return this;
}

private void sendMessageQuietly(Interaction interaction) {
try {
unit.sendInteractionToRti(interaction);
} catch (RuntimeException e) {
unit.getOsLog().error("Could not send interaction", e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public interface TrafficManagementCenterOperatingSystem extends ServerOperatingS
*/
ChangeLaneState changeLaneState(String edge, int laneIndex);

/**
* Provides a facility to change the lane state of a Variable Message Sign (VMS).
*
* @param signId The ID of the sign.
* @param laneIndex The index of the lane (0 = right-most lane).
*/
ChangeLaneState changeVmsLaneState(String signId, int laneIndex);

interface ChangeLaneState {

/**
Expand Down

0 comments on commit 4ac3808

Please sign in to comment.