From 2f65aee90d4b8746a0201cec049e44ddf6f26d83 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 14 May 2022 20:38:29 +0200 Subject: [PATCH] opti forceThrough --- Car.py | 31 +++++++++++++++++++++---------- main.py | 4 ++++ mainLoop.py | 3 ++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Car.py b/Car.py index 0939bf3..45904f1 100644 --- a/Car.py +++ b/Car.py @@ -433,8 +433,14 @@ class Car(): #print(self.distToInter, self.minSpace, dts) # Si on est bloqué dans une dépendance circulaire - if self.timeAtInter >= 1 and self.leader is None and self.circularLeaderDep(self.leaderAtInter, 20): - self.forceThrough = True + if self.leader is None and self.timeAtInter >= 0: + cd, maxInterTime = self.circularLeaderDep(self.leaderAtInter, 0, 20) + if cd and self.timeAtInter >= maxInterTime: + print(maxInterTime) + self.forceThrough = True + # Ou si notre leader est bloqué devant un autre leader + #if self.leader is None and self.leaderAtInter.v == 0 and self.leaderAtInter.leaderAtInter is not None and self.leaderAtInter.leaderAtInterDist > 20: + # self.forceThrough = True # si on est suffisement loin de l'intersection (i.e on s'en fout du leader) # ou si on as le temps d'arriver à l'intersection avant le leader (plus un marge pour garder un distance de sécu) @@ -447,7 +453,6 @@ class Car(): vsecInter = max(0, self.v - self.b*dt) if self.forceThrough: - self.leaderAtInter = None # On supprime le leader (pour que seulement la premiere voiture detecte la dependance circulaire) vsecInter = min(vmax, self.v + self.a*dt) vsec = vmax @@ -464,21 +469,27 @@ class Car(): self.updateGraph(self.v, vmax, vsec, vsecInter) # fonction pour verifier si on as pas une dependence circulaire de leader - def circularLeaderDep(self, car, timeout): + def circularLeaderDep(self, car, maxTimeStopped, timeout): if timeout <= 0: - return False + return False, 0 if car is None: - return False + return False, 0 + + if car.forceThrough: + return False, 0 + + maxTimeStopped = max(maxTimeStopped, car.timeAtInter) if car.id == self.id: - return True + return True, maxTimeStopped timeout -= 1 - res = self.circularLeaderDep(car.leader, timeout) - res |= self.circularLeaderDep(car.leaderAtInter, timeout) + res,mts = self.circularLeaderDep(car.leader, maxTimeStopped, timeout) + res2,mts2 = self.circularLeaderDep(car.leaderAtInter, maxTimeStopped, timeout) + maxTimeStopped = max(mts, mts2) - return res + return (res or res2), maxTimeStopped def updateGraph(self, v, vmax, vsec, interVsec): if self.infoWidg is None: diff --git a/main.py b/main.py index cba0b1d..201501c 100644 --- a/main.py +++ b/main.py @@ -76,6 +76,10 @@ class MainWindow(QMainWindow): self.setPhTimerInterval.emit(17) elif e.key() == Qt.Key_F: self.setPhTimerInterval.emit(500) + elif e.key() == Qt.Key_C: + self.mainLoop.controller.dt = 0.3 + elif e.key() == Qt.Key_P: + self.mainLoop.controller.dt = 1/60 else: self.mainLoop.quickLoad(e.key()) diff --git a/mainLoop.py b/mainLoop.py index 235bda7..58b58b8 100644 --- a/mainLoop.py +++ b/mainLoop.py @@ -16,7 +16,8 @@ class mainLoop(QObject): Qt.Key_2 : ["comp_rdp.net.xml", "comp_rdp.rou.xml"], Qt.Key_3 : ["comp_rdp.net.xml", "comp_rdp_t3.rou.xml"], Qt.Key_4 : ["rdpt_polytech_fixed.net.xml", "rdpt_polytech_burst.rou.xml"], - Qt.Key_5 : ["rdpt_polytech_fixed.net.xml", "rdpt_polytech_burst_2.rou.xml"] + Qt.Key_5 : ["rdpt_polytech_fixed.net.xml", "rdpt_polytech_burst_2.rou.xml"], + Qt.Key_6 : ["rdpt_polytech_fixed.net.xml", "rdpt_polytech_burst_2_IA.rou.xml"] } def __init__(self, parent):