Beispiel #1
0
    def __init__(self, world, ego_vehicles, config, randomize=False, debug_mode=False, criteria_enable=True,
                 timeout=80):
        """
        Setup all relevant parameters and create scenario
        """
        self._world = world
        self._map = CarlaDataProvider.get_map()
        self._target_vel = 5  # 6.9
        self._brake_value = 0.5
        self._ego_distance = 110
        self._traffic_light = None
        self._other_actor_transform = None
        self._blackboard_queue_name = 'SignalizedJunctionLeftTurn/actor_flow_queue'
        self._queue = py_trees.blackboard.Blackboard().set(self._blackboard_queue_name, Queue())
        self._initialized = True
        super(SignalizedJunctionLeftTurn, self).__init__("TurnLeftAtSignalizedJunction",
                                                         ego_vehicles,
                                                         config,
                                                         world,
                                                         debug_mode,
                                                         criteria_enable=criteria_enable)

        self._traffic_light = CarlaDataProvider.get_next_traffic_light(self.ego_vehicles[0], False)
        traffic_light_other = CarlaDataProvider.get_next_traffic_light(self.other_actors[0], False)
        if self._traffic_light is None or traffic_light_other is None:
            raise RuntimeError("No traffic light for the given location found")
        self._traffic_light.set_state(carla.TrafficLightState.Green)
        self._traffic_light.set_green_time(self.timeout)
        # other vehicle's traffic light
        traffic_light_other.set_state(carla.TrafficLightState.Green)
        traffic_light_other.set_green_time(self.timeout)
Beispiel #2
0
    def __init__(self,
                 world,
                 ego_vehicles,
                 config,
                 randomize=False,
                 debug_mode=False,
                 criteria_enable=True,
                 timeout=180):
        """
        Setup all relevant parameters and create scenario
        and instantiate scenario manager
        """

        self._other_actor_transform = None

        # Timeout of scenario in seconds
        self.timeout = timeout

        super(OppositeVehicleRunningRedLight,
              self).__init__("OppositeVehicleRunningRedLight",
                             ego_vehicles,
                             config,
                             world,
                             debug_mode,
                             criteria_enable=criteria_enable)

        self._traffic_light = CarlaDataProvider.get_next_traffic_light(
            self.ego_vehicles[0], False)

        if self._traffic_light is None:
            print(
                "No traffic light for the given location of the ego vehicle found"
            )
            sys.exit(-1)

        self._traffic_light.set_state(carla.TrafficLightState.Green)
        self._traffic_light.set_green_time(self.timeout)

        # other vehicle's traffic light
        traffic_light_other = CarlaDataProvider.get_next_traffic_light(
            self.other_actors[0], False)

        if traffic_light_other is None:
            print(
                "No traffic light for the given location of the other vehicle found"
            )
            sys.exit(-1)

        traffic_light_other.set_state(carla.TrafficLightState.Red)
        traffic_light_other.set_red_time(self.timeout)
Beispiel #3
0
    def __init__(
        self,
        world,
        ego_vehicles,
        config,
        randomize=False,
        debug_mode=False,
        criteria_enable=True,
        timeout=80,
    ):
        """
        Setup all relevant parameters and create scenario
        """
        self._target_vel = 6.9
        self._brake_value = 0.5
        self._ego_distance = 40
        self._traffic_light = None
        self._other_actor_transform = None
        self._other_actor_transform2 = None
        self._pedestrian_transform = None
        # Timeout of scenario in seconds
        self.timeout = timeout
        super(RightTurn, self).__init__(
            "RightTurn",
            ego_vehicles,
            config,
            world,
            debug_mode,
            criteria_enable=criteria_enable,
        )

        self._traffic_light = CarlaDataProvider.get_next_traffic_light(
            self.ego_vehicles[0], False)
        if self._traffic_light is None:
            print(
                "No traffic light for the given location of the ego vehicle found"
            )
            sys.exit(-1)
        self._traffic_light.set_state(carla.TrafficLightState.Red)
        self._traffic_light.set_red_time(self.timeout)
        # other vehicle's traffic light
        traffic_light_other = CarlaDataProvider.get_next_traffic_light(
            self.other_actors[0], False)
        if traffic_light_other is None:
            print(
                "No traffic light for the given location of the other vehicle found"
            )
            sys.exit(-1)
        traffic_light_other.set_state(carla.TrafficLightState.Green)
        traffic_light_other.set_green_time(self.timeout)
Beispiel #4
0
    def __init__(self,
                 world,
                 ego_vehicles,
                 config,
                 randomize=False,
                 debug_mode=False,
                 continuous=True,  # continuous traffic flow or single vehicle scenario

                 v=6,
                 criteria_enable=True,
                 timeout=80):
        """
        Setup all relevant parameters and create scenario
        """
        self._world = world
        self._map = CarlaDataProvider.get_map()
        self._target_vel = v
        self._brake_value = 0.5
        self._ego_distance = 110
        self._traffic_light = None
        self._other_actor_transform = None
        self._blackboard_queue_name = 'SignalizedJunctionLeftTurn/actor_flow_queue'
        self._queue = py_trees.blackboard.Blackboard().set(self._blackboard_queue_name, Queue())
        self._initialized = True
        
        super(VerificationScenario, self).__init__(name='VerificationScenario',
                                                   ego_vehicles=ego_vehicles,
                                                   config=config,
                                                   world=world,
                                                   debug_mode=debug_mode,
                                                   terminate_on_failure=True,
                                                   criteria_enable=criteria_enable,
                                                   )

        self._traffic_light = CarlaDataProvider.get_next_traffic_light(self.ego_vehicles[0], False)
        traffic_light_other = CarlaDataProvider.get_next_traffic_light(self.other_actors[0], False)
        if self._traffic_light is None or traffic_light_other is None:
            raise RuntimeError("No traffic light for the given location found")
        self._traffic_light.set_state(carla.TrafficLightState.Green)
        self._traffic_light.set_green_time(self.timeout)
        # other vehicle's traffic light
        traffic_light_other.set_state(carla.TrafficLightState.Green)
        traffic_light_other.set_green_time(self.timeout)

        # ================   additional class attributes   ================

        self.continuous_scenario = continuous
        # init params for traffic flow
        self._target_vel
    def update(self):
        master_scenario_command = self.blackboard.get(
            'master_scenario_command')
        if master_scenario_command and master_scenario_command == 'scenarios_stop_request':
            new_status = py_trees.common.Status.SUCCESS
            return new_status
        else:
            new_status = py_trees.common.Status.RUNNING

        # find a suitable target
        if not self.target_traffic_light:
            traffic_light = CarlaDataProvider.get_next_traffic_light(
                self.ego_vehicle, use_cached_location=False)
            if not traffic_light:
                # nothing else to do in this iteration...
                return new_status

            base_transform = traffic_light.get_transform()
            area_loc = carla.Location(
                base_transform.transform(
                    traffic_light.trigger_volume.location))
            distance_to_traffic_light = area_loc.distance(
                self.ego_vehicle.get_location())

            if self.debug:
                print("[{}] distance={}".format(traffic_light.id,
                                                distance_to_traffic_light))

            if distance_to_traffic_light < self.MAX_DISTANCE_TRAFFIC_LIGHT:
                self.target_traffic_light = traffic_light
                self.intervention = random.random(
                ) > self.RANDOM_VALUE_INTERVENTION

                if self.intervention:
                    if self.debug:
                        print(
                            "--- We are going to affect the following intersection"
                        )
                        loc = self.target_traffic_light.get_location()
                        CarlaDataProvider.get_world().debug.draw_point(
                            loc + carla.Location(z=1.0),
                            size=0.5,
                            color=carla.Color(255, 255, 0),
                            life_time=50000)
                    self.annotations = CarlaDataProvider.annotate_trafficlight_in_group(
                        self.target_traffic_light)
        else:
            if not self.reset_annotations:
                if self.intervention:
                    # the light has not been manipulated yet
                    choice = random.choice(self.INTERSECTION_CONFIGURATIONS)
                    self.reset_annotations = CarlaDataProvider.update_light_states(
                        self.target_traffic_light,
                        self.annotations,
                        choice,
                        freeze=True)

            else:
                # the traffic light has been manipulated...
                base_transform = self.target_traffic_light.get_transform()
                area_loc = carla.Location(
                    base_transform.transform(
                        self.target_traffic_light.trigger_volume.location))
                distance_to_traffic_light = area_loc.distance(
                    self.ego_vehicle.get_location())

                if self.debug:
                    print("++ distance={}".format(distance_to_traffic_light))

                if distance_to_traffic_light > self.MAX_DISTANCE_TRAFFIC_LIGHT:
                    if self.reset_annotations:
                        CarlaDataProvider.reset_lights(self.reset_annotations)
                        self.target_traffic_light = None
                        self.reset_annotations = None
                        self.annotations = None
                        self.intervention = False

        return new_status