Skip to content

Commit

Permalink
metadrive: fix dual_camera mode (commaai#30743)
Browse files Browse the repository at this point in the history
* Use wide cam in metadrive

* 120 fov
  • Loading branch information
fredyshox authored Dec 15, 2023
1 parent 0830f62 commit 5fe9f14
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tools/sim/bridge/metadrive/metadrive_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, *args, **kwargs):
cam = self.get_cam()
cam.setPos(C3_POSITION)
lens = self.get_lens()
lens.setFov(160)
lens.setFov(120)

class RGBCameraRoad(CopyRamRGBCamera):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -116,4 +116,4 @@ def spawn_world(self):
preload_models=False
)

return MetaDriveWorld(config)
return MetaDriveWorld(config, self.dual_camera)
9 changes: 6 additions & 3 deletions tools/sim/bridge/metadrive/metadrive_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ def arrive_destination_patch(self, vehicle):

MetaDriveEnv._is_arrive_destination = arrive_destination_patch

def metadrive_process(dual_camera: bool, config: dict, camera_array, controls_recv: Connection, state_send: Connection, exit_event):
def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera_array, controls_recv: Connection, state_send: Connection, exit_event):
apply_metadrive_patches()

road_image = np.frombuffer(camera_array.get_obj(), dtype=np.uint8).reshape((H, W, 3))
if dual_camera:
assert wide_camera_array is not None
wide_road_image = np.frombuffer(wide_camera_array.get_obj(), dtype=np.uint8).reshape((H, W, 3))

env = MetaDriveEnv(config)

Expand Down Expand Up @@ -92,8 +95,8 @@ def get_cam_as_rgb(cam):
if terminated:
reset()

#if dual_camera:
# wide_road_image = get_cam_as_rgb("rgb_wide")
if dual_camera:
wide_road_image[...] = get_cam_as_rgb("rgb_wide")
road_image[...] = get_cam_as_rgb("rgb_road")

rk.keep_time()
6 changes: 5 additions & 1 deletion tools/sim/bridge/metadrive/metadrive_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def __init__(self, config, dual_camera = False):
super().__init__(dual_camera)
self.camera_array = Array(ctypes.c_uint8, W*H*3)
self.road_image = np.frombuffer(self.camera_array.get_obj(), dtype=np.uint8).reshape((H, W, 3))
self.wide_camera_array = None
if dual_camera:
self.wide_camera_array = Array(ctypes.c_uint8, W*H*3)
self.wide_road_image = np.frombuffer(self.wide_camera_array.get_obj(), dtype=np.uint8).reshape((H, W, 3))

self.controls_send, self.controls_recv = Pipe()
self.state_send, self.state_recv = Pipe()
Expand All @@ -23,7 +27,7 @@ def __init__(self, config, dual_camera = False):

self.metadrive_process = multiprocessing.Process(name="metadrive process", target=
functools.partial(metadrive_process, dual_camera, config,
self.camera_array, self.controls_recv, self.state_send, self.exit_event))
self.camera_array, self.wide_camera_array, self.controls_recv, self.state_send, self.exit_event))
self.metadrive_process.start()

print("----------------------------------------------------------")
Expand Down

0 comments on commit 5fe9f14

Please sign in to comment.