예제 #1
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()
        action_wrapper = MotionPrimitives()
        evaluator = GoalReached()
        viewer = PygameViewer(
            params=params, use_world_bounds=True
        )  # x_range=[-40,40], y_range=[-40,40], follow_agent_id=True)

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

        for _ in range(0, 5):  # run 5 scenarios in a row, repeating after 3
            nn_state = runtimerl.reset()
            for _ in range(0, 10):  # run each scenario for 10 steps
                next_nn_state, reward, done, info = runtimerl.step(
                    action_wrapper.action_space.sample())
                runtimerl.render()
                print("State: {} \n Reward: {} \n Done {}, Info: {} \n \
                         =================================================".
                      format(next_nn_state, reward, done, info))
    def initialize_viewer(self):
        # Viewer of Bark simulation, the pygame surface will be extracted
        self.bark_viewer = PygameViewer(params=self.param_server,
                                        use_world_bounds=True,
                                        screen_dims=BARK_SCREEN_DIMS)

        # Viewer of cosimulation
        # Set the number of cameras to show both simulation side by side
        # windows from Bark simulation & camera image from Carla simulation
        self.cosimulation_viewer = CosimulationViewer(BARK_SCREEN_DIMS,
                                                      num_cameras=NUM_CAMERAS)
예제 #3
0
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],)
"""
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(
예제 #4
0
agent = Agent(
    init_state,
    behavior_model,
    dynamic_model,
    execution_model,
    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)
예제 #5
0
import time
import os

scenario_dump_folder = "examples/scenarios/"
scenario_param_file = "highway_merging.json"  # must be within scenario dump folder

param_server = ParameterServer(
    filename=os.path.join("examples/params/", scenario_param_file))

scenario_generation = UniformVehicleDistribution(num_scenarios=3,
                                                 random_seed=0,
                                                 params=param_server)
scenario_generation.params.save(
    os.path.join(scenario_dump_folder, scenario_param_file))

viewer = PygameViewer(params=param_server, use_world_bounds=True)
sim_step_time = param_server["simulation"]["step_time",
                                           "Step-time used in simulation",
                                           0.05]
sim_real_time_factor = param_server["simulation"][
    "real_time_factor", "execution in real-time or faster", 1]

for _ in range(0, 2):  # run 5 scenarios in a row, repeating after 3
    scenario, idx = scenario_generation.get_next_scenario()
    world_state = scenario.get_world_state()
    print("Running scenario {} of {}".format(
        idx, scenario_generation.num_scenarios))
    for _ in range(0, 10):  # run each scenario for 3 steps
        world_state.step(sim_step_time)
        viewer.drawWorld(world_state)
        viewer.show(block=False)
예제 #6
0
from modules.runtime.scenario.scenario_generation.uniform_vehicle_distribution import UniformVehicleDistribution
from modules.runtime.commons.parameters import ParameterServer
from modules.runtime.viewer.matplotlib_viewer import MPViewer
from modules.runtime.viewer.pygame_viewer import PygameViewer
from modules.runtime.viewer.threaded_viewer import ThreadedViewer
import time
import os

scenario_param_file ="highway_merging.json" # must be within examples params folder

param_server = ParameterServer(filename= os.path.join("examples/params/",scenario_param_file))

scenario_generation = UniformVehicleDistribution(num_scenarios=3, random_seed=0, params=param_server)


viewer = PygameViewer(params=param_server, x_range=[-50,50], y_range=[-20,80], use_world_bounds=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()

print("Running scenario {} of {}".format(idx, scenario_generation.num_scenarios))
for _ in range(0, 100): # run each scenario for 3 steps
    world_state.do_planning(sim_step_time)
    viewer.drawWorld(world_state)
예제 #7
0
# Copyright (c) 2019 fortiss GmbH
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT

from modules.runtime.scenario.scenario_generation.scenario_generation import ScenarioGeneration
from modules.runtime.viewer.pygame_viewer import PygameViewer
from modules.runtime.viewer.matplotlib_viewer import MPViewer
from modules.runtime.commons.parameters import ParameterServer
import time

param_server = ParameterServer()

viewer = PygameViewer(params=param_server,
                      x_range=[4950, 5250],
                      y_range=[5100, 5300])

sim_step_time = param_server["simulation"]["step_time",
                                           "Step-time used in simulation",
                                           0.05]
sim_real_time_factor = param_server["simulation"][
    "real_time_factor", "execution in real-time or faster", 1]
scenario_generation = ScenarioGeneration()
scenario_generation.load_scenario_list(
    filename="examples/scenarios/highway_merging.bark_scenarios")

for _ in range(0, 5):  # run 5 scenarios in a row, repeating after 3
    scenario, idx = scenario_generation.get_next_scenario()
    world_state = scenario.get_world_state()
    print("Running scenario {} of {}".format(
        idx, scenario_generation.num_scenarios))