Пример #1
0
    def test_lane_change(self):
        # World Definition
        params = ParameterServer()
        world = World(params)

        # Model Definitions
        behavior_model = BehaviorMobil(params)
        execution_model = ExecutionModelInterpolate(params)
        dynamic_model = SingleTrackModel(params)

        behavior_model2 = BehaviorIDMLaneTracking(params)
        execution_model2 = ExecutionModelInterpolate(params)
        dynamic_model2 = SingleTrackModel(params)

        # Map Definition
        map_interface = MapInterface()
        xodr_map = MakeXodrMapOneRoadTwoLanes()
        map_interface.SetOpenDriveMap(xodr_map)
        world.SetMap(map_interface)

        #agent_2d_shape = CarLimousine()
        agent_2d_shape = CarRectangle()
        init_state = np.array([0, 3, -1.75, 0, 5])
        agent_params = params.AddChild("agent1")
        goal_polygon = Polygon2d(
            [1, 1, 0],
            [Point2d(0, 0),
             Point2d(0, 2),
             Point2d(2, 2),
             Point2d(2, 0)])
        goal_polygon = goal_polygon.Translate(Point2d(50, -2))

        agent = Agent(init_state, behavior_model, dynamic_model,
                      execution_model, agent_2d_shape, agent_params,
                      GoalDefinitionPolygon(goal_polygon), map_interface)
        world.AddAgent(agent)

        init_state2 = np.array([0, 15, -1.75, 0, 2])
        agent2 = Agent(init_state2, behavior_model2, dynamic_model2,
                       execution_model2, agent_2d_shape, agent_params,
                       GoalDefinitionPolygon(goal_polygon), map_interface)
        world.AddAgent(agent2)

        # viewer
        viewer = MPViewer(params=params, use_world_bounds=True)

        # World Simulation
        sim_step_time = params["simulation"]["step_time",
                                             "Step-time in simulation", 0.05]
        sim_real_time_factor = params["simulation"][
            "real_time_factor", "execution in real-time or faster", 100]

        # Draw map
        for _ in range(0, 10):
            viewer.clear()
            world.Step(sim_step_time)
            viewer.drawWorld(world)
            viewer.show(block=False)
            time.sleep(sim_step_time / sim_real_time_factor)
Пример #2
0
  def create_single_scenario(self):
    scenario = Scenario(map_file_name=self._map_file_name,
                        json_params=self._params.convert_to_dict())
    world = scenario.get_world_state()
    agent_list = []
    # OTHER AGENTS
    for idx, source in enumerate(self._others_source):
      connecting_center_line, s_start, s_end, _, lane_id_end = \
        self.center_line_between_source_and_sink(world.map,
                                                 source,
                                                 self._others_sink[idx])
       # TODO(@bernhard): orient goal polygon along road
      goal_polygon = Polygon2d([0, 0, 0],
                               [Point2d(-1.5,0),
                                Point2d(-1.5,8),
                                Point2d(1.5,8),
                                Point2d(1.5,0)])
      goal_polygon = goal_polygon.translate(Point2d(self._others_sink[idx][0],
                                                    self._others_sink[idx][1]))
      goal_definition = GoalDefinitionPolygon(goal_polygon)
      agent_list.extend(
        self.place_agents_along_linestring(world,
                                           connecting_center_line,
                                           s_start,
                                           s_end,
                                           self._agent_params,
                                           goal_definition))

    description=self._params.convert_to_dict()
    description["ScenarioGenerator"] = "UniformVehicleDistribution"
    scenario._agent_list = agent_list

    # EGO AGENT
    num_agents = len(scenario._agent_list)
    # take agent in the middle of list 
    ego_agent = scenario._agent_list[math.floor(num_agents/4)]
    
    # TODO(@bernhard): orient goal polygon along road
    goal_polygon = Polygon2d([0, 0, 0],
                             [Point2d(-1.5,0),
                              Point2d(-1.5,8),
                              Point2d(1.5,8),
                              Point2d(1.5,0)])
    goal_polygon = goal_polygon.translate(Point2d(self._ego_goal[0],
                                                  self._ego_goal[1]))
    ego_agent.goal_definition = GoalDefinitionPolygon(goal_polygon)
    # only one agent is ego in the middle of all other agents
    scenario._eval_agent_ids = [ego_agent.id]
    return scenario
Пример #3
0
    def test_one_agent_at_goal_polygon(self):
        param_server = ParameterServer()
        # Model Definition
        behavior_model = BehaviorConstantVelocity(param_server)
        execution_model = ExecutionModelInterpolate(param_server)
        dynamic_model = SingleTrackModel(param_server)

        # Agent Definition
        agent_2d_shape = CarLimousine()
        init_state = np.array(
            [0, -191.789, -50.1725, 3.14 * 3.0 / 4.0, 150 / 3.6])
        agent_params = param_server.AddChild("agent1")
        goal_polygon = Polygon2d(
            [0, 0, 0],
            [Point2d(-4, -4),
             Point2d(-4, 4),
             Point2d(4, 4),
             Point2d(4, -4)])
        goal_polygon = goal_polygon.Translate(Point2d(-191.789, -50.1725))

        agent = Agent(init_state, behavior_model, dynamic_model,
                      execution_model, agent_2d_shape, agent_params,
                      GoalDefinitionPolygon(goal_polygon), None)

        world = World(param_server)
        world.AddAgent(agent)
        evaluator = EvaluatorGoalReached(agent.id)
        world.AddEvaluator("success", evaluator)

        info = world.Evaluate()
        self.assertEqual(info["success"], True)
Пример #4
0
    def create_single_scenario(self):
        scenario = Scenario(map_file_name=self._map_file_name,
                            json_params=self._params.convert_to_dict())
        world = scenario.get_world_state()
        agent_list = []
        scenario._agent_list = []
        for agent_json_ in self._local_params["Agents"]:
            agent_json = agent_json_["VehicleModel"].copy()
            agent_json["map_interface"] = world.map
            goal_polygon = Polygon2d([0, 0, 0],
                                     np.array(
                                         agent_json["goal"]["polygon_points"]))
            goal_polygon = goal_polygon.translate(
                Point2d(agent_json["goal"]["center_pose"][0],
                        agent_json["goal"]["center_pose"][1]))

            agent_json["goal_definition"] = GoalDefinitionPolygon(goal_polygon)

            agent_state = np.array(agent_json["state"])
            if len(np.shape(agent_state)) > 1:
                agent_state = np.random.uniform(low=agent_state[:, 0],
                                                high=agent_state[:, 1])
            agent_json["state"] = agent_state.tolist()
            agent = self._json_converter.agent_from_json(
                agent_json, param_server=self._local_params)
            agent.set_agent_id(agent_json["id"])
            scenario._agent_list.append(agent)
        scenario._eval_agent_ids = [
            self._local_params["EgoAgentId", "ID of the ego-agent", 0]
        ]
        return scenario
Пример #5
0
    def _build_sequential_goal_definition(self):
        goal_list = []
        for goal_pose in self.goal_frame_poses:
            goal_polygon = Polygon2d(self.goal_frame_center,
                                     np.array(self.goal_frame_points))
            goal_polygon = goal_polygon.Transform(goal_pose)
            goal_definition = GoalDefinitionPolygon(goal_polygon)
            goal_list.append(goal_definition)

        return GoalDefinitionSequential(goal_list)
Пример #6
0
def goal_definition_from_track(track, end):
    states = list(dict_utils.get_item_iterator(track.motion_states))
    motion_state = states[-1][1]
    bark_state = bark_state_from_motion_state(motion_state)
    goal_polygon = Polygon2d(
        np.array([0.0, 0.0, 0.0]),
        [Point2d(-1.5, 0),
         Point2d(-1.5, 8),
         Point2d(1.5, 8),
         Point2d(1.5, 0)])
    goal_polygon = goal_polygon.Translate(
        Point2d(bark_state[0, int(StateDefinition.X_POSITION)],
                bark_state[0, int(StateDefinition.Y_POSITION)]))
    goal_definition = GoalDefinitionPolygon(goal_polygon)
    return goal_definition
Пример #7
0
    def create_single_scenario(self):
        scenario = Scenario(map_file_name=self._map_file_name,
                            json_params=self._params.ConvertToDict())
        world = scenario.get_world_state()
        agent_list = []
        scenario._agent_list = []
        for agent_json_ in self._local_params["Agents"]:
            agent_json = agent_json_["VehicleModel"].copy()
            agent_json["map_interface"] = world.map
            goal_polygon = Polygon2d([0, 0, 0],
                                     np.array(
                                         agent_json["goal"]["polygon_points"]))
            goal_polygon = goal_polygon.Translate(
                Point2d(agent_json["goal"]["center_pose"][0],
                        agent_json["goal"]["center_pose"][1]))

            sequential_goals = []
            goal = GoalDefinitionPolygon(goal_polygon)
            if "goal_type" in agent_json["goal"]:
                goal_type = agent_json["goal"]["goal_type"]
                if goal_type == "GoalDefinitionStateLimits":
                    goal = GoalDefinitionStateLimits(goal_polygon,
                                                     (1.49, 1.65))

            # state_limit_goal = GoalDefinitionStateLimits(goal_polygon, (1.49, 1.65))
            for _ in range(self._local_params["goal"]["num_reached", "num",
                                                      5]):
                sequential_goals.append(goal)
            sequential_goal = GoalDefinitionSequential(sequential_goals)
            agent_json["goal_definition"] = sequential_goal

            agent_state = np.array(agent_json["state"])
            if len(np.shape(agent_state)) > 1:
                agent_state = np.random.uniform(low=agent_state[:, 0],
                                                high=agent_state[:, 1])
            agent_json["state"] = agent_state.tolist()
            agent = self._json_converter.agent_from_json(
                agent_json, param_server=self._params)
            agent.SetAgentId(agent_json["id"])
            scenario._agent_list.append(agent)

        # TODO(@hart): this could be mult. agents
        scenario._eval_agent_ids = self._local_params[
            "controlled_ids", "IDs of agents to be controlled. ", [0]]
        return scenario
Пример #8
0
world.set_map(map_interface)

# Agent Definition
agent_2d_shape = CarLimousine()
init_state = np.array([0, -11, -8, 3.14 * 3.0 / 4.0, 50 / 3.6])
goal_polygon = Polygon2d(
    [0, 0, 0],
    [Point2d(-1, -1),
     Point2d(-1, 1),
     Point2d(1, 1),
     Point2d(1, -1)])
goal_polygon = goal_polygon.translate(Point2d(-63, -61))
agent_params = param_server.addChild("agent1")
agent1 = Agent(init_state, behavior_model, dynamic_model,
               execution_model, agent_2d_shape, agent_params,
               GoalDefinitionPolygon(goal_polygon), map_interface)
world.add_agent(agent1)

agent_2d_shape2 = CarLimousine()
init_state2 = np.array([0, -11, -8, 3.14 * 3.0 / 4.0, 5.2])
agent_params2 = param_server.addChild("agent2")
agent2 = Agent(init_state2, behavior_model2, dynamic_model2, execution_model2,
               agent_2d_shape2, agent_params2,
               GoalDefinitionPolygon(goal_polygon), map_interface)
world.add_agent(agent2)

# viewer
"""
viewer = Panda3dViewer(params=param_server,
                      x_range=[-200, 200],
                      y_range=[-200, 200],)
Пример #9
0
    def test_evaluator_drivable_area(self):
        # World Definition
        params = ParameterServer()
        world = World(params)

        # Model Definitions
        behavior_model = BehaviorConstantVelocity(params)
        execution_model = ExecutionModelInterpolate(params)
        dynamic_model = SingleTrackModel(params)

        # Map Definition
        map_interface = MapInterface()
        xodr_map = MakeXodrMapOneRoadTwoLanes()
        map_interface.SetOpenDriveMap(xodr_map)
        world.SetMap(map_interface)
        #open_drive_map = world.map.GetOpenDriveMap()

        #agent_2d_shape = CarLimousine()
        agent_2d_shape = Polygon2d(
            [1.25, 1, 0],
            [Point2d(-1, -1),
             Point2d(-1, 1),
             Point2d(3, 1),
             Point2d(3, -1)])
        init_state = np.array([0, 3, -1.75, 0, 5])
        agent_params = params.AddChild("agent1")
        goal_polygon = Polygon2d(
            [1, 1, 0],
            [Point2d(0, 0),
             Point2d(0, 2),
             Point2d(2, 2),
             Point2d(2, 0)])
        goal_polygon = goal_polygon.Translate(Point2d(50, -2))

        agent = Agent(
            init_state,
            behavior_model,
            dynamic_model,
            execution_model,
            agent_2d_shape,
            agent_params,
            GoalDefinitionPolygon(goal_polygon),  # goal_lane_id
            map_interface)
        world.AddAgent(agent)

        evaluator = EvaluatorDrivableArea()
        world.AddEvaluator("drivable_area", evaluator)

        info = world.Evaluate()
        self.assertFalse(info["drivable_area"])

        viewer = MPViewer(params=params, use_world_bounds=True)

        # Draw map
        viewer.drawGoalDefinition(goal_polygon,
                                  color=(1, 0, 0),
                                  alpha=0.5,
                                  facecolor=(1, 0, 0))
        viewer.drawWorld(world)
        viewer.drawRoadCorridor(agent.road_corridor)
        viewer.show(block=False)
    def create_single_scenario(self):
        scenario = Scenario(map_file_name=self._map_file_name,
                            json_params=self._params.ConvertToDict())
        world = scenario.get_world_state()
        agent_list = []
        # OTHER AGENTS
        for idx, source in enumerate(self._others_source):
            connecting_center_line, s_start, s_end = \
              self.center_line_between_source_and_sink(world.map,
                                                       source,
                                                       self._others_sink[idx])
            goal_polygon = Polygon2d([0, 0, 0], [
                Point2d(-1.5, 0),
                Point2d(-1.5, 8),
                Point2d(1.5, 8),
                Point2d(1.5, 0)
            ])
            goal_polygon = goal_polygon.Translate(
                Point2d(self._others_sink[idx][0], self._others_sink[idx][1]))
            goal_definition = GoalDefinitionPolygon(goal_polygon)
            agent_list.extend(
                self.place_agents_along_linestring(world,
                                                   connecting_center_line,
                                                   s_start, s_end,
                                                   self._agent_params,
                                                   goal_definition))

        description = self._params.ConvertToDict()
        description["ScenarioGenerator"] = "UniformVehicleDistribution"

        # EGO AGENT
        ego_agent = None
        if len(self._ego_route) == 0:
            # take agent in the middle of list
            num_agents = len(agent_list)
            ego_agent = agent_list[math.floor(num_agents / 4)]
        else:
            connecting_center_line, s_start, s_end  = \
            self.center_line_between_source_and_sink(world.map,
                                                     self._ego_route[0],
                                                     self._ego_route[1])

            sego = self.sample_srange_uniform([s_start, s_end])
            xy_point = GetPointAtS(connecting_center_line, sego)
            angle = GetTangentAngleAtS(connecting_center_line, sego)
            velocity = self.sample_velocity_uniform(self._ego_velocity_range)
            agent_state = np.array(
                [0, xy_point.x(),
                 xy_point.y(), angle, velocity])

            agent_params = self._agent_params.copy()
            agent_params["state"] = agent_state
            # goal for driving corridor generation
            goal_polygon = Polygon2d([0, 0, 0], [
                Point2d(-1.5, 0),
                Point2d(-1.5, 8),
                Point2d(1.5, 8),
                Point2d(1.5, 0)
            ])
            goal_polygon = goal_polygon.Translate(
                Point2d(self._ego_route[1][0], self._ego_route[1][1]))
            goal_definition = GoalDefinitionPolygon(goal_polygon)
            agent_params["goal_definition"] = goal_definition
            agent_params["map_interface"] = world.map

            converter = ModelJsonConversion()
            ego_agent = converter.agent_from_json(agent_params,
                                                  self._params["Agent"])
            # TODO(@bernhard): ensure that ego agent not collides with others

        agent_list.append(ego_agent)

        # EGO Agent Goal Definition
        if len(self._ego_goal_start) == 0:
            if len(self._ego_route) == 0:
                # ego agent is one of the random agents, so the goal definition is
                # already set
                pass
            else:
                goal_polygon = Polygon2d([0, 0, 0], [
                    Point2d(-1.5, 0),
                    Point2d(-1.5, 8),
                    Point2d(1.5, 8),
                    Point2d(1.5, 0)
                ])
                goal_polygon = goal_polygon.Translate(
                    Point2d(self._ego_goal_end[0], self._ego_goal_end[1]))
                ego_agent.goal_definition = GoalDefinitionPolygon(goal_polygon)
        else:
            connecting_center_line, s_start, s_end = \
            self.center_line_between_source_and_sink(world.map,
                                                     self._ego_goal_start,
                                                     self._ego_goal_end)

            goal_center_line = GetLineFromSInterval(connecting_center_line,
                                                    s_start, s_end)

            # build polygon representing state limits
            lims = self._ego_goal_state_limits
            goal_limits_left = goal_center_line.Translate(
                Point2d(-lims[0], -lims[1]))
            goal_limits_right = goal_center_line.Translate(
                Point2d(lims[0], lims[1]))
            goal_limits_right.Reverse()
            goal_limits_left.AppendLinestring(goal_limits_right)
            polygon = Polygon2d([0, 0, 0], goal_limits_left)

            ego_agent.goal_definition = GoalDefinitionStateLimits(
                polygon, (1.57 - 0.08, 1.57 + 0.08))

        # only one agent is ego in the middle of all other agents
        scenario._agent_list = agent_list
        scenario._eval_agent_ids = [ego_agent.id]
        return scenario
Пример #11
0
goal_polygon = Polygon2d(
    [0, 0, 0],
    [Point2d(-1, -1),
     Point2d(-1, 1),
     Point2d(1, 1),
     Point2d(1, -1)])
goal_polygon = goal_polygon.Translate(Point2d(-191.789, -50.1725))

agent = Agent(
    init_state,
    behavior_model,
    dynamic_model,
    execution_model,
    agent_2d_shape,
    agent_params,
    GoalDefinitionPolygon(goal_polygon),  # goal_lane_id
    map_interface)
world.AddAgent(agent)

# viewer
viewer = MPViewer(params=param_server, use_world_bounds=True)

# World Simulation
sim_step_time = param_server["simulation"]["step_time",
                                           "Step-time in simulation", 0.05]
sim_real_time_factor = param_server["simulation"][
    "real_time_factor", "execution in real-time or faster", 100]

for _ in range(0, 10):
    viewer.clear()
    world.Step(sim_step_time)