Exemplo n.º 1
0
    def test_parameters(self):
        # initialize Params
        p = ParameterServer()  # TODO: this has to be the ParameterServer

        # set new parameter
        self.assertTrue(p["LetsTest"]["hierarchy", "bla", True])

        # check whether right value is recovered
        tester = p["Car"]["Length", "Car Length", 6]
        tester2 = p["Car"]["Length", "Car Length", 8]
        self.assertEqual(tester, 6)
        self.assertEqual(
            tester2,
            6)  # value should not change, since key already exists in dict

        # check whether access without description and default value is possible
        self.assertEqual(p["Car"]["Length"], 6)

        # check whether setting values works
        p["Age"] = 24
        self.assertEqual(p["Age"], 24)
        p["Localization"]["Number of Particles"] = 2000
        self.assertEqual(p["Localization"]["Number of Particles"], 2000)

        # C++ Test in /modules/commons/Params/params_test.h
        # write in parameters in C++ and check whether they can be accessed in python afterwards
        #ParamsTest(p)
        #self.assertEqual(p["param_cpp"], 16.5)

        # add child in python
        child = p.AddChild("ch")
        self.assertTrue(child["ChildTest"]["hierarchy", "bla", True])

        # write parameters to json file
        p.save("written_a_param_test.json")
Exemplo n.º 2
0
  def test_configurable_scenario_generation_default_params(self):
    params = ParameterServer()
    scenario_generation = ConfigurableScenarioGeneration(num_scenarios=2,params=params)
    scenario_generation.dump_scenario_list("test.scenario")

    scenario_loader = ScenarioGeneration()
    scenario_loader.load_scenario_list("test.scenario")

    self.assertEqual(len(scenario_loader._scenario_list), 2)
    self.assertEqual(len(scenario_loader._scenario_list[0]._agent_list), len(scenario_generation._scenario_list[0]._agent_list))

    scenario = scenario_loader.get_scenario(idx=0)

    params.save("default_params.json")
Exemplo n.º 3
0
 def test_write_params_agent(self):
     params = ParameterServer()
     behavior = BehaviorConstantVelocity(params)
     execution = ExecutionModelInterpolate(params)
     dynamic = SingleTrackModel(params)
     shape = Polygon2d([1.25, 1, 0], [
         Point2d(0, 0),
         Point2d(0, 2),
         Point2d(4, 2),
         Point2d(4, 0),
         Point2d(0, 0)
     ])
     init_state = np.zeros(4)
     agent = Agent(init_state, behavior, dynamic, execution, shape,
                   params.AddChild("agent"))
     params.save("written_agents_param_test.json")
Exemplo n.º 4
0
    def test_motion_primitives_concat_state(self):
        params = ParameterServer(
            filename="modules/runtime/tests/data/highway_merging.json")
        scenario_generation = UniformVehicleDistribution(num_scenarios=3,
                                                         random_seed=0,
                                                         params=params)
        state_observer = StateConcatenation(params=params)
        action_wrapper = MotionPrimitives(params=params)
        evaluator = GoalReached(params=params)
        viewer = MPViewer(params=params,
                          x_range=[-30, 30],
                          y_range=[-20, 40],
                          follow_agent_id=True)  #use_world_bounds=True) #

        runtimerl = RuntimeRL(action_wrapper=action_wrapper,
                              nn_observer=state_observer,
                              evaluator=evaluator,
                              step_time=0.05,
                              viewer=viewer,
                              scenario_generator=scenario_generation)

        for _ in range(0, 5):  # run 5 scenarios in a row, repeating after 3
            nn_state = runtimerl.reset()
            i = 0
            actionsteps = []
            for _ in range(0, 1000):  # run each scenario for 1000 steps
                actionstep = action_wrapper.action_space.sample()
                next_nn_state, reward, done, info = runtimerl.step(actionstep)
                actionsteps.append(actionstep)
                i += 1
                runtimerl.render()
                if info["success"] or done:
                    print("Finish in ", i)
                    print("Actions taken:", actionsteps)
                    print("State: {} \n Reward: {} \n Done {}, Info: {} \n \
                         =================================================".
                          format(next_nn_state, reward, done, info))
                    break

        params.save(filename="highway_merging_written.json")
Exemplo n.º 5
0
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],)
"""
viewer = PygameViewer(params=param_server,
                      x_range=[-200, 200],
                      y_range=[-200, 200])

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

for _ in range(0, 30):
    world.step(sim_step_time)
    viewer.drawWorld(world)
    viewer.show(block=False)
    time.sleep(sim_step_time / sim_real_time_factor)

param_server.save(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "params",
                 "od8_const_vel_one_agent_written.json"))
Exemplo n.º 6
0
    agent_2d_shape,
    agent_params,
    GoalDefinition(goal_polygon),  # goal_lane_id
    map_interface)
world.add_agent(agent)

# viewer

viewer = PygameViewer(params=param_server,
                      x_range=[-50, 50],
                      y_range=[-50, 50],
                      follow_agent_id=agent.id,
                      screen_dims=[500, 500])

#viewer = MPViewer(params=param_server)

# 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, 100):
    viewer.clear()
    world.step(sim_step_time)
    viewer.drawWorld(world)
    viewer.show(block=False)
    time.sleep(sim_step_time / sim_real_time_factor)

param_server.save("examples/params/od8_const_vel_one_agent_written.json")
    def test_configurable_scenario_generation_sample_behavior_types(self):
        sink_source_dict = [{
            "SourceSink": [[5111.626, 5006.8305], [5110.789, 5193.1725]],
            "Description":
            "left_lane",
            "ConfigAgentStatesGeometries": {
                "Type": "UniformVehicleDistribution",
                "LanePositions": [0]
            },
            "ConfigBehaviorModels": {
                "Type": "FixedBehaviorType",
                "ModelType": "BehaviorIDMClassic",
                "ModelParams": {
                    "BehaviorIDMClassic::MaxVelocity": 60.0
                }
            },
            "ConfigExecutionModels": {
                "Type": "FixedExecutionType"
            },
            "ConfigDynamicModels": {
                "Type": "FixedDynamicType"
            },
            "ConfigGoalDefinitions": {
                "Type": "FixedGoalTypes"
            },
            "ConfigControlledAgents": {
                "Type": "NoneControlled"
            },
            "AgentParams": {}
        }, {
            "SourceSink": [[5111.626, 5006.8305], [5110.789, 5193.1725]],
            "Description":
            "right_lane",
            "ConfigAgentStatesGeometries": {
                "Type": "UniformVehicleDistribution",
                "LanePositions": [1]
            },
            "ConfigBehaviorModels": {
                "Type": "SampleBehaviorType"
            },
            "ConfigExecutionModels": {
                "Type": "FixedExecutionType"
            },
            "ConfigDynamicModels": {
                "Type": "FixedDynamicType"
            },
            "ConfigGoalDefinitions": {
                "Type": "FixedGoalTypes"
            },
            "ConfigControlledAgents": {
                "Type": "RandomSingleAgent"
            },
            "AgentParams": {}
        }]
        params = ParameterServer()
        params["Scenario"]["Generation"]["ConfigurableScenarioGeneration"][
            "SinksSources"] = sink_source_dict
        scenario_generation = ConfigurableScenarioGeneration(num_scenarios=2,
                                                             params=params)
        scenario_generation.dump_scenario_list("test.scenario")

        params.save("default_params_behavior_type_sampling.json")
Exemplo n.º 8
0
                                                 params=param_server)

viewer = MPViewer(params=param_server,
                  x_range=[-16, 16],
                  y_range=[-2, 30],
                  follow_agent_id=True)
sim_step_time = param_server["simulation"]["step_time",
                                           "Step-time used in simulation", 0.2]
sim_real_time_factor = param_server["simulation"][
    "real_time_factor", "execution in real-time or faster", 1]
scenario, idx = scenario_generation.get_next_scenario()

world_state = scenario.get_world_state()
world_state.agents[scenario._eval_agent_ids[
    0]].behavior_model = BehaviorUCTSingleAgent(param_server)
param_server.save("examples/params/mcts_params_written.json")

# world_state.agents[scenario._eval_agent_ids[0]].behavior_model

video_renderer = VideoRenderer(renderer=viewer,
                               world_step_time=sim_step_time,
                               render_intermediate_steps=10)
for _ in range(0, 40):  # run scenario for 100 steps
    world_state.do_planning(sim_step_time)
    video_renderer.drawWorld(world_state, scenario._eval_agent_ids)
    world_state.do_execution(sim_step_time)

video_renderer.export_video(
    filename="examples/scenarios/test_video_intermediate",
    remove_image_dir=False)