Implement correct scaling
This commit is contained in:
parent
5c492460b9
commit
81a41226a0
@ -3,21 +3,21 @@
|
|||||||
"id": "1",
|
"id": "1",
|
||||||
"location": [16.20719, 47.89584],
|
"location": [16.20719, 47.89584],
|
||||||
"range": 2000,
|
"range": 2000,
|
||||||
"switchingTime": 5,
|
"switchingTime": 26,
|
||||||
"color": "RED"
|
"color": "RED"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "2",
|
"id": "2",
|
||||||
"location": [16.20814, 47.90937],
|
"location": [16.20814, 47.90937],
|
||||||
"range": 800,
|
"range": 800,
|
||||||
"switchingTime": 15,
|
"switchingTime": 16,
|
||||||
"color": "GREEN"
|
"color": "GREEN"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "3",
|
"id": "3",
|
||||||
"location": [16.20917, 47.92703],
|
"location": [16.20917, 47.92703],
|
||||||
"range": 1000,
|
"range": 1000,
|
||||||
"switchingTime": 10,
|
"switchingTime": 20,
|
||||||
"color": "RED"
|
"color": "RED"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -13,7 +13,7 @@ from pika.exceptions import AMQPConnectionError
|
|||||||
|
|
||||||
SWITCHING_TIME = 15
|
SWITCHING_TIME = 15
|
||||||
# Scale speed of switching by factor x
|
# Scale speed of switching by factor x
|
||||||
SCALING = 1
|
SCALING = 6
|
||||||
|
|
||||||
|
|
||||||
class TrafficLight:
|
class TrafficLight:
|
||||||
|
|||||||
@ -19,7 +19,7 @@ STARTING_POINT = geopy.Point(47.89053, 16.20703)
|
|||||||
# Driving direction in degrees: 0=N, 90=E, 180=S, 270=W
|
# Driving direction in degrees: 0=N, 90=E, 180=S, 270=W
|
||||||
BEARING = 2
|
BEARING = 2
|
||||||
# Scale speed of vehicles by factor x
|
# Scale speed of vehicles by factor x
|
||||||
SCALING = 1
|
SCALING = 6
|
||||||
# in km/h
|
# in km/h
|
||||||
STARTING_VELOCITY = 130 * SCALING
|
STARTING_VELOCITY = 130 * SCALING
|
||||||
# Interval between status updates in seconds (is not scaled)
|
# Interval between status updates in seconds (is not scaled)
|
||||||
@ -170,7 +170,7 @@ class Vehicle:
|
|||||||
driving_time = (updated_timestamp - old_timestamp).total_seconds()
|
driving_time = (updated_timestamp - old_timestamp).total_seconds()
|
||||||
|
|
||||||
# reached distance in kilometers: convert km/h to km/s and multiply by driving time
|
# reached distance in kilometers: convert km/h to km/s and multiply by driving time
|
||||||
kilometers = self.velocity / 3600 * driving_time * SCALING
|
kilometers = self.velocity / 3600 * driving_time
|
||||||
|
|
||||||
# Define a general distance object, initialized with a distance of k km.
|
# Define a general distance object, initialized with a distance of k km.
|
||||||
d = geopy.distance.distance(kilometers=kilometers)
|
d = geopy.distance.distance(kilometers=kilometers)
|
||||||
@ -231,6 +231,7 @@ class Vehicle:
|
|||||||
self._driven_kms = 0
|
self._driven_kms = 0
|
||||||
self.last_update = datetime.now()
|
self.last_update = datetime.now()
|
||||||
self.nce = False
|
self.nce = False
|
||||||
|
self.velocity = STARTING_VELOCITY
|
||||||
|
|
||||||
@circuit(failure_threshold=10, expected_exception=AMQPConnectionError)
|
@circuit(failure_threshold=10, expected_exception=AMQPConnectionError)
|
||||||
def send_status_update(self):
|
def send_status_update(self):
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import pickle
|
|||||||
import sys
|
import sys
|
||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from math import floor, ceil
|
from math import floor
|
||||||
|
|
||||||
import requests
|
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
|
||||||
@ -22,7 +22,7 @@ sys.modules['target_velocity'] = target_velocity
|
|||||||
|
|
||||||
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
|
ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
|
||||||
|
|
||||||
SCALING = 1
|
SCALING = 6
|
||||||
|
|
||||||
|
|
||||||
class Orchestrator:
|
class Orchestrator:
|
||||||
@ -109,7 +109,7 @@ class Orchestrator:
|
|||||||
switching_time = self.tls[tl_id]['switching_time'] / float(SCALING)
|
switching_time = self.tls[tl_id]['switching_time'] / float(SCALING)
|
||||||
# Time until next switch must be scaled accordingly
|
# Time until next switch must be scaled accordingly
|
||||||
next_switch_time = self.tls[tl_id]['last_switch'] + timedelta(seconds=switching_time)
|
next_switch_time = self.tls[tl_id]['last_switch'] + timedelta(seconds=switching_time)
|
||||||
time_until_switch = (next_switch_time - datetime.now()).total_seconds()
|
time_until_switch = (next_switch_time - datetime.utcnow()).total_seconds()
|
||||||
print('Distance to TL: {}'.format(distance))
|
print('Distance to TL: {}'.format(distance))
|
||||||
print('Time until switch in seconds: {}'.format(time_until_switch))
|
print('Time until switch in seconds: {}'.format(time_until_switch))
|
||||||
if self.tls[tl_id]['color'] is TrafficLightColor.RED:
|
if self.tls[tl_id]['color'] is TrafficLightColor.RED:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user