avoid freeze carla
This commit is contained in:
parent
244a85a9a1
commit
d03af8cc9c
|
@ -53,11 +53,11 @@ class SimulationSynchronization(object):
|
||||||
SimulationSynchronization class is responsible for the synchronization of ptv-vissim and carla
|
SimulationSynchronization class is responsible for the synchronization of ptv-vissim and carla
|
||||||
simulations.
|
simulations.
|
||||||
"""
|
"""
|
||||||
def __init__(self, args):
|
def __init__(self, vissim_simulation, carla_simulation, args):
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
||||||
self.vissim = PTVVissimSimulation(args)
|
self.vissim = vissim_simulation
|
||||||
self.carla = CarlaSimulation(args)
|
self.carla = carla_simulation
|
||||||
|
|
||||||
# Mapped actor ids.
|
# Mapped actor ids.
|
||||||
self.vissim2carla_ids = {} # Contains only actors controlled by vissim.
|
self.vissim2carla_ids = {} # Contains only actors controlled by vissim.
|
||||||
|
@ -68,6 +68,12 @@ class SimulationSynchronization(object):
|
||||||
with open(os.path.join(dir_path, 'data', 'vtypes.json')) as f:
|
with open(os.path.join(dir_path, 'data', 'vtypes.json')) as f:
|
||||||
BridgeHelper.vtypes = json.load(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):
|
def tick(self):
|
||||||
"""
|
"""
|
||||||
Tick to simulation synchronization
|
Tick to simulation synchronization
|
||||||
|
@ -165,8 +171,11 @@ def synchronization_loop(args):
|
||||||
"""
|
"""
|
||||||
Entry point for vissim-carla co-simulation.
|
Entry point for vissim-carla co-simulation.
|
||||||
"""
|
"""
|
||||||
|
carla_simulation = CarlaSimulation(args)
|
||||||
|
vissim_simulation = PTVVissimSimulation(args)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
synchronization = SimulationSynchronization(args)
|
synchronization = SimulationSynchronization(vissim_simulation, carla_simulation, args)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
|
@ -37,12 +37,6 @@ class CarlaSimulation(object):
|
||||||
self.world = self.client.get_world()
|
self.world = self.client.get_world()
|
||||||
self.blueprint_library = self.world.get_blueprint_library()
|
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.
|
# The following sets contain updated information for the current frame.
|
||||||
self._active_actors = set()
|
self._active_actors = set()
|
||||||
self.spawned_actors = set()
|
self.spawned_actors = set()
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
import enum
|
import enum
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
|
|
||||||
import carla # pylint: disable=import-error
|
import carla # pylint: disable=import-error
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
|
@ -143,15 +144,19 @@ class PTVVissimSimulation(object):
|
||||||
|
|
||||||
# Connection to vissim simulator.
|
# Connection to vissim simulator.
|
||||||
logging.info('Establishing a connection with a GUI version of PTV-Vissim')
|
logging.info('Establishing a connection with a GUI version of PTV-Vissim')
|
||||||
self.ds_proxy.VISSIM_Connect(args.vissim_version, args.vissim_network,
|
result = self.ds_proxy.VISSIM_Connect(args.vissim_version,
|
||||||
int(1. / args.step_length),
|
os.path.abspath(args.vissim_network),
|
||||||
c_double(constants.VISSIM_VISIBILITY_RADIUS),
|
int(1. / args.step_length),
|
||||||
c_ushort(constants.VISSIM_MAX_SIMULATOR_VEH),
|
c_double(constants.VISSIM_VISIBILITY_RADIUS),
|
||||||
c_ushort(constants.VISSIM_MAX_SIMULATOR_PED),
|
c_ushort(constants.VISSIM_MAX_SIMULATOR_VEH),
|
||||||
c_ushort(constants.VISSIM_MAX_SIMULATOR_DET),
|
c_ushort(constants.VISSIM_MAX_SIMULATOR_PED),
|
||||||
c_ushort(constants.VISSIM_MAX_VISSIM_VEH),
|
c_ushort(constants.VISSIM_MAX_SIMULATOR_DET),
|
||||||
c_ushort(constants.VISSIM_MAX_VISSIM_PED),
|
c_ushort(constants.VISSIM_MAX_VISSIM_VEH),
|
||||||
c_ushort(constants.VISSIM_MAX_VISSIM_SIGGRP))
|
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.
|
# Structures to keep track of the simulation state at each time step.
|
||||||
self._vissim_vehicles = {} # vissim_actor_id: VissimVehicle (only vissim traffic)
|
self._vissim_vehicles = {} # vissim_actor_id: VissimVehicle (only vissim traffic)
|
||||||
|
|
Loading…
Reference in New Issue