File TestResultsSimulator.txt changed (mode: 100644) (index bd0fc12..27de9bb) |
1 |
|
Voetgangers extra out of the blue. als ze op een vluchtheuvel moeten w8en. |
|
|
1 |
|
Voetgangers extra out of the blue. als ze op een vluchtheuvel moeten w8en.. Maybe DONE? |
2 |
2 |
Alle voetgangers freezen als eentje staat te w8en. |
Alle voetgangers freezen als eentje staat te w8en. |
3 |
3 |
201 nog implemtenteren.. DONE! |
201 nog implemtenteren.. DONE! |
4 |
|
treinen nog implementeren |
|
5 |
|
De simulator queue'd zelf. |
|
|
4 |
|
treinen nog implementeren.. Maybe DONE? |
|
5 |
|
De simulator queue'd zelf.. Is dat zo? |
6 |
6 |
Als alles klaar is, stuur ie nul ipv count - 1.. DONE! |
Als alles klaar is, stuur ie nul ipv count - 1.. DONE! |
File simulatie/connection.py changed (mode: 100644) (index 94ff54b..fc6cd90) |
... |
... |
RecieveConnection = pika.BlockingConnection(pika.ConnectionParameters(host=model |
49 |
49 |
channel = SendConnection.channel() |
channel = SendConnection.channel() |
50 |
50 |
recieve = RecieveConnection.channel() |
recieve = RecieveConnection.channel() |
51 |
51 |
|
|
|
52 |
|
inputEnabled = True |
|
53 |
|
|
52 |
54 |
recieve.queue_declare( |
recieve.queue_declare( |
53 |
55 |
queue=model.recieveQueue, |
queue=model.recieveQueue, |
54 |
56 |
arguments={'x-message-ttl' : 10000}, |
arguments={'x-message-ttl' : 10000}, |
|
... |
... |
def sendMsg(msg, index, amount): |
73 |
75 |
time.sleep(2) |
time.sleep(2) |
74 |
76 |
|
|
75 |
77 |
def update(index, addCars, dirRequests): |
def update(index, addCars, dirRequests): |
76 |
|
lights[index][1] += addCars |
|
77 |
|
lights[index][2] = dirRequests |
|
78 |
|
waitingVehicles = None |
|
79 |
|
vehicleMutation = 0 |
|
80 |
|
|
|
81 |
|
if addCars < 0: |
|
82 |
|
vehicleMutation *= -1 |
|
83 |
|
|
|
84 |
|
for i in range(0, vehicleMutation): |
|
85 |
|
if addCars > 0: |
|
86 |
|
lights[index][2].append(dirRequests[i]) |
|
87 |
|
else: |
|
88 |
|
lights[index][2].pop() |
|
89 |
|
|
|
90 |
|
if len(lights[index][2]) > 0: |
|
91 |
|
waitingVehicles = lights[index][2] |
|
92 |
|
|
|
93 |
|
msg = json.dumps({ |
|
94 |
|
"TrafficUpdate": { |
|
95 |
|
"LightId": lights[index][0], |
|
96 |
|
"Count": lights[index][1], |
|
97 |
|
"DirectionRequests": waitingVehicles |
|
98 |
|
} |
|
99 |
|
}, sort_keys=True, indent=4, separators=(',',': ')) |
|
100 |
|
|
|
101 |
|
sendMsg(msg, index, amountOfCars) # Geeft deze functie de bug bij een transform? |
|
|
78 |
|
if inputEnabled: |
|
79 |
|
lights[index][1] += addCars |
|
80 |
|
lights[index][2] = dirRequests |
|
81 |
|
waitingVehicles = None |
|
82 |
|
vehicleMutation = 0 |
|
83 |
|
|
|
84 |
|
if addCars < 0: |
|
85 |
|
vehicleMutation *= -1 |
|
86 |
|
|
|
87 |
|
for i in range(0, vehicleMutation): |
|
88 |
|
if addCars > 0: |
|
89 |
|
lights[index][2].append(dirRequests[i]) |
|
90 |
|
else: |
|
91 |
|
lights[index][2].pop() |
|
92 |
|
|
|
93 |
|
if len(lights[index][2]) > 0: |
|
94 |
|
waitingVehicles = lights[index][2] |
|
95 |
|
|
|
96 |
|
msg = json.dumps({ |
|
97 |
|
"TrafficUpdate": { |
|
98 |
|
"LightId": lights[index][0], |
|
99 |
|
"Count": lights[index][1], |
|
100 |
|
"DirectionRequests": waitingVehicles |
|
101 |
|
} |
|
102 |
|
}, sort_keys=True, indent=4, separators=(',',': ')) |
|
103 |
|
|
|
104 |
|
sendMsg(msg, index, amountOfCars) # Geeft deze functie de bug bij een transform? |
|
105 |
|
|
|
106 |
|
else: |
|
107 |
|
print("INPUT IS DISABLED!") |
102 |
108 |
|
|
103 |
109 |
def listen(): |
def listen(): |
104 |
110 |
print('Waiting for a sign..') |
print('Waiting for a sign..') |
File simulatie/pyg.py changed (mode: 100644) (index 93ca924..1ff7bbf) |
1 |
1 |
#!/bin/env python |
#!/bin/env python |
2 |
2 |
|
|
3 |
3 |
import sys, pygame |
import sys, pygame |
4 |
|
import thread |
|
|
4 |
|
import threading |
5 |
5 |
import time |
import time |
6 |
6 |
import json |
import json |
7 |
7 |
|
|
8 |
8 |
import trafficModel as tm |
import trafficModel as tm |
9 |
|
#import connection |
|
|
9 |
|
import connection |
10 |
10 |
|
|
11 |
11 |
vehicles = list() |
vehicles = list() |
12 |
12 |
lights = list() |
lights = list() |
|
... |
... |
class Vehicle(object): |
120 |
120 |
self.wp += 1 |
self.wp += 1 |
121 |
121 |
print("W: " + str(self.wp) + " / " + str(len(tm.queues[self.trafficId]))) |
print("W: " + str(self.wp) + " / " + str(len(tm.queues[self.trafficId]))) |
122 |
122 |
|
|
123 |
|
elif self.waiting: # Debug |
|
124 |
|
time.sleep(1) |
|
125 |
|
tm.lights[self.trafficId]["Status"] = 1 # Debug |
|
|
123 |
|
#elif self.waiting: # Debug |
|
124 |
|
#time.sleep(1) |
|
125 |
|
# tm.lights[self.trafficId]["Status"] = 1 # Debug |
126 |
126 |
|
|
127 |
127 |
elif not self.waiting and self.wp < len(tm.waypoints[self.trafficId][self.direction]): |
elif not self.waiting and self.wp < len(tm.waypoints[self.trafficId][self.direction]): |
128 |
128 |
self.goto(tm.waypoints[self.trafficId][self.direction][self.wp][0], tm.waypoints[self.trafficId][self.direction][self.wp][1]) |
self.goto(tm.waypoints[self.trafficId][self.direction][self.wp][0], tm.waypoints[self.trafficId][self.direction][self.wp][1]) |
|
... |
... |
class Vehicle(object): |
136 |
136 |
self.waiting = True |
self.waiting = True |
137 |
137 |
|
|
138 |
138 |
self.transform = self.checkForTransform() |
self.transform = self.checkForTransform() |
139 |
|
# connection.update(self.trafficId, 1, self.direction) |
|
|
139 |
|
connection.update(self.trafficId, 1, self.direction) |
140 |
140 |
else: |
else: |
141 |
141 |
pass # Destructor here? |
pass # Destructor here? |
142 |
142 |
|
|
|
... |
... |
class Vehicle(object): |
144 |
144 |
|
|
145 |
145 |
def trafficCheck(self): |
def trafficCheck(self): |
146 |
146 |
if tm.lights[self.trafficId]["Status"] != 0 and self.waiting and self.wp <= len(tm.queues[self.trafficId]): |
if tm.lights[self.trafficId]["Status"] != 0 and self.waiting and self.wp <= len(tm.queues[self.trafficId]): |
|
147 |
|
# If trafficlight 601 is red and vehicle also needs to wait for 601... |
|
148 |
|
if tm.lights[len(tm.lights) - 1]["Status"] == 0 and self.trafficId == 102 or 106 <= self.trafficId <= 108: |
|
149 |
|
return |
147 |
150 |
self.waiting = False |
self.waiting = False |
148 |
151 |
self.wp = 0 |
self.wp = 0 |
149 |
|
#connection.update(self.trafficId, -1, self.direction) |
|
|
152 |
|
connection.update(self.trafficId, -1, self.direction) |
150 |
153 |
self.update() |
self.update() |
151 |
154 |
|
|
152 |
155 |
clock = pygame.time.Clock() |
clock = pygame.time.Clock() |
|
... |
... |
def spawnTrein(naarGroningen): |
163 |
166 |
else: |
else: |
164 |
167 |
train = Vehicle(tm.queues[28][0][0], tm.queues[28][0][1],28)#9) |
train = Vehicle(tm.queues[28][0][0], tm.queues[28][0][1],28)#9) |
165 |
168 |
|
|
166 |
|
def slagbomenDalen(): |
|
167 |
|
print("Lichten knipperen & bellen luiden") |
|
168 |
|
time.sleep(5) |
|
169 |
|
print("Slagbomen dalen..") |
|
170 |
|
time.sleep(12) |
|
171 |
|
print("Slagbomen zijn dicht.") |
|
172 |
|
|
|
173 |
|
def slagbomenOpenen(): |
|
174 |
|
print("Slagbomen gaan open..") |
|
175 |
|
time.sleep(12) |
|
176 |
|
print("Slagbomen zijn open.") |
|
177 |
|
|
|
178 |
|
def spawnVehicle(index): |
|
179 |
|
vehicles.append(Vehicle(tm.queues[index][0][0], tm.queues[index][0][1], index)) |
|
|
169 |
|
def spawnVehicle(index, dirRequest): |
|
170 |
|
vehicles.append(Vehicle(tm.queues[index][0][0], tm.queues[index][0][1], index, dirRequest)) |
180 |
171 |
|
|
181 |
172 |
# Mainloop |
# Mainloop |
182 |
173 |
def gameloop(): |
def gameloop(): |
183 |
|
id = 5 |
|
184 |
|
car = Vehicle(tm.queues[id][0][0],tm.queues[id][0][1],id,4) |
|
|
174 |
|
#id = 12 |
|
175 |
|
#car = Vehicle(tm.queues[id][0][0],tm.queues[id][0][1],id,None) |
185 |
176 |
|
|
186 |
|
for i in range(0, len(tm.lights)): |
|
187 |
|
lights.append(Light(i)) |
|
|
177 |
|
#for i in range(0, len(tm.lights)): |
|
178 |
|
# lights.append(Light(i)) |
188 |
179 |
|
|
189 |
180 |
while True: |
while True: |
190 |
181 |
clock.tick(60) |
clock.tick(60) |
|
... |
... |
def gameloop(): |
197 |
188 |
vehicle.trafficCheck() |
vehicle.trafficCheck() |
198 |
189 |
#for light in lights: |
#for light in lights: |
199 |
190 |
# light.lightCheck() |
# light.lightCheck() |
200 |
|
car.trafficCheck() |
|
|
191 |
|
#car.trafficCheck() |
201 |
192 |
pygame.display.flip() |
pygame.display.flip() |
202 |
193 |
|
|
203 |
|
gameloop() |
|
|
194 |
|
# All below is debug stuff |
|
195 |
|
#gameloop() |