mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2025-12-17 13:01:12 +00:00
feat: vis 2d for plr
This commit is contained in:
@@ -70,16 +70,20 @@ def parse_args():
|
|||||||
help="信息页web服务的启动端口",
|
help="信息页web服务的启动端口",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--open_browser",
|
"--disable_browser",
|
||||||
type=bool,
|
action='store_true',
|
||||||
default=True,
|
help="是否在启动时关闭信息页",
|
||||||
help="是否在启动时打开信息页",
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--2d_vis",
|
||||||
|
action='store_true',
|
||||||
|
help="是否在pylabrobot实例启动时,同时启动可视化",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--visual",
|
"--visual",
|
||||||
choices=["rviz", "web", "deck", "disable"],
|
choices=["rviz", "web", "disable"],
|
||||||
default="disable",
|
default="disable",
|
||||||
help="选择可视化工具: rviz, web, deck(2D bird view)",
|
help="选择可视化工具: rviz, web",
|
||||||
)
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
@@ -111,6 +115,7 @@ def main():
|
|||||||
machine_name = os.popen("hostname").read().strip()
|
machine_name = os.popen("hostname").read().strip()
|
||||||
machine_name = "".join([c if c.isalnum() or c == "_" else "_" for c in machine_name])
|
machine_name = "".join([c if c.isalnum() or c == "_" else "_" for c in machine_name])
|
||||||
BasicConfig.machine_name = machine_name
|
BasicConfig.machine_name = machine_name
|
||||||
|
BasicConfig.vis_2d_enable = args_dict["2d_vis"]
|
||||||
|
|
||||||
from unilabos.resources.graphio import (
|
from unilabos.resources.graphio import (
|
||||||
read_node_link_json,
|
read_node_link_json,
|
||||||
@@ -186,7 +191,7 @@ def main():
|
|||||||
resource_visualization = ResourceVisualization(devices_and_resources, args_dict["resources_config"] ,enable_rviz=enable_rviz)
|
resource_visualization = ResourceVisualization(devices_and_resources, args_dict["resources_config"] ,enable_rviz=enable_rviz)
|
||||||
args_dict["resources_mesh_config"] = resource_visualization.resource_model
|
args_dict["resources_mesh_config"] = resource_visualization.resource_model
|
||||||
start_backend(**args_dict)
|
start_backend(**args_dict)
|
||||||
server_thread = threading.Thread(target=start_server)
|
server_thread = threading.Thread(target=start_server, args=(not args_dict["disable_browser"],))
|
||||||
server_thread.start()
|
server_thread.start()
|
||||||
asyncio.set_event_loop(asyncio.new_event_loop())
|
asyncio.set_event_loop(asyncio.new_event_loop())
|
||||||
resource_visualization.start()
|
resource_visualization.start()
|
||||||
@@ -194,10 +199,10 @@ def main():
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
start_backend(**args_dict)
|
start_backend(**args_dict)
|
||||||
start_server()
|
start_server(open_browser=not args_dict["disable_browser"])
|
||||||
else:
|
else:
|
||||||
start_backend(**args_dict)
|
start_backend(**args_dict)
|
||||||
start_server()
|
start_server(open_browser=not args_dict["disable_browser"])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class BasicConfig:
|
|||||||
is_host_mode = True # 从registry.py移动过来
|
is_host_mode = True # 从registry.py移动过来
|
||||||
slave_no_host = False # 是否跳过rclient.wait_for_service()
|
slave_no_host = False # 是否跳过rclient.wait_for_service()
|
||||||
machine_name = "undefined"
|
machine_name = "undefined"
|
||||||
|
vis_2d_enable = False
|
||||||
|
|
||||||
|
|
||||||
# MQTT配置
|
# MQTT配置
|
||||||
|
|||||||
@@ -225,6 +225,14 @@ class PyLabRobotCreator(DeviceClassCreator[T]):
|
|||||||
from unilabos.ros.nodes.base_device_node import ROS2DeviceNode
|
from unilabos.ros.nodes.base_device_node import ROS2DeviceNode
|
||||||
def done_cb(*args):
|
def done_cb(*args):
|
||||||
logger.debug(f"PyLabRobot设备实例 {self.device_instance} 设置完成")
|
logger.debug(f"PyLabRobot设备实例 {self.device_instance} 设置完成")
|
||||||
|
from unilabos.config.config import BasicConfig
|
||||||
|
if BasicConfig.vis_2d_enable:
|
||||||
|
from pylabrobot.visualizer.visualizer import Visualizer
|
||||||
|
vis = Visualizer(resource=self.device_instance, open_browser=True)
|
||||||
|
def vis_done_cb(*args):
|
||||||
|
logger.info(f"PyLabRobot设备实例开启了Visualizer {self.device_instance}")
|
||||||
|
ROS2DeviceNode.run_async_func(vis.setup).add_done_callback(vis_done_cb)
|
||||||
|
logger.debug(f"PyLabRobot设备实例提交开启Visualizer {self.device_instance}")
|
||||||
ROS2DeviceNode.run_async_func(getattr(self.device_instance, "setup")).add_done_callback(done_cb)
|
ROS2DeviceNode.run_async_func(getattr(self.device_instance, "setup")).add_done_callback(done_cb)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user