Skip to content

Commit c963f1a

Browse files
authored
Merge pull request #249 from JdeRobot/o3de-lanch
Add o3de
2 parents 43b836c + 023ff7c commit c963f1a

4 files changed

Lines changed: 173 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import sys
2+
from manager.manager.launcher.launcher_interface import ILauncher
3+
from manager.manager.docker_thread.docker_thread import DockerThread
4+
from manager.manager.vnc.vnc_server import Vnc_server
5+
from manager.libs.process_utils import (
6+
wait_for_process_to_start,
7+
check_gpu_acceleration,
8+
)
9+
import subprocess
10+
import time
11+
import os
12+
import stat
13+
from typing import List, Any
14+
from manager.ram_logging.log_manager import LogManager
15+
16+
class LauncherO3de(ILauncher):
17+
running: bool = False
18+
threads: List[Any] = []
19+
acceptsMsgs: bool = False
20+
gz_vnc: Any = Vnc_server()
21+
22+
def run(self, config_file, callback):
23+
24+
# process_name = "gz sim"
25+
# wait_for_process_to_start(process_name, timeout=60)
26+
27+
self.running = True
28+
29+
def check_device(self, device_path):
30+
try:
31+
return stat.S_ISCHR(os.lstat(device_path)[stat.ST_MODE])
32+
except:
33+
return False
34+
35+
def is_running(self):
36+
return self.running
37+
38+
def terminate(self):
39+
self.running = False
40+
41+
def died(self):
42+
pass
43+
44+
def pause(self):
45+
self.running = False
46+
pass
47+
48+
def unpause(self):
49+
self.running = True
50+
pass
51+
52+
def reset(self):
53+
#TODO: add reset
54+
pass
55+
56+
def get_dri_path(self):
57+
directory_path = "/dev/dri"
58+
dri_path = ""
59+
if os.path.exists(directory_path) and os.path.isdir(directory_path):
60+
files = os.listdir(directory_path)
61+
if "card1" in files:
62+
dri_path = os.path.join("/dev/dri", os.environ.get("DRI_NAME", "card1"))
63+
else:
64+
dri_path = os.path.join("/dev/dri", os.environ.get("DRI_NAME", "card0"))
65+
return dri_path
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import os
2+
import sys
3+
from typing import List, Any
4+
import time
5+
import stat
6+
7+
from manager.manager.launcher.launcher_interface import ILauncher, LauncherException
8+
from manager.manager.docker_thread.docker_thread import DockerThread
9+
from manager.manager.vnc.vnc_server import Vnc_server
10+
from manager.libs.process_utils import (
11+
wait_for_process_to_start,
12+
check_gpu_acceleration,
13+
)
14+
import subprocess
15+
16+
import logging
17+
18+
class LauncherO3deApi(ILauncher):
19+
display: str
20+
internal_port: int
21+
external_port: int
22+
height: int
23+
width: int
24+
type: str
25+
module: str
26+
launch_file: str
27+
threads: List[Any] = []
28+
gz_vnc: Any = Vnc_server()
29+
30+
def run(self, callback):
31+
DRI_PATH = self.get_dri_path()
32+
ACCELERATION_ENABLED = self.check_device(DRI_PATH)
33+
34+
#TODO: add run here
35+
36+
xserver_cmd = f"/usr/bin/Xorg -quiet -noreset +extension GLX +extension RANDR +extension RENDER -logfile ./xdummy.log -config ./xorg.conf :0"
37+
xserver_thread = DockerThread(xserver_cmd)
38+
xserver_thread.start()
39+
self.threads.append(xserver_thread)
40+
41+
LevelSelect=f'echo "LoadLevel Levels/{self.launch_file}" > data/workspace/ROS2Demo/autoexec.cfg'
42+
43+
LevelSelect_thread = DockerThread(LevelSelect)
44+
LevelSelect_thread.start()
45+
self.threads.append(LevelSelect_thread)
46+
47+
if ACCELERATION_ENABLED:
48+
# Starts xserver, x11vnc and novnc
49+
self.gz_vnc.start_vnc_gpu(
50+
self.display, self.internal_port, self.external_port, DRI_PATH
51+
)
52+
# Write display config
53+
o3decmd = f'export DISPLAY={self.display}; data/workspace/ROS2Demo/build/linux/bin/profile/ROS2Demo.GameLauncher --forceAdapter="NVIDIA"'
54+
else:
55+
# Starts xserver, x11vnc and novnc
56+
self.gz_vnc.start_vnc(self.display, self.internal_port, self.external_port)
57+
# Write display config
58+
o3decmd = f'export DISPLAY={self.display}; data/workspace/ROS2Demo/build/linux/bin/profile/ROS2Demo.GameLauncher --forceAdapter="NVIDIA"'
59+
60+
gzclient_thread = DockerThread(o3decmd)
61+
gzclient_thread.start()
62+
self.threads.append(gzclient_thread)
63+
64+
process_name = 'ROS2Demo.GameLauncher'
65+
wait_for_process_to_start(process_name, timeout=360)
66+
67+
def terminate(self):
68+
self.gz_vnc.terminate()
69+
if self.threads is not None:
70+
for thread in self.threads:
71+
if thread.is_alive():
72+
thread.terminate()
73+
thread.join()
74+
self.threads.remove(thread)
75+
76+
# TODO: processes to kill
77+
to_kill = ["ROS2Demo.GameLauncher"]
78+
79+
kill_cmd = "pkill -9 -f "
80+
for i in to_kill:
81+
cmd = kill_cmd + i
82+
subprocess.call(
83+
cmd,
84+
shell=True,
85+
stdout=subprocess.PIPE,
86+
bufsize=1024,
87+
universal_newlines=True,
88+
)

manager/manager/launcher/launcher_tools.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"external_port": 6080,
3333
"internal_port": 5900,
3434
},
35+
"o3de": {
36+
"type": "module",
37+
"module": "o3de",
38+
},
3539
"rviz": {
3640
"module": "rviz",
3741
"display": ":3",
@@ -61,6 +65,7 @@
6165
simulator = {
6266
"gazebo": {"tool": "gazebo"},
6367
"gz": {"tool": "gzsim"},
68+
"o3de": {"tool": "o3de"},
6469
}
6570

6671

manager/manager/launcher/launcher_world.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@
2626
}
2727
],
2828
},
29+
"o3de": {
30+
"2": [
31+
{
32+
"width": 1024,
33+
"height": 768,
34+
"display": ":2",
35+
"external_port": 6080,
36+
"internal_port": 5900,
37+
"type": "o3de",
38+
"module": "o3de_api",
39+
"parameters": [],
40+
"launch_file": [],
41+
}
42+
],
43+
},
2944
"physical": {},
3045
}
3146

0 commit comments

Comments
 (0)