Skip to content

Commit

Permalink
New code style and CPU proper waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarMrZ committed Mar 24, 2024
1 parent ee8e479 commit f5b3800
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 145 deletions.
20 changes: 11 additions & 9 deletions manager/manager/launcher/launcher_console.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from src.manager.manager.launcher.launcher_interface import ILauncher
from src.manager.manager.docker_thread.docker_thread import DockerThread
from src.manager.manager.vnc.vnc_server import Vnc_server
from src.manager.libs.process_utils import check_gpu_acceleration
from src.manager.libs.process_utils import check_gpu_acceleration
import os
import stat
from typing import List, Any
Expand All @@ -11,22 +11,24 @@ class LauncherConsole(ILauncher):
display: str
internal_port: int
external_port: int
running:bool = False
running: bool = False
threads: List[Any] = []
console_vnc: Any = Vnc_server()

def run(self, callback):
DRI_PATH = os.path.join("/dev/dri", os.environ.get("DRI_NAME", "card0"))
ACCELERATION_ENABLED = False



if (ACCELERATION_ENABLED):
self.console_vnc.start_vnc_gpu(self.display, self.internal_port, self.external_port,DRI_PATH)
if ACCELERATION_ENABLED:
self.console_vnc.start_vnc_gpu(
self.display, self.internal_port, self.external_port, DRI_PATH
)
# Write display config and start the console
console_cmd = f"export VGL_DISPLAY={DRI_PATH}; export DISPLAY={self.display}; vglrun xterm -fullscreen -sb -fa 'Monospace' -fs 10 -bg black -fg white"
else:
self.console_vnc.start_vnc(self.display, self.internal_port, self.external_port)
self.console_vnc.start_vnc(
self.display, self.internal_port, self.external_port
)
# Write display config and start the console
console_cmd = f"export DISPLAY={self.display};xterm -geometry 100x10+0+0 -fa 'Monospace' -fs 10 -bg black -fg white"

Expand All @@ -35,7 +37,7 @@ def run(self, callback):
self.threads.append(console_thread)

self.running = True

def check_device(self, device_path):
try:
return stat.S_ISCHR(os.lstat(device_path)[stat.ST_MODE])
Expand All @@ -53,4 +55,4 @@ def terminate(self):
self.running = False

def died(self):
pass
pass
27 changes: 13 additions & 14 deletions manager/manager/launcher/launcher_gazebo_view.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from src.manager.manager.launcher.launcher_interface import ILauncher
from src.manager.manager.docker_thread.docker_thread import DockerThread
from src.manager.manager.vnc.vnc_server import Vnc_server
from src.manager.libs.process_utils import wait_for_process_to_start, check_gpu_acceleration
from src.manager.libs.process_utils import (
wait_for_process_to_start,
check_gpu_acceleration,
)
import subprocess
import time
import os
Expand Down Expand Up @@ -29,17 +32,15 @@ def run(self, callback):
if ACCELERATION_ENABLED:
# Starts xserver, x11vnc and novnc
self.gz_vnc.start_vnc_gpu(
self.display, self.internal_port, self.external_port, DRI_PATH)
self.display, self.internal_port, self.external_port, DRI_PATH
)
# Write display config and start gzclient
gzclient_cmd = (
f"export DISPLAY={self.display}; {gzclient_config_cmds} export VGL_DISPLAY={DRI_PATH}; vglrun gzclient --verbose")
gzclient_cmd = f"export DISPLAY={self.display}; {gzclient_config_cmds} export VGL_DISPLAY={DRI_PATH}; vglrun gzclient --verbose"
else:
# Starts xserver, x11vnc and novnc
self.gz_vnc.start_vnc(
self.display, self.internal_port, self.external_port)
self.gz_vnc.start_vnc(self.display, self.internal_port, self.external_port)
# Write display config and start gzclient
gzclient_cmd = (
f"export DISPLAY={self.display}; {gzclient_config_cmds} gzclient --verbose")
gzclient_cmd = f"export DISPLAY={self.display}; {gzclient_config_cmds} gzclient --verbose"

gzclient_thread = DockerThread(gzclient_cmd)
gzclient_thread.start()
Expand Down Expand Up @@ -70,14 +71,12 @@ def died(self):
pass

def get_dri_path(self):
directory_path = '/dev/dri'
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"))
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"))
dri_path = os.path.join("/dev/dri", os.environ.get("DRI_NAME", "card0"))
return dri_path
155 changes: 87 additions & 68 deletions manager/manager/launcher/launcher_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,80 +10,98 @@

visualization = {
"none": [],
"console": [{"module": "console",
"display": ":1",
"external_port": 1108,
"internal_port": 5901}],
"gazebo_gra": [{
"type": "module",
"module": "console",
"display": ":1",
"external_port": 1108,
"internal_port": 5901},
"console": [
{
"type": "module",
"width": 1024,
"height": 768,
"module": "gazebo_view",
"display": ":2",
"external_port": 6080,
"internal_port": 5900
},
"module": "console",
"display": ":1",
"external_port": 1108,
"internal_port": 5901,
}
],
"gazebo_gra": [
{
"type": "module",
"module": "console",
"display": ":1",
"external_port": 1108,
"internal_port": 5901,
},
{
"type": "module",
"width": 1024,
"height": 768,
"module": "gazebo_view",
"display": ":2",
"external_port": 6080,
"internal_port": 5900,
},
{
"type": "module",
"width": 1024,
"height": 768,
"module": "robot_display_view",
"display": ":3",
"external_port": 2303,
"internal_port": 5902,
},
],
"gazebo_rae": [
{
"type": "module",
"module": "console",
"display": ":1",
"external_port": 1108,
"internal_port": 5901,
},
{
"type": "module",
"width": 1024,
"height": 768,
"module": "gazebo_view",
"display": ":2",
"external_port": 6080,
"internal_port": 5900,
},
],
"physic_gra": [
{
"module": "console",
"display": ":1",
"external_port": 1108,
"internal_port": 5901,
},
{
"type": "module",
"width": 1024,
"height": 768,
"module": "robot_display_view",
"display": ":2",
"external_port": 2303,
"internal_port": 5902,
},
],
"physic_rae": [
{
"module": "console",
"display": ":1",
"external_port": 1108,
"internal_port": 5901,
},
{
"type": "module",
"width": 1024,
"height": 768,
"module": "robot_display_view",
"display": ":3",
"external_port": 2303,
"internal_port": 5902
}
"type": "module",
"width": 1024,
"height": 768,
"module": "robot_display_view",
"display": ":2",
"external_port": 2303,
"internal_port": 5902,
},
],
"gazebo_rae": [{"type": "module",
"module": "console",
"display": ":1",
"external_port": 1108,
"internal_port": 5901},
{
"type": "module",
"width": 1024,
"height": 768,
"module": "gazebo_view",
"display": ":2",
"external_port": 6080,
"internal_port": 5900
}],
"physic_gra": [{"module": "console",
"display": ":1",
"external_port": 1108,
"internal_port": 5901},
{
"type": "module",
"width": 1024,
"height": 768,
"module": "robot_display_view",
"display": ":2",
"external_port": 2303,
"internal_port": 5902
}],
"physic_rae": [{"module": "console",
"display": ":1",
"external_port": 1108,
"internal_port": 5901},
{
"type": "module",
"width": 1024,
"height": 768,
"module": "robot_display_view",
"display": ":2",
"external_port": 2303,
"internal_port": 5902
}]
}


class LauncherVisualization(BaseModel):
module: str = '.'.join(__name__.split('.')[:-1])
module: str = ".".join(__name__.split(".")[:-1])
visualization: str
launchers: Optional[ILauncher] = []

Expand All @@ -102,7 +120,8 @@ def terminate(self):
def launch_module(self, configuration):
def process_terminated(name, exit_code):
LogManager.logger.info(
f"LauncherEngine: {name} exited with code {exit_code}")
f"LauncherEngine: {name} exited with code {exit_code}"
)
if self.terminated_callback is not None:
self.terminated_callback(name, exit_code)

Expand Down
79 changes: 46 additions & 33 deletions manager/manager/launcher/launcher_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,56 @@
from src.manager.manager.launcher.launcher_interface import ILauncher

worlds = {
"gazebo":
{"1": [{
"type": "module",
"module": "ros_api",
"parameters": [],
"launch_file": [],
}], "2": [{
"type": "module",
"module": "ros2_api",
"parameters": [],
"launch_file": [],
}]},
"drones":
{"1": [{
"type": "module",
"module": "drones",
"resource_folders": [],
"model_folders": [],
"plugin_folders": [],
"parameters": [],
"launch_file": [],
}], "2": [{
"type": "module",
"module": "drones_ros2",
"resource_folders": [],
"model_folders": [],
"plugin_folders": [],
"parameters": [],
"launch_file": [],
}]},
"physical": {}
"gazebo": {
"1": [
{
"type": "module",
"module": "ros_api",
"parameters": [],
"launch_file": [],
}
],
"2": [
{
"type": "module",
"module": "ros2_api",
"parameters": [],
"launch_file": [],
}
],
},
"drones": {
"1": [
{
"type": "module",
"module": "drones",
"resource_folders": [],
"model_folders": [],
"plugin_folders": [],
"parameters": [],
"launch_file": [],
}
],
"2": [
{
"type": "module",
"module": "drones_ros2",
"resource_folders": [],
"model_folders": [],
"plugin_folders": [],
"parameters": [],
"launch_file": [],
}
],
},
"physical": {},
}


class LauncherWorld(BaseModel):
world: str
launch_file_path: str
module: str = '.'.join(__name__.split('.')[:-1])
module: str = ".".join(__name__.split(".")[:-1])
ros_version: int = get_ros_version()
launchers: Optional[ILauncher] = []

Expand All @@ -63,7 +75,8 @@ def terminate(self):
def launch_module(self, configuration):
def process_terminated(name, exit_code):
LogManager.logger.info(
f"LauncherEngine: {name} exited with code {exit_code}")
f"LauncherEngine: {name} exited with code {exit_code}"
)
if self.terminated_callback is not None:
self.terminated_callback(name, exit_code)

Expand Down
Loading

0 comments on commit f5b3800

Please sign in to comment.