Skip to content

Commit

Permalink
Releases/0.2.0 (#58)
Browse files Browse the repository at this point in the history
* version 0.2.0 & safe driving example

* format

* windows ignore

* test example

* test examples again

* fix setup.py

* metadrive-simulator
  • Loading branch information
QuanyiLi committed Sep 5, 2021
1 parent ff38d99 commit 90cbd25
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
/seed*.json
**/.vscode
**/.idea
/metadrive/cutils.cp37-win_amd64.pyd
2 changes: 1 addition & 1 deletion metadrive/component/blocks/first_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
lane_num: int,
render_root_np: NodePath,
physics_world: PhysicsWorld,
length: float = 50,
length: float = 30,
ignore_intersection_checking=False
):
place_holder = PGBlockSocket(Road(Decoration.start, Decoration.end), Road(Decoration.start, Decoration.end))
Expand Down
2 changes: 1 addition & 1 deletion metadrive/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from panda3d.core import Vec3
from panda3d.core import Vec4, BitMask32

EDITION = "MetaDrive v0.1.4"
EDITION = "MetaDrive v0.2.0"
DEFAULT_AGENT = "default_agent"
RENDER_MODE_NONE = "none" # Do not render
RENDER_MODE_ONSCREEN = "onscreen" # Pop up a window and draw image in it
Expand Down
2 changes: 1 addition & 1 deletion metadrive/examples/drive_in_single_agent_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
random_agent_model=True,
random_lane_width=True,
random_lane_num=True,
map=7, # seven block
map=4, # seven block
start_seed=random.randint(0, 1000)
)
parser = argparse.ArgumentParser()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,22 @@
from metadrive.component.static_object.traffic_object import TrafficCone, TrafficWarning
from metadrive.constants import BodyName, TerminationState, DEFAULT_AGENT
from metadrive.envs.safe_metadrive_env import SafeMetaDriveEnv
from metadrive.manager.object_manager import TrafficObjectManager


class ComplexEnv(SafeMetaDriveEnv):
"""
now for test use and demo use only
"""
def default_config(self):
config = super(ComplexEnv, self).default_config()
config.update(
{
"environment_num": 1,
"traffic_density": 0.02,
"start_seed": 5,
"accident_prob": 0.0,
# "traffic_mode":"respawn",
"debug_physics_world": False,
"debug": False,
"map": "CSRCR"
}
)
return config

def __init__(self, config=None):
super(ComplexEnv, self).__init__(config)
self.breakdown_vehicle = None
self.alert = None

def reset(self, episode_data: dict = None, force_seed=None):
ret = super(ComplexEnv, self).reset(episode_data)
self.vehicle.max_speed = 60
lane = self.current_map.road_network.graph[">>>"]["1C0_0_"][0]
self.breakdown_vehicle = self.engine.object_manager.spawn_object(
class ComplexObjectManager(TrafficObjectManager):
def reset(self):
ret = super(ComplexObjectManager, self).reset()
lane = self.engine.current_map.road_network.graph[">>>"]["1C0_0_"][0]
breakdown_vehicle = self.engine.object_manager.spawn_object(
self.engine.traffic_manager.random_vehicle_type(),
vehicle_config={
"spawn_lane_index": lane.index,
"spawn_longitude": 30
}
)
self.engine.object_manager.accident_lanes.append(lane)
lane_ = self.current_map.road_network.graph[">>>"]["1C0_0_"][1]
lane_ = self.engine.current_map.road_network.graph[">>>"]["1C0_0_"][1]
breakdown_vehicle = self.engine.object_manager.spawn_object(
LVehicle, vehicle_config={
"spawn_lane_index": lane_.index,
Expand All @@ -50,12 +26,12 @@ def reset(self, episode_data: dict = None, force_seed=None):
)
self.engine.object_manager.accident_lanes.append(lane_)

self.alert = self.engine.object_manager.spawn_object(
alert = self.engine.object_manager.spawn_object(
TrafficWarning, lane=lane, longitude=22, lateral=0, pbr_model=False
)

# part 1
lane = self.current_map.road_network.graph["1C0_1_"]["2S0_0_"][2]
lane = self.engine.current_map.road_network.graph["1C0_1_"]["2S0_0_"][2]
pos = [
(-20, lane.width / 3), (-15.6, lane.width / 4), (-12.1, 0), (-8.7, -lane.width / 4),
(-4.2, -lane.width / 2), (-0.7, -lane.width * 3 / 4), (4.1, -lane.width), (7.3, -lane.width),
Expand All @@ -64,7 +40,9 @@ def reset(self, episode_data: dict = None, force_seed=None):
]

for p in pos:
cone = self.engine.object_manager.spawn_object(TrafficCone, lane=lane, longitude=p[0], lateral=p[1])
cone = self.engine.object_manager.spawn_object(
TrafficCone, lane=lane, longitude=p[0], lateral=p[1] + lane.width / 2
)
self.engine.object_manager.accident_lanes.append(lane)
from metadrive.component.vehicle.vehicle_type import SVehicle, XLVehicle
v_pos = [8, 14]
Expand All @@ -78,7 +56,7 @@ def reset(self, episode_data: dict = None, force_seed=None):
)

# part 2
lane = self.current_map.road_network.graph["3R0_0_"]["3R0_1_"][0]
lane = self.engine.current_map.road_network.graph["3R0_0_"]["3R0_1_"][0]
self.engine.object_manager.accident_lanes.append(lane)
pos = [
(-20, lane.width / 3), (-15.6, lane.width / 4), (-12.1, 0), (-8.7, -lane.width / 4),
Expand All @@ -89,7 +67,9 @@ def reset(self, episode_data: dict = None, force_seed=None):

for p in pos:
p_ = (p[0] + 5, -p[1])
cone = self.engine.object_manager.spawn_object(TrafficCone, lane=lane, longitude=p_[0], lateral=p_[1])
cone = self.engine.object_manager.spawn_object(
TrafficCone, lane=lane, longitude=p_[0], lateral=-p[1] - lane.width / 2
)

v_pos = [14, 19]
for v_long in v_pos:
Expand All @@ -106,7 +86,7 @@ def reset(self, episode_data: dict = None, force_seed=None):
alert = self.engine.object_manager.spawn_object(TrafficWarning, lane=lane, longitude=-60, lateral=0)

# part 3
lane = self.current_map.road_network.graph["4C0_0_"]["4C0_1_"][2]
lane = self.engine.current_map.road_network.graph["4C0_0_"]["4C0_1_"][2]
self.engine.object_manager.accident_lanes.append(lane)
pos = [
(-12.1, 0), (-8.7, -lane.width / 4), (-4.2, -lane.width / 2), (-0.7, -lane.width * 3 / 4),
Expand All @@ -116,7 +96,9 @@ def reset(self, episode_data: dict = None, force_seed=None):

for p in pos:
p_ = (p[0] + 5, p[1] * 3.5 / 3)
cone = self.engine.object_manager.spawn_object(TrafficCone, lane=lane, longitude=p_[0], lateral=p_[1])
cone = self.engine.object_manager.spawn_object(
TrafficCone, lane=lane, longitude=p_[0], lateral=p[1] + lane.width / 2
)

v_pos = [14, 19]
for v_long in v_pos:
Expand All @@ -129,17 +111,42 @@ def reset(self, episode_data: dict = None, force_seed=None):
)

# part 4
lane = self.current_map.road_network.graph["4C0_1_"]["5R0_0_"][0]
lane = self.engine.current_map.road_network.graph["4C0_1_"]["5R0_0_"][0]
self.engine.object_manager.accident_lanes.append(lane)
pos = [(-12, lane.width / 4), (-8.1, 0), (-4, -lane.width / 4), (-0.1, -lane.width / 2), (4, -lane.width)]

for p in pos:
p_ = (p[0] + 60, -p[1] * 3.5 / 3)
cone = self.engine.object_manager.spawn_object(TrafficCone, lane=lane, longitude=p_[0], lateral=p_[1])
# pos = [(-12, lane.width / 4), (-8.1, 0), (-4, -lane.width / 4), (-0.1, -lane.width / 2), (4, -lane.width)]
#
# for p in pos:
# p_ = (p[0] + 60, -p[1] * 3.5 / 3)
# cone = self.engine.object_manager.spawn_object(TrafficCone, lane=lane, longitude=p_[0], lateral=p_[1])

return ret


class ComplexEnv(SafeMetaDriveEnv):
"""
now for test use and demo use only
"""
def default_config(self):
config = super(ComplexEnv, self).default_config()
config.update(
{
"environment_num": 1,
"traffic_density": 0.05,
"start_seed": 5,
"accident_prob": 0.0,
# "traffic_mode":"respawn",
"debug_physics_world": False,
"debug": False,
"map": "CSRCR"
}
)
return config

def setup_engine(self):
super(ComplexEnv, self).setup_engine()
self.engine.update_manager("object_manager", ComplexObjectManager())


def test_object_collision_detection(render=False):
env = ComplexEnv(
{
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Please don't change the order of following packages!
import sys
from distutils.core import setup
from distutils.extension import Extension
from os import path

import numpy
from Cython.Build import cythonize
from setuptools import find_namespace_packages # This should be place at top!
from Cython.Build import cythonize
from distutils.extension import Extension


def is_mac():
Expand All @@ -27,7 +27,7 @@ def is_win():
print("We will install the following packages: ", packages)

""" ===== Remember to modify the PG_EDITION at first ====="""
version = "0.1.4"
version = "0.2.0"

ext_modules = cythonize([Extension(
"metadrive.cutils", ["metadrive/cutils.pyx"], include_dirs=[numpy.get_include()]
Expand Down Expand Up @@ -56,7 +56,7 @@ def is_win():
install_requires.append("evdev")

setup(
name="metadrive",
name="metadrive-simulator",
version=version,
description="An open-ended driving simulator with infinite scenes",
url="https://github.com/decisionforce/metadrive",
Expand Down

0 comments on commit 90cbd25

Please sign in to comment.