-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding init metadrive interface to Scenic
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .simulator import MetaDriveSimulator |
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,2 @@ | ||
from scenic.simulators.newtonian.simulator import MetaDriveSimulator | ||
simulator MetaDriveSimulator() |
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,39 @@ | ||
from scenic.core.simulators import ( | ||
Simulation, | ||
SimulationCreationError, | ||
Simulator, | ||
SimulatorInterfaceWarning, | ||
) | ||
|
||
from metadrive.envs import BaseEnv | ||
import logging | ||
|
||
class MetaDriveSimulator(Simulator): | ||
def __init__(self): | ||
self.client = BaseEnv(dict(use_render=False, # if you have a screen and OpenGL suppor, you can set use_render=True to use 3D rendering | ||
manual_control=False, # we usually manually control the car to test environment | ||
log_level=logging.CRITICAL)) # suppress logging message | ||
super().__init__() | ||
|
||
def createSimulation(self, scene, **kwargs): | ||
simulation = MetaDriveSimulation(self, scene, self.client, **kwargs) | ||
self.client.top_down_renderer.generate_gif() | ||
return | ||
|
||
def destroy(self): | ||
self.client.close() | ||
super().destroy() | ||
|
||
class MetaDriveSimulation(Simulation): | ||
def __init__(self, simulator, scene, client, **kwargs): | ||
self.simulator = simulator | ||
self.client = client | ||
super().__init__(scene, **kwargs) | ||
|
||
def setup(self): | ||
super().setup() | ||
|
||
def step(self): | ||
self.client.step(self.client.action_space.sample()) | ||
|
||
|