How to use the carla.Transform function in carla

To help you get started, we’ve selected a few carla examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github layssi / Carla_Ray_Rlib / test_code / synchronous_mode.py View on Github external
vehicle = world.spawn_actor(
            random.choice(blueprint_library.filter('vehicle.*')),
            start_pose)
        actor_list.append(vehicle)
        vehicle.set_simulate_physics(False)

        camera_rgb = world.spawn_actor(
            blueprint_library.find('sensor.camera.rgb'),
            carla.Transform(carla.Location(x=-5.5, z=2.8), carla.Rotation(pitch=-15)),
            attach_to=vehicle)
        actor_list.append(camera_rgb)

        camera_semseg = world.spawn_actor(
            blueprint_library.find('sensor.camera.semantic_segmentation'),
            carla.Transform(carla.Location(x=-5.5, z=2.8), carla.Rotation(pitch=-15)),
            attach_to=vehicle)
        actor_list.append(camera_semseg)

        # Create a synchronous mode context.
        with CarlaSyncMode(world, camera_rgb, camera_semseg, fps=50) as sync_mode:
            while True:
                if should_quit():
                    return
                clock.tick()
                t = time.time()

                # Advance the simulation and wait for the data.
                snapshot, image_rgb, image_semseg = sync_mode.tick(timeout=2.0)

                # Choose the next waypoint and update the car location.
                waypoint = random.choice(waypoint.next(1.5))
github carla-simulator / carla / PythonAPI / examples / automatic_control.py View on Github external
def __init__(self, parent_actor):
        self.sensor = None
        self._parent = parent_actor
        self.lat = 0.0
        self.lon = 0.0
        world = self._parent.get_world()
        bp = world.get_blueprint_library().find('sensor.other.gnss')
        self.sensor = world.spawn_actor(bp, carla.Transform(carla.Location(x=1.0, z=2.8)),
                                        attach_to=self._parent)
        # We need to pass the lambda a weak reference to self to avoid circular
        # reference.
        weak_self = weakref.ref(self)
        self.sensor.listen(lambda event: GnssSensor._on_gnss_event(weak_self, event))
github carla-simulator / scenario_runner / srunner / metrics / tools / metrics_parser.py View on Github external
def parse_transform(info):
    """
    Parses a list into a carla.Transform

    Args:
        info (list): list corresponding to a row of the recorder
    """
    transform = carla.Transform(
        carla.Location(
            float(info[3][1:-1]) / 100,
            float(info[4][:-1]) / 100,
            float(info[5][:-1]) / 100,
        ),
        carla.Rotation(
            float(info[8][:-1]),   # pitch
            float(info[9][:-1]),   # yaw
            float(info[7][1:-1])   # roll
        )
    )

    return transform
github carla-simulator / scenario_runner / srunner / scenarios / object_crash_vehicle.py View on Github external
except RuntimeError as r:
                # We keep retrying until we spawn
                print("Base transform is blocking objects ", self.transform)
                _start_distance += 0.4
                self._spawn_attempted += 1
                if self._spawn_attempted >= self._number_of_attempts:
                    raise r

        # Now that we found a possible position we just put the vehicle to the underground
        disp_transform = carla.Transform(
            carla.Location(self.transform.location.x,
                           self.transform.location.y,
                           self.transform.location.z - 500),
            self.transform.rotation)

        prop_disp_transform = carla.Transform(
            carla.Location(self.transform2.location.x,
                           self.transform2.location.y,
                           self.transform2.location.z - 500),
            self.transform2.rotation)

        first_vehicle.set_transform(disp_transform)
        blocker.set_transform(prop_disp_transform)
        first_vehicle.set_simulate_physics(enabled=False)
        blocker.set_simulate_physics(enabled=False)
        self.other_actors.append(first_vehicle)
        self.other_actors.append(blocker)
github rohjunha / language-grounded-driving / game / sensors.py View on Github external
def generate_collision_sensor(world, agent):
    bp = world.get_blueprint_library().find('sensor.other.collision')
    return world.spawn_actor(bp, carla.Transform(), attach_to=agent)
github dianchen96 / LearningByCheating / bird_view / utils / carla_utils.py View on Github external
def spawn_pedestrians(self, n_pedestrians):
        SpawnActor = carla.command.SpawnActor

        peds_spawned = 0
        
        walkers = []
        controllers = []
        
        while peds_spawned < n_pedestrians:
            spawn_points = []
            _walkers = []
            _controllers = []
            
            for i in range(n_pedestrians - peds_spawned):
                spawn_point = carla.Transform()
                loc = self._world.get_random_location_from_navigation()
    
                if loc is not None:
                    spawn_point.location = loc
                    spawn_points.append(spawn_point)
    
            blueprints = self._blueprints.filter('walker.pedestrian.*')
            batch = []
            for spawn_point in spawn_points:
                walker_bp = random.choice(blueprints)
    
                if walker_bp.has_attribute('is_invincible'):
                    walker_bp.set_attribute('is_invincible', 'false')
    
                batch.append(SpawnActor(walker_bp, spawn_point))
github carla-simulator / scenario_runner / srunner / scenarios / opposite_vehicle_taking_priority.py View on Github external
def _initialize_actors(self, config):
        """
        Custom initialization
        """
        self._other_actor_transform = config.other_actors[0].transform
        first_vehicle_transform = carla.Transform(
            carla.Location(config.other_actors[0].transform.location.x,
                           config.other_actors[0].transform.location.y,
                           config.other_actors[0].transform.location.z),
            config.other_actors[0].transform.rotation)
        first_vehicle = CarlaDataProvider.request_new_actor(config.other_actors[0].model, first_vehicle_transform)
        self.other_actors.append(first_vehicle)
github carla-simulator / carla / PythonAPI / examples / tm_spawn_npc.py View on Github external
color = random.choice(blueprint.get_attribute('color').recommended_values)
                blueprint.set_attribute('color', color)
            if blueprint.has_attribute('driver_id'):
                driver_id = random.choice(blueprint.get_attribute('driver_id').recommended_values)
                blueprint.set_attribute('driver_id', driver_id)
            blueprint.set_attribute('role_name', 'autopilot')
            vehicle = world.try_spawn_actor(blueprint, transform)
            vehicles_list.append(vehicle)

        # -------------
        # Spawn Walkers
        # -------------
        # 1. take all the random locations to spawn
        spawn_points = []
        for i in range(args.number_of_walkers):
            spawn_point = carla.Transform()
            loc = world.get_random_location_from_navigation()
            if (loc != None):
                spawn_point.location = loc
                spawn_points.append(spawn_point)
        # 2. we spawn the walker object
        batch = []
        for spawn_point in spawn_points:
            walker_bp = random.choice(blueprints_walkers)
            # set as not invencible
            if walker_bp.has_attribute('is_invincible'):
                walker_bp.set_attribute('is_invincible', 'false')
            batch.append(SpawnActor(walker_bp, spawn_point))
        results = client.apply_batch_sync(batch, True)
        for i in range(len(results)):
            if results[i].error:
                logging.error(results[i].error)
github carla-simulator / carla-autoware / carla_autoware_control.py View on Github external
def restart(self):
        # Keep same camera config if the camera manager exists.
        cam_index = self.camera_manager._index if self.camera_manager is not None else 0
        cam_pos_index = self.camera_manager._transform_index if self.camera_manager is not None else 0
        # Get a random blueprint.
        blueprint = random.choice(self.world.get_blueprint_library().filter(self._actor_filter))
        blueprint.set_attribute('role_name', 'hero')
        if blueprint.has_attribute('color'):
            color = random.choice(blueprint.get_attribute('color').recommended_values)
            blueprint.set_attribute('color', color)
        # Spawn the player.
        if self._actor_spawnpoint:
            spawn_point = carla.Transform()
            spawn_point.location.x = self._actor_spawnpoint[0]
            spawn_point.location.y = self._actor_spawnpoint[1]
            spawn_point.location.z = self._actor_spawnpoint[2]
            spawn_point.rotation.yaw = self._actor_spawnpoint[3]
            if self.player is not None:
                self.destroy()
            while self.player is None:
                self.player = self.world.try_spawn_actor(blueprint, spawn_point)
        else:
            if self.player is not None:
                spawn_point = self.player.get_transform()
                spawn_point.location.z += 2.0
                spawn_point.rotation.roll = 0.0
                spawn_point.rotation.pitch = 0.0
                self.destroy()
                self.player = self.world.try_spawn_actor(blueprint, spawn_point)
github carla-simulator / carla / PythonAPI / examples / spawn_pedestrians.py View on Github external
for spawn_point in spawn_points:
          walker_bp = random.choice(world.get_blueprint_library().filter('walker.pedestrian.*'))
          batch.append(SpawnActor(walker_bp, spawn_point))
      # apply
      results = client.apply_batch_sync(batch, True)
      for i in range(len(results)):
          if results[i].error:
              logging.error(results[i].error)
          else:
              info.append({ "id":results[i].actor_id, "trans":spawn_points[i], "con":None })

      # Spawn walker controller
      batch = []
      walker_controller_bp = world.get_blueprint_library().find('controller.ai.walker')
      for i in range(len(info)):
          batch.append(SpawnActor(walker_controller_bp, carla.Transform(), info[i]["id"]))
      # apply
      results = client.apply_batch_sync(batch, True)
      for i in range(len(results)):
          if results[i].error:
              logging.error(results[i].error)
          else:
              info[i]["con"] = results[i].actor_id

      # get whole list of actors (child and parents)
      all_id = []
      for i in range(len(info)):
          all_id.append(info[i]["id"])
          all_id.append(info[i]["con"])
      all_actors = world.get_actors(all_id)

      # initialize each controller and set target to walk to