Skip to content

Commit

Permalink
avoid freeze carla
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-mb authored and bernatx committed Apr 15, 2020
1 parent 244a85a commit d03af8c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
17 changes: 13 additions & 4 deletions Co-Simulation/PTV-Vissim/run_synchronization.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class SimulationSynchronization(object):
SimulationSynchronization class is responsible for the synchronization of ptv-vissim and carla
simulations.
"""
def __init__(self, args):
def __init__(self, vissim_simulation, carla_simulation, args):
self.args = args

self.vissim = PTVVissimSimulation(args)
self.carla = CarlaSimulation(args)
self.vissim = vissim_simulation
self.carla = carla_simulation

# Mapped actor ids.
self.vissim2carla_ids = {} # Contains only actors controlled by vissim.
Expand All @@ -68,6 +68,12 @@ def __init__(self, args):
with open(os.path.join(dir_path, 'data', 'vtypes.json')) as f:
BridgeHelper.vtypes = json.load(f)

# Configuring carla simulation in sync mode.
settings = self.carla.world.get_settings()
settings.synchronous_mode = True
settings.fixed_delta_seconds = args.step_length
self.carla.world.apply_settings(settings)

def tick(self):
"""
Tick to simulation synchronization
Expand Down Expand Up @@ -165,8 +171,11 @@ def synchronization_loop(args):
"""
Entry point for vissim-carla co-simulation.
"""
carla_simulation = CarlaSimulation(args)
vissim_simulation = PTVVissimSimulation(args)

try:
synchronization = SimulationSynchronization(args)
synchronization = SimulationSynchronization(vissim_simulation, carla_simulation, args)

while True:
start = time.time()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ def __init__(self, args):
self.world = self.client.get_world()
self.blueprint_library = self.world.get_blueprint_library()

# Configuring carla simulation in sync mode.
settings = self.world.get_settings()
settings.synchronous_mode = True
settings.fixed_delta_seconds = args.step_length
self.world.apply_settings(settings)

# The following sets contain updated information for the current frame.
self._active_actors = set()
self.spawned_actors = set()
Expand Down
23 changes: 14 additions & 9 deletions Co-Simulation/PTV-Vissim/vissim_integration/vissim_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import enum
import logging
import math
import os

import carla # pylint: disable=import-error
from ctypes import *
Expand Down Expand Up @@ -143,15 +144,19 @@ def __init__(self, args):

# Connection to vissim simulator.
logging.info('Establishing a connection with a GUI version of PTV-Vissim')
self.ds_proxy.VISSIM_Connect(args.vissim_version, args.vissim_network,
int(1. / args.step_length),
c_double(constants.VISSIM_VISIBILITY_RADIUS),
c_ushort(constants.VISSIM_MAX_SIMULATOR_VEH),
c_ushort(constants.VISSIM_MAX_SIMULATOR_PED),
c_ushort(constants.VISSIM_MAX_SIMULATOR_DET),
c_ushort(constants.VISSIM_MAX_VISSIM_VEH),
c_ushort(constants.VISSIM_MAX_VISSIM_PED),
c_ushort(constants.VISSIM_MAX_VISSIM_SIGGRP))
result = self.ds_proxy.VISSIM_Connect(args.vissim_version,
os.path.abspath(args.vissim_network),
int(1. / args.step_length),
c_double(constants.VISSIM_VISIBILITY_RADIUS),
c_ushort(constants.VISSIM_MAX_SIMULATOR_VEH),
c_ushort(constants.VISSIM_MAX_SIMULATOR_PED),
c_ushort(constants.VISSIM_MAX_SIMULATOR_DET),
c_ushort(constants.VISSIM_MAX_VISSIM_VEH),
c_ushort(constants.VISSIM_MAX_VISSIM_PED),
c_ushort(constants.VISSIM_MAX_VISSIM_SIGGRP))

if not result:
raise RuntimeError('There was an error when establishing a connection with PTV-Vissim')

# Structures to keep track of the simulation state at each time step.
self._vissim_vehicles = {} # vissim_actor_id: VissimVehicle (only vissim traffic)
Expand Down

0 comments on commit d03af8c

Please sign in to comment.