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:
|
||||
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
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
|
|
@ -50,12 +50,13 @@ def create_map(track_size=60):
|
|||
class MetaDriveBridge(SimulatorBridge):
|
||||
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)
|
||||
|
||||
self.should_render = False
|
||||
self.test_run = test_run
|
||||
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):
|
||||
sensors = {
|
||||
|
@ -90,4 +91,4 @@ class MetaDriveBridge(SimulatorBridge):
|
|||
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_HPR = Vec3(0, 0,0)
|
||||
|
||||
VEHICLE_STARTING_POS = [110, 4.5]
|
||||
|
||||
metadrive_simulation_state = namedtuple("metadrive_simulation_state", ["running", "done", "done_info"])
|
||||
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,
|
||||
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)
|
||||
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.vehicle.config["max_speed_km_h"] = 1000
|
||||
lane_idx_prev, _ = get_current_lane_info(env.vehicle)
|
||||
env.vehicle.set_position(VEHICLE_STARTING_POS)
|
||||
|
||||
simulation_state = metadrive_simulation_state(
|
||||
running=True,
|
||||
|
@ -98,6 +100,9 @@ def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera
|
|||
steer_ratio = 8
|
||||
vc = [0,0]
|
||||
|
||||
total_distance = 0
|
||||
prev_x_pos = VEHICLE_STARTING_POS[0]
|
||||
|
||||
while not exit_event.is_set():
|
||||
vehicle_state = metadrive_vehicle_state(
|
||||
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)
|
||||
|
||||
total_distance += abs(env.vehicle.position[0] - prev_x_pos)
|
||||
prev_x_pos = env.vehicle.position[0]
|
||||
|
||||
if controls_recv.poll(0):
|
||||
while controls_recv.poll(0):
|
||||
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:
|
||||
done_result = (True, {"out_of_lane" : True})
|
||||
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(
|
||||
running=False,
|
||||
|
|
|
@ -14,7 +14,7 @@ from openpilot.tools.sim.lib.camerad import W, H
|
|||
|
||||
|
||||
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)
|
||||
self.status_q = status_q
|
||||
self.camera_array = Array(ctypes.c_uint8, W*H*3)
|
||||
|
@ -41,7 +41,7 @@ class MetaDriveWorld(World):
|
|||
functools.partial(metadrive_process, dual_camera, config,
|
||||
self.camera_array, self.wide_camera_array, self.image_lock,
|
||||
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.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
|
||||
self.distance_moved += x_dist + y_dist
|
||||
|
||||
time_check_threshold = 30
|
||||
time_check_threshold = 7.5
|
||||
current_time = time.monotonic()
|
||||
since_last_check = current_time - self.last_check_timestamp
|
||||
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
|
||||
class TestMetaDriveBridge(TestSimBridgeBase):
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup_create_bridge(self, test_duration):
|
||||
# run bridge test for at least 60s, since not-moving check runs every 30s
|
||||
if test_duration < 60:
|
||||
test_duration = 60
|
||||
self.test_duration = test_duration
|
||||
def setup_create_bridge(self):
|
||||
self.test_duration = 15
|
||||
self.minimal_distance = 10
|
||||
|
||||
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