diff --git a/Car.py b/Car.py index 0f6b7fe..9ade0fe 100644 --- a/Car.py +++ b/Car.py @@ -50,6 +50,7 @@ class Car(): self.v=0 self.a=10 self.b=20 + self.minSpace=10 self.leaderBefore=False self.distToInter=0 @@ -130,7 +131,9 @@ class Car(): edgeInd+=1 carComing = self.getLeaderAtIntersection(prevInd,edgeInd) if(carComing is not None): - self.distToInter = l + self.distToInter = l # y as un bug qqu part dans le calcul de la distance, ça saute quand on change d'edge + if self.route[edgeInd].isSpecial(): + self.distToInter += self.route[edgeInd + 1].getLength() self.leaderDist = carComing[0] self.leaderBefore = True return carComing[1] @@ -173,9 +176,8 @@ class Car(): return cDist def getLeaderAtIntersection(self, prevInd, edgeInd): - if(self.getCurrentEdge().isSpecial()): - return while(self.route[edgeInd].isSpecial()): + return edgeInd = edgeInd + 1 if edgeInd >= len(self.route): return None @@ -204,7 +206,7 @@ class Car(): laneInd = conn[i].getFromLane().getIndex() intLane = self.map.getLane(conn[i].getViaLaneID()) intLaneLgt = intLane.getLength() - carsInEdge = list(self.controller.getCarsOnLane(edge.getID(), laneInd)) # doit y avoir moyen de le faire en gardant les filters, flemme + carsInEdge = list(self.controller.getCarsOnLane(edge.getID(), laneInd)) # doit y avoir moyen de le faire en gardant les filters if len(carsInEdge) != 0: carsInEdge = zip([self.getCarDist(c, edge, laneInd)+intLaneLgt for c in carsInEdge], carsInEdge) closest = min(carsInEdge, key=lambda c: c[0]) @@ -237,8 +239,8 @@ class Car(): painter.drawText(QPointF(0,0),"vroom") self.vroom -= 1 painter.restore() - elSize = self.v * self.T - painter.drawEllipse(pt,elSize, elSize) + #elSize = self.v * self.T + #painter.drawEllipse(pt,elSize, elSize) def conduite(self,vmax,leader,dt): """if self.id == "f_00" and self.controller.t%10>5: @@ -293,11 +295,22 @@ class Car(): Va = self.v + 2.5 * self.a * dt * (1 - self.v/self.vmax) * sqrt(0.025 + self.v/self.vmax) #Vb = self.b * dt + sqrt(self.b**2 * dt**2 - self.b * ) + def calcTti(self, dist, v0, vmax, a): + ttms = (vmax - v0)/a # "time to max speed", temps pris par la voiture pour atteindre la vmax à partir de sa vitesse actuelle + delta = v0**2 + 2*a*dist # delta du trinome qui donne le temps mis pour traverser la distance dist + tti = (-v0 + sqrt(delta))/a # "time to intersection", temps mis pour arriver à l'intersection(dist), si il n'y a pas de vmax + sai = v0 + tti*a # "speed at intersection", vitesse qu'aura la voiture quand elle arrivera + if tti > ttms: # si on atteint vmax avant l'intersection alors ça foire le calcul + dbvm = a/2 * ttms**2 + v0 * ttms # "distance before vmax", distance parcouru avant d'atteindre vmax + tti = ttms + (dist - dbvm) / vmax # la temps necessaire est donc : temps pour atteindre vmax + temps pour traverser le reste à la vitesse vmax + sai = vmax + return (tti, sai) + def conduiteKrauss(self, vmax, leader, dt): - if self.id == "f_00" and self.controller.t%10>5: + """if self.id == "f_00" and self.controller.t%10>5: self.v = 0 return - + """ if leader is None: vd = min(self.v + self.a * dt, vmax) self.v = max(0, vd-self.nu) @@ -305,10 +318,30 @@ class Car(): vleader = leader.v bleader = leader.b + + # si on est à une intersection + if(self.leaderBefore): + # on calcule le temps qu'on va mettre à arriver à l'intersection + # et le temps que le leader va mettre + tti, sai = self.calcTti(self.distToInter, self.v, vmax, self.a) + ltti, lsai = self.calcTti(self.leaderDist, vleader, leader.vmax, leader.a) + + lta = leader.vmax / 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 + + # 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) + # alors on accelere pour s'inserer + if self.distToInter > self.minSpace or (tti + leader.T + marg) < ltti: + self.v = min(vmax, self.v + self.a*dt) + else:# sinon on s'arrete net + self.v = 0 + self.updateGraph(self.v, vmax, 0) + return + vb = (vleader + self.v) / 2 bb = (bleader + self.b) / 2 - #S = self.alpha * vleader**2 + self.beta * self.v**2 + self.gamma * self.v + self.delta - vsec = vleader + (self.leaderDist - vleader * self.T)/((vb/bb) + self.T) + vsec = vleader + (self.leaderDist - vleader * self.T - self.minSpace)/((vb/bb) + self.T) vd = min(self.v + self.a * dt, vsec, vmax) self.v = max(0, vd-self.nu) self.updateGraph(self.v, vmax, vsec) diff --git a/mainLoop.py b/mainLoop.py index e6b6d0a..743480f 100644 --- a/mainLoop.py +++ b/mainLoop.py @@ -86,9 +86,9 @@ class mainLoop(QObject): @threadSafe def quickLoad(self): - self.map.fromPath("test7.net.xml") + self.map.fromPath("test9.net.xml") self.painter.generateTransform() - self.controller.fromPath("test13.rou.xml") + self.controller.fromPath("test14.rou.xml") self.controller.prepareRoute() def updateFps(self): diff --git a/test14.rou.xml b/test14.rou.xml index f604cea..732781f 100644 --- a/test14.rou.xml +++ b/test14.rou.xml @@ -7,10 +7,14 @@ - + + + + + - + diff --git a/test16.rou.xml b/test16.rou.xml index dd94b1e..a70a250 100644 --- a/test16.rou.xml +++ b/test16.rou.xml @@ -4,17 +4,17 @@ --> - + - + - + - +