Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 110 additions & 7 deletions test/experiments/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"id": "Gripper1",
"name": "假夹爪",
"children": [
"Plate1"
],
"parent": null,
"type": "device",
"class": "gripper.mock",
"position": {
"x": 620.6111111111111,
"y": 171,
"x": 0,
"y": 0,
"z": 0
},
"config": {
Expand All @@ -23,18 +24,120 @@
"name": "Plate1",
"children": [
],
"parent": null,
"parent": "Gripper1",
"type": "plate",
"class": "nest_96_wellplate_2ml_deep",
"class": "nest_96_wellplate_100ul_pcr_full_skirt",
"position": {
"x": 620.6111111111111,
"y": 171,
"z": 0
"x": 0,
"y": 0,
"z": 69
},
"config": {
},
"data": {
}
},
{
"id": "ot_joint_publisher",
"name": "ot_joint_publisher",
"sample_id": null,
"children": [

],
"parent": null,
"type": "device",
"class": "lh_joint_publisher",
"position": {
"x": 0,
"y": 0,
"z": 0
},
"config": {
"lh_id":"deck",
"joint_config":
{
"joint_names":[
"first_joint",
"second_joint",
"third_joint",
"fourth_joint"
],
"y":{
"first_joint":{
"factor":-1,
"offset":0.0
}
},
"x":{
"second_joint":{
"factor":-1,
"offset":0.0
}
},
"z":{
"third_joint":{
"factor":1,
"offset":0.0
},
"fourth_joint":{
"factor":1,
"offset":0.0
}
}
}
},
"data": {}
},
{
"id": "ot_joint_publisher",
"name": "ot_joint_publisher",
"sample_id": null,
"children": [

],
"parent": null,
"type": "device",
"class": "lh_joint_publisher",
"position": {
"x": 0,
"y": 0,
"z": 0
},
"config": {
"lh_id":"deck",
"joint_config":
{
"joint_names":[
"first_joint",
"second_joint",
"third_joint",
"fourth_joint"
],
"y":{
"first_joint":{
"factor":-1,
"offset":0.0
}
},
"x":{
"second_joint":{
"factor":-1,
"offset":0.0
}
},
"z":{
"third_joint":{
"factor":1,
"offset":0.0
},
"fourth_joint":{
"factor":1,
"offset":0.0
}
}
}
},
"data": {}
}
],
"links": [
Expand Down
135 changes: 135 additions & 0 deletions test/experiments/test_copy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"nodes": [
{
"id": "PLR_STATION",
"name": "PLR_LH_TEST",
"parent": null,
"type": "device",
"class": "liquid_handler",
"position": {
"x": 620.6111111111111,
"y": 171,
"z": 0
},
"config": {
"data": {
"children": [
{
"_resource_child_name": "deck",
"_resource_type": "pylabrobot.resources.opentrons.deck:OTDeck"
}
],
"backend": {
"type": "LiquidHandlerRvizBackend"
}
}
},
"data": {},
"children": [
"deck"
]
},
{
"id": "deck",
"name": "deck",
"sample_id": null,
"children": [
"teaching_carrier"
],
"parent": "PLR_STATION",
"type": "deck",
"class": "OTDeck",
"position": {
"x": 0,
"y": 0,
"z": 0
},
"config": {
"type": "OTDeck",
"with_trash": false,
"rotation": {
"x": 0,
"y": 0,
"z": 0,
"type": "Rotation"
}
},
"data": {}
},

{
"id": "teaching_carrier",
"name": "teaching_carrier",
"sample_id": null,
"children": [
"teaching_carrier_A1"
],
"parent": "deck",
"type": "plate",
"class": "opentrons_96_filtertiprack_1000ul",
"position": {
"x": 0,
"y": 0,
"z": 69
},
"config": {
"type": "Resource",
"size_x": 127,
"size_y": 85,
"size_z": 0,
"rotation": {
"x": 0,
"y": 0,
"z": 0,
"type": "Rotation"
},
"category": null,
"model": null
},
"data": {}
},
{
"id": "teaching_carrier_A1",
"name": "teaching_carrier_A1",
"sample_id": null,
"children": [],
"parent": "teaching_carrier",
"type": "device",
"class": "",
"position": {
"x": 10.87,
"y": 70.77,
"z": 10
},
"config": {
"type": "TipSpot",
"size_x": 6.86,
"size_y": 6.86,
"size_z": 10.67,
"rotation": {
"x": 0,
"y": 0,
"z": 0,
"type": "Rotation"
},
"category": "tip_spot",
"model": null,
"prototype_tip": {
"type": "Tip",
"total_tip_length": 39.2,
"has_filter": true,
"maximal_volume": 20.0,
"fitting_depth": 3.29
}
},
"data": {
"liquids": [],
"pending_liquids": [],
"liquid_history": []
}
}
],
"links": [

]
}
6 changes: 5 additions & 1 deletion unilabos/app/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def start_backend(
controllers_config: dict = {},
bridges=[],
without_host: bool = False,
visual: str = "None",
resources_mesh_config: dict = {},
**kwargs
):
if backend == "ros":
Expand All @@ -29,7 +31,9 @@ def start_backend(

backend_thread = threading.Thread(
target=main if not without_host else slave,
args=(devices_config, resources_config, graph, controllers_config, bridges)
args=(devices_config, resources_config, graph, controllers_config, bridges, visual, resources_mesh_config),
name="backend_thread",
daemon=True,
)
backend_thread.start()
logger.info(f"Backend {backend} started.")
45 changes: 41 additions & 4 deletions unilabos/app/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import argparse
import asyncio
import os
import signal
import sys
import json
import time

import yaml
from copy import deepcopy
import threading

import rclpy
from unilabos.ros.nodes.resource_tracker import DeviceNodeResourceTracker

# 首先添加项目根目录到路径
current_dir = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -14,6 +21,10 @@

from unilabos.config.config import load_config, BasicConfig, _update_config_from_env
from unilabos.utils.banner_print import print_status, print_unilab_banner
from unilabos.device_mesh.resource_visalization import ResourceVisualization
from unilabos.ros.nodes.presets.joint_republisher import JointRepublisher
from unilabos.ros.nodes.presets.resource_mesh_manager import ResourceMeshManager
from rclpy.executors import MultiThreadedExecutor


def parse_args():
Expand Down Expand Up @@ -70,7 +81,12 @@ def parse_args():
default=True,
help="是否在启动时打开信息页",
)

parser.add_argument(
"--visual",
choices=["rviz", "web","None"],
default="rviz",
help="选择可视化工具: 'rviz' 或 'web' 或 'None',默认'rviz'",
)
return parser.parse_args()


Expand Down Expand Up @@ -121,6 +137,7 @@ def main():
# 注册表
build_registry(args_dict["registry_path"])


if args_dict["graph"] is not None:
import unilabos.resources.graphio as graph_res
graph_res.physical_setup_graph = (
Expand All @@ -132,6 +149,7 @@ def main():
args_dict["resources_config"] = initialize_resources(list(deepcopy(devices_and_resources).values()))
args_dict["devices_config"] = dict_to_nested_dict(deepcopy(devices_and_resources), devices_only=False)
# args_dict["resources_config"] = dict_to_tree(devices_and_resources, devices_only=False)

args_dict["graph"] = graph_res.physical_setup_graph
else:
if args_dict["devices"] is None or args_dict["resources"] is None:
Expand Down Expand Up @@ -166,9 +184,28 @@ def _exit(signum, frame):
signal.signal(signal.SIGINT, _exit)
signal.signal(signal.SIGTERM, _exit)
mqtt_client.start()

start_backend(**args_dict)
start_server(port=args_dict.get("port", 8002), open_browser=args_dict.get("open_browser", False))
args_dict["resources_mesh_config"] = {}

if args_dict["visual"] != "None":
if args_dict["visual"] == "rviz":
enable_rviz=True
elif args_dict["visual"] == "web":
enable_rviz=False
resource_visualization = ResourceVisualization(devices_and_resources, args_dict["resources_config"] ,enable_rviz=enable_rviz)

args_dict["resources_mesh_config"] = resource_visualization.resource_model
# 将joint_republisher和resource_mesh_manager添加进 main_slave_run.py中

start_backend(**args_dict)
server_thread = threading.Thread(target=start_server)
server_thread.start()
asyncio.set_event_loop(asyncio.new_event_loop())
resource_visualization.start()
while True:
time.sleep(1)
else:
start_backend(**args_dict)
start_server()


if __name__ == "__main__":
Expand Down
Loading