Skip to content

Commit

Permalink
Introduce Tollgate MARL environment (#447)
Browse files Browse the repository at this point in the history
* add flexible bottle part length

* toll block

* fix object bug

* runable

* fix memory leak

* add building type

* test script

* speed limit

* finish

* 10 agent

* format

* test reward

* add crash building flag & add test script

* format

* fix test and format

* update config

* update camera setting

* update configs

* update reward scheme

* rename to toll gate

* update side detector

* remove navi info

* yellow line

* min pass time

* finish

* format

* rename tollgate env

* move config to top

* format

* optimize config

* format

* optimize

* finish this branch

Co-authored-by: pengzhenghao <pengzh@ie.cuhk.edu.hk>
  • Loading branch information
QuanyiLi and pengzhenghao committed May 21, 2021
1 parent 8f5314a commit 821f7dd
Show file tree
Hide file tree
Showing 30 changed files with 1,572 additions and 60 deletions.
16 changes: 15 additions & 1 deletion pgdrive/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class TerminationState:
CRASH = "crash"
CRASH_VEHICLE = "crash_vehicle"
CRASH_OBJECT = "crash_object"
CRASH_BUILDING = "crash_building"


HELP_MESSAGE = "Keyboard Shortcuts:\n" \
Expand Down Expand Up @@ -53,12 +54,14 @@ class BodyName:
Broken_line = "Broken Line"
Sidewalk = "Sidewalk"
Ground = "Ground"
InvisibleWall = "InvisibleWall"
Base_vehicle = "Target Vehicle"
Base_vehicle_beneath = "Target Vehicle Beneath"
Traffic_vehicle = "Traffic Vehicle"
Lane = "Lane"
Traffic_cone = "Traffic Cone"
Traffic_triangle = "Traffic Triangle"
TollGate = "Toll Gate"


COLOR = {
Expand All @@ -70,7 +73,9 @@ class BodyName:
BodyName.Traffic_cone: "orange",
BodyName.Traffic_triangle: "orange",
BodyName.Base_vehicle: "red",
BodyName.Base_vehicle_beneath: "red"
BodyName.Base_vehicle_beneath: "red",
BodyName.InvisibleWall: "red",
BodyName.TollGate: "red",
}


Expand Down Expand Up @@ -110,6 +115,7 @@ class CollisionGroup:
EgoVehicleBeneath = 6
BrokenLaneLine = 3
ContinuousLaneLine = 7
InvisibleWall = 8
TrafficVehicle = 4
LaneSurface = 5 # useless now, since it is in another physics world

Expand All @@ -124,6 +130,7 @@ def collision_rules(cls):
(cls.Terrain, cls.EgoVehicleBeneath, False),
(cls.Terrain, cls.TrafficVehicle, False),
(cls.Terrain, cls.ContinuousLaneLine, False),
(cls.Terrain, cls.InvisibleWall, False),

# block collision
(cls.BrokenLaneLine, cls.BrokenLaneLine, False),
Expand All @@ -133,31 +140,38 @@ def collision_rules(cls):
# change it after we design a new traffic system !
(cls.BrokenLaneLine, cls.TrafficVehicle, False),
(cls.BrokenLaneLine, cls.ContinuousLaneLine, False),
(cls.BrokenLaneLine, cls.InvisibleWall, False),

# traffic vehicles collision
(cls.TrafficVehicle, cls.TrafficVehicle, False),
(cls.TrafficVehicle, cls.LaneSurface, False),
(cls.TrafficVehicle, cls.EgoVehicle, True),
(cls.TrafficVehicle, cls.EgoVehicleBeneath, True),
(cls.TrafficVehicle, cls.ContinuousLaneLine, False),
# FIXME maybe set to True in the future
(cls.TrafficVehicle, cls.InvisibleWall, False),

# ego vehicle collision
(cls.EgoVehicle, cls.EgoVehicle, True),
(cls.EgoVehicle, cls.EgoVehicleBeneath, False),
(cls.EgoVehicle, cls.LaneSurface, False),
(cls.EgoVehicle, cls.ContinuousLaneLine, False),
(cls.EgoVehicle, cls.InvisibleWall, True),

# lane surface
(cls.LaneSurface, cls.LaneSurface, False),
(cls.LaneSurface, cls.EgoVehicleBeneath, False),
(cls.LaneSurface, cls.ContinuousLaneLine, False),
(cls.LaneSurface, cls.InvisibleWall, False),

# vehicle beneath
(cls.EgoVehicleBeneath, cls.EgoVehicleBeneath, True),
(cls.EgoVehicleBeneath, cls.ContinuousLaneLine, True),
(cls.EgoVehicleBeneath, cls.InvisibleWall, True),

# continuous lane line
(cls.ContinuousLaneLine, cls.ContinuousLaneLine, False),
(cls.ContinuousLaneLine, cls.InvisibleWall, False),
]

@classmethod
Expand Down
7 changes: 4 additions & 3 deletions pgdrive/envs/generation_envs/safe_pgdrive_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ def cost_function(self, vehicle_id: str):
"accident_prob": 1.0,
"manual_control": True,
"use_render": True,
"environment_num": 100,
"start_seed": 139,
"environment_num": 1,
"start_seed": 187,
"out_of_road_cost": 1,
# "debug": True,
"debug": True,
"cull_scene": True,
"pg_world_config": {
"pstats": True
Expand All @@ -130,6 +130,7 @@ def cost_function(self, vehicle_id: str):
o, r, d, info = env.step([0, 1])
total_cost += info["cost"]
env.render(text={"cost": total_cost, "seed": env.current_map.random_seed, "reward": r})
print(len(env.scene_manager.traffic_manager.traffic_vehicles))
if d:
total_cost = 0
print("done_cost:{}".format(info["cost"]))
Expand Down
11 changes: 1 addition & 10 deletions pgdrive/envs/marl_envs/marl_intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,7 @@ def _generate(self, pg_world):
InterSection.EXIT_PART_LENGTH = length
last_block = InterSection(1, last_block.get_socket(index=0), self.road_network, random_seed=1)
last_block.add_u_turn(True)
last_block.construct_block(
parent_node_path,
pg_physics_world,
extra_config={
"exit_radius": 10,
"inner_radius": 30,
"angle": 70,
# Note: lane_num is set in config.map_config.lane_num
}
)
last_block.construct_block(parent_node_path, pg_physics_world)
self.blocks.append(last_block)


Expand Down

0 comments on commit 821f7dd

Please sign in to comment.