Skip to content

Commit

Permalink
feat(sumo): LaneChangeMode.OFF should do no lane changes at all (#383)
Browse files Browse the repository at this point in the history
* feat(sumo): new lane change mode "FOLLOW_ROUTE"
* fix(utils): remove elements of RingBuffer when calling clear()
* fix(rti): fixed realTimeSynchronization when pausing
  • Loading branch information
kschrab authored Mar 22, 2024
1 parent b68eac3 commit e58293c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public T next() {
}

public void clear() {
Arrays.fill(elements, null);
ringMode = false;
head = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e58293c

Please sign in to comment.