-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathlauncher_tools.py
More file actions
149 lines (130 loc) · 4.1 KB
/
launcher_tools.py
File metadata and controls
149 lines (130 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from robotics_application_manager.libs import get_class, class_from_module
from typing import Optional
from pydantic import BaseModel
from robotics_application_manager import LogManager
from .launcher_interface import ILauncher
tools = {
"console": {
"module": "console",
"display": ":1",
"external_port": 6082,
"internal_port": 5901,
},
"gazebo": {
"type": "module",
"width": 1024,
"height": 768,
"module": "gazebo",
"display": ":2",
"external_port": 6080,
"internal_port": 5900,
},
"gzsim": {
"type": "module",
"width": 1024,
"height": 768,
"module": "gzsim",
"display": ":2",
"external_port": 6080,
"internal_port": 5900,
},
"o3de": {
"type": "module",
"module": "o3de",
},
"rviz": {
"module": "rviz",
"display": ":3",
"external_port": 6081,
"internal_port": 5902,
},
"web_gui": {
"type": "module",
"module": "web_gui",
"internal_port": 2303,
"consumer": None,
},
"state_monitor": {
"type": "module",
"module": "state_monitor",
"file": "/tmp/tree_state",
"consumer": None,
},
"webcam": {
"type": "module",
"module": None,
"internal_port": 2303,
"consumer": None,
},
"video": {
"type": "module",
"module": None,
"internal_port": 2303,
"consumer": None,
},
}
simulator = {
"gazebo": {"tool": "gazebo"},
"gz": {"tool": "gzsim"},
"o3de": {"tool": "o3de"},
}
class LauncherTools(BaseModel):
module: str = ".".join(__name__.split(".")[:-1])
world_type: Optional[str] = None
tools: list[str]
tools_config: Optional[dict] = None
launchers: Optional[ILauncher] = []
def run(self, consumer):
for tool in self.tools:
if tool == "simulator":
if self.world_type is None or self.world_type == "physical":
continue
tool = simulator[self.world_type]["tool"]
module = tools[tool]
if module["module"] is None:
continue
launcher = self.launch_module(tool, module, consumer)
self.launchers.append(launcher)
def terminate(self):
LogManager.logger.info("Terminating tools launcher")
for launcher in self.launchers:
if launcher.is_running():
launcher.terminate()
self.launchers = []
def launch_module(self, name, configuration, consumer):
def process_terminated(name, exit_code):
LogManager.logger.info(
f"LauncherEngine: {name} exited with code {exit_code}"
)
if self.terminated_callback is not None:
self.terminated_callback(name, exit_code)
# Replace consumer
if "consumer" in configuration:
configuration["consumer"] = consumer
launcher_module_name = configuration["module"]
launcher_module = f"{self.module}.launcher_{launcher_module_name}.Launcher{class_from_module(launcher_module_name)}"
launcher_class = get_class(launcher_module)
config = None
if self.tools_config is not None and name in self.tools_config:
config = self.tools_config[name]
launcher = launcher_class.from_config(launcher_class, configuration)
launcher.run(config, process_terminated)
return launcher
def pause(self):
for launcher in self.launchers:
launcher.pause()
def unpause(self):
for launcher in self.launchers:
launcher.unpause()
def reset(self):
for launcher in self.launchers:
launcher.reset()
def pass_msg(self, data):
for launcher in self.launchers:
if launcher.acceptsMsgs:
launcher.get_msg(data)
def launch_command(self, configuration):
pass
class LauncherToolsException(Exception):
def __init__(self, message):
super(LauncherToolsException, self).__init__(message)