Example #1
0
    def load_scenario(self,
                      scenario,
                      agent=None,
                      agent_leaderboard_parsing=False):
        """
        Load a new scenario
        """
        if agent_leaderboard_parsing:
            from leaderboard.autoagents.agent_wrapper import AgentWrapper

        self._reset()
        self._agent = AgentWrapper(agent) if agent else None
        if self._agent is not None:
            self._sync_mode = True
        self.scenario_class = scenario
        self.scenario = scenario.scenario
        self.scenario_tree = self.scenario.scenario_tree
        self.ego_vehicles = scenario.ego_vehicles
        self.other_actors = scenario.other_actors

        # To print the scenario tree uncomment the next line
        # py_trees.display.render_dot_tree(self.scenario_tree)

        if self._agent is not None:
            self._agent.setup_sensors(self.ego_vehicles[0], self._debug_mode)
Example #2
0
    def load_scenario(self, scenario, agent=None):
        """
        Load a new scenario
        """
        self._reset()
        self._agent = AgentWrapper(agent) if agent else None
        self.scenario_class = scenario
        self.scenario = scenario.scenario
        self.scenario_tree = self.scenario.scenario_tree
        self.ego_vehicles = scenario.ego_vehicles
        self.other_actors = scenario.other_actors

        CarlaDataProvider.register_actors(self.ego_vehicles)
        CarlaDataProvider.register_actors(self.other_actors)
        # To print the scenario tree uncomment the next line
        # py_trees.display.render_dot_tree(self.scenario_tree)

        if self._agent is not None:
            self._agent.setup_sensors(self.ego_vehicles[0], self._debug_mode)
Example #3
0
        # generate ego vehicle
        blueprint_library = world.get_blueprint_library()
        bp = random.choice(blueprint_library.filter('vehicle'))

        if bp.has_attribute('color'):
            color = random.choice(bp.get_attribute('color').recommended_values)
            bp.set_attribute('color', color)
        transform = random.choice(world.get_map().get_spawn_points())
        vehicle = world.spawn_actor(bp, transform)
        actor_list.append(vehicle)

        # set agent
        # a_agent = HumanAgent(path_to_conf_file="")
        a_agent = ImitationAgent(vehicle, city_name, True)
        work_agent = AgentWrapper(a_agent)
        work_agent.setup_sensors(vehicle)

        hic = HumanInterface()

        clock = pygame.time.Clock()
        while True:
            # game loop
            world = CarlaDataProvider.get_world()
            if world:
                v = vehicle.get_velocity()
                a_agent.current_speed = math.sqrt(v.x**2 + v.y**2 + v.z**2)
                print('speed:', a_agent.current_speed)
                snapshot = world.get_snapshot()
                if snapshot:
                    timestamp = snapshot.timestamp