CI/simulator: metadrive test starts when OP engaged and world is initialized (#32523)

* fix metadrive start time

* fix
pull/32538/head
Hoang Bui 11 months ago committed by GitHub
parent 95aa7c4b68
commit 613f73c53f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      tools/sim/bridge/metadrive/metadrive_process.py
  2. 6
      tools/sim/bridge/metadrive/metadrive_world.py

@ -50,7 +50,7 @@ def apply_metadrive_patches(arrive_dest_done=True):
def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera_array, image_lock, def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera_array, image_lock,
controls_recv: Connection, simulation_state_send: Connection, vehicle_state_send: Connection, controls_recv: Connection, simulation_state_send: Connection, vehicle_state_send: Connection,
exit_event, start_time, test_duration, test_run): exit_event, op_engaged, test_duration, test_run):
arrive_dest_done = config.pop("arrive_dest_done", True) arrive_dest_done = config.pop("arrive_dest_done", True)
apply_metadrive_patches(arrive_dest_done) apply_metadrive_patches(arrive_dest_done)
@ -81,6 +81,7 @@ def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera
return lane_idx_prev return lane_idx_prev
lane_idx_prev = reset() lane_idx_prev = reset()
start_time = None
def get_cam_as_rgb(cam): def get_cam_as_rgb(cam):
cam = env.engine.sensors[cam] cam = env.engine.sensors[cam]
@ -104,7 +105,6 @@ def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera
bearing=float(math.degrees(env.vehicle.heading_theta)), bearing=float(math.degrees(env.vehicle.heading_theta)),
steering_angle=env.vehicle.steering * env.vehicle.MAX_STEERING steering_angle=env.vehicle.steering * env.vehicle.MAX_STEERING
) )
vehicle_state_send.send(vehicle_state) vehicle_state_send.send(vehicle_state)
if controls_recv.poll(0): if controls_recv.poll(0):
@ -118,10 +118,15 @@ def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera
if should_reset: if should_reset:
lane_idx_prev = reset() lane_idx_prev = reset()
start_time = None
is_engaged = op_engaged.is_set()
if is_engaged and start_time is None:
start_time = time.monotonic()
if rk.frame % 5 == 0: if rk.frame % 5 == 0:
_, _, terminated, _, _ = env.step(vc) _, _, terminated, _, _ = env.step(vc)
timeout = True if time.monotonic() - start_time >= test_duration else False timeout = True if start_time is not None and time.monotonic() - start_time >= test_duration else False
lane_idx_curr, on_lane = get_current_lane_info(env.vehicle) lane_idx_curr, on_lane = get_current_lane_info(env.vehicle)
out_of_lane = lane_idx_curr != lane_idx_prev or not on_lane out_of_lane = lane_idx_curr != lane_idx_prev or not on_lane
lane_idx_prev = lane_idx_curr lane_idx_prev = lane_idx_curr

@ -29,10 +29,10 @@ class MetaDriveWorld(World):
self.vehicle_state_send, self.vehicle_state_recv = Pipe() self.vehicle_state_send, self.vehicle_state_recv = Pipe()
self.exit_event = multiprocessing.Event() self.exit_event = multiprocessing.Event()
self.op_engaged = multiprocessing.Event()
self.test_run = test_run self.test_run = test_run
self.start_time = time.monotonic()
self.first_engage = None self.first_engage = None
self.last_check_timestamp = 0 self.last_check_timestamp = 0
self.distance_moved = 0 self.distance_moved = 0
@ -41,7 +41,7 @@ class MetaDriveWorld(World):
functools.partial(metadrive_process, dual_camera, config, functools.partial(metadrive_process, dual_camera, config,
self.camera_array, self.wide_camera_array, self.image_lock, self.camera_array, self.wide_camera_array, self.image_lock,
self.controls_recv, self.simulation_state_send, self.controls_recv, self.simulation_state_send,
self.vehicle_state_send, self.exit_event, self.start_time, test_duration, self.test_run)) self.vehicle_state_send, self.exit_event, self.op_engaged, test_duration, self.test_run))
self.metadrive_process.start() self.metadrive_process.start()
self.status_q.put(QueueMessage(QueueMessageType.START_STATUS, "starting")) self.status_q.put(QueueMessage(QueueMessageType.START_STATUS, "starting"))
@ -94,6 +94,8 @@ class MetaDriveWorld(World):
is_engaged = state.is_engaged is_engaged = state.is_engaged
if is_engaged and self.first_engage is None: if is_engaged and self.first_engage is None:
self.first_engage = time.monotonic() self.first_engage = time.monotonic()
self.op_engaged.set()
# check moving 5 seconds after engaged, doesn't move right away # check moving 5 seconds after engaged, doesn't move right away
after_engaged_check = is_engaged and time.monotonic() - self.first_engage >= 5 and self.test_run after_engaged_check = is_engaged and time.monotonic() - self.first_engage >= 5 and self.test_run

Loading…
Cancel
Save