def _calculate_base_transform(self, _start_distance, waypoint):

        lane_width = waypoint.lane_width

        # Patches false junctions
        if self._reference_waypoint.is_junction:
            stop_at_junction = False
        else:
            stop_at_junction = True

        location, _ = get_location_in_distance_from_wp(waypoint,
                                                       _start_distance,
                                                       stop_at_junction)
        waypoint = self._wmap.get_waypoint(location)
        offset = {"orientation": 270, "position": 90, "z": 0.6, "k": 1.0}
        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 = self._trigger_location.z + offset['z']
        return carla.Transform(
            location, carla.Rotation(yaw=orientation_yaw)), orientation_yaw
 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)
     self._create_construction_setup(waypoint.transform, lane_width)
    def _initialize_actors(self, config):
        """
        Custom initialization
        """
        if self._randomize:
            self._distance = random.randint(low=10, high=80, size=3)
            self._distance = sorted(self._distance)
        else:
            self._distance = [14, 48, 74]
        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 = CarlaDataProvider.request_new_actor(
            'static.prop.dirtdebris01', self.first_transform, 'prop')
        second_debris = CarlaDataProvider.request_new_actor(
            'static.prop.dirtdebris01', self.sec_transform, 'prop')
        third_debris = CarlaDataProvider.request_new_actor(
            'static.prop.dirtdebris01', self.third_transform, 'prop')

        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)
    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
    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)
    def _calculate_transform(self):
        if (self.direction == "left"):
            self.spawn_point = self.spawn_point.get_left_lane()
        else:
            self.spawn_point = self.spawn_point.get_right_lane()

        spawn_location = self.spawn_point.transform.location
        ahead_location, _ = get_location_in_distance_from_wp(
            self.trigger, self.start_dist, False)
        self.trigger = self.map.get_waypoint(ahead_location)

        # change_x = ahead_location.x - trigger_location.x
        # change_y = ahead_location.y - trigger_location.y
        actor_location = carla.Location(spawn_location.x, spawn_location.y,
                                        spawn_location.z)
        waypoint = self.map.get_waypoint(actor_location)
        print("cut in start location: " + str(waypoint))

        return waypoint.transform
예제 #7
0
    def _calculate_base_transform(self, _start_distance, waypoint):

        lane_width = waypoint.lane_width

        location, _ = get_location_in_distance_from_wp(waypoint,
                                                       _start_distance)
        waypoint = self._wmap.get_waypoint(location)
        if self._adversary_type:
            offset = {"orientation": 270, "position": 90, "z": 0.6, "k": -0.1}
        else:
            offset = {"orientation": 270, "position": 90, "z": 0.6, "k": -0.1}
        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 = self._trigger_location.z + offset['z']
        return carla.Transform(
            location, carla.Rotation(yaw=orientation_yaw)), orientation_yaw
 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 = CarlaDataProvider.request_new_actor('static.prop.container',
                                                  self.transform)
     static.set_simulate_physics(True)
     self.other_actors.append(static)
    def _calculate_transform(self):
        waypoint = self._get_sidewalk_waypoint()
        lane_width = waypoint.lane_width
        if self.trigger.is_junction:
            stop_at_junction = False
        else:
            stop_at_junction = True
        # print("self.start_dist when calculating: " + str(self.start_dist))
        location, _ = get_location_in_distance_from_wp(waypoint,
                                                       self.start_dist,
                                                       stop_at_junction)
        waypoint = self.map.get_waypoint(location)

        position_yaw = waypoint.transform.rotation.yaw + self.offset['position']
        orientation_yaw = waypoint.transform.rotation.yaw + self.offset[
            'orientation']
        offset_location = carla.Location(
            self.offset['k'] * lane_width *
            math.cos(math.radians(position_yaw)), self.offset['k'] *
            lane_width * math.sin(math.radians(position_yaw)))
        location += offset_location

        return carla.Transform(
            location, carla.Rotation(yaw=orientation_yaw)), orientation_yaw