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 9b23b4821..4e2436454 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 @@ -739,7 +739,7 @@ private synchronized void receiveInteraction(VehicleLaneChange vehicleLaneChange log.warn("VehicleLaneChange failed: unsupported lane change mode."); return; } - bridge.getVehicleControl().changeLane(vehicleLaneChange.getVehicleId(), targetLaneId, vehicleLaneChange.getDuration()); + bridge.getVehicleControl().changeLane(vehicleLaneChange.getVehicleId(), Math.max(0, targetLaneId), vehicleLaneChange.getDuration()); if (sumoConfig.highlights.contains(CSumo.HIGHLIGHT_CHANGE_LANE)) { VehicleData vehicleData = bridge.getSimulationControl().getLastKnownVehicleData(vehicleLaneChange.getVehicleId()); diff --git a/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/bridge/api/complex/SumoLaneChangeMode.java b/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/bridge/api/complex/SumoLaneChangeMode.java index 5332bdc31..748ea7b32 100644 --- a/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/bridge/api/complex/SumoLaneChangeMode.java +++ b/fed/mosaic-sumo/src/main/java/org/eclipse/mosaic/fed/sumo/bridge/api/complex/SumoLaneChangeMode.java @@ -38,11 +38,15 @@ public static SumoLaneChangeMode translateFromEnum(final LaneChangeMode laneChan switch (laneChangeMode) { case OFF: mode.setSublaneChanges(false, false); - mode.setStrategicChanges(true, true); mode.setRespectOtherDrivers(RESPECT_SPEED_GAPS_OF_OTHER_DRIVERS_ADAPT_SPEED); break; // For strategic lane changes (change lanes to continue the route), // we always let SUMO overwrite requested lane changes (overrideTraci = true) + case FOLLOW_ROUTE: + mode.setSublaneChanges(false, false); + mode.setStrategicChanges(true, true); + mode.setRespectOtherDrivers(RESPECT_SPEED_GAPS_OF_OTHER_DRIVERS_ADAPT_SPEED); + break; case AGGRESSIVE: mode.setStrategicChanges(true, true); mode.setSpeedChanges(true, false); @@ -51,16 +55,10 @@ public static SumoLaneChangeMode translateFromEnum(final LaneChangeMode laneChan mode.setStrategicChanges(true, true); mode.setCooperativeChanges(true, false); mode.setSpeedChanges(true, false); - mode.setRightDriveChanges(true, true); + mode.setRightDriveChanges(true, false); mode.setRespectOtherDrivers(RESPECT_SPEED_GAPS_OF_OTHER_DRIVERS_DO_NOT_ADAPT_SPEED); break; case PASSIVE: - mode.setStrategicChanges(true, true); - mode.setCooperativeChanges(true, false); - mode.setSpeedChanges(true, false); - mode.setRightDriveChanges(true, true); - mode.setRespectOtherDrivers(RESPECT_SPEED_GAPS_OF_OTHER_DRIVERS_ADAPT_SPEED); - break; case COOPERATIVE: case DEFAULT: mode.setStrategicChanges(true, true); diff --git a/fed/mosaic-sumo/src/test/java/org/eclipse/mosaic/fed/sumo/bridge/api/complex/SumoLaneChangeModeTest.java b/fed/mosaic-sumo/src/test/java/org/eclipse/mosaic/fed/sumo/bridge/api/complex/SumoLaneChangeModeTest.java index dd35d872a..ae3330d45 100644 --- a/fed/mosaic-sumo/src/test/java/org/eclipse/mosaic/fed/sumo/bridge/api/complex/SumoLaneChangeModeTest.java +++ b/fed/mosaic-sumo/src/test/java/org/eclipse/mosaic/fed/sumo/bridge/api/complex/SumoLaneChangeModeTest.java @@ -91,11 +91,12 @@ public void testGetAsInteger_overrideTraci() { @Test public void testTranslateFromEnum() { assertEquals(1622, SumoLaneChangeMode.translateFromEnum(LaneChangeMode.DEFAULT).getAsInteger()); - assertEquals(514, SumoLaneChangeMode.translateFromEnum(LaneChangeMode.OFF).getAsInteger()); + assertEquals(512, SumoLaneChangeMode.translateFromEnum(LaneChangeMode.OFF).getAsInteger()); + assertEquals(514, SumoLaneChangeMode.translateFromEnum(LaneChangeMode.FOLLOW_ROUTE).getAsInteger()); assertEquals(1042, SumoLaneChangeMode.translateFromEnum(LaneChangeMode.AGGRESSIVE).getAsInteger()); assertEquals(1622, SumoLaneChangeMode.translateFromEnum(LaneChangeMode.COOPERATIVE).getAsInteger()); - assertEquals(1942, SumoLaneChangeMode.translateFromEnum(LaneChangeMode.CAUTIOUS).getAsInteger()); - assertEquals(1686, SumoLaneChangeMode.translateFromEnum(LaneChangeMode.PASSIVE).getAsInteger()); + assertEquals(1878, SumoLaneChangeMode.translateFromEnum(LaneChangeMode.CAUTIOUS).getAsInteger()); + assertEquals(1622, SumoLaneChangeMode.translateFromEnum(LaneChangeMode.PASSIVE).getAsInteger()); } } diff --git a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/enums/LaneChangeMode.java b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/enums/LaneChangeMode.java index 55fee2905..4bcd465fd 100644 --- a/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/enums/LaneChangeMode.java +++ b/lib/mosaic-objects/src/main/java/org/eclipse/mosaic/lib/enums/LaneChangeMode.java @@ -17,9 +17,10 @@ public enum LaneChangeMode { DEFAULT, // == COOPERATIVE - OFF, // no lane changes except strategic (514 in SUMO) - CAUTIOUS, //strategic, cooperative, speed changes, keep right, no speed adaption when changing lanes (917 in SUMO) - COOPERATIVE, //strategic, cooperative, speed changes, keep right, avoid collisions (597 in SUMO) - AGGRESSIVE, //strategic, no cooperative, speed changes, stay left, do not respect other drivers (17 in SUMO) - PASSIVE //strategic, no cooperative, speed changes, stay right, do not respect other drivers (661 in SUMO) + OFF, // no lane changes at all, only by explicit calls of changeLane + FOLLOW_ROUTE, // no lane changes except strategic + CAUTIOUS, //strategic, cooperative, speed changes, keep right, no speed adaption when changing lanes + COOPERATIVE, //strategic, cooperative, speed changes, keep right, avoid collisions + AGGRESSIVE, //strategic, no cooperative, speed changes, stay left, do not respect other drivers + PASSIVE //strategic, no cooperative, speed changes, stay right, do not respect other drivers } \ No newline at end of file diff --git a/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/RingBuffer.java b/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/RingBuffer.java index 9fc6078a4..35d0a06de 100644 --- a/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/RingBuffer.java +++ b/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/RingBuffer.java @@ -103,6 +103,7 @@ public T next() { } public void clear() { + Arrays.fill(elements, null); ringMode = false; head = 0; } diff --git a/rti/mosaic-rti-core/src/main/java/org/eclipse/mosaic/rti/time/RealtimeSynchronisation.java b/rti/mosaic-rti-core/src/main/java/org/eclipse/mosaic/rti/time/RealtimeSynchronisation.java index eb89c99bf..0837e5c9f 100644 --- a/rti/mosaic-rti-core/src/main/java/org/eclipse/mosaic/rti/time/RealtimeSynchronisation.java +++ b/rti/mosaic-rti-core/src/main/java/org/eclipse/mosaic/rti/time/RealtimeSynchronisation.java @@ -52,13 +52,14 @@ public RealtimeSynchronisation(double realtimeFactor) { public void sync(long timestamp) { if (realtimeFactor > 0d && realNanoTimeLastSync > 0) { - long realTimeSinceLastSync = System.nanoTime() - realNanoTimeLastSync; + // Consider real time difference of 1s at maximum, to prevent "catching up" behavior when pausing a simulator on purpose + long realTimeSinceLastSync = Math.min(TIME.SECOND, System.nanoTime() - realNanoTimeLastSync); long simTimeSinceLastSync = timestamp - simNanoTimeLastSync; // Conversion from simulation to wanted realtime according to the given realtime factor long realTimeSinceLastSyncWanted = (long) (simTimeSinceLastSync * (1 / realtimeFactor)); - // The real nano seconds we now have to wait to fulfill the requirement above + // The real nanoseconds we now have to wait to fulfill the requirement above long nanoTimeToWait = realTimeSinceLastSyncWanted - realTimeSinceLastSync + waitOffset; // The actual waiting