inter check intEdge
This commit is contained in:
parent
00be5580a1
commit
3370a466a9
35
Car.py
35
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
|
||||
|
13
comp_rdp_t1.rou.xml
Normal file
13
comp_rdp_t1.rou.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- generated on 2022-05-13 14:31:11 by Eclipse SUMO netedit Version 1.12.0
|
||||
-->
|
||||
|
||||
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd">
|
||||
<vehicle id="v_0" depart="0.00">
|
||||
<route edges="E1 E10 E9 -E20 -E7"/>
|
||||
</vehicle>
|
||||
<vehicle id="v_1" depart="4.50">
|
||||
<route edges="E8 E4 E11 E10 E9 -E20 -E7"/>
|
||||
</vehicle>
|
||||
</routes>
|
5
main.py
5
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
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user