Skip to content

Commit

Permalink
applying solution (2) from sidewalklabs#19 (comment) and merging with…
Browse files Browse the repository at this point in the history
… flow-sumo-web3d fork
  • Loading branch information
roireshef committed Jul 8, 2020
1 parent d89fe80 commit 8b2b357
Show file tree
Hide file tree
Showing 3 changed files with 120,570 additions and 9 deletions.
24 changes: 15 additions & 9 deletions sumo_web3d/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import websockets
import xmltodict

from . import constants # noqa
from . import constants # noqa
from .deltas import round_vehicles, diff_dicts
import sumolib
import traci
Expand All @@ -34,6 +34,8 @@
parser.add_argument(
'--gui', action='store_true', default=False,
help='Run sumo-gui rather than sumo. This is useful for debugging.')
parser.add_argument(
'--sumo-port', dest='sumo_port')

# Base directory for sumo_web3d
DIR = os.path.join(os.path.dirname(__file__), '..')
Expand Down Expand Up @@ -335,16 +337,20 @@ async def websocket_simulation_control(sumo_start_fn, task, websocket, path):

# TraCI business logic
def start_sumo_executable(gui, sumo_args, sumocfg_file):
sumoBinary = sumolib.checkBinary('sumo' if not gui else 'sumo-gui')
additional_args = shlex.split(sumo_args) if sumo_args else []
args = [sumoBinary, '-c', sumocfg_file] + additional_args
print('Executing %s' % ' '.join(args))
traci.start(args)
if sumo_args.sumo_port:
traci.init(port=int(sumo_args.sumo_port), label="")
traci.setOrder(1)
else:
sumoBinary = sumolib.checkBinary('sumo' if not gui else 'sumo-gui')
additional_args = shlex.split(sumo_args.sumo_args) if sumo_args.sumo_args else []
args = [sumoBinary, '-c', sumocfg_file] + additional_args
print('Executing %s' % ' '.join(args))
traci.start(args)
traci.simulation.subscribe()

# Subscribe to all traffic lights. This set of IDs should never change.
for light_id in traci.trafficlights.getIDList():
traci.trafficlights.subscribe(light_id, [
for light_id in traci.trafficlight.getIDList():
traci.trafficlight.subscribe(light_id, [
tc.TL_CURRENT_PHASE,
tc.TL_CURRENT_PROGRAM
])
Expand Down Expand Up @@ -553,7 +559,7 @@ def setup_http_server(task, scenario_file, scenarios):
def main(args):
global current_scenario, scenarios, SCENARIOS_PATH
task = None
sumo_start_fn = functools.partial(start_sumo_executable, args.gui, args.sumo_args)
sumo_start_fn = functools.partial(start_sumo_executable, args.gui, args)

if args.configuration_file:
# Replace the built-in scenarios with a single, user-specified one.
Expand Down
Loading

0 comments on commit 8b2b357

Please sign in to comment.