From 3370a466a9b3fb2097a7de6acda1c7894066067d Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 13 May 2022 15:20:55 +0200 Subject: [PATCH] inter check intEdge --- Car.py | 35 +++++++++++++++++++++++++++-------- comp_rdp_t1.rou.xml | 13 +++++++++++++ main.py | 5 +++++ mainLoop.py | 4 ++-- 4 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 comp_rdp_t1.rou.xml diff --git a/Car.py b/Car.py index e073140..defa6c6 100644 --- a/Car.py +++ b/Car.py @@ -260,17 +260,32 @@ class Car(): carsInEdge = zip([self.getCarDist(c, intEdge, intLane.getIndex()) for c in carsInEdge], carsInEdge) closest = min(carsInEdge, key=lambda c: c[0]) cars.append(closest) + + # On cherche aussi dans les edges du node precedent et les edge d'avant + prevLanesLgt = intLaneLgt + conn[i].getFromLane().getLength() + prevNode = edge.getFromNode() + for intLaneID in prevNode.getInternal(): + intLane = self.map.getLane(intLaneID) + intEdge = intLane.getEdge() + carsInEdge = self.controller.getCarsOnLane(intEdge.getID(), intLane.getIndex()) + carsInEdge = list(filter(lambda c: c.nextNonSpecialEdge() == edge and c.nextNonSpecialEdge(3) == conn[i].getTo(), carsInEdge)) + if len(carsInEdge) != 0: + carsInEdge = zip([self.getCarDist(c, intEdge, intLane.getIndex())+prevLanesLgt for c in carsInEdge], carsInEdge) + closest = min(carsInEdge, key=lambda c: c[0]) + cars.append(closest) + if(len(cars) == 0): return None + cDist,closest = min(cars, key=lambda c: c[0]) return (cDist,closest) def turnNext(self): return self.cligno[self.index] != self.CLIGNO_NONE - def nextNonSpecialEdge(self): - return next(filter(lambda e: not e.isSpecial(), islice(self.route, self.index + 1, None))) + def nextNonSpecialEdge(self, startOffset = 1): + return next(filter(lambda e: not e.isSpecial(), islice(self.route, self.index + startOffset, None))) def draw(self,painter): pt = QPointF(*self.pos) @@ -389,7 +404,7 @@ class Car(): vd = min(self.v + self.a * dt, vmax) self.v = max(0, vd-self.nu) return - + vleader = leader.v bleader = leader.b @@ -403,13 +418,17 @@ class Car(): # on calcule le temps qu'on va mettre à arriver à l'intersection # et le temps que le leader va mettre + lvmax = leader.vmax + if leader.getCurrentEdge().isSpecial(): + lvmax = leader.nextNonSpecialEdge().getSpeed() + nextInternalIndex = self.index # Pour la voiture actuelle, dans l'ideal on calculerait la durée selon la vitesse sur chaque troncon while not self.route[nextInternalIndex].isSpecial(): # Mais pour l'instant on prend juste la vitesse sur le troncon interne (le plus lent en general) nextInternalIndex += 1 tti, sai = self.calcTti(self.distToInter, self.v, self.route[nextInternalIndex].getLane(0).getSpeed(), self.a) # TODO : laneID - ltti, lsai = self.calcTti(self.leaderDist, vleader, leader.vmax, leader.a) + ltti, lsai = self.calcTti(self.leaderDist, vleader, lvmax, leader.a) - lta = (leader.vmax-vleader) / leader.a # temps ou le leader accelere (i.e on ne gagne pas de vitesse relative) (on considere que leader.a==self.a) + lta = (lvmax-vleader) / leader.a # temps ou le leader accelere (i.e on ne gagne pas de vitesse relative) (on considere que leader.a==self.a) marg = lta + (lsai-sai) / self.a # marge à prendre pour accelerer après l'intersection sans que le leader nous rattrape tts = self.v/self.b # time to stop, temps pour s'arreter si on freine mnt @@ -431,12 +450,12 @@ class Car(): # ou si on as le temps d'arriver à l'intersection avant le leader (plus un marge pour garder un distance de sécu) # alors on accelere pour s'inserer #print(tti, leader.T, marg, ltti) - if self.distToInter > self.interMinSpace + dts or (not self.IA and self.distToInter < 5) or (tti + leader.T + marg) < ltti: + if self.distToInter > self.interMinSpace + dts or (tti + leader.T + marg) < ltti: self.v = min(vmax, self.v + self.a*dt) #print(self.id, "ca passe") else:# sinon on freine self.v = max(0, self.v - self.b*dt) - self.updateGraph(self.v, vmax, 0) + self.updateGraph(self.v, vmax, self.leaderDist) return vb = (vleader + self.v) / 2 @@ -454,7 +473,7 @@ class Car(): while l is not None and timeout > 0: ls.append(l.id) if l.id == self.id: - print(ls) + #print(ls) return True timeout -= 1 l = l.leader diff --git a/comp_rdp_t1.rou.xml b/comp_rdp_t1.rou.xml new file mode 100644 index 0000000..38df867 --- /dev/null +++ b/comp_rdp_t1.rou.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/main.py b/main.py index e6e769b..9f33ffc 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,7 @@ from mainLoop import mainLoop class MainWindow(QMainWindow): stopMainLoopTimer = Signal() + startMainLoop = Signal() def __init__(self): super().__init__() self.ui = Ui_MainWindow() @@ -49,6 +50,8 @@ class MainWindow(QMainWindow): self.ui.startButton.clicked.connect(self.mainLoop.startTimer) self.ui.stopButton.clicked.connect(self.mainLoop.stopTimer) + self.startMainLoop.connect(self.mainLoop.startTimer) + self.stopMainLoopTimer.connect(self.mainLoop.stopTimer) self.ui.mainFPS_set.valueChanged.connect(self.drawTimer.setInterval) @@ -65,6 +68,8 @@ class MainWindow(QMainWindow): self.mainLoop.controller.vroomEnable = not self.mainLoop.controller.vroomEnable elif e.key() == Qt.Key_S: self.mainLoop.quickLoad() + elif e.key() == Qt.Key_G: + self.startMainLoop.emit() def updateFPS(self): self.fpsAverage += 1 diff --git a/mainLoop.py b/mainLoop.py index 108fd3a..164abaf 100644 --- a/mainLoop.py +++ b/mainLoop.py @@ -88,9 +88,9 @@ class mainLoop(QObject): @threadSafe def quickLoad(self): - self.map.fromPath("comp_inter.net.xml") + self.map.fromPath("comp_rdp.net.xml") self.painter.generateTransform() - self.controller.fromPath("comp_inter.rou.xml") + self.controller.fromPath("comp_rdp_t1.rou.xml") self.controller.prepareRoute() def updateFps(self):