mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-30 19:33:45 +08:00
Simulator: add metadrive as optional simulator (#29935)
* Add metadrive sim * use monotonic * don't use cuda if it's not available * Cleanup metadrive patches * PR suggestions * fix typo old-commit-hash: e02519bb71beb4bf1f6b7f5def5a077886e00327
This commit is contained in:
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
import time
|
||||
import unittest
|
||||
|
||||
from openpilot.selfdrive.manager.helpers import unblock_stdout
|
||||
from openpilot.tools.sim.run_bridge import parse_args
|
||||
from openpilot.tools.sim.bridge.carla import CarlaBridge
|
||||
from openpilot.tools.sim.tests.test_sim_bridge import SIM_DIR, TestSimBridgeBase
|
||||
|
||||
|
||||
class TestCarlaBridge(TestSimBridgeBase):
|
||||
"""
|
||||
Tests need Carla simulator to run
|
||||
"""
|
||||
carla_process = None
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
# We want to make sure that carla_sim docker isn't still running.
|
||||
subprocess.run("docker rm -f carla_sim", shell=True, stderr=subprocess.PIPE, check=False)
|
||||
self.carla_process = subprocess.Popen("./start_carla.sh", cwd=SIM_DIR)
|
||||
|
||||
# Too many lagging messages in bridge.py can cause a crash. This prevents it.
|
||||
unblock_stdout()
|
||||
# Wait 10 seconds to startup carla
|
||||
time.sleep(10)
|
||||
|
||||
def create_bridge(self):
|
||||
return CarlaBridge(parse_args([]))
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
|
||||
# Stop carla simulator by removing docker container
|
||||
subprocess.run("docker rm -f carla_sim", shell=True, stderr=subprocess.PIPE, check=False)
|
||||
if self.carla_process is not None:
|
||||
self.carla_process.wait()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
import unittest
|
||||
|
||||
from openpilot.tools.sim.run_bridge import parse_args
|
||||
from openpilot.tools.sim.bridge.metadrive import MetaDriveBridge
|
||||
from openpilot.tools.sim.tests.test_sim_bridge import TestSimBridgeBase
|
||||
|
||||
|
||||
class TestMetaDriveBridge(TestSimBridgeBase):
|
||||
def create_bridge(self):
|
||||
return MetaDriveBridge(parse_args([]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Executable → Regular
+8
-29
@@ -1,40 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
import unittest
|
||||
import os
|
||||
|
||||
from multiprocessing import Queue
|
||||
|
||||
from cereal import messaging
|
||||
from openpilot.common.basedir import BASEDIR
|
||||
from openpilot.selfdrive.manager.helpers import unblock_stdout
|
||||
from openpilot.tools.sim.run_bridge import parse_args
|
||||
from openpilot.tools.sim.bridge.carla import CarlaBridge
|
||||
|
||||
CI = "CI" in os.environ
|
||||
|
||||
SIM_DIR = os.path.join(BASEDIR, "tools/sim")
|
||||
|
||||
class TestCarlaIntegration(unittest.TestCase):
|
||||
"""
|
||||
Tests need Carla simulator to run
|
||||
"""
|
||||
processes = None
|
||||
carla_process = None
|
||||
class TestSimBridgeBase(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
if cls is TestSimBridgeBase:
|
||||
raise unittest.SkipTest("Don't run this base class, run test_carla_bridge.py instead")
|
||||
|
||||
def setUp(self):
|
||||
self.processes = []
|
||||
|
||||
if not CI:
|
||||
# We want to make sure that carla_sim docker isn't still running.
|
||||
subprocess.run("docker rm -f carla_sim", shell=True, stderr=subprocess.PIPE, check=False)
|
||||
self.carla_process = subprocess.Popen("./start_carla.sh", cwd=SIM_DIR)
|
||||
|
||||
# Too many lagging messages in bridge.py can cause a crash. This prevents it.
|
||||
unblock_stdout()
|
||||
# Wait 10 seconds to startup carla
|
||||
time.sleep(10)
|
||||
|
||||
def test_engage(self):
|
||||
# Startup manager and bridge.py. Check processes are running, then engage and verify.
|
||||
p_manager = subprocess.Popen("./launch_openpilot.sh", cwd=SIM_DIR)
|
||||
@@ -42,7 +26,7 @@ class TestCarlaIntegration(unittest.TestCase):
|
||||
|
||||
sm = messaging.SubMaster(['controlsState', 'carEvents', 'managerState'])
|
||||
q = Queue()
|
||||
carla_bridge = CarlaBridge(parse_args([]))
|
||||
carla_bridge = self.create_bridge()
|
||||
p_bridge = carla_bridge.run(q, retries=10)
|
||||
self.processes.append(p_bridge)
|
||||
|
||||
@@ -99,11 +83,6 @@ class TestCarlaIntegration(unittest.TestCase):
|
||||
else:
|
||||
p.join(15)
|
||||
|
||||
# Stop carla simulator by removing docker container
|
||||
subprocess.run("docker rm -f carla_sim", shell=True, stderr=subprocess.PIPE, check=False)
|
||||
if self.carla_process is not None:
|
||||
self.carla_process.wait()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user