Skip to content

Commit

Permalink
Metadrive: fix slow acceleration and enable past 50 mph (commaai#30171)
Browse files Browse the repository at this point in the history
metadrive tuning
  • Loading branch information
jnewb1 authored Oct 5, 2023
1 parent 56b16e7 commit f4b2b70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions tools/sim/bridge/metadrive/metadrive_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ def metadrive_process(dual_camera: bool, config: dict, camera_array, controls_re
road_image = np.frombuffer(camera_array.get_obj(), dtype=np.uint8).reshape((H, W, 3))

env = MetaDriveEnv(config)
env.reset()

def reset():
env.reset()
env.vehicle.config["max_speed_km_h"] = 1000

reset()

def get_cam_as_rgb(cam):
cam = env.engine.sensors[cam]
Expand All @@ -71,21 +76,21 @@ def get_cam_as_rgb(cam):

if controls_recv.poll(0):
while controls_recv.poll(0):
steer_angle, gas, reset = controls_recv.recv()
steer_angle, gas, should_reset = controls_recv.recv()

steer_metadrive = steer_angle * 1 / (env.vehicle.MAX_STEERING * steer_ratio)
steer_metadrive = np.clip(steer_metadrive, -1, 1)

vc = [steer_metadrive, gas]

if reset:
env.reset()
if should_reset:
reset()

if rk.frame % 5 == 0:
obs, _, terminated, _, info = env.step(vc)

if terminated:
env.reset()
reset()

#if dual_camera:
# wide_road_image = get_cam_as_rgb("rgb_wide")
Expand Down
2 changes: 1 addition & 1 deletion tools/sim/bridge/metadrive/metadrive_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def apply_controls(self, steer_angle, throttle_out, brake_out):
self.vc[0] = steer_angle

if throttle_out:
self.vc[1] = throttle_out/10
self.vc[1] = throttle_out
else:
self.vc[1] = -brake_out
else:
Expand Down

0 comments on commit f4b2b70

Please sign in to comment.