44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import sys
|
|
import time
|
|
|
|
import requests
|
|
from dse_shared_libs import daf, traffic_light_state, traffic_light_color, target_velocity
|
|
|
|
from devices.traffic_light import TrafficLight
|
|
from devices.vehicle import Vehicle
|
|
|
|
sys.modules['daf'] = daf
|
|
sys.modules['traffic_light_state'] = traffic_light_state
|
|
sys.modules['traffic_light_color'] = traffic_light_color
|
|
sys.modules['target_velocity'] = target_velocity
|
|
|
|
"""
|
|
USED AS ENTRYPOINT FOR DOCKERFILE
|
|
Start all vehicles / traffic lights here
|
|
"""
|
|
|
|
if __name__ == '__main__':
|
|
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
|
|
try:
|
|
response = requests.get(ENTITY_IDENT_URL + 'cars')
|
|
cars = response.json()
|
|
|
|
response = requests.get(ENTITY_IDENT_URL + 'traffic_lights')
|
|
traffic_lights = response.json()
|
|
except requests.exceptions.ConnectionError as e:
|
|
print("Is the entity_ident_server running and reachable?")
|
|
raise e
|
|
|
|
print('Traffic lights', traffic_lights['cursor'])
|
|
for traffic_light in traffic_lights['cursor']:
|
|
print(traffic_light)
|
|
TrafficLight(tlid=traffic_light['id'],
|
|
switching_time=traffic_light['switchingTime']).start()
|
|
time.sleep(1)
|
|
|
|
print('Cars', cars['cursor'])
|
|
for car in cars['cursor']:
|
|
print(car)
|
|
Vehicle(vin=car['vin']).start_driving()
|
|
time.sleep(0.5)
|