|
| 1 | +# Copyright (c) 2021 fortiss GmbH |
| 2 | +# |
| 3 | +# Authors: Julian Bernhard, Klemens Esterle, Patrick Hart and |
| 4 | +# Tobias Kessler |
| 5 | +# |
| 6 | +# This work is licensed under the terms of the MIT license. |
| 7 | +# For a copy, see <https://opensource.org/licenses/MIT>. |
| 8 | + |
| 9 | + |
| 10 | +# NOTE: To run this example, you need to clone BARKSCAPE |
| 11 | +# Clone using: git clone https://github.com/bark-simulator/barkscape |
| 12 | +# Run the web-inferfce: bazel run //barkscape/web:run |
| 13 | + |
| 14 | +import sys, os, logging |
| 15 | +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
| 16 | +from bark.runtime.commons.parameters import ParameterServer |
| 17 | +from bark.runtime.viewer.buffered_viewer import BufferedViewer |
| 18 | +from bark.runtime.scenario.scenario_generation.config_with_ease import \ |
| 19 | + LaneCorridorConfig, ConfigWithEase |
| 20 | +from bark.runtime.runtime import Runtime |
| 21 | +from bark.examples.paths import Data |
| 22 | + |
| 23 | +from bark.core.world.opendrive import * |
| 24 | +from bark.core.world.goal_definition import * |
| 25 | +from bark.core.models.behavior import * |
| 26 | +from bark.core.commons import SetVerboseLevel |
| 27 | + |
| 28 | +# BARKSCAPE |
| 29 | +from barkscape.server.base_server import BaseServer |
| 30 | +from barkscape.server.runners.bark_runner import BARKRunner |
| 31 | + |
| 32 | +# scenario |
| 33 | +class CustomLaneCorridorConfig(LaneCorridorConfig): |
| 34 | + def __init__(self, |
| 35 | + params=None, |
| 36 | + **kwargs): |
| 37 | + super(CustomLaneCorridorConfig, self).__init__(params, **kwargs) |
| 38 | + |
| 39 | + def goal(self, world): |
| 40 | + road_corr = world.map.GetRoadCorridor( |
| 41 | + self._road_ids, XodrDrivingDirection.forward) |
| 42 | + lane_corr = self._road_corridor.lane_corridors[0] |
| 43 | + return GoalDefinitionPolygon(lane_corr.polygon) |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + # configure lanes |
| 48 | + param_server = ParameterServer() |
| 49 | + # NOTE: merging |
| 50 | + # left_lane = CustomLaneCorridorConfig(params=param_server, |
| 51 | + # lane_corridor_id=0, |
| 52 | + # road_ids=[0, 1], |
| 53 | + # behavior_model=BehaviorMobilRuleBased(param_server), |
| 54 | + # s_min=5., |
| 55 | + # s_max=50.) |
| 56 | + # right_lane = CustomLaneCorridorConfig(params=param_server, |
| 57 | + # lane_corridor_id=1, |
| 58 | + # road_ids=[0, 1], |
| 59 | + # controlled_ids=True, |
| 60 | + # behavior_model=BehaviorMobilRuleBased(param_server), |
| 61 | + # s_min=5., |
| 62 | + # s_max=20.) |
| 63 | + # scenarios = \ |
| 64 | + # ConfigWithEase(num_scenarios=3, |
| 65 | + # map_file_name=Data.xodr_data("DR_DEU_Merging_MT_v01_shifted"), |
| 66 | + # random_seed=0, |
| 67 | + # params=param_server, |
| 68 | + # lane_corridor_configs=[left_lane, right_lane]) |
| 69 | + |
| 70 | + # NOTE: intersection |
| 71 | + param_server["BehaviorIDMLaneTracking"]["CrosstrackErrorGain"] = 2.5 |
| 72 | + param_server["BehaviorIDMClassic"]["DesiredVelocity"] = 5. |
| 73 | + param_server["BehaviorIntersectionRuleBased"]["BrakingDistance"] = 10. |
| 74 | + param_server["BehaviorIntersectionRuleBased"]["PredictionTimeHorizon"] = 5. |
| 75 | + param_server["BehaviorIntersectionRuleBased"]["AngleDiffForIntersection"] = 0.25 |
| 76 | + |
| 77 | + # configure the lane corridors and how the agents |
| 78 | + lane_corridors = [] |
| 79 | + lane_corridors.append( |
| 80 | + LaneCorridorConfig(params=param_server, |
| 81 | + source_pos=[-30, -3], |
| 82 | + sink_pos=[30, -3], |
| 83 | + behavior_model=BehaviorIntersectionRuleBased(param_server), |
| 84 | + min_vel=5., |
| 85 | + max_vel=5., |
| 86 | + ds_min=5., |
| 87 | + ds_max=10., |
| 88 | + s_min=15., |
| 89 | + s_max=30.)) |
| 90 | + lane_corridors.append( |
| 91 | + LaneCorridorConfig(params=param_server, |
| 92 | + source_pos=[30, 3], |
| 93 | + sink_pos=[-30, 3], |
| 94 | + behavior_model=BehaviorIntersectionRuleBased(param_server), |
| 95 | + min_vel=5., |
| 96 | + max_vel=5., |
| 97 | + ds_min=5., |
| 98 | + ds_max=10., |
| 99 | + s_min=15., |
| 100 | + s_max=30.)) |
| 101 | + lane_corridors.append( |
| 102 | + LaneCorridorConfig(params=param_server, |
| 103 | + source_pos=[3, -30], |
| 104 | + sink_pos=[-30, 3], |
| 105 | + behavior_model=BehaviorIntersectionRuleBased(param_server), |
| 106 | + controlled_ids=True, |
| 107 | + min_vel=5., |
| 108 | + max_vel=5., |
| 109 | + ds_min=5., |
| 110 | + ds_max=10., |
| 111 | + s_min=15., |
| 112 | + s_max=30.)) |
| 113 | + |
| 114 | + scenarios = \ |
| 115 | + ConfigWithEase(num_scenarios=3, |
| 116 | + map_file_name=Data.xodr_data("threeway_intersection"), |
| 117 | + random_seed=0, |
| 118 | + params=param_server, |
| 119 | + lane_corridor_configs=lane_corridors) |
| 120 | + |
| 121 | + viewer = BufferedViewer() |
| 122 | + env = Runtime(step_time=0.2, |
| 123 | + viewer=viewer, |
| 124 | + scenario_generator=scenarios, |
| 125 | + render=True, |
| 126 | + maintain_world_history=True) |
| 127 | + |
| 128 | + # run BARKSCAPE |
| 129 | + logger = logging.getLogger() |
| 130 | + bark_server = BaseServer( |
| 131 | + runner=BARKRunner, runnable_object=env, logger=logger) |
| 132 | + bark_server.Start() |
0 commit comments