Example #1
0
  def test_one_agent_at_goal_sequential(self):
    param_server = ParameterServer()
    # Model Definition
    dynamic_model = SingleTrackModel(param_server)
    behavior_model = BehaviorMotionPrimitives(dynamic_model, param_server)
    idx = behavior_model.add_motion_primitive(np.array([1, 0]))
    behavior_model.action_to_behavior(idx)
    execution_model = ExecutionModelInterpolate(param_server)


    # Agent Definition
    agent_2d_shape = CarLimousine()
    init_state = np.array([0, 0, 0, 0, 0])
    agent_params = param_server.addChild("agent1")
    goal_frame = Polygon2d([0, 0, 0],
                             [Point2d(-1,-1),
                              Point2d(-1,1),
                              Point2d(1,1),
                              Point2d(1,-1)])

    goal_polygon1 = goal_frame.translate(Point2d(10, 0))
    goal_polygon2 = goal_frame.translate(Point2d(20, 0))
    goal_polygon3 = goal_frame.translate(Point2d(30, 0))

    goal_def1 = GoalDefinitionStateLimits(goal_polygon1, [-0.08, 0.08])
    goal_def2 = GoalDefinitionStateLimits(goal_polygon2, [-0.08, 0.08])
    goal_def3 = GoalDefinitionStateLimits(goal_polygon3, [-0.08, 0.08])

    goal_definition = GoalDefinitionSequential([goal_def1,
                                                goal_def2,
                                                goal_def3])

    self.assertEqual(len(goal_definition.sequential_goals),3)
    agent = Agent(init_state,
                behavior_model,
                dynamic_model,
                execution_model,
                agent_2d_shape,
                agent_params,
                goal_definition,
                  None)

    world = World(param_server)
    world.add_agent(agent)
    evaluator = EvaluatorGoalReached(agent.id)
    world.add_evaluator("success", evaluator)

    # just drive with the single motion primitive should be successful 
    for _ in range(0,1000):
        world.step(0.2)
        info = world.evaluate()
        if info["success"]:
            break
    
    self.assertEqual(info["success"], True)
    self.assertAlmostEqual(agent.state[int(StateDefinition.X_POSITION)], 30, delta=0.5)
Example #2
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)
Example #3
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