Skip to content

Commit

Permalink
feat: adding init metadrive interface to Scenic
Browse files Browse the repository at this point in the history
  • Loading branch information
abanuelo committed Jul 1, 2024
1 parent ef3f6a0 commit b0cc6e9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/scenic/simulators/metadrive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .simulator import MetaDriveSimulator
2 changes: 2 additions & 0 deletions src/scenic/simulators/metadrive/model.scenic
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from scenic.simulators.newtonian.simulator import MetaDriveSimulator
simulator MetaDriveSimulator()
39 changes: 39 additions & 0 deletions src/scenic/simulators/metadrive/simulator.py
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())


0 comments on commit b0cc6e9

Please sign in to comment.