|
| 1 | +from manager.manager.launcher.launcher_interface import ILauncher |
| 2 | +from manager.manager.docker_thread.docker_thread import DockerThread |
| 3 | +from manager.manager.vnc.vnc_server import Vnc_server |
| 4 | +from manager.libs.process_utils import check_gpu_acceleration |
| 5 | +import os |
| 6 | +import stat |
| 7 | +from typing import List, Any |
| 8 | + |
| 9 | + |
| 10 | +class LauncherRviz(ILauncher): |
| 11 | + display: str |
| 12 | + internal_port: int |
| 13 | + external_port: int |
| 14 | + running: bool = False |
| 15 | + acceptsMsgs: bool = False |
| 16 | + threads: List[Any] = [] |
| 17 | + console_vnc: Any = Vnc_server() |
| 18 | + |
| 19 | + def run(self, config_file, callback): |
| 20 | + DRI_PATH = self.get_dri_path() |
| 21 | + ACCELERATION_ENABLED = False |
| 22 | + |
| 23 | + if ACCELERATION_ENABLED: |
| 24 | + self.console_vnc.start_vnc_gpu( |
| 25 | + self.display, self.internal_port, self.external_port, DRI_PATH |
| 26 | + ) |
| 27 | + # Write display config and start the console |
| 28 | + console_cmd = f"export VGL_DISPLAY={DRI_PATH}; export DISPLAY={self.display}; vglrun ros2 run rviz2 rviz2" |
| 29 | + else: |
| 30 | + self.console_vnc.start_vnc( |
| 31 | + self.display, self.internal_port, self.external_port |
| 32 | + ) |
| 33 | + # Write display config and start the console |
| 34 | + console_cmd = f"export DISPLAY={self.display};ros2 run rviz2 rviz2" |
| 35 | + |
| 36 | + console_thread = DockerThread(console_cmd) |
| 37 | + console_thread.start() |
| 38 | + self.threads.append(console_thread) |
| 39 | + |
| 40 | + self.running = True |
| 41 | + |
| 42 | + def pause(self): |
| 43 | + pass |
| 44 | + |
| 45 | + def unpause(self): |
| 46 | + pass |
| 47 | + |
| 48 | + def reset(self): |
| 49 | + pass |
| 50 | + |
| 51 | + def is_running(self): |
| 52 | + return self.running |
| 53 | + |
| 54 | + def terminate(self): |
| 55 | + self.console_vnc.terminate() |
| 56 | + for thread in self.threads: |
| 57 | + if thread.is_alive(): |
| 58 | + thread.terminate() |
| 59 | + thread.join() |
| 60 | + self.threads.remove(thread) |
| 61 | + self.running = False |
| 62 | + |
| 63 | + def died(self): |
| 64 | + pass |
0 commit comments