Ejemplo n.º 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)
Ejemplo n.º 2
0
    def test_relevant_agents(self):

        params = ParameterServer()
        map = "bark/runtime/tests/data/city_highway_straight.xodr"
        params["EvaluatorRss"]["MapFilename"] = map

        map_interface = EvaluatorRSSTests.load_map(map)
        world = World(params)
        world.SetMap(map_interface)

        goal_polygon_1 = Polygon2d(
            [0, 0, 0],
            [Point2d(-1, -1),
             Point2d(-1, 1),
             Point2d(1, 1),
             Point2d(1, -1)])
        goal_polygon_1 = goal_polygon_1.Translate(Point2d(5.5, 120))

        goal_polygon_2 = Polygon2d(
            [0, 0, 0],
            [Point2d(-1, -1),
             Point2d(-1, 1),
             Point2d(1, 1),
             Point2d(1, -1)])
        goal_polygon_2 = goal_polygon_2.Translate(Point2d(1.8, 120))

        ego_state = np.array([0, 5.5, 10, np.pi / 2, 10])
        other_1_state = np.array([0, 1.8, -10, np.pi / 2, 15])
        other_2_state = np.array([0, 1.8, -120, np.pi / 2, 10])

        ego = TestAgent(ego_state, goal_polygon_1, map_interface, params)
        other_1 = TestAgent(other_1_state, goal_polygon_2, map_interface,
                            params)
        other_2 = TestAgent(other_2_state, goal_polygon_2, map_interface,
                            params)

        world.AddAgent(ego)
        world.AddAgent(other_1)
        world.AddAgent(other_2)

        viewer = MPViewer(params=params, use_world_bounds=True)
        viewer.drawWorld(world)
        viewer.show(block=False)

        evaluator_rss = EvaluatorRSS(ego.id, params)
        responses = evaluator_rss.PairwiseEvaluate(world)

        self.assertEqual(1, len(responses))
        self.assertTrue(responses[other_1.id])
        self.assertFalse(other_2.id in responses)
Ejemplo n.º 3
0
    def test_lateral_highway_unsafe(self):
        """
        Checking Lateral Responses (true means safe)
        """

        params = ParameterServer()
        map = "bark/runtime/tests/data/city_highway_straight.xodr"
        params["EvaluatorRss"]["MapFilename"] = map

        map_interface = EvaluatorRSSTests.load_map(map)
        world = World(params)
        world.SetMap(map_interface)

        goal_polygon_1 = Polygon2d(
            [0, 0, 0],
            [Point2d(-1, -1),
             Point2d(-1, 1),
             Point2d(1, 1),
             Point2d(1, -1)])
        goal_polygon_1 = goal_polygon_1.Translate(Point2d(5.5, 120))

        goal_polygon_2 = Polygon2d(
            [0, 0, 0],
            [Point2d(-1, -1),
             Point2d(-1, 1),
             Point2d(1, 1),
             Point2d(1, -1)])
        goal_polygon_2 = goal_polygon_2.Translate(Point2d(1.8, 120))

        # Hard coded
        ego_state = np.array([0, 5.0, 10, np.pi / 2, 10])  # straight north
        other_state = np.array([0, 3.1, 0, np.pi / 2, 10])  # straight north

        ego = TestAgent(ego_state, goal_polygon_1, map_interface, params)
        other = TestAgent(other_state, goal_polygon_2, map_interface, params)

        world.AddAgent(ego)
        world.AddAgent(other)
        world.UpdateAgentRTree()

        viewer = MPViewer(params=params, use_world_bounds=True)
        viewer.drawWorld(world)
        viewer.show(block=False)

        evaluator_rss = EvaluatorRSS(ego.id, params)

        self.assertEqual(
            False,
            evaluator_rss.PairwiseDirectionalEvaluate(world)[other.id][1])
Ejemplo n.º 4
0
    def test_longitude_highway_unsafe(self):
        """
        Checking Longitudinal Responses (true means safe)
        """

        params = ParameterServer()
        map = "bark/runtime/tests/data/city_highway_straight.xodr"
        params["EvaluatorRss"]["MapFilename"] = map

        map_interface = EvaluatorRSSTests.load_map(map)
        world = World(params)
        world.SetMap(map_interface)

        goal_polygon = Polygon2d(
            [0, 0, 0],
            [Point2d(-1, -1),
             Point2d(-1, 1),
             Point2d(1, 1),
             Point2d(1, -1)])
        goal_polygon = goal_polygon.Translate(Point2d(1.8, 120))

        # The safety distance seems more conservative than in the paper
        # Hard coded
        ego_state = np.array([0, 1.8, -60.0, np.pi / 2, 10])
        other_state = np.array([0, 1.8, -68.0, np.pi / 2, 10])

        ego = TestAgent(ego_state, goal_polygon, map_interface, params)
        other = TestAgent(other_state, goal_polygon, map_interface, params)

        world.AddAgent(ego)
        world.AddAgent(other)
        world.UpdateAgentRTree()

        viewer = MPViewer(params=params, use_world_bounds=True)
        viewer.drawWorld(world)
        viewer.show(block=False)

        evaluator_rss = EvaluatorRSS(ego.id, params)

        pw_directional_evaluation_return = evaluator_rss.PairwiseDirectionalEvaluate(
            world)
        self.assertEqual(False, pw_directional_evaluation_return[other.id][0])
Ejemplo n.º 5
0
    def test_lateral_merging_safe(self):
        """
        Checking Lateral Responses (true means safe)
        """

        params = ParameterServer()
        map = "bark/runtime/tests/data/DR_DEU_Merging_MT_v01_centered.xodr"
        params["EvaluatorRss"]["MapFilename"] = map

        map_interface = EvaluatorRSSTests.load_map(map)
        world = World(params)
        world.SetMap(map_interface)

        goal_polygon = Polygon2d(
            [0, 0, 0],
            [Point2d(-1, -1),
             Point2d(-1, 1),
             Point2d(1, 1),
             Point2d(1, -1)])
        goal_polygon = goal_polygon.Translate(Point2d(-15.4, 108.6))

        # Hard coded
        ego_state = np.array([0, 68.1, 108, -np.pi, 5])
        other_state = np.array([0, 64.1, 105, -np.pi, 5])

        ego = TestAgent(ego_state, goal_polygon, map_interface, params)
        other = TestAgent(other_state, goal_polygon, map_interface, params)

        world.AddAgent(ego)
        world.AddAgent(other)
        world.UpdateAgentRTree()

        viewer = MPViewer(params=params, use_world_bounds=True)
        viewer.drawWorld(world)
        viewer.show(block=False)

        evaluator_rss = EvaluatorRSS(ego.id, params)
        world.AddEvaluator("rss", evaluator_rss)

        pw_directional_evaluation_return = evaluator_rss.PairwiseDirectionalEvaluate(
            world)
        self.assertEqual(True, pw_directional_evaluation_return[other.id][1])
Ejemplo n.º 6
0
    def test_evaluator_drivable_area(self):
        # World Definition
        params = ParameterServer()
        world = World(params)

        # Model Definitions
        behavior_model = BehaviorConstantAcceleration(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)