Exemplo n.º 1
0
  def test_uniform_vehicle_distribution_default_params(self):
    scenario_generation = UniformVehicleDistribution(num_scenarios=2, random_seed=0)
    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))
Exemplo n.º 2
0
    def _build_configuration(self):
        """Builds a configuration using an SAC agent
    """
        self._scenario_generator = \
            UniformVehicleDistribution(num_scenarios=20,
                                      random_seed=0,
                                      params=self._params)

        self._observer = CustomObserver(params=self._params)
        self._behavior_model = DynamicModel(params=self._params)
        self._evaluator = CustomEvaluator(params=self._params)

        self._viewer = MPViewer(params=self._params,
                                x_range=[-30, 30],
                                y_range=[-60, 20],
                                follow_agent_id=True)
        #self._viewer = VideoRenderer(renderer=viewer, world_step_time=0.2)
        self._runtime = RuntimeRL(action_wrapper=self._behavior_model,
                                  observer=self._observer,
                                  evaluator=self._evaluator,
                                  step_time=0.2,
                                  viewer=self._viewer,
                                  scenario_generator=self._scenario_generator)
        tfa_env = tf_py_environment.TFPyEnvironment(TFAWrapper(self._runtime))
        self._agent_0 = SACAgent(tfa_env, params=self._params)
        self._agent_1 = SACAgent(tfa_env, params=self._params)
        self._runner = SACRunner(tfa_env, [self._agent_0, self._agent_1],
                                 params=self._params,
                                 unwrapped_runtime=self._runtime)
Exemplo n.º 3
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))
Exemplo n.º 4
0
    def test_motion_primitives_concat_state():
        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)

        tfa_env = TFAWrapper(runtimerl)
        _ = tfa_env.reset()
        utils.validate_py_environment(tfa_env, episodes=5)
        _ = tf_py_environment.TFPyEnvironment(tfa_env)
Exemplo n.º 5
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.º 6
0
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT

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
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 = MPViewer(params=param_server,
                  x_range=[5060, 5160],
                  y_range=[5070, 5150],
                  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]

# TODO(@hart): does not work with bazel test //... because of read only file-system
# scenario_generation.dump_scenario_list(filename="examples/scenarios/highway_merging_dump.bark_scenarios")

# load scenario list
Exemplo n.º 7
0
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT

# ffmpeg must be installed and available on command line


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.video_renderer import VideoRenderer
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=10, random_seed=0, params=param_server)

viewer = MPViewer(params=param_server, x_range=[5060, 5160], y_range=[5070,5150])
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()


# Rendering WITHOUT intermediate steps
video_renderer = VideoRenderer(renderer=viewer, world_step_time=sim_step_time)

for _ in range(0, 1):
  scenario, idx = scenario_generation.get_next_scenario()
Exemplo n.º 8
0
# https://opensource.org/licenses/MIT

from modules.runtime.scenario.scenario_generation.uniform_vehicle_distribution import UniformVehicleDistribution
from modules.runtime.commons.parameters import ParameterServer
from modules.runtime.viewer.pygame_viewer import PygameViewer
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(
# Copyright (c) 2019 fortiss GmbH
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT

from modules.runtime.scenario.scenario_generation.uniform_vehicle_distribution import UniformVehicleDistribution
from modules.runtime.commons.parameters import ParameterServer
import time
import os

param_server = ParameterServer()

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

scenario_generation.dump_scenario_list("test.bark_scenarios")