diff --git a/manager/manager/launcher/launcher_o3de.py b/manager/manager/launcher/launcher_o3de.py new file mode 100644 index 0000000..f633dc0 --- /dev/null +++ b/manager/manager/launcher/launcher_o3de.py @@ -0,0 +1,65 @@ +import sys +from manager.manager.launcher.launcher_interface import ILauncher +from manager.manager.docker_thread.docker_thread import DockerThread +from manager.manager.vnc.vnc_server import Vnc_server +from manager.libs.process_utils import ( + wait_for_process_to_start, + check_gpu_acceleration, +) +import subprocess +import time +import os +import stat +from typing import List, Any +from manager.ram_logging.log_manager import LogManager + +class LauncherO3de(ILauncher): + running: bool = False + threads: List[Any] = [] + acceptsMsgs: bool = False + gz_vnc: Any = Vnc_server() + + def run(self, config_file, callback): + + # process_name = "gz sim" + # wait_for_process_to_start(process_name, timeout=60) + + self.running = True + + def check_device(self, device_path): + try: + return stat.S_ISCHR(os.lstat(device_path)[stat.ST_MODE]) + except: + return False + + def is_running(self): + return self.running + + def terminate(self): + self.running = False + + def died(self): + pass + + def pause(self): + self.running = False + pass + + def unpause(self): + self.running = True + pass + + def reset(self): + #TODO: add reset + pass + + def get_dri_path(self): + directory_path = "/dev/dri" + dri_path = "" + if os.path.exists(directory_path) and os.path.isdir(directory_path): + files = os.listdir(directory_path) + if "card1" in files: + dri_path = os.path.join("/dev/dri", os.environ.get("DRI_NAME", "card1")) + else: + dri_path = os.path.join("/dev/dri", os.environ.get("DRI_NAME", "card0")) + return dri_path diff --git a/manager/manager/launcher/launcher_o3de_api.py b/manager/manager/launcher/launcher_o3de_api.py new file mode 100644 index 0000000..b5c8697 --- /dev/null +++ b/manager/manager/launcher/launcher_o3de_api.py @@ -0,0 +1,88 @@ +import os +import sys +from typing import List, Any +import time +import stat + +from manager.manager.launcher.launcher_interface import ILauncher, LauncherException +from manager.manager.docker_thread.docker_thread import DockerThread +from manager.manager.vnc.vnc_server import Vnc_server +from manager.libs.process_utils import ( + wait_for_process_to_start, + check_gpu_acceleration, +) +import subprocess + +import logging + +class LauncherO3deApi(ILauncher): + display: str + internal_port: int + external_port: int + height: int + width: int + type: str + module: str + launch_file: str + threads: List[Any] = [] + gz_vnc: Any = Vnc_server() + + def run(self, callback): + DRI_PATH = self.get_dri_path() + ACCELERATION_ENABLED = self.check_device(DRI_PATH) + + #TODO: add run here + + xserver_cmd = f"/usr/bin/Xorg -quiet -noreset +extension GLX +extension RANDR +extension RENDER -logfile ./xdummy.log -config ./xorg.conf :0" + xserver_thread = DockerThread(xserver_cmd) + xserver_thread.start() + self.threads.append(xserver_thread) + + LevelSelect=f'echo "LoadLevel Levels/{self.launch_file}" > data/workspace/ROS2Demo/autoexec.cfg' + + LevelSelect_thread = DockerThread(LevelSelect) + LevelSelect_thread.start() + self.threads.append(LevelSelect_thread) + + if ACCELERATION_ENABLED: + # Starts xserver, x11vnc and novnc + self.gz_vnc.start_vnc_gpu( + self.display, self.internal_port, self.external_port, DRI_PATH + ) + # Write display config + o3decmd = f'export DISPLAY={self.display}; data/workspace/ROS2Demo/build/linux/bin/profile/ROS2Demo.GameLauncher --forceAdapter="NVIDIA"' + else: + # Starts xserver, x11vnc and novnc + self.gz_vnc.start_vnc(self.display, self.internal_port, self.external_port) + # Write display config + o3decmd = f'export DISPLAY={self.display}; data/workspace/ROS2Demo/build/linux/bin/profile/ROS2Demo.GameLauncher --forceAdapter="NVIDIA"' + + gzclient_thread = DockerThread(o3decmd) + gzclient_thread.start() + self.threads.append(gzclient_thread) + + process_name = 'ROS2Demo.GameLauncher' + wait_for_process_to_start(process_name, timeout=360) + + def terminate(self): + self.gz_vnc.terminate() + if self.threads is not None: + for thread in self.threads: + if thread.is_alive(): + thread.terminate() + thread.join() + self.threads.remove(thread) + + # TODO: processes to kill + to_kill = ["ROS2Demo.GameLauncher"] + + kill_cmd = "pkill -9 -f " + for i in to_kill: + cmd = kill_cmd + i + subprocess.call( + cmd, + shell=True, + stdout=subprocess.PIPE, + bufsize=1024, + universal_newlines=True, + ) diff --git a/manager/manager/launcher/launcher_tools.py b/manager/manager/launcher/launcher_tools.py index 416b159..b7dbf21 100644 --- a/manager/manager/launcher/launcher_tools.py +++ b/manager/manager/launcher/launcher_tools.py @@ -11,7 +11,7 @@ "console": { "module": "console", "display": ":1", - "external_port": 1108, + "external_port": 6082, "internal_port": 5901, }, "gazebo": { @@ -32,6 +32,10 @@ "external_port": 6080, "internal_port": 5900, }, + "o3de": { + "type": "module", + "module": "o3de", + }, "rviz": { "module": "rviz", "display": ":3", @@ -61,6 +65,7 @@ simulator = { "gazebo": {"tool": "gazebo"}, "gz": {"tool": "gzsim"}, + "o3de": {"tool": "o3de"}, } diff --git a/manager/manager/launcher/launcher_world.py b/manager/manager/launcher/launcher_world.py index eeb23bc..d9ba862 100644 --- a/manager/manager/launcher/launcher_world.py +++ b/manager/manager/launcher/launcher_world.py @@ -26,6 +26,21 @@ } ], }, + "o3de": { + "2": [ + { + "width": 1024, + "height": 768, + "display": ":2", + "external_port": 6080, + "internal_port": 5900, + "type": "o3de", + "module": "o3de_api", + "parameters": [], + "launch_file": [], + } + ], + }, "physical": {}, }