fix + nv problemes

This commit is contained in:
leo 2022-04-23 00:08:15 +02:00
parent afe65943aa
commit 76b89967ac
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
6 changed files with 121 additions and 9 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ main.build
main.dist
main.onefile-build
profile.txt
todo.txt

26
Car.py
View File

@ -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))

9
Map.py
View File

@ -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):

View File

@ -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):

75
test_calc_dist.net.xml Normal file
View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated on 2022-04-22 16:50:23 by Eclipse SUMO netedit Version 1.12.0
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd">
<output>
<output-file value="/home/leo/Sketchbook/python/Traffic/test_calc_dist.net.xml"/>
</output>
<processing>
<offset.disable-normalization value="true"/>
</processing>
<junctions>
<no-turnarounds value="true"/>
</junctions>
<netedit>
<route-files value="/home/leo/Sketchbook/python/Traffic/test_calc_dist.rou.xml"/>
</netedit>
<report>
<aggregate-warnings value="5"/>
</report>
</configuration>
-->
<net version="1.9" junctionCornerDetail="5" limitTurnSpeed="5.50" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/net_file.xsd">
<location netOffset="0.00,0.00" convBoundary="-37.63,15.86,168.37,80.47" origBoundary="10000000000.00,10000000000.00,-10000000000.00,-10000000000.00" projParameter="!"/>
<edge id=":J1_0" function="internal">
<lane id=":J1_0_0" index="0" speed="6.39" length="5.55" shape="96.23,48.62 96.15,47.41 96.48,46.21 97.23,45.01 98.41,43.81"/>
</edge>
<edge id=":J1_1" function="internal">
<lane id=":J1_1_0" index="0" speed="8.98" length="6.18" shape="92.62,45.20 94.47,45.25 95.79,45.23 96.97,44.85 98.41,43.81"/>
</edge>
<edge id=":J2_0" function="internal">
<lane id=":J2_0_0" index="0" speed="4.29" length="1.18" shape="132.11,14.65 132.37,14.43 132.59,14.31 132.83,14.27 133.18,14.26"/>
</edge>
<edge id="E0" from="J0" to="J1" priority="-1">
<lane id="E0_0" index="0" speed="13.89" length="130.26" shape="-37.63,45.93 92.62,45.20"/>
</edge>
<edge id="E1" from="J1" to="J2" priority="-1">
<lane id="E1_0" index="0" speed="13.89" length="44.56" shape="98.41,43.81 132.11,14.65"/>
</edge>
<edge id="E2" from="J2" to="J3" priority="-1">
<lane id="E2_0" index="0" speed="13.89" length="35.22" shape="133.18,14.26 168.39,14.77"/>
</edge>
<edge id="E3" from="J4" to="J1" priority="1">
<lane id="E3_0" index="0" speed="13.89" length="33.22" shape="104.23,80.86 96.23,48.62"/>
</edge>
<junction id="J0" type="dead_end" x="-37.63" y="47.53" incLanes="" intLanes="" shape="-37.63,47.53 -37.64,44.33"/>
<junction id="J1" type="priority" x="97.43" y="46.77" incLanes="E3_0 E0_0" intLanes=":J1_0_0 :J1_1_0" shape="94.68,49.00 97.79,48.23 97.81,47.23 98.02,46.70 98.37,46.16 98.84,45.60 99.45,45.02 97.36,42.60 95.85,43.56 95.21,43.69 94.52,43.69 93.68,43.63 92.62,43.60 92.63,46.80 93.53,47.04 93.90,47.35 94.21,47.77 94.47,48.33">
<request index="0" response="00" foes="10" cont="0"/>
<request index="1" response="01" foes="01" cont="0"/>
</junction>
<junction id="J2" type="priority" x="133.15" y="15.86" incLanes="E1_0" intLanes=":J2_0_0" shape="133.15,15.86 133.20,12.66 132.33,12.69 132.02,12.77 131.74,12.90 131.44,13.12 131.06,13.44">
<request index="0" response="0" foes="0" cont="0"/>
</junction>
<junction id="J3" type="dead_end" x="168.37" y="16.37" incLanes="E2_0" intLanes="" shape="168.42,13.17 168.37,16.37"/>
<junction id="J4" type="dead_end" x="105.79" y="80.47" incLanes="" intLanes="" shape="105.79,80.47 102.68,81.24"/>
<connection from="E0" to="E1" fromLane="0" toLane="0" via=":J1_1_0" dir="s" state="m"/>
<connection from="E1" to="E2" fromLane="0" toLane="0" via=":J2_0_0" dir="s" state="M"/>
<connection from="E3" to="E1" fromLane="0" toLane="0" via=":J1_0_0" dir="l" state="M"/>
<connection from=":J1_0" to="E1" fromLane="0" toLane="0" dir="l" state="M"/>
<connection from=":J1_1" to="E1" fromLane="0" toLane="0" dir="s" state="M"/>
<connection from=":J2_0" to="E2" fromLane="0" toLane="0" dir="s" state="M"/>
</net>

13
test_calc_dist.rou.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated on 2022-04-22 16:43:43 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="E0 E1 E2"/>
</vehicle>
<vehicle id="v_1" depart="5.00">
<route edges="E3 E1 E2"/>
</vehicle>
</routes>