-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
429 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from metadrive.component.map.scenario_map import ScenarioMap | ||
from metadrive.manager.base_manager import BaseManager | ||
from metadrive.utils.sumo.map_utils import StreetMap, extract_map_features | ||
|
||
|
||
class SumoMapManager(BaseManager): | ||
""" | ||
It currently only support load one map into the simulation. | ||
""" | ||
PRIORITY = 0 # Map update has the most high priority | ||
|
||
def __init__(self, sumo_map_path): | ||
super(SumoMapManager, self).__init__() | ||
self.current_map = None | ||
street_map = StreetMap() | ||
street_map.reset(sumo_map_path) | ||
self.map_feature = extract_map_features(street_map) | ||
|
||
def destroy(self): | ||
self.current_map.destroy() | ||
super(SumoMapManager, self).destroy() | ||
self.current_map = None | ||
|
||
def before_reset(self): | ||
if self.current_map: | ||
self.current_map.detach_from_world() | ||
|
||
def reset(self): | ||
if not self.current_map: | ||
self.current_map = ScenarioMap(map_index=0, map_data=self.map_feature) | ||
self.current_map.attach_to_world() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""use netconvert --opendrive-files CARLA_town01.net.xml first""" | ||
|
||
|
||
from metadrive.envs import BaseEnv | ||
from metadrive.obs.observation_base import DummyObservation | ||
import logging | ||
from metadrive.manager.sumo_map_manager import SumoMapManager | ||
from metadrive.engine.asset_loader import AssetLoader | ||
|
||
|
||
class MyEnv(BaseEnv): | ||
|
||
def reward_function(self, agent): | ||
return 0, {} | ||
|
||
def cost_function(self, agent): | ||
return 0, {} | ||
|
||
def done_function(self, agent): | ||
return False, {} | ||
|
||
def get_single_observation(self): | ||
return DummyObservation() | ||
|
||
def setup_engine(self): | ||
super().setup_engine() | ||
map_path = AssetLoader.file_path("carla", "CARLA_town01.net.xml", unix_style=False) | ||
self.engine.register_manager("map_manager", SumoMapManager(map_path)) | ||
|
||
|
||
if __name__ == "__main__": | ||
# create env | ||
env = MyEnv(dict(use_render=True, | ||
# if you have a screen and OpenGL suppor, you can set use_render=True to use 3D rendering | ||
vehicle_config={"spawn_position_heading": [(0, 0), 0]}, | ||
manual_control=True, # we usually manually control the car to test environment | ||
use_mesh_terrain=True, | ||
log_level=logging.CRITICAL)) # suppress logging message | ||
env.reset() | ||
for i in range(10000): | ||
# step | ||
obs, reward, termination, truncate, info = env.step(env.action_space.sample()) | ||
env.close() |
Empty file.
Oops, something went wrong.