call entity_ident traffic_lights_geo

This commit is contained in:
Marco Zeisler 2021-06-02 23:06:13 +02:00
parent 291e2ef78a
commit 564c7e9f3d
2 changed files with 34 additions and 14 deletions

View File

@ -23,17 +23,6 @@ def api2():
if __name__ == '__main__': if __name__ == '__main__':
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/' orc = Orchestrator()
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
orc = Orchestrator(cars, traffic_lights)
threading.Thread(target=orc.setup_msg_queues).start() threading.Thread(target=orc.setup_msg_queues).start()
threading.Thread(target=app.run, args=('0.0.0.0', 5003)).start() threading.Thread(target=app.run, args=('0.0.0.0', 5003)).start()

View File

@ -4,11 +4,14 @@ import sys
from random import randrange from random import randrange
from typing import List, Dict from typing import List, Dict
import requests
from dse_shared_libs import daf, traffic_light_state, traffic_light_color, target_velocity from dse_shared_libs import daf, traffic_light_state, traffic_light_color, target_velocity
from dse_shared_libs.daf import DAF
from dse_shared_libs.message_broker_wrapper import MBWrapper from dse_shared_libs.message_broker_wrapper import MBWrapper
# necessary to unpickle daf object # necessary to unpickle daf object
from dse_shared_libs.target_velocity import TargetVelocity from dse_shared_libs.target_velocity import TargetVelocity
from dse_shared_libs.traffic_light_state import TrafficLightState from dse_shared_libs.traffic_light_state import TrafficLightState
from requests import Session
sys.modules['daf'] = daf sys.modules['daf'] = daf
sys.modules['traffic_light_state'] = traffic_light_state sys.modules['traffic_light_state'] = traffic_light_state
@ -16,6 +19,9 @@ sys.modules['traffic_light_color'] = traffic_light_color
sys.modules['target_velocity'] = target_velocity sys.modules['target_velocity'] = target_velocity
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
class Orchestrator: class Orchestrator:
# vehicle ids # vehicle ids
vins: List[str] = [] vins: List[str] = []
@ -26,7 +32,22 @@ class Orchestrator:
_daf_mbs: Dict[str, MBWrapper] = {} _daf_mbs: Dict[str, MBWrapper] = {}
_velocity_mbs: Dict[str, MBWrapper] = {} _velocity_mbs: Dict[str, MBWrapper] = {}
def __init__(self, cars, traffic_lights): _session: Session
def __init__(self):
# re-use http session, is faster then request.ing everytime
self._session = requests.Session()
try:
response = self._session.get(ENTITY_IDENT_URL + 'cars')
cars = response.json()
response = self._session.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
for car in cars['cursor']: for car in cars['cursor']:
self.vins.append(car['vin']) self.vins.append(car['vin'])
@ -59,10 +80,20 @@ class Orchestrator:
:param pickle_binary: daf object pickle binary dump :param pickle_binary: daf object pickle binary dump
""" """
received_daf_object = pickle.loads(pickle_binary) received_daf_object: DAF = pickle.loads(pickle_binary)
loc = received_daf_object.gps_location
print(received_daf_object) print(received_daf_object)
# TODO ask entity ident if tl in range?! # TODO ask entity ident if tl in range?!
response = self._session.get(ENTITY_IDENT_URL + 'traffic_lights_geo',
params={'lat': loc.latitude, 'lon': loc.longitude})
traffic_lights_geo = response.json()
print('TLGeo', traffic_lights_geo)
# TODO in the best case we get a traffic light ID and some sort of visibility range here?
# we need to calculate new speed regarding current speed and position and visibility of TL to ensure a
# green wave
# keep NCE in mind!?
# TODO use the data from the traffic lights (self.tls) # TODO use the data from the traffic lights (self.tls)
# to transmit a new target velocity for this vehicle to achieve a green wave # to transmit a new target velocity for this vehicle to achieve a green wave