diff --git a/.gitignore b/.gitignore index 451483e..3b071a7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ main.build main.dist main.onefile-build profile.txt +todo.txt diff --git a/Car.py b/Car.py index 4d93845..2d68840 100644 --- a/Car.py +++ b/Car.py @@ -80,6 +80,9 @@ class Car(): def prepareRoute(self): route = list(map(self.map.getEdge,self.rawRoute)) + if None in route: + print("error planning route, mismatched net/demand?") + return for r,rn in zip(route,route[1:]): self.route.append(r) conn=r.getConnections(rn) @@ -252,6 +255,7 @@ class Car(): self.v = 0 return """ + if(leader is None): self.v = self.vmax self.updateGraph(self.v, vmax, 0) @@ -314,6 +318,10 @@ class Car(): """if self.id == "f_00" and self.controller.t%10>5: self.v = 0 return + if self.id == "v_0" and self.controller.t > 5: + self.v = 0 + self.updateGraph(self.leaderDist, self.distToInter, 0) + return """ if leader is None: vd = min(self.v + self.a * dt, vmax) @@ -327,19 +335,27 @@ class Car(): 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) + + 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) 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 + tts = self.v/self.b # time to stop, temps pour s'arreter si on freine mnt + dts = self.v*tts - (self.b*tts**2)/2 # distance to stop, distance parcouru en tts si on freine + #print(self.distToInter, self.minSpace, dts) # 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: + if self.distToInter > self.minSpace + dts or (tti + leader.T + marg) < ltti: self.v = min(vmax, self.v + self.a*dt) - else:# sinon on s'arrete net - self.v = 0#max(0, self.v - self.b*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) return @@ -353,7 +369,7 @@ class Car(): def updateGraph(self, v, vmax, vsec): if self.infoWidg is None: return - self.signals.addGraphPt.emit((2,self.controller.t,self.v)) + self.signals.addGraphPt.emit((2,self.controller.t,v)) self.signals.addGraphPt.emit((0,self.controller.t,vmax)) self.signals.addGraphPt.emit((1,self.controller.t,vsec)) diff --git a/Map.py b/Map.py index f793961..e0f5d56 100644 --- a/Map.py +++ b/Map.py @@ -41,7 +41,14 @@ class Map: @safeCall def getEdge(self,edgeID): - return self.net.getEdge(edgeID) + ret = None + try: + ret = self.net.getEdge(edgeID) + except KeyError: + print("key not found, mismatched net/demand? clearing net") + self.net = None + else: + return ret @safeCall def getNode(self,nodeID): diff --git a/mainLoop.py b/mainLoop.py index 743480f..a7d6531 100644 --- a/mainLoop.py +++ b/mainLoop.py @@ -44,7 +44,7 @@ class mainLoop(QObject): self.timer.timeout.connect(self.updateFps) self.timer.timeout.connect(self.update) self.timer.setInterval(1000/60) - self.stopSignal.connect(self.timer.stop) + #self.stopSignal.connect(self.timer.stop) def startTimer(self): self.timer.start() @@ -86,9 +86,9 @@ class mainLoop(QObject): @threadSafe def quickLoad(self): - self.map.fromPath("test9.net.xml") + self.map.fromPath("test_calc_dist.net.xml") self.painter.generateTransform() - self.controller.fromPath("test14.rou.xml") + self.controller.fromPath("test_calc_dist.rou.xml") self.controller.prepareRoute() def updateFps(self): diff --git a/test_calc_dist.net.xml b/test_calc_dist.net.xml new file mode 100644 index 0000000..3321596 --- /dev/null +++ b/test_calc_dist.net.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test_calc_dist.rou.xml b/test_calc_dist.rou.xml new file mode 100644 index 0000000..3dc65f9 --- /dev/null +++ b/test_calc_dist.rou.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + +