mirror of https://github.com/commaai/openpilot.git
ci: faster metadrive test (#33755)
* fast * fix * same ratio * output * check old * error * fail * better * log * test faster runner * work? * test * ratio * forward * try without wait * test old distance * fxi * test old runner * test this * assert distance * cleanup * better * get distance * cleanup * choose runner * very slow * wait * put this back
This commit is contained in:
parent
48abdf825b
commit
d7c0906d0b
|
@ -27,7 +27,9 @@ env:
|
||||||
jobs:
|
jobs:
|
||||||
simulator_driving:
|
simulator_driving:
|
||||||
name: simulator driving
|
name: simulator driving
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{ ((github.repository == 'commaai/openpilot') &&
|
||||||
|
((github.event_name != 'pull_request') ||
|
||||||
|
(github.event.pull_request.head.repo.full_name == 'commaai/openpilot'))) && 'namespace-profile-amd64-8x16' || 'ubuntu-latest' }}
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
|
@ -50,12 +50,13 @@ def create_map(track_size=60):
|
||||||
class MetaDriveBridge(SimulatorBridge):
|
class MetaDriveBridge(SimulatorBridge):
|
||||||
TICKS_PER_FRAME = 5
|
TICKS_PER_FRAME = 5
|
||||||
|
|
||||||
def __init__(self, dual_camera, high_quality, test_duration=math.inf, test_run=False):
|
def __init__(self, dual_camera, high_quality, test_duration=math.inf, minimal_distance=0, test_run=False):
|
||||||
super().__init__(dual_camera, high_quality)
|
super().__init__(dual_camera, high_quality)
|
||||||
|
|
||||||
self.should_render = False
|
self.should_render = False
|
||||||
self.test_run = test_run
|
self.test_run = test_run
|
||||||
self.test_duration = test_duration if self.test_run else math.inf
|
self.test_duration = test_duration if self.test_run else math.inf
|
||||||
|
self.minimal_distance = minimal_distance if self.test_run else 0
|
||||||
|
|
||||||
def spawn_world(self, queue: Queue):
|
def spawn_world(self, queue: Queue):
|
||||||
sensors = {
|
sensors = {
|
||||||
|
@ -90,4 +91,4 @@ class MetaDriveBridge(SimulatorBridge):
|
||||||
anisotropic_filtering=False
|
anisotropic_filtering=False
|
||||||
)
|
)
|
||||||
|
|
||||||
return MetaDriveWorld(queue, config, self.test_duration, self.test_run, self.dual_camera)
|
return MetaDriveWorld(queue, config, self.test_duration, self.minimal_distance, self.test_run, self.dual_camera)
|
||||||
|
|
|
@ -19,6 +19,7 @@ from openpilot.tools.sim.lib.camerad import W, H
|
||||||
C3_POSITION = Vec3(0.0, 0, 1.22)
|
C3_POSITION = Vec3(0.0, 0, 1.22)
|
||||||
C3_HPR = Vec3(0, 0,0)
|
C3_HPR = Vec3(0, 0,0)
|
||||||
|
|
||||||
|
VEHICLE_STARTING_POS = [110, 4.5]
|
||||||
|
|
||||||
metadrive_simulation_state = namedtuple("metadrive_simulation_state", ["running", "done", "done_info"])
|
metadrive_simulation_state = namedtuple("metadrive_simulation_state", ["running", "done", "done_info"])
|
||||||
metadrive_vehicle_state = namedtuple("metadrive_vehicle_state", ["velocity", "position", "bearing", "steering_angle"])
|
metadrive_vehicle_state = namedtuple("metadrive_vehicle_state", ["velocity", "position", "bearing", "steering_angle"])
|
||||||
|
@ -50,7 +51,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, op_engaged, test_duration, test_run):
|
exit_event, op_engaged, test_duration, minimal_distance, 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)
|
||||||
|
|
||||||
|
@ -70,6 +71,7 @@ def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera
|
||||||
env.reset()
|
env.reset()
|
||||||
env.vehicle.config["max_speed_km_h"] = 1000
|
env.vehicle.config["max_speed_km_h"] = 1000
|
||||||
lane_idx_prev, _ = get_current_lane_info(env.vehicle)
|
lane_idx_prev, _ = get_current_lane_info(env.vehicle)
|
||||||
|
env.vehicle.set_position(VEHICLE_STARTING_POS)
|
||||||
|
|
||||||
simulation_state = metadrive_simulation_state(
|
simulation_state = metadrive_simulation_state(
|
||||||
running=True,
|
running=True,
|
||||||
|
@ -98,6 +100,9 @@ def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera
|
||||||
steer_ratio = 8
|
steer_ratio = 8
|
||||||
vc = [0,0]
|
vc = [0,0]
|
||||||
|
|
||||||
|
total_distance = 0
|
||||||
|
prev_x_pos = VEHICLE_STARTING_POS[0]
|
||||||
|
|
||||||
while not exit_event.is_set():
|
while not exit_event.is_set():
|
||||||
vehicle_state = metadrive_vehicle_state(
|
vehicle_state = metadrive_vehicle_state(
|
||||||
velocity=vec3(x=float(env.vehicle.velocity[0]), y=float(env.vehicle.velocity[1]), z=0),
|
velocity=vec3(x=float(env.vehicle.velocity[0]), y=float(env.vehicle.velocity[1]), z=0),
|
||||||
|
@ -107,6 +112,9 @@ def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera
|
||||||
)
|
)
|
||||||
vehicle_state_send.send(vehicle_state)
|
vehicle_state_send.send(vehicle_state)
|
||||||
|
|
||||||
|
total_distance += abs(env.vehicle.position[0] - prev_x_pos)
|
||||||
|
prev_x_pos = env.vehicle.position[0]
|
||||||
|
|
||||||
if controls_recv.poll(0):
|
if controls_recv.poll(0):
|
||||||
while controls_recv.poll(0):
|
while controls_recv.poll(0):
|
||||||
steer_angle, gas, should_reset = controls_recv.recv()
|
steer_angle, gas, should_reset = controls_recv.recv()
|
||||||
|
@ -137,7 +145,10 @@ def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera
|
||||||
elif out_of_lane:
|
elif out_of_lane:
|
||||||
done_result = (True, {"out_of_lane" : True})
|
done_result = (True, {"out_of_lane" : True})
|
||||||
elif timeout:
|
elif timeout:
|
||||||
done_result = (True, {"timeout" : True})
|
if total_distance < minimal_distance:
|
||||||
|
done_result = (True, {"minimal_distance" : True})
|
||||||
|
else:
|
||||||
|
done_result = (True, {"timeout" : True})
|
||||||
|
|
||||||
simulation_state = metadrive_simulation_state(
|
simulation_state = metadrive_simulation_state(
|
||||||
running=False,
|
running=False,
|
||||||
|
|
|
@ -14,7 +14,7 @@ from openpilot.tools.sim.lib.camerad import W, H
|
||||||
|
|
||||||
|
|
||||||
class MetaDriveWorld(World):
|
class MetaDriveWorld(World):
|
||||||
def __init__(self, status_q, config, test_duration, test_run, dual_camera=False):
|
def __init__(self, status_q, config, test_duration, minimal_distance, test_run, dual_camera=False):
|
||||||
super().__init__(dual_camera)
|
super().__init__(dual_camera)
|
||||||
self.status_q = status_q
|
self.status_q = status_q
|
||||||
self.camera_array = Array(ctypes.c_uint8, W*H*3)
|
self.camera_array = Array(ctypes.c_uint8, W*H*3)
|
||||||
|
@ -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.op_engaged, test_duration, self.test_run))
|
self.vehicle_state_send, self.exit_event, self.op_engaged, test_duration, minimal_distance, 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"))
|
||||||
|
@ -105,7 +105,7 @@ class MetaDriveWorld(World):
|
||||||
if x_dist >= dist_threshold or y_dist >= dist_threshold: # position not the same during staying still, > threshold is considered moving
|
if x_dist >= dist_threshold or y_dist >= dist_threshold: # position not the same during staying still, > threshold is considered moving
|
||||||
self.distance_moved += x_dist + y_dist
|
self.distance_moved += x_dist + y_dist
|
||||||
|
|
||||||
time_check_threshold = 30
|
time_check_threshold = 7.5
|
||||||
current_time = time.monotonic()
|
current_time = time.monotonic()
|
||||||
since_last_check = current_time - self.last_check_timestamp
|
since_last_check = current_time - self.last_check_timestamp
|
||||||
if since_last_check >= time_check_threshold:
|
if since_last_check >= time_check_threshold:
|
||||||
|
|
|
@ -11,11 +11,9 @@ from openpilot.tools.sim.tests.test_sim_bridge import TestSimBridgeBase
|
||||||
@pytest.mark.filterwarnings("ignore::pyopencl.CompilerWarning") # Unimportant warning of non-empty compile log
|
@pytest.mark.filterwarnings("ignore::pyopencl.CompilerWarning") # Unimportant warning of non-empty compile log
|
||||||
class TestMetaDriveBridge(TestSimBridgeBase):
|
class TestMetaDriveBridge(TestSimBridgeBase):
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def setup_create_bridge(self, test_duration):
|
def setup_create_bridge(self):
|
||||||
# run bridge test for at least 60s, since not-moving check runs every 30s
|
self.test_duration = 15
|
||||||
if test_duration < 60:
|
self.minimal_distance = 10
|
||||||
test_duration = 60
|
|
||||||
self.test_duration = test_duration
|
|
||||||
|
|
||||||
def create_bridge(self):
|
def create_bridge(self):
|
||||||
return MetaDriveBridge(False, False, self.test_duration, True)
|
return MetaDriveBridge(False, False, self.test_duration, self.minimal_distance, True)
|
||||||
|
|
Loading…
Reference in New Issue