class_docstr: SimulationSynchronization class is responsible for the synchronization of ptv-vissim and carla
  simulations.
class_docstr_tok: ["SimulationSynchronization","class","is","responsible","for","the","synchronization","of","ptv-vissim","and","carla","simulations","."]
docstr: Tick to simulation synchronization
docstr_tok: ["Tick","to","simulation","synchronization"]
code: def tick(self):
      """
      Tick to simulation synchronization
      """
      # -------------------
      # vissim-->carla sync
      # -------------------
      self.vissim.tick()
  
      # Spawning vissim controlled vehicles in carla.
      vissim_spawned_actors = self.vissim.spawned_vehicles - set(
          self.carla2vissim_ids.values()
      )
      for vissim_actor_id in vissim_spawned_actors:
          vissim_actor = self.vissim.get_actor(vissim_actor_id)
  
          carla_blueprint = BridgeHelper.get_carla_blueprint(
              vissim_actor
          )
          if carla_blueprint is not None:
              carla_transform = BridgeHelper.get_carla_transform(
                  vissim_actor.get_transform()
              )
              carla_actor_id = self.carla.spawn_actor(
                  carla_blueprint, carla_transform
              )
  
              if carla_actor_id != INVALID_ACTOR_ID:
                  self.vissim2carla_ids[
                      vissim_actor_id
                  ] = carla_actor_id
  
      # Destroying vissim controlled vehicles in carla.
      for vissim_actor_id in self.vissim.destroyed_vehicles:
          if vissim_actor_id in self.vissim2carla_ids:
              self.vissim.destroy_actor(
                  self.vissim2carla_ids.pop(vissim_actor_id)
              )
  
      # Updating vissim controlled vehicles in carla.
      for vissim_actor_id in self.vissim2carla_ids:
          carla_actor_id = self.vissim2carla_ids[vissim_actor_id]
  
          vissim_actor = self.vissim.get_actor(vissim_actor_id)
          carla_actor = self.carla.get_actor(carla_actor_id)
  
          carla_transform = BridgeHelper.get_carla_transform(
              vissim_actor.get_transform(),
              carla_actor.bounding_box.extent,
          )
          carla_velocity = BridgeHelper.get_carla_velocity(
              vissim_actor.get_velocity()
          )
          self.carla.synchronize_vehicle(
              carla_actor_id, carla_transform, carla_velocity
          )
  
      # -------------------
      # carla-->vissim sync
      # -------------------
      self.carla.tick()
  
      # Spawning carla controlled vehicles in vissim. This also takes into account carla vehicles
      # that could not be spawned in vissim in previous time steps.
      carla_spawned_actors = self.carla.spawned_actors - set(
          self.vissim2carla_ids.values()
      )
      carla_spawned_actors.update(
          [
              c_id
              for c_id, v_id in self.carla2vissim_ids.items()
              if v_id == INVALID_ACTOR_ID
          ]
      )
      for carla_actor_id in carla_spawned_actors:
          carla_actor = self.carla.get_actor(carla_actor_id)
  
          vissim_transform = BridgeHelper.get_vissim_transform(
              carla_actor.get_transform()
          )
          vissim_actor_id = self.vissim.spawn_actor(vissim_transform)
  
          # Add the vissim_actor_id even if it was not possible to spawn it (INVALID_ACTOR_ID) to
          # try to spawn it again in next time steps.
          self.carla2vissim_ids[carla_actor_id] = vissim_actor_id
  
      # Destroying carla controlled vehicles in vissim.
      for carla_actor_id in self.carla.destroyed_actors:
          if carla_actor_id in self.carla2vissim_ids:
              self.vissim.destroy_actor(
                  self.carla2vissim_ids.pop(carla_actor_id)
              )
  
      # Updating carla controlled vehicles in vissim.
      for carla_actor_id in self.carla2vissim_ids:
          vissim_actor_id = self.carla2vissim_ids[carla_actor_id]
          if vissim_actor_id != INVALID_ACTOR_ID:
              carla_actor = self.carla.get_actor(carla_actor_id)
  
              vissim_transform = BridgeHelper.get_vissim_transform(
                  carla_actor.get_transform(),
                  carla_actor.bounding_box.extent,
              )
              vissim_velocity = BridgeHelper.get_vissim_velocity(
                  carla_actor.get_velocity()
              )
              self.vissim.synchronize_vehicle(
                  vissim_actor_id, vissim_transform, vissim_velocity
              )
  
file_path: carla/Co-Simulation/PTV-Vissim/run_synchronization.py
imports: import argparse
  import json
  import logging
  import time
  import glob
  import os
  import sys
  from vissim_integration.bridge_helper import BridgeHelper
  from vissim_integration.carla_simulation import CarlaSimulation
  from vissim_integration.vissim_simulation import PTVVissimSimulation
  from vissim_integration.constants import INVALID_ACTOR_ID
label_desc: Use image node_id 2 for calling the SimulationSynchronization obj's underlying member method code with example usage: obj.tick() without return types