예제 #1
0
    def _initialize_actors(self, config):
        """
        Custom initialization
        """
        first_vehicle_waypoint, _ = get_waypoint_in_distance(
            self._reference_waypoint, self._first_vehicle_location)
        second_vehicle_waypoint, _ = get_waypoint_in_distance(
            self._reference_waypoint, self._second_vehicle_location)
        second_vehicle_waypoint = second_vehicle_waypoint.get_left_lane()

        first_vehicle_transform = carla.Transform(
            first_vehicle_waypoint.transform.location,
            first_vehicle_waypoint.transform.rotation)
        second_vehicle_transform = carla.Transform(
            second_vehicle_waypoint.transform.location,
            second_vehicle_waypoint.transform.rotation)

        first_vehicle = CarlaActorPool.request_new_actor(
            'vehicle.nissan.patrol', first_vehicle_transform)
        second_vehicle = CarlaActorPool.request_new_actor(
            'vehicle.audi.tt', second_vehicle_transform)

        self.other_actors.append(first_vehicle)
        self.other_actors.append(second_vehicle)

        self._first_actor_transform = first_vehicle_transform
        self._second_actor_transform = second_vehicle_transform
예제 #2
0
    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 - 500,
            ),
            config.other_actors[0].transform.rotation,
        )
        try:
            first_vehicle = CarlaActorPool.request_new_actor(
                config.other_actors[0].model, self._other_actor_transform)
        except RuntimeError as r_error:
            raise r_error
        first_vehicle.set_transform(first_vehicle_transform)
        self.other_actors.append(first_vehicle)

        self._other_actor_transform2 = config.other_actors[1].transform
        first_vehicle_transform2 = carla.Transform(
            carla.Location(
                config.other_actors[1].transform.location.x,
                config.other_actors[1].transform.location.y,
                config.other_actors[1].transform.location.z,
            ),
            config.other_actors[1].transform.rotation,
        )
        try:
            first_vehicle2 = CarlaActorPool.request_new_actor(
                config.other_actors[1].model, self._other_actor_transform2)
        except RuntimeError as r_error:
            raise r_error
        first_vehicle2.set_transform(first_vehicle_transform2)
        self.other_actors.append(first_vehicle2)

        self._other_actor_transform3 = config.other_actors[2].transform
        first_vehicle_transform3 = carla.Transform(
            carla.Location(
                config.other_actors[2].transform.location.x,
                config.other_actors[2].transform.location.y,
                config.other_actors[2].transform.location.z,
            ),
            config.other_actors[2].transform.rotation,
        )
        try:
            first_vehicle3 = CarlaActorPool.request_new_actor(
                config.other_actors[2].model, self._other_actor_transform3)
        except RuntimeError as r_error:
            raise r_error
        first_vehicle3.set_transform(first_vehicle_transform3)
        self.other_actors.append(first_vehicle3)
        print("Init done.")
    def _initialize_actors(self, config):
        """
        Custom initialization
        """
        self._distance = random.sample(range(10, 80), 3)
        self._distance = sorted(self._distance)
        first_loc, _ = get_location_in_distance_from_wp(
            self._reference_waypoint, self._distance[0])
        second_loc, _ = get_location_in_distance_from_wp(
            self._reference_waypoint, self._distance[1])
        third_loc, _ = get_location_in_distance_from_wp(
            self._reference_waypoint, self._distance[2])

        self.loc_list.extend([first_loc, second_loc, third_loc])
        self._dist_prop = [x - 2 for x in self._distance]

        self.first_loc_prev, _ = get_location_in_distance_from_wp(
            self._reference_waypoint, self._dist_prop[0])
        self.sec_loc_prev, _ = get_location_in_distance_from_wp(
            self._reference_waypoint, self._dist_prop[1])
        self.third_loc_prev, _ = get_location_in_distance_from_wp(
            self._reference_waypoint, self._dist_prop[2])

        self.first_transform = carla.Transform(self.first_loc_prev)
        self.sec_transform = carla.Transform(self.sec_loc_prev)
        self.third_transform = carla.Transform(self.third_loc_prev)
        self.first_transform = carla.Transform(
            carla.Location(self.first_loc_prev.x, self.first_loc_prev.y,
                           self.first_loc_prev.z))
        self.sec_transform = carla.Transform(
            carla.Location(self.sec_loc_prev.x, self.sec_loc_prev.y,
                           self.sec_loc_prev.z))
        self.third_transform = carla.Transform(
            carla.Location(self.third_loc_prev.x, self.third_loc_prev.y,
                           self.third_loc_prev.z))

        first_debris = CarlaActorPool.request_new_actor(
            'static.prop.dirtdebris01', self.first_transform)
        second_debris = CarlaActorPool.request_new_actor(
            'static.prop.dirtdebris01', self.sec_transform)
        third_debris = CarlaActorPool.request_new_actor(
            'static.prop.dirtdebris01', self.third_transform)

        first_debris.set_transform(self.first_transform)
        second_debris.set_transform(self.sec_transform)
        third_debris.set_transform(self.third_transform)

        self.obj.extend([first_debris, second_debris, third_debris])
        for debris in self.obj:
            debris.set_simulate_physics(False)

        self.other_actors.append(first_debris)
        self.other_actors.append(second_debris)
        self.other_actors.append(third_debris)
예제 #4
0
    def _initialize_actors(self, config):
        """
        Custom initialization
        """
        first_actor_waypoint, _ = get_waypoint_in_distance(
            self._reference_waypoint, self._first_vehicle_location)
        second_actor_waypoint, _ = get_waypoint_in_distance(
            self._reference_waypoint, self._second_vehicle_location)
        second_actor_waypoint = second_actor_waypoint.get_left_lane()

        first_actor_transform = carla.Transform(
            first_actor_waypoint.transform.location,
            first_actor_waypoint.transform.rotation)
        if self._obstacle_type == 'vehicle':
            first_actor_model = 'vehicle.nissan.micra'
        else:
            first_actor_transform.rotation.yaw += 90
            first_actor_model = 'static.prop.streetbarrier'
            second_prop_waypoint = first_actor_waypoint.next(2.0)[0]
            position_yaw = second_prop_waypoint.transform.rotation.yaw + 90
            offset_location = carla.Location(
                0.50 * second_prop_waypoint.lane_width *
                math.cos(math.radians(position_yaw)),
                0.50 * second_prop_waypoint.lane_width *
                math.sin(math.radians(position_yaw)))
            second_prop_transform = carla.Transform(
                second_prop_waypoint.transform.location + offset_location,
                first_actor_transform.rotation)
            second_prop_actor = CarlaActorPool.request_new_actor(
                first_actor_model, second_prop_transform)
            second_prop_actor.set_simulate_physics(True)
        first_actor = CarlaActorPool.request_new_actor(first_actor_model,
                                                       first_actor_transform)
        first_actor.set_simulate_physics(True)
        second_actor = CarlaActorPool.request_new_actor(
            'vehicle.audi.tt', second_actor_waypoint.transform)

        self.other_actors.append(first_actor)
        self.other_actors.append(second_actor)
        if self._obstacle_type != 'vehicle':
            self.other_actors.append(second_prop_actor)

        self._source_transform = second_actor_waypoint.transform
        sink_waypoint = second_actor_waypoint.next(1)[0]
        while not sink_waypoint.is_intersection:
            sink_waypoint = sink_waypoint.next(1)[0]
        self._sink_location = sink_waypoint.transform.location

        self._first_actor_transform = first_actor_transform
        self._second_actor_transform = second_actor_waypoint.transform
        self._third_actor_transform = second_prop_transform
예제 #5
0
    def _initialize_actors(self, config):

        # add actors from xml file
        for actor in config.other_actors:
            vehicle = CarlaActorPool.request_new_actor(actor.model,
                                                       actor.transform)
            self.other_actors.append(vehicle)
            vehicle.set_simulate_physics(enabled=False)

        # fast vehicle, tesla
        # transform visible
        fast_car_waypoint, _ = get_waypoint_in_distance(
            self._reference_waypoint, self._fast_vehicle_distance)
        self.fast_car_visible = carla.Transform(
            carla.Location(fast_car_waypoint.transform.location.x,
                           fast_car_waypoint.transform.location.y,
                           fast_car_waypoint.transform.location.z + 1),
            fast_car_waypoint.transform.rotation)

        # slow vehicle, vw
        # transform visible
        slow_car_waypoint, _ = get_waypoint_in_distance(
            self._reference_waypoint, self._slow_vehicle_distance)
        self.slow_car_visible = carla.Transform(
            carla.Location(slow_car_waypoint.transform.location.x,
                           slow_car_waypoint.transform.location.y,
                           slow_car_waypoint.transform.location.z),
            slow_car_waypoint.transform.rotation)
예제 #6
0
    def _spawn_blocker(self, transform):
        """
        Spawn the blocker prop that blocks the vision from the egovehicle of the jaywalker
        :return:
        """
        # static object transform
        shift = 0.9
        x_ego = self._reference_waypoint.transform.location.x
        y_ego = self._reference_waypoint.transform.location.y
        x_cycle = transform.location.x
        y_cycle = transform.location.y
        x_static = x_ego + shift * (x_cycle - x_ego)
        y_static = y_ego + shift * (y_cycle - y_ego)

        spawn_point_wp = self.ego_vehicles[0].get_world().get_map(
        ).get_waypoint(transform.location)

        self.transform2 = carla.Transform(
            carla.Location(x_static, y_static,
                           spawn_point_wp.transform.location.z + 0.3))

        static = CarlaActorPool.request_new_actor('static.prop.vendingmachine',
                                                  self.transform2)
        static.set_simulate_physics(enabled=False)

        return static
    def update(self):
        new_status = py_trees.common.Status.RUNNING
        if self._actor_limit > 0:
            world_actors = self._world.get_actors()
            spawn_point_blocked = False
            if (self._last_blocking_actor
                    and self._spawn_point.location.distance(
                        self._last_blocking_actor.get_location()) <
                    self._threshold):
                spawn_point_blocked = True

            if not spawn_point_blocked:
                for actor in world_actors:
                    if self._spawn_point.location.distance(
                            actor.get_location()) < self._threshold:
                        spawn_point_blocked = True
                        self._last_blocking_actor = actor
                        break

            if not spawn_point_blocked:
                try:
                    new_actor = CarlaActorPool.request_new_actor(
                        np.random.choice(self._actor_types), self._spawn_point)
                    self._actor_limit -= 1
                    self._queue.put(new_actor)
                except:
                    print("ActorSource unable to spawn actor")
        return new_status
예제 #8
0
    def _initialize_dynamic_obstacles_ahead(self, actor_dict):
        actor_dict.speed = 3 + (0.4 * actor_dict.num_lane_changes)
        while True:
            try:
                actor_dict.start_transform, orientation = actor_dict._calculate_transform(
                )
                walker = CarlaActorPool.request_new_actor(
                    'walker.*', actor_dict.start_transform)
                walker.set_transform(actor_dict.start_transform)
                walker.set_simulate_physics(enabled=False)
                # print("walker spawned at" + str(actor_dict.start_transform))
                break

            except RuntimeError as r:
                # actor_dict._update_transform()
                actor_dict.start_dist += 0.4
                # print("self.start_dist after update: " + str(self.start_dist))
                actor_dict.spawn_attempted += 1
                if actor_dict.spawn_attempted >= actor_dict._number_of_attempts:
                    raise r

        default = actor_dict._calculate_default(actor_dict.start_transform)
        walker.set_transform(default)
        index = len(self.other_actors)
        actor_dict.index = index
        # print("index of dynamic crossing actor: " + str(index))
        self.other_actors.append(walker)
예제 #9
0
 def _initialize_stationary_obstacles_ahead(self, actor_dict):
     static = CarlaActorPool.request_new_actor('vehicle.nissan.patrol',
                                               actor_dict.start_transform)
     static.set_simulate_physics(True)
     index = len(self.other_actors)
     actor_dict.index = index
     # print("index of Stationary obstacle actor: " + str(index))
     self.other_actors.append(static)
예제 #10
0
    def _initialize_actors(self, config):
        """
        Custom initialization
        """
        num_actors = 0
        actor_locations = []
        while num_actors < self._num_actors:
            actor_dict = dict()
            actor_dict["speed"] = random.randint(10, 20)
            actor_dict["location"] = self.generate_valid_location(
                actor_locations)
            actor_locations.append(actor_dict["location"])

            print("actor " + str(num_actors) + " location: " +
                  str(actor_dict["location"]))
            self.actor_list[num_actors] = actor_dict
            num_actors += 1

        num_actors = self._num_actors - 1
        while num_actors >= 0:
            vehicle_location = self.actor_list[num_actors]["location"]
            # first_vehicle_waypoint, _ = get_waypoint_in_distance(self._reference_waypoint, vehicle_location)
            first_vehicle_waypoint, _ = get_waypoint_in_distance(
                self._reference_waypoint, vehicle_location)
            lane = random.randint(0, 2)
            if lane == 0:
                pass
            elif lane == 1:
                left_lane = first_vehicle_waypoint.get_left_lane()
                if left_lane:
                    first_vehicle_waypoint = left_lane
            elif lane == 2:
                right_lane = first_vehicle_waypoint.get_right_lane()
                if right_lane:
                    first_vehicle_waypoint = right_lane

            # self.actor_list[num_actors]["transform"] = carla.Transform(
            #     carla.Location(first_vehicle_waypoint.transform.location.x,
            #                 first_vehicle_waypoint.transform.location.y,
            #                 first_vehicle_waypoint.transform.location.z + 1),
            #                 first_vehicle_waypoint.transform.rotation)
            other_actor_transform = carla.Transform(
                carla.Location(first_vehicle_waypoint.transform.location.x,
                               first_vehicle_waypoint.transform.location.y,
                               first_vehicle_waypoint.transform.location.z +
                               1), first_vehicle_waypoint.transform.rotation)
            self.actor_list[num_actors]["transform"] = other_actor_transform
            first_vehicle_transform = carla.Transform(
                carla.Location(other_actor_transform.location.x,
                               other_actor_transform.location.y,
                               other_actor_transform.location.z - 500),
                other_actor_transform.rotation)
            first_vehicle = CarlaActorPool.request_new_actor(
                'vehicle.nissan.patrol', first_vehicle_transform)
            first_vehicle.set_simulate_physics(enabled=False)
            self.other_actors.append(first_vehicle)
            num_actors -= 1
예제 #11
0
    def _spawn_adversary(self, transform, orientation_yaw):

        self._time_to_reach *= self._num_lane_changes

        if self._adversary_type is False:
            self._walker_yaw = orientation_yaw
            self._other_actor_target_velocity = 3 + (0.4 *
                                                     self._num_lane_changes)
            walker = CarlaActorPool.request_new_actor('walker.*', transform)
            adversary = walker
        else:
            self._other_actor_target_velocity = self._other_actor_target_velocity * self._num_lane_changes
            first_vehicle = CarlaActorPool.request_new_actor(
                'vehicle.diamondback.century', transform)
            first_vehicle.set_simulate_physics(enabled=False)
            adversary = first_vehicle

        return adversary
예제 #12
0
 def _initialize_cut_in(self, actor_dict):
     vehicle = CarlaActorPool.request_new_actor(
         'vehicle.nissan.patrol',
         actor_dict.start_transform)  #default_transform)
     vehicle.set_simulate_physics(enabled=False)
     index = len(self.other_actors)
     actor_dict.index = index
     # print("index of Cut In actor: " + str(index))
     self.other_actors.append(vehicle)
    def _initialize_actors(self, config):
        """
        Custom initialization
        """

        first_actor_waypoint, _ = get_waypoint_in_distance(
            self._reference_waypoint, self._first_actor_location)
        second_actor_waypoint, _ = get_waypoint_in_distance(
            self._reference_waypoint, self._second_actor_location)
        first_actor_transform = carla.Transform(
            carla.Location(first_actor_waypoint.transform.location.x,
                           first_actor_waypoint.transform.location.y,
                           first_actor_waypoint.transform.location.z - 500),
            first_actor_waypoint.transform.rotation)
        self._first_actor_transform = carla.Transform(
            carla.Location(first_actor_waypoint.transform.location.x,
                           first_actor_waypoint.transform.location.y,
                           first_actor_waypoint.transform.location.z + 1),
            first_actor_waypoint.transform.rotation)
        yaw_1 = second_actor_waypoint.transform.rotation.yaw + 90
        second_actor_transform = carla.Transform(
            carla.Location(second_actor_waypoint.transform.location.x,
                           second_actor_waypoint.transform.location.y,
                           second_actor_waypoint.transform.location.z - 500),
            carla.Rotation(second_actor_waypoint.transform.rotation.pitch,
                           yaw_1,
                           second_actor_waypoint.transform.rotation.roll))
        self._second_actor_transform = carla.Transform(
            carla.Location(second_actor_waypoint.transform.location.x,
                           second_actor_waypoint.transform.location.y,
                           second_actor_waypoint.transform.location.z + 1),
            carla.Rotation(second_actor_waypoint.transform.rotation.pitch,
                           yaw_1,
                           second_actor_waypoint.transform.rotation.roll))

        first_actor = CarlaActorPool.request_new_actor('vehicle.nissan.patrol',
                                                       first_actor_transform)
        second_actor = CarlaActorPool.request_new_actor(
            'vehicle.diamondback.century', second_actor_transform)

        first_actor.set_simulate_physics(enabled=False)
        second_actor.set_simulate_physics(enabled=False)
        self.other_actors.append(first_actor)
        self.other_actors.append(second_actor)
예제 #14
0
 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 - 500),
         config.other_actors[0].transform.rotation)
     first_vehicle = CarlaActorPool.request_new_actor(config.other_actors[0].model, first_vehicle_transform)
     self.other_actors.append(first_vehicle)
예제 #15
0
    def _spawn_ego_car(self, start_transform):
        """
        Spawn or update all scenario actors according to
        a certain start position.
        """
        # If ego_vehicle already exists, just update location
        # Otherwise spawn ego vehicle
        self._ego_actor = CarlaActorPool.request_new_actor(self._vehicle_model, start_transform,
                                                           hero=True)

        CarlaDataProvider.set_ego_vehicle_route( convert_transform_to_location(self._route))
        logging.debug("Created Ego Vehicle")
    def _initialize_actors(self, config):
        """
        Custom initialization
        """

        waypoint = self._reference_waypoint
        direction = self.SUBTYPE_INDEX_TRANSLATION[config.subtype]
        waypoint = generate_target_waypoint(waypoint, direction)
        _start_distance = 8
        while True:
            wp_next = waypoint.get_right_lane()
            self._num_lane_changes += 1
            if wp_next is not None:
                _start_distance += 1
                waypoint = wp_next
                if waypoint.lane_type == carla.LaneType.Shoulder or waypoint.lane_type == carla.LaneType.Sidewalk:
                    last_waypoint_lane = waypoint.lane_type
                    break

            else:
                last_waypoint_lane = waypoint.lane_type
                break

        while True:
            try:
                self._other_actor_transform = get_opponent_transform(
                    _start_distance, waypoint, self._trigger_location,
                    last_waypoint_lane)
                first_vehicle = CarlaActorPool.request_new_actor(
                    'vehicle.diamondback.century', self._other_actor_transform)
                first_vehicle.set_simulate_physics(enabled=False)

                break
            except RuntimeError as r:
                # In the case there is an object just move a little bit and retry
                print("Base transform is blocking objects ",
                      self._other_actor_transform)
                _start_distance += 0.2
                self._spawn_attempted += 1
                if self._spawn_attempted >= self._number_of_attempts:
                    raise r
        # Set the transform to -500 z after we are able to spawn it
        actor_transform = carla.Transform(
            carla.Location(self._other_actor_transform.location.x,
                           self._other_actor_transform.location.y,
                           self._other_actor_transform.location.z - 500),
            self._other_actor_transform.rotation)
        first_vehicle.set_transform(actor_transform)
        first_vehicle.set_simulate_physics(enabled=False)
        self.other_actors.append(first_vehicle)
    def _update_ego_vehicle(self):
        """
        Set/Update the start position of the ego_vehicle
        """
        # move ego to correct position
        elevate_transform = self.route[0][0]
        elevate_transform.location.z += 0.5

        ego_vehicle = CarlaActorPool.request_new_actor('vehicle.lincoln.mkz2017',
                                                       elevate_transform,
                                                       rolename='hero',
                                                       hero=True)

        return ego_vehicle
    def _initialize_actors(self, config):
        """
        Custom initialization
        """
        actor_list = []
        num_actors = 0
        # initialize parameters for each actor
        while num_actors < self._num_actors:
            actor_dict = {}
            actor_dict["_start_distance"] = random.randint(
                1, 3) * num_actors * 10 + random.randint(
                    10, 30)  #num_actors * 20 + 20
            actor_dict["offset"] = {
                "orientation": 270,
                "position": 90,
                "z": 0.4,
                "k": 0.2
            }
            actor_list.append(actor_dict)
            num_actors += 1

        print("num_actors: " + str(num_actors))
        num_actors -= 1
        while num_actors >= 0:
            actor_dict = actor_list[num_actors]
            _start_distance = actor_dict["_start_distance"]
            lane_width = self._reference_waypoint.lane_width
            location, _ = get_location_in_distance_from_wp(
                self._reference_waypoint, _start_distance)
            waypoint = self._wmap.get_waypoint(location)
            offset = actor_dict["offset"]
            position_yaw = waypoint.transform.rotation.yaw + offset['position']
            orientation_yaw = waypoint.transform.rotation.yaw + offset[
                'orientation']
            offset_location = carla.Location(
                offset['k'] * lane_width *
                math.cos(math.radians(position_yaw)), offset['k'] *
                lane_width * math.sin(math.radians(position_yaw)))
            location += offset_location
            location.z += offset['z']
            self.transform = carla.Transform(
                location, carla.Rotation(yaw=orientation_yaw))
            static = CarlaActorPool.request_new_actor('static.prop.container',
                                                      self.transform)
            static.set_simulate_physics(True)
            self.other_actors.append(static)
            print("initialized actor: " + str(num_actors))
            num_actors -= 1
예제 #19
0
    def _initialize_actors(self, config):
        """
        Custom initialization
        """

        # Get the waypoint right after the junction
        waypoint = generate_target_waypoint_in_route(self._reference_waypoint,
                                                     self._ego_route)

        # Move a certain distance to the front
        start_distance = 8
        waypoint = waypoint.next(start_distance)[0]

        # Get the last driving lane to the right
        waypoint, self._num_lane_changes = get_right_driving_lane(waypoint)
        # And for synchrony purposes, move to the front a bit
        added_dist = self._num_lane_changes

        while True:

            # Try to spawn the actor
            try:
                self._other_actor_transform = get_opponent_transform(
                    added_dist, waypoint, self._trigger_location)
                first_vehicle = CarlaActorPool.request_new_actor(
                    'vehicle.diamondback.century', self._other_actor_transform)
                first_vehicle.set_simulate_physics(enabled=False)
                break

            # Move the spawning point a bit and try again
            except RuntimeError as r:
                # In the case there is an object just move a little bit and retry
                print(" Base transform is blocking objects ",
                      self._other_actor_transform)
                added_dist += 0.5
                self._spawn_attempted += 1
                if self._spawn_attempted >= self._number_of_attempts:
                    raise r

        # Set the transform to -500 z after we are able to spawn it
        actor_transform = carla.Transform(
            carla.Location(self._other_actor_transform.location.x,
                           self._other_actor_transform.location.y,
                           self._other_actor_transform.location.z - 500),
            self._other_actor_transform.rotation)
        first_vehicle.set_transform(actor_transform)
        first_vehicle.set_simulate_physics(enabled=False)
        self.other_actors.append(first_vehicle)
예제 #20
0
    def _initialize_actors(self, config):
        """
        Default initialization of other actors.
        Override this method in child class to provide custom initialization.
        """
        for actor in config.other_actors:
            new_actor = CarlaActorPool.request_new_actor(actor.model,
                                                         actor.transform,
                                                         rolename=actor.rolename,
                                                         hero=False,
                                                         autopilot=actor.autopilot,
                                                         random_location=actor.random_location)
            if new_actor is None:
                raise Exception("Error: Unable to add actor {} at {}".format(actor.model, actor.transform))

            self.other_actors.append(new_actor)
예제 #21
0
 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 - 500),
         config.other_actors[0].transform.rotation)
     try:
         first_vehicle = CarlaActorPool.request_new_actor(
             config.other_actors[0].model, self._other_actor_transform)
     except RuntimeError as r:
         raise r
     first_vehicle.set_transform(first_vehicle_transform)
     self.other_actors.append(first_vehicle)
    def prepare_ego_car(self, start_transform):
        """
        Spawn or update all scenario actors according to
        a certain start position.
        """

        # If ego_vehicle already exists, just update location
        # Otherwise spawn ego vehicle
        if self.ego_vehicle is None:
            # TODO: the model is now hardcoded but that can change in a future.
            self.ego_vehicle = CarlaActorPool.request_new_actor(
                'vehicle.lincoln.mkz2017', start_transform, hero=True)
        else:
            self.ego_vehicle.set_transform(start_transform)

        # setup sensors
        if self.agent_instance is not None:
            self.setup_sensors(self.agent_instance.sensors(), self.ego_vehicle)
예제 #23
0
 def _initialize_actors(self, config):
     """
     Custom initialization
     """
     
     first_vehicle_waypoint, _ = get_waypoint_in_distance(self._reference_waypoint, self._first_vehicle_location)
     self._other_actor_transform = carla.Transform(
         carla.Location(first_vehicle_waypoint.transform.location.x,
                        first_vehicle_waypoint.transform.location.y,
                        first_vehicle_waypoint.transform.location.z + 1),
         first_vehicle_waypoint.transform.rotation)
     first_vehicle_transform = carla.Transform(
         carla.Location(self._other_actor_transform.location.x,
                        self._other_actor_transform.location.y,
                        self._other_actor_transform.location.z - 500),
         self._other_actor_transform.rotation)
     first_vehicle = CarlaActorPool.request_new_actor('vehicle.nissan.patrol', first_vehicle_transform)
     first_vehicle.set_simulate_physics(enabled=False)
     self.other_actors.append(first_vehicle)
예제 #24
0
    def _initialize_actors(self, config):

        # direction of lane, on which other_actor is driving before lane change
        if 'LEFT' in self._config.name.upper():
            self._direction = 'left'

        if 'RIGHT' in self._config.name.upper():
            self._direction = 'right'

        # add actors from xml file
        for actor in config.other_actors:
            vehicle = CarlaActorPool.request_new_actor(actor.model, actor.transform)
            self.other_actors.append(vehicle)
            vehicle.set_simulate_physics(enabled=False)

        # transform visible
        other_actor_transform = self.other_actors[0].get_transform()
        self._transform_visible = carla.Transform(
            carla.Location(other_actor_transform.location.x,
                           other_actor_transform.location.y,
                           other_actor_transform.location.z + 105),
            other_actor_transform.rotation)
예제 #25
0
 def _initialize_actors(self, config):
     """
     Custom initialization
     """
     _start_distance = 40
     lane_width = self._reference_waypoint.lane_width
     location, _ = get_location_in_distance_from_wp(
         self._reference_waypoint, _start_distance)
     waypoint = self._wmap.get_waypoint(location)
     offset = {"orientation": 270, "position": 90, "z": 0.4, "k": 0.2}
     position_yaw = waypoint.transform.rotation.yaw + offset['position']
     orientation_yaw = waypoint.transform.rotation.yaw + offset[
         'orientation']
     offset_location = carla.Location(
         offset['k'] * lane_width * math.cos(math.radians(position_yaw)),
         offset['k'] * lane_width * math.sin(math.radians(position_yaw)))
     location += offset_location
     location.z += offset['z']
     self.transform = carla.Transform(location,
                                      carla.Rotation(yaw=orientation_yaw))
     static = CarlaActorPool.request_new_actor('static.prop.container',
                                               self.transform)
     static.set_simulate_physics(True)
     self.other_actors.append(static)