fix metadrive after bump (#30967)

* fix clip

* wip

* oop

* 1.22

* ... ugly

* fix tuning
pull/30977/head
Justin Newberry 1 year ago committed by GitHub
parent e7657d896f
commit f2c73039d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      tools/sim/bridge/metadrive/metadrive_bridge.py
  2. 12
      tools/sim/bridge/metadrive/metadrive_process.py

@ -3,15 +3,13 @@ import numpy as np
from metadrive.component.sensors.rgb_camera import RGBCamera
from metadrive.component.sensors.base_camera import _cuda_enable
from metadrive.component.map.pg_map import MapGenerateMethod
from panda3d.core import Vec3, Texture, GraphicsOutput
from panda3d.core import Texture, GraphicsOutput
from openpilot.tools.sim.bridge.common import SimulatorBridge
from openpilot.tools.sim.bridge.metadrive.metadrive_world import MetaDriveWorld
from openpilot.tools.sim.lib.camerad import W, H
C3_POSITION = Vec3(0.0, 1.0, 1.22)
class CopyRamRGBCamera(RGBCamera):
"""Camera which copies its content into RAM during the render process, for faster image grabbing."""
@ -33,8 +31,6 @@ class CopyRamRGBCamera(RGBCamera):
class RGBCameraWide(CopyRamRGBCamera):
def __init__(self, *args, **kwargs):
super(RGBCameraWide, self).__init__(*args, **kwargs)
cam = self.get_cam()
cam.setPos(C3_POSITION)
lens = self.get_lens()
lens.setFov(120)
lens.setNear(0.1)
@ -42,8 +38,6 @@ class RGBCameraWide(CopyRamRGBCamera):
class RGBCameraRoad(CopyRamRGBCamera):
def __init__(self, *args, **kwargs):
super(RGBCameraRoad, self).__init__(*args, **kwargs)
cam = self.get_cam()
cam.setPos(C3_POSITION)
lens = self.get_lens()
lens.setFov(40)
lens.setNear(0.1)

@ -2,6 +2,7 @@ import math
import numpy as np
from collections import namedtuple
from panda3d.core import Vec3
from multiprocessing.connection import Connection
from metadrive.engine.core.engine_core import EngineCore
@ -10,9 +11,13 @@ from metadrive.envs.metadrive_env import MetaDriveEnv
from metadrive.obs.image_obs import ImageObservation
from openpilot.common.realtime import Ratekeeper
from openpilot.tools.sim.lib.common import vec3
from openpilot.tools.sim.lib.camerad import W, H
C3_POSITION = Vec3(0.0, 0, 1.22)
C3_HPR = Vec3(0, 0,0)
metadrive_state = namedtuple("metadrive_state", ["velocity", "position", "bearing", "steering_angle"])
@ -58,14 +63,17 @@ def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera
def get_cam_as_rgb(cam):
cam = env.engine.sensors[cam]
img = cam.perceive(env.vehicle, clip=False)
cam.get_cam().reparentTo(env.vehicle.origin)
cam.get_cam().setPos(C3_POSITION)
cam.get_cam().setHpr(C3_HPR)
img = cam.perceive(clip=False)
if type(img) != np.ndarray:
img = img.get() # convert cupy array to numpy
return img
rk = Ratekeeper(100, None)
steer_ratio = 15
steer_ratio = 8
vc = [0,0]
while not exit_event.is_set():

Loading…
Cancel
Save