Implement correct scaling

This commit is contained in:
Tobias Eidelpes 2021-06-17 19:52:52 +02:00
parent 5c492460b9
commit 81a41226a0
4 changed files with 10 additions and 9 deletions

View File

@ -3,21 +3,21 @@
"id": "1",
"location": [16.20719, 47.89584],
"range": 2000,
"switchingTime": 5,
"switchingTime": 26,
"color": "RED"
},
{
"id": "2",
"location": [16.20814, 47.90937],
"range": 800,
"switchingTime": 15,
"switchingTime": 16,
"color": "GREEN"
},
{
"id": "3",
"location": [16.20917, 47.92703],
"range": 1000,
"switchingTime": 10,
"switchingTime": 20,
"color": "RED"
}
]

View File

@ -13,7 +13,7 @@ from pika.exceptions import AMQPConnectionError
SWITCHING_TIME = 15
# Scale speed of switching by factor x
SCALING = 1
SCALING = 6
class TrafficLight:

View File

@ -19,7 +19,7 @@ STARTING_POINT = geopy.Point(47.89053, 16.20703)
# Driving direction in degrees: 0=N, 90=E, 180=S, 270=W
BEARING = 2
# Scale speed of vehicles by factor x
SCALING = 1
SCALING = 6
# in km/h
STARTING_VELOCITY = 130 * SCALING
# Interval between status updates in seconds (is not scaled)
@ -170,7 +170,7 @@ class Vehicle:
driving_time = (updated_timestamp - old_timestamp).total_seconds()
# 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.
d = geopy.distance.distance(kilometers=kilometers)
@ -231,6 +231,7 @@ class Vehicle:
self._driven_kms = 0
self.last_update = datetime.now()
self.nce = False
self.velocity = STARTING_VELOCITY
@circuit(failure_threshold=10, expected_exception=AMQPConnectionError)
def send_status_update(self):

View File

@ -3,7 +3,7 @@ import pickle
import sys
from typing import List, Dict
from datetime import datetime, timedelta
from math import floor, ceil
from math import floor
import requests
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/'
SCALING = 1
SCALING = 6
class Orchestrator:
@ -109,7 +109,7 @@ class Orchestrator:
switching_time = self.tls[tl_id]['switching_time'] / float(SCALING)
# Time until next switch must be scaled accordingly
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('Time until switch in seconds: {}'.format(time_until_switch))
if self.tls[tl_id]['color'] is TrafficLightColor.RED: