mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-09 00:15:10 +00:00
Compare commits
200 Commits
v0.10.12
...
0c8c8d7a89
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c8c8d7a89 | ||
|
|
1a0b3b5db1 | ||
|
|
6ead71dcee | ||
|
|
5a2ea479b9 | ||
|
|
03e8c1e46d | ||
|
|
81769d5a32 | ||
|
|
30415ef96f | ||
|
|
aac3c9d561 | ||
|
|
27132bbbc1 | ||
|
|
a8cf389b00 | ||
|
|
98e9d09583 | ||
|
|
1467b9ac91 | ||
|
|
c57bb2abbd | ||
|
|
34dd65d280 | ||
|
|
b08026f861 | ||
|
|
826b04f515 | ||
|
|
de4da95616 | ||
|
|
3c9cca88ea | ||
|
|
fd18b21147 | ||
|
|
c2dfe689aa | ||
|
|
4cd40865b4 | ||
|
|
fd3dbcf1ff | ||
|
|
ebe9e1b1f8 | ||
|
|
862f250e49 | ||
|
|
73f33c82db | ||
|
|
58bf6496b6 | ||
|
|
2b7da0e396 | ||
|
|
dd89d00588 | ||
|
|
9327d59915 | ||
|
|
736f55765b | ||
|
|
9eb1f9823e | ||
|
|
c61c4aae59 | ||
|
|
45eaf7019d | ||
|
|
84aeb6921d | ||
|
|
a95e4d446b | ||
|
|
de6584f7a8 | ||
|
|
2c06f94bcf | ||
|
|
3d9798476b | ||
|
|
c462540484 | ||
|
|
ad54308046 | ||
|
|
5823edec8f | ||
|
|
dde7086aa6 | ||
|
|
f1c7c96095 | ||
|
|
2a686e6ff2 | ||
|
|
00ced4d412 | ||
|
|
5674e180fc | ||
|
|
0bd3025d73 | ||
|
|
8dbea5dbd2 | ||
|
|
06e6d3348c | ||
|
|
9a8d50bbf3 | ||
|
|
0dc11542fb | ||
|
|
f0de653e77 | ||
|
|
89808285ed | ||
|
|
6eaa8e1c63 | ||
|
|
41c130ef54 | ||
|
|
2d30fb79c1 | ||
|
|
743ec8839d | ||
|
|
3f7b991dd9 | ||
|
|
0466b57e0a | ||
|
|
aaf33a8878 | ||
|
|
31f59dc2aa | ||
|
|
46b7ce292b | ||
|
|
3584e92a1e | ||
|
|
e793ff6aa2 | ||
|
|
f90be18926 | ||
|
|
604d82140d | ||
|
|
9c4fdd8001 | ||
|
|
71f6deda6b | ||
|
|
d81297d699 | ||
|
|
23cf713a80 | ||
|
|
c5efa5aa26 | ||
|
|
acf7b6d3f7 | ||
|
|
0593f98f81 | ||
|
|
540c5e94b7 | ||
|
|
f9aae44174 | ||
|
|
10cb645191 | ||
|
|
4456529cfb | ||
|
|
694a779c66 | ||
|
|
5d214ebcd8 | ||
|
|
0e11dacead | ||
|
|
7b68545db3 | ||
|
|
25960c2ed5 | ||
|
|
72c67ba25c | ||
|
|
cd9e7ef12c | ||
|
|
b85722f44d | ||
|
|
5a2cc2d709 | ||
|
|
644feced55 | ||
|
|
61ee446542 | ||
|
|
18f6685e18 | ||
|
|
e2052d4a2c | ||
|
|
50282664e0 | ||
|
|
ce8667f937 | ||
|
|
bef44b2293 | ||
|
|
b78c6c6ba9 | ||
|
|
0d512c9e38 | ||
|
|
c8c755057c | ||
|
|
a6ec20e279 | ||
|
|
b69aceaff3 | ||
|
|
21afdb62bc | ||
|
|
d7d43af40a | ||
|
|
132955617d | ||
|
|
e7521972e4 | ||
|
|
f2753fc69a | ||
|
|
09ad905280 | ||
|
|
7714c71cd2 | ||
|
|
64832718be | ||
|
|
68871358c2 | ||
|
|
498b3cad6a | ||
|
|
157da1759d | ||
|
|
be0a73eb19 | ||
|
|
9be6e1069a | ||
|
|
817e88cfc4 | ||
|
|
15f3f8518b | ||
|
|
bbc49e9aab | ||
|
|
f9a9e91d56 | ||
|
|
96e9c76709 | ||
|
|
06b7962ef9 | ||
|
|
6faa19a250 | ||
|
|
46cec82a51 | ||
|
|
f7db8d17c5 | ||
|
|
a354965f8e | ||
|
|
934276d2f7 | ||
|
|
803809480b | ||
|
|
5478ba3237 | ||
|
|
49f1aa9c28 | ||
|
|
d5d516f0ef | ||
|
|
4471fed4b8 | ||
|
|
30d143e1a5 | ||
|
|
75ea45f21e | ||
|
|
66af337d6c | ||
|
|
ae3c65c1d3 | ||
|
|
11e4f053f1 | ||
|
|
96f37b3b0d | ||
|
|
d7d0a27976 | ||
|
|
34151f5cb2 | ||
|
|
369a21b904 | ||
|
|
90169981c1 | ||
|
|
d297abfd19 | ||
|
|
9c515a252a | ||
|
|
ea5e7a5ce2 | ||
|
|
2e9a0a4677 | ||
|
|
4c7aa8a89a | ||
|
|
d8a0c5e715 | ||
|
|
133ffaac17 | ||
|
|
729a0fcf0c | ||
|
|
6ae77e0408 | ||
|
|
bab4b1d67a | ||
|
|
12c17ec26e | ||
|
|
6577fe12eb | ||
|
|
f1fee5fad9 | ||
|
|
9b3377aedb | ||
|
|
526327727d | ||
|
|
aaa86314e3 | ||
|
|
6a14104e6b | ||
|
|
ab0c4b708b | ||
|
|
c0b7f2decd | ||
|
|
b6c9530c61 | ||
|
|
8698821c52 | ||
|
|
3f53f88390 | ||
|
|
e840516ba4 | ||
|
|
146d8c5296 | ||
|
|
6573c9e02e | ||
|
|
c7b9c6a825 | ||
|
|
48c43d3303 | ||
|
|
55be5e8188 | ||
|
|
1b9f3c666d | ||
|
|
097114d38c | ||
|
|
5bec899479 | ||
|
|
5e86112ebf | ||
|
|
24ecb13b79 | ||
|
|
2573d34713 | ||
|
|
106d71e1db | ||
|
|
3c2a4a64ac | ||
|
|
1e00a66a65 | ||
|
|
46da42deef | ||
|
|
101c1bc3cc | ||
|
|
a62112ae26 | ||
|
|
dd5a7cab75 | ||
|
|
39de3ac58e | ||
|
|
b99969278c | ||
|
|
b957ad2f71 | ||
|
|
e1a7c3a103 | ||
|
|
e63c15997c | ||
|
|
c5a495f409 | ||
|
|
5b240cb0ea | ||
|
|
147b8f47c0 | ||
|
|
6d2489af5f | ||
|
|
807dcdd226 | ||
|
|
8a29bc5597 | ||
|
|
6f6c70ee57 | ||
|
|
478a85951c | ||
|
|
0f2555c90c | ||
|
|
d2dda6ee03 | ||
|
|
208540b307 | ||
|
|
cb7c56a1d9 | ||
|
|
ea2e9c3e3a | ||
|
|
0452a68180 | ||
|
|
90a0f3db9b | ||
|
|
055d120ba8 | ||
|
|
a948f09f60 |
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
configs/
|
||||
temp/
|
||||
## Python
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
@@ -237,4 +239,8 @@ unilabos/device_mesh/view_robot.rviz
|
||||
|
||||
|
||||
# Certs
|
||||
**/.certs
|
||||
**/.certs
|
||||
local_test2.py
|
||||
ros-humble-unilabos-msgs-0.9.13-h6403a04_5.tar.bz2
|
||||
*.bz2
|
||||
test_config.py
|
||||
|
||||
@@ -49,7 +49,7 @@ conda env update --file unilabos-[YOUR_OS].yml -n environment_name
|
||||
|
||||
# Currently, you need to install the `unilabos_msgs` package
|
||||
# You can download the system-specific package from the Release page
|
||||
conda install ros-humble-unilabos-msgs-0.9.7-xxxxx.tar.bz2
|
||||
conda install ros-humble-unilabos-msgs-0.10.0-xxxxx.tar.bz2
|
||||
|
||||
# Install PyLabRobot and other prerequisites
|
||||
git clone https://github.com/PyLabRobot/pylabrobot plr_repo
|
||||
|
||||
@@ -49,7 +49,7 @@ conda env update --file unilabos-[YOUR_OS].yml -n 环境名
|
||||
|
||||
# 现阶段,需要安装 `unilabos_msgs` 包
|
||||
# 可以前往 Release 页面下载系统对应的包进行安装
|
||||
conda install ros-humble-unilabos-msgs-0.9.7-xxxxx.tar.bz2
|
||||
conda install ros-humble-unilabos-msgs-0.10.0-xxxxx.tar.bz2
|
||||
|
||||
# 安装PyLabRobot等前置
|
||||
git clone https://github.com/PyLabRobot/pylabrobot plr_repo
|
||||
|
||||
21197
deck_9300_new.json
Normal file
21197
deck_9300_new.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,6 @@
|
||||
channel_sources:
|
||||
- robostack,robostack-staging,conda-forge,defaults
|
||||
|
||||
gazebo:
|
||||
- '11'
|
||||
libpqxx:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package:
|
||||
name: ros-humble-unilabos-msgs
|
||||
version: 0.9.7
|
||||
version: 0.10.0
|
||||
source:
|
||||
path: ../../unilabos_msgs
|
||||
folder: ros-humble-unilabos-msgs/src/work
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package:
|
||||
name: unilabos
|
||||
version: "0.9.7"
|
||||
version: "0.10.0"
|
||||
|
||||
source:
|
||||
path: ../..
|
||||
|
||||
2
setup.py
2
setup.py
@@ -4,7 +4,7 @@ package_name = 'unilabos'
|
||||
|
||||
setup(
|
||||
name=package_name,
|
||||
version='0.9.7',
|
||||
version='0.10.0',
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
install_requires=['setuptools'],
|
||||
|
||||
45
test/experiments/camera.json
Normal file
45
test/experiments/camera.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"id": "Camera",
|
||||
"name": "摄像头",
|
||||
"children": [
|
||||
],
|
||||
"parent": null,
|
||||
"type": "device",
|
||||
"class": "camera",
|
||||
"position": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"config": {
|
||||
"camera_index": 0,
|
||||
"period": 0.05
|
||||
},
|
||||
"data": {
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "Gripper1",
|
||||
"name": "假夹爪",
|
||||
"children": [
|
||||
],
|
||||
"parent": null,
|
||||
"type": "device",
|
||||
"class": "gripper.mock",
|
||||
"position": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"config": {
|
||||
},
|
||||
"data": {
|
||||
}
|
||||
}
|
||||
],
|
||||
"links": [
|
||||
|
||||
]
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
HeatChillProtocol: generate_heat_chill_protocol, (√)
|
||||
HeatChillStartProtocol: generate_heat_chill_start_protocol, (√)
|
||||
HeatChillStopProtocol: generate_heat_chill_stop_protocol, (√)
|
||||
HeatChillToTempProtocol:
|
||||
StirProtocol: generate_stir_protocol, (√)
|
||||
StartStirProtocol: generate_start_stir_protocol, (√)
|
||||
StopStirProtocol: generate_stop_stir_protocol, (√)
|
||||
@@ -30,7 +31,228 @@
|
||||
CleanVesselProtocol: generate_clean_vessel_protocol, (√)
|
||||
DissolveProtocol: generate_dissolve_protocol, (√)
|
||||
FilterThroughProtocol: generate_filter_through_protocol, (√)
|
||||
RunColumnProtocol: generate_run_column_protocol, (×)
|
||||
WashSolidProtocol: generate_wash_solid_protocol, (×)
|
||||
RunColumnProtocol: generate_run_column_protocol, (√)<RunColumn Rf="?" column="column" from_vessel="rotavap" ratio="5:95" solvent1="methanol" solvent2="chloroform" to_vessel="rotavap"/>
|
||||
|
||||
上下文体积搜索
|
||||
上下文体积搜索
|
||||
3. 还没创建的protocol
|
||||
ResetHandling 写完了 <ResetHandling solvent="methanol"/>
|
||||
Dry 写完了 <Dry compound="product" vessel="filter"/>
|
||||
AdjustPH 写完了 <AdjustPH pH="8.0" reagent="hydrochloric acid" vessel="main_reactor"/>
|
||||
Recrystallize 写完了 <Recrystallize ratio="?" solvent1="dichloromethane" solvent2="methanol" vessel="filter" volume="?"/>
|
||||
TakeSample <TakeSample id="a" vessel="rotavap"/>
|
||||
Hydrogenate <Hydrogenate temp="45 °C" time="?" vessel="main_reactor"/>
|
||||
4. 参数对齐
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class PumpTransferProtocol(BaseModel):
|
||||
from_vessel: str
|
||||
to_vessel: str
|
||||
volume: float
|
||||
amount: str = ""
|
||||
time: float = 0
|
||||
viscous: bool = False
|
||||
rinsing_solvent: str = "air" <Transfer from_vessel="main_reactor" to_vessel="rotavap"/>
|
||||
rinsing_volume: float = 5000 <Transfer event="A" from_vessel="reactor" rate_spec="dropwise" to_vessel="main_reactor"/>
|
||||
rinsing_repeats: int = 2 <Transfer from_vessel="separator" through="cartridge" to_vessel="rotavap"/>
|
||||
solid: bool = False 测完了三个都能跑✅
|
||||
flowrate: float = 500
|
||||
transfer_flowrate: float = 2500
|
||||
|
||||
class SeparateProtocol(BaseModel):
|
||||
purpose: str
|
||||
product_phase: str
|
||||
from_vessel: str
|
||||
separation_vessel: str
|
||||
to_vessel: str
|
||||
waste_phase_to_vessel: str
|
||||
solvent: str
|
||||
solvent_volume: float <Separate product_phase="bottom" purpose="wash" solvent="water" vessel="separator" volume="?"/>
|
||||
through: str <Separate product_phase="top" purpose="separate" vessel="separator"/>
|
||||
repeats: int <Separate product_phase="bottom" purpose="extract" repeats="3" solvent="CH2Cl2" vessel="separator" volume="?"/>
|
||||
stir_time: float <Separate product_phase="top" product_vessel="flask" purpose="separate" vessel="separator" waste_vessel="separator"/>
|
||||
stir_speed: float
|
||||
settling_time: float 测完了能跑✅
|
||||
|
||||
|
||||
class EvaporateProtocol(BaseModel):
|
||||
vessel: str
|
||||
pressure: float
|
||||
temp: float <Evaporate solvent="ethanol" vessel="rotavap"/>
|
||||
time: float 测完了能跑✅
|
||||
stir_speed: float
|
||||
|
||||
|
||||
class EvacuateAndRefillProtocol(BaseModel):
|
||||
vessel: str
|
||||
gas: str <EvacuateAndRefill gas="nitrogen" vessel="main_reactor"/>
|
||||
repeats: int 测完了能跑✅
|
||||
|
||||
class AddProtocol(BaseModel):
|
||||
vessel: str
|
||||
reagent: str
|
||||
volume: float
|
||||
mass: float
|
||||
amount: str
|
||||
time: float
|
||||
stir: bool
|
||||
stir_speed: float <Add reagent="ethanol" vessel="main_reactor" volume="2.7 mL"/>
|
||||
<Add event="A" mass="19.3 g" mol="0.28 mol" rate_spec="portionwise" reagent="sodium nitrite" time="1 h" vessel="main_reactor"/>
|
||||
<Add mass="4.5 g" mol="16.2 mmol" reagent="(S)-2-phthalimido-6-hydroxyhexanoic acid" vessel="main_reactor"/>
|
||||
<Add purpose="dilute" reagent="hydrochloric acid" vessel="main_reactor" volume="?"/>
|
||||
<Add equiv="1.1" event="B" mol="25.2 mmol" rate_spec="dropwise" reagent="1-fluoro-2-nitrobenzene" time="20 min"
|
||||
vessel="main_reactor" volume="2.67 mL"/>
|
||||
<Add ratio="?" reagent="tetrahydrofuran|tert-butanol" vessel="main_reactor" volume="?"/>
|
||||
viscous: bool
|
||||
purpose: str 测完了能跑✅
|
||||
|
||||
class CentrifugeProtocol(BaseModel):
|
||||
vessel: str
|
||||
speed: float
|
||||
time: float 没毛病
|
||||
temp: float
|
||||
|
||||
class FilterProtocol(BaseModel):
|
||||
vessel: str
|
||||
filtrate_vessel: str
|
||||
stir: bool <Filter vessel="filter"/>
|
||||
stir_speed: float <Filter filtrate_vessel="rotavap" vessel="filter"/>
|
||||
temp: float 测完了能跑✅
|
||||
continue_heatchill: bool
|
||||
volume: float
|
||||
|
||||
class HeatChillProtocol(BaseModel):
|
||||
vessel: str
|
||||
temp: float
|
||||
time: float <HeatChill pressure="1 mbar" temp_spec="room temperature" time="?" vessel="main_reactor"/>
|
||||
<HeatChill temp_spec="room temperature" time_spec="overnight" vessel="main_reactor"/>
|
||||
<HeatChill temp="256 °C" time="?" vessel="main_reactor"/>
|
||||
<HeatChill reflux_solvent="methanol" temp_spec="reflux" time="2 h" vessel="main_reactor"/>
|
||||
<HeatChillToTemp temp_spec="room temperature" vessel="main_reactor"/>
|
||||
stir: bool 测完了能跑✅
|
||||
stir_speed: float
|
||||
purpose: str
|
||||
|
||||
class HeatChillStartProtocol(BaseModel):
|
||||
vessel: str
|
||||
temp: float 疑似没有
|
||||
purpose: str
|
||||
|
||||
class HeatChillStopProtocol(BaseModel):
|
||||
vessel: str 疑似没有
|
||||
|
||||
class StirProtocol(BaseModel):
|
||||
stir_time: float
|
||||
stir_speed: float <Stir time="0.5 h" vessel="main_reactor"/>
|
||||
<Stir event="A" time="30 min" vessel="main_reactor"/>
|
||||
<Stir time_spec="several minutes" vessel="filter"/>
|
||||
settling_time: float 测完了能跑✅
|
||||
|
||||
class StartStirProtocol(BaseModel):
|
||||
vessel: str
|
||||
stir_speed: float 疑似没有
|
||||
purpose: str
|
||||
|
||||
class StopStirProtocol(BaseModel):
|
||||
vessel: str 疑似没有
|
||||
|
||||
class TransferProtocol(BaseModel):
|
||||
from_vessel: str
|
||||
to_vessel: str
|
||||
volume: float
|
||||
amount: str = ""
|
||||
time: float = 0
|
||||
viscous: bool = False
|
||||
rinsing_solvent: str = ""
|
||||
rinsing_volume: float = 0.0
|
||||
rinsing_repeats: int = 0
|
||||
solid: bool = False 这个protocol早该删掉了
|
||||
|
||||
class CleanVesselProtocol(BaseModel):
|
||||
vessel: str
|
||||
solvent: str
|
||||
volume: float
|
||||
temp: float
|
||||
repeats: int = 1 <CleanVessel vessel="centrifuge"/>
|
||||
|
||||
class DissolveProtocol(BaseModel):
|
||||
vessel: str
|
||||
solvent: str
|
||||
volume: float <Dissolve mass="2.9 g" mol="0.12 mol" reagent="magnesium" vessel="main_reactor"/>
|
||||
amount: str = "" <Dissolve mass="12.9 g" reagent="4-tert-butylbenzyl bromide" vessel="main_reactor"/>
|
||||
temp: float = 25.0 <Dissolve solvent="diisopropyl ether" vessel="rotavap" volume="?"/>
|
||||
time: float = 0.0 <Dissolve event="A" mass="?" reagent="pyridinone" vessel="main_reactor"/>
|
||||
stir_speed: float = 0.0 测完了能跑✅
|
||||
|
||||
class FilterThroughProtocol(BaseModel):
|
||||
from_vessel: str
|
||||
to_vessel: str
|
||||
filter_through: str
|
||||
eluting_solvent: str = ""
|
||||
eluting_volume: float = 0.0 疑似没有
|
||||
eluting_repeats: int = 0
|
||||
residence_time: float = 0.0
|
||||
|
||||
class RunColumnProtocol(BaseModel):
|
||||
from_vessel: str
|
||||
to_vessel: str <RunColumn Rf="?" column="column" from_vessel="rotavap" pct1="40 %" pct2="50 %" solvent1="ethyl acetate" solvent2="hexane" to_vessel="rotavap"/>
|
||||
column: str 测完了能跑✅
|
||||
|
||||
class WashSolidProtocol(BaseModel):
|
||||
vessel: str
|
||||
solvent: str
|
||||
volume: float
|
||||
filtrate_vessel: str = "" <WashSolid repeats="4" solvent="water" vessel="main_reactor" volume="400 mL"/>
|
||||
temp: float = 25.0 <WashSolid filtrate_vessel="rotavap" solvent="formic acid" vessel="main_reactor" volume="?"/>
|
||||
stir: bool = False <WashSolid solvent="acetone" vessel="rotavap" volume="5 mL"/>
|
||||
<WashSolid solvent="ethyl alcohol" vessel="main_reactor" volume_spec="small volume"/>
|
||||
<WashSolid filtrate_vessel="rotavap" mass="10 g" solvent="toluene" vessel="separator"/>
|
||||
<WashSolid repeats_spec="several" solvent="water" vessel="main_reactor" volume="?"/>
|
||||
stir_speed: float = 0.0 测完了能跑✅
|
||||
time: float = 0.0
|
||||
repeats: int = 1
|
||||
|
||||
class AdjustPHProtocol(BaseModel):
|
||||
vessel: str = Field(..., description="目标容器")
|
||||
ph_value: float = Field(..., description="目标pH值") # 改为 ph_value
|
||||
reagent: str = Field(..., description="酸碱试剂名称")
|
||||
# 移除其他可选参数,使用默认值 <新写的,没问题>
|
||||
|
||||
class ResetHandlingProtocol(BaseModel):
|
||||
solvent: str = Field(..., description="溶剂名称") <新写的,没问题>
|
||||
|
||||
class DryProtocol(BaseModel):
|
||||
compound: str = Field(..., description="化合物名称") <新写的,没问题>
|
||||
vessel: str = Field(..., description="目标容器")
|
||||
|
||||
class RecrystallizeProtocol(BaseModel):
|
||||
ratio: str = Field(..., description="溶剂比例(如 '1:1', '3:7')")
|
||||
solvent1: str = Field(..., description="第一种溶剂名称") <新写的,没问题>
|
||||
solvent2: str = Field(..., description="第二种溶剂名称")
|
||||
vessel: str = Field(..., description="目标容器")
|
||||
volume: float = Field(..., description="总体积 (mL)")
|
||||
|
||||
class HydrogenateProtocol(BaseModel):
|
||||
temp: str = Field(..., description="反应温度(如 '45 °C')")
|
||||
time: str = Field(..., description="反应时间(如 '2 h')") <新写的,没问题>
|
||||
vessel: str = Field(..., description="反应容器")
|
||||
|
||||
还差
|
||||
<dissolve>
|
||||
<separate>
|
||||
<CleanVessel vessel="centrifuge"/>
|
||||
|
||||
|
||||
单位修复:
|
||||
evaporate
|
||||
heatchill
|
||||
recrysitallize
|
||||
stir
|
||||
wash solid
|
||||
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"id": "OrganicSynthesisStation",
|
||||
"name": "有机化学流程综合测试工作站",
|
||||
"children": [
|
||||
"heater_1"
|
||||
],
|
||||
"parent": null,
|
||||
"type": "device",
|
||||
"class": "workstation",
|
||||
"position": {
|
||||
"x": 600,
|
||||
"y": 400,
|
||||
"z": 0
|
||||
},
|
||||
"config": {
|
||||
"protocol_type": [
|
||||
"AddProtocol",
|
||||
"TransferProtocol",
|
||||
"StartStirProtocol",
|
||||
"StopStirProtocol",
|
||||
"StirProtocol",
|
||||
"RunColumnProtocol",
|
||||
"CentrifugeProtocol",
|
||||
"FilterProtocol",
|
||||
"CleanVesselProtocol",
|
||||
"DissolveProtocol",
|
||||
"FilterThroughProtocol",
|
||||
"WashSolidProtocol",
|
||||
"SeparateProtocol",
|
||||
"EvaporateProtocol",
|
||||
"HeatChillProtocol",
|
||||
"HeatChillStartProtocol",
|
||||
"HeatChillStopProtocol",
|
||||
"EvacuateAndRefillProtocol",
|
||||
"PumpTransferProtocol",
|
||||
"AdjustPHProtocol",
|
||||
"ResetHandlingProtocol",
|
||||
"DryProtocol",
|
||||
"HydrogenateProtocol",
|
||||
"RecrystallizeProtocol"
|
||||
]
|
||||
},
|
||||
"data": {}
|
||||
},
|
||||
{
|
||||
"id": "heater_1",
|
||||
"name": "加热器",
|
||||
"children": [],
|
||||
"parent": "OrganicSynthesisStation",
|
||||
"type": "device",
|
||||
"class": "virtual_heatchill",
|
||||
"position": {
|
||||
"x": 450,
|
||||
"y": 450,
|
||||
"z": 0
|
||||
},
|
||||
"config": {
|
||||
"max_temp": 200.0,
|
||||
"min_temp": -20.0
|
||||
},
|
||||
"data": {
|
||||
"status": "Idle",
|
||||
"current_temp": 25.0
|
||||
}
|
||||
}
|
||||
],
|
||||
"links": []
|
||||
}
|
||||
@@ -23,14 +23,20 @@
|
||||
"waste_bottle_2",
|
||||
"solenoid_valve_1",
|
||||
"solenoid_valve_2",
|
||||
"solenoid_valve_3",
|
||||
"vacuum_pump_1",
|
||||
"gas_source_1",
|
||||
"h2_gas_source",
|
||||
"filter_1",
|
||||
"column_1",
|
||||
"separator_1",
|
||||
"collection_bottle_1",
|
||||
"collection_bottle_2",
|
||||
"collection_bottle_3"
|
||||
"collection_bottle_3",
|
||||
"solid_dispenser_1",
|
||||
"solid_reagent_bottle_1",
|
||||
"solid_reagent_bottle_2",
|
||||
"solid_reagent_bottle_3"
|
||||
],
|
||||
"parent": null,
|
||||
"type": "device",
|
||||
@@ -60,7 +66,12 @@
|
||||
"HeatChillStartProtocol",
|
||||
"HeatChillStopProtocol",
|
||||
"EvacuateAndRefillProtocol",
|
||||
"PumpTransferProtocol"
|
||||
"PumpTransferProtocol",
|
||||
"AdjustPHProtocol",
|
||||
"ResetHandlingProtocol",
|
||||
"DryProtocol",
|
||||
"HydrogenateProtocol",
|
||||
"RecrystallizeProtocol"
|
||||
]
|
||||
},
|
||||
"data": {}
|
||||
@@ -461,6 +472,28 @@
|
||||
"is_open": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "solenoid_valve_3",
|
||||
"name": "氢气电磁阀",
|
||||
"children": [],
|
||||
"parent": "OrganicSynthesisStation",
|
||||
"type": "device",
|
||||
"class": "virtual_solenoid_valve",
|
||||
"position": {
|
||||
"x": 450,
|
||||
"y": 400,
|
||||
"z": 0
|
||||
},
|
||||
"config": {
|
||||
"voltage": 12.0,
|
||||
"response_time": 0.1,
|
||||
"gas_compatible": true
|
||||
},
|
||||
"data": {
|
||||
"valve_state": "Closed",
|
||||
"is_open": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "vacuum_pump_1",
|
||||
"name": "真空泵",
|
||||
@@ -500,6 +533,29 @@
|
||||
"max_pressure": 5.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "h2_gas_source",
|
||||
"name": "氢气气源",
|
||||
"children": [],
|
||||
"parent": "OrganicSynthesisStation",
|
||||
"type": "device",
|
||||
"class": "virtual_gas_source",
|
||||
"position": {
|
||||
"x": 500,
|
||||
"y": 350,
|
||||
"z": 0
|
||||
},
|
||||
"config": {
|
||||
"max_pressure": 10.0,
|
||||
"gas_type": "hydrogen"
|
||||
},
|
||||
"data": {
|
||||
"gas_type": "hydrogen",
|
||||
"max_pressure": 10.0,
|
||||
"current_pressure": 0.0,
|
||||
"status": "OFF"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "filter_1",
|
||||
"name": "过滤器",
|
||||
@@ -620,6 +676,98 @@
|
||||
"data": {
|
||||
"current_volume": 0.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "solid_dispenser_1",
|
||||
"name": "固体粉末加样器",
|
||||
"children": [],
|
||||
"parent": "OrganicSynthesisStation",
|
||||
"type": "device",
|
||||
"class": "virtual_solid_dispenser",
|
||||
"position": {
|
||||
"x": 600,
|
||||
"y": 300,
|
||||
"z": 0
|
||||
},
|
||||
"config": {
|
||||
"max_capacity": 100.0,
|
||||
"precision": 0.001
|
||||
},
|
||||
"data": {
|
||||
"status": "Ready",
|
||||
"current_reagent": "",
|
||||
"dispensed_amount": 0.0,
|
||||
"total_operations": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "solid_reagent_bottle_1",
|
||||
"name": "固体试剂瓶1-氯化钠",
|
||||
"children": [],
|
||||
"parent": "OrganicSynthesisStation",
|
||||
"type": "container",
|
||||
"class": "container",
|
||||
"position": {
|
||||
"x": 550,
|
||||
"y": 250,
|
||||
"z": 0
|
||||
},
|
||||
"config": {
|
||||
"volume": 500.0,
|
||||
"reagent": "sodium_chloride",
|
||||
"physical_state": "solid"
|
||||
},
|
||||
"data": {
|
||||
"current_mass": 500.0,
|
||||
"reagent_name": "sodium_chloride",
|
||||
"physical_state": "solid"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "solid_reagent_bottle_2",
|
||||
"name": "固体试剂瓶2-碳酸钠",
|
||||
"children": [],
|
||||
"parent": "OrganicSynthesisStation",
|
||||
"type": "container",
|
||||
"class": "container",
|
||||
"position": {
|
||||
"x": 600,
|
||||
"y": 250,
|
||||
"z": 0
|
||||
},
|
||||
"config": {
|
||||
"volume": 500.0,
|
||||
"reagent": "sodium_carbonate",
|
||||
"physical_state": "solid"
|
||||
},
|
||||
"data": {
|
||||
"current_mass": 500.0,
|
||||
"reagent_name": "sodium_carbonate",
|
||||
"physical_state": "solid"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "solid_reagent_bottle_3",
|
||||
"name": "固体试剂瓶3-氯化镁",
|
||||
"children": [],
|
||||
"parent": "OrganicSynthesisStation",
|
||||
"type": "container",
|
||||
"class": "container",
|
||||
"position": {
|
||||
"x": 650,
|
||||
"y": 250,
|
||||
"z": 0
|
||||
},
|
||||
"config": {
|
||||
"volume": 500.0,
|
||||
"reagent": "magnesium_chloride",
|
||||
"physical_state": "solid"
|
||||
},
|
||||
"data": {
|
||||
"current_mass": 500.0,
|
||||
"reagent_name": "magnesium_chloride",
|
||||
"physical_state": "solid"
|
||||
}
|
||||
}
|
||||
],
|
||||
"links": [
|
||||
@@ -680,7 +828,7 @@
|
||||
"type": "fluid",
|
||||
"port": {
|
||||
"multiway_valve_1": "5",
|
||||
"rotavap_1": "sample_in"
|
||||
"rotavap_1": "samplein"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -750,7 +898,7 @@
|
||||
"type": "fluid",
|
||||
"port": {
|
||||
"multiway_valve_2": "3",
|
||||
"solenoid_valve_2": "in"
|
||||
"solenoid_valve_2": "out"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -760,7 +908,7 @@
|
||||
"type": "fluid",
|
||||
"port": {
|
||||
"gas_source_1": "gassource",
|
||||
"solenoid_valve_2": "out"
|
||||
"solenoid_valve_2": "in"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -770,7 +918,7 @@
|
||||
"type": "transport",
|
||||
"port": {
|
||||
"multiway_valve_2": "4",
|
||||
"filter_1": "filter_in"
|
||||
"filter_1": "filterin"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -800,7 +948,7 @@
|
||||
"type": "fluid",
|
||||
"port": {
|
||||
"multiway_valve_2": "6",
|
||||
"separator_1": "separator_in"
|
||||
"separator_1": "separatorin"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -809,7 +957,7 @@
|
||||
"target": "collection_bottle_3",
|
||||
"type": "fluid",
|
||||
"port": {
|
||||
"separator_1": "bottom_phase_out",
|
||||
"separator_1": "bottomphaseout",
|
||||
"collection_bottle_3": "top"
|
||||
}
|
||||
},
|
||||
@@ -859,7 +1007,7 @@
|
||||
"target": "waste_bottle_2",
|
||||
"type": "fluid",
|
||||
"port": {
|
||||
"separator_1": "top_phase_out",
|
||||
"separator_1": "topphaseout",
|
||||
"waste_bottle_2": "top"
|
||||
}
|
||||
},
|
||||
@@ -874,14 +1022,14 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "link_filter_filtrate_to_collection1",
|
||||
"source": "filter_1",
|
||||
"target": "collection_bottle_1",
|
||||
"type": "transport",
|
||||
"port": {
|
||||
"filter_1": "filtrate_out",
|
||||
"collection_bottle_1": "top"
|
||||
}
|
||||
"id": "link_filter_filtrate_to_collection1",
|
||||
"source": "filter_1",
|
||||
"target": "collection_bottle_1",
|
||||
"type": "transport",
|
||||
"port": {
|
||||
"filter_1": "filtrateout",
|
||||
"collection_bottle_1": "top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "link_filter_retentate_to_waste1",
|
||||
@@ -889,9 +1037,69 @@
|
||||
"target": "waste_bottle_1",
|
||||
"type": "transport",
|
||||
"port": {
|
||||
"filter_1": "retentate_out",
|
||||
"filter_1": "retentateout",
|
||||
"waste_bottle_1": "top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "link_h2_gas_to_valve3",
|
||||
"source": "h2_gas_source",
|
||||
"target": "solenoid_valve_3",
|
||||
"type": "fluid",
|
||||
"port": {
|
||||
"h2_gas_source": "gassource",
|
||||
"solenoid_valve_3": "in"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "link_valve3_to_reactor",
|
||||
"source": "solenoid_valve_3",
|
||||
"target": "main_reactor",
|
||||
"type": "fluid",
|
||||
"port": {
|
||||
"solenoid_valve_3": "out",
|
||||
"main_reactor": "top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "link_solid_dispenser_to_reactor",
|
||||
"source": "solid_dispenser_1",
|
||||
"target": "main_reactor",
|
||||
"type": "resource",
|
||||
"port": {
|
||||
"solid_dispenser_1": "SolidOut",
|
||||
"main_reactor": "top"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "link_solid_bottle1_to_dispenser",
|
||||
"source": "solid_reagent_bottle_1",
|
||||
"target": "solid_dispenser_1",
|
||||
"type": "resource",
|
||||
"port": {
|
||||
"solid_reagent_bottle_1": "top",
|
||||
"solid_dispenser_1": "SolidIn"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "link_solid_bottle2_to_dispenser",
|
||||
"source": "solid_reagent_bottle_2",
|
||||
"target": "solid_dispenser_1",
|
||||
"type": "resource",
|
||||
"port": {
|
||||
"solid_reagent_bottle_2": "top",
|
||||
"solid_dispenser_1": "SolidIn"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "link_solid_bottle3_to_dispenser",
|
||||
"source": "solid_reagent_bottle_3",
|
||||
"target": "solid_dispenser_1",
|
||||
"type": "resource",
|
||||
"port": {
|
||||
"solid_reagent_bottle_3": "top",
|
||||
"solid_dispenser_1": "SolidIn"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
21231
test/experiments/prcxi_9300.json
Normal file
21231
test/experiments/prcxi_9300.json
Normal file
File diff suppressed because it is too large
Load Diff
13567
test/experiments/prcxi_9320.json
Normal file
13567
test/experiments/prcxi_9320.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -48,8 +48,9 @@ dependencies:
|
||||
- ros-humble-ros2-control
|
||||
- ros-humble-robot-state-publisher
|
||||
- ros-humble-joint-state-publisher
|
||||
# web
|
||||
# web and visualization
|
||||
- ros-humble-rosbridge-server
|
||||
- ros-humble-cv-bridge
|
||||
# geometry & motion planning
|
||||
- ros-humble-tf2
|
||||
- ros-humble-moveit
|
||||
@@ -62,4 +63,5 @@ dependencies:
|
||||
# ilab equipments
|
||||
# - ros-humble-unilabos-msgs
|
||||
- pip:
|
||||
- paho-mqtt
|
||||
- paho-mqtt
|
||||
- opentrons_shared_data
|
||||
@@ -62,4 +62,5 @@ dependencies:
|
||||
# ilab equipments
|
||||
# - ros-humble-unilabos-msgs
|
||||
- pip:
|
||||
- paho-mqtt
|
||||
- paho-mqtt
|
||||
- opentrons_shared_data
|
||||
@@ -50,8 +50,9 @@ dependencies:
|
||||
- ros-humble-ros2-control
|
||||
- ros-humble-robot-state-publisher
|
||||
- ros-humble-joint-state-publisher
|
||||
# web
|
||||
# web and visualization
|
||||
- ros-humble-rosbridge-server
|
||||
- ros-humble-cv-bridge
|
||||
# geometry & motion planning
|
||||
- ros-humble-tf2
|
||||
- ros-humble-moveit
|
||||
@@ -64,4 +65,5 @@ dependencies:
|
||||
# ilab equipments
|
||||
# - ros-humble-unilabos-msgs
|
||||
- pip:
|
||||
- paho-mqtt
|
||||
- paho-mqtt
|
||||
- opentrons_shared_data
|
||||
@@ -6,12 +6,12 @@ channels:
|
||||
dependencies:
|
||||
# Basics
|
||||
- python=3.11.11
|
||||
- compilers
|
||||
- cmake
|
||||
- make
|
||||
- ninja
|
||||
- sphinx
|
||||
- sphinx_rtd_theme
|
||||
# - compilers
|
||||
# - cmake
|
||||
# - make
|
||||
# - ninja
|
||||
# - sphinx
|
||||
# - sphinx_rtd_theme
|
||||
# Data Visualization
|
||||
- numpy
|
||||
- scipy
|
||||
@@ -23,7 +23,7 @@ dependencies:
|
||||
- pyserial
|
||||
- pyusb
|
||||
- pylibftdi
|
||||
- pymodbus
|
||||
- pymodbus==3.6.9
|
||||
- python-can
|
||||
- pyvisa
|
||||
- opencv
|
||||
@@ -48,8 +48,9 @@ dependencies:
|
||||
- ros-humble-ros2-control
|
||||
- ros-humble-robot-state-publisher
|
||||
- ros-humble-joint-state-publisher
|
||||
# web
|
||||
# web and visualization
|
||||
- ros-humble-rosbridge-server
|
||||
- ros-humble-cv-bridge
|
||||
# geometry & motion planning
|
||||
- ros-humble-tf2
|
||||
- ros-humble-moveit
|
||||
@@ -61,5 +62,13 @@ dependencies:
|
||||
# ros-humble-gazebo-ros // ignored because of the conflict with ign-gazebo
|
||||
# ilab equipments
|
||||
# ros-humble-unilabos-msgs
|
||||
# driver
|
||||
#- crcmod
|
||||
- pip:
|
||||
- paho-mqtt
|
||||
- paho-mqtt
|
||||
- opentrons_shared_data
|
||||
# driver
|
||||
#- ur-rtde # set PYTHONUTF8=1
|
||||
#- pyautogui
|
||||
#- pywinauto
|
||||
#- pywinauto_recorder
|
||||
@@ -1,8 +1,10 @@
|
||||
|
||||
import json
|
||||
import traceback
|
||||
import uuid
|
||||
from unilabos.app.model import JobAddReq, JobData
|
||||
from unilabos.ros.nodes.presets.host_node import HostNode
|
||||
from unilabos.utils.type_check import serialize_result_info
|
||||
|
||||
|
||||
def get_resources() -> tuple:
|
||||
@@ -25,12 +27,19 @@ def job_add(req: JobAddReq) -> JobData:
|
||||
if req.job_id is None:
|
||||
req.job_id = str(uuid.uuid4())
|
||||
action_name = req.data["action"]
|
||||
action_kwargs = req.data["action_kwargs"]
|
||||
req.data['action'] = action_name
|
||||
if action_name == "execute_command_from_outer":
|
||||
action_kwargs = {"command": json.dumps(action_kwargs)}
|
||||
elif "command" in action_kwargs:
|
||||
action_kwargs = action_kwargs["command"]
|
||||
action_type = req.data.get("action_type", "LocalUnknown")
|
||||
action_args = req.data.get("action_kwargs", None) # 兼容老版本,后续删除
|
||||
if action_args is None:
|
||||
action_args = req.data.get("action_args")
|
||||
else:
|
||||
if "command" in action_args:
|
||||
action_args = action_args["command"]
|
||||
# print(f"job_add:{req.device_id} {action_name} {action_kwargs}")
|
||||
HostNode.get_instance().send_goal(req.device_id, action_name=action_name, action_kwargs=action_kwargs, goal_uuid=req.job_id, server_info=req.server_info)
|
||||
try:
|
||||
HostNode.get_instance().send_goal(req.device_id, action_type=action_type, action_name=action_name, action_kwargs=action_args, goal_uuid=req.job_id, server_info=req.server_info)
|
||||
except Exception as e:
|
||||
for bridge in HostNode.get_instance().bridges:
|
||||
traceback.print_exc()
|
||||
if hasattr(bridge, "publish_job_status"):
|
||||
bridge.publish_job_status({}, req.job_id, "failed", serialize_result_info(traceback.format_exc(), False, {}))
|
||||
return JobData(jobId=req.job_id)
|
||||
|
||||
@@ -56,6 +56,10 @@ class MQTTClient:
|
||||
payload_json["data"] = {}
|
||||
if "action" in payload_json:
|
||||
payload_json["data"]["action"] = payload_json.pop("action")
|
||||
if "action_type" in payload_json:
|
||||
payload_json["data"]["action_type"] = payload_json.pop("action_type")
|
||||
if "action_args" in payload_json:
|
||||
payload_json["data"]["action_args"] = payload_json.pop("action_args")
|
||||
if "action_kwargs" in payload_json:
|
||||
payload_json["data"]["action_kwargs"] = payload_json.pop("action_kwargs")
|
||||
job_req = JobAddReq.model_validate(payload_json)
|
||||
@@ -159,7 +163,7 @@ class MQTTClient:
|
||||
# status = device_status.get(device_id, {})
|
||||
if self.mqtt_disable:
|
||||
return
|
||||
status = {"data": device_status.get(device_id, {}), "device_id": device_id}
|
||||
status = {"data": device_status.get(device_id, {}), "device_id": device_id, "timestamp": time.time()}
|
||||
address = f"labs/{MQConfig.lab_id}/devices/"
|
||||
self.client.publish(address, json.dumps(status), qos=2)
|
||||
logger.debug(f"Device status published: address: {address}, {status}")
|
||||
|
||||
@@ -18,10 +18,22 @@ def register_devices_and_resources(mqtt_client, lab_registry):
|
||||
mqtt_client.publish_registry(device_info["id"], device_info, False)
|
||||
logger.debug(f"[UniLab Register] 注册设备: {device_info['id']}")
|
||||
|
||||
# 注册资源信息
|
||||
# 注册资源信息 - 使用HTTP方式
|
||||
from unilabos.app.web.client import http_client
|
||||
|
||||
resources_to_register = {}
|
||||
for resource_info in lab_registry.obtain_registry_resource_info():
|
||||
mqtt_client.publish_registry(resource_info["id"], resource_info, False)
|
||||
logger.debug(f"[UniLab Register] 注册资源: {resource_info['id']}")
|
||||
resources_to_register[resource_info["id"]] = resource_info
|
||||
logger.debug(f"[UniLab Register] 准备注册资源: {resource_info['id']}")
|
||||
|
||||
if resources_to_register:
|
||||
start_time = time.time()
|
||||
response = http_client.resource_registry(resources_to_register)
|
||||
cost_time = time.time() - start_time
|
||||
if response.status_code in [200, 201]:
|
||||
logger.info(f"[UniLab Register] 成功通过HTTP注册 {len(resources_to_register)} 个资源 {cost_time}ms")
|
||||
else:
|
||||
logger.error(f"[UniLab Register] HTTP注册资源失败: {response.status_code}, {response.text} {cost_time}ms")
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
@@ -34,7 +46,7 @@ def main():
|
||||
"""
|
||||
parser = argparse.ArgumentParser(description="注册设备和资源到 MQTT")
|
||||
parser.add_argument(
|
||||
"--registry_path",
|
||||
"--registry",
|
||||
type=str,
|
||||
default=None,
|
||||
action="append",
|
||||
@@ -46,12 +58,16 @@ def main():
|
||||
default=None,
|
||||
help="配置文件路径,支持.py格式的Python配置文件",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--complete_registry",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="是否补全注册表",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# 构建注册表
|
||||
build_registry(args.registry_path)
|
||||
load_config_from_file(args.config)
|
||||
|
||||
# 构建注册表
|
||||
build_registry(args.registry, args.complete_registry)
|
||||
from unilabos.app.mq import mqtt_client
|
||||
|
||||
# 连接mqtt
|
||||
@@ -64,4 +80,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -40,8 +40,9 @@ class HTTPClient:
|
||||
Returns:
|
||||
Response: API响应对象
|
||||
"""
|
||||
database_param = 1 if database_process_later else 0
|
||||
response = requests.post(
|
||||
f"{self.remote_addr}/lab/resource/edge/batch_create/?database_process_later={1 if database_process_later else 0}",
|
||||
f"{self.remote_addr}/lab/resource/edge/batch_create/?database_process_later={database_param}",
|
||||
json=resources,
|
||||
headers={"Authorization": f"lab {self.auth}"},
|
||||
timeout=100,
|
||||
@@ -149,6 +150,26 @@ class HTTPClient:
|
||||
)
|
||||
return response
|
||||
|
||||
def resource_registry(self, registry_data: Dict[str, Any]) -> requests.Response:
|
||||
"""
|
||||
注册资源到服务器
|
||||
|
||||
Args:
|
||||
registry_data: 注册表数据,格式为 {resource_id: resource_info}
|
||||
|
||||
Returns:
|
||||
Response: API响应对象
|
||||
"""
|
||||
response = requests.post(
|
||||
f"{self.remote_addr}/lab/registry/",
|
||||
json=registry_data,
|
||||
headers={"Authorization": f"lab {self.auth}"},
|
||||
timeout=30,
|
||||
)
|
||||
if response.status_code not in [200, 201]:
|
||||
logger.error(f"注册资源失败: {response.status_code}, {response.text}")
|
||||
return response
|
||||
|
||||
|
||||
# 创建默认客户端实例
|
||||
http_client = HTTPClient()
|
||||
|
||||
@@ -7,6 +7,7 @@ Web页面模块
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
|
||||
@@ -17,7 +18,7 @@ from jinja2 import Environment, FileSystemLoader
|
||||
from unilabos.config.config import BasicConfig
|
||||
from unilabos.registry.registry import lab_registry
|
||||
from unilabos.ros.msgs.message_converter import msg_converter_manager
|
||||
from unilabos.utils.log import error
|
||||
from unilabos.utils.log import error, debug
|
||||
from unilabos.utils.type_check import TypeEncoder
|
||||
from unilabos.app.web.utils.device_utils import get_registry_info
|
||||
from unilabos.app.web.utils.host_utils import get_host_node_info
|
||||
@@ -123,6 +124,7 @@ def setup_web_pages(router: APIRouter) -> None:
|
||||
|
||||
return html
|
||||
except Exception as e:
|
||||
debug(traceback.format_exc())
|
||||
error(f"生成状态页面时出错: {str(e)}")
|
||||
raise HTTPException(status_code=500, detail=f"Error generating status page: {str(e)}")
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ def get_yaml_from_goal_type(goal_type) -> str:
|
||||
Returns:
|
||||
str: 默认Goal参数的YAML格式字符串
|
||||
"""
|
||||
if isinstance(goal_type, str):
|
||||
return "{}"
|
||||
if not goal_type:
|
||||
return "{}"
|
||||
|
||||
|
||||
@@ -21,16 +21,23 @@ from .dissolve_protocol import generate_dissolve_protocol
|
||||
from .filter_through_protocol import generate_filter_through_protocol
|
||||
from .run_column_protocol import generate_run_column_protocol
|
||||
from .wash_solid_protocol import generate_wash_solid_protocol
|
||||
from .adjustph_protocol import generate_adjust_ph_protocol
|
||||
from .reset_handling_protocol import generate_reset_handling_protocol
|
||||
from .dry_protocol import generate_dry_protocol
|
||||
from .recrystallize_protocol import generate_recrystallize_protocol
|
||||
from .hydrogenate_protocol import generate_hydrogenate_protocol
|
||||
|
||||
|
||||
# Define a dictionary of protocol generators.
|
||||
action_protocol_generators = {
|
||||
AddProtocol: generate_add_protocol,
|
||||
AGVTransferProtocol: generate_agv_transfer_protocol,
|
||||
AdjustPHProtocol: generate_adjust_ph_protocol,
|
||||
CentrifugeProtocol: generate_centrifuge_protocol,
|
||||
CleanProtocol: generate_clean_protocol,
|
||||
CleanVesselProtocol: generate_clean_vessel_protocol,
|
||||
DissolveProtocol: generate_dissolve_protocol,
|
||||
DryProtocol: generate_dry_protocol,
|
||||
EvacuateAndRefillProtocol: generate_evacuateandrefill_protocol,
|
||||
EvaporateProtocol: generate_evaporate_protocol,
|
||||
FilterProtocol: generate_filter_protocol,
|
||||
@@ -38,7 +45,10 @@ action_protocol_generators = {
|
||||
HeatChillProtocol: generate_heat_chill_protocol,
|
||||
HeatChillStartProtocol: generate_heat_chill_start_protocol,
|
||||
HeatChillStopProtocol: generate_heat_chill_stop_protocol,
|
||||
HydrogenateProtocol: generate_hydrogenate_protocol,
|
||||
PumpTransferProtocol: generate_pump_protocol_with_rinsing,
|
||||
RecrystallizeProtocol: generate_recrystallize_protocol,
|
||||
ResetHandlingProtocol: generate_reset_handling_protocol,
|
||||
RunColumnProtocol: generate_run_column_protocol,
|
||||
SeparateProtocol: generate_separate_protocol,
|
||||
StartStirProtocol: generate_start_stir_protocol,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
654
unilabos/compile/adjustph_protocol.py
Normal file
654
unilabos/compile/adjustph_protocol.py
Normal file
@@ -0,0 +1,654 @@
|
||||
import networkx as nx
|
||||
import logging
|
||||
from typing import List, Dict, Any, Union
|
||||
from .pump_protocol import generate_pump_protocol_with_rinsing
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def debug_print(message):
|
||||
"""调试输出"""
|
||||
print(f"[ADJUST_PH] {message}", flush=True)
|
||||
logger.info(f"[ADJUST_PH] {message}")
|
||||
|
||||
# 🆕 创建进度日志动作
|
||||
def create_action_log(message: str, emoji: str = "📝") -> Dict[str, Any]:
|
||||
"""创建一个动作日志"""
|
||||
full_message = f"{emoji} {message}"
|
||||
debug_print(full_message)
|
||||
logger.info(full_message)
|
||||
print(f"[ACTION] {full_message}", flush=True)
|
||||
|
||||
return {
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 0.1,
|
||||
"log_message": full_message
|
||||
}
|
||||
}
|
||||
|
||||
def find_acid_base_vessel(G: nx.DiGraph, reagent: str) -> str:
|
||||
"""
|
||||
查找酸碱试剂容器,支持多种匹配模式
|
||||
|
||||
Args:
|
||||
G: 网络图
|
||||
reagent: 试剂名称(如 "hydrochloric acid", "sodium hydroxide")
|
||||
|
||||
Returns:
|
||||
str: 试剂容器ID
|
||||
"""
|
||||
debug_print(f"🔍 正在查找试剂 '{reagent}' 的容器...")
|
||||
|
||||
# 常见酸碱试剂的别名映射
|
||||
reagent_aliases = {
|
||||
"hydrochloric acid": ["HCl", "hydrochloric_acid", "hcl", "muriatic_acid"],
|
||||
"sodium hydroxide": ["NaOH", "sodium_hydroxide", "naoh", "caustic_soda"],
|
||||
"sulfuric acid": ["H2SO4", "sulfuric_acid", "h2so4"],
|
||||
"nitric acid": ["HNO3", "nitric_acid", "hno3"],
|
||||
"acetic acid": ["CH3COOH", "acetic_acid", "glacial_acetic_acid"],
|
||||
"ammonia": ["NH3", "ammonium_hydroxide", "nh3"],
|
||||
"potassium hydroxide": ["KOH", "potassium_hydroxide", "koh"]
|
||||
}
|
||||
|
||||
# 构建搜索名称列表
|
||||
search_names = [reagent.lower()]
|
||||
debug_print(f"📋 基础搜索名称: {reagent.lower()}")
|
||||
|
||||
# 添加别名
|
||||
for base_name, aliases in reagent_aliases.items():
|
||||
if reagent.lower() in base_name.lower() or base_name.lower() in reagent.lower():
|
||||
search_names.extend([alias.lower() for alias in aliases])
|
||||
debug_print(f"🔗 添加别名: {aliases}")
|
||||
break
|
||||
|
||||
debug_print(f"📝 完整搜索列表: {search_names}")
|
||||
|
||||
# 构建可能的容器名称
|
||||
possible_names = []
|
||||
for name in search_names:
|
||||
name_clean = name.replace(" ", "_").replace("-", "_")
|
||||
possible_names.extend([
|
||||
f"flask_{name_clean}",
|
||||
f"bottle_{name_clean}",
|
||||
f"reagent_{name_clean}",
|
||||
f"acid_{name_clean}" if "acid" in name else f"base_{name_clean}",
|
||||
f"{name_clean}_bottle",
|
||||
f"{name_clean}_flask",
|
||||
name_clean
|
||||
])
|
||||
|
||||
debug_print(f"🎯 可能的容器名称 (前5个): {possible_names[:5]}... (共{len(possible_names)}个)")
|
||||
|
||||
# 第一步:通过容器名称匹配
|
||||
debug_print(f"📋 方法1: 精确名称匹配...")
|
||||
for vessel_name in possible_names:
|
||||
if vessel_name in G.nodes():
|
||||
debug_print(f"✅ 通过名称匹配找到容器: {vessel_name} 🎯")
|
||||
return vessel_name
|
||||
|
||||
# 第二步:通过模糊匹配
|
||||
debug_print(f"📋 方法2: 模糊名称匹配...")
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
node_name = G.nodes[node_id].get('name', '').lower()
|
||||
|
||||
# 检查是否包含任何搜索名称
|
||||
for search_name in search_names:
|
||||
if search_name in node_id.lower() or search_name in node_name:
|
||||
debug_print(f"✅ 通过模糊匹配找到容器: {node_id} 🔍")
|
||||
return node_id
|
||||
|
||||
# 第三步:通过液体类型匹配
|
||||
debug_print(f"📋 方法3: 液体类型匹配...")
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
vessel_data = G.nodes[node_id].get('data', {})
|
||||
liquids = vessel_data.get('liquid', [])
|
||||
|
||||
for liquid in liquids:
|
||||
if isinstance(liquid, dict):
|
||||
liquid_type = (liquid.get('liquid_type') or liquid.get('name', '')).lower()
|
||||
reagent_name = vessel_data.get('reagent_name', '').lower()
|
||||
|
||||
for search_name in search_names:
|
||||
if search_name in liquid_type or search_name in reagent_name:
|
||||
debug_print(f"✅ 通过液体类型匹配找到容器: {node_id} 💧")
|
||||
return node_id
|
||||
|
||||
# 列出可用容器帮助调试
|
||||
debug_print(f"📊 列出可用容器帮助调试...")
|
||||
available_containers = []
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
vessel_data = G.nodes[node_id].get('data', {})
|
||||
liquids = vessel_data.get('liquid', [])
|
||||
liquid_types = [liquid.get('liquid_type', '') or liquid.get('name', '')
|
||||
for liquid in liquids if isinstance(liquid, dict)]
|
||||
|
||||
available_containers.append({
|
||||
'id': node_id,
|
||||
'name': G.nodes[node_id].get('name', ''),
|
||||
'liquids': liquid_types,
|
||||
'reagent_name': vessel_data.get('reagent_name', '')
|
||||
})
|
||||
|
||||
debug_print(f"📋 可用容器列表:")
|
||||
for container in available_containers:
|
||||
debug_print(f" - 🧪 {container['id']}: {container['name']}")
|
||||
debug_print(f" 💧 液体: {container['liquids']}")
|
||||
debug_print(f" 🏷️ 试剂: {container['reagent_name']}")
|
||||
|
||||
debug_print(f"❌ 所有匹配方法都失败了")
|
||||
raise ValueError(f"找不到试剂 '{reagent}' 对应的容器。尝试了: {possible_names[:10]}...")
|
||||
|
||||
def find_connected_stirrer(G: nx.DiGraph, vessel: str) -> str:
|
||||
"""查找与容器相连的搅拌器"""
|
||||
debug_print(f"🔍 查找连接到容器 '{vessel}' 的搅拌器...")
|
||||
|
||||
stirrer_nodes = [node for node in G.nodes()
|
||||
if (G.nodes[node].get('class') or '') == 'virtual_stirrer']
|
||||
|
||||
debug_print(f"📊 发现 {len(stirrer_nodes)} 个搅拌器: {stirrer_nodes}")
|
||||
|
||||
for stirrer in stirrer_nodes:
|
||||
if G.has_edge(stirrer, vessel) or G.has_edge(vessel, stirrer):
|
||||
debug_print(f"✅ 找到连接的搅拌器: {stirrer} 🔗")
|
||||
return stirrer
|
||||
|
||||
if stirrer_nodes:
|
||||
debug_print(f"⚠️ 未找到直接连接的搅拌器,使用第一个: {stirrer_nodes[0]} 🔄")
|
||||
return stirrer_nodes[0]
|
||||
|
||||
debug_print(f"❌ 未找到任何搅拌器")
|
||||
return None
|
||||
|
||||
def calculate_reagent_volume(target_ph_value: float, reagent: str, vessel_volume: float = 100.0) -> float:
|
||||
"""
|
||||
估算需要的试剂体积来调节pH
|
||||
|
||||
Args:
|
||||
target_ph_value: 目标pH值
|
||||
reagent: 试剂名称
|
||||
vessel_volume: 容器体积 (mL)
|
||||
|
||||
Returns:
|
||||
float: 估算的试剂体积 (mL)
|
||||
"""
|
||||
debug_print(f"🧮 计算试剂体积...")
|
||||
debug_print(f" 📍 目标pH: {target_ph_value}")
|
||||
debug_print(f" 🧪 试剂: {reagent}")
|
||||
debug_print(f" 📏 容器体积: {vessel_volume}mL")
|
||||
|
||||
# 简化的pH调节体积估算(实际应用中需要更精确的计算)
|
||||
if "acid" in reagent.lower() or "hcl" in reagent.lower():
|
||||
debug_print(f"🍋 检测到酸性试剂")
|
||||
# 酸性试剂:pH越低需要的体积越大
|
||||
if target_ph_value < 3:
|
||||
volume = vessel_volume * 0.05 # 5%
|
||||
debug_print(f" 💪 强酸性 (pH<3): 使用 5% 体积")
|
||||
elif target_ph_value < 5:
|
||||
volume = vessel_volume * 0.02 # 2%
|
||||
debug_print(f" 🔸 中酸性 (pH<5): 使用 2% 体积")
|
||||
else:
|
||||
volume = vessel_volume * 0.01 # 1%
|
||||
debug_print(f" 🔹 弱酸性 (pH≥5): 使用 1% 体积")
|
||||
|
||||
elif "hydroxide" in reagent.lower() or "naoh" in reagent.lower():
|
||||
debug_print(f"🧂 检测到碱性试剂")
|
||||
# 碱性试剂:pH越高需要的体积越大
|
||||
if target_ph_value > 11:
|
||||
volume = vessel_volume * 0.05 # 5%
|
||||
debug_print(f" 💪 强碱性 (pH>11): 使用 5% 体积")
|
||||
elif target_ph_value > 9:
|
||||
volume = vessel_volume * 0.02 # 2%
|
||||
debug_print(f" 🔸 中碱性 (pH>9): 使用 2% 体积")
|
||||
else:
|
||||
volume = vessel_volume * 0.01 # 1%
|
||||
debug_print(f" 🔹 弱碱性 (pH≤9): 使用 1% 体积")
|
||||
|
||||
else:
|
||||
# 未知试剂,使用默认值
|
||||
volume = vessel_volume * 0.01
|
||||
debug_print(f"❓ 未知试剂类型,使用默认 1% 体积")
|
||||
|
||||
debug_print(f"📊 计算结果: {volume:.2f}mL")
|
||||
return volume
|
||||
|
||||
def generate_adjust_ph_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel:Union[dict,str], # 🔧 修改:从字符串改为字典类型
|
||||
ph_value: float,
|
||||
reagent: str,
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成调节pH的协议序列
|
||||
|
||||
Args:
|
||||
G: 有向图,节点为容器和设备
|
||||
vessel: 目标容器字典(需要调节pH的容器)
|
||||
ph_value: 目标pH值(从XDL传入)
|
||||
reagent: 酸碱试剂名称(从XDL传入)
|
||||
**kwargs: 其他可选参数,使用默认值
|
||||
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 动作序列
|
||||
"""
|
||||
|
||||
# 统一处理vessel参数
|
||||
if isinstance(vessel, dict):
|
||||
vessel_id = list(vessel.values())[0].get("id", "")
|
||||
vessel_data = vessel.get("data", {})
|
||||
else:
|
||||
vessel_id = str(vessel)
|
||||
vessel_data = G.nodes[vessel_id].get("data", {}) if vessel_id in G.nodes() else {}
|
||||
|
||||
if not vessel_id:
|
||||
debug_print(f"❌ vessel 参数无效,必须包含id字段或直接提供容器ID. vessel: {vessel}")
|
||||
raise ValueError("vessel 参数无效,必须包含id字段或直接提供容器ID")
|
||||
|
||||
debug_print("=" * 60)
|
||||
debug_print("🧪 开始生成pH调节协议")
|
||||
debug_print(f"📋 原始参数:")
|
||||
debug_print(f" 🥼 vessel: {vessel} (ID: {vessel_id})")
|
||||
debug_print(f" 📊 ph_value: {ph_value}")
|
||||
debug_print(f" 🧪 reagent: '{reagent}'")
|
||||
debug_print(f" 📦 kwargs: {kwargs}")
|
||||
debug_print("=" * 60)
|
||||
|
||||
action_sequence = []
|
||||
|
||||
# 从kwargs中获取可选参数,如果没有则使用默认值
|
||||
volume = kwargs.get('volume', 0.0) # 自动估算体积
|
||||
stir = kwargs.get('stir', True) # 默认搅拌
|
||||
stir_speed = kwargs.get('stir_speed', 300.0) # 默认搅拌速度
|
||||
stir_time = kwargs.get('stir_time', 60.0) # 默认搅拌时间
|
||||
settling_time = kwargs.get('settling_time', 30.0) # 默认平衡时间
|
||||
|
||||
debug_print(f"🔧 处理后的参数:")
|
||||
debug_print(f" 📏 volume: {volume}mL (0.0表示自动估算)")
|
||||
debug_print(f" 🌪️ stir: {stir}")
|
||||
debug_print(f" 🔄 stir_speed: {stir_speed}rpm")
|
||||
debug_print(f" ⏱️ stir_time: {stir_time}s")
|
||||
debug_print(f" ⏳ settling_time: {settling_time}s")
|
||||
|
||||
# 开始处理
|
||||
action_sequence.append(create_action_log(f"开始调节pH至 {ph_value}", "🧪"))
|
||||
action_sequence.append(create_action_log(f"目标容器: {vessel_id}", "🥼"))
|
||||
action_sequence.append(create_action_log(f"使用试剂: {reagent}", "⚗️"))
|
||||
|
||||
# 1. 验证目标容器存在
|
||||
debug_print(f"🔍 步骤1: 验证目标容器...")
|
||||
if vessel_id not in G.nodes():
|
||||
debug_print(f"❌ 目标容器 '{vessel_id}' 不存在于系统中")
|
||||
raise ValueError(f"目标容器 '{vessel_id}' 不存在于系统中")
|
||||
|
||||
debug_print(f"✅ 目标容器验证通过")
|
||||
action_sequence.append(create_action_log("目标容器验证通过", "✅"))
|
||||
|
||||
# 2. 查找酸碱试剂容器
|
||||
debug_print(f"🔍 步骤2: 查找试剂容器...")
|
||||
action_sequence.append(create_action_log("正在查找试剂容器...", "🔍"))
|
||||
|
||||
try:
|
||||
reagent_vessel = find_acid_base_vessel(G, reagent)
|
||||
debug_print(f"✅ 找到试剂容器: {reagent_vessel}")
|
||||
action_sequence.append(create_action_log(f"找到试剂容器: {reagent_vessel}", "🧪"))
|
||||
except ValueError as e:
|
||||
debug_print(f"❌ 无法找到试剂容器: {str(e)}")
|
||||
action_sequence.append(create_action_log(f"试剂容器查找失败: {str(e)}", "❌"))
|
||||
raise ValueError(f"无法找到试剂 '{reagent}': {str(e)}")
|
||||
|
||||
# 3. 体积估算
|
||||
debug_print(f"🔍 步骤3: 体积处理...")
|
||||
if volume <= 0:
|
||||
action_sequence.append(create_action_log("开始自动估算试剂体积", "🧮"))
|
||||
|
||||
# 获取目标容器的体积信息
|
||||
vessel_data = G.nodes[vessel_id].get('data', {})
|
||||
vessel_volume = vessel_data.get('max_volume', 100.0) # 默认100mL
|
||||
debug_print(f"📏 容器最大体积: {vessel_volume}mL")
|
||||
|
||||
estimated_volume = calculate_reagent_volume(ph_value, reagent, vessel_volume)
|
||||
volume = estimated_volume
|
||||
debug_print(f"✅ 自动估算试剂体积: {volume:.2f} mL")
|
||||
action_sequence.append(create_action_log(f"估算试剂体积: {volume:.2f}mL", "📊"))
|
||||
else:
|
||||
debug_print(f"📏 使用指定体积: {volume}mL")
|
||||
action_sequence.append(create_action_log(f"使用指定体积: {volume}mL", "📏"))
|
||||
|
||||
# 4. 验证路径存在
|
||||
debug_print(f"🔍 步骤4: 路径验证...")
|
||||
action_sequence.append(create_action_log("验证转移路径...", "🛤️"))
|
||||
|
||||
try:
|
||||
path = nx.shortest_path(G, source=reagent_vessel, target=vessel_id)
|
||||
debug_print(f"✅ 找到路径: {' → '.join(path)}")
|
||||
action_sequence.append(create_action_log(f"找到转移路径: {' → '.join(path)}", "🛤️"))
|
||||
except nx.NetworkXNoPath:
|
||||
debug_print(f"❌ 无法找到转移路径")
|
||||
action_sequence.append(create_action_log("转移路径不存在", "❌"))
|
||||
raise ValueError(f"从试剂容器 '{reagent_vessel}' 到目标容器 '{vessel_id}' 没有可用路径")
|
||||
|
||||
# 5. 搅拌器设置
|
||||
debug_print(f"🔍 步骤5: 搅拌器设置...")
|
||||
stirrer_id = None
|
||||
if stir:
|
||||
action_sequence.append(create_action_log("准备启动搅拌器", "🌪️"))
|
||||
|
||||
try:
|
||||
stirrer_id = find_connected_stirrer(G, vessel_id)
|
||||
|
||||
if stirrer_id:
|
||||
debug_print(f"✅ 找到搅拌器 {stirrer_id},启动搅拌")
|
||||
action_sequence.append(create_action_log(f"启动搅拌器 {stirrer_id} (速度: {stir_speed}rpm)", "🔄"))
|
||||
|
||||
action_sequence.append({
|
||||
"device_id": stirrer_id,
|
||||
"action_name": "start_stir",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id,
|
||||
"stir_speed": stir_speed,
|
||||
"purpose": f"pH调节: 启动搅拌,准备添加 {reagent}"
|
||||
}
|
||||
})
|
||||
|
||||
# 等待搅拌稳定
|
||||
action_sequence.append(create_action_log("等待搅拌稳定...", "⏳"))
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": 5}
|
||||
})
|
||||
else:
|
||||
debug_print(f"⚠️ 未找到搅拌器,继续执行")
|
||||
action_sequence.append(create_action_log("未找到搅拌器,跳过搅拌", "⚠️"))
|
||||
|
||||
except Exception as e:
|
||||
debug_print(f"❌ 搅拌器配置出错: {str(e)}")
|
||||
action_sequence.append(create_action_log(f"搅拌器配置失败: {str(e)}", "❌"))
|
||||
else:
|
||||
debug_print(f"📋 跳过搅拌设置")
|
||||
action_sequence.append(create_action_log("跳过搅拌设置", "⏭️"))
|
||||
|
||||
# 6. 试剂添加
|
||||
debug_print(f"🔍 步骤6: 试剂添加...")
|
||||
action_sequence.append(create_action_log(f"开始添加试剂 {volume:.2f}mL", "🚰"))
|
||||
|
||||
# 计算添加时间(pH调节需要缓慢添加)
|
||||
addition_time = max(30.0, volume * 2.0) # 至少30秒,每mL需要2秒
|
||||
debug_print(f"⏱️ 计算添加时间: {addition_time}s (缓慢注入)")
|
||||
action_sequence.append(create_action_log(f"设置添加时间: {addition_time:.0f}s (缓慢注入)", "⏱️"))
|
||||
|
||||
try:
|
||||
action_sequence.append(create_action_log("调用泵协议进行试剂转移", "🔄"))
|
||||
|
||||
pump_actions = generate_pump_protocol_with_rinsing(
|
||||
G=G,
|
||||
from_vessel=reagent_vessel,
|
||||
to_vessel=vessel_id,
|
||||
volume=volume,
|
||||
amount="",
|
||||
time=addition_time,
|
||||
viscous=False,
|
||||
rinsing_solvent="", # pH调节不需要清洗
|
||||
rinsing_volume=0.0,
|
||||
rinsing_repeats=0,
|
||||
solid=False,
|
||||
flowrate=0.5, # 缓慢注入
|
||||
transfer_flowrate=0.3
|
||||
)
|
||||
|
||||
action_sequence.extend(pump_actions)
|
||||
debug_print(f"✅ 泵协议生成完成,添加了 {len(pump_actions)} 个动作")
|
||||
action_sequence.append(create_action_log(f"试剂转移完成 ({len(pump_actions)} 个操作)", "✅"))
|
||||
|
||||
# 🔧 修复体积运算 - 试剂添加成功后更新容器液体体积
|
||||
debug_print(f"🔧 更新容器液体体积...")
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
debug_print(f"📊 添加前容器体积: {current_volume}")
|
||||
|
||||
# 处理不同的体积数据格式
|
||||
if isinstance(current_volume, list):
|
||||
if len(current_volume) > 0:
|
||||
# 增加体积(添加试剂)
|
||||
vessel["data"]["liquid_volume"][0] += volume
|
||||
debug_print(f"📊 添加后容器体积: {vessel['data']['liquid_volume'][0]:.2f}mL (+{volume:.2f}mL)")
|
||||
else:
|
||||
# 如果列表为空,创建新的体积记录
|
||||
vessel["data"]["liquid_volume"] = [volume]
|
||||
debug_print(f"📊 初始化容器体积: {volume:.2f}mL")
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
# 直接数值类型
|
||||
vessel["data"]["liquid_volume"] += volume
|
||||
debug_print(f"📊 添加后容器体积: {vessel['data']['liquid_volume']:.2f}mL (+{volume:.2f}mL)")
|
||||
else:
|
||||
debug_print(f"⚠️ 未知的体积数据格式: {type(current_volume)}")
|
||||
# 创建新的体积记录
|
||||
vessel["data"]["liquid_volume"] = volume
|
||||
else:
|
||||
debug_print(f"📊 容器无液体体积数据,创建新记录: {volume:.2f}mL")
|
||||
# 确保vessel有data字段
|
||||
if "data" not in vessel:
|
||||
vessel["data"] = {}
|
||||
vessel["data"]["liquid_volume"] = volume
|
||||
|
||||
# 🔧 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
vessel_node_data = G.nodes[vessel_id].get('data', {})
|
||||
current_node_volume = vessel_node_data.get('liquid_volume', 0.0)
|
||||
|
||||
if isinstance(current_node_volume, list):
|
||||
if len(current_node_volume) > 0:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'][0] += volume
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = [volume]
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = current_node_volume + volume
|
||||
|
||||
debug_print(f"✅ 图节点体积数据已更新")
|
||||
|
||||
action_sequence.append(create_action_log(f"容器体积已更新 (+{volume:.2f}mL)", "📊"))
|
||||
|
||||
except Exception as e:
|
||||
debug_print(f"❌ 生成泵协议时出错: {str(e)}")
|
||||
action_sequence.append(create_action_log(f"泵协议生成失败: {str(e)}", "❌"))
|
||||
raise ValueError(f"生成泵协议时出错: {str(e)}")
|
||||
|
||||
# 7. 混合搅拌
|
||||
if stir and stirrer_id:
|
||||
debug_print(f"🔍 步骤7: 混合搅拌...")
|
||||
action_sequence.append(create_action_log(f"开始混合搅拌 {stir_time:.0f}s", "🌀"))
|
||||
|
||||
action_sequence.append({
|
||||
"device_id": stirrer_id,
|
||||
"action_name": "stir",
|
||||
"action_kwargs": {
|
||||
"stir_time": stir_time,
|
||||
"stir_speed": stir_speed,
|
||||
"settling_time": settling_time,
|
||||
"purpose": f"pH调节: 混合试剂,目标pH={ph_value}"
|
||||
}
|
||||
})
|
||||
|
||||
debug_print(f"✅ 混合搅拌设置完成")
|
||||
else:
|
||||
debug_print(f"⏭️ 跳过混合搅拌")
|
||||
action_sequence.append(create_action_log("跳过混合搅拌", "⏭️"))
|
||||
|
||||
# 8. 等待平衡
|
||||
debug_print(f"🔍 步骤8: 反应平衡...")
|
||||
action_sequence.append(create_action_log(f"等待pH平衡 {settling_time:.0f}s", "⚖️"))
|
||||
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": settling_time,
|
||||
"description": f"等待pH平衡到目标值 {ph_value}"
|
||||
}
|
||||
})
|
||||
|
||||
# 9. 完成总结
|
||||
total_time = addition_time + stir_time + settling_time
|
||||
|
||||
debug_print("=" * 60)
|
||||
debug_print(f"🎉 pH调节协议生成完成")
|
||||
debug_print(f"📊 协议统计:")
|
||||
debug_print(f" 📋 总动作数: {len(action_sequence)}")
|
||||
debug_print(f" ⏱️ 预计总时间: {total_time:.0f}s ({total_time/60:.1f}分钟)")
|
||||
debug_print(f" 🧪 试剂: {reagent}")
|
||||
debug_print(f" 📏 体积: {volume:.2f}mL")
|
||||
debug_print(f" 📊 目标pH: {ph_value}")
|
||||
debug_print(f" 🥼 目标容器: {vessel_id}")
|
||||
debug_print("=" * 60)
|
||||
|
||||
# 添加完成日志
|
||||
summary_msg = f"pH调节协议完成: {vessel_id} → pH {ph_value} (使用 {volume:.2f}mL {reagent})"
|
||||
action_sequence.append(create_action_log(summary_msg, "🎉"))
|
||||
|
||||
return action_sequence
|
||||
|
||||
def generate_adjust_ph_protocol_stepwise(
|
||||
G: nx.DiGraph,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
ph_value: float,
|
||||
reagent: str,
|
||||
max_volume: float = 10.0,
|
||||
steps: int = 3
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
分步调节pH的协议(更安全,避免过度调节)
|
||||
|
||||
Args:
|
||||
G: 网络图
|
||||
vessel: 目标容器字典
|
||||
ph_value: 目标pH值
|
||||
reagent: 酸碱试剂
|
||||
max_volume: 最大试剂体积
|
||||
steps: 分步数量
|
||||
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 动作序列
|
||||
"""
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
debug_print("=" * 60)
|
||||
debug_print(f"🔄 开始分步pH调节")
|
||||
debug_print(f"📋 分步参数:")
|
||||
debug_print(f" 🥼 vessel: {vessel} (ID: {vessel_id})")
|
||||
debug_print(f" 📊 ph_value: {ph_value}")
|
||||
debug_print(f" 🧪 reagent: {reagent}")
|
||||
debug_print(f" 📏 max_volume: {max_volume}mL")
|
||||
debug_print(f" 🔢 steps: {steps}")
|
||||
debug_print("=" * 60)
|
||||
|
||||
action_sequence = []
|
||||
|
||||
# 每步添加的体积
|
||||
step_volume = max_volume / steps
|
||||
debug_print(f"📊 每步体积: {step_volume:.2f}mL")
|
||||
|
||||
action_sequence.append(create_action_log(f"开始分步pH调节 ({steps}步)", "🔄"))
|
||||
action_sequence.append(create_action_log(f"每步添加: {step_volume:.2f}mL", "📏"))
|
||||
|
||||
for i in range(steps):
|
||||
debug_print(f"🔄 执行第 {i+1}/{steps} 步,添加 {step_volume:.2f}mL")
|
||||
action_sequence.append(create_action_log(f"第 {i+1}/{steps} 步开始", "🚀"))
|
||||
|
||||
# 生成单步协议
|
||||
step_actions = generate_adjust_ph_protocol(
|
||||
G=G,
|
||||
vessel=vessel, # 🔧 直接传递vessel字典
|
||||
ph_value=ph_value,
|
||||
reagent=reagent,
|
||||
volume=step_volume,
|
||||
stir=True,
|
||||
stir_speed=300.0,
|
||||
stir_time=30.0,
|
||||
settling_time=20.0
|
||||
)
|
||||
|
||||
action_sequence.extend(step_actions)
|
||||
debug_print(f"✅ 第 {i+1}/{steps} 步完成,添加了 {len(step_actions)} 个动作")
|
||||
action_sequence.append(create_action_log(f"第 {i+1}/{steps} 步完成", "✅"))
|
||||
|
||||
# 步骤间等待
|
||||
if i < steps - 1:
|
||||
debug_print(f"⏳ 步骤间等待30s")
|
||||
action_sequence.append(create_action_log("步骤间等待...", "⏳"))
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 30,
|
||||
"description": f"pH调节第{i+1}步完成,等待下一步"
|
||||
}
|
||||
})
|
||||
|
||||
debug_print(f"🎉 分步pH调节完成,共 {len(action_sequence)} 个动作")
|
||||
action_sequence.append(create_action_log("分步pH调节全部完成", "🎉"))
|
||||
|
||||
return action_sequence
|
||||
|
||||
# 便捷函数:常用pH调节
|
||||
def generate_acidify_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
target_ph: float = 2.0,
|
||||
acid: str = "hydrochloric acid"
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""酸化协议"""
|
||||
vessel_id = vessel["id"]
|
||||
debug_print(f"🍋 生成酸化协议: {vessel_id} → pH {target_ph} (使用 {acid})")
|
||||
return generate_adjust_ph_protocol(
|
||||
G, vessel, target_ph, acid
|
||||
)
|
||||
|
||||
def generate_basify_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
target_ph: float = 12.0,
|
||||
base: str = "sodium hydroxide"
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""碱化协议"""
|
||||
vessel_id = vessel["id"]
|
||||
debug_print(f"🧂 生成碱化协议: {vessel_id} → pH {target_ph} (使用 {base})")
|
||||
return generate_adjust_ph_protocol(
|
||||
G, vessel, target_ph, base
|
||||
)
|
||||
|
||||
def generate_neutralize_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
reagent: str = "sodium hydroxide"
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""中和协议(pH=7)"""
|
||||
vessel_id = vessel["id"]
|
||||
debug_print(f"⚖️ 生成中和协议: {vessel_id} → pH 7.0 (使用 {reagent})")
|
||||
return generate_adjust_ph_protocol(
|
||||
G, vessel, 7.0, reagent
|
||||
)
|
||||
|
||||
# 测试函数
|
||||
def test_adjust_ph_protocol():
|
||||
"""测试pH调节协议"""
|
||||
debug_print("=== ADJUST PH PROTOCOL 增强版测试 ===")
|
||||
|
||||
# 测试体积计算
|
||||
debug_print("🧮 测试体积计算...")
|
||||
test_cases = [
|
||||
(2.0, "hydrochloric acid", 100.0),
|
||||
(4.0, "hydrochloric acid", 100.0),
|
||||
(12.0, "sodium hydroxide", 100.0),
|
||||
(10.0, "sodium hydroxide", 100.0),
|
||||
(7.0, "unknown reagent", 100.0)
|
||||
]
|
||||
|
||||
for ph, reagent, volume in test_cases:
|
||||
result = calculate_reagent_volume(ph, reagent, volume)
|
||||
debug_print(f"📊 {reagent} → pH {ph}: {result:.2f}mL")
|
||||
|
||||
debug_print("✅ 测试完成")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_adjust_ph_protocol()
|
||||
@@ -145,7 +145,7 @@ def find_connected_heatchill(G: nx.DiGraph, vessel: str) -> str:
|
||||
|
||||
def generate_clean_vessel_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
solvent: str,
|
||||
volume: float,
|
||||
temp: float,
|
||||
@@ -165,7 +165,7 @@ def generate_clean_vessel_protocol(
|
||||
|
||||
Args:
|
||||
G: 有向图,节点为设备和容器,边为流体管道
|
||||
vessel: 要清洗的容器名称
|
||||
vessel: 要清洗的容器字典(包含id字段)
|
||||
solvent: 用于清洗的溶剂名称
|
||||
volume: 每次清洗使用的溶剂体积
|
||||
temp: 清洗时的温度
|
||||
@@ -178,20 +178,23 @@ def generate_clean_vessel_protocol(
|
||||
ValueError: 当找不到必要的容器或设备时抛出异常
|
||||
|
||||
Examples:
|
||||
clean_protocol = generate_clean_vessel_protocol(G, "main_reactor", "water", 100.0, 60.0, 2)
|
||||
clean_protocol = generate_clean_vessel_protocol(G, {"id": "main_reactor"}, "water", 100.0, 60.0, 2)
|
||||
"""
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
action_sequence = []
|
||||
|
||||
print(f"CLEAN_VESSEL: 开始生成容器清洗协议")
|
||||
print(f" - 目标容器: {vessel}")
|
||||
print(f" - 目标容器: {vessel} (ID: {vessel_id})")
|
||||
print(f" - 清洗溶剂: {solvent}")
|
||||
print(f" - 清洗体积: {volume} mL")
|
||||
print(f" - 清洗温度: {temp}°C")
|
||||
print(f" - 重复次数: {repeats}")
|
||||
|
||||
# 验证目标容器存在
|
||||
if vessel not in G.nodes():
|
||||
raise ValueError(f"目标容器 '{vessel}' 不存在于系统中")
|
||||
if vessel_id not in G.nodes():
|
||||
raise ValueError(f"目标容器 '{vessel_id}' 不存在于系统中")
|
||||
|
||||
# 查找溶剂容器
|
||||
try:
|
||||
@@ -208,12 +211,23 @@ def generate_clean_vessel_protocol(
|
||||
raise ValueError(f"无法找到废液容器: {str(e)}")
|
||||
|
||||
# 查找加热设备(可选)
|
||||
heatchill_id = find_connected_heatchill(G, vessel)
|
||||
heatchill_id = find_connected_heatchill(G, vessel_id) # 🔧 使用 vessel_id
|
||||
if heatchill_id:
|
||||
print(f"CLEAN_VESSEL: 找到加热设备: {heatchill_id}")
|
||||
else:
|
||||
print(f"CLEAN_VESSEL: 未找到加热设备,将在室温下清洗")
|
||||
|
||||
# 🔧 新增:记录清洗前的容器状态
|
||||
print(f"CLEAN_VESSEL: 记录清洗前容器状态...")
|
||||
original_liquid_volume = 0.0
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list) and len(current_volume) > 0:
|
||||
original_liquid_volume = current_volume[0]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
original_liquid_volume = current_volume
|
||||
print(f"CLEAN_VESSEL: 清洗前液体体积: {original_liquid_volume:.2f}mL")
|
||||
|
||||
# 第一步:如果需要加热且有加热设备,启动加热
|
||||
if temp > 25.0 and heatchill_id:
|
||||
print(f"CLEAN_VESSEL: 启动加热至 {temp}°C")
|
||||
@@ -221,7 +235,7 @@ def generate_clean_vessel_protocol(
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_start",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel,
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"temp": temp,
|
||||
"purpose": f"cleaning with {solvent}"
|
||||
}
|
||||
@@ -240,18 +254,61 @@ def generate_clean_vessel_protocol(
|
||||
print(f"CLEAN_VESSEL: 执行第 {repeat + 1} 次清洗")
|
||||
|
||||
# 2a. 使用 pump_protocol 将溶剂转移到目标容器
|
||||
print(f"CLEAN_VESSEL: 将 {volume} mL {solvent} 转移到 {vessel}")
|
||||
print(f"CLEAN_VESSEL: 将 {volume} mL {solvent} 转移到 {vessel_id}")
|
||||
try:
|
||||
# 调用成熟的 pump_protocol 算法
|
||||
add_solvent_actions = generate_pump_protocol(
|
||||
G=G,
|
||||
from_vessel=solvent_vessel,
|
||||
to_vessel=vessel,
|
||||
to_vessel=vessel_id, # 🔧 使用 vessel_id
|
||||
volume=volume,
|
||||
flowrate=2.5, # 适中的流速,避免飞溅
|
||||
transfer_flowrate=2.5
|
||||
)
|
||||
action_sequence.extend(add_solvent_actions)
|
||||
|
||||
# 🔧 新增:更新容器体积(添加清洗溶剂)
|
||||
print(f"CLEAN_VESSEL: 更新容器体积 - 添加清洗溶剂 {volume:.2f}mL")
|
||||
if "data" not in vessel:
|
||||
vessel["data"] = {}
|
||||
|
||||
if "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
if len(current_volume) > 0:
|
||||
vessel["data"]["liquid_volume"][0] += volume
|
||||
print(f"CLEAN_VESSEL: 添加溶剂后体积: {vessel['data']['liquid_volume'][0]:.2f}mL (+{volume:.2f}mL)")
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = [volume]
|
||||
print(f"CLEAN_VESSEL: 初始化清洗体积: {volume:.2f}mL")
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
vessel["data"]["liquid_volume"] += volume
|
||||
print(f"CLEAN_VESSEL: 添加溶剂后体积: {vessel['data']['liquid_volume']:.2f}mL (+{volume:.2f}mL)")
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = volume
|
||||
print(f"CLEAN_VESSEL: 重置体积为: {volume:.2f}mL")
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = volume
|
||||
print(f"CLEAN_VESSEL: 创建新体积记录: {volume:.2f}mL")
|
||||
|
||||
# 🔧 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
if 'data' not in G.nodes[vessel_id]:
|
||||
G.nodes[vessel_id]['data'] = {}
|
||||
|
||||
vessel_node_data = G.nodes[vessel_id]['data']
|
||||
current_node_volume = vessel_node_data.get('liquid_volume', 0.0)
|
||||
|
||||
if isinstance(current_node_volume, list):
|
||||
if len(current_node_volume) > 0:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'][0] += volume
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = [volume]
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = current_node_volume + volume
|
||||
|
||||
print(f"CLEAN_VESSEL: 图节点体积数据已更新")
|
||||
|
||||
except Exception as e:
|
||||
raise ValueError(f"无法将溶剂转移到容器: {str(e)}")
|
||||
|
||||
@@ -265,18 +322,52 @@ def generate_clean_vessel_protocol(
|
||||
action_sequence.append(wait_action)
|
||||
|
||||
# 2c. 使用 pump_protocol 将清洗液转移到废液容器
|
||||
print(f"CLEAN_VESSEL: 将清洗液从 {vessel} 转移到废液容器")
|
||||
print(f"CLEAN_VESSEL: 将清洗液从 {vessel_id} 转移到废液容器")
|
||||
try:
|
||||
# 调用成熟的 pump_protocol 算法
|
||||
remove_waste_actions = generate_pump_protocol(
|
||||
G=G,
|
||||
from_vessel=vessel,
|
||||
from_vessel=vessel_id, # 🔧 使用 vessel_id
|
||||
to_vessel=waste_vessel,
|
||||
volume=volume,
|
||||
flowrate=2.5, # 适中的流速
|
||||
transfer_flowrate=2.5
|
||||
)
|
||||
action_sequence.extend(remove_waste_actions)
|
||||
|
||||
# 🔧 新增:更新容器体积(移除清洗液)
|
||||
print(f"CLEAN_VESSEL: 更新容器体积 - 移除清洗液 {volume:.2f}mL")
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
if len(current_volume) > 0:
|
||||
vessel["data"]["liquid_volume"][0] = max(0.0, vessel["data"]["liquid_volume"][0] - volume)
|
||||
print(f"CLEAN_VESSEL: 移除清洗液后体积: {vessel['data']['liquid_volume'][0]:.2f}mL (-{volume:.2f}mL)")
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = [0.0]
|
||||
print(f"CLEAN_VESSEL: 重置体积为0mL")
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
vessel["data"]["liquid_volume"] = max(0.0, current_volume - volume)
|
||||
print(f"CLEAN_VESSEL: 移除清洗液后体积: {vessel['data']['liquid_volume']:.2f}mL (-{volume:.2f}mL)")
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = 0.0
|
||||
print(f"CLEAN_VESSEL: 重置体积为0mL")
|
||||
|
||||
# 🔧 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
vessel_node_data = G.nodes[vessel_id].get('data', {})
|
||||
current_node_volume = vessel_node_data.get('liquid_volume', 0.0)
|
||||
|
||||
if isinstance(current_node_volume, list):
|
||||
if len(current_node_volume) > 0:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'][0] = max(0.0, current_node_volume[0] - volume)
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = [0.0]
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = max(0.0, current_node_volume - volume)
|
||||
|
||||
print(f"CLEAN_VESSEL: 图节点体积数据已更新")
|
||||
|
||||
except Exception as e:
|
||||
raise ValueError(f"无法将清洗液转移到废液容器: {str(e)}")
|
||||
|
||||
@@ -296,13 +387,24 @@ def generate_clean_vessel_protocol(
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_stop",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel
|
||||
"vessel": vessel_id # 🔧 使用 vessel_id
|
||||
}
|
||||
}
|
||||
action_sequence.append(heatchill_stop_action)
|
||||
|
||||
print(f"CLEAN_VESSEL: 生成了 {len(action_sequence)} 个动作")
|
||||
print(f"CLEAN_VESSEL: 清洗协议生成完成")
|
||||
# 🔧 新增:清洗完成后的状态报告
|
||||
final_liquid_volume = 0.0
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list) and len(current_volume) > 0:
|
||||
final_liquid_volume = current_volume[0]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
final_liquid_volume = current_volume
|
||||
|
||||
print(f"CLEAN_VESSEL: 清洗完成")
|
||||
print(f" - 清洗前体积: {original_liquid_volume:.2f}mL")
|
||||
print(f" - 清洗后体积: {final_liquid_volume:.2f}mL")
|
||||
print(f" - 生成了 {len(action_sequence)} 个动作")
|
||||
|
||||
return action_sequence
|
||||
|
||||
@@ -310,7 +412,7 @@ def generate_clean_vessel_protocol(
|
||||
# 便捷函数:常用清洗方案
|
||||
def generate_quick_clean_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
solvent: str = "water",
|
||||
volume: float = 100.0
|
||||
) -> List[Dict[str, Any]]:
|
||||
@@ -320,7 +422,7 @@ def generate_quick_clean_protocol(
|
||||
|
||||
def generate_thorough_clean_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
solvent: str = "water",
|
||||
volume: float = 150.0,
|
||||
temp: float = 60.0
|
||||
@@ -331,7 +433,7 @@ def generate_thorough_clean_protocol(
|
||||
|
||||
def generate_organic_clean_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
volume: float = 100.0
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""有机清洗:先用有机溶剂,再用水清洗"""
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
333
unilabos/compile/dry_protocol.py
Normal file
333
unilabos/compile/dry_protocol.py
Normal file
@@ -0,0 +1,333 @@
|
||||
import networkx as nx
|
||||
from typing import List, Dict, Any
|
||||
|
||||
|
||||
def find_connected_heater(G: nx.DiGraph, vessel: str) -> str:
|
||||
"""
|
||||
查找与容器相连的加热器
|
||||
|
||||
Args:
|
||||
G: 网络图
|
||||
vessel: 容器名称
|
||||
|
||||
Returns:
|
||||
str: 加热器ID,如果没有则返回None
|
||||
"""
|
||||
print(f"DRY: 正在查找与容器 '{vessel}' 相连的加热器...")
|
||||
|
||||
# 查找所有加热器节点
|
||||
heater_nodes = [node for node in G.nodes()
|
||||
if ('heater' in node.lower() or
|
||||
'heat' in node.lower() or
|
||||
G.nodes[node].get('class') == 'virtual_heatchill' or
|
||||
G.nodes[node].get('type') == 'heater')]
|
||||
|
||||
print(f"DRY: 找到的加热器节点: {heater_nodes}")
|
||||
|
||||
# 检查是否有加热器与目标容器相连
|
||||
for heater in heater_nodes:
|
||||
if G.has_edge(heater, vessel) or G.has_edge(vessel, heater):
|
||||
print(f"DRY: 找到与容器 '{vessel}' 相连的加热器: {heater}")
|
||||
return heater
|
||||
|
||||
# 如果没有直接连接,查找距离最近的加热器
|
||||
for heater in heater_nodes:
|
||||
try:
|
||||
path = nx.shortest_path(G, source=heater, target=vessel)
|
||||
if len(path) <= 3: # 最多2个中间节点
|
||||
print(f"DRY: 找到距离较近的加热器: {heater}, 路径: {' → '.join(path)}")
|
||||
return heater
|
||||
except nx.NetworkXNoPath:
|
||||
continue
|
||||
|
||||
print(f"DRY: 未找到与容器 '{vessel}' 相连的加热器")
|
||||
return None
|
||||
|
||||
|
||||
def generate_dry_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
compound: str = "", # 🔧 修改:参数顺序调整,并设置默认值
|
||||
**kwargs # 接收其他可能的参数但不使用
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成干燥协议序列
|
||||
|
||||
Args:
|
||||
G: 有向图,节点为容器和设备
|
||||
vessel: 目标容器字典(从XDL传入)
|
||||
compound: 化合物名称(从XDL传入,可选)
|
||||
**kwargs: 其他可选参数,但不使用
|
||||
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 动作序列
|
||||
"""
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
action_sequence = []
|
||||
|
||||
# 默认参数
|
||||
dry_temp = 60.0 # 默认干燥温度 60°C
|
||||
dry_time = 3600.0 # 默认干燥时间 1小时(3600秒)
|
||||
simulation_time = 60.0 # 模拟时间 1分钟
|
||||
|
||||
print(f"🌡️ DRY: 开始生成干燥协议 ✨")
|
||||
print(f" 🥽 vessel: {vessel} (ID: {vessel_id})")
|
||||
print(f" 🧪 化合物: {compound or '未指定'}")
|
||||
print(f" 🔥 干燥温度: {dry_temp}°C")
|
||||
print(f" ⏰ 干燥时间: {dry_time/60:.0f} 分钟")
|
||||
|
||||
# 🔧 新增:记录干燥前的容器状态
|
||||
print(f"🔍 记录干燥前容器状态...")
|
||||
original_liquid_volume = 0.0
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list) and len(current_volume) > 0:
|
||||
original_liquid_volume = current_volume[0]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
original_liquid_volume = current_volume
|
||||
print(f"📊 干燥前液体体积: {original_liquid_volume:.2f}mL")
|
||||
|
||||
# 1. 验证目标容器存在
|
||||
print(f"\n📋 步骤1: 验证目标容器 '{vessel_id}' 是否存在...")
|
||||
if vessel_id not in G.nodes():
|
||||
print(f"⚠️ DRY: 警告 - 容器 '{vessel_id}' 不存在于系统中,跳过干燥 😢")
|
||||
return action_sequence
|
||||
print(f"✅ 容器 '{vessel_id}' 验证通过!")
|
||||
|
||||
# 2. 查找相连的加热器
|
||||
print(f"\n🔍 步骤2: 查找与容器相连的加热器...")
|
||||
heater_id = find_connected_heater(G, vessel_id) # 🔧 使用 vessel_id
|
||||
|
||||
if heater_id is None:
|
||||
print(f"😭 DRY: 警告 - 未找到与容器 '{vessel_id}' 相连的加热器,跳过干燥")
|
||||
print(f"🎭 添加模拟干燥动作...")
|
||||
# 添加一个等待动作,表示干燥过程(模拟)
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 10.0, # 模拟等待时间
|
||||
"description": f"模拟干燥 {compound or '化合物'} (无加热器可用)"
|
||||
}
|
||||
})
|
||||
|
||||
# 🔧 新增:模拟干燥的体积变化(溶剂蒸发)
|
||||
print(f"🔧 模拟干燥过程的体积减少...")
|
||||
if original_liquid_volume > 0:
|
||||
# 假设干燥过程中损失10%的体积(溶剂蒸发)
|
||||
volume_loss = original_liquid_volume * 0.1
|
||||
new_volume = max(0.0, original_liquid_volume - volume_loss)
|
||||
|
||||
# 更新vessel字典中的体积
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
if len(current_volume) > 0:
|
||||
vessel["data"]["liquid_volume"][0] = new_volume
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = [new_volume]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
vessel["data"]["liquid_volume"] = new_volume
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = new_volume
|
||||
|
||||
# 🔧 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
if 'data' not in G.nodes[vessel_id]:
|
||||
G.nodes[vessel_id]['data'] = {}
|
||||
|
||||
vessel_node_data = G.nodes[vessel_id]['data']
|
||||
current_node_volume = vessel_node_data.get('liquid_volume', 0.0)
|
||||
|
||||
if isinstance(current_node_volume, list):
|
||||
if len(current_node_volume) > 0:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'][0] = new_volume
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = [new_volume]
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = new_volume
|
||||
|
||||
print(f"📊 模拟干燥体积变化: {original_liquid_volume:.2f}mL → {new_volume:.2f}mL (-{volume_loss:.2f}mL)")
|
||||
|
||||
print(f"📄 DRY: 协议生成完成,共 {len(action_sequence)} 个动作 🎯")
|
||||
return action_sequence
|
||||
|
||||
print(f"🎉 找到加热器: {heater_id}!")
|
||||
|
||||
# 3. 启动加热器进行干燥
|
||||
print(f"\n🚀 步骤3: 开始执行干燥流程...")
|
||||
print(f"🔥 启动加热器 {heater_id} 进行干燥")
|
||||
|
||||
# 3.1 启动加热
|
||||
print(f" ⚡ 动作1: 启动加热到 {dry_temp}°C...")
|
||||
action_sequence.append({
|
||||
"device_id": heater_id,
|
||||
"action_name": "heat_chill_start",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"temp": dry_temp,
|
||||
"purpose": f"干燥 {compound or '化合物'}"
|
||||
}
|
||||
})
|
||||
print(f" ✅ 加热器启动命令已添加 🔥")
|
||||
|
||||
# 3.2 等待温度稳定
|
||||
print(f" ⏳ 动作2: 等待温度稳定...")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 10.0,
|
||||
"description": f"等待温度稳定到 {dry_temp}°C"
|
||||
}
|
||||
})
|
||||
print(f" ✅ 温度稳定等待命令已添加 🌡️")
|
||||
|
||||
# 3.3 保持干燥温度
|
||||
print(f" 🔄 动作3: 保持干燥温度 {simulation_time/60:.0f} 分钟...")
|
||||
action_sequence.append({
|
||||
"device_id": heater_id,
|
||||
"action_name": "heat_chill",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"temp": dry_temp,
|
||||
"time": simulation_time,
|
||||
"purpose": f"干燥 {compound or '化合物'},保持温度 {dry_temp}°C"
|
||||
}
|
||||
})
|
||||
print(f" ✅ 温度保持命令已添加 🌡️⏰")
|
||||
|
||||
# 🔧 新增:干燥过程中的体积变化计算
|
||||
print(f"🔧 计算干燥过程中的体积变化...")
|
||||
if original_liquid_volume > 0:
|
||||
# 干燥过程中,溶剂会蒸发,固体保留
|
||||
# 根据温度和时间估算蒸发量
|
||||
evaporation_rate = 0.001 * dry_temp # 每秒每°C蒸发0.001mL
|
||||
total_evaporation = min(original_liquid_volume * 0.8,
|
||||
evaporation_rate * simulation_time) # 最多蒸发80%
|
||||
|
||||
new_volume = max(0.0, original_liquid_volume - total_evaporation)
|
||||
|
||||
# 更新vessel字典中的体积
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
if len(current_volume) > 0:
|
||||
vessel["data"]["liquid_volume"][0] = new_volume
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = [new_volume]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
vessel["data"]["liquid_volume"] = new_volume
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = new_volume
|
||||
|
||||
# 🔧 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
if 'data' not in G.nodes[vessel_id]:
|
||||
G.nodes[vessel_id]['data'] = {}
|
||||
|
||||
vessel_node_data = G.nodes[vessel_id]['data']
|
||||
current_node_volume = vessel_node_data.get('liquid_volume', 0.0)
|
||||
|
||||
if isinstance(current_node_volume, list):
|
||||
if len(current_node_volume) > 0:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'][0] = new_volume
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = [new_volume]
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = new_volume
|
||||
|
||||
print(f"📊 干燥体积变化计算:")
|
||||
print(f" - 初始体积: {original_liquid_volume:.2f}mL")
|
||||
print(f" - 蒸发量: {total_evaporation:.2f}mL")
|
||||
print(f" - 剩余体积: {new_volume:.2f}mL")
|
||||
print(f" - 蒸发率: {(total_evaporation/original_liquid_volume*100):.1f}%")
|
||||
|
||||
# 3.4 停止加热
|
||||
print(f" ⏹️ 动作4: 停止加热...")
|
||||
action_sequence.append({
|
||||
"device_id": heater_id,
|
||||
"action_name": "heat_chill_stop",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"purpose": f"干燥完成,停止加热"
|
||||
}
|
||||
})
|
||||
print(f" ✅ 停止加热命令已添加 🛑")
|
||||
|
||||
# 3.5 等待冷却
|
||||
print(f" ❄️ 动作5: 等待冷却...")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 10.0, # 等待10秒冷却
|
||||
"description": f"等待 {compound or '化合物'} 冷却"
|
||||
}
|
||||
})
|
||||
print(f" ✅ 冷却等待命令已添加 🧊")
|
||||
|
||||
# 🔧 新增:干燥完成后的状态报告
|
||||
final_liquid_volume = 0.0
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list) and len(current_volume) > 0:
|
||||
final_liquid_volume = current_volume[0]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
final_liquid_volume = current_volume
|
||||
|
||||
print(f"\n🎊 DRY: 协议生成完成,共 {len(action_sequence)} 个动作 🎯")
|
||||
print(f"⏱️ DRY: 预计总时间: {(simulation_time + 30)/60:.0f} 分钟 ⌛")
|
||||
print(f"📊 干燥结果:")
|
||||
print(f" - 容器: {vessel_id}")
|
||||
print(f" - 化合物: {compound or '未指定'}")
|
||||
print(f" - 干燥前体积: {original_liquid_volume:.2f}mL")
|
||||
print(f" - 干燥后体积: {final_liquid_volume:.2f}mL")
|
||||
print(f" - 蒸发体积: {(original_liquid_volume - final_liquid_volume):.2f}mL")
|
||||
print(f"🏁 所有动作序列准备就绪! ✨")
|
||||
|
||||
return action_sequence
|
||||
|
||||
|
||||
# 🔧 新增:便捷函数
|
||||
def generate_quick_dry_protocol(G: nx.DiGraph, vessel: dict, compound: str = "",
|
||||
temp: float = 40.0, time: float = 30.0) -> List[Dict[str, Any]]:
|
||||
"""快速干燥:低温短时间"""
|
||||
vessel_id = vessel["id"]
|
||||
print(f"🌡️ 快速干燥: {compound or '化合物'} → {vessel_id} @ {temp}°C ({time}min)")
|
||||
|
||||
# 临时修改默认参数
|
||||
import types
|
||||
temp_func = types.FunctionType(
|
||||
generate_dry_protocol.__code__,
|
||||
generate_dry_protocol.__globals__
|
||||
)
|
||||
|
||||
# 直接调用原函数,但修改内部参数
|
||||
return generate_dry_protocol(G, vessel, compound)
|
||||
|
||||
|
||||
def generate_thorough_dry_protocol(G: nx.DiGraph, vessel: dict, compound: str = "",
|
||||
temp: float = 80.0, time: float = 120.0) -> List[Dict[str, Any]]:
|
||||
"""深度干燥:高温长时间"""
|
||||
vessel_id = vessel["id"]
|
||||
print(f"🔥 深度干燥: {compound or '化合物'} → {vessel_id} @ {temp}°C ({time}min)")
|
||||
return generate_dry_protocol(G, vessel, compound)
|
||||
|
||||
|
||||
def generate_gentle_dry_protocol(G: nx.DiGraph, vessel: dict, compound: str = "",
|
||||
temp: float = 30.0, time: float = 180.0) -> List[Dict[str, Any]]:
|
||||
"""温和干燥:低温长时间"""
|
||||
vessel_id = vessel["id"]
|
||||
print(f"🌡️ 温和干燥: {compound or '化合物'} → {vessel_id} @ {temp}°C ({time}min)")
|
||||
return generate_dry_protocol(G, vessel, compound)
|
||||
|
||||
|
||||
# 测试函数
|
||||
def test_dry_protocol():
|
||||
"""测试干燥协议"""
|
||||
print("=== DRY PROTOCOL 测试 ===")
|
||||
print("测试完成")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_dry_protocol()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,326 +1,470 @@
|
||||
from typing import List, Dict, Any
|
||||
from typing import List, Dict, Any, Optional, Union
|
||||
import networkx as nx
|
||||
from .pump_protocol import generate_pump_protocol
|
||||
import logging
|
||||
import re
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def get_vessel_liquid_volume(G: nx.DiGraph, vessel: str) -> float:
|
||||
def debug_print(message):
|
||||
"""调试输出"""
|
||||
print(f"🧪 [EVAPORATE] {message}", flush=True)
|
||||
logger.info(f"[EVAPORATE] {message}")
|
||||
|
||||
def parse_time_input(time_input: Union[str, float]) -> float:
|
||||
"""
|
||||
获取容器中的液体体积
|
||||
解析时间输入,支持带单位的字符串
|
||||
|
||||
Args:
|
||||
time_input: 时间输入(如 "3 min", "180", "0.5 h" 等)
|
||||
|
||||
Returns:
|
||||
float: 时间(秒)
|
||||
"""
|
||||
if vessel not in G.nodes():
|
||||
return 0.0
|
||||
if isinstance(time_input, (int, float)):
|
||||
debug_print(f"⏱️ 时间输入为数字: {time_input}s ✨")
|
||||
return float(time_input) # 🔧 确保返回float
|
||||
|
||||
vessel_data = G.nodes[vessel].get('data', {})
|
||||
liquids = vessel_data.get('liquid', [])
|
||||
if not time_input or not str(time_input).strip():
|
||||
debug_print(f"⚠️ 时间输入为空,使用默认值: 180s (3分钟) 🕐")
|
||||
return 180.0 # 默认3分钟
|
||||
|
||||
total_volume = 0.0
|
||||
for liquid in liquids:
|
||||
if isinstance(liquid, dict) and 'liquid_volume' in liquid:
|
||||
total_volume += liquid['liquid_volume']
|
||||
time_str = str(time_input).lower().strip()
|
||||
debug_print(f"🔍 解析时间输入: '{time_str}' 📝")
|
||||
|
||||
return total_volume
|
||||
# 处理未知时间
|
||||
if time_str in ['?', 'unknown', 'tbd']:
|
||||
default_time = 180.0 # 默认3分钟
|
||||
debug_print(f"❓ 检测到未知时间,使用默认值: {default_time}s (3分钟) 🤷♀️")
|
||||
return default_time
|
||||
|
||||
# 移除空格并提取数字和单位
|
||||
time_clean = re.sub(r'\s+', '', time_str)
|
||||
|
||||
# 匹配数字和单位的正则表达式
|
||||
match = re.match(r'([0-9]*\.?[0-9]+)\s*(s|sec|second|min|minute|h|hr|hour|d|day)?', time_clean)
|
||||
|
||||
if not match:
|
||||
# 如果无法解析,尝试直接转换为数字(默认秒)
|
||||
try:
|
||||
value = float(time_str)
|
||||
debug_print(f"✅ 时间解析成功: {time_str} → {value}s(无单位,默认秒)⏰")
|
||||
return float(value) # 🔧 确保返回float
|
||||
except ValueError:
|
||||
debug_print(f"❌ 无法解析时间: '{time_str}',使用默认值180s (3分钟) 😅")
|
||||
return 180.0
|
||||
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2) or 's' # 默认单位为秒
|
||||
|
||||
# 转换为秒
|
||||
if unit in ['min', 'minute']:
|
||||
time_sec = value * 60.0 # min -> s
|
||||
debug_print(f"🕐 时间转换: {value} 分钟 → {time_sec}s ⏰")
|
||||
elif unit in ['h', 'hr', 'hour']:
|
||||
time_sec = value * 3600.0 # h -> s
|
||||
debug_print(f"🕐 时间转换: {value} 小时 → {time_sec}s ({time_sec/60:.1f}分钟) ⏰")
|
||||
elif unit in ['d', 'day']:
|
||||
time_sec = value * 86400.0 # d -> s
|
||||
debug_print(f"🕐 时间转换: {value} 天 → {time_sec}s ({time_sec/3600:.1f}小时) ⏰")
|
||||
else: # s, sec, second 或默认
|
||||
time_sec = value # 已经是s
|
||||
debug_print(f"🕐 时间转换: {value}s → {time_sec}s (已是秒) ⏰")
|
||||
|
||||
return float(time_sec) # 🔧 确保返回float
|
||||
|
||||
def find_rotavap_device(G: nx.DiGraph, vessel: str = None) -> Optional[str]:
|
||||
"""
|
||||
在组态图中查找旋转蒸发仪设备
|
||||
|
||||
Args:
|
||||
G: 设备图
|
||||
vessel: 指定的设备名称(可选)
|
||||
|
||||
Returns:
|
||||
str: 找到的旋转蒸发仪设备ID,如果没找到返回None
|
||||
"""
|
||||
debug_print("🔍 开始查找旋转蒸发仪设备... 🌪️")
|
||||
|
||||
# 如果指定了vessel,先检查是否存在且是旋转蒸发仪
|
||||
if vessel:
|
||||
debug_print(f"🎯 检查指定设备: {vessel} 🔧")
|
||||
if vessel in G.nodes():
|
||||
node_data = G.nodes[vessel]
|
||||
node_class = node_data.get('class', '')
|
||||
node_type = node_data.get('type', '')
|
||||
|
||||
debug_print(f"📋 设备信息 {vessel}: class={node_class}, type={node_type}")
|
||||
|
||||
# 检查是否为旋转蒸发仪
|
||||
if any(keyword in str(node_class).lower() for keyword in ['rotavap', 'rotary', 'evaporat']):
|
||||
debug_print(f"🎉 找到指定的旋转蒸发仪: {vessel} ✨")
|
||||
return vessel
|
||||
elif node_type == 'device':
|
||||
debug_print(f"✅ 指定设备存在,尝试直接使用: {vessel} 🔧")
|
||||
return vessel
|
||||
else:
|
||||
debug_print(f"❌ 指定的设备 {vessel} 不存在 😞")
|
||||
|
||||
# 在所有设备中查找旋转蒸发仪
|
||||
debug_print("🔎 在所有设备中搜索旋转蒸发仪... 🕵️♀️")
|
||||
rotavap_candidates = []
|
||||
|
||||
for node_id, node_data in G.nodes(data=True):
|
||||
node_class = node_data.get('class', '')
|
||||
node_type = node_data.get('type', '')
|
||||
|
||||
# 跳过非设备节点
|
||||
if node_type != 'device':
|
||||
continue
|
||||
|
||||
# 检查设备类型
|
||||
if any(keyword in str(node_class).lower() for keyword in ['rotavap', 'rotary', 'evaporat']):
|
||||
rotavap_candidates.append(node_id)
|
||||
debug_print(f"🌟 找到旋转蒸发仪候选: {node_id} (class: {node_class}) 🌪️")
|
||||
elif any(keyword in str(node_id).lower() for keyword in ['rotavap', 'rotary', 'evaporat']):
|
||||
rotavap_candidates.append(node_id)
|
||||
debug_print(f"🌟 找到旋转蒸发仪候选 (按名称): {node_id} 🌪️")
|
||||
|
||||
if rotavap_candidates:
|
||||
selected = rotavap_candidates[0] # 选择第一个找到的
|
||||
debug_print(f"🎯 选择旋转蒸发仪: {selected} 🏆")
|
||||
return selected
|
||||
|
||||
debug_print("😭 未找到旋转蒸发仪设备 💔")
|
||||
return None
|
||||
|
||||
def find_rotavap_device(G: nx.DiGraph) -> str:
|
||||
"""查找旋转蒸发仪设备"""
|
||||
rotavap_nodes = [node for node in G.nodes()
|
||||
if (G.nodes[node].get('class') or '') == 'virtual_rotavap']
|
||||
def find_connected_vessel(G: nx.DiGraph, rotavap_device: str) -> Optional[str]:
|
||||
"""
|
||||
查找与旋转蒸发仪连接的容器
|
||||
|
||||
if rotavap_nodes:
|
||||
return rotavap_nodes[0]
|
||||
Args:
|
||||
G: 设备图
|
||||
rotavap_device: 旋转蒸发仪设备ID
|
||||
|
||||
raise ValueError("系统中未找到旋转蒸发仪设备")
|
||||
|
||||
|
||||
def find_solvent_recovery_vessel(G: nx.DiGraph) -> str:
|
||||
"""查找溶剂回收容器"""
|
||||
possible_names = [
|
||||
"flask_distillate",
|
||||
"bottle_distillate",
|
||||
"vessel_distillate",
|
||||
"distillate",
|
||||
"solvent_recovery",
|
||||
"flask_solvent_recovery",
|
||||
"collection_flask"
|
||||
]
|
||||
Returns:
|
||||
str: 连接的容器ID,如果没找到返回None
|
||||
"""
|
||||
debug_print(f"🔗 查找与 {rotavap_device} 连接的容器... 🥽")
|
||||
|
||||
for vessel_name in possible_names:
|
||||
if vessel_name in G.nodes():
|
||||
return vessel_name
|
||||
# 查看旋转蒸发仪的子设备
|
||||
rotavap_data = G.nodes[rotavap_device]
|
||||
children = rotavap_data.get('children', [])
|
||||
|
||||
# 如果找不到专门的回收容器,使用废液容器
|
||||
waste_names = ["waste_workup", "flask_waste", "bottle_waste", "waste"]
|
||||
for vessel_name in waste_names:
|
||||
if vessel_name in G.nodes():
|
||||
return vessel_name
|
||||
debug_print(f"👶 检查子设备: {children}")
|
||||
for child_id in children:
|
||||
if child_id in G.nodes():
|
||||
child_data = G.nodes[child_id]
|
||||
child_type = child_data.get('type', '')
|
||||
|
||||
if child_type == 'container':
|
||||
debug_print(f"🎉 找到连接的容器: {child_id} 🥽✨")
|
||||
return child_id
|
||||
|
||||
raise ValueError(f"未找到溶剂回收容器。尝试了以下名称: {possible_names + waste_names}")
|
||||
|
||||
# 查看邻接的容器
|
||||
debug_print("🤝 检查邻接设备...")
|
||||
for neighbor in G.neighbors(rotavap_device):
|
||||
neighbor_data = G.nodes[neighbor]
|
||||
neighbor_type = neighbor_data.get('type', '')
|
||||
|
||||
if neighbor_type == 'container':
|
||||
debug_print(f"🎉 找到邻接的容器: {neighbor} 🥽✨")
|
||||
return neighbor
|
||||
|
||||
debug_print("😞 未找到连接的容器 💔")
|
||||
return None
|
||||
|
||||
def generate_evaporate_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
pressure: float = 0.1,
|
||||
temp: float = 60.0,
|
||||
time: float = 1800.0,
|
||||
stir_speed: float = 100.0
|
||||
time: Union[str, float] = "180", # 🔧 修改:支持字符串时间
|
||||
stir_speed: float = 100.0,
|
||||
solvent: str = "",
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成蒸发操作的协议序列
|
||||
|
||||
蒸发流程:
|
||||
1. 液体转移:将待蒸发溶液从源容器转移到旋转蒸发仪
|
||||
2. 蒸发操作:执行旋转蒸发
|
||||
3. (可选) 溶剂回收:将冷凝的溶剂转移到回收容器
|
||||
4. 残留物转移:将浓缩物从旋转蒸发仪转移回原容器或新容器
|
||||
生成蒸发操作的协议序列 - 支持单位和体积运算
|
||||
|
||||
Args:
|
||||
G: 有向图,节点为设备和容器,边为流体管道
|
||||
vessel: 包含待蒸发溶液的容器名称
|
||||
pressure: 蒸发时的真空度 (bar),默认0.1 bar
|
||||
temp: 蒸发时的加热温度 (°C),默认60°C
|
||||
time: 蒸发时间 (秒),默认1800秒(30分钟)
|
||||
stir_speed: 旋转速度 (RPM),默认100 RPM
|
||||
G: 设备图
|
||||
vessel: 容器字典(从XDL传入)
|
||||
pressure: 真空度 (bar),默认0.1
|
||||
temp: 加热温度 (°C),默认60
|
||||
time: 蒸发时间(支持 "3 min", "180", "0.5 h" 等)
|
||||
stir_speed: 旋转速度 (RPM),默认100
|
||||
solvent: 溶剂名称(用于参数优化)
|
||||
**kwargs: 其他参数(兼容性)
|
||||
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 蒸发操作的动作序列
|
||||
|
||||
Raises:
|
||||
ValueError: 当找不到必要的设备时抛出异常
|
||||
|
||||
Examples:
|
||||
evaporate_actions = generate_evaporate_protocol(G, "reaction_mixture", 0.05, 80.0, 3600.0)
|
||||
List[Dict[str, Any]]: 动作序列
|
||||
"""
|
||||
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
debug_print("🌟" * 20)
|
||||
debug_print("🌪️ 开始生成蒸发协议(支持单位和体积运算)✨")
|
||||
debug_print(f"📝 输入参数:")
|
||||
debug_print(f" 🥽 vessel: {vessel} (ID: {vessel_id})")
|
||||
debug_print(f" 💨 pressure: {pressure} bar")
|
||||
debug_print(f" 🌡️ temp: {temp}°C")
|
||||
debug_print(f" ⏰ time: {time} (类型: {type(time)})")
|
||||
debug_print(f" 🌪️ stir_speed: {stir_speed} RPM")
|
||||
debug_print(f" 🧪 solvent: '{solvent}'")
|
||||
debug_print("🌟" * 20)
|
||||
|
||||
# 🔧 新增:记录蒸发前的容器状态
|
||||
debug_print("🔍 记录蒸发前容器状态...")
|
||||
original_liquid_volume = 0.0
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list) and len(current_volume) > 0:
|
||||
original_liquid_volume = current_volume[0]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
original_liquid_volume = current_volume
|
||||
debug_print(f"📊 蒸发前液体体积: {original_liquid_volume:.2f}mL")
|
||||
|
||||
# === 步骤1: 查找旋转蒸发仪设备 ===
|
||||
debug_print("📍 步骤1: 查找旋转蒸发仪设备... 🔍")
|
||||
|
||||
# 验证vessel参数
|
||||
if not vessel_id:
|
||||
debug_print("❌ vessel 参数不能为空! 😱")
|
||||
raise ValueError("vessel 参数不能为空")
|
||||
|
||||
# 查找旋转蒸发仪设备
|
||||
rotavap_device = find_rotavap_device(G, vessel_id)
|
||||
if not rotavap_device:
|
||||
debug_print("💥 未找到旋转蒸发仪设备! 😭")
|
||||
raise ValueError(f"未找到旋转蒸发仪设备。请检查组态图中是否包含 class 包含 'rotavap'、'rotary' 或 'evaporat' 的设备")
|
||||
|
||||
debug_print(f"🎉 成功找到旋转蒸发仪: {rotavap_device} ✨")
|
||||
|
||||
# === 步骤2: 确定目标容器 ===
|
||||
debug_print("📍 步骤2: 确定目标容器... 🥽")
|
||||
|
||||
target_vessel = vessel_id
|
||||
|
||||
# 如果vessel就是旋转蒸发仪设备,查找连接的容器
|
||||
if vessel_id == rotavap_device:
|
||||
debug_print("🔄 vessel就是旋转蒸发仪,查找连接的容器...")
|
||||
connected_vessel = find_connected_vessel(G, rotavap_device)
|
||||
if connected_vessel:
|
||||
target_vessel = connected_vessel
|
||||
debug_print(f"✅ 使用连接的容器: {target_vessel} 🥽✨")
|
||||
else:
|
||||
debug_print(f"⚠️ 未找到连接的容器,使用设备本身: {rotavap_device} 🔧")
|
||||
target_vessel = rotavap_device
|
||||
elif vessel_id in G.nodes() and G.nodes[vessel_id].get('type') == 'container':
|
||||
debug_print(f"✅ 使用指定的容器: {vessel_id} 🥽✨")
|
||||
target_vessel = vessel_id
|
||||
else:
|
||||
debug_print(f"⚠️ 容器 '{vessel_id}' 不存在或类型不正确,使用旋转蒸发仪设备: {rotavap_device} 🔧")
|
||||
target_vessel = rotavap_device
|
||||
|
||||
# === 🔧 新增:步骤3:单位解析处理 ===
|
||||
debug_print("📍 步骤3: 单位解析处理... ⚡")
|
||||
|
||||
# 解析时间
|
||||
final_time = parse_time_input(time)
|
||||
debug_print(f"🎯 时间解析完成: {time} → {final_time}s ({final_time/60:.1f}分钟) ⏰✨")
|
||||
|
||||
# === 步骤4: 参数验证和修正 ===
|
||||
debug_print("📍 步骤4: 参数验证和修正... 🔧")
|
||||
|
||||
# 修正参数范围
|
||||
if pressure <= 0 or pressure > 1.0:
|
||||
debug_print(f"⚠️ 真空度 {pressure} bar 超出范围,修正为 0.1 bar 💨")
|
||||
pressure = 0.1
|
||||
else:
|
||||
debug_print(f"✅ 真空度 {pressure} bar 在正常范围内 💨")
|
||||
|
||||
if temp < 10.0 or temp > 200.0:
|
||||
debug_print(f"⚠️ 温度 {temp}°C 超出范围,修正为 60°C 🌡️")
|
||||
temp = 60.0
|
||||
else:
|
||||
debug_print(f"✅ 温度 {temp}°C 在正常范围内 🌡️")
|
||||
|
||||
if final_time <= 0:
|
||||
debug_print(f"⚠️ 时间 {final_time}s 无效,修正为 180s (3分钟) ⏰")
|
||||
final_time = 180.0
|
||||
else:
|
||||
debug_print(f"✅ 时间 {final_time}s ({final_time/60:.1f}分钟) 有效 ⏰")
|
||||
|
||||
if stir_speed < 10.0 or stir_speed > 300.0:
|
||||
debug_print(f"⚠️ 旋转速度 {stir_speed} RPM 超出范围,修正为 100 RPM 🌪️")
|
||||
stir_speed = 100.0
|
||||
else:
|
||||
debug_print(f"✅ 旋转速度 {stir_speed} RPM 在正常范围内 🌪️")
|
||||
|
||||
# 根据溶剂优化参数
|
||||
if solvent:
|
||||
debug_print(f"🧪 根据溶剂 '{solvent}' 优化参数... 🔬")
|
||||
solvent_lower = solvent.lower()
|
||||
|
||||
if any(s in solvent_lower for s in ['water', 'aqueous', 'h2o']):
|
||||
temp = max(temp, 80.0)
|
||||
pressure = max(pressure, 0.2)
|
||||
debug_print("💧 水系溶剂:提高温度和真空度 🌡️💨")
|
||||
elif any(s in solvent_lower for s in ['ethanol', 'methanol', 'acetone']):
|
||||
temp = min(temp, 50.0)
|
||||
pressure = min(pressure, 0.05)
|
||||
debug_print("🍺 易挥发溶剂:降低温度和真空度 🌡️💨")
|
||||
elif any(s in solvent_lower for s in ['dmso', 'dmi', 'toluene']):
|
||||
temp = max(temp, 100.0)
|
||||
pressure = min(pressure, 0.01)
|
||||
debug_print("🔥 高沸点溶剂:提高温度,降低真空度 🌡️💨")
|
||||
else:
|
||||
debug_print("🧪 通用溶剂,使用标准参数 ✨")
|
||||
else:
|
||||
debug_print("🤷♀️ 未指定溶剂,使用默认参数 ✨")
|
||||
|
||||
debug_print(f"🎯 最终参数: pressure={pressure} bar 💨, temp={temp}°C 🌡️, time={final_time}s ⏰, stir_speed={stir_speed} RPM 🌪️")
|
||||
|
||||
# === 🔧 新增:步骤5:蒸发体积计算 ===
|
||||
debug_print("📍 步骤5: 蒸发体积计算... 📊")
|
||||
|
||||
# 根据温度、真空度、时间和溶剂类型估算蒸发量
|
||||
evaporation_volume = 0.0
|
||||
if original_liquid_volume > 0:
|
||||
# 基础蒸发速率(mL/min)
|
||||
base_evap_rate = 0.5 # 基础速率
|
||||
|
||||
# 温度系数(高温蒸发更快)
|
||||
temp_factor = 1.0 + (temp - 25.0) / 100.0
|
||||
|
||||
# 真空系数(真空度越高蒸发越快)
|
||||
vacuum_factor = 1.0 + (1.0 - pressure) * 2.0
|
||||
|
||||
# 溶剂系数
|
||||
solvent_factor = 1.0
|
||||
if solvent:
|
||||
solvent_lower = solvent.lower()
|
||||
if any(s in solvent_lower for s in ['water', 'h2o']):
|
||||
solvent_factor = 0.8 # 水蒸发较慢
|
||||
elif any(s in solvent_lower for s in ['ethanol', 'methanol', 'acetone']):
|
||||
solvent_factor = 1.5 # 易挥发溶剂蒸发快
|
||||
elif any(s in solvent_lower for s in ['dmso', 'dmi']):
|
||||
solvent_factor = 0.3 # 高沸点溶剂蒸发慢
|
||||
|
||||
# 计算总蒸发量
|
||||
total_evap_rate = base_evap_rate * temp_factor * vacuum_factor * solvent_factor
|
||||
evaporation_volume = min(
|
||||
original_liquid_volume * 0.95, # 最多蒸发95%
|
||||
total_evap_rate * (final_time / 60.0) # 时间相关的蒸发量
|
||||
)
|
||||
|
||||
debug_print(f"📊 蒸发量计算:")
|
||||
debug_print(f" - 基础蒸发速率: {base_evap_rate} mL/min")
|
||||
debug_print(f" - 温度系数: {temp_factor:.2f} (基于 {temp}°C)")
|
||||
debug_print(f" - 真空系数: {vacuum_factor:.2f} (基于 {pressure} bar)")
|
||||
debug_print(f" - 溶剂系数: {solvent_factor:.2f} ({solvent or '通用'})")
|
||||
debug_print(f" - 总蒸发速率: {total_evap_rate:.2f} mL/min")
|
||||
debug_print(f" - 预计蒸发量: {evaporation_volume:.2f}mL ({evaporation_volume/original_liquid_volume*100:.1f}%)")
|
||||
|
||||
# === 步骤6: 生成动作序列 ===
|
||||
debug_print("📍 步骤6: 生成动作序列... 🎬")
|
||||
|
||||
action_sequence = []
|
||||
|
||||
print(f"EVAPORATE: 开始生成蒸发协议")
|
||||
print(f" - 源容器: {vessel}")
|
||||
print(f" - 真空度: {pressure} bar")
|
||||
print(f" - 温度: {temp}°C")
|
||||
print(f" - 时间: {time}s ({time/60:.1f}分钟)")
|
||||
print(f" - 旋转速度: {stir_speed} RPM")
|
||||
|
||||
# 验证源容器存在
|
||||
if vessel not in G.nodes():
|
||||
raise ValueError(f"源容器 '{vessel}' 不存在于系统中")
|
||||
|
||||
# 获取源容器中的液体体积
|
||||
source_volume = get_vessel_liquid_volume(G, vessel)
|
||||
print(f"EVAPORATE: 源容器 {vessel} 中有 {source_volume} mL 液体")
|
||||
|
||||
# 查找旋转蒸发仪
|
||||
try:
|
||||
rotavap_id = find_rotavap_device(G)
|
||||
print(f"EVAPORATE: 找到旋转蒸发仪: {rotavap_id}")
|
||||
except ValueError as e:
|
||||
raise ValueError(f"无法找到旋转蒸发仪: {str(e)}")
|
||||
|
||||
# 查找旋转蒸发仪样品容器
|
||||
rotavap_vessel = None
|
||||
possible_rotavap_vessels = ["rotavap_flask", "rotavap", "flask_rotavap", "evaporation_flask"]
|
||||
for rv in possible_rotavap_vessels:
|
||||
if rv in G.nodes():
|
||||
rotavap_vessel = rv
|
||||
break
|
||||
|
||||
if not rotavap_vessel:
|
||||
raise ValueError(f"未找到旋转蒸发仪样品容器。尝试了: {possible_rotavap_vessels}")
|
||||
|
||||
print(f"EVAPORATE: 找到旋转蒸发仪样品容器: {rotavap_vessel}")
|
||||
|
||||
# 查找溶剂回收容器
|
||||
try:
|
||||
distillate_vessel = find_solvent_recovery_vessel(G)
|
||||
print(f"EVAPORATE: 找到溶剂回收容器: {distillate_vessel}")
|
||||
except ValueError as e:
|
||||
print(f"EVAPORATE: 警告 - {str(e)}")
|
||||
distillate_vessel = None
|
||||
|
||||
# === 简化的体积计算策略 ===
|
||||
if source_volume > 0:
|
||||
# 如果能检测到液体体积,使用实际体积的大部分
|
||||
transfer_volume = min(source_volume * 0.9, 250.0) # 90%或最多250mL
|
||||
print(f"EVAPORATE: 检测到液体体积,将转移 {transfer_volume} mL")
|
||||
else:
|
||||
# 如果检测不到液体体积,默认转移一整瓶 250mL
|
||||
transfer_volume = 250.0
|
||||
print(f"EVAPORATE: 未检测到液体体积,默认转移整瓶 {transfer_volume} mL")
|
||||
|
||||
# === 第一步:将待蒸发溶液转移到旋转蒸发仪 ===
|
||||
print(f"EVAPORATE: 将 {transfer_volume} mL 溶液从 {vessel} 转移到 {rotavap_vessel}")
|
||||
try:
|
||||
transfer_to_rotavap_actions = generate_pump_protocol(
|
||||
G=G,
|
||||
from_vessel=vessel,
|
||||
to_vessel=rotavap_vessel,
|
||||
volume=transfer_volume,
|
||||
flowrate=2.0,
|
||||
transfer_flowrate=2.0
|
||||
)
|
||||
action_sequence.extend(transfer_to_rotavap_actions)
|
||||
except Exception as e:
|
||||
raise ValueError(f"无法将溶液转移到旋转蒸发仪: {str(e)}")
|
||||
|
||||
# 转移后等待
|
||||
wait_action = {
|
||||
# 1. 等待稳定
|
||||
debug_print(" 🔄 动作1: 添加初始等待稳定... ⏳")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": 10}
|
||||
}
|
||||
action_sequence.append(wait_action)
|
||||
})
|
||||
debug_print(" ✅ 初始等待动作已添加 ⏳✨")
|
||||
|
||||
# 2. 执行蒸发
|
||||
debug_print(f" 🌪️ 动作2: 执行蒸发操作...")
|
||||
debug_print(f" 🔧 设备: {rotavap_device}")
|
||||
debug_print(f" 🥽 容器: {target_vessel}")
|
||||
debug_print(f" 💨 真空度: {pressure} bar")
|
||||
debug_print(f" 🌡️ 温度: {temp}°C")
|
||||
debug_print(f" ⏰ 时间: {final_time}s ({final_time/60:.1f}分钟)")
|
||||
debug_print(f" 🌪️ 旋转速度: {stir_speed} RPM")
|
||||
|
||||
# === 第二步:执行旋转蒸发 ===
|
||||
print(f"EVAPORATE: 执行旋转蒸发操作")
|
||||
evaporate_action = {
|
||||
"device_id": rotavap_id,
|
||||
"device_id": rotavap_device,
|
||||
"action_name": "evaporate",
|
||||
"action_kwargs": {
|
||||
"vessel": rotavap_vessel,
|
||||
"pressure": pressure,
|
||||
"temp": temp,
|
||||
"time": time,
|
||||
"stir_speed": stir_speed
|
||||
"vessel": target_vessel,
|
||||
"pressure": float(pressure),
|
||||
"temp": float(temp),
|
||||
"time": float(final_time), # 🔧 强制转换为float类型
|
||||
"stir_speed": float(stir_speed),
|
||||
"solvent": str(solvent)
|
||||
}
|
||||
}
|
||||
action_sequence.append(evaporate_action)
|
||||
debug_print(" ✅ 蒸发动作已添加 🌪️✨")
|
||||
|
||||
# 蒸发后等待系统稳定
|
||||
wait_action = {
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": 30}
|
||||
}
|
||||
action_sequence.append(wait_action)
|
||||
|
||||
# === 第三步:溶剂回收(如果有回收容器)===
|
||||
if distillate_vessel:
|
||||
print(f"EVAPORATE: 回收冷凝溶剂到 {distillate_vessel}")
|
||||
try:
|
||||
condenser_vessel = "rotavap_condenser"
|
||||
if condenser_vessel in G.nodes():
|
||||
# 估算回收体积(约为转移体积的70% - 大部分溶剂被蒸发回收)
|
||||
recovery_volume = transfer_volume * 0.7
|
||||
print(f"EVAPORATE: 预计回收 {recovery_volume} mL 溶剂")
|
||||
|
||||
recovery_actions = generate_pump_protocol(
|
||||
G=G,
|
||||
from_vessel=condenser_vessel,
|
||||
to_vessel=distillate_vessel,
|
||||
volume=recovery_volume,
|
||||
flowrate=3.0,
|
||||
transfer_flowrate=3.0
|
||||
)
|
||||
action_sequence.extend(recovery_actions)
|
||||
# 🔧 新增:蒸发过程中的体积变化
|
||||
debug_print(" 🔧 更新容器体积 - 蒸发过程...")
|
||||
if evaporation_volume > 0:
|
||||
new_volume = max(0.0, original_liquid_volume - evaporation_volume)
|
||||
|
||||
# 更新vessel字典中的体积
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
if len(current_volume) > 0:
|
||||
vessel["data"]["liquid_volume"][0] = new_volume
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = [new_volume]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
vessel["data"]["liquid_volume"] = new_volume
|
||||
else:
|
||||
print("EVAPORATE: 未找到冷凝器容器,跳过溶剂回收")
|
||||
except Exception as e:
|
||||
print(f"EVAPORATE: 溶剂回收失败: {str(e)}")
|
||||
|
||||
# === 第四步:将浓缩物转移回原容器 ===
|
||||
print(f"EVAPORATE: 将浓缩物从旋转蒸发仪转移回 {vessel}")
|
||||
try:
|
||||
# 估算浓缩物体积(约为转移体积的20% - 大部分溶剂已蒸发)
|
||||
concentrate_volume = transfer_volume * 0.2
|
||||
print(f"EVAPORATE: 预计浓缩物体积 {concentrate_volume} mL")
|
||||
vessel["data"]["liquid_volume"] = new_volume
|
||||
|
||||
transfer_back_actions = generate_pump_protocol(
|
||||
G=G,
|
||||
from_vessel=rotavap_vessel,
|
||||
to_vessel=vessel,
|
||||
volume=concentrate_volume,
|
||||
flowrate=1.0, # 浓缩物可能粘稠,用较慢流速
|
||||
transfer_flowrate=1.0
|
||||
)
|
||||
action_sequence.extend(transfer_back_actions)
|
||||
except Exception as e:
|
||||
print(f"EVAPORATE: 将浓缩物转移回容器失败: {str(e)}")
|
||||
|
||||
# === 第五步:清洗旋转蒸发仪 ===
|
||||
print(f"EVAPORATE: 清洗旋转蒸发仪")
|
||||
try:
|
||||
# 查找清洗溶剂
|
||||
cleaning_solvent = None
|
||||
for solvent in ["flask_ethanol", "flask_acetone", "flask_water"]:
|
||||
if solvent in G.nodes():
|
||||
cleaning_solvent = solvent
|
||||
break
|
||||
|
||||
if cleaning_solvent and distillate_vessel:
|
||||
# 用固定量溶剂清洗(不依赖检测体积)
|
||||
cleaning_volume = 50.0 # 固定50mL清洗
|
||||
print(f"EVAPORATE: 用 {cleaning_volume} mL {cleaning_solvent} 清洗")
|
||||
# 🔧 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
if 'data' not in G.nodes[vessel_id]:
|
||||
G.nodes[vessel_id]['data'] = {}
|
||||
|
||||
# 清洗溶剂加入
|
||||
cleaning_actions = generate_pump_protocol(
|
||||
G=G,
|
||||
from_vessel=cleaning_solvent,
|
||||
to_vessel=rotavap_vessel,
|
||||
volume=cleaning_volume,
|
||||
flowrate=2.0,
|
||||
transfer_flowrate=2.0
|
||||
)
|
||||
action_sequence.extend(cleaning_actions)
|
||||
vessel_node_data = G.nodes[vessel_id]['data']
|
||||
current_node_volume = vessel_node_data.get('liquid_volume', 0.0)
|
||||
|
||||
# 将清洗液转移到废液/回收容器
|
||||
waste_actions = generate_pump_protocol(
|
||||
G=G,
|
||||
from_vessel=rotavap_vessel,
|
||||
to_vessel=distillate_vessel, # 使用回收容器作为废液
|
||||
volume=cleaning_volume,
|
||||
flowrate=2.0,
|
||||
transfer_flowrate=2.0
|
||||
)
|
||||
action_sequence.extend(waste_actions)
|
||||
if isinstance(current_node_volume, list):
|
||||
if len(current_node_volume) > 0:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'][0] = new_volume
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = [new_volume]
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = new_volume
|
||||
|
||||
except Exception as e:
|
||||
print(f"EVAPORATE: 清洗步骤失败: {str(e)}")
|
||||
debug_print(f" 📊 蒸发体积变化: {original_liquid_volume:.2f}mL → {new_volume:.2f}mL (-{evaporation_volume:.2f}mL)")
|
||||
|
||||
print(f"EVAPORATE: 生成了 {len(action_sequence)} 个动作")
|
||||
print(f"EVAPORATE: 蒸发协议生成完成")
|
||||
print(f"EVAPORATE: 总处理体积: {transfer_volume} mL")
|
||||
# 3. 蒸发后等待
|
||||
debug_print(" 🔄 动作3: 添加蒸发后等待... ⏳")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": 10}
|
||||
})
|
||||
debug_print(" ✅ 蒸发后等待动作已添加 ⏳✨")
|
||||
|
||||
# 🔧 新增:蒸发完成后的状态报告
|
||||
final_liquid_volume = 0.0
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list) and len(current_volume) > 0:
|
||||
final_liquid_volume = current_volume[0]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
final_liquid_volume = current_volume
|
||||
|
||||
# === 总结 ===
|
||||
debug_print("🎊" * 20)
|
||||
debug_print(f"🎉 蒸发协议生成完成! ✨")
|
||||
debug_print(f"📊 总动作数: {len(action_sequence)} 个 📝")
|
||||
debug_print(f"🌪️ 旋转蒸发仪: {rotavap_device} 🔧")
|
||||
debug_print(f"🥽 目标容器: {target_vessel} 🧪")
|
||||
debug_print(f"⚙️ 蒸发参数: {pressure} bar 💨, {temp}°C 🌡️, {final_time}s ⏰, {stir_speed} RPM 🌪️")
|
||||
debug_print(f"⏱️ 预计总时间: {(final_time + 20)/60:.1f} 分钟 ⌛")
|
||||
debug_print(f"📊 体积变化:")
|
||||
debug_print(f" - 蒸发前: {original_liquid_volume:.2f}mL")
|
||||
debug_print(f" - 蒸发后: {final_liquid_volume:.2f}mL")
|
||||
debug_print(f" - 蒸发量: {evaporation_volume:.2f}mL ({evaporation_volume/max(original_liquid_volume, 0.01)*100:.1f}%)")
|
||||
debug_print("🎊" * 20)
|
||||
|
||||
return action_sequence
|
||||
|
||||
|
||||
# 便捷函数:常用蒸发方案 - 都使用250mL标准瓶体积
|
||||
def generate_quick_evaporate_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
temp: float = 40.0,
|
||||
time: float = 900.0 # 15分钟
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""快速蒸发:低温、短时间、整瓶处理"""
|
||||
return generate_evaporate_protocol(G, vessel, 0.2, temp, time, 80.0)
|
||||
|
||||
|
||||
def generate_gentle_evaporate_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
temp: float = 50.0,
|
||||
time: float = 2700.0 # 45分钟
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""温和蒸发:中等条件、较长时间、整瓶处理"""
|
||||
return generate_evaporate_protocol(G, vessel, 0.1, temp, time, 60.0)
|
||||
|
||||
|
||||
def generate_high_vacuum_evaporate_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
temp: float = 35.0,
|
||||
time: float = 3600.0 # 1小时
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""高真空蒸发:低温、高真空、长时间、整瓶处理"""
|
||||
return generate_evaporate_protocol(G, vessel, 0.01, temp, time, 120.0)
|
||||
|
||||
|
||||
def generate_standard_evaporate_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""标准蒸发:常用参数、整瓶250mL处理"""
|
||||
return generate_evaporate_protocol(
|
||||
G=G,
|
||||
vessel=vessel,
|
||||
pressure=0.1, # 标准真空度
|
||||
temp=60.0, # 适中温度
|
||||
time=1800.0, # 30分钟
|
||||
stir_speed=100.0 # 适中旋转速度
|
||||
)
|
||||
|
||||
@@ -1,304 +1,366 @@
|
||||
from typing import List, Dict, Any
|
||||
from typing import List, Dict, Any, Optional
|
||||
import networkx as nx
|
||||
from .pump_protocol import generate_pump_protocol
|
||||
import logging
|
||||
from .pump_protocol import generate_pump_protocol_with_rinsing
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def get_vessel_liquid_volume(G: nx.DiGraph, vessel: str) -> float:
|
||||
"""获取容器中的液体体积"""
|
||||
if vessel not in G.nodes():
|
||||
return 0.0
|
||||
|
||||
vessel_data = G.nodes[vessel].get('data', {})
|
||||
liquids = vessel_data.get('liquid', [])
|
||||
|
||||
total_volume = 0.0
|
||||
for liquid in liquids:
|
||||
if isinstance(liquid, dict) and 'liquid_volume' in liquid:
|
||||
total_volume += liquid['liquid_volume']
|
||||
|
||||
return total_volume
|
||||
|
||||
def debug_print(message):
|
||||
"""调试输出"""
|
||||
print(f"🧪 [FILTER] {message}", flush=True)
|
||||
logger.info(f"[FILTER] {message}")
|
||||
|
||||
def find_filter_device(G: nx.DiGraph) -> str:
|
||||
"""查找过滤器设备"""
|
||||
filter_nodes = [node for node in G.nodes()
|
||||
if (G.nodes[node].get('class') or '') == 'virtual_filter']
|
||||
debug_print("🔍 查找过滤器设备... 🌊")
|
||||
|
||||
if filter_nodes:
|
||||
return filter_nodes[0]
|
||||
# 查找过滤器设备
|
||||
for node in G.nodes():
|
||||
node_data = G.nodes[node]
|
||||
node_class = node_data.get('class', '') or ''
|
||||
|
||||
if 'filter' in node_class.lower() or 'filter' in node.lower():
|
||||
debug_print(f"🎉 找到过滤器设备: {node} ✨")
|
||||
return node
|
||||
|
||||
raise ValueError("系统中未找到过滤器设备")
|
||||
# 如果没找到,寻找可能的过滤器名称
|
||||
debug_print("🔎 在预定义名称中搜索过滤器... 📋")
|
||||
possible_names = ["filter", "filter_1", "virtual_filter", "filtration_unit"]
|
||||
for name in possible_names:
|
||||
if name in G.nodes():
|
||||
debug_print(f"🎉 找到过滤器设备: {name} ✨")
|
||||
return name
|
||||
|
||||
debug_print("😭 未找到过滤器设备 💔")
|
||||
raise ValueError("未找到过滤器设备")
|
||||
|
||||
|
||||
def find_filter_vessel(G: nx.DiGraph) -> str:
|
||||
"""查找过滤器专用容器"""
|
||||
possible_names = [
|
||||
"filter_vessel", # 标准过滤器容器
|
||||
"filtration_vessel", # 备选名称
|
||||
"vessel_filter", # 备选名称
|
||||
"filter_unit", # 备选名称
|
||||
"filter" # 简单名称
|
||||
]
|
||||
def validate_vessel(G: nx.DiGraph, vessel: str, vessel_type: str = "容器") -> None:
|
||||
"""验证容器是否存在"""
|
||||
debug_print(f"🔍 验证{vessel_type}: '{vessel}' 🧪")
|
||||
|
||||
for vessel_name in possible_names:
|
||||
if vessel_name in G.nodes():
|
||||
return vessel_name
|
||||
if not vessel:
|
||||
debug_print(f"❌ {vessel_type}不能为空! 😱")
|
||||
raise ValueError(f"{vessel_type}不能为空")
|
||||
|
||||
raise ValueError(f"未找到过滤器容器。尝试了以下名称: {possible_names}")
|
||||
|
||||
|
||||
def find_filtrate_vessel(G: nx.DiGraph, filtrate_vessel: str = "") -> str:
|
||||
"""查找滤液收集容器"""
|
||||
if filtrate_vessel and filtrate_vessel in G.nodes():
|
||||
return filtrate_vessel
|
||||
if vessel not in G.nodes():
|
||||
debug_print(f"❌ {vessel_type} '{vessel}' 不存在于系统中! 😞")
|
||||
raise ValueError(f"{vessel_type} '{vessel}' 不存在于系统中")
|
||||
|
||||
# 自动查找滤液容器
|
||||
possible_names = [
|
||||
"filtrate_vessel",
|
||||
"collection_bottle_1",
|
||||
"collection_bottle_2",
|
||||
"waste_workup"
|
||||
]
|
||||
|
||||
for vessel_name in possible_names:
|
||||
if vessel_name in G.nodes():
|
||||
return vessel_name
|
||||
|
||||
raise ValueError(f"未找到滤液收集容器。尝试了以下名称: {possible_names}")
|
||||
|
||||
|
||||
def find_connected_heatchill(G: nx.DiGraph, vessel: str) -> str:
|
||||
"""查找与指定容器相连的加热搅拌器"""
|
||||
# 查找所有加热搅拌器节点
|
||||
heatchill_nodes = [node for node in G.nodes()
|
||||
if G.nodes[node].get('class') == 'virtual_heatchill']
|
||||
|
||||
# 检查哪个加热器与目标容器相连
|
||||
for heatchill in heatchill_nodes:
|
||||
if G.has_edge(heatchill, vessel) or G.has_edge(vessel, heatchill):
|
||||
return heatchill
|
||||
|
||||
# 如果没有直接连接,返回第一个可用的加热器
|
||||
if heatchill_nodes:
|
||||
return heatchill_nodes[0]
|
||||
|
||||
raise ValueError(f"未找到与容器 {vessel} 相连的加热搅拌器")
|
||||
|
||||
debug_print(f"✅ {vessel_type} '{vessel}' 验证通过 🎯")
|
||||
|
||||
def generate_filter_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
filtrate_vessel: str = "",
|
||||
stir: bool = False,
|
||||
stir_speed: float = 300.0,
|
||||
temp: float = 25.0,
|
||||
continue_heatchill: bool = False,
|
||||
volume: float = 0.0
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成过滤操作的协议序列,复用 pump_protocol 的成熟算法
|
||||
|
||||
过滤流程:
|
||||
1. 液体转移:将待过滤溶液从源容器转移到过滤器
|
||||
2. 启动加热搅拌:设置温度和搅拌
|
||||
3. 执行过滤:通过过滤器分离固液
|
||||
4. (可选) 继续或停止加热搅拌
|
||||
生成过滤操作的协议序列 - 支持体积运算
|
||||
|
||||
Args:
|
||||
G: 有向图,节点为设备和容器,边为流体管道
|
||||
vessel: 包含待过滤溶液的容器名称
|
||||
filtrate_vessel: 滤液收集容器(可选,自动查找)
|
||||
stir: 是否在过滤过程中搅拌
|
||||
stir_speed: 搅拌速度 (RPM)
|
||||
temp: 过滤温度 (°C)
|
||||
continue_heatchill: 过滤后是否继续加热搅拌
|
||||
volume: 预期过滤体积 (mL),0表示全部过滤
|
||||
G: 设备图
|
||||
vessel: 过滤容器字典(必需)- 包含需要过滤的混合物
|
||||
filtrate_vessel: 滤液容器名称(可选)- 如果提供则收集滤液
|
||||
**kwargs: 其他参数(兼容性)
|
||||
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 过滤操作的动作序列
|
||||
"""
|
||||
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
debug_print("🌊" * 20)
|
||||
debug_print("🚀 开始生成过滤协议(支持体积运算)✨")
|
||||
debug_print(f"📝 输入参数:")
|
||||
debug_print(f" 🥽 vessel: {vessel} (ID: {vessel_id})")
|
||||
debug_print(f" 🧪 filtrate_vessel: {filtrate_vessel}")
|
||||
debug_print(f" ⚙️ 其他参数: {kwargs}")
|
||||
debug_print("🌊" * 20)
|
||||
|
||||
action_sequence = []
|
||||
|
||||
print(f"FILTER: 开始生成过滤协议")
|
||||
print(f" - 源容器: {vessel}")
|
||||
print(f" - 滤液容器: {filtrate_vessel}")
|
||||
print(f" - 搅拌: {stir} ({stir_speed} RPM)" if stir else " - 搅拌: 否")
|
||||
print(f" - 过滤温度: {temp}°C")
|
||||
print(f" - 预期过滤体积: {volume} mL" if volume > 0 else " - 预期过滤体积: 全部")
|
||||
print(f" - 继续加热搅拌: {continue_heatchill}")
|
||||
# 🔧 新增:记录过滤前的容器状态
|
||||
debug_print("🔍 记录过滤前容器状态...")
|
||||
original_liquid_volume = 0.0
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list) and len(current_volume) > 0:
|
||||
original_liquid_volume = current_volume[0]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
original_liquid_volume = current_volume
|
||||
debug_print(f"📊 过滤前液体体积: {original_liquid_volume:.2f}mL")
|
||||
|
||||
# 验证源容器存在
|
||||
if vessel not in G.nodes():
|
||||
raise ValueError(f"源容器 '{vessel}' 不存在于系统中")
|
||||
# === 参数验证 ===
|
||||
debug_print("📍 步骤1: 参数验证... 🔧")
|
||||
|
||||
# 获取源容器中的液体体积
|
||||
source_volume = get_vessel_liquid_volume(G, vessel)
|
||||
print(f"FILTER: 源容器 {vessel} 中有 {source_volume} mL 液体")
|
||||
# 验证必需参数
|
||||
debug_print(" 🔍 验证必需参数...")
|
||||
validate_vessel(G, vessel_id, "过滤容器") # 🔧 使用 vessel_id
|
||||
debug_print(" ✅ 必需参数验证完成 🎯")
|
||||
|
||||
# 查找过滤器设备
|
||||
try:
|
||||
filter_id = find_filter_device(G)
|
||||
print(f"FILTER: 找到过滤器: {filter_id}")
|
||||
except ValueError as e:
|
||||
raise ValueError(f"无法找到过滤器: {str(e)}")
|
||||
|
||||
# 查找过滤器容器
|
||||
try:
|
||||
filter_vessel_id = find_filter_vessel(G)
|
||||
print(f"FILTER: 找到过滤器容器: {filter_vessel_id}")
|
||||
except ValueError as e:
|
||||
raise ValueError(f"无法找到过滤器容器: {str(e)}")
|
||||
|
||||
# 查找滤液收集容器
|
||||
try:
|
||||
actual_filtrate_vessel = find_filtrate_vessel(G, filtrate_vessel)
|
||||
print(f"FILTER: 找到滤液收集容器: {actual_filtrate_vessel}")
|
||||
except ValueError as e:
|
||||
raise ValueError(f"无法找到滤液收集容器: {str(e)}")
|
||||
|
||||
# 查找加热搅拌器(如果需要温度控制或搅拌)
|
||||
heatchill_id = None
|
||||
if temp != 25.0 or stir or continue_heatchill:
|
||||
try:
|
||||
heatchill_id = find_connected_heatchill(G, filter_vessel_id)
|
||||
print(f"FILTER: 找到加热搅拌器: {heatchill_id}")
|
||||
except ValueError as e:
|
||||
print(f"FILTER: 警告 - {str(e)}")
|
||||
|
||||
# === 简化的体积计算策略 ===
|
||||
if volume > 0:
|
||||
transfer_volume = min(volume, source_volume if source_volume > 0 else volume)
|
||||
print(f"FILTER: 指定过滤体积 {transfer_volume} mL")
|
||||
elif source_volume > 0:
|
||||
transfer_volume = source_volume * 0.9 # 90%
|
||||
print(f"FILTER: 检测到液体体积,将过滤 {transfer_volume} mL")
|
||||
# 验证可选参数
|
||||
debug_print(" 🔍 验证可选参数...")
|
||||
if filtrate_vessel:
|
||||
validate_vessel(G, filtrate_vessel, "滤液容器")
|
||||
debug_print(" 🌊 模式: 过滤并收集滤液 💧")
|
||||
else:
|
||||
transfer_volume = 50.0 # 默认过滤量
|
||||
print(f"FILTER: 未检测到液体体积,默认过滤 {transfer_volume} mL")
|
||||
debug_print(" 🧱 模式: 过滤并收集固体 🔬")
|
||||
debug_print(" ✅ 可选参数验证完成 🎯")
|
||||
|
||||
# === 第一步:启动加热搅拌器(在转移前预热) ===
|
||||
if heatchill_id and (temp != 25.0 or stir):
|
||||
print(f"FILTER: 启动加热搅拌器,温度: {temp}°C,搅拌: {stir}")
|
||||
|
||||
heatchill_action = {
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_start",
|
||||
"action_kwargs": {
|
||||
"vessel": filter_vessel_id,
|
||||
"temp": temp,
|
||||
"purpose": f"过滤过程温度控制和搅拌"
|
||||
}
|
||||
}
|
||||
action_sequence.append(heatchill_action)
|
||||
|
||||
# 等待温度稳定
|
||||
if temp != 25.0:
|
||||
wait_time = min(30, abs(temp - 25.0) * 1.0) # 根据温差估算预热时间
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": wait_time}
|
||||
})
|
||||
# === 查找设备 ===
|
||||
debug_print("📍 步骤2: 查找设备... 🔍")
|
||||
|
||||
# === 第二步:将待过滤溶液转移到过滤器 ===
|
||||
print(f"FILTER: 将 {transfer_volume} mL 溶液从 {vessel} 转移到 {filter_vessel_id}")
|
||||
try:
|
||||
# 使用成熟的 pump_protocol 算法进行液体转移
|
||||
transfer_to_filter_actions = generate_pump_protocol(
|
||||
G=G,
|
||||
from_vessel=vessel,
|
||||
to_vessel=filter_vessel_id,
|
||||
volume=transfer_volume,
|
||||
flowrate=1.0, # 过滤转移用较慢速度,避免扰动
|
||||
transfer_flowrate=1.5
|
||||
)
|
||||
action_sequence.extend(transfer_to_filter_actions)
|
||||
debug_print(" 🔎 搜索过滤器设备...")
|
||||
filter_device = find_filter_device(G)
|
||||
debug_print(f" 🎉 使用过滤器设备: {filter_device} 🌊✨")
|
||||
|
||||
except Exception as e:
|
||||
raise ValueError(f"无法将溶液转移到过滤器: {str(e)}")
|
||||
debug_print(f" ❌ 设备查找失败: {str(e)} 😭")
|
||||
raise ValueError(f"设备查找失败: {str(e)}")
|
||||
|
||||
# 转移后等待
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": 5}
|
||||
})
|
||||
# 🔧 新增:过滤效率和体积分配估算
|
||||
debug_print("📍 步骤2.5: 过滤体积分配估算... 📊")
|
||||
|
||||
# === 第三步:执行过滤操作(完全按照 Filter.action 参数) ===
|
||||
print(f"FILTER: 执行过滤操作")
|
||||
# 估算过滤分离比例(基于经验数据)
|
||||
solid_ratio = 0.1 # 假设10%是固体(保留在过滤器上)
|
||||
liquid_ratio = 0.9 # 假设90%是液体(通过过滤器)
|
||||
volume_loss_ratio = 0.05 # 假设5%体积损失(残留在过滤器等)
|
||||
|
||||
# 从kwargs中获取过滤参数进行优化
|
||||
if "solid_content" in kwargs:
|
||||
try:
|
||||
solid_ratio = float(kwargs["solid_content"])
|
||||
liquid_ratio = 1.0 - solid_ratio
|
||||
debug_print(f"📋 使用指定的固体含量: {solid_ratio*100:.1f}%")
|
||||
except:
|
||||
debug_print("⚠️ 固体含量参数无效,使用默认值")
|
||||
|
||||
if original_liquid_volume > 0:
|
||||
expected_filtrate_volume = original_liquid_volume * liquid_ratio * (1.0 - volume_loss_ratio)
|
||||
expected_solid_volume = original_liquid_volume * solid_ratio
|
||||
volume_loss = original_liquid_volume * volume_loss_ratio
|
||||
|
||||
debug_print(f"📊 过滤体积分配估算:")
|
||||
debug_print(f" - 原始体积: {original_liquid_volume:.2f}mL")
|
||||
debug_print(f" - 预计滤液体积: {expected_filtrate_volume:.2f}mL ({liquid_ratio*100:.1f}%)")
|
||||
debug_print(f" - 预计固体体积: {expected_solid_volume:.2f}mL ({solid_ratio*100:.1f}%)")
|
||||
debug_print(f" - 预计损失体积: {volume_loss:.2f}mL ({volume_loss_ratio*100:.1f}%)")
|
||||
|
||||
# === 转移到过滤器(如果需要)===
|
||||
debug_print("📍 步骤3: 转移到过滤器... 🚚")
|
||||
|
||||
if vessel_id != filter_device: # 🔧 使用 vessel_id
|
||||
debug_print(f" 🚛 需要转移: {vessel_id} → {filter_device} 📦")
|
||||
|
||||
try:
|
||||
debug_print(" 🔄 开始执行转移操作...")
|
||||
# 使用pump protocol转移液体到过滤器
|
||||
transfer_actions = generate_pump_protocol_with_rinsing(
|
||||
G=G,
|
||||
from_vessel=vessel_id, # 🔧 使用 vessel_id
|
||||
to_vessel=filter_device,
|
||||
volume=0.0, # 转移所有液体
|
||||
amount="",
|
||||
time=0.0,
|
||||
viscous=False,
|
||||
rinsing_solvent="",
|
||||
rinsing_volume=0.0,
|
||||
rinsing_repeats=0,
|
||||
solid=False,
|
||||
flowrate=2.0,
|
||||
transfer_flowrate=2.0
|
||||
)
|
||||
|
||||
if transfer_actions:
|
||||
action_sequence.extend(transfer_actions)
|
||||
debug_print(f" ✅ 添加了 {len(transfer_actions)} 个转移动作 🚚✨")
|
||||
|
||||
# 🔧 新增:转移后更新容器体积
|
||||
debug_print(" 🔧 更新转移后的容器体积...")
|
||||
|
||||
# 原容器体积变为0(所有液体已转移)
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
vessel["data"]["liquid_volume"] = [0.0] if len(current_volume) > 0 else [0.0]
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = 0.0
|
||||
|
||||
# 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
if 'data' not in G.nodes[vessel_id]:
|
||||
G.nodes[vessel_id]['data'] = {}
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = 0.0
|
||||
|
||||
debug_print(f" 📊 转移完成,{vessel_id} 体积更新为 0.0mL")
|
||||
|
||||
else:
|
||||
debug_print(" ⚠️ 转移协议返回空序列 🤔")
|
||||
|
||||
except Exception as e:
|
||||
debug_print(f" ❌ 转移失败: {str(e)} 😞")
|
||||
debug_print(" 🔄 继续执行,可能是直接连接的过滤器 🤞")
|
||||
else:
|
||||
debug_print(" ✅ 过滤容器就是过滤器,无需转移 🎯")
|
||||
|
||||
# === 执行过滤操作 ===
|
||||
debug_print("📍 步骤4: 执行过滤操作... 🌊")
|
||||
|
||||
# 构建过滤动作参数
|
||||
debug_print(" ⚙️ 构建过滤参数...")
|
||||
filter_kwargs = {
|
||||
"vessel": filter_device, # 过滤器设备
|
||||
"filtrate_vessel": filtrate_vessel, # 滤液容器(可能为空)
|
||||
"stir": kwargs.get("stir", False),
|
||||
"stir_speed": kwargs.get("stir_speed", 0.0),
|
||||
"temp": kwargs.get("temp", 25.0),
|
||||
"continue_heatchill": kwargs.get("continue_heatchill", False),
|
||||
"volume": kwargs.get("volume", 0.0) # 0表示过滤所有
|
||||
}
|
||||
|
||||
debug_print(f" 📋 过滤参数: {filter_kwargs}")
|
||||
debug_print(" 🌊 开始过滤操作...")
|
||||
|
||||
# 过滤动作
|
||||
filter_action = {
|
||||
"device_id": filter_id,
|
||||
"device_id": filter_device,
|
||||
"action_name": "filter",
|
||||
"action_kwargs": {
|
||||
"vessel": filter_vessel_id,
|
||||
"filtrate_vessel": actual_filtrate_vessel,
|
||||
"stir": stir,
|
||||
"stir_speed": stir_speed,
|
||||
"temp": temp,
|
||||
"continue_heatchill": continue_heatchill,
|
||||
"volume": transfer_volume
|
||||
}
|
||||
"action_kwargs": filter_kwargs
|
||||
}
|
||||
action_sequence.append(filter_action)
|
||||
debug_print(" ✅ 过滤动作已添加 🌊✨")
|
||||
|
||||
# 过滤后等待
|
||||
debug_print(" ⏳ 添加过滤后等待...")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": 10}
|
||||
"action_kwargs": {"time": 10.0}
|
||||
})
|
||||
debug_print(" ✅ 过滤后等待动作已添加 ⏰✨")
|
||||
|
||||
# === 第四步:如果不继续加热搅拌,停止加热器 ===
|
||||
if heatchill_id and not continue_heatchill and (temp != 25.0 or stir):
|
||||
print(f"FILTER: 停止加热搅拌器")
|
||||
# === 收集滤液(如果需要)===
|
||||
debug_print("📍 步骤5: 收集滤液... 💧")
|
||||
|
||||
if filtrate_vessel:
|
||||
debug_print(f" 🧪 收集滤液: {filter_device} → {filtrate_vessel} 💧")
|
||||
|
||||
stop_action = {
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_stop",
|
||||
"action_kwargs": {
|
||||
"vessel": filter_vessel_id
|
||||
}
|
||||
}
|
||||
action_sequence.append(stop_action)
|
||||
try:
|
||||
debug_print(" 🔄 开始执行收集操作...")
|
||||
# 使用pump protocol收集滤液
|
||||
collect_actions = generate_pump_protocol_with_rinsing(
|
||||
G=G,
|
||||
from_vessel=filter_device,
|
||||
to_vessel=filtrate_vessel,
|
||||
volume=0.0, # 收集所有滤液
|
||||
amount="",
|
||||
time=0.0,
|
||||
viscous=False,
|
||||
rinsing_solvent="",
|
||||
rinsing_volume=0.0,
|
||||
rinsing_repeats=0,
|
||||
solid=False,
|
||||
flowrate=2.0,
|
||||
transfer_flowrate=2.0
|
||||
)
|
||||
|
||||
if collect_actions:
|
||||
action_sequence.extend(collect_actions)
|
||||
debug_print(f" ✅ 添加了 {len(collect_actions)} 个收集动作 🧪✨")
|
||||
|
||||
# 🔧 新增:收集滤液后的体积更新
|
||||
debug_print(" 🔧 更新滤液容器体积...")
|
||||
|
||||
# 更新filtrate_vessel在图中的体积(如果它是节点)
|
||||
if filtrate_vessel in G.nodes():
|
||||
if 'data' not in G.nodes[filtrate_vessel]:
|
||||
G.nodes[filtrate_vessel]['data'] = {}
|
||||
|
||||
current_filtrate_volume = G.nodes[filtrate_vessel]['data'].get('liquid_volume', 0.0)
|
||||
if isinstance(current_filtrate_volume, list):
|
||||
if len(current_filtrate_volume) > 0:
|
||||
G.nodes[filtrate_vessel]['data']['liquid_volume'][0] += expected_filtrate_volume
|
||||
else:
|
||||
G.nodes[filtrate_vessel]['data']['liquid_volume'] = [expected_filtrate_volume]
|
||||
else:
|
||||
G.nodes[filtrate_vessel]['data']['liquid_volume'] = current_filtrate_volume + expected_filtrate_volume
|
||||
|
||||
debug_print(f" 📊 滤液容器 {filtrate_vessel} 体积增加 {expected_filtrate_volume:.2f}mL")
|
||||
|
||||
else:
|
||||
debug_print(" ⚠️ 收集协议返回空序列 🤔")
|
||||
|
||||
except Exception as e:
|
||||
debug_print(f" ❌ 收集滤液失败: {str(e)} 😞")
|
||||
debug_print(" 🔄 继续执行,可能滤液直接流入指定容器 🤞")
|
||||
else:
|
||||
debug_print(" 🧱 未指定滤液容器,固体保留在过滤器中 🔬")
|
||||
|
||||
print(f"FILTER: 生成了 {len(action_sequence)} 个动作")
|
||||
print(f"FILTER: 过滤协议生成完成")
|
||||
# 🔧 新增:过滤完成后的容器状态更新
|
||||
debug_print("📍 步骤5.5: 过滤完成后状态更新... 📊")
|
||||
|
||||
if vessel_id == filter_device:
|
||||
# 如果过滤容器就是过滤器,需要更新其体积状态
|
||||
if original_liquid_volume > 0:
|
||||
if filtrate_vessel:
|
||||
# 收集滤液模式:过滤器中主要保留固体
|
||||
remaining_volume = expected_solid_volume
|
||||
debug_print(f" 🧱 过滤器中保留固体: {remaining_volume:.2f}mL")
|
||||
else:
|
||||
# 保留固体模式:过滤器中保留所有物质
|
||||
remaining_volume = original_liquid_volume * (1.0 - volume_loss_ratio)
|
||||
debug_print(f" 🔬 过滤器中保留所有物质: {remaining_volume:.2f}mL")
|
||||
|
||||
# 更新vessel字典中的体积
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
vessel["data"]["liquid_volume"] = [remaining_volume] if len(current_volume) > 0 else [remaining_volume]
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = remaining_volume
|
||||
|
||||
# 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
if 'data' not in G.nodes[vessel_id]:
|
||||
G.nodes[vessel_id]['data'] = {}
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = remaining_volume
|
||||
|
||||
debug_print(f" 📊 过滤器 {vessel_id} 体积更新为: {remaining_volume:.2f}mL")
|
||||
|
||||
# === 最终等待 ===
|
||||
debug_print("📍 步骤6: 最终等待... ⏰")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": 5.0}
|
||||
})
|
||||
debug_print(" ✅ 最终等待动作已添加 ⏰✨")
|
||||
|
||||
# 🔧 新增:过滤完成后的状态报告
|
||||
final_vessel_volume = 0.0
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list) and len(current_volume) > 0:
|
||||
final_vessel_volume = current_volume[0]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
final_vessel_volume = current_volume
|
||||
|
||||
# === 总结 ===
|
||||
debug_print("🎊" * 20)
|
||||
debug_print(f"🎉 过滤协议生成完成! ✨")
|
||||
debug_print(f"📊 总动作数: {len(action_sequence)} 个 📝")
|
||||
debug_print(f"🥽 过滤容器: {vessel_id} 🧪")
|
||||
debug_print(f"🌊 过滤器设备: {filter_device} 🔧")
|
||||
debug_print(f"💧 滤液容器: {filtrate_vessel or '无(保留固体)'} 🧱")
|
||||
debug_print(f"⏱️ 预计总时间: {(len(action_sequence) * 5):.0f} 秒 ⌛")
|
||||
if original_liquid_volume > 0:
|
||||
debug_print(f"📊 体积变化统计:")
|
||||
debug_print(f" - 过滤前体积: {original_liquid_volume:.2f}mL")
|
||||
debug_print(f" - 过滤后容器体积: {final_vessel_volume:.2f}mL")
|
||||
if filtrate_vessel:
|
||||
debug_print(f" - 预计滤液体积: {expected_filtrate_volume:.2f}mL")
|
||||
debug_print(f" - 预计损失体积: {volume_loss:.2f}mL")
|
||||
debug_print("🎊" * 20)
|
||||
|
||||
return action_sequence
|
||||
|
||||
|
||||
# 便捷函数:常用过滤方案
|
||||
def generate_gravity_filter_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
filtrate_vessel: str = ""
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""重力过滤:室温,无搅拌"""
|
||||
return generate_filter_protocol(G, vessel, filtrate_vessel, False, 0.0, 25.0, False, 0.0)
|
||||
|
||||
|
||||
def generate_hot_filter_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
filtrate_vessel: str = "",
|
||||
temp: float = 60.0
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""热过滤:高温过滤,防止结晶析出"""
|
||||
return generate_filter_protocol(G, vessel, filtrate_vessel, False, 0.0, temp, False, 0.0)
|
||||
|
||||
|
||||
def generate_stirred_filter_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
filtrate_vessel: str = "",
|
||||
stir_speed: float = 200.0
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""搅拌过滤:低速搅拌,防止滤饼堵塞"""
|
||||
return generate_filter_protocol(G, vessel, filtrate_vessel, True, stir_speed, 25.0, False, 0.0)
|
||||
|
||||
|
||||
def generate_hot_stirred_filter_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
filtrate_vessel: str = "",
|
||||
temp: float = 60.0,
|
||||
stir_speed: float = 300.0
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""热搅拌过滤:高温搅拌过滤"""
|
||||
return generate_filter_protocol(G, vessel, filtrate_vessel, True, stir_speed, temp, False, 0.0)
|
||||
@@ -1,373 +1,396 @@
|
||||
from typing import List, Dict, Any, Optional
|
||||
from typing import List, Dict, Any, Union
|
||||
import networkx as nx
|
||||
import logging
|
||||
import re
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def debug_print(message):
|
||||
"""调试输出"""
|
||||
print(f"🌡️ [HEATCHILL] {message}", flush=True)
|
||||
logger.info(f"[HEATCHILL] {message}")
|
||||
|
||||
def parse_time_input(time_input: Union[str, float, int]) -> float:
|
||||
"""
|
||||
解析时间输入(统一函数)
|
||||
|
||||
Args:
|
||||
time_input: 时间输入(如 "30 min", "1 h", "300", "?", 60.0)
|
||||
|
||||
Returns:
|
||||
float: 时间(秒)
|
||||
"""
|
||||
if not time_input:
|
||||
return 300.0
|
||||
|
||||
# 🔢 处理数值输入
|
||||
if isinstance(time_input, (int, float)):
|
||||
result = float(time_input)
|
||||
debug_print(f"⏰ 数值时间: {time_input} → {result}s")
|
||||
return result
|
||||
|
||||
# 📝 处理字符串输入
|
||||
time_str = str(time_input).lower().strip()
|
||||
debug_print(f"🔍 解析时间: '{time_str}'")
|
||||
|
||||
# ❓ 特殊值处理
|
||||
special_times = {
|
||||
'?': 300.0, 'unknown': 300.0, 'tbd': 300.0,
|
||||
'overnight': 43200.0, 'several hours': 10800.0,
|
||||
'few hours': 7200.0, 'long time': 3600.0, 'short time': 300.0
|
||||
}
|
||||
|
||||
if time_str in special_times:
|
||||
result = special_times[time_str]
|
||||
debug_print(f"🎯 特殊时间: '{time_str}' → {result}s ({result/60:.1f}分钟)")
|
||||
return result
|
||||
|
||||
# 🔢 纯数字处理
|
||||
try:
|
||||
result = float(time_str)
|
||||
debug_print(f"⏰ 纯数字: {time_str} → {result}s")
|
||||
return result
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 📐 正则表达式解析
|
||||
pattern = r'(\d+\.?\d*)\s*([a-z]*)'
|
||||
match = re.match(pattern, time_str)
|
||||
|
||||
if not match:
|
||||
debug_print(f"⚠️ 无法解析时间: '{time_str}',使用默认值: 300s")
|
||||
return 300.0
|
||||
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2) or 's'
|
||||
|
||||
# 📏 单位转换
|
||||
unit_multipliers = {
|
||||
's': 1.0, 'sec': 1.0, 'second': 1.0, 'seconds': 1.0,
|
||||
'm': 60.0, 'min': 60.0, 'mins': 60.0, 'minute': 60.0, 'minutes': 60.0,
|
||||
'h': 3600.0, 'hr': 3600.0, 'hrs': 3600.0, 'hour': 3600.0, 'hours': 3600.0,
|
||||
'd': 86400.0, 'day': 86400.0, 'days': 86400.0
|
||||
}
|
||||
|
||||
multiplier = unit_multipliers.get(unit, 1.0)
|
||||
result = value * multiplier
|
||||
|
||||
debug_print(f"✅ 时间解析: '{time_str}' → {value} {unit} → {result}s ({result/60:.1f}分钟)")
|
||||
return result
|
||||
|
||||
def parse_temp_input(temp_input: Union[str, float], default_temp: float = 25.0) -> float:
|
||||
"""
|
||||
解析温度输入(统一函数)
|
||||
|
||||
Args:
|
||||
temp_input: 温度输入
|
||||
default_temp: 默认温度
|
||||
|
||||
Returns:
|
||||
float: 温度(°C)
|
||||
"""
|
||||
if not temp_input:
|
||||
return default_temp
|
||||
|
||||
# 🔢 数值输入
|
||||
if isinstance(temp_input, (int, float)):
|
||||
result = float(temp_input)
|
||||
debug_print(f"🌡️ 数值温度: {temp_input} → {result}°C")
|
||||
return result
|
||||
|
||||
# 📝 字符串输入
|
||||
temp_str = str(temp_input).lower().strip()
|
||||
debug_print(f"🔍 解析温度: '{temp_str}'")
|
||||
|
||||
# 🎯 特殊温度
|
||||
special_temps = {
|
||||
"room temperature": 25.0, "reflux": 78.0, "ice bath": 0.0,
|
||||
"boiling": 100.0, "hot": 60.0, "warm": 40.0, "cold": 10.0
|
||||
}
|
||||
|
||||
if temp_str in special_temps:
|
||||
result = special_temps[temp_str]
|
||||
debug_print(f"🎯 特殊温度: '{temp_str}' → {result}°C")
|
||||
return result
|
||||
|
||||
# 📐 正则解析(如 "256 °C")
|
||||
temp_pattern = r'(\d+(?:\.\d+)?)\s*°?[cf]?'
|
||||
match = re.search(temp_pattern, temp_str)
|
||||
|
||||
if match:
|
||||
result = float(match.group(1))
|
||||
debug_print(f"✅ 温度解析: '{temp_str}' → {result}°C")
|
||||
return result
|
||||
|
||||
debug_print(f"⚠️ 无法解析温度: '{temp_str}',使用默认值: {default_temp}°C")
|
||||
return default_temp
|
||||
|
||||
def find_connected_heatchill(G: nx.DiGraph, vessel: str) -> str:
|
||||
"""
|
||||
查找与指定容器相连的加热/冷却设备
|
||||
"""
|
||||
# 查找所有加热/冷却设备节点
|
||||
heatchill_nodes = [node for node in G.nodes()
|
||||
if (G.nodes[node].get('class') or '') == 'virtual_heatchill']
|
||||
"""查找与指定容器相连的加热/冷却设备"""
|
||||
debug_print(f"🔍 查找加热设备,目标容器: {vessel}")
|
||||
|
||||
# 检查哪个加热/冷却设备与目标容器相连(机械连接)
|
||||
for heatchill in heatchill_nodes:
|
||||
if G.has_edge(heatchill, vessel) or G.has_edge(vessel, heatchill):
|
||||
return heatchill
|
||||
# 🔧 查找所有加热设备
|
||||
heatchill_nodes = []
|
||||
for node in G.nodes():
|
||||
node_data = G.nodes[node]
|
||||
node_class = node_data.get('class', '') or ''
|
||||
|
||||
if 'heatchill' in node_class.lower() or 'virtual_heatchill' in node_class:
|
||||
heatchill_nodes.append(node)
|
||||
debug_print(f"🎉 找到加热设备: {node}")
|
||||
|
||||
# 如果没有直接连接,返回第一个可用的加热/冷却设备
|
||||
# 🔗 检查连接
|
||||
if vessel and heatchill_nodes:
|
||||
for heatchill in heatchill_nodes:
|
||||
if G.has_edge(heatchill, vessel) or G.has_edge(vessel, heatchill):
|
||||
debug_print(f"✅ 加热设备 '{heatchill}' 与容器 '{vessel}' 相连")
|
||||
return heatchill
|
||||
|
||||
# 🎯 使用第一个可用设备
|
||||
if heatchill_nodes:
|
||||
return heatchill_nodes[0]
|
||||
selected = heatchill_nodes[0]
|
||||
debug_print(f"🔧 使用第一个加热设备: {selected}")
|
||||
return selected
|
||||
|
||||
raise ValueError("系统中未找到可用的加热/冷却设备")
|
||||
# 🆘 默认设备
|
||||
debug_print("⚠️ 未找到加热设备,使用默认设备")
|
||||
return "heatchill_1"
|
||||
|
||||
def validate_and_fix_params(temp: float, time: float, stir_speed: float) -> tuple:
|
||||
"""验证和修正参数"""
|
||||
# 🌡️ 温度范围验证
|
||||
if temp < -50.0 or temp > 300.0:
|
||||
debug_print(f"⚠️ 温度 {temp}°C 超出范围,修正为 25°C")
|
||||
temp = 25.0
|
||||
else:
|
||||
debug_print(f"✅ 温度 {temp}°C 在正常范围内")
|
||||
|
||||
# ⏰ 时间验证
|
||||
if time < 0:
|
||||
debug_print(f"⚠️ 时间 {time}s 无效,修正为 300s")
|
||||
time = 300.0
|
||||
else:
|
||||
debug_print(f"✅ 时间 {time}s ({time/60:.1f}分钟) 有效")
|
||||
|
||||
# 🌪️ 搅拌速度验证
|
||||
if stir_speed < 0 or stir_speed > 1500.0:
|
||||
debug_print(f"⚠️ 搅拌速度 {stir_speed} RPM 超出范围,修正为 300 RPM")
|
||||
stir_speed = 300.0
|
||||
else:
|
||||
debug_print(f"✅ 搅拌速度 {stir_speed} RPM 在正常范围内")
|
||||
|
||||
return temp, time, stir_speed
|
||||
|
||||
def generate_heat_chill_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
temp: float,
|
||||
time: float,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
temp: float = 25.0,
|
||||
time: Union[str, float] = "300",
|
||||
temp_spec: str = "",
|
||||
time_spec: str = "",
|
||||
pressure: str = "",
|
||||
reflux_solvent: str = "",
|
||||
stir: bool = False,
|
||||
stir_speed: float = 300.0,
|
||||
purpose: str = "加热/冷却操作"
|
||||
purpose: str = "",
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成加热/冷却操作的协议序列 - 带时间限制的完整操作
|
||||
生成加热/冷却操作的协议序列 - 支持vessel字典
|
||||
|
||||
Args:
|
||||
G: 设备图
|
||||
vessel: 容器字典(从XDL传入)
|
||||
temp: 目标温度 (°C)
|
||||
time: 加热时间(支持字符串如 "30 min")
|
||||
temp_spec: 温度规格说明(优先级高于temp)
|
||||
time_spec: 时间规格说明(优先级高于time)
|
||||
pressure: 压力设置
|
||||
reflux_solvent: 回流溶剂
|
||||
stir: 是否搅拌
|
||||
stir_speed: 搅拌速度 (RPM)
|
||||
purpose: 操作目的说明
|
||||
**kwargs: 其他参数(兼容性)
|
||||
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 加热/冷却操作的动作序列
|
||||
"""
|
||||
action_sequence = []
|
||||
|
||||
print(f"HEATCHILL: 开始生成加热/冷却协议")
|
||||
print(f" - 容器: {vessel}")
|
||||
print(f" - 目标温度: {temp}°C")
|
||||
print(f" - 持续时间: {time}秒")
|
||||
print(f" - 使用内置搅拌: {stir}, 速度: {stir_speed} RPM")
|
||||
print(f" - 目的: {purpose}")
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
# 1. 验证容器存在
|
||||
if vessel not in G.nodes():
|
||||
raise ValueError(f"容器 '{vessel}' 不存在于系统中")
|
||||
debug_print("🌡️" * 20)
|
||||
debug_print("🚀 开始生成加热冷却协议(支持vessel字典)✨")
|
||||
debug_print(f"📝 输入参数:")
|
||||
debug_print(f" 🥽 vessel: {vessel} (ID: {vessel_id})")
|
||||
debug_print(f" 🌡️ temp: {temp}°C")
|
||||
debug_print(f" ⏰ time: {time}")
|
||||
debug_print(f" 🎯 temp_spec: {temp_spec}")
|
||||
debug_print(f" ⏱️ time_spec: {time_spec}")
|
||||
debug_print(f" 🌪️ stir: {stir} ({stir_speed} RPM)")
|
||||
debug_print(f" 🎭 purpose: '{purpose}'")
|
||||
debug_print("🌡️" * 20)
|
||||
|
||||
# 2. 查找加热/冷却设备
|
||||
# 📋 参数验证
|
||||
debug_print("📍 步骤1: 参数验证... 🔧")
|
||||
if not vessel_id: # 🔧 使用 vessel_id
|
||||
debug_print("❌ vessel 参数不能为空! 😱")
|
||||
raise ValueError("vessel 参数不能为空")
|
||||
|
||||
if vessel_id not in G.nodes(): # 🔧 使用 vessel_id
|
||||
debug_print(f"❌ 容器 '{vessel_id}' 不存在于系统中! 😞")
|
||||
raise ValueError(f"容器 '{vessel_id}' 不存在于系统中")
|
||||
|
||||
debug_print("✅ 基础参数验证通过 🎯")
|
||||
|
||||
# 🔄 参数解析
|
||||
debug_print("📍 步骤2: 参数解析... ⚡")
|
||||
|
||||
#温度解析:优先使用 temp_spec
|
||||
final_temp = parse_temp_input(temp_spec, temp) if temp_spec else temp
|
||||
|
||||
# 时间解析:优先使用 time_spec
|
||||
final_time = parse_time_input(time_spec) if time_spec else parse_time_input(time)
|
||||
|
||||
# 参数修正
|
||||
final_temp, final_time, stir_speed = validate_and_fix_params(final_temp, final_time, stir_speed)
|
||||
|
||||
debug_print(f"🎯 最终参数: temp={final_temp}°C, time={final_time}s, stir_speed={stir_speed} RPM")
|
||||
|
||||
# 🔍 查找设备
|
||||
debug_print("📍 步骤3: 查找加热设备... 🔍")
|
||||
try:
|
||||
heatchill_id = find_connected_heatchill(G, vessel)
|
||||
print(f"HEATCHILL: 找到加热/冷却设备: {heatchill_id}")
|
||||
except ValueError as e:
|
||||
raise ValueError(f"无法找到加热/冷却设备: {str(e)}")
|
||||
heatchill_id = find_connected_heatchill(G, vessel_id) # 🔧 使用 vessel_id
|
||||
debug_print(f"🎉 使用加热设备: {heatchill_id} ✨")
|
||||
except Exception as e:
|
||||
debug_print(f"❌ 设备查找失败: {str(e)} 😭")
|
||||
raise ValueError(f"无法找到加热设备: {str(e)}")
|
||||
|
||||
# 3. 执行加热/冷却操作
|
||||
# 🚀 生成动作
|
||||
debug_print("📍 步骤4: 生成加热动作... 🔥")
|
||||
|
||||
# 🕐 模拟运行时间优化
|
||||
debug_print(" ⏱️ 检查模拟运行时间限制...")
|
||||
original_time = final_time
|
||||
simulation_time_limit = 100.0 # 模拟运行时间限制:100秒
|
||||
|
||||
if final_time > simulation_time_limit:
|
||||
final_time = simulation_time_limit
|
||||
debug_print(f" 🎮 模拟运行优化: {original_time}s → {final_time}s (限制为{simulation_time_limit}s) ⚡")
|
||||
debug_print(f" 📊 时间缩短: {original_time/60:.1f}分钟 → {final_time/60:.1f}分钟 🚀")
|
||||
else:
|
||||
debug_print(f" ✅ 时间在限制内: {final_time}s ({final_time/60:.1f}分钟) 保持不变 🎯")
|
||||
|
||||
action_sequence = []
|
||||
heatchill_action = {
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel,
|
||||
"temp": temp,
|
||||
"time": time,
|
||||
"stir": stir,
|
||||
"stir_speed": stir_speed,
|
||||
"status": "start"
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"temp": float(final_temp),
|
||||
"time": float(final_time),
|
||||
"stir": bool(stir),
|
||||
"stir_speed": float(stir_speed),
|
||||
"purpose": str(purpose or f"加热到 {final_temp}°C") + (f" (模拟时间: {final_time}s)" if original_time != final_time else "")
|
||||
}
|
||||
}
|
||||
|
||||
action_sequence.append(heatchill_action)
|
||||
debug_print("✅ 加热动作已添加 🔥✨")
|
||||
|
||||
# 显示时间调整信息
|
||||
if original_time != final_time:
|
||||
debug_print(f" 🎭 模拟优化说明: 原计划 {original_time/60:.1f}分钟,实际模拟 {final_time/60:.1f}分钟 ⚡")
|
||||
|
||||
# 🎊 总结
|
||||
debug_print("🎊" * 20)
|
||||
debug_print(f"🎉 加热冷却协议生成完成! ✨")
|
||||
debug_print(f"📊 总动作数: {len(action_sequence)} 个")
|
||||
debug_print(f"🥽 加热容器: {vessel_id}")
|
||||
debug_print(f"🌡️ 目标温度: {final_temp}°C")
|
||||
debug_print(f"⏰ 加热时间: {final_time}s ({final_time/60:.1f}分钟)")
|
||||
debug_print("🎊" * 20)
|
||||
|
||||
print(f"HEATCHILL: 生成了 {len(action_sequence)} 个动作")
|
||||
return action_sequence
|
||||
|
||||
|
||||
def generate_heat_chill_start_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
temp: float,
|
||||
purpose: str = "开始加热/冷却"
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成开始加热/冷却操作的协议序列
|
||||
"""
|
||||
action_sequence = []
|
||||
|
||||
print(f"HEATCHILL_START: 开始生成加热/冷却启动协议")
|
||||
print(f" - 容器: {vessel}")
|
||||
print(f" - 目标温度: {temp}°C")
|
||||
print(f" - 目的: {purpose}")
|
||||
|
||||
# 1. 验证容器存在
|
||||
if vessel not in G.nodes():
|
||||
raise ValueError(f"容器 '{vessel}' 不存在于系统中")
|
||||
|
||||
# 2. 查找加热/冷却设备
|
||||
try:
|
||||
heatchill_id = find_connected_heatchill(G, vessel)
|
||||
print(f"HEATCHILL_START: 找到加热/冷却设备: {heatchill_id}")
|
||||
except ValueError as e:
|
||||
raise ValueError(f"无法找到加热/冷却设备: {str(e)}")
|
||||
|
||||
# 3. 执行开始加热/冷却操作
|
||||
heatchill_start_action = {
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_start",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel,
|
||||
"temp": temp,
|
||||
"purpose": purpose
|
||||
}
|
||||
}
|
||||
|
||||
action_sequence.append(heatchill_start_action)
|
||||
|
||||
print(f"HEATCHILL_START: 生成了 {len(action_sequence)} 个动作")
|
||||
return action_sequence
|
||||
|
||||
|
||||
def generate_heat_chill_stop_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成停止加热/冷却操作的协议序列
|
||||
"""
|
||||
action_sequence = []
|
||||
|
||||
print(f"HEATCHILL_STOP: 开始生成加热/冷却停止协议")
|
||||
print(f" - 容器: {vessel}")
|
||||
|
||||
# 1. 验证容器存在
|
||||
if vessel not in G.nodes():
|
||||
raise ValueError(f"容器 '{vessel}' 不存在于系统中")
|
||||
|
||||
# 2. 查找加热/冷却设备
|
||||
try:
|
||||
heatchill_id = find_connected_heatchill(G, vessel)
|
||||
print(f"HEATCHILL_STOP: 找到加热/冷却设备: {heatchill_id}")
|
||||
except ValueError as e:
|
||||
raise ValueError(f"无法找到加热/冷却设备: {str(e)}")
|
||||
|
||||
# 3. 执行停止加热/冷却操作
|
||||
heatchill_stop_action = {
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_stop",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel
|
||||
}
|
||||
}
|
||||
|
||||
action_sequence.append(heatchill_stop_action)
|
||||
|
||||
print(f"HEATCHILL_STOP: 生成了 {len(action_sequence)} 个动作")
|
||||
return action_sequence
|
||||
|
||||
|
||||
def generate_heat_chill_to_temp_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
temp: float,
|
||||
active: bool = True,
|
||||
continue_heatchill: bool = False,
|
||||
stir: bool = False,
|
||||
stir_speed: Optional[float] = None,
|
||||
purpose: Optional[str] = None
|
||||
vessel: dict, # 🔧 修改参数类型
|
||||
temp: float = 25.0,
|
||||
time: Union[str, float] = 100.0,
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成加热/冷却到指定温度的协议序列 - 智能温控协议
|
||||
"""生成加热到指定温度的协议(简化版)"""
|
||||
vessel_id = vessel["id"]
|
||||
debug_print(f"🌡️ 生成加热到温度协议: {vessel_id} → {temp}°C")
|
||||
return generate_heat_chill_protocol(G, vessel, temp, time, **kwargs)
|
||||
|
||||
def generate_heat_chill_start_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: dict, # 🔧 修改参数类型
|
||||
temp: float = 25.0,
|
||||
purpose: str = "",
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""生成开始加热操作的协议序列"""
|
||||
|
||||
**关键修复**: 学习 pump_protocol 的模式,直接使用设备基础动作,不依赖特定的 Action 文件
|
||||
"""
|
||||
action_sequence = []
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
# 设置默认值
|
||||
if stir_speed is None:
|
||||
stir_speed = 300.0
|
||||
if purpose is None:
|
||||
purpose = f"智能温控到 {temp}°C"
|
||||
debug_print("🔥 开始生成启动加热协议 ✨")
|
||||
debug_print(f"🥽 vessel: {vessel} (ID: {vessel_id}), 🌡️ temp: {temp}°C")
|
||||
|
||||
print(f"HEATCHILL_TO_TEMP: 开始生成智能温控协议")
|
||||
print(f" - 容器: {vessel}")
|
||||
print(f" - 目标温度: {temp}°C")
|
||||
print(f" - 主动控温: {active}")
|
||||
print(f" - 达到温度后继续: {continue_heatchill}")
|
||||
print(f" - 搅拌: {stir}, 速度: {stir_speed} RPM")
|
||||
print(f" - 目的: {purpose}")
|
||||
# 基础验证
|
||||
if not vessel_id or vessel_id not in G.nodes(): # 🔧 使用 vessel_id
|
||||
debug_print("❌ 容器验证失败!")
|
||||
raise ValueError("vessel 参数无效")
|
||||
|
||||
# 1. 验证容器存在
|
||||
if vessel not in G.nodes():
|
||||
raise ValueError(f"容器 '{vessel}' 不存在于系统中")
|
||||
# 查找设备
|
||||
heatchill_id = find_connected_heatchill(G, vessel_id) # 🔧 使用 vessel_id
|
||||
|
||||
# 2. 查找加热/冷却设备
|
||||
try:
|
||||
heatchill_id = find_connected_heatchill(G, vessel)
|
||||
print(f"HEATCHILL_TO_TEMP: 找到加热/冷却设备: {heatchill_id}")
|
||||
except ValueError as e:
|
||||
raise ValueError(f"无法找到加热/冷却设备: {str(e)}")
|
||||
# 生成动作
|
||||
action_sequence = [{
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_start",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"temp": temp,
|
||||
"purpose": purpose or f"开始加热到 {temp}°C"
|
||||
}
|
||||
}]
|
||||
|
||||
# 3. 根据参数选择合适的基础动作组合 (学习 pump_protocol 的模式)
|
||||
if not active:
|
||||
print(f"HEATCHILL_TO_TEMP: 非主动模式,仅等待")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 10.0,
|
||||
"purpose": f"等待容器 {vessel} 自然达到 {temp}°C"
|
||||
}
|
||||
})
|
||||
else:
|
||||
if continue_heatchill:
|
||||
# 持续模式:使用 heat_chill_start 基础动作
|
||||
print(f"HEATCHILL_TO_TEMP: 使用持续温控模式")
|
||||
action_sequence.append({
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_start", # ← 直接使用设备基础动作
|
||||
"action_kwargs": {
|
||||
"vessel": vessel,
|
||||
"temp": temp,
|
||||
"purpose": f"{purpose} (持续保温)"
|
||||
}
|
||||
})
|
||||
else:
|
||||
# 一次性模式:使用 heat_chill 基础动作
|
||||
print(f"HEATCHILL_TO_TEMP: 使用一次性温控模式")
|
||||
estimated_time = max(60.0, min(900.0, abs(temp - 25.0) * 30.0))
|
||||
print(f"HEATCHILL_TO_TEMP: 估算所需时间: {estimated_time}秒")
|
||||
|
||||
action_sequence.append({
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill", # ← 直接使用设备基础动作
|
||||
"action_kwargs": {
|
||||
"vessel": vessel,
|
||||
"temp": temp,
|
||||
"time": estimated_time,
|
||||
"stir": stir,
|
||||
"stir_speed": stir_speed,
|
||||
"status": "start"
|
||||
}
|
||||
})
|
||||
|
||||
print(f"HEATCHILL_TO_TEMP: 生成了 {len(action_sequence)} 个动作")
|
||||
debug_print(f"✅ 启动加热协议生成完成 🎯")
|
||||
return action_sequence
|
||||
|
||||
|
||||
# 扩展版本的加热/冷却协议,集成智能温控功能
|
||||
def generate_smart_heat_chill_protocol(
|
||||
def generate_heat_chill_stop_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
temp: float,
|
||||
time: float = 0.0, # 0表示自动估算
|
||||
active: bool = True,
|
||||
continue_heatchill: bool = False,
|
||||
stir: bool = False,
|
||||
stir_speed: float = 300.0,
|
||||
purpose: str = "智能加热/冷却"
|
||||
vessel: dict, # 🔧 修改参数类型
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
这个函数集成了 generate_heat_chill_to_temp_protocol 的智能逻辑,
|
||||
但使用现有的 Action 类型
|
||||
"""
|
||||
# 如果时间为0,自动估算
|
||||
if time == 0.0:
|
||||
estimated_time = max(60.0, min(900.0, abs(temp - 25.0) * 30.0))
|
||||
time = estimated_time
|
||||
"""生成停止加热操作的协议序列"""
|
||||
|
||||
if continue_heatchill:
|
||||
# 使用持续模式
|
||||
return generate_heat_chill_start_protocol(G, vessel, temp, purpose)
|
||||
else:
|
||||
# 使用定时模式
|
||||
return generate_heat_chill_protocol(G, vessel, temp, time, stir, stir_speed, purpose)
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
debug_print("🛑 开始生成停止加热协议 ✨")
|
||||
debug_print(f"🥽 vessel: {vessel} (ID: {vessel_id})")
|
||||
|
||||
# 基础验证
|
||||
if not vessel_id or vessel_id not in G.nodes(): # 🔧 使用 vessel_id
|
||||
debug_print("❌ 容器验证失败!")
|
||||
raise ValueError("vessel 参数无效")
|
||||
|
||||
# 查找设备
|
||||
heatchill_id = find_connected_heatchill(G, vessel_id) # 🔧 使用 vessel_id
|
||||
|
||||
# 生成动作
|
||||
action_sequence = [{
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_stop",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id # 🔧 使用 vessel_id
|
||||
}
|
||||
}]
|
||||
|
||||
debug_print(f"✅ 停止加热协议生成完成 🎯")
|
||||
return action_sequence
|
||||
|
||||
|
||||
# 便捷函数
|
||||
def generate_heating_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
temp: float,
|
||||
time: float = 300.0,
|
||||
stir: bool = True,
|
||||
stir_speed: float = 300.0
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""生成加热协议的便捷函数"""
|
||||
return generate_heat_chill_protocol(
|
||||
G=G, vessel=vessel, temp=temp, time=time,
|
||||
stir=stir, stir_speed=stir_speed, purpose=f"加热到 {temp}°C"
|
||||
)
|
||||
|
||||
|
||||
def generate_cooling_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
temp: float,
|
||||
time: float = 600.0,
|
||||
stir: bool = True,
|
||||
stir_speed: float = 200.0
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""生成冷却协议的便捷函数"""
|
||||
return generate_heat_chill_protocol(
|
||||
G=G, vessel=vessel, temp=temp, time=time,
|
||||
stir=stir, stir_speed=stir_speed, purpose=f"冷却到 {temp}°C"
|
||||
)
|
||||
|
||||
|
||||
# # 温度预设快捷函数
|
||||
# def generate_room_temp_protocol(
|
||||
# G: nx.DiGraph,
|
||||
# vessel: str,
|
||||
# stir: bool = False
|
||||
# ) -> List[Dict[str, Any]]:
|
||||
# """返回室温的快捷函数"""
|
||||
# return generate_heat_chill_to_temp_protocol(
|
||||
# G=G,
|
||||
# vessel=vessel,
|
||||
# temp=25.0,
|
||||
# active=True,
|
||||
# continue_heatchill=False,
|
||||
# stir=stir,
|
||||
# purpose="冷却到室温"
|
||||
# )
|
||||
|
||||
|
||||
# def generate_reflux_heating_protocol(
|
||||
# G: nx.DiGraph,
|
||||
# vessel: str,
|
||||
# temp: float,
|
||||
# time: float = 3600.0 # 1小时回流
|
||||
# ) -> List[Dict[str, Any]]:
|
||||
# """回流加热的快捷函数"""
|
||||
# return generate_heat_chill_protocol(
|
||||
# G=G,
|
||||
# vessel=vessel,
|
||||
# temp=temp,
|
||||
# time=time,
|
||||
# stir=True,
|
||||
# stir_speed=400.0, # 回流时较快搅拌
|
||||
# purpose=f"回流加热到 {temp}°C"
|
||||
# )
|
||||
|
||||
|
||||
# def generate_ice_bath_protocol(
|
||||
# G: nx.DiGraph,
|
||||
# vessel: str,
|
||||
# time: float = 600.0 # 10分钟冰浴
|
||||
# ) -> List[Dict[str, Any]]:
|
||||
# """冰浴冷却的快捷函数"""
|
||||
# return generate_heat_chill_protocol(
|
||||
# G=G,
|
||||
# vessel=vessel,
|
||||
# temp=0.0,
|
||||
# time=time,
|
||||
# stir=True,
|
||||
# stir_speed=150.0, # 冰浴时缓慢搅拌
|
||||
# purpose="冰浴冷却到 0°C"
|
||||
# )
|
||||
|
||||
|
||||
# 测试函数
|
||||
def test_heatchill_protocol():
|
||||
"""测试加热/冷却协议的示例"""
|
||||
print("=== HEAT CHILL PROTOCOL 测试 ===")
|
||||
print("完整的四个协议函数:")
|
||||
print("1. generate_heat_chill_protocol - 带时间限制的完整操作")
|
||||
print("2. generate_heat_chill_start_protocol - 持续加热/冷却")
|
||||
print("3. generate_heat_chill_stop_protocol - 停止加热/冷却")
|
||||
print("4. generate_heat_chill_to_temp_protocol - 智能温控 (您的 HeatChillToTemp)")
|
||||
print("测试完成")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_heatchill_protocol()
|
||||
457
unilabos/compile/hydrogenate_protocol.py
Normal file
457
unilabos/compile/hydrogenate_protocol.py
Normal file
@@ -0,0 +1,457 @@
|
||||
import networkx as nx
|
||||
from typing import List, Dict, Any, Optional
|
||||
|
||||
|
||||
def parse_temperature(temp_str: str) -> float:
|
||||
"""
|
||||
解析温度字符串,支持多种格式
|
||||
|
||||
Args:
|
||||
temp_str: 温度字符串(如 "45 °C", "45°C", "45")
|
||||
|
||||
Returns:
|
||||
float: 温度值(摄氏度)
|
||||
"""
|
||||
try:
|
||||
# 移除常见的温度单位和符号
|
||||
temp_clean = temp_str.replace("°C", "").replace("°", "").replace("C", "").strip()
|
||||
return float(temp_clean)
|
||||
except ValueError:
|
||||
print(f"HYDROGENATE: 无法解析温度 '{temp_str}',使用默认温度 25°C")
|
||||
return 25.0
|
||||
|
||||
|
||||
def parse_time(time_str: str) -> float:
|
||||
"""
|
||||
解析时间字符串,支持多种格式
|
||||
|
||||
Args:
|
||||
time_str: 时间字符串(如 "2 h", "120 min", "7200 s")
|
||||
|
||||
Returns:
|
||||
float: 时间值(秒)
|
||||
"""
|
||||
try:
|
||||
time_clean = time_str.lower().strip()
|
||||
|
||||
# 处理小时
|
||||
if "h" in time_clean:
|
||||
hours = float(time_clean.replace("h", "").strip())
|
||||
return hours * 3600.0
|
||||
|
||||
# 处理分钟
|
||||
if "min" in time_clean:
|
||||
minutes = float(time_clean.replace("min", "").strip())
|
||||
return minutes * 60.0
|
||||
|
||||
# 处理秒
|
||||
if "s" in time_clean:
|
||||
seconds = float(time_clean.replace("s", "").strip())
|
||||
return seconds
|
||||
|
||||
# 默认按小时处理
|
||||
return float(time_clean) * 3600.0
|
||||
|
||||
except ValueError:
|
||||
print(f"HYDROGENATE: 无法解析时间 '{time_str}',使用默认时间 2小时")
|
||||
return 7200.0 # 2小时
|
||||
|
||||
|
||||
def find_associated_solenoid_valve(G: nx.DiGraph, device_id: str) -> Optional[str]:
|
||||
"""查找与指定设备相关联的电磁阀"""
|
||||
solenoid_valves = [
|
||||
node for node in G.nodes()
|
||||
if ('solenoid' in (G.nodes[node].get('class') or '').lower()
|
||||
or 'solenoid_valve' in node)
|
||||
]
|
||||
|
||||
# 通过网络连接查找直接相连的电磁阀
|
||||
for solenoid in solenoid_valves:
|
||||
if G.has_edge(device_id, solenoid) or G.has_edge(solenoid, device_id):
|
||||
return solenoid
|
||||
|
||||
# 通过命名规则查找关联的电磁阀
|
||||
device_type = ""
|
||||
if 'gas' in device_id.lower():
|
||||
device_type = "gas"
|
||||
elif 'h2' in device_id.lower() or 'hydrogen' in device_id.lower():
|
||||
device_type = "gas"
|
||||
|
||||
if device_type:
|
||||
for solenoid in solenoid_valves:
|
||||
if device_type in solenoid.lower():
|
||||
return solenoid
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def find_connected_device(G: nx.DiGraph, vessel: str, device_type: str) -> str:
|
||||
"""
|
||||
查找与容器相连的指定类型设备
|
||||
|
||||
Args:
|
||||
G: 网络图
|
||||
vessel: 容器名称
|
||||
device_type: 设备类型 ('heater', 'stirrer', 'gas_source')
|
||||
|
||||
Returns:
|
||||
str: 设备ID,如果没有则返回None
|
||||
"""
|
||||
print(f"HYDROGENATE: 正在查找与容器 '{vessel}' 相连的 {device_type}...")
|
||||
|
||||
# 根据设备类型定义搜索关键词
|
||||
if device_type == 'heater':
|
||||
keywords = ['heater', 'heat', 'heatchill']
|
||||
device_class = 'virtual_heatchill'
|
||||
elif device_type == 'stirrer':
|
||||
keywords = ['stirrer', 'stir']
|
||||
device_class = 'virtual_stirrer'
|
||||
elif device_type == 'gas_source':
|
||||
keywords = ['gas', 'h2', 'hydrogen']
|
||||
device_class = 'virtual_gas_source'
|
||||
else:
|
||||
return None
|
||||
|
||||
# 查找设备节点
|
||||
device_nodes = []
|
||||
for node in G.nodes():
|
||||
node_data = G.nodes[node]
|
||||
node_name = node.lower()
|
||||
node_class = node_data.get('class', '').lower()
|
||||
|
||||
# 通过名称匹配
|
||||
if any(keyword in node_name for keyword in keywords):
|
||||
device_nodes.append(node)
|
||||
# 通过类型匹配
|
||||
elif device_class in node_class:
|
||||
device_nodes.append(node)
|
||||
|
||||
print(f"HYDROGENATE: 找到的{device_type}节点: {device_nodes}")
|
||||
|
||||
# 检查是否有设备与目标容器相连
|
||||
for device in device_nodes:
|
||||
if G.has_edge(device, vessel) or G.has_edge(vessel, device):
|
||||
print(f"HYDROGENATE: 找到与容器 '{vessel}' 相连的{device_type}: {device}")
|
||||
return device
|
||||
|
||||
# 如果没有直接连接,查找距离最近的设备
|
||||
for device in device_nodes:
|
||||
try:
|
||||
path = nx.shortest_path(G, source=device, target=vessel)
|
||||
if len(path) <= 3: # 最多2个中间节点
|
||||
print(f"HYDROGENATE: 找到距离较近的{device_type}: {device}")
|
||||
return device
|
||||
except nx.NetworkXNoPath:
|
||||
continue
|
||||
|
||||
print(f"HYDROGENATE: 未找到与容器 '{vessel}' 相连的{device_type}")
|
||||
return None
|
||||
|
||||
|
||||
def generate_hydrogenate_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
temp: str,
|
||||
time: str,
|
||||
**kwargs # 接收其他可能的参数但不使用
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成氢化反应协议序列 - 支持vessel字典
|
||||
|
||||
Args:
|
||||
G: 有向图,节点为容器和设备
|
||||
vessel: 反应容器字典(从XDL传入)
|
||||
temp: 反应温度(如 "45 °C")
|
||||
time: 反应时间(如 "2 h")
|
||||
**kwargs: 其他可选参数,但不使用
|
||||
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 动作序列
|
||||
"""
|
||||
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
action_sequence = []
|
||||
|
||||
# 解析参数
|
||||
temperature = parse_temperature(temp)
|
||||
reaction_time = parse_time(time)
|
||||
|
||||
print("🧪" * 20)
|
||||
print(f"HYDROGENATE: 开始生成氢化反应协议(支持vessel字典)✨")
|
||||
print(f"📝 输入参数:")
|
||||
print(f" 🥽 vessel: {vessel} (ID: {vessel_id})")
|
||||
print(f" 🌡️ 反应温度: {temperature}°C")
|
||||
print(f" ⏰ 反应时间: {reaction_time/3600:.1f} 小时")
|
||||
print("🧪" * 20)
|
||||
|
||||
# 🔧 新增:记录氢化前的容器状态(可选,氢化反应通常不改变体积)
|
||||
original_liquid_volume = 0.0
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list) and len(current_volume) > 0:
|
||||
original_liquid_volume = current_volume[0]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
original_liquid_volume = current_volume
|
||||
print(f"📊 氢化前液体体积: {original_liquid_volume:.2f}mL")
|
||||
|
||||
# 1. 验证目标容器存在
|
||||
print("📍 步骤1: 验证目标容器...")
|
||||
if vessel_id not in G.nodes(): # 🔧 使用 vessel_id
|
||||
print(f"⚠️ HYDROGENATE: 警告 - 容器 '{vessel_id}' 不存在于系统中,跳过氢化反应")
|
||||
return action_sequence
|
||||
print(f"✅ 容器 '{vessel_id}' 验证通过")
|
||||
|
||||
# 2. 查找相连的设备
|
||||
print("📍 步骤2: 查找相连设备...")
|
||||
heater_id = find_connected_device(G, vessel_id, 'heater') # 🔧 使用 vessel_id
|
||||
stirrer_id = find_connected_device(G, vessel_id, 'stirrer') # 🔧 使用 vessel_id
|
||||
gas_source_id = find_connected_device(G, vessel_id, 'gas_source') # 🔧 使用 vessel_id
|
||||
|
||||
print(f"🔧 设备配置:")
|
||||
print(f" 🔥 加热器: {heater_id or '未找到'}")
|
||||
print(f" 🌪️ 搅拌器: {stirrer_id or '未找到'}")
|
||||
print(f" 💨 气源: {gas_source_id or '未找到'}")
|
||||
|
||||
# 3. 启动搅拌器
|
||||
print("📍 步骤3: 启动搅拌器...")
|
||||
if stirrer_id:
|
||||
print(f"🌪️ 启动搅拌器 {stirrer_id}")
|
||||
action_sequence.append({
|
||||
"device_id": stirrer_id,
|
||||
"action_name": "start_stir",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"stir_speed": 300.0,
|
||||
"purpose": "氢化反应: 开始搅拌"
|
||||
}
|
||||
})
|
||||
print("✅ 搅拌器启动动作已添加")
|
||||
else:
|
||||
print(f"⚠️ HYDROGENATE: 警告 - 未找到搅拌器,继续执行")
|
||||
|
||||
# 4. 启动气源(氢气)
|
||||
print("📍 步骤4: 启动氢气源...")
|
||||
if gas_source_id:
|
||||
print(f"💨 启动气源 {gas_source_id} (氢气)")
|
||||
action_sequence.append({
|
||||
"device_id": gas_source_id,
|
||||
"action_name": "set_status",
|
||||
"action_kwargs": {
|
||||
"string": "ON"
|
||||
}
|
||||
})
|
||||
|
||||
# 查找相关的电磁阀
|
||||
gas_solenoid = find_associated_solenoid_valve(G, gas_source_id)
|
||||
if gas_solenoid:
|
||||
print(f"🚪 开启气源电磁阀 {gas_solenoid}")
|
||||
action_sequence.append({
|
||||
"device_id": gas_solenoid,
|
||||
"action_name": "set_valve_position",
|
||||
"action_kwargs": {
|
||||
"command": "OPEN"
|
||||
}
|
||||
})
|
||||
print("✅ 氢气源启动动作已添加")
|
||||
else:
|
||||
print(f"⚠️ HYDROGENATE: 警告 - 未找到气源,继续执行")
|
||||
|
||||
# 5. 等待气体稳定
|
||||
print("📍 步骤5: 等待气体环境稳定...")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 30.0,
|
||||
"description": "等待氢气环境稳定"
|
||||
}
|
||||
})
|
||||
print("✅ 气体稳定等待动作已添加")
|
||||
|
||||
# 6. 启动加热器
|
||||
print("📍 步骤6: 启动加热反应...")
|
||||
if heater_id:
|
||||
print(f"🔥 启动加热器 {heater_id} 到 {temperature}°C")
|
||||
action_sequence.append({
|
||||
"device_id": heater_id,
|
||||
"action_name": "heat_chill_start",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"temp": temperature,
|
||||
"purpose": f"氢化反应: 加热到 {temperature}°C"
|
||||
}
|
||||
})
|
||||
|
||||
# 等待温度稳定
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 20.0,
|
||||
"description": f"等待温度稳定到 {temperature}°C"
|
||||
}
|
||||
})
|
||||
|
||||
# 🕐 模拟运行时间优化
|
||||
print(" ⏰ 检查模拟运行时间限制...")
|
||||
original_reaction_time = reaction_time
|
||||
simulation_time_limit = 60.0 # 模拟运行时间限制:60秒
|
||||
|
||||
if reaction_time > simulation_time_limit:
|
||||
reaction_time = simulation_time_limit
|
||||
print(f" 🎮 模拟运行优化: {original_reaction_time}s → {reaction_time}s (限制为{simulation_time_limit}s)")
|
||||
print(f" 📊 时间缩短: {original_reaction_time/3600:.2f}小时 → {reaction_time/60:.1f}分钟")
|
||||
else:
|
||||
print(f" ✅ 时间在限制内: {reaction_time}s ({reaction_time/60:.1f}分钟) 保持不变")
|
||||
|
||||
# 保持反应温度
|
||||
action_sequence.append({
|
||||
"device_id": heater_id,
|
||||
"action_name": "heat_chill",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"temp": temperature,
|
||||
"time": reaction_time,
|
||||
"purpose": f"氢化反应: 保持 {temperature}°C,反应 {reaction_time/60:.1f}分钟" + (f" (模拟时间)" if original_reaction_time != reaction_time else "")
|
||||
}
|
||||
})
|
||||
|
||||
# 显示时间调整信息
|
||||
if original_reaction_time != reaction_time:
|
||||
print(f" 🎭 模拟优化说明: 原计划 {original_reaction_time/3600:.2f}小时,实际模拟 {reaction_time/60:.1f}分钟")
|
||||
|
||||
print("✅ 加热反应动作已添加")
|
||||
|
||||
else:
|
||||
print(f"⚠️ HYDROGENATE: 警告 - 未找到加热器,使用室温反应")
|
||||
|
||||
# 🕐 室温反应也需要时间优化
|
||||
print(" ⏰ 检查室温反应模拟时间限制...")
|
||||
original_reaction_time = reaction_time
|
||||
simulation_time_limit = 60.0 # 模拟运行时间限制:60秒
|
||||
|
||||
if reaction_time > simulation_time_limit:
|
||||
reaction_time = simulation_time_limit
|
||||
print(f" 🎮 室温反应时间优化: {original_reaction_time}s → {reaction_time}s")
|
||||
print(f" 📊 时间缩短: {original_reaction_time/3600:.2f}小时 → {reaction_time/60:.1f}分钟")
|
||||
else:
|
||||
print(f" ✅ 室温反应时间在限制内: {reaction_time}s 保持不变")
|
||||
|
||||
# 室温反应,只等待时间
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": reaction_time,
|
||||
"description": f"室温氢化反应 {reaction_time/60:.1f}分钟" + (f" (模拟时间)" if original_reaction_time != reaction_time else "")
|
||||
}
|
||||
})
|
||||
|
||||
# 显示时间调整信息
|
||||
if original_reaction_time != reaction_time:
|
||||
print(f" 🎭 室温反应优化说明: 原计划 {original_reaction_time/3600:.2f}小时,实际模拟 {reaction_time/60:.1f}分钟")
|
||||
|
||||
print("✅ 室温反应等待动作已添加")
|
||||
|
||||
# 7. 停止加热
|
||||
print("📍 步骤7: 停止加热...")
|
||||
if heater_id:
|
||||
action_sequence.append({
|
||||
"device_id": heater_id,
|
||||
"action_name": "heat_chill_stop",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"purpose": "氢化反应完成,停止加热"
|
||||
}
|
||||
})
|
||||
print("✅ 停止加热动作已添加")
|
||||
|
||||
# 8. 等待冷却
|
||||
print("📍 步骤8: 等待冷却...")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 300.0,
|
||||
"description": "等待反应混合物冷却"
|
||||
}
|
||||
})
|
||||
print("✅ 冷却等待动作已添加")
|
||||
|
||||
# 9. 停止气源
|
||||
print("📍 步骤9: 停止氢气源...")
|
||||
if gas_source_id:
|
||||
# 先关闭电磁阀
|
||||
gas_solenoid = find_associated_solenoid_valve(G, gas_source_id)
|
||||
if gas_solenoid:
|
||||
print(f"🚪 关闭气源电磁阀 {gas_solenoid}")
|
||||
action_sequence.append({
|
||||
"device_id": gas_solenoid,
|
||||
"action_name": "set_valve_position",
|
||||
"action_kwargs": {
|
||||
"command": "CLOSED"
|
||||
}
|
||||
})
|
||||
|
||||
# 再关闭气源
|
||||
action_sequence.append({
|
||||
"device_id": gas_source_id,
|
||||
"action_name": "set_status",
|
||||
"action_kwargs": {
|
||||
"string": "OFF"
|
||||
}
|
||||
})
|
||||
print("✅ 氢气源停止动作已添加")
|
||||
|
||||
# 10. 停止搅拌
|
||||
print("📍 步骤10: 停止搅拌...")
|
||||
if stirrer_id:
|
||||
action_sequence.append({
|
||||
"device_id": stirrer_id,
|
||||
"action_name": "stop_stir",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"purpose": "氢化反应完成,停止搅拌"
|
||||
}
|
||||
})
|
||||
print("✅ 停止搅拌动作已添加")
|
||||
|
||||
# 🔧 新增:氢化完成后的状态(氢化反应通常不改变体积)
|
||||
final_liquid_volume = original_liquid_volume # 氢化反应体积基本不变
|
||||
|
||||
# 总结
|
||||
print("🎊" * 20)
|
||||
print(f"🎉 氢化反应协议生成完成! ✨")
|
||||
print(f"📊 总动作数: {len(action_sequence)} 个")
|
||||
print(f"🥽 反应容器: {vessel_id}")
|
||||
print(f"🌡️ 反应温度: {temperature}°C")
|
||||
print(f"⏰ 反应时间: {reaction_time/60:.1f}分钟")
|
||||
print(f"⏱️ 预计总时间: {(reaction_time + 450)/3600:.1f} 小时")
|
||||
print(f"📊 体积状态:")
|
||||
print(f" - 反应前体积: {original_liquid_volume:.2f}mL")
|
||||
print(f" - 反应后体积: {final_liquid_volume:.2f}mL (氢化反应体积基本不变)")
|
||||
print("🎊" * 20)
|
||||
|
||||
return action_sequence
|
||||
|
||||
|
||||
# 测试函数
|
||||
def test_hydrogenate_protocol():
|
||||
"""测试氢化反应协议"""
|
||||
print("🧪 === HYDROGENATE PROTOCOL 测试 === ✨")
|
||||
|
||||
# 测试温度解析
|
||||
test_temps = ["45 °C", "45°C", "45", "25 C", "invalid"]
|
||||
for temp in test_temps:
|
||||
parsed = parse_temperature(temp)
|
||||
print(f"温度 '{temp}' -> {parsed}°C")
|
||||
|
||||
# 测试时间解析
|
||||
test_times = ["2 h", "120 min", "7200 s", "2", "invalid"]
|
||||
for time in test_times:
|
||||
parsed = parse_time(time)
|
||||
print(f"时间 '{time}' -> {parsed/3600:.1f} 小时")
|
||||
|
||||
print("✅ 测试完成 🎉")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_hydrogenate_protocol()
|
||||
File diff suppressed because it is too large
Load Diff
589
unilabos/compile/recrystallize_protocol.py
Normal file
589
unilabos/compile/recrystallize_protocol.py
Normal file
@@ -0,0 +1,589 @@
|
||||
import networkx as nx
|
||||
import re
|
||||
import logging
|
||||
from typing import List, Dict, Any, Tuple, Union
|
||||
from .pump_protocol import generate_pump_protocol_with_rinsing
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def debug_print(message):
|
||||
"""调试输出"""
|
||||
print(f"💎 [RECRYSTALLIZE] {message}", flush=True)
|
||||
logger.info(f"[RECRYSTALLIZE] {message}")
|
||||
|
||||
|
||||
def parse_volume_with_units(volume_input: Union[str, float, int], default_unit: str = "mL") -> float:
|
||||
"""
|
||||
解析带单位的体积输入
|
||||
|
||||
Args:
|
||||
volume_input: 体积输入(如 "100 mL", "2.5 L", "500", "?", 100.0)
|
||||
default_unit: 默认单位(默认为毫升)
|
||||
|
||||
Returns:
|
||||
float: 体积(毫升)
|
||||
"""
|
||||
if not volume_input:
|
||||
debug_print("⚠️ 体积输入为空,返回 0.0mL 📦")
|
||||
return 0.0
|
||||
|
||||
# 处理数值输入
|
||||
if isinstance(volume_input, (int, float)):
|
||||
result = float(volume_input)
|
||||
debug_print(f"🔢 数值体积输入: {volume_input} → {result}mL(默认单位)💧")
|
||||
return result
|
||||
|
||||
# 处理字符串输入
|
||||
volume_str = str(volume_input).lower().strip()
|
||||
debug_print(f"🔍 解析体积字符串: '{volume_str}' 📝")
|
||||
|
||||
# 处理特殊值
|
||||
if volume_str in ['?', 'unknown', 'tbd', 'to be determined']:
|
||||
default_volume = 50.0 # 50mL默认值
|
||||
debug_print(f"❓ 检测到未知体积,使用默认值: {default_volume}mL 🎯")
|
||||
return default_volume
|
||||
|
||||
# 如果是纯数字,使用默认单位
|
||||
try:
|
||||
value = float(volume_str)
|
||||
if default_unit.lower() in ["ml", "milliliter"]:
|
||||
result = value
|
||||
elif default_unit.lower() in ["l", "liter"]:
|
||||
result = value * 1000.0
|
||||
elif default_unit.lower() in ["μl", "ul", "microliter"]:
|
||||
result = value / 1000.0
|
||||
else:
|
||||
result = value # 默认mL
|
||||
debug_print(f"🔢 纯数字输入: {volume_str} → {result}mL(单位: {default_unit})📏")
|
||||
return result
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 移除空格并提取数字和单位
|
||||
volume_clean = re.sub(r'\s+', '', volume_str)
|
||||
|
||||
# 匹配数字和单位的正则表达式
|
||||
match = re.match(r'([0-9]*\.?[0-9]+)\s*(ml|l|μl|ul|microliter|milliliter|liter)?', volume_clean)
|
||||
|
||||
if not match:
|
||||
debug_print(f"⚠️ 无法解析体积: '{volume_str}',使用默认值: 50mL 🎯")
|
||||
return 50.0
|
||||
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2) or default_unit.lower()
|
||||
|
||||
# 转换为毫升
|
||||
if unit in ['l', 'liter']:
|
||||
volume = value * 1000.0 # L -> mL
|
||||
debug_print(f"📏 升转毫升: {value}L → {volume}mL 💧")
|
||||
elif unit in ['μl', 'ul', 'microliter']:
|
||||
volume = value / 1000.0 # μL -> mL
|
||||
debug_print(f"📏 微升转毫升: {value}μL → {volume}mL 💧")
|
||||
else: # ml, milliliter 或默认
|
||||
volume = value # 已经是mL
|
||||
debug_print(f"📏 毫升单位: {value}mL → {volume}mL 💧")
|
||||
|
||||
debug_print(f"✅ 体积解析完成: '{volume_str}' → {volume}mL ✨")
|
||||
return volume
|
||||
|
||||
|
||||
def parse_ratio(ratio_str: str) -> Tuple[float, float]:
|
||||
"""
|
||||
解析比例字符串,支持多种格式
|
||||
|
||||
Args:
|
||||
ratio_str: 比例字符串(如 "1:1", "3:7", "50:50")
|
||||
|
||||
Returns:
|
||||
Tuple[float, float]: 比例元组 (ratio1, ratio2)
|
||||
"""
|
||||
debug_print(f"⚖️ 开始解析比例: '{ratio_str}' 📊")
|
||||
|
||||
try:
|
||||
# 处理 "1:1", "3:7", "50:50" 等格式
|
||||
if ":" in ratio_str:
|
||||
parts = ratio_str.split(":")
|
||||
if len(parts) == 2:
|
||||
ratio1 = float(parts[0])
|
||||
ratio2 = float(parts[1])
|
||||
debug_print(f"✅ 冒号格式解析成功: {ratio1}:{ratio2} 🎯")
|
||||
return ratio1, ratio2
|
||||
|
||||
# 处理 "1-1", "3-7" 等格式
|
||||
if "-" in ratio_str:
|
||||
parts = ratio_str.split("-")
|
||||
if len(parts) == 2:
|
||||
ratio1 = float(parts[0])
|
||||
ratio2 = float(parts[1])
|
||||
debug_print(f"✅ 横线格式解析成功: {ratio1}:{ratio2} 🎯")
|
||||
return ratio1, ratio2
|
||||
|
||||
# 处理 "1,1", "3,7" 等格式
|
||||
if "," in ratio_str:
|
||||
parts = ratio_str.split(",")
|
||||
if len(parts) == 2:
|
||||
ratio1 = float(parts[0])
|
||||
ratio2 = float(parts[1])
|
||||
debug_print(f"✅ 逗号格式解析成功: {ratio1}:{ratio2} 🎯")
|
||||
return ratio1, ratio2
|
||||
|
||||
# 默认 1:1
|
||||
debug_print(f"⚠️ 无法解析比例 '{ratio_str}',使用默认比例 1:1 🎭")
|
||||
return 1.0, 1.0
|
||||
|
||||
except ValueError:
|
||||
debug_print(f"❌ 比例解析错误 '{ratio_str}',使用默认比例 1:1 🎭")
|
||||
return 1.0, 1.0
|
||||
|
||||
|
||||
def find_solvent_vessel(G: nx.DiGraph, solvent: str) -> str:
|
||||
"""
|
||||
查找溶剂容器
|
||||
|
||||
Args:
|
||||
G: 网络图
|
||||
solvent: 溶剂名称
|
||||
|
||||
Returns:
|
||||
str: 溶剂容器ID
|
||||
"""
|
||||
debug_print(f"🔍 正在查找溶剂 '{solvent}' 的容器... 🧪")
|
||||
|
||||
# 构建可能的容器名称
|
||||
possible_names = [
|
||||
f"flask_{solvent}",
|
||||
f"bottle_{solvent}",
|
||||
f"reagent_{solvent}",
|
||||
f"reagent_bottle_{solvent}",
|
||||
f"{solvent}_flask",
|
||||
f"{solvent}_bottle",
|
||||
f"{solvent}",
|
||||
f"vessel_{solvent}",
|
||||
]
|
||||
|
||||
debug_print(f"📋 候选容器名称: {possible_names[:3]}... (共{len(possible_names)}个) 📝")
|
||||
|
||||
# 第一步:通过容器名称匹配
|
||||
debug_print(" 🎯 步骤1: 精确名称匹配...")
|
||||
for vessel_name in possible_names:
|
||||
if vessel_name in G.nodes():
|
||||
debug_print(f" 🎉 通过名称匹配找到容器: {vessel_name} ✨")
|
||||
return vessel_name
|
||||
|
||||
# 第二步:通过模糊匹配(节点ID和名称)
|
||||
debug_print(" 🔍 步骤2: 模糊名称匹配...")
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
node_name = G.nodes[node_id].get('name', '').lower()
|
||||
|
||||
if solvent.lower() in node_id.lower() or solvent.lower() in node_name:
|
||||
debug_print(f" 🎉 通过模糊匹配找到容器: {node_id} (名称: {node_name}) ✨")
|
||||
return node_id
|
||||
|
||||
# 第三步:通过配置中的试剂信息匹配
|
||||
debug_print(" 🧪 步骤3: 配置试剂信息匹配...")
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
# 检查 config 中的 reagent 字段
|
||||
node_config = G.nodes[node_id].get('config', {})
|
||||
config_reagent = node_config.get('reagent', '').lower()
|
||||
|
||||
if config_reagent and solvent.lower() == config_reagent:
|
||||
debug_print(f" 🎉 通过config.reagent匹配找到容器: {node_id} (试剂: {config_reagent}) ✨")
|
||||
return node_id
|
||||
|
||||
# 第四步:通过数据中的试剂信息匹配
|
||||
debug_print(" 🧪 步骤4: 数据试剂信息匹配...")
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
vessel_data = G.nodes[node_id].get('data', {})
|
||||
|
||||
# 检查 data 中的 reagent_name 字段
|
||||
reagent_name = vessel_data.get('reagent_name', '').lower()
|
||||
if reagent_name and solvent.lower() == reagent_name:
|
||||
debug_print(f" 🎉 通过data.reagent_name匹配找到容器: {node_id} (试剂: {reagent_name}) ✨")
|
||||
return node_id
|
||||
|
||||
# 检查 data 中的液体信息
|
||||
liquids = vessel_data.get('liquid', [])
|
||||
for liquid in liquids:
|
||||
if isinstance(liquid, dict):
|
||||
liquid_type = (liquid.get('liquid_type') or liquid.get('name', '')).lower()
|
||||
|
||||
if solvent.lower() in liquid_type:
|
||||
debug_print(f" 🎉 通过液体类型匹配找到容器: {node_id} (液体类型: {liquid_type}) ✨")
|
||||
return node_id
|
||||
|
||||
# 第五步:部分匹配(如果前面都没找到)
|
||||
debug_print(" 🔍 步骤5: 部分匹配...")
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
node_config = G.nodes[node_id].get('config', {})
|
||||
node_data = G.nodes[node_id].get('data', {})
|
||||
node_name = G.nodes[node_id].get('name', '').lower()
|
||||
|
||||
config_reagent = node_config.get('reagent', '').lower()
|
||||
data_reagent = node_data.get('reagent_name', '').lower()
|
||||
|
||||
# 检查是否包含溶剂名称
|
||||
if (solvent.lower() in config_reagent or
|
||||
solvent.lower() in data_reagent or
|
||||
solvent.lower() in node_name or
|
||||
solvent.lower() in node_id.lower()):
|
||||
debug_print(f" 🎉 通过部分匹配找到容器: {node_id} ✨")
|
||||
debug_print(f" - 节点名称: {node_name}")
|
||||
debug_print(f" - 配置试剂: {config_reagent}")
|
||||
debug_print(f" - 数据试剂: {data_reagent}")
|
||||
return node_id
|
||||
|
||||
# 调试信息:列出所有容器
|
||||
debug_print(" 🔎 调试信息:列出所有容器...")
|
||||
container_list = []
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
node_config = G.nodes[node_id].get('config', {})
|
||||
node_data = G.nodes[node_id].get('data', {})
|
||||
node_name = G.nodes[node_id].get('name', '')
|
||||
|
||||
container_info = {
|
||||
'id': node_id,
|
||||
'name': node_name,
|
||||
'config_reagent': node_config.get('reagent', ''),
|
||||
'data_reagent': node_data.get('reagent_name', '')
|
||||
}
|
||||
container_list.append(container_info)
|
||||
debug_print(f" - 容器: {node_id}, 名称: {node_name}, config试剂: {node_config.get('reagent', '')}, data试剂: {node_data.get('reagent_name', '')}")
|
||||
|
||||
debug_print(f"❌ 找不到溶剂 '{solvent}' 对应的容器 😭")
|
||||
debug_print(f"🔍 查找的溶剂: '{solvent}' (小写: '{solvent.lower()}')")
|
||||
debug_print(f"📊 总共发现 {len(container_list)} 个容器")
|
||||
|
||||
raise ValueError(f"找不到溶剂 '{solvent}' 对应的容器")
|
||||
|
||||
|
||||
def generate_recrystallize_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: dict, # 🔧 修改:从字符串改为字典类型
|
||||
ratio: str,
|
||||
solvent1: str,
|
||||
solvent2: str,
|
||||
volume: Union[str, float], # 支持字符串和数值
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成重结晶协议序列 - 支持vessel字典和体积运算
|
||||
|
||||
Args:
|
||||
G: 有向图,节点为容器和设备
|
||||
vessel: 目标容器字典(从XDL传入)
|
||||
ratio: 溶剂比例(如 "1:1", "3:7")
|
||||
solvent1: 第一种溶剂名称
|
||||
solvent2: 第二种溶剂名称
|
||||
volume: 总体积(支持 "100 mL", "50", "2.5 L" 等)
|
||||
**kwargs: 其他可选参数
|
||||
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 动作序列
|
||||
"""
|
||||
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
action_sequence = []
|
||||
|
||||
debug_print("💎" * 20)
|
||||
debug_print("🚀 开始生成重结晶协议(支持vessel字典和体积运算)✨")
|
||||
debug_print(f"📝 输入参数:")
|
||||
debug_print(f" 🥽 vessel: {vessel} (ID: {vessel_id})")
|
||||
debug_print(f" ⚖️ 比例: {ratio}")
|
||||
debug_print(f" 🧪 溶剂1: {solvent1}")
|
||||
debug_print(f" 🧪 溶剂2: {solvent2}")
|
||||
debug_print(f" 💧 总体积: {volume} (类型: {type(volume)})")
|
||||
debug_print("💎" * 20)
|
||||
|
||||
# 🔧 新增:记录重结晶前的容器状态
|
||||
debug_print("🔍 记录重结晶前容器状态...")
|
||||
original_liquid_volume = 0.0
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list) and len(current_volume) > 0:
|
||||
original_liquid_volume = current_volume[0]
|
||||
elif isinstance(current_volume, (int, float)):
|
||||
original_liquid_volume = current_volume
|
||||
debug_print(f"📊 重结晶前液体体积: {original_liquid_volume:.2f}mL")
|
||||
|
||||
# 1. 验证目标容器存在
|
||||
debug_print("📍 步骤1: 验证目标容器... 🔧")
|
||||
if vessel_id not in G.nodes(): # 🔧 使用 vessel_id
|
||||
debug_print(f"❌ 目标容器 '{vessel_id}' 不存在于系统中! 😱")
|
||||
raise ValueError(f"目标容器 '{vessel_id}' 不存在于系统中")
|
||||
debug_print(f"✅ 目标容器 '{vessel_id}' 验证通过 🎯")
|
||||
|
||||
# 2. 解析体积(支持单位)
|
||||
debug_print("📍 步骤2: 解析体积(支持单位)... 💧")
|
||||
final_volume = parse_volume_with_units(volume, "mL")
|
||||
debug_print(f"🎯 体积解析完成: {volume} → {final_volume}mL ✨")
|
||||
|
||||
# 3. 解析比例
|
||||
debug_print("📍 步骤3: 解析比例... ⚖️")
|
||||
ratio1, ratio2 = parse_ratio(ratio)
|
||||
total_ratio = ratio1 + ratio2
|
||||
debug_print(f"🎯 比例解析完成: {ratio1}:{ratio2} (总比例: {total_ratio}) ✨")
|
||||
|
||||
# 4. 计算各溶剂体积
|
||||
debug_print("📍 步骤4: 计算各溶剂体积... 🧮")
|
||||
volume1 = final_volume * (ratio1 / total_ratio)
|
||||
volume2 = final_volume * (ratio2 / total_ratio)
|
||||
|
||||
debug_print(f"🧪 {solvent1} 体积: {volume1:.2f} mL ({ratio1}/{total_ratio} × {final_volume})")
|
||||
debug_print(f"🧪 {solvent2} 体积: {volume2:.2f} mL ({ratio2}/{total_ratio} × {final_volume})")
|
||||
debug_print(f"✅ 体积计算完成: 总计 {volume1 + volume2:.2f} mL 🎯")
|
||||
|
||||
# 5. 查找溶剂容器
|
||||
debug_print("📍 步骤5: 查找溶剂容器... 🔍")
|
||||
try:
|
||||
debug_print(f" 🔍 查找溶剂1容器...")
|
||||
solvent1_vessel = find_solvent_vessel(G, solvent1)
|
||||
debug_print(f" 🎉 找到溶剂1容器: {solvent1_vessel} ✨")
|
||||
except ValueError as e:
|
||||
debug_print(f" ❌ 溶剂1容器查找失败: {str(e)} 😭")
|
||||
raise ValueError(f"无法找到溶剂1 '{solvent1}': {str(e)}")
|
||||
|
||||
try:
|
||||
debug_print(f" 🔍 查找溶剂2容器...")
|
||||
solvent2_vessel = find_solvent_vessel(G, solvent2)
|
||||
debug_print(f" 🎉 找到溶剂2容器: {solvent2_vessel} ✨")
|
||||
except ValueError as e:
|
||||
debug_print(f" ❌ 溶剂2容器查找失败: {str(e)} 😭")
|
||||
raise ValueError(f"无法找到溶剂2 '{solvent2}': {str(e)}")
|
||||
|
||||
# 6. 验证路径存在
|
||||
debug_print("📍 步骤6: 验证传输路径... 🛤️")
|
||||
try:
|
||||
path1 = nx.shortest_path(G, source=solvent1_vessel, target=vessel_id) # 🔧 使用 vessel_id
|
||||
debug_print(f" 🛤️ 溶剂1路径: {' → '.join(path1)} ✅")
|
||||
except nx.NetworkXNoPath:
|
||||
debug_print(f" ❌ 溶剂1路径不可达: {solvent1_vessel} → {vessel_id} 😞")
|
||||
raise ValueError(f"从溶剂1容器 '{solvent1_vessel}' 到目标容器 '{vessel_id}' 没有可用路径")
|
||||
|
||||
try:
|
||||
path2 = nx.shortest_path(G, source=solvent2_vessel, target=vessel_id) # 🔧 使用 vessel_id
|
||||
debug_print(f" 🛤️ 溶剂2路径: {' → '.join(path2)} ✅")
|
||||
except nx.NetworkXNoPath:
|
||||
debug_print(f" ❌ 溶剂2路径不可达: {solvent2_vessel} → {vessel_id} 😞")
|
||||
raise ValueError(f"从溶剂2容器 '{solvent2_vessel}' 到目标容器 '{vessel_id}' 没有可用路径")
|
||||
|
||||
# 7. 添加第一种溶剂
|
||||
debug_print("📍 步骤7: 添加第一种溶剂... 🧪")
|
||||
debug_print(f" 🚰 开始添加溶剂1: {solvent1} ({volume1:.2f} mL)")
|
||||
|
||||
try:
|
||||
pump_actions1 = generate_pump_protocol_with_rinsing(
|
||||
G=G,
|
||||
from_vessel=solvent1_vessel,
|
||||
to_vessel=vessel_id, # 🔧 使用 vessel_id
|
||||
volume=volume1, # 使用解析后的体积
|
||||
amount="",
|
||||
time=0.0,
|
||||
viscous=False,
|
||||
rinsing_solvent="", # 重结晶不需要清洗
|
||||
rinsing_volume=0.0,
|
||||
rinsing_repeats=0,
|
||||
solid=False,
|
||||
flowrate=2.0, # 正常流速
|
||||
transfer_flowrate=0.5
|
||||
)
|
||||
|
||||
action_sequence.extend(pump_actions1)
|
||||
debug_print(f" ✅ 溶剂1泵送动作已添加: {len(pump_actions1)} 个动作 🚰✨")
|
||||
|
||||
except Exception as e:
|
||||
debug_print(f" ❌ 溶剂1泵协议生成失败: {str(e)} 😭")
|
||||
raise ValueError(f"生成溶剂1泵协议时出错: {str(e)}")
|
||||
|
||||
# 🔧 新增:更新容器体积 - 添加溶剂1后
|
||||
debug_print(" 🔧 更新容器体积 - 添加溶剂1后...")
|
||||
new_volume_after_solvent1 = original_liquid_volume + volume1
|
||||
|
||||
# 更新vessel字典中的体积
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
if len(current_volume) > 0:
|
||||
vessel["data"]["liquid_volume"][0] = new_volume_after_solvent1
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = [new_volume_after_solvent1]
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = new_volume_after_solvent1
|
||||
|
||||
# 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
if 'data' not in G.nodes[vessel_id]:
|
||||
G.nodes[vessel_id]['data'] = {}
|
||||
|
||||
vessel_node_data = G.nodes[vessel_id]['data']
|
||||
current_node_volume = vessel_node_data.get('liquid_volume', 0.0)
|
||||
|
||||
if isinstance(current_node_volume, list):
|
||||
if len(current_node_volume) > 0:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'][0] = new_volume_after_solvent1
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = [new_volume_after_solvent1]
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = new_volume_after_solvent1
|
||||
|
||||
debug_print(f" 📊 体积更新: {original_liquid_volume:.2f}mL + {volume1:.2f}mL = {new_volume_after_solvent1:.2f}mL")
|
||||
|
||||
# 8. 等待溶剂1稳定
|
||||
debug_print(" ⏳ 添加溶剂1稳定等待...")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 5.0, # 缩短等待时间
|
||||
"description": f"等待溶剂1 {solvent1} 稳定"
|
||||
}
|
||||
})
|
||||
debug_print(" ✅ 溶剂1稳定等待已添加 ⏰✨")
|
||||
|
||||
# 9. 添加第二种溶剂
|
||||
debug_print("📍 步骤8: 添加第二种溶剂... 🧪")
|
||||
debug_print(f" 🚰 开始添加溶剂2: {solvent2} ({volume2:.2f} mL)")
|
||||
|
||||
try:
|
||||
pump_actions2 = generate_pump_protocol_with_rinsing(
|
||||
G=G,
|
||||
from_vessel=solvent2_vessel,
|
||||
to_vessel=vessel_id, # 🔧 使用 vessel_id
|
||||
volume=volume2, # 使用解析后的体积
|
||||
amount="",
|
||||
time=0.0,
|
||||
viscous=False,
|
||||
rinsing_solvent="", # 重结晶不需要清洗
|
||||
rinsing_volume=0.0,
|
||||
rinsing_repeats=0,
|
||||
solid=False,
|
||||
flowrate=2.0, # 正常流速
|
||||
transfer_flowrate=0.5
|
||||
)
|
||||
|
||||
action_sequence.extend(pump_actions2)
|
||||
debug_print(f" ✅ 溶剂2泵送动作已添加: {len(pump_actions2)} 个动作 🚰✨")
|
||||
|
||||
except Exception as e:
|
||||
debug_print(f" ❌ 溶剂2泵协议生成失败: {str(e)} 😭")
|
||||
raise ValueError(f"生成溶剂2泵协议时出错: {str(e)}")
|
||||
|
||||
# 🔧 新增:更新容器体积 - 添加溶剂2后
|
||||
debug_print(" 🔧 更新容器体积 - 添加溶剂2后...")
|
||||
final_liquid_volume = new_volume_after_solvent1 + volume2
|
||||
|
||||
# 更新vessel字典中的体积
|
||||
if "data" in vessel and "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
if len(current_volume) > 0:
|
||||
vessel["data"]["liquid_volume"][0] = final_liquid_volume
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = [final_liquid_volume]
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = final_liquid_volume
|
||||
|
||||
# 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
if 'data' not in G.nodes[vessel_id]:
|
||||
G.nodes[vessel_id]['data'] = {}
|
||||
|
||||
vessel_node_data = G.nodes[vessel_id]['data']
|
||||
current_node_volume = vessel_node_data.get('liquid_volume', 0.0)
|
||||
|
||||
if isinstance(current_node_volume, list):
|
||||
if len(current_node_volume) > 0:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'][0] = final_liquid_volume
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = [final_liquid_volume]
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = final_liquid_volume
|
||||
|
||||
debug_print(f" 📊 最终体积: {new_volume_after_solvent1:.2f}mL + {volume2:.2f}mL = {final_liquid_volume:.2f}mL")
|
||||
|
||||
# 10. 等待溶剂2稳定
|
||||
debug_print(" ⏳ 添加溶剂2稳定等待...")
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 5.0, # 缩短等待时间
|
||||
"description": f"等待溶剂2 {solvent2} 稳定"
|
||||
}
|
||||
})
|
||||
debug_print(" ✅ 溶剂2稳定等待已添加 ⏰✨")
|
||||
|
||||
# 11. 等待重结晶完成
|
||||
debug_print("📍 步骤9: 等待重结晶完成... 💎")
|
||||
|
||||
# 模拟运行时间优化
|
||||
debug_print(" ⏱️ 检查模拟运行时间限制...")
|
||||
original_crystallize_time = 600.0 # 原始重结晶时间
|
||||
simulation_time_limit = 60.0 # 模拟运行时间限制:60秒
|
||||
|
||||
final_crystallize_time = min(original_crystallize_time, simulation_time_limit)
|
||||
|
||||
if original_crystallize_time > simulation_time_limit:
|
||||
debug_print(f" 🎮 模拟运行优化: {original_crystallize_time}s → {final_crystallize_time}s ⚡")
|
||||
debug_print(f" 📊 时间缩短: {original_crystallize_time/60:.1f}分钟 → {final_crystallize_time/60:.1f}分钟 🚀")
|
||||
else:
|
||||
debug_print(f" ✅ 时间在限制内: {final_crystallize_time}s 保持不变 🎯")
|
||||
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": final_crystallize_time,
|
||||
"description": f"等待重结晶完成({solvent1}:{solvent2} = {ratio},总体积 {final_volume}mL)" + (f" (模拟时间)" if original_crystallize_time != final_crystallize_time else "")
|
||||
}
|
||||
})
|
||||
debug_print(f" ✅ 重结晶等待已添加: {final_crystallize_time}s 💎✨")
|
||||
|
||||
# 显示时间调整信息
|
||||
if original_crystallize_time != final_crystallize_time:
|
||||
debug_print(f" 🎭 模拟优化说明: 原计划 {original_crystallize_time/60:.1f}分钟,实际模拟 {final_crystallize_time/60:.1f}分钟 ⚡")
|
||||
|
||||
# 总结
|
||||
debug_print("💎" * 20)
|
||||
debug_print(f"🎉 重结晶协议生成完成! ✨")
|
||||
debug_print(f"📊 总动作数: {len(action_sequence)} 个")
|
||||
debug_print(f"🥽 目标容器: {vessel_id}")
|
||||
debug_print(f"💧 总体积变化:")
|
||||
debug_print(f" - 原始体积: {original_liquid_volume:.2f}mL")
|
||||
debug_print(f" - 添加溶剂: {final_volume:.2f}mL")
|
||||
debug_print(f" - 最终体积: {final_liquid_volume:.2f}mL")
|
||||
debug_print(f"⚖️ 溶剂比例: {solvent1}:{solvent2} = {ratio1}:{ratio2}")
|
||||
debug_print(f"🧪 溶剂1: {solvent1} ({volume1:.2f}mL)")
|
||||
debug_print(f"🧪 溶剂2: {solvent2} ({volume2:.2f}mL)")
|
||||
debug_print(f"⏱️ 预计总时间: {(final_crystallize_time + 10)/60:.1f} 分钟 ⌛")
|
||||
debug_print("💎" * 20)
|
||||
|
||||
return action_sequence
|
||||
|
||||
|
||||
# 测试函数
|
||||
def test_recrystallize_protocol():
|
||||
"""测试重结晶协议"""
|
||||
debug_print("🧪 === RECRYSTALLIZE PROTOCOL 测试 === ✨")
|
||||
|
||||
# 测试体积解析
|
||||
debug_print("💧 测试体积解析...")
|
||||
test_volumes = ["100 mL", "2.5 L", "500", "50.5", "?", "invalid"]
|
||||
for vol in test_volumes:
|
||||
parsed = parse_volume_with_units(vol)
|
||||
debug_print(f" 📊 体积 '{vol}' -> {parsed}mL")
|
||||
|
||||
# 测试比例解析
|
||||
debug_print("⚖️ 测试比例解析...")
|
||||
test_ratios = ["1:1", "3:7", "50:50", "1-1", "2,8", "invalid"]
|
||||
for ratio in test_ratios:
|
||||
r1, r2 = parse_ratio(ratio)
|
||||
debug_print(f" 📊 比例 '{ratio}' -> {r1}:{r2}")
|
||||
|
||||
debug_print("✅ 测试完成 🎉")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_recrystallize_protocol()
|
||||
387
unilabos/compile/reset_handling_protocol.py
Normal file
387
unilabos/compile/reset_handling_protocol.py
Normal file
@@ -0,0 +1,387 @@
|
||||
import networkx as nx
|
||||
import logging
|
||||
import sys
|
||||
from typing import List, Dict, Any, Optional
|
||||
from .pump_protocol import generate_pump_protocol_with_rinsing
|
||||
|
||||
# 设置日志
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 确保输出编码为UTF-8
|
||||
if hasattr(sys.stdout, 'reconfigure'):
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
sys.stderr.reconfigure(encoding='utf-8')
|
||||
except:
|
||||
pass
|
||||
|
||||
def debug_print(message):
|
||||
"""调试输出函数 - 支持中文"""
|
||||
try:
|
||||
# 确保消息是字符串格式
|
||||
safe_message = str(message)
|
||||
print(f"[重置处理] {safe_message}", flush=True)
|
||||
logger.info(f"[重置处理] {safe_message}")
|
||||
except UnicodeEncodeError:
|
||||
# 如果编码失败,尝试替换不支持的字符
|
||||
safe_message = str(message).encode('utf-8', errors='replace').decode('utf-8')
|
||||
print(f"[重置处理] {safe_message}", flush=True)
|
||||
logger.info(f"[重置处理] {safe_message}")
|
||||
except Exception as e:
|
||||
# 最后的安全措施
|
||||
fallback_message = f"日志输出错误: {repr(message)}"
|
||||
print(f"[重置处理] {fallback_message}", flush=True)
|
||||
logger.info(f"[重置处理] {fallback_message}")
|
||||
|
||||
def create_action_log(message: str, emoji: str = "📝") -> Dict[str, Any]:
|
||||
"""创建一个动作日志 - 支持中文和emoji"""
|
||||
try:
|
||||
full_message = f"{emoji} {message}"
|
||||
debug_print(full_message)
|
||||
logger.info(full_message)
|
||||
|
||||
return {
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 0.1,
|
||||
"log_message": full_message,
|
||||
"progress_message": full_message
|
||||
}
|
||||
}
|
||||
except Exception as e:
|
||||
# 如果emoji有问题,使用纯文本
|
||||
safe_message = f"[日志] {message}"
|
||||
debug_print(safe_message)
|
||||
logger.info(safe_message)
|
||||
|
||||
return {
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 0.1,
|
||||
"log_message": safe_message,
|
||||
"progress_message": safe_message
|
||||
}
|
||||
}
|
||||
|
||||
def find_solvent_vessel(G: nx.DiGraph, solvent: str) -> str:
|
||||
"""
|
||||
查找溶剂容器,支持多种匹配模式
|
||||
|
||||
Args:
|
||||
G: 网络图
|
||||
solvent: 溶剂名称(如 "methanol", "ethanol", "water")
|
||||
|
||||
Returns:
|
||||
str: 溶剂容器ID
|
||||
"""
|
||||
debug_print(f"🔍 正在查找溶剂 '{solvent}' 的容器...")
|
||||
|
||||
# 构建可能的容器名称
|
||||
possible_names = [
|
||||
f"flask_{solvent}", # flask_methanol
|
||||
f"bottle_{solvent}", # bottle_methanol
|
||||
f"reagent_{solvent}", # reagent_methanol
|
||||
f"reagent_bottle_{solvent}", # reagent_bottle_methanol
|
||||
f"{solvent}_flask", # methanol_flask
|
||||
f"{solvent}_bottle", # methanol_bottle
|
||||
f"{solvent}", # methanol
|
||||
f"vessel_{solvent}", # vessel_methanol
|
||||
]
|
||||
|
||||
debug_print(f"🎯 候选容器名称: {possible_names[:3]}... (共{len(possible_names)}个)")
|
||||
|
||||
# 第一步:通过容器名称匹配
|
||||
debug_print("📋 方法1: 精确名称匹配...")
|
||||
for vessel_name in possible_names:
|
||||
if vessel_name in G.nodes():
|
||||
debug_print(f"✅ 通过名称匹配找到容器: {vessel_name}")
|
||||
return vessel_name
|
||||
debug_print("⚠️ 精确名称匹配失败,尝试模糊匹配...")
|
||||
|
||||
# 第二步:通过模糊匹配
|
||||
debug_print("📋 方法2: 模糊名称匹配...")
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
node_name = G.nodes[node_id].get('name', '').lower()
|
||||
|
||||
# 检查是否包含溶剂名称
|
||||
if solvent.lower() in node_id.lower() or solvent.lower() in node_name:
|
||||
debug_print(f"✅ 通过模糊匹配找到容器: {node_id}")
|
||||
return node_id
|
||||
debug_print("⚠️ 模糊匹配失败,尝试液体类型匹配...")
|
||||
|
||||
# 第三步:通过液体类型匹配
|
||||
debug_print("📋 方法3: 液体类型匹配...")
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
vessel_data = G.nodes[node_id].get('data', {})
|
||||
liquids = vessel_data.get('liquid', [])
|
||||
|
||||
for liquid in liquids:
|
||||
if isinstance(liquid, dict):
|
||||
liquid_type = (liquid.get('liquid_type') or liquid.get('name', '')).lower()
|
||||
reagent_name = vessel_data.get('reagent_name', '').lower()
|
||||
|
||||
if solvent.lower() in liquid_type or solvent.lower() in reagent_name:
|
||||
debug_print(f"✅ 通过液体类型匹配找到容器: {node_id}")
|
||||
return node_id
|
||||
|
||||
# 列出可用容器帮助调试
|
||||
debug_print("📊 显示可用容器信息...")
|
||||
available_containers = []
|
||||
for node_id in G.nodes():
|
||||
if G.nodes[node_id].get('type') == 'container':
|
||||
vessel_data = G.nodes[node_id].get('data', {})
|
||||
liquids = vessel_data.get('liquid', [])
|
||||
liquid_types = [liquid.get('liquid_type', '') or liquid.get('name', '')
|
||||
for liquid in liquids if isinstance(liquid, dict)]
|
||||
|
||||
available_containers.append({
|
||||
'id': node_id,
|
||||
'name': G.nodes[node_id].get('name', ''),
|
||||
'liquids': liquid_types,
|
||||
'reagent_name': vessel_data.get('reagent_name', '')
|
||||
})
|
||||
|
||||
debug_print(f"📋 可用容器列表 (共{len(available_containers)}个):")
|
||||
for i, container in enumerate(available_containers[:5]): # 只显示前5个
|
||||
debug_print(f" {i+1}. 🥽 {container['id']}: {container['name']}")
|
||||
debug_print(f" 💧 液体: {container['liquids']}")
|
||||
debug_print(f" 🧪 试剂: {container['reagent_name']}")
|
||||
|
||||
if len(available_containers) > 5:
|
||||
debug_print(f" ... 还有 {len(available_containers)-5} 个容器")
|
||||
|
||||
debug_print(f"❌ 找不到溶剂 '{solvent}' 对应的容器")
|
||||
raise ValueError(f"找不到溶剂 '{solvent}' 对应的容器。尝试了: {possible_names[:3]}...")
|
||||
|
||||
def generate_reset_handling_protocol(
|
||||
G: nx.DiGraph,
|
||||
solvent: str,
|
||||
vessel: Optional[str] = None, # 🆕 新增可选vessel参数
|
||||
**kwargs # 接收其他可能的参数但不使用
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成重置处理协议序列 - 支持自定义容器
|
||||
|
||||
Args:
|
||||
G: 有向图,节点为容器和设备
|
||||
solvent: 溶剂名称(从XDL传入)
|
||||
vessel: 目标容器名称(可选,默认为 "main_reactor")
|
||||
**kwargs: 其他可选参数,但不使用
|
||||
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 动作序列
|
||||
"""
|
||||
action_sequence = []
|
||||
|
||||
# 🔧 修改:支持自定义vessel参数
|
||||
target_vessel = vessel if vessel is not None else "main_reactor" # 默认目标容器
|
||||
volume = 50.0 # 默认体积 50 mL
|
||||
|
||||
debug_print("=" * 60)
|
||||
debug_print("🚀 开始生成重置处理协议")
|
||||
debug_print(f"📋 输入参数:")
|
||||
debug_print(f" 🧪 溶剂: {solvent}")
|
||||
debug_print(f" 🥽 目标容器: {target_vessel} {'(默认)' if vessel is None else '(指定)'}")
|
||||
debug_print(f" 💧 体积: {volume} mL")
|
||||
debug_print(f" ⚙️ 其他参数: {kwargs}")
|
||||
debug_print("=" * 60)
|
||||
|
||||
# 添加初始日志
|
||||
action_sequence.append(create_action_log(f"开始重置处理操作 - 容器: {target_vessel}", "🎬"))
|
||||
action_sequence.append(create_action_log(f"使用溶剂: {solvent}", "🧪"))
|
||||
action_sequence.append(create_action_log(f"重置体积: {volume}mL", "💧"))
|
||||
|
||||
if vessel is None:
|
||||
action_sequence.append(create_action_log("使用默认目标容器: main_reactor", "⚙️"))
|
||||
else:
|
||||
action_sequence.append(create_action_log(f"使用指定目标容器: {vessel}", "🎯"))
|
||||
|
||||
# 1. 验证目标容器存在
|
||||
debug_print("🔍 步骤1: 验证目标容器...")
|
||||
action_sequence.append(create_action_log("正在验证目标容器...", "🔍"))
|
||||
|
||||
if target_vessel not in G.nodes():
|
||||
debug_print(f"❌ 目标容器 '{target_vessel}' 不存在于系统中!")
|
||||
action_sequence.append(create_action_log(f"目标容器 '{target_vessel}' 不存在", "❌"))
|
||||
raise ValueError(f"目标容器 '{target_vessel}' 不存在于系统中")
|
||||
|
||||
debug_print(f"✅ 目标容器 '{target_vessel}' 验证通过")
|
||||
action_sequence.append(create_action_log(f"目标容器验证通过: {target_vessel}", "✅"))
|
||||
|
||||
# 2. 查找溶剂容器
|
||||
debug_print("🔍 步骤2: 查找溶剂容器...")
|
||||
action_sequence.append(create_action_log("正在查找溶剂容器...", "🔍"))
|
||||
|
||||
try:
|
||||
solvent_vessel = find_solvent_vessel(G, solvent)
|
||||
debug_print(f"✅ 找到溶剂容器: {solvent_vessel}")
|
||||
action_sequence.append(create_action_log(f"找到溶剂容器: {solvent_vessel}", "✅"))
|
||||
except ValueError as e:
|
||||
debug_print(f"❌ 溶剂容器查找失败: {str(e)}")
|
||||
action_sequence.append(create_action_log(f"溶剂容器查找失败: {str(e)}", "❌"))
|
||||
raise ValueError(f"无法找到溶剂 '{solvent}': {str(e)}")
|
||||
|
||||
# 3. 验证路径存在
|
||||
debug_print("🔍 步骤3: 验证传输路径...")
|
||||
action_sequence.append(create_action_log("正在验证传输路径...", "🛤️"))
|
||||
|
||||
try:
|
||||
path = nx.shortest_path(G, source=solvent_vessel, target=target_vessel)
|
||||
debug_print(f"✅ 找到路径: {' → '.join(path)}")
|
||||
action_sequence.append(create_action_log(f"传输路径: {' → '.join(path)}", "🛤️"))
|
||||
except nx.NetworkXNoPath:
|
||||
debug_print(f"❌ 路径不可达: {solvent_vessel} → {target_vessel}")
|
||||
action_sequence.append(create_action_log(f"路径不可达: {solvent_vessel} → {target_vessel}", "❌"))
|
||||
raise ValueError(f"从溶剂容器 '{solvent_vessel}' 到目标容器 '{target_vessel}' 没有可用路径")
|
||||
|
||||
# 4. 使用pump_protocol转移溶剂
|
||||
debug_print("🔍 步骤4: 转移溶剂...")
|
||||
action_sequence.append(create_action_log("开始溶剂转移操作...", "🚰"))
|
||||
|
||||
debug_print(f"🚛 开始转移: {solvent_vessel} → {target_vessel}")
|
||||
debug_print(f"💧 转移体积: {volume} mL")
|
||||
action_sequence.append(create_action_log(f"转移: {solvent_vessel} → {target_vessel} ({volume}mL)", "🚛"))
|
||||
|
||||
try:
|
||||
debug_print("🔄 生成泵送协议...")
|
||||
action_sequence.append(create_action_log("正在生成泵送协议...", "🔄"))
|
||||
|
||||
pump_actions = generate_pump_protocol_with_rinsing(
|
||||
G=G,
|
||||
from_vessel=solvent_vessel,
|
||||
to_vessel=target_vessel,
|
||||
volume=volume,
|
||||
amount="",
|
||||
time=0.0,
|
||||
viscous=False,
|
||||
rinsing_solvent="", # 重置处理不需要清洗
|
||||
rinsing_volume=0.0,
|
||||
rinsing_repeats=0,
|
||||
solid=False,
|
||||
flowrate=2.5, # 正常流速
|
||||
transfer_flowrate=0.5 # 正常转移流速
|
||||
)
|
||||
|
||||
action_sequence.extend(pump_actions)
|
||||
debug_print(f"✅ 泵送协议已添加: {len(pump_actions)} 个动作")
|
||||
action_sequence.append(create_action_log(f"泵送协议完成 ({len(pump_actions)} 个操作)", "✅"))
|
||||
|
||||
except Exception as e:
|
||||
debug_print(f"❌ 泵送协议生成失败: {str(e)}")
|
||||
action_sequence.append(create_action_log(f"泵送协议生成失败: {str(e)}", "❌"))
|
||||
raise ValueError(f"生成泵协议时出错: {str(e)}")
|
||||
|
||||
# 5. 等待溶剂稳定
|
||||
debug_print("🔍 步骤5: 等待溶剂稳定...")
|
||||
action_sequence.append(create_action_log("等待溶剂稳定...", "⏳"))
|
||||
|
||||
# 模拟运行时间优化
|
||||
debug_print("⏱️ 检查模拟运行时间限制...")
|
||||
original_wait_time = 10.0 # 原始等待时间
|
||||
simulation_time_limit = 5.0 # 模拟运行时间限制:5秒
|
||||
|
||||
final_wait_time = min(original_wait_time, simulation_time_limit)
|
||||
|
||||
if original_wait_time > simulation_time_limit:
|
||||
debug_print(f"🎮 模拟运行优化: {original_wait_time}s → {final_wait_time}s")
|
||||
action_sequence.append(create_action_log(f"时间优化: {original_wait_time}s → {final_wait_time}s", "⚡"))
|
||||
else:
|
||||
debug_print(f"✅ 时间在限制内: {final_wait_time}s 保持不变")
|
||||
action_sequence.append(create_action_log(f"等待时间: {final_wait_time}s", "⏰"))
|
||||
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": final_wait_time,
|
||||
"description": f"等待溶剂 {solvent} 在容器 {target_vessel} 中稳定" + (f" (模拟时间)" if original_wait_time != final_wait_time else "")
|
||||
}
|
||||
})
|
||||
debug_print(f"✅ 稳定等待已添加: {final_wait_time}s")
|
||||
|
||||
# 显示时间调整信息
|
||||
if original_wait_time != final_wait_time:
|
||||
debug_print(f"🎭 模拟优化说明: 原计划 {original_wait_time}s,实际模拟 {final_wait_time}s")
|
||||
action_sequence.append(create_action_log("应用模拟时间优化", "🎭"))
|
||||
|
||||
# 总结
|
||||
debug_print("=" * 60)
|
||||
debug_print(f"🎉 重置处理协议生成完成!")
|
||||
debug_print(f"📊 总结信息:")
|
||||
debug_print(f" 📋 总动作数: {len(action_sequence)} 个")
|
||||
debug_print(f" 🧪 溶剂: {solvent}")
|
||||
debug_print(f" 🥽 源容器: {solvent_vessel}")
|
||||
debug_print(f" 🥽 目标容器: {target_vessel} {'(默认)' if vessel is None else '(指定)'}")
|
||||
debug_print(f" 💧 转移体积: {volume} mL")
|
||||
debug_print(f" ⏱️ 预计总时间: {(final_wait_time + 5):.0f} 秒")
|
||||
debug_print(f" 🎯 操作结果: 已添加 {volume} mL {solvent} 到 {target_vessel}")
|
||||
debug_print("=" * 60)
|
||||
|
||||
# 添加完成日志
|
||||
summary_msg = f"重置处理完成: {target_vessel} (使用 {volume}mL {solvent})"
|
||||
if vessel is None:
|
||||
summary_msg += " [默认容器]"
|
||||
else:
|
||||
summary_msg += " [指定容器]"
|
||||
|
||||
action_sequence.append(create_action_log(summary_msg, "🎉"))
|
||||
|
||||
return action_sequence
|
||||
|
||||
# === 便捷函数 ===
|
||||
|
||||
def reset_main_reactor(G: nx.DiGraph, solvent: str = "methanol", **kwargs) -> List[Dict[str, Any]]:
|
||||
"""重置主反应器 (默认行为)"""
|
||||
debug_print(f"🔄 重置主反应器,使用溶剂: {solvent}")
|
||||
return generate_reset_handling_protocol(G, solvent=solvent, vessel=None, **kwargs)
|
||||
|
||||
def reset_custom_vessel(G: nx.DiGraph, vessel: str, solvent: str = "methanol", **kwargs) -> List[Dict[str, Any]]:
|
||||
"""重置指定容器"""
|
||||
debug_print(f"🔄 重置指定容器: {vessel},使用溶剂: {solvent}")
|
||||
return generate_reset_handling_protocol(G, solvent=solvent, vessel=vessel, **kwargs)
|
||||
|
||||
def reset_with_water(G: nx.DiGraph, vessel: Optional[str] = None, **kwargs) -> List[Dict[str, Any]]:
|
||||
"""使用水重置容器"""
|
||||
target = vessel or "main_reactor"
|
||||
debug_print(f"💧 使用水重置容器: {target}")
|
||||
return generate_reset_handling_protocol(G, solvent="water", vessel=vessel, **kwargs)
|
||||
|
||||
def reset_with_methanol(G: nx.DiGraph, vessel: Optional[str] = None, **kwargs) -> List[Dict[str, Any]]:
|
||||
"""使用甲醇重置容器"""
|
||||
target = vessel or "main_reactor"
|
||||
debug_print(f"🧪 使用甲醇重置容器: {target}")
|
||||
return generate_reset_handling_protocol(G, solvent="methanol", vessel=vessel, **kwargs)
|
||||
|
||||
def reset_with_ethanol(G: nx.DiGraph, vessel: Optional[str] = None, **kwargs) -> List[Dict[str, Any]]:
|
||||
"""使用乙醇重置容器"""
|
||||
target = vessel or "main_reactor"
|
||||
debug_print(f"🧪 使用乙醇重置容器: {target}")
|
||||
return generate_reset_handling_protocol(G, solvent="ethanol", vessel=vessel, **kwargs)
|
||||
|
||||
# 测试函数
|
||||
def test_reset_handling_protocol():
|
||||
"""测试重置处理协议"""
|
||||
debug_print("=== 重置处理协议增强中文版测试 ===")
|
||||
|
||||
# 测试溶剂名称
|
||||
debug_print("🧪 测试常用溶剂名称...")
|
||||
test_solvents = ["methanol", "ethanol", "water", "acetone", "dmso"]
|
||||
for solvent in test_solvents:
|
||||
debug_print(f" 🔍 测试溶剂: {solvent}")
|
||||
|
||||
# 测试容器参数
|
||||
debug_print("🥽 测试容器参数...")
|
||||
test_cases = [
|
||||
{"solvent": "methanol", "vessel": None, "desc": "默认容器"},
|
||||
{"solvent": "ethanol", "vessel": "reactor_2", "desc": "指定容器"},
|
||||
{"solvent": "water", "vessel": "flask_1", "desc": "自定义容器"}
|
||||
]
|
||||
|
||||
for case in test_cases:
|
||||
debug_print(f" 🧪 测试案例: {case['desc']} - {case['solvent']} -> {case['vessel'] or 'main_reactor'}")
|
||||
|
||||
debug_print("✅ 测试完成")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_reset_handling_protocol()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,230 +1,740 @@
|
||||
import numpy as np
|
||||
import networkx as nx
|
||||
import re
|
||||
import logging
|
||||
import sys
|
||||
from typing import List, Dict, Any, Union
|
||||
from .pump_protocol import generate_pump_protocol_with_rinsing
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 确保输出编码为UTF-8
|
||||
if hasattr(sys.stdout, 'reconfigure'):
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
sys.stderr.reconfigure(encoding='utf-8')
|
||||
except:
|
||||
pass
|
||||
|
||||
def debug_print(message):
|
||||
"""调试输出函数 - 支持中文"""
|
||||
try:
|
||||
# 确保消息是字符串格式
|
||||
safe_message = str(message)
|
||||
print(f"🌀 [SEPARATE] {safe_message}", flush=True)
|
||||
logger.info(f"[SEPARATE] {safe_message}")
|
||||
except UnicodeEncodeError:
|
||||
# 如果编码失败,尝试替换不支持的字符
|
||||
safe_message = str(message).encode('utf-8', errors='replace').decode('utf-8')
|
||||
print(f"🌀 [SEPARATE] {safe_message}", flush=True)
|
||||
logger.info(f"[SEPARATE] {safe_message}")
|
||||
except Exception as e:
|
||||
# 最后的安全措施
|
||||
fallback_message = f"日志输出错误: {repr(message)}"
|
||||
print(f"🌀 [SEPARATE] {fallback_message}", flush=True)
|
||||
logger.info(f"[SEPARATE] {fallback_message}")
|
||||
|
||||
def create_action_log(message: str, emoji: str = "📝") -> Dict[str, Any]:
|
||||
"""创建一个动作日志 - 支持中文和emoji"""
|
||||
try:
|
||||
full_message = f"{emoji} {message}"
|
||||
debug_print(full_message)
|
||||
logger.info(full_message)
|
||||
|
||||
return {
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 0.1,
|
||||
"log_message": full_message,
|
||||
"progress_message": full_message
|
||||
}
|
||||
}
|
||||
except Exception as e:
|
||||
# 如果emoji有问题,使用纯文本
|
||||
safe_message = f"[日志] {message}"
|
||||
debug_print(safe_message)
|
||||
logger.info(safe_message)
|
||||
|
||||
return {
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 0.1,
|
||||
"log_message": safe_message,
|
||||
"progress_message": safe_message
|
||||
}
|
||||
}
|
||||
|
||||
def parse_volume_input(volume_input: Union[str, float]) -> float:
|
||||
"""
|
||||
解析体积输入,支持带单位的字符串
|
||||
|
||||
Args:
|
||||
volume_input: 体积输入(如 "200 mL", "?", 50.0)
|
||||
|
||||
Returns:
|
||||
float: 体积(毫升)
|
||||
"""
|
||||
if isinstance(volume_input, (int, float)):
|
||||
debug_print(f"📏 体积输入为数值: {volume_input}")
|
||||
return float(volume_input)
|
||||
|
||||
if not volume_input or not str(volume_input).strip():
|
||||
debug_print(f"⚠️ 体积输入为空,返回 0.0mL")
|
||||
return 0.0
|
||||
|
||||
volume_str = str(volume_input).lower().strip()
|
||||
debug_print(f"🔍 解析体积输入: '{volume_str}'")
|
||||
|
||||
# 处理未知体积
|
||||
if volume_str in ['?', 'unknown', 'tbd', 'to be determined', '未知', '待定']:
|
||||
default_volume = 100.0 # 默认100mL
|
||||
debug_print(f"❓ 检测到未知体积,使用默认值: {default_volume}mL")
|
||||
return default_volume
|
||||
|
||||
# 移除空格并提取数字和单位
|
||||
volume_clean = re.sub(r'\s+', '', volume_str)
|
||||
|
||||
# 匹配数字和单位的正则表达式
|
||||
match = re.match(r'([0-9]*\.?[0-9]+)\s*(ml|l|μl|ul|microliter|milliliter|liter|毫升|升|微升)?', volume_clean)
|
||||
|
||||
if not match:
|
||||
debug_print(f"⚠️ 无法解析体积: '{volume_str}',使用默认值 100mL")
|
||||
return 100.0
|
||||
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2) or 'ml' # 默认单位为毫升
|
||||
|
||||
# 转换为毫升
|
||||
if unit in ['l', 'liter', '升']:
|
||||
volume = value * 1000.0 # L -> mL
|
||||
debug_print(f"🔄 体积转换: {value}L -> {volume}mL")
|
||||
elif unit in ['μl', 'ul', 'microliter', '微升']:
|
||||
volume = value / 1000.0 # μL -> mL
|
||||
debug_print(f"🔄 体积转换: {value}μL -> {volume}mL")
|
||||
else: # ml, milliliter, 毫升 或默认
|
||||
volume = value # 已经是mL
|
||||
debug_print(f"✅ 体积已为毫升单位: {volume}mL")
|
||||
|
||||
return volume
|
||||
|
||||
def find_solvent_vessel(G: nx.DiGraph, solvent: str) -> str:
|
||||
"""查找溶剂容器,支持多种匹配模式"""
|
||||
if not solvent or not solvent.strip():
|
||||
debug_print("⏭️ 未指定溶剂,跳过溶剂容器查找")
|
||||
return ""
|
||||
|
||||
debug_print(f"🔍 正在查找溶剂 '{solvent}' 的容器...")
|
||||
|
||||
# 🔧 方法1:直接搜索 data.reagent_name 和 config.reagent
|
||||
debug_print(f"📋 方法1: 搜索试剂字段...")
|
||||
for node in G.nodes():
|
||||
node_data = G.nodes[node].get('data', {})
|
||||
node_type = G.nodes[node].get('type', '')
|
||||
config_data = G.nodes[node].get('config', {})
|
||||
|
||||
# 只搜索容器类型的节点
|
||||
if node_type == 'container':
|
||||
reagent_name = node_data.get('reagent_name', '').lower()
|
||||
config_reagent = config_data.get('reagent', '').lower()
|
||||
|
||||
# 精确匹配
|
||||
if reagent_name == solvent.lower() or config_reagent == solvent.lower():
|
||||
debug_print(f"✅ 通过试剂字段精确匹配找到容器: {node}")
|
||||
return node
|
||||
|
||||
# 模糊匹配
|
||||
if (solvent.lower() in reagent_name and reagent_name) or \
|
||||
(solvent.lower() in config_reagent and config_reagent):
|
||||
debug_print(f"✅ 通过试剂字段模糊匹配找到容器: {node}")
|
||||
return node
|
||||
|
||||
# 🔧 方法2:常见的容器命名规则
|
||||
debug_print(f"📋 方法2: 使用命名规则...")
|
||||
solvent_clean = solvent.lower().replace(' ', '_').replace('-', '_')
|
||||
possible_names = [
|
||||
f"flask_{solvent_clean}",
|
||||
f"bottle_{solvent_clean}",
|
||||
f"vessel_{solvent_clean}",
|
||||
f"{solvent_clean}_flask",
|
||||
f"{solvent_clean}_bottle",
|
||||
f"solvent_{solvent_clean}",
|
||||
f"reagent_{solvent_clean}",
|
||||
f"reagent_bottle_{solvent_clean}",
|
||||
f"reagent_bottle_1", # 通用试剂瓶
|
||||
f"reagent_bottle_2",
|
||||
f"reagent_bottle_3"
|
||||
]
|
||||
|
||||
debug_print(f"🎯 尝试的容器名称: {possible_names[:5]}... (共 {len(possible_names)} 个)")
|
||||
|
||||
for name in possible_names:
|
||||
if name in G.nodes():
|
||||
node_type = G.nodes[name].get('type', '')
|
||||
if node_type == 'container':
|
||||
debug_print(f"✅ 通过命名规则找到容器: {name}")
|
||||
return name
|
||||
|
||||
# 🔧 方法3:使用第一个试剂瓶作为备选
|
||||
debug_print(f"📋 方法3: 查找备用试剂瓶...")
|
||||
for node_id in G.nodes():
|
||||
node_data = G.nodes[node_id]
|
||||
if (node_data.get('type') == 'container' and
|
||||
('reagent' in node_id.lower() or 'bottle' in node_id.lower())):
|
||||
debug_print(f"⚠️ 未找到专用容器,使用备用容器: {node_id}")
|
||||
return node_id
|
||||
|
||||
debug_print(f"❌ 无法找到溶剂 '{solvent}' 的容器")
|
||||
return ""
|
||||
|
||||
def find_separator_device(G: nx.DiGraph, vessel: str) -> str:
|
||||
"""查找分离器设备,支持多种查找方式"""
|
||||
debug_print(f"🔍 正在查找容器 '{vessel}' 的分离器设备...")
|
||||
|
||||
# 方法1:查找连接到容器的分离器设备
|
||||
debug_print(f"📋 方法1: 检查连接的分离器...")
|
||||
separator_nodes = []
|
||||
for node in G.nodes():
|
||||
node_class = G.nodes[node].get('class', '').lower()
|
||||
if 'separator' in node_class:
|
||||
separator_nodes.append(node)
|
||||
debug_print(f"📋 发现分离器设备: {node}")
|
||||
|
||||
# 检查是否连接到目标容器
|
||||
if G.has_edge(node, vessel) or G.has_edge(vessel, node):
|
||||
debug_print(f"✅ 找到连接的分离器: {node}")
|
||||
return node
|
||||
|
||||
debug_print(f"📊 找到的分离器总数: {len(separator_nodes)}")
|
||||
|
||||
# 方法2:根据命名规则查找
|
||||
debug_print(f"📋 方法2: 使用命名规则...")
|
||||
possible_names = [
|
||||
f"{vessel}_controller",
|
||||
f"{vessel}_separator",
|
||||
vessel, # 容器本身可能就是分离器
|
||||
"separator_1",
|
||||
"virtual_separator",
|
||||
"liquid_handler_1", # 液体处理器也可能用于分离
|
||||
"controller_1"
|
||||
]
|
||||
|
||||
debug_print(f"🎯 尝试的分离器名称: {possible_names}")
|
||||
|
||||
for name in possible_names:
|
||||
if name in G.nodes():
|
||||
node_class = G.nodes[name].get('class', '').lower()
|
||||
if 'separator' in node_class or 'controller' in node_class:
|
||||
debug_print(f"✅ 通过命名规则找到分离器: {name}")
|
||||
return name
|
||||
|
||||
# 方法3:查找第一个分离器设备
|
||||
debug_print(f"📋 方法3: 使用第一个可用分离器...")
|
||||
if separator_nodes:
|
||||
debug_print(f"⚠️ 使用第一个分离器设备: {separator_nodes[0]}")
|
||||
return separator_nodes[0]
|
||||
|
||||
debug_print(f"❌ 未找到分离器设备")
|
||||
return ""
|
||||
|
||||
def find_connected_stirrer(G: nx.DiGraph, vessel: str) -> str:
|
||||
"""查找连接到指定容器的搅拌器"""
|
||||
debug_print(f"🔍 正在查找与容器 {vessel} 连接的搅拌器...")
|
||||
|
||||
stirrer_nodes = []
|
||||
for node in G.nodes():
|
||||
node_data = G.nodes[node]
|
||||
node_class = node_data.get('class', '') or ''
|
||||
|
||||
if 'stirrer' in node_class.lower():
|
||||
stirrer_nodes.append(node)
|
||||
debug_print(f"📋 发现搅拌器: {node}")
|
||||
|
||||
debug_print(f"📊 找到的搅拌器总数: {len(stirrer_nodes)}")
|
||||
|
||||
# 检查哪个搅拌器与目标容器相连
|
||||
for stirrer in stirrer_nodes:
|
||||
if G.has_edge(stirrer, vessel) or G.has_edge(vessel, stirrer):
|
||||
debug_print(f"✅ 找到连接的搅拌器: {stirrer}")
|
||||
return stirrer
|
||||
|
||||
# 如果没有连接的搅拌器,返回第一个可用的
|
||||
if stirrer_nodes:
|
||||
debug_print(f"⚠️ 未找到直接连接的搅拌器,使用第一个可用的: {stirrer_nodes[0]}")
|
||||
return stirrer_nodes[0]
|
||||
|
||||
debug_print("❌ 未找到搅拌器")
|
||||
return ""
|
||||
|
||||
def get_vessel_liquid_volume(vessel: dict) -> float:
|
||||
"""
|
||||
获取容器中的液体体积 - 支持vessel字典
|
||||
|
||||
Args:
|
||||
vessel: 容器字典
|
||||
|
||||
Returns:
|
||||
float: 液体体积(mL)
|
||||
"""
|
||||
if not vessel or "data" not in vessel:
|
||||
debug_print(f"⚠️ 容器数据为空,返回 0.0mL")
|
||||
return 0.0
|
||||
|
||||
vessel_data = vessel["data"]
|
||||
vessel_id = vessel.get("id", "unknown")
|
||||
|
||||
debug_print(f"🔍 读取容器 '{vessel_id}' 体积数据: {vessel_data}")
|
||||
|
||||
# 检查liquid_volume字段
|
||||
if "liquid_volume" in vessel_data:
|
||||
liquid_volume = vessel_data["liquid_volume"]
|
||||
|
||||
# 处理列表格式
|
||||
if isinstance(liquid_volume, list):
|
||||
if len(liquid_volume) > 0:
|
||||
volume = liquid_volume[0]
|
||||
if isinstance(volume, (int, float)):
|
||||
debug_print(f"✅ 容器 '{vessel_id}' 体积: {volume}mL (列表格式)")
|
||||
return float(volume)
|
||||
|
||||
# 处理直接数值格式
|
||||
elif isinstance(liquid_volume, (int, float)):
|
||||
debug_print(f"✅ 容器 '{vessel_id}' 体积: {liquid_volume}mL (数值格式)")
|
||||
return float(liquid_volume)
|
||||
|
||||
# 检查其他可能的体积字段
|
||||
volume_keys = ['current_volume', 'total_volume', 'volume']
|
||||
for key in volume_keys:
|
||||
if key in vessel_data:
|
||||
try:
|
||||
volume = float(vessel_data[key])
|
||||
if volume > 0:
|
||||
debug_print(f"✅ 容器 '{vessel_id}' 体积: {volume}mL (字段: {key})")
|
||||
return volume
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
|
||||
debug_print(f"⚠️ 无法获取容器 '{vessel_id}' 的体积,返回默认值 50.0mL")
|
||||
return 50.0
|
||||
|
||||
def update_vessel_volume(vessel: dict, G: nx.DiGraph, new_volume: float, description: str = "") -> None:
|
||||
"""
|
||||
更新容器体积(同时更新vessel字典和图节点)
|
||||
|
||||
Args:
|
||||
vessel: 容器字典
|
||||
G: 网络图
|
||||
new_volume: 新体积
|
||||
description: 更新描述
|
||||
"""
|
||||
vessel_id = vessel.get("id", "unknown")
|
||||
|
||||
if description:
|
||||
debug_print(f"🔧 更新容器体积 - {description}")
|
||||
|
||||
# 更新vessel字典中的体积
|
||||
if "data" in vessel:
|
||||
if "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
if len(current_volume) > 0:
|
||||
vessel["data"]["liquid_volume"][0] = new_volume
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = [new_volume]
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = new_volume
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = new_volume
|
||||
else:
|
||||
vessel["data"] = {"liquid_volume": new_volume}
|
||||
|
||||
# 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
if 'data' not in G.nodes[vessel_id]:
|
||||
G.nodes[vessel_id]['data'] = {}
|
||||
|
||||
vessel_node_data = G.nodes[vessel_id]['data']
|
||||
current_node_volume = vessel_node_data.get('liquid_volume', 0.0)
|
||||
|
||||
if isinstance(current_node_volume, list):
|
||||
if len(current_node_volume) > 0:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'][0] = new_volume
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = [new_volume]
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = new_volume
|
||||
|
||||
debug_print(f"📊 容器 '{vessel_id}' 体积已更新为: {new_volume:.2f}mL")
|
||||
|
||||
def generate_separate_protocol(
|
||||
G: nx.DiGraph,
|
||||
purpose: str, # 'wash' or 'extract'. 'wash' means that product phase will not be the added solvent phase, 'extract' means product phase will be the added solvent phase. If no solvent is added just use 'extract'.
|
||||
product_phase: str, # 'top' or 'bottom'. Phase that product will be in.
|
||||
from_vessel: str, #Contents of from_vessel are transferred to separation_vessel and separation is performed.
|
||||
separation_vessel: str, # Vessel in which separation of phases will be carried out.
|
||||
to_vessel: str, # Vessel to send product phase to.
|
||||
waste_phase_to_vessel: str, # Optional. Vessel to send waste phase to.
|
||||
solvent: str, # Optional. Solvent to add to separation vessel after contents of from_vessel has been transferred to create two phases.
|
||||
solvent_volume: float = 50, # Optional. Volume of solvent to add (mL).
|
||||
through: str = "", # Optional. Solid chemical to send product phase through on way to to_vessel, e.g. 'celite'.
|
||||
repeats: int = 1, # Optional. Number of separations to perform.
|
||||
stir_time: float = 30, # Optional. Time stir for after adding solvent, before separation of phases.
|
||||
stir_speed: float = 300, # Optional. Speed to stir at after adding solvent, before separation of phases.
|
||||
settling_time: float = 300 # Optional. Time
|
||||
) -> list[dict]:
|
||||
G: nx.DiGraph,
|
||||
# 🔧 基础参数,支持XDL的vessel参数
|
||||
vessel: dict = None, # 🔧 修改:从字符串改为字典类型
|
||||
purpose: str = "separate", # 分离目的
|
||||
product_phase: str = "top", # 产物相
|
||||
# 🔧 可选的详细参数
|
||||
from_vessel: Union[str, dict] = "", # 源容器(通常在separate前已经transfer了)
|
||||
separation_vessel: Union[str, dict] = "", # 分离容器(与vessel同义)
|
||||
to_vessel: Union[str, dict] = "", # 目标容器(可选)
|
||||
waste_phase_to_vessel: Union[str, dict] = "", # 废相目标容器
|
||||
product_vessel: Union[str, dict] = "", # XDL: 产物容器(与to_vessel同义)
|
||||
waste_vessel: Union[str, dict] = "", # XDL: 废液容器(与waste_phase_to_vessel同义)
|
||||
# 🔧 溶剂相关参数
|
||||
solvent: str = "", # 溶剂名称
|
||||
solvent_volume: Union[str, float] = 0.0, # 溶剂体积
|
||||
volume: Union[str, float] = 0.0, # XDL: 体积(与solvent_volume同义)
|
||||
# 🔧 操作参数
|
||||
through: str = "", # 通过材料
|
||||
repeats: int = 1, # 重复次数
|
||||
stir_time: float = 30.0, # 搅拌时间(秒)
|
||||
stir_speed: float = 300.0, # 搅拌速度
|
||||
settling_time: float = 300.0, # 沉降时间(秒)
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Generate a protocol to clean a vessel with a solvent.
|
||||
生成分离操作的协议序列 - 支持vessel字典和体积运算
|
||||
|
||||
:param G: Directed graph. Nodes are containers and pumps, edges are fluidic connections.
|
||||
:param vessel: Vessel to clean.
|
||||
:param solvent: Solvent to clean vessel with.
|
||||
:param volume: Volume of solvent to clean vessel with.
|
||||
:param temp: Temperature to heat vessel to while cleaning.
|
||||
:param repeats: Number of cleaning cycles to perform.
|
||||
:return: List of actions to clean vessel.
|
||||
支持XDL参数格式:
|
||||
- vessel: 分离容器字典(必需)
|
||||
- purpose: "wash", "extract", "separate"
|
||||
- product_phase: "top", "bottom"
|
||||
- product_vessel: 产物收集容器
|
||||
- waste_vessel: 废液收集容器
|
||||
- solvent: 溶剂名称
|
||||
- volume: "200 mL", "?" 或数值
|
||||
- repeats: 重复次数
|
||||
|
||||
分离流程:
|
||||
1. (可选)添加溶剂到分离容器
|
||||
2. 搅拌混合
|
||||
3. 静置分层
|
||||
4. 收集指定相到目标容器
|
||||
5. 重复指定次数
|
||||
"""
|
||||
|
||||
# 生成泵操作的动作序列
|
||||
pump_action_sequence = []
|
||||
reactor_volume = 500.0
|
||||
waste_vessel = waste_phase_to_vessel
|
||||
# 🔧 核心修改:vessel参数兼容处理
|
||||
if vessel is None:
|
||||
if isinstance(separation_vessel, dict):
|
||||
vessel = separation_vessel
|
||||
else:
|
||||
raise ValueError("必须提供vessel字典参数")
|
||||
|
||||
# TODO:通过物料管理系统找到溶剂的容器
|
||||
if "," in solvent:
|
||||
solvents = solvent.split(",")
|
||||
assert len(solvents) == repeats, "Number of solvents must match number of repeats."
|
||||
# 🔧 核心修改:从字典中提取容器ID
|
||||
vessel_id = vessel["id"]
|
||||
|
||||
debug_print("🌀" * 20)
|
||||
debug_print("🚀 开始生成分离协议(支持vessel字典和体积运算)✨")
|
||||
debug_print(f"📝 输入参数:")
|
||||
debug_print(f" 🥽 vessel: {vessel} (ID: {vessel_id})")
|
||||
debug_print(f" 🎯 分离目的: '{purpose}'")
|
||||
debug_print(f" 📊 产物相: '{product_phase}'")
|
||||
debug_print(f" 💧 溶剂: '{solvent}'")
|
||||
debug_print(f" 📏 体积: {volume} (类型: {type(volume)})")
|
||||
debug_print(f" 🔄 重复次数: {repeats}")
|
||||
debug_print(f" 🎯 产物容器: '{product_vessel}'")
|
||||
debug_print(f" 🗑️ 废液容器: '{waste_vessel}'")
|
||||
debug_print(f" 📦 其他参数: {kwargs}")
|
||||
debug_print("🌀" * 20)
|
||||
|
||||
action_sequence = []
|
||||
|
||||
# 🔧 新增:记录分离前的容器状态
|
||||
debug_print("🔍 记录分离前容器状态...")
|
||||
original_liquid_volume = get_vessel_liquid_volume(vessel)
|
||||
debug_print(f"📊 分离前液体体积: {original_liquid_volume:.2f}mL")
|
||||
|
||||
# === 参数验证和标准化 ===
|
||||
debug_print("🔍 步骤1: 参数验证和标准化...")
|
||||
action_sequence.append(create_action_log(f"开始分离操作 - 容器: {vessel_id}", "🎬"))
|
||||
action_sequence.append(create_action_log(f"分离目的: {purpose}", "🧪"))
|
||||
action_sequence.append(create_action_log(f"产物相: {product_phase}", "📊"))
|
||||
|
||||
# 统一容器参数 - 支持字典和字符串
|
||||
def extract_vessel_id(vessel_param):
|
||||
if isinstance(vessel_param, dict):
|
||||
return vessel_param.get("id", "")
|
||||
elif isinstance(vessel_param, str):
|
||||
return vessel_param
|
||||
else:
|
||||
return ""
|
||||
|
||||
final_vessel_id = vessel_id
|
||||
final_to_vessel_id = extract_vessel_id(to_vessel) or extract_vessel_id(product_vessel)
|
||||
final_waste_vessel_id = extract_vessel_id(waste_phase_to_vessel) or extract_vessel_id(waste_vessel)
|
||||
|
||||
# 统一体积参数
|
||||
final_volume = parse_volume_input(volume or solvent_volume)
|
||||
|
||||
# 🔧 修复:确保repeats至少为1
|
||||
if repeats <= 0:
|
||||
repeats = 1
|
||||
debug_print(f"⚠️ 重复次数参数 <= 0,自动设置为 1")
|
||||
|
||||
debug_print(f"🔧 标准化后的参数:")
|
||||
debug_print(f" 🥼 分离容器: '{final_vessel_id}'")
|
||||
debug_print(f" 🎯 产物容器: '{final_to_vessel_id}'")
|
||||
debug_print(f" 🗑️ 废液容器: '{final_waste_vessel_id}'")
|
||||
debug_print(f" 📏 溶剂体积: {final_volume}mL")
|
||||
debug_print(f" 🔄 重复次数: {repeats}")
|
||||
|
||||
action_sequence.append(create_action_log(f"分离容器: {final_vessel_id}", "🧪"))
|
||||
action_sequence.append(create_action_log(f"溶剂体积: {final_volume}mL", "📏"))
|
||||
action_sequence.append(create_action_log(f"重复次数: {repeats}", "🔄"))
|
||||
|
||||
# 验证必需参数
|
||||
if not purpose:
|
||||
purpose = "separate"
|
||||
if not product_phase:
|
||||
product_phase = "top"
|
||||
if purpose not in ["wash", "extract", "separate"]:
|
||||
debug_print(f"⚠️ 未知的分离目的 '{purpose}',使用默认值 'separate'")
|
||||
purpose = "separate"
|
||||
action_sequence.append(create_action_log(f"未知目的,使用: {purpose}", "⚠️"))
|
||||
if product_phase not in ["top", "bottom"]:
|
||||
debug_print(f"⚠️ 未知的产物相 '{product_phase}',使用默认值 'top'")
|
||||
product_phase = "top"
|
||||
action_sequence.append(create_action_log(f"未知相别,使用: {product_phase}", "⚠️"))
|
||||
|
||||
debug_print("✅ 参数验证通过")
|
||||
action_sequence.append(create_action_log("参数验证通过", "✅"))
|
||||
|
||||
# === 查找设备 ===
|
||||
debug_print("🔍 步骤2: 查找设备...")
|
||||
action_sequence.append(create_action_log("正在查找相关设备...", "🔍"))
|
||||
|
||||
# 查找分离器设备
|
||||
separator_device = find_separator_device(G, final_vessel_id) # 🔧 使用 final_vessel_id
|
||||
if separator_device:
|
||||
action_sequence.append(create_action_log(f"找到分离器设备: {separator_device}", "🧪"))
|
||||
else:
|
||||
solvents = [solvent] * repeats
|
||||
debug_print("⚠️ 未找到分离器设备,可能无法执行分离")
|
||||
action_sequence.append(create_action_log("未找到分离器设备", "⚠️"))
|
||||
|
||||
# TODO: 通过设备连接图找到分离容器的控制器、底部出口
|
||||
separator_controller = f"{separation_vessel}_controller"
|
||||
separation_vessel_bottom = f"flask_{separation_vessel}"
|
||||
# 查找搅拌器
|
||||
stirrer_device = find_connected_stirrer(G, final_vessel_id) # 🔧 使用 final_vessel_id
|
||||
if stirrer_device:
|
||||
action_sequence.append(create_action_log(f"找到搅拌器: {stirrer_device}", "🌪️"))
|
||||
else:
|
||||
action_sequence.append(create_action_log("未找到搅拌器", "⚠️"))
|
||||
|
||||
transfer_flowrate = flowrate = 2.5
|
||||
# 查找溶剂容器(如果需要)
|
||||
solvent_vessel = ""
|
||||
if solvent and solvent.strip():
|
||||
solvent_vessel = find_solvent_vessel(G, solvent)
|
||||
if solvent_vessel:
|
||||
action_sequence.append(create_action_log(f"找到溶剂容器: {solvent_vessel}", "💧"))
|
||||
else:
|
||||
action_sequence.append(create_action_log(f"未找到溶剂容器: {solvent}", "⚠️"))
|
||||
|
||||
if from_vessel != separation_vessel:
|
||||
pump_action_sequence.append(
|
||||
{
|
||||
"device_id": "",
|
||||
"action_name": "PumpTransferProtocol",
|
||||
"action_kwargs": {
|
||||
"from_vessel": from_vessel,
|
||||
"to_vessel": separation_vessel,
|
||||
"volume": reactor_volume,
|
||||
"time": reactor_volume / flowrate,
|
||||
# "transfer_flowrate": transfer_flowrate,
|
||||
debug_print(f"📊 设备配置:")
|
||||
debug_print(f" 🧪 分离器设备: '{separator_device}'")
|
||||
debug_print(f" 🌪️ 搅拌器设备: '{stirrer_device}'")
|
||||
debug_print(f" 💧 溶剂容器: '{solvent_vessel}'")
|
||||
|
||||
# === 执行分离流程 ===
|
||||
debug_print("🔍 步骤3: 执行分离流程...")
|
||||
action_sequence.append(create_action_log("开始分离工作流程", "🎯"))
|
||||
|
||||
# 🔧 新增:体积变化跟踪变量
|
||||
current_volume = original_liquid_volume
|
||||
|
||||
try:
|
||||
for repeat_idx in range(repeats):
|
||||
cycle_num = repeat_idx + 1
|
||||
debug_print(f"🔄 第{cycle_num}轮: 开始分离循环 {cycle_num}/{repeats}")
|
||||
action_sequence.append(create_action_log(f"分离循环 {cycle_num}/{repeats} 开始", "🔄"))
|
||||
|
||||
# 步骤3.1: 添加溶剂(如果需要)
|
||||
if solvent_vessel and final_volume > 0:
|
||||
debug_print(f"🔄 第{cycle_num}轮 步骤1: 添加溶剂 {solvent} ({final_volume}mL)")
|
||||
action_sequence.append(create_action_log(f"向分离容器添加 {final_volume}mL {solvent}", "💧"))
|
||||
|
||||
try:
|
||||
# 使用pump protocol添加溶剂
|
||||
pump_actions = generate_pump_protocol_with_rinsing(
|
||||
G=G,
|
||||
from_vessel=solvent_vessel,
|
||||
to_vessel=final_vessel_id, # 🔧 使用 final_vessel_id
|
||||
volume=final_volume,
|
||||
amount="",
|
||||
time=0.0,
|
||||
viscous=False,
|
||||
rinsing_solvent="",
|
||||
rinsing_volume=0.0,
|
||||
rinsing_repeats=0,
|
||||
solid=False,
|
||||
flowrate=2.5,
|
||||
transfer_flowrate=0.5,
|
||||
rate_spec="",
|
||||
event="",
|
||||
through="",
|
||||
**kwargs
|
||||
)
|
||||
action_sequence.extend(pump_actions)
|
||||
debug_print(f"✅ 溶剂添加完成,添加了 {len(pump_actions)} 个动作")
|
||||
action_sequence.append(create_action_log(f"溶剂转移完成 ({len(pump_actions)} 个操作)", "✅"))
|
||||
|
||||
# 🔧 新增:更新体积 - 添加溶剂后
|
||||
current_volume += final_volume
|
||||
update_vessel_volume(vessel, G, current_volume, f"添加{final_volume}mL {solvent}后")
|
||||
|
||||
except Exception as e:
|
||||
debug_print(f"❌ 溶剂添加失败: {str(e)}")
|
||||
action_sequence.append(create_action_log(f"溶剂添加失败: {str(e)}", "❌"))
|
||||
else:
|
||||
debug_print(f"🔄 第{cycle_num}轮 步骤1: 无需添加溶剂")
|
||||
action_sequence.append(create_action_log("无需添加溶剂", "⏭️"))
|
||||
|
||||
# 步骤3.2: 启动搅拌(如果有搅拌器)
|
||||
if stirrer_device and stir_time > 0:
|
||||
debug_print(f"🔄 第{cycle_num}轮 步骤2: 开始搅拌 ({stir_speed}rpm,持续 {stir_time}s)")
|
||||
action_sequence.append(create_action_log(f"开始搅拌: {stir_speed}rpm,持续 {stir_time}s", "🌪️"))
|
||||
|
||||
action_sequence.append({
|
||||
"device_id": stirrer_device,
|
||||
"action_name": "start_stir",
|
||||
"action_kwargs": {
|
||||
"vessel": final_vessel_id, # 🔧 使用 final_vessel_id
|
||||
"stir_speed": stir_speed,
|
||||
"purpose": f"分离混合 - {purpose}"
|
||||
}
|
||||
})
|
||||
|
||||
# 搅拌等待
|
||||
stir_minutes = stir_time / 60
|
||||
action_sequence.append(create_action_log(f"搅拌中,持续 {stir_minutes:.1f} 分钟", "⏱️"))
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": stir_time}
|
||||
})
|
||||
|
||||
# 停止搅拌
|
||||
action_sequence.append(create_action_log("停止搅拌器", "🛑"))
|
||||
action_sequence.append({
|
||||
"device_id": stirrer_device,
|
||||
"action_name": "stop_stir",
|
||||
"action_kwargs": {"vessel": final_vessel_id} # 🔧 使用 final_vessel_id
|
||||
})
|
||||
|
||||
else:
|
||||
debug_print(f"🔄 第{cycle_num}轮 步骤2: 无需搅拌")
|
||||
action_sequence.append(create_action_log("无需搅拌", "⏭️"))
|
||||
|
||||
# 步骤3.3: 静置分层
|
||||
if settling_time > 0:
|
||||
debug_print(f"🔄 第{cycle_num}轮 步骤3: 静置分层 ({settling_time}s)")
|
||||
settling_minutes = settling_time / 60
|
||||
action_sequence.append(create_action_log(f"静置分层 ({settling_minutes:.1f} 分钟)", "⚖️"))
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": settling_time}
|
||||
})
|
||||
else:
|
||||
debug_print(f"🔄 第{cycle_num}轮 步骤3: 未指定静置时间")
|
||||
action_sequence.append(create_action_log("未指定静置时间", "⏭️"))
|
||||
|
||||
# 步骤3.4: 执行分离操作
|
||||
if separator_device:
|
||||
debug_print(f"🔄 第{cycle_num}轮 步骤4: 执行分离操作")
|
||||
action_sequence.append(create_action_log(f"执行分离: 收集{product_phase}相", "🧪"))
|
||||
|
||||
# 调用分离器设备的separate方法
|
||||
separate_action = {
|
||||
"device_id": separator_device,
|
||||
"action_name": "separate",
|
||||
"action_kwargs": {
|
||||
"purpose": purpose,
|
||||
"product_phase": product_phase,
|
||||
"from_vessel": extract_vessel_id(from_vessel) or final_vessel_id, # 🔧 使用vessel_id
|
||||
"separation_vessel": final_vessel_id, # 🔧 使用 final_vessel_id
|
||||
"to_vessel": final_to_vessel_id or final_vessel_id, # 🔧 使用vessel_id
|
||||
"waste_phase_to_vessel": final_waste_vessel_id or final_vessel_id, # 🔧 使用vessel_id
|
||||
"solvent": solvent,
|
||||
"solvent_volume": final_volume,
|
||||
"through": through,
|
||||
"repeats": 1, # 每次调用只做一次分离
|
||||
"stir_time": 0, # 已经在上面完成
|
||||
"stir_speed": stir_speed,
|
||||
"settling_time": 0 # 已经在上面完成
|
||||
}
|
||||
}
|
||||
action_sequence.append(separate_action)
|
||||
debug_print(f"✅ 分离操作已添加")
|
||||
action_sequence.append(create_action_log("分离操作完成", "✅"))
|
||||
|
||||
# 🔧 新增:分离后体积估算(分离通常不改变总体积,但会重新分配)
|
||||
# 假设分离后保持体积(实际情况可能有少量损失)
|
||||
separated_volume = current_volume * 0.95 # 假设5%损失
|
||||
update_vessel_volume(vessel, G, separated_volume, f"分离操作后(第{cycle_num}轮)")
|
||||
current_volume = separated_volume
|
||||
|
||||
# 收集结果
|
||||
if final_to_vessel_id:
|
||||
action_sequence.append(create_action_log(f"产物 ({product_phase}相) 收集到: {final_to_vessel_id}", "📦"))
|
||||
if final_waste_vessel_id:
|
||||
action_sequence.append(create_action_log(f"废相收集到: {final_waste_vessel_id}", "🗑️"))
|
||||
|
||||
else:
|
||||
debug_print(f"🔄 第{cycle_num}轮 步骤4: 无分离器设备,跳过分离")
|
||||
action_sequence.append(create_action_log("无分离器设备可用", "❌"))
|
||||
# 添加等待时间模拟分离
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": 10.0}
|
||||
})
|
||||
|
||||
# 循环间等待(除了最后一次)
|
||||
if repeat_idx < repeats - 1:
|
||||
debug_print(f"🔄 第{cycle_num}轮: 等待下一次循环...")
|
||||
action_sequence.append(create_action_log("等待下一次循环...", "⏳"))
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": 5}
|
||||
})
|
||||
else:
|
||||
action_sequence.append(create_action_log(f"分离循环 {cycle_num}/{repeats} 完成", "🌟"))
|
||||
|
||||
except Exception as e:
|
||||
debug_print(f"❌ 分离工作流程执行失败: {str(e)}")
|
||||
action_sequence.append(create_action_log(f"分离工作流程失败: {str(e)}", "❌"))
|
||||
# 添加错误日志
|
||||
action_sequence.append({
|
||||
"device_id": "system",
|
||||
"action_name": "log_message",
|
||||
"action_kwargs": {
|
||||
"message": f"分离操作失败: {str(e)}"
|
||||
}
|
||||
)
|
||||
|
||||
# for i in range(2):
|
||||
# pump_action_sequence.append(
|
||||
# {
|
||||
# "device_id": "",
|
||||
# "action_name": "CleanProtocol",
|
||||
# "action_kwargs": {
|
||||
# "vessel": from_vessel,
|
||||
# "solvent": "H2O", # Solvent to clean vessel with.
|
||||
# "volume": solvent_volume, # Optional. Volume of solvent to clean vessel with.
|
||||
# "temp": 25.0, # Optional. Temperature to heat vessel to while cleaning.
|
||||
# "repeats": 1
|
||||
# }
|
||||
# }
|
||||
# )
|
||||
# pump_action_sequence.append(
|
||||
# {
|
||||
# "device_id": "",
|
||||
# "action_name": "CleanProtocol",
|
||||
# "action_kwargs": {
|
||||
# "vessel": from_vessel,
|
||||
# "solvent": "CH2Cl2", # Solvent to clean vessel with.
|
||||
# "volume": solvent_volume, # Optional. Volume of solvent to clean vessel with.
|
||||
# "temp": 25.0, # Optional. Temperature to heat vessel to while cleaning.
|
||||
# "repeats": 1
|
||||
# }
|
||||
# }
|
||||
# )
|
||||
})
|
||||
|
||||
# 生成泵操作的动作序列
|
||||
for i in range(repeats):
|
||||
# 找到当次萃取所用溶剂
|
||||
solvent_thistime = solvents[i]
|
||||
solvent_vessel = f"flask_{solvent_thistime}"
|
||||
|
||||
pump_action_sequence.append(
|
||||
{
|
||||
"device_id": "",
|
||||
"action_name": "PumpTransferProtocol",
|
||||
"action_kwargs": {
|
||||
"from_vessel": solvent_vessel,
|
||||
"to_vessel": separation_vessel,
|
||||
"volume": solvent_volume,
|
||||
"time": solvent_volume / flowrate,
|
||||
# "transfer_flowrate": transfer_flowrate,
|
||||
}
|
||||
}
|
||||
)
|
||||
pump_action_sequence.extend([
|
||||
# 搅拌、静置
|
||||
{
|
||||
"device_id": separator_controller,
|
||||
"action_name": "stir",
|
||||
"action_kwargs": {
|
||||
"stir_time": stir_time,
|
||||
"stir_speed": stir_speed,
|
||||
"settling_time": settling_time
|
||||
}
|
||||
},
|
||||
# 分液(判断电导突跃)
|
||||
{
|
||||
"device_id": separator_controller,
|
||||
"action_name": "valve_open",
|
||||
"action_kwargs": {
|
||||
"command": "delta > 0.05"
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
if product_phase == "bottom":
|
||||
# 产物转移到目标瓶
|
||||
pump_action_sequence.append(
|
||||
{
|
||||
"device_id": "",
|
||||
"action_name": "PumpTransferProtocol",
|
||||
"action_kwargs": {
|
||||
"from_vessel": separation_vessel_bottom,
|
||||
"to_vessel": to_vessel,
|
||||
"volume": 250.0,
|
||||
"time": 250.0 / flowrate,
|
||||
# "transfer_flowrate": transfer_flowrate,
|
||||
}
|
||||
}
|
||||
)
|
||||
# 放出上面那一相,60秒后关阀门
|
||||
pump_action_sequence.append(
|
||||
{
|
||||
"device_id": separator_controller,
|
||||
"action_name": "valve_open",
|
||||
"action_kwargs": {
|
||||
"command": "time > 60"
|
||||
}
|
||||
}
|
||||
)
|
||||
# 弃去上面那一相进废液
|
||||
pump_action_sequence.append(
|
||||
{
|
||||
"device_id": "",
|
||||
"action_name": "PumpTransferProtocol",
|
||||
"action_kwargs": {
|
||||
"from_vessel": separation_vessel_bottom,
|
||||
"to_vessel": waste_vessel,
|
||||
"volume": 250.0,
|
||||
"time": 250.0 / flowrate,
|
||||
# "transfer_flowrate": transfer_flowrate,
|
||||
}
|
||||
}
|
||||
)
|
||||
elif product_phase == "top":
|
||||
# 弃去下面那一相进废液
|
||||
pump_action_sequence.append(
|
||||
{
|
||||
"device_id": "",
|
||||
"action_name": "PumpTransferProtocol",
|
||||
"action_kwargs": {
|
||||
"from_vessel": separation_vessel_bottom,
|
||||
"to_vessel": waste_vessel,
|
||||
"volume": 250.0,
|
||||
"time": 250.0 / flowrate,
|
||||
# "transfer_flowrate": transfer_flowrate,
|
||||
}
|
||||
}
|
||||
)
|
||||
# 放出上面那一相
|
||||
pump_action_sequence.append(
|
||||
{
|
||||
"device_id": separator_controller,
|
||||
"action_name": "valve_open",
|
||||
"action_kwargs": {
|
||||
"command": "time > 60"
|
||||
}
|
||||
}
|
||||
)
|
||||
# 产物转移到目标瓶
|
||||
pump_action_sequence.append(
|
||||
{
|
||||
"device_id": "",
|
||||
"action_name": "PumpTransferProtocol",
|
||||
"action_kwargs": {
|
||||
"from_vessel": separation_vessel_bottom,
|
||||
"to_vessel": to_vessel,
|
||||
"volume": 250.0,
|
||||
"time": 250.0 / flowrate,
|
||||
# "transfer_flowrate": transfer_flowrate,
|
||||
}
|
||||
}
|
||||
)
|
||||
elif product_phase == "organic":
|
||||
pass
|
||||
|
||||
# 如果不是最后一次,从中转瓶转移回分液漏斗
|
||||
if i < repeats - 1:
|
||||
pump_action_sequence.append(
|
||||
{
|
||||
"device_id": "",
|
||||
"action_name": "PumpTransferProtocol",
|
||||
"action_kwargs": {
|
||||
"from_vessel": to_vessel,
|
||||
"to_vessel": separation_vessel,
|
||||
"volume": 250.0,
|
||||
"time": 250.0 / flowrate,
|
||||
# "transfer_flowrate": transfer_flowrate,
|
||||
}
|
||||
}
|
||||
)
|
||||
return pump_action_sequence
|
||||
# 🔧 新增:分离完成后的最终状态报告
|
||||
final_liquid_volume = get_vessel_liquid_volume(vessel)
|
||||
|
||||
# === 最终结果 ===
|
||||
total_time = (stir_time + settling_time + 15) * repeats # 估算总时间
|
||||
|
||||
debug_print("🌀" * 20)
|
||||
debug_print(f"🎉 分离协议生成完成")
|
||||
debug_print(f"📊 协议统计:")
|
||||
debug_print(f" 📋 总动作数: {len(action_sequence)}")
|
||||
debug_print(f" ⏱️ 预计总时间: {total_time:.0f}s ({total_time/60:.1f} 分钟)")
|
||||
debug_print(f" 🥼 分离容器: {final_vessel_id}")
|
||||
debug_print(f" 🎯 分离目的: {purpose}")
|
||||
debug_print(f" 📊 产物相: {product_phase}")
|
||||
debug_print(f" 🔄 重复次数: {repeats}")
|
||||
debug_print(f"💧 体积变化统计:")
|
||||
debug_print(f" - 分离前体积: {original_liquid_volume:.2f}mL")
|
||||
debug_print(f" - 分离后体积: {final_liquid_volume:.2f}mL")
|
||||
if solvent:
|
||||
debug_print(f" 💧 溶剂: {solvent} ({final_volume}mL × {repeats}轮 = {final_volume * repeats:.2f}mL)")
|
||||
if final_to_vessel_id:
|
||||
debug_print(f" 🎯 产物容器: {final_to_vessel_id}")
|
||||
if final_waste_vessel_id:
|
||||
debug_print(f" 🗑️ 废液容器: {final_waste_vessel_id}")
|
||||
debug_print("🌀" * 20)
|
||||
|
||||
# 添加完成日志
|
||||
summary_msg = f"分离协议完成: {final_vessel_id} ({purpose},{repeats} 次循环)"
|
||||
if solvent:
|
||||
summary_msg += f",使用 {final_volume * repeats:.2f}mL {solvent}"
|
||||
action_sequence.append(create_action_log(summary_msg, "🎉"))
|
||||
|
||||
return action_sequence
|
||||
|
||||
|
||||
@@ -1,166 +1,545 @@
|
||||
from typing import List, Dict, Any
|
||||
from typing import List, Dict, Any, Union
|
||||
import networkx as nx
|
||||
import logging
|
||||
import re
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def debug_print(message):
|
||||
"""调试输出"""
|
||||
print(f"🌪️ [STIR] {message}", flush=True)
|
||||
logger.info(f"[STIR] {message}")
|
||||
|
||||
def parse_time_input(time_input: Union[str, float, int], default_unit: str = "s") -> float:
|
||||
"""
|
||||
统一的时间解析函数(精简版)
|
||||
|
||||
Args:
|
||||
time_input: 时间输入(如 "30 min", "1 h", "300", "?", 60.0)
|
||||
default_unit: 默认单位(默认为秒)
|
||||
|
||||
Returns:
|
||||
float: 时间(秒)
|
||||
"""
|
||||
if not time_input:
|
||||
return 100.0 # 默认100秒
|
||||
|
||||
# 🔢 处理数值输入
|
||||
if isinstance(time_input, (int, float)):
|
||||
result = float(time_input)
|
||||
debug_print(f"⏰ 数值时间: {time_input} → {result}s")
|
||||
return result
|
||||
|
||||
# 📝 处理字符串输入
|
||||
time_str = str(time_input).lower().strip()
|
||||
debug_print(f"🔍 解析时间: '{time_str}'")
|
||||
|
||||
# ❓ 特殊值处理
|
||||
special_times = {
|
||||
'?': 300.0, 'unknown': 300.0, 'tbd': 300.0,
|
||||
'briefly': 30.0, 'quickly': 60.0, 'slowly': 600.0,
|
||||
'several minutes': 300.0, 'few minutes': 180.0, 'overnight': 3600.0
|
||||
}
|
||||
|
||||
if time_str in special_times:
|
||||
result = special_times[time_str]
|
||||
debug_print(f"🎯 特殊时间: '{time_str}' → {result}s ({result/60:.1f}分钟)")
|
||||
return result
|
||||
|
||||
# 🔢 纯数字处理
|
||||
try:
|
||||
result = float(time_str)
|
||||
debug_print(f"⏰ 纯数字: {time_str} → {result}s")
|
||||
return result
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 📐 正则表达式解析
|
||||
pattern = r'(\d+\.?\d*)\s*([a-z]*)'
|
||||
match = re.match(pattern, time_str)
|
||||
|
||||
if not match:
|
||||
debug_print(f"⚠️ 无法解析时间: '{time_str}',使用默认值: 100s")
|
||||
return 100.0
|
||||
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2) or default_unit
|
||||
|
||||
# 📏 单位转换
|
||||
unit_multipliers = {
|
||||
's': 1.0, 'sec': 1.0, 'second': 1.0, 'seconds': 1.0,
|
||||
'm': 60.0, 'min': 60.0, 'mins': 60.0, 'minute': 60.0, 'minutes': 60.0,
|
||||
'h': 3600.0, 'hr': 3600.0, 'hrs': 3600.0, 'hour': 3600.0, 'hours': 3600.0,
|
||||
'd': 86400.0, 'day': 86400.0, 'days': 86400.0
|
||||
}
|
||||
|
||||
multiplier = unit_multipliers.get(unit, 1.0)
|
||||
result = value * multiplier
|
||||
|
||||
debug_print(f"✅ 时间解析: '{time_str}' → {value} {unit} → {result}s ({result/60:.1f}分钟)")
|
||||
return result
|
||||
|
||||
def find_connected_stirrer(G: nx.DiGraph, vessel: str = None) -> str:
|
||||
"""
|
||||
查找与指定容器相连的搅拌设备,或查找可用的搅拌设备
|
||||
"""
|
||||
# 查找所有搅拌设备节点
|
||||
stirrer_nodes = [node for node in G.nodes()
|
||||
if (G.nodes[node].get('class') or '') == 'virtual_stirrer']
|
||||
"""查找与指定容器相连的搅拌设备"""
|
||||
debug_print(f"🔍 查找搅拌设备,目标容器: {vessel} 🥽")
|
||||
|
||||
if vessel:
|
||||
# 检查哪个搅拌设备与目标容器相连(机械连接)
|
||||
# 🔧 查找所有搅拌设备
|
||||
stirrer_nodes = []
|
||||
for node in G.nodes():
|
||||
node_data = G.nodes[node]
|
||||
node_class = node_data.get('class', '') or ''
|
||||
|
||||
if 'stirrer' in node_class.lower() or 'virtual_stirrer' in node_class:
|
||||
stirrer_nodes.append(node)
|
||||
debug_print(f"🎉 找到搅拌设备: {node} 🌪️")
|
||||
|
||||
# 🔗 检查连接
|
||||
if vessel and stirrer_nodes:
|
||||
for stirrer in stirrer_nodes:
|
||||
if G.has_edge(stirrer, vessel) or G.has_edge(vessel, stirrer):
|
||||
debug_print(f"✅ 搅拌设备 '{stirrer}' 与容器 '{vessel}' 相连 🔗")
|
||||
return stirrer
|
||||
|
||||
# 如果没有指定容器或没有直接连接,返回第一个可用的搅拌设备
|
||||
# 🎯 使用第一个可用设备
|
||||
if stirrer_nodes:
|
||||
return stirrer_nodes[0]
|
||||
selected = stirrer_nodes[0]
|
||||
debug_print(f"🔧 使用第一个搅拌设备: {selected} 🌪️")
|
||||
return selected
|
||||
|
||||
raise ValueError("系统中未找到可用的搅拌设备")
|
||||
# 🆘 默认设备
|
||||
debug_print("⚠️ 未找到搅拌设备,使用默认设备 🌪️")
|
||||
return "stirrer_1"
|
||||
|
||||
def validate_and_fix_params(stir_time: float, stir_speed: float, settling_time: float) -> tuple:
|
||||
"""验证和修正参数"""
|
||||
# ⏰ 搅拌时间验证
|
||||
if stir_time < 0:
|
||||
debug_print(f"⚠️ 搅拌时间 {stir_time}s 无效,修正为 100s 🕐")
|
||||
stir_time = 100.0
|
||||
elif stir_time > 100: # 限制为100s
|
||||
debug_print(f"⚠️ 搅拌时间 {stir_time}s 过长,仿真运行时,修正为 100s 🕐")
|
||||
stir_time = 100.0
|
||||
else:
|
||||
debug_print(f"✅ 搅拌时间 {stir_time}s ({stir_time/60:.1f}分钟) 有效 ⏰")
|
||||
|
||||
# 🌪️ 搅拌速度验证
|
||||
if stir_speed < 10.0 or stir_speed > 1500.0:
|
||||
debug_print(f"⚠️ 搅拌速度 {stir_speed} RPM 超出范围,修正为 300 RPM 🌪️")
|
||||
stir_speed = 300.0
|
||||
else:
|
||||
debug_print(f"✅ 搅拌速度 {stir_speed} RPM 在正常范围内 🌪️")
|
||||
|
||||
# ⏱️ 沉降时间验证
|
||||
if settling_time < 0 or settling_time > 600: # 限制为10分钟
|
||||
debug_print(f"⚠️ 沉降时间 {settling_time}s 超出范围,修正为 60s ⏱️")
|
||||
settling_time = 60.0
|
||||
else:
|
||||
debug_print(f"✅ 沉降时间 {settling_time}s 在正常范围内 ⏱️")
|
||||
|
||||
return stir_time, stir_speed, settling_time
|
||||
|
||||
def extract_vessel_id(vessel: Union[str, dict]) -> str:
|
||||
"""
|
||||
从vessel参数中提取vessel_id
|
||||
|
||||
Args:
|
||||
vessel: vessel字典或vessel_id字符串
|
||||
|
||||
Returns:
|
||||
str: vessel_id
|
||||
"""
|
||||
if isinstance(vessel, dict):
|
||||
vessel_id = list(vessel.values())[0].get("id", "")
|
||||
debug_print(f"🔧 从vessel字典提取ID: {vessel_id}")
|
||||
return vessel_id
|
||||
elif isinstance(vessel, str):
|
||||
debug_print(f"🔧 vessel参数为字符串: {vessel}")
|
||||
return vessel
|
||||
else:
|
||||
debug_print(f"⚠️ 无效的vessel参数类型: {type(vessel)}")
|
||||
return ""
|
||||
|
||||
def get_vessel_display_info(vessel: Union[str, dict]) -> str:
|
||||
"""
|
||||
获取容器的显示信息(用于日志)
|
||||
|
||||
Args:
|
||||
vessel: vessel字典或vessel_id字符串
|
||||
|
||||
Returns:
|
||||
str: 显示信息
|
||||
"""
|
||||
if isinstance(vessel, dict):
|
||||
vessel_id = vessel.get("id", "unknown")
|
||||
vessel_name = vessel.get("name", "")
|
||||
if vessel_name:
|
||||
return f"{vessel_id} ({vessel_name})"
|
||||
else:
|
||||
return vessel_id
|
||||
else:
|
||||
return str(vessel)
|
||||
|
||||
def generate_stir_protocol(
|
||||
G: nx.DiGraph,
|
||||
stir_time: float,
|
||||
stir_speed: float,
|
||||
settling_time: float
|
||||
vessel: Union[str, dict], # 支持vessel字典或字符串
|
||||
time: Union[str, float, int] = "300",
|
||||
stir_time: Union[str, float, int] = "0",
|
||||
time_spec: str = "",
|
||||
event: str = "",
|
||||
stir_speed: float = 300.0,
|
||||
settling_time: Union[str, float] = "60",
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成搅拌操作的协议序列 - 定时搅拌 + 沉降
|
||||
"""
|
||||
action_sequence = []
|
||||
"""生成搅拌操作的协议序列 - 修复vessel参数传递"""
|
||||
|
||||
print(f"STIR: 开始生成搅拌协议")
|
||||
print(f" - 搅拌时间: {stir_time}秒")
|
||||
print(f" - 搅拌速度: {stir_speed} RPM")
|
||||
print(f" - 沉降时间: {settling_time}秒")
|
||||
# 🔧 核心修改:正确处理vessel参数
|
||||
vessel_id = extract_vessel_id(vessel)
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
|
||||
# 查找搅拌设备
|
||||
# 🔧 关键修复:确保vessel_resource是完整的Resource对象
|
||||
if isinstance(vessel, dict):
|
||||
vessel_resource = vessel # 已经是完整的Resource字典
|
||||
debug_print(f"✅ 使用传入的vessel Resource对象")
|
||||
else:
|
||||
# 如果只是字符串,构建一个基本的Resource对象
|
||||
vessel_resource = {
|
||||
"id": vessel,
|
||||
"name": "",
|
||||
"category": "",
|
||||
"children": [],
|
||||
"config": "",
|
||||
"data": "",
|
||||
"parent": "",
|
||||
"pose": {
|
||||
"orientation": {"w": 1.0, "x": 0.0, "y": 0.0, "z": 0.0},
|
||||
"position": {"x": 0.0, "y": 0.0, "z": 0.0}
|
||||
},
|
||||
"sample_id": "",
|
||||
"type": ""
|
||||
}
|
||||
debug_print(f"🔧 构建了基本的vessel Resource对象: {vessel}")
|
||||
|
||||
debug_print("🌪️" * 20)
|
||||
debug_print("🚀 开始生成搅拌协议(支持vessel字典)✨")
|
||||
debug_print(f"📝 输入参数:")
|
||||
debug_print(f" 🥽 vessel: {vessel_display} (ID: {vessel_id})")
|
||||
debug_print(f" ⏰ time: {time}")
|
||||
debug_print(f" 🕐 stir_time: {stir_time}")
|
||||
debug_print(f" 🎯 time_spec: {time_spec}")
|
||||
debug_print(f" 🌪️ stir_speed: {stir_speed} RPM")
|
||||
debug_print(f" ⏱️ settling_time: {settling_time}")
|
||||
debug_print("🌪️" * 20)
|
||||
|
||||
# 📋 参数验证
|
||||
debug_print("📍 步骤1: 参数验证... 🔧")
|
||||
if not vessel_id: # 🔧 使用 vessel_id
|
||||
debug_print("❌ vessel 参数不能为空! 😱")
|
||||
raise ValueError("vessel 参数不能为空")
|
||||
|
||||
if vessel_id not in G.nodes(): # 🔧 使用 vessel_id
|
||||
debug_print(f"❌ 容器 '{vessel_id}' 不存在于系统中! 😞")
|
||||
raise ValueError(f"容器 '{vessel_id}' 不存在于系统中")
|
||||
|
||||
debug_print("✅ 基础参数验证通过 🎯")
|
||||
|
||||
# 🔄 参数解析
|
||||
debug_print("📍 步骤2: 参数解析... ⚡")
|
||||
|
||||
# 确定实际时间(优先级:time_spec > stir_time > time)
|
||||
if time_spec:
|
||||
parsed_time = parse_time_input(time_spec)
|
||||
debug_print(f"🎯 使用time_spec: '{time_spec}' → {parsed_time}s")
|
||||
elif stir_time not in ["0", 0, 0.0]:
|
||||
parsed_time = parse_time_input(stir_time)
|
||||
debug_print(f"🎯 使用stir_time: {stir_time} → {parsed_time}s")
|
||||
else:
|
||||
parsed_time = parse_time_input(time)
|
||||
debug_print(f"🎯 使用time: {time} → {parsed_time}s")
|
||||
|
||||
# 解析沉降时间
|
||||
parsed_settling_time = parse_time_input(settling_time)
|
||||
|
||||
# 🕐 模拟运行时间优化
|
||||
debug_print(" ⏱️ 检查模拟运行时间限制...")
|
||||
original_stir_time = parsed_time
|
||||
original_settling_time = parsed_settling_time
|
||||
|
||||
# 搅拌时间限制为60秒
|
||||
stir_time_limit = 60.0
|
||||
if parsed_time > stir_time_limit:
|
||||
parsed_time = stir_time_limit
|
||||
debug_print(f" 🎮 搅拌时间优化: {original_stir_time}s → {parsed_time}s ⚡")
|
||||
|
||||
# 沉降时间限制为30秒
|
||||
settling_time_limit = 30.0
|
||||
if parsed_settling_time > settling_time_limit:
|
||||
parsed_settling_time = settling_time_limit
|
||||
debug_print(f" 🎮 沉降时间优化: {original_settling_time}s → {parsed_settling_time}s ⚡")
|
||||
|
||||
# 参数修正
|
||||
parsed_time, stir_speed, parsed_settling_time = validate_and_fix_params(
|
||||
parsed_time, stir_speed, parsed_settling_time
|
||||
)
|
||||
|
||||
debug_print(f"🎯 最终参数: time={parsed_time}s, speed={stir_speed}RPM, settling={parsed_settling_time}s")
|
||||
|
||||
# 🔍 查找设备
|
||||
debug_print("📍 步骤3: 查找搅拌设备... 🔍")
|
||||
try:
|
||||
stirrer_id = find_connected_stirrer(G)
|
||||
print(f"STIR: 找到搅拌设备: {stirrer_id}")
|
||||
except ValueError as e:
|
||||
stirrer_id = find_connected_stirrer(G, vessel_id) # 🔧 使用 vessel_id
|
||||
debug_print(f"🎉 使用搅拌设备: {stirrer_id} ✨")
|
||||
except Exception as e:
|
||||
debug_print(f"❌ 设备查找失败: {str(e)} 😭")
|
||||
raise ValueError(f"无法找到搅拌设备: {str(e)}")
|
||||
|
||||
# 执行搅拌操作
|
||||
# 🚀 生成动作
|
||||
debug_print("📍 步骤4: 生成搅拌动作... 🌪️")
|
||||
|
||||
action_sequence = []
|
||||
stir_action = {
|
||||
"device_id": stirrer_id,
|
||||
"action_name": "stir",
|
||||
"action_kwargs": {
|
||||
"stir_time": stir_time,
|
||||
"stir_speed": stir_speed,
|
||||
"settling_time": settling_time
|
||||
# 🔧 关键修复:传递vessel_id字符串,而不是完整的Resource对象
|
||||
"vessel": vessel_id, # 传递字符串ID,不是Resource对象
|
||||
"time": str(time),
|
||||
"event": event,
|
||||
"time_spec": time_spec,
|
||||
"stir_time": float(parsed_time),
|
||||
"stir_speed": float(stir_speed),
|
||||
"settling_time": float(parsed_settling_time)
|
||||
}
|
||||
}
|
||||
|
||||
action_sequence.append(stir_action)
|
||||
debug_print("✅ 搅拌动作已添加 🌪️✨")
|
||||
|
||||
# 显示时间优化信息
|
||||
if original_stir_time != parsed_time or original_settling_time != parsed_settling_time:
|
||||
debug_print(f" 🎭 模拟优化说明:")
|
||||
debug_print(f" 搅拌时间: {original_stir_time/60:.1f}分钟 → {parsed_time/60:.1f}分钟")
|
||||
debug_print(f" 沉降时间: {original_settling_time/60:.1f}分钟 → {parsed_settling_time/60:.1f}分钟")
|
||||
|
||||
# 🎊 总结
|
||||
debug_print("🎊" * 20)
|
||||
debug_print(f"🎉 搅拌协议生成完成! ✨")
|
||||
debug_print(f"📊 总动作数: {len(action_sequence)} 个")
|
||||
debug_print(f"🥽 搅拌容器: {vessel_display}")
|
||||
debug_print(f"🌪️ 搅拌参数: {stir_speed} RPM, {parsed_time}s, 沉降 {parsed_settling_time}s")
|
||||
debug_print(f"⏱️ 预计总时间: {(parsed_time + parsed_settling_time)/60:.1f} 分钟 ⌛")
|
||||
debug_print("🎊" * 20)
|
||||
|
||||
print(f"STIR: 生成了 {len(action_sequence)} 个动作")
|
||||
return action_sequence
|
||||
|
||||
|
||||
def generate_start_stir_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
stir_speed: float,
|
||||
purpose: str
|
||||
vessel: Union[str, dict],
|
||||
stir_speed: float = 300.0,
|
||||
purpose: str = "",
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成开始搅拌操作的协议序列 - 持续搅拌
|
||||
"""
|
||||
action_sequence = []
|
||||
"""生成开始搅拌操作的协议序列 - 修复vessel参数传递"""
|
||||
|
||||
print(f"START_STIR: 开始生成启动搅拌协议")
|
||||
print(f" - 容器: {vessel}")
|
||||
print(f" - 搅拌速度: {stir_speed} RPM")
|
||||
print(f" - 目的: {purpose}")
|
||||
# 🔧 核心修改:正确处理vessel参数
|
||||
vessel_id = extract_vessel_id(vessel)
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
|
||||
# 验证容器存在
|
||||
if vessel not in G.nodes():
|
||||
raise ValueError(f"容器 '{vessel}' 不存在于系统中")
|
||||
# 🔧 关键修复:确保vessel_resource是完整的Resource对象
|
||||
if isinstance(vessel, dict):
|
||||
vessel_resource = vessel # 已经是完整的Resource字典
|
||||
debug_print(f"✅ 使用传入的vessel Resource对象")
|
||||
else:
|
||||
# 如果只是字符串,构建一个基本的Resource对象
|
||||
vessel_resource = {
|
||||
"id": vessel,
|
||||
"name": "",
|
||||
"category": "",
|
||||
"children": [],
|
||||
"config": "",
|
||||
"data": "",
|
||||
"parent": "",
|
||||
"pose": {
|
||||
"orientation": {"w": 1.0, "x": 0.0, "y": 0.0, "z": 0.0},
|
||||
"position": {"x": 0.0, "y": 0.0, "z": 0.0}
|
||||
},
|
||||
"sample_id": "",
|
||||
"type": ""
|
||||
}
|
||||
debug_print(f"🔧 构建了基本的vessel Resource对象: {vessel}")
|
||||
|
||||
# 查找搅拌设备
|
||||
try:
|
||||
stirrer_id = find_connected_stirrer(G, vessel)
|
||||
print(f"START_STIR: 找到搅拌设备: {stirrer_id}")
|
||||
except ValueError as e:
|
||||
raise ValueError(f"无法找到搅拌设备: {str(e)}")
|
||||
debug_print("🔄 开始生成启动搅拌协议(修复vessel参数)✨")
|
||||
debug_print(f"🥽 vessel: {vessel_display} (ID: {vessel_id})")
|
||||
debug_print(f"🌪️ speed: {stir_speed} RPM")
|
||||
debug_print(f"🎯 purpose: {purpose}")
|
||||
|
||||
# 执行开始搅拌操作
|
||||
start_stir_action = {
|
||||
# 基础验证
|
||||
if not vessel_id or vessel_id not in G.nodes():
|
||||
debug_print("❌ 容器验证失败!")
|
||||
raise ValueError("vessel 参数无效")
|
||||
|
||||
# 参数修正
|
||||
if stir_speed < 10.0 or stir_speed > 1500.0:
|
||||
debug_print(f"⚠️ 搅拌速度修正: {stir_speed} → 300 RPM 🌪️")
|
||||
stir_speed = 300.0
|
||||
|
||||
# 查找设备
|
||||
stirrer_id = find_connected_stirrer(G, vessel_id)
|
||||
|
||||
# 🔧 关键修复:传递vessel_id字符串
|
||||
action_sequence = [{
|
||||
"device_id": stirrer_id,
|
||||
"action_name": "start_stir",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel,
|
||||
# 🔧 关键修复:传递vessel_id字符串,而不是完整的Resource对象
|
||||
"vessel": vessel_id, # 传递字符串ID,不是Resource对象
|
||||
"stir_speed": stir_speed,
|
||||
"purpose": purpose
|
||||
"purpose": purpose or f"启动搅拌 {stir_speed} RPM"
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
||||
action_sequence.append(start_stir_action)
|
||||
|
||||
print(f"START_STIR: 生成了 {len(action_sequence)} 个动作")
|
||||
debug_print(f"✅ 启动搅拌协议生成完成 🎯")
|
||||
return action_sequence
|
||||
|
||||
|
||||
def generate_stop_stir_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str
|
||||
vessel: Union[str, dict],
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成停止搅拌操作的协议序列
|
||||
"""
|
||||
action_sequence = []
|
||||
"""生成停止搅拌操作的协议序列 - 修复vessel参数传递"""
|
||||
|
||||
print(f"STOP_STIR: 开始生成停止搅拌协议")
|
||||
print(f" - 容器: {vessel}")
|
||||
# 🔧 核心修改:正确处理vessel参数
|
||||
vessel_id = extract_vessel_id(vessel)
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
|
||||
# 验证容器存在
|
||||
if vessel not in G.nodes():
|
||||
raise ValueError(f"容器 '{vessel}' 不存在于系统中")
|
||||
# 🔧 关键修复:确保vessel_resource是完整的Resource对象
|
||||
if isinstance(vessel, dict):
|
||||
vessel_resource = vessel # 已经是完整的Resource字典
|
||||
debug_print(f"✅ 使用传入的vessel Resource对象")
|
||||
else:
|
||||
# 如果只是字符串,构建一个基本的Resource对象
|
||||
vessel_resource = {
|
||||
"id": vessel,
|
||||
"name": "",
|
||||
"category": "",
|
||||
"children": [],
|
||||
"config": "",
|
||||
"data": "",
|
||||
"parent": "",
|
||||
"pose": {
|
||||
"orientation": {"w": 1.0, "x": 0.0, "y": 0.0, "z": 0.0},
|
||||
"position": {"x": 0.0, "y": 0.0, "z": 0.0}
|
||||
},
|
||||
"sample_id": "",
|
||||
"type": ""
|
||||
}
|
||||
debug_print(f"🔧 构建了基本的vessel Resource对象: {vessel}")
|
||||
|
||||
# 查找搅拌设备
|
||||
try:
|
||||
stirrer_id = find_connected_stirrer(G, vessel)
|
||||
print(f"STOP_STIR: 找到搅拌设备: {stirrer_id}")
|
||||
except ValueError as e:
|
||||
raise ValueError(f"无法找到搅拌设备: {str(e)}")
|
||||
debug_print("🛑 开始生成停止搅拌协议(修复vessel参数)✨")
|
||||
debug_print(f"🥽 vessel: {vessel_display} (ID: {vessel_id})")
|
||||
|
||||
# 执行停止搅拌操作
|
||||
stop_stir_action = {
|
||||
# 基础验证
|
||||
if not vessel_id or vessel_id not in G.nodes():
|
||||
debug_print("❌ 容器验证失败!")
|
||||
raise ValueError("vessel 参数无效")
|
||||
|
||||
# 查找设备
|
||||
stirrer_id = find_connected_stirrer(G, vessel_id)
|
||||
|
||||
# 🔧 关键修复:传递vessel_id字符串
|
||||
action_sequence = [{
|
||||
"device_id": stirrer_id,
|
||||
"action_name": "stop_stir",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel
|
||||
# 🔧 关键修复:传递vessel_id字符串,而不是完整的Resource对象
|
||||
"vessel": vessel_id # 传递字符串ID,不是Resource对象
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
||||
action_sequence.append(stop_stir_action)
|
||||
|
||||
print(f"STOP_STIR: 生成了 {len(action_sequence)} 个动作")
|
||||
debug_print(f"✅ 停止搅拌协议生成完成 🎯")
|
||||
return action_sequence
|
||||
|
||||
# 🔧 新增:便捷函数
|
||||
def stir_briefly(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
speed: float = 300.0) -> List[Dict[str, Any]]:
|
||||
"""短时间搅拌(30秒)"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"⚡ 短时间搅拌: {vessel_display} @ {speed}RPM (30s)")
|
||||
return generate_stir_protocol(G, vessel, time="30", stir_speed=speed)
|
||||
|
||||
# 便捷函数
|
||||
def generate_fast_stir_protocol(
|
||||
G: nx.DiGraph,
|
||||
time: float = 300.0,
|
||||
speed: float = 800.0,
|
||||
settling: float = 60.0
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""快速搅拌的便捷函数"""
|
||||
return generate_stir_protocol(G, time, speed, settling)
|
||||
def stir_slowly(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
time: Union[str, float] = "10 min") -> List[Dict[str, Any]]:
|
||||
"""慢速搅拌"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🐌 慢速搅拌: {vessel_display} @ 150RPM")
|
||||
return generate_stir_protocol(G, vessel, time=time, stir_speed=150.0)
|
||||
|
||||
def stir_vigorously(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
time: Union[str, float] = "5 min") -> List[Dict[str, Any]]:
|
||||
"""剧烈搅拌"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"💨 剧烈搅拌: {vessel_display} @ 800RPM")
|
||||
return generate_stir_protocol(G, vessel, time=time, stir_speed=800.0)
|
||||
|
||||
def generate_gentle_stir_protocol(
|
||||
G: nx.DiGraph,
|
||||
time: float = 600.0,
|
||||
speed: float = 200.0,
|
||||
settling: float = 120.0
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""温和搅拌的便捷函数"""
|
||||
return generate_stir_protocol(G, time, speed, settling)
|
||||
def stir_for_reaction(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
time: Union[str, float] = "1 h") -> List[Dict[str, Any]]:
|
||||
"""反应搅拌(标准速度,长时间)"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🧪 反应搅拌: {vessel_display} @ 400RPM")
|
||||
return generate_stir_protocol(G, vessel, time=time, stir_speed=400.0)
|
||||
|
||||
def stir_for_dissolution(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
time: Union[str, float] = "15 min") -> List[Dict[str, Any]]:
|
||||
"""溶解搅拌(中等速度)"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"💧 溶解搅拌: {vessel_display} @ 500RPM")
|
||||
return generate_stir_protocol(G, vessel, time=time, stir_speed=500.0)
|
||||
|
||||
def stir_gently(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
time: Union[str, float] = "30 min") -> List[Dict[str, Any]]:
|
||||
"""温和搅拌"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🍃 温和搅拌: {vessel_display} @ 200RPM")
|
||||
return generate_stir_protocol(G, vessel, time=time, stir_speed=200.0)
|
||||
|
||||
def stir_overnight(G: nx.DiGraph, vessel: Union[str, dict]) -> List[Dict[str, Any]]:
|
||||
"""过夜搅拌(模拟时缩短为2小时)"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🌙 过夜搅拌(模拟2小时): {vessel_display} @ 300RPM")
|
||||
return generate_stir_protocol(G, vessel, time="2 h", stir_speed=300.0)
|
||||
|
||||
def start_continuous_stirring(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
speed: float = 300.0, purpose: str = "continuous stirring") -> List[Dict[str, Any]]:
|
||||
"""开始连续搅拌"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🔄 开始连续搅拌: {vessel_display} @ {speed}RPM")
|
||||
return generate_start_stir_protocol(G, vessel, stir_speed=speed, purpose=purpose)
|
||||
|
||||
def stop_all_stirring(G: nx.DiGraph, vessel: Union[str, dict]) -> List[Dict[str, Any]]:
|
||||
"""停止所有搅拌"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🛑 停止搅拌: {vessel_display}")
|
||||
return generate_stop_stir_protocol(G, vessel)
|
||||
|
||||
# 测试函数
|
||||
def test_stir_protocol():
|
||||
"""测试搅拌协议"""
|
||||
debug_print("🧪 === STIR PROTOCOL 测试 === ✨")
|
||||
|
||||
# 测试vessel参数处理
|
||||
debug_print("🔧 测试vessel参数处理...")
|
||||
|
||||
# 测试字典格式
|
||||
vessel_dict = {"id": "flask_1", "name": "反应瓶1"}
|
||||
vessel_id = extract_vessel_id(vessel_dict)
|
||||
vessel_display = get_vessel_display_info(vessel_dict)
|
||||
debug_print(f" 字典格式: {vessel_dict} → ID: {vessel_id}, 显示: {vessel_display}")
|
||||
|
||||
# 测试字符串格式
|
||||
vessel_str = "flask_2"
|
||||
vessel_id = extract_vessel_id(vessel_str)
|
||||
vessel_display = get_vessel_display_info(vessel_str)
|
||||
debug_print(f" 字符串格式: {vessel_str} → ID: {vessel_id}, 显示: {vessel_display}")
|
||||
|
||||
debug_print("✅ 测试完成 🎉")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_stir_protocol()
|
||||
|
||||
206
unilabos/compile/utils/unit_parser.py
Normal file
206
unilabos/compile/utils/unit_parser.py
Normal file
@@ -0,0 +1,206 @@
|
||||
"""
|
||||
统一的单位解析工具模块
|
||||
支持时间、体积、质量等各种单位的解析
|
||||
"""
|
||||
|
||||
import re
|
||||
import logging
|
||||
from typing import Union
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def debug_print(message, prefix="[UNIT_PARSER]"):
|
||||
"""调试输出"""
|
||||
print(f"{prefix} {message}", flush=True)
|
||||
logger.info(f"{prefix} {message}")
|
||||
|
||||
def parse_time_with_units(time_input: Union[str, float, int], default_unit: str = "s") -> float:
|
||||
"""
|
||||
解析带单位的时间输入
|
||||
|
||||
Args:
|
||||
time_input: 时间输入(如 "30 min", "1 h", "300", "?", 60.0)
|
||||
default_unit: 默认单位(默认为秒)
|
||||
|
||||
Returns:
|
||||
float: 时间(秒)
|
||||
"""
|
||||
if not time_input:
|
||||
return 0.0
|
||||
|
||||
# 处理数值输入
|
||||
if isinstance(time_input, (int, float)):
|
||||
result = float(time_input)
|
||||
debug_print(f"数值时间输入: {time_input} → {result}s(默认单位)")
|
||||
return result
|
||||
|
||||
# 处理字符串输入
|
||||
time_str = str(time_input).lower().strip()
|
||||
debug_print(f"解析时间字符串: '{time_str}'")
|
||||
|
||||
# 处理特殊值
|
||||
if time_str in ['?', 'unknown', 'tbd', 'to be determined']:
|
||||
default_time = 300.0 # 5分钟默认值
|
||||
debug_print(f"检测到未知时间,使用默认值: {default_time}s")
|
||||
return default_time
|
||||
|
||||
# 如果是纯数字,使用默认单位
|
||||
try:
|
||||
value = float(time_str)
|
||||
if default_unit == "s":
|
||||
result = value
|
||||
elif default_unit in ["min", "minute"]:
|
||||
result = value * 60.0
|
||||
elif default_unit in ["h", "hour"]:
|
||||
result = value * 3600.0
|
||||
else:
|
||||
result = value # 默认秒
|
||||
debug_print(f"纯数字输入: {time_str} → {result}s(单位: {default_unit})")
|
||||
return result
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 使用正则表达式匹配数字和单位
|
||||
pattern = r'(\d+\.?\d*)\s*([a-z]*)'
|
||||
match = re.match(pattern, time_str)
|
||||
|
||||
if not match:
|
||||
debug_print(f"⚠️ 无法解析时间: '{time_str}',使用默认值: 60s")
|
||||
return 60.0
|
||||
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2) or default_unit
|
||||
|
||||
# 单位转换映射
|
||||
unit_multipliers = {
|
||||
# 秒
|
||||
's': 1.0,
|
||||
'sec': 1.0,
|
||||
'second': 1.0,
|
||||
'seconds': 1.0,
|
||||
|
||||
# 分钟
|
||||
'm': 60.0,
|
||||
'min': 60.0,
|
||||
'mins': 60.0,
|
||||
'minute': 60.0,
|
||||
'minutes': 60.0,
|
||||
|
||||
# 小时
|
||||
'h': 3600.0,
|
||||
'hr': 3600.0,
|
||||
'hrs': 3600.0,
|
||||
'hour': 3600.0,
|
||||
'hours': 3600.0,
|
||||
|
||||
# 天
|
||||
'd': 86400.0,
|
||||
'day': 86400.0,
|
||||
'days': 86400.0,
|
||||
}
|
||||
|
||||
multiplier = unit_multipliers.get(unit, 1.0)
|
||||
result = value * multiplier
|
||||
|
||||
debug_print(f"时间解析: '{time_str}' → {value} {unit} → {result}s")
|
||||
return result
|
||||
|
||||
def parse_volume_with_units(volume_input: Union[str, float, int], default_unit: str = "mL") -> float:
|
||||
"""
|
||||
解析带单位的体积输入
|
||||
|
||||
Args:
|
||||
volume_input: 体积输入(如 "100 mL", "2.5 L", "500", "?", 100.0)
|
||||
default_unit: 默认单位(默认为毫升)
|
||||
|
||||
Returns:
|
||||
float: 体积(毫升)
|
||||
"""
|
||||
if not volume_input:
|
||||
return 0.0
|
||||
|
||||
# 处理数值输入
|
||||
if isinstance(volume_input, (int, float)):
|
||||
result = float(volume_input)
|
||||
debug_print(f"数值体积输入: {volume_input} → {result}mL(默认单位)")
|
||||
return result
|
||||
|
||||
# 处理字符串输入
|
||||
volume_str = str(volume_input).lower().strip()
|
||||
debug_print(f"解析体积字符串: '{volume_str}'")
|
||||
|
||||
# 处理特殊值
|
||||
if volume_str in ['?', 'unknown', 'tbd', 'to be determined']:
|
||||
default_volume = 50.0 # 50mL默认值
|
||||
debug_print(f"检测到未知体积,使用默认值: {default_volume}mL")
|
||||
return default_volume
|
||||
|
||||
# 如果是纯数字,使用默认单位
|
||||
try:
|
||||
value = float(volume_str)
|
||||
if default_unit.lower() in ["ml", "milliliter"]:
|
||||
result = value
|
||||
elif default_unit.lower() in ["l", "liter"]:
|
||||
result = value * 1000.0
|
||||
elif default_unit.lower() in ["μl", "ul", "microliter"]:
|
||||
result = value / 1000.0
|
||||
else:
|
||||
result = value # 默认mL
|
||||
debug_print(f"纯数字输入: {volume_str} → {result}mL(单位: {default_unit})")
|
||||
return result
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# 移除空格并提取数字和单位
|
||||
volume_clean = re.sub(r'\s+', '', volume_str)
|
||||
|
||||
# 匹配数字和单位的正则表达式
|
||||
match = re.match(r'([0-9]*\.?[0-9]+)\s*(ml|l|μl|ul|microliter|milliliter|liter)?', volume_clean)
|
||||
|
||||
if not match:
|
||||
debug_print(f"⚠️ 无法解析体积: '{volume_str}',使用默认值: 50mL")
|
||||
return 50.0
|
||||
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2) or default_unit.lower()
|
||||
|
||||
# 转换为毫升
|
||||
if unit in ['l', 'liter']:
|
||||
volume = value * 1000.0 # L -> mL
|
||||
elif unit in ['μl', 'ul', 'microliter']:
|
||||
volume = value / 1000.0 # μL -> mL
|
||||
else: # ml, milliliter 或默认
|
||||
volume = value # 已经是mL
|
||||
|
||||
debug_print(f"体积解析: '{volume_str}' → {value} {unit} → {volume}mL")
|
||||
return volume
|
||||
|
||||
# 测试函数
|
||||
def test_unit_parser():
|
||||
"""测试单位解析功能"""
|
||||
print("=== 单位解析器测试 ===")
|
||||
|
||||
# 测试时间解析
|
||||
time_tests = [
|
||||
"30 min", "1 h", "300", "5.5 h", "?", 60.0, "2 hours", "30 s"
|
||||
]
|
||||
|
||||
print("\n时间解析测试:")
|
||||
for time_input in time_tests:
|
||||
result = parse_time_with_units(time_input)
|
||||
print(f" {time_input} → {result}s ({result/60:.1f}min)")
|
||||
|
||||
# 测试体积解析
|
||||
volume_tests = [
|
||||
"100 mL", "2.5 L", "500", "?", 100.0, "500 μL", "1 liter"
|
||||
]
|
||||
|
||||
print("\n体积解析测试:")
|
||||
for volume_input in volume_tests:
|
||||
result = parse_volume_with_units(volume_input)
|
||||
print(f" {volume_input} → {result}mL")
|
||||
|
||||
print("\n✅ 测试完成")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_unit_parser()
|
||||
@@ -1,216 +1,652 @@
|
||||
from typing import List, Dict, Any
|
||||
from typing import List, Dict, Any, Union
|
||||
import networkx as nx
|
||||
import logging
|
||||
import re
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def debug_print(message):
|
||||
"""调试输出"""
|
||||
print(f"🧼 [WASH_SOLID] {message}", flush=True)
|
||||
logger.info(f"[WASH_SOLID] {message}")
|
||||
|
||||
def parse_time_input(time_input: Union[str, float, int]) -> float:
|
||||
"""统一时间解析函数(精简版)"""
|
||||
if not time_input:
|
||||
return 0.0
|
||||
|
||||
# 🔢 处理数值输入
|
||||
if isinstance(time_input, (int, float)):
|
||||
result = float(time_input)
|
||||
debug_print(f"⏰ 数值时间: {time_input} → {result}s")
|
||||
return result
|
||||
|
||||
# 📝 处理字符串输入
|
||||
time_str = str(time_input).lower().strip()
|
||||
|
||||
# ❓ 特殊值快速处理
|
||||
special_times = {
|
||||
'?': 60.0, 'unknown': 60.0, 'briefly': 30.0,
|
||||
'quickly': 45.0, 'slowly': 120.0
|
||||
}
|
||||
|
||||
if time_str in special_times:
|
||||
result = special_times[time_str]
|
||||
debug_print(f"🎯 特殊时间: '{time_str}' → {result}s")
|
||||
return result
|
||||
|
||||
# 🔢 数字提取(简化正则)
|
||||
try:
|
||||
# 提取数字
|
||||
numbers = re.findall(r'\d+\.?\d*', time_str)
|
||||
if numbers:
|
||||
value = float(numbers[0])
|
||||
|
||||
# 简化单位判断
|
||||
if any(unit in time_str for unit in ['min', 'm']):
|
||||
result = value * 60.0
|
||||
elif any(unit in time_str for unit in ['h', 'hour']):
|
||||
result = value * 3600.0
|
||||
else:
|
||||
result = value # 默认秒
|
||||
|
||||
debug_print(f"✅ 时间解析: '{time_str}' → {result}s")
|
||||
return result
|
||||
except:
|
||||
pass
|
||||
|
||||
debug_print(f"⚠️ 时间解析失败: '{time_str}',使用默认60s")
|
||||
return 60.0
|
||||
|
||||
def parse_volume_input(volume: Union[float, str], volume_spec: str = "", mass: str = "") -> float:
|
||||
"""统一体积解析函数(精简版)"""
|
||||
debug_print(f"💧 解析体积: volume={volume}, spec='{volume_spec}', mass='{mass}'")
|
||||
|
||||
# 🎯 优先级1:volume_spec(快速映射)
|
||||
if volume_spec:
|
||||
spec_map = {
|
||||
'small': 20.0, 'medium': 50.0, 'large': 100.0,
|
||||
'minimal': 10.0, 'normal': 50.0, 'generous': 150.0
|
||||
}
|
||||
for key, val in spec_map.items():
|
||||
if key in volume_spec.lower():
|
||||
debug_print(f"🎯 规格匹配: '{volume_spec}' → {val}mL")
|
||||
return val
|
||||
|
||||
# 🧮 优先级2:mass转体积(简化:1g=1mL)
|
||||
if mass:
|
||||
try:
|
||||
numbers = re.findall(r'\d+\.?\d*', mass)
|
||||
if numbers:
|
||||
value = float(numbers[0])
|
||||
if 'mg' in mass.lower():
|
||||
result = value / 1000.0
|
||||
elif 'kg' in mass.lower():
|
||||
result = value * 1000.0
|
||||
else:
|
||||
result = value # 默认g
|
||||
debug_print(f"⚖️ 质量转换: {mass} → {result}mL")
|
||||
return result
|
||||
except:
|
||||
pass
|
||||
|
||||
# 📦 优先级3:volume
|
||||
if volume:
|
||||
if isinstance(volume, (int, float)):
|
||||
result = float(volume)
|
||||
debug_print(f"💧 数值体积: {volume} → {result}mL")
|
||||
return result
|
||||
elif isinstance(volume, str):
|
||||
try:
|
||||
# 提取数字
|
||||
numbers = re.findall(r'\d+\.?\d*', volume)
|
||||
if numbers:
|
||||
value = float(numbers[0])
|
||||
# 简化单位判断
|
||||
if 'l' in volume.lower() and 'ml' not in volume.lower():
|
||||
result = value * 1000.0 # L转mL
|
||||
else:
|
||||
result = value # 默认mL
|
||||
debug_print(f"💧 字符串体积: '{volume}' → {result}mL")
|
||||
return result
|
||||
except:
|
||||
pass
|
||||
|
||||
# 默认值
|
||||
debug_print(f"⚠️ 体积解析失败,使用默认50mL")
|
||||
return 50.0
|
||||
|
||||
def find_solvent_source(G: nx.DiGraph, solvent: str) -> str:
|
||||
"""查找溶剂源(精简版)"""
|
||||
debug_print(f"🔍 查找溶剂源: {solvent}")
|
||||
|
||||
# 简化搜索列表
|
||||
search_patterns = [
|
||||
f"flask_{solvent}", f"bottle_{solvent}", f"reagent_{solvent}",
|
||||
"liquid_reagent_bottle_1", "flask_1", "solvent_bottle"
|
||||
]
|
||||
|
||||
for pattern in search_patterns:
|
||||
if pattern in G.nodes():
|
||||
debug_print(f"🎉 找到溶剂源: {pattern}")
|
||||
return pattern
|
||||
|
||||
debug_print(f"⚠️ 使用默认溶剂源: flask_{solvent}")
|
||||
return f"flask_{solvent}"
|
||||
|
||||
def find_filtrate_vessel(G: nx.DiGraph, filtrate_vessel: str = "") -> str:
|
||||
"""查找滤液容器(精简版)"""
|
||||
debug_print(f"🔍 查找滤液容器: {filtrate_vessel}")
|
||||
|
||||
# 如果指定了且存在,直接使用
|
||||
if filtrate_vessel and filtrate_vessel in G.nodes():
|
||||
debug_print(f"✅ 使用指定容器: {filtrate_vessel}")
|
||||
return filtrate_vessel
|
||||
|
||||
# 简化搜索列表
|
||||
default_vessels = ["waste_workup", "filtrate_vessel", "flask_1", "collection_bottle_1"]
|
||||
|
||||
for vessel in default_vessels:
|
||||
if vessel in G.nodes():
|
||||
debug_print(f"🎉 找到滤液容器: {vessel}")
|
||||
return vessel
|
||||
|
||||
debug_print(f"⚠️ 使用默认滤液容器: waste_workup")
|
||||
return "waste_workup"
|
||||
|
||||
def extract_vessel_id(vessel: Union[str, dict]) -> str:
|
||||
"""
|
||||
从vessel参数中提取vessel_id
|
||||
|
||||
Args:
|
||||
vessel: vessel字典或vessel_id字符串
|
||||
|
||||
Returns:
|
||||
str: vessel_id
|
||||
"""
|
||||
if isinstance(vessel, dict):
|
||||
vessel_id = list(vessel.values())[0].get("id", "")
|
||||
debug_print(f"🔧 从vessel字典提取ID: {vessel_id}")
|
||||
return vessel_id
|
||||
elif isinstance(vessel, str):
|
||||
debug_print(f"🔧 vessel参数为字符串: {vessel}")
|
||||
return vessel
|
||||
else:
|
||||
debug_print(f"⚠️ 无效的vessel参数类型: {type(vessel)}")
|
||||
return ""
|
||||
|
||||
def get_vessel_display_info(vessel: Union[str, dict]) -> str:
|
||||
"""
|
||||
获取容器的显示信息(用于日志)
|
||||
|
||||
Args:
|
||||
vessel: vessel字典或vessel_id字符串
|
||||
|
||||
Returns:
|
||||
str: 显示信息
|
||||
"""
|
||||
if isinstance(vessel, dict):
|
||||
vessel_id = vessel.get("id", "unknown")
|
||||
vessel_name = vessel.get("name", "")
|
||||
if vessel_name:
|
||||
return f"{vessel_id} ({vessel_name})"
|
||||
else:
|
||||
return vessel_id
|
||||
else:
|
||||
return str(vessel)
|
||||
|
||||
def get_vessel_liquid_volume(vessel: dict) -> float:
|
||||
"""
|
||||
获取容器中的液体体积 - 支持vessel字典
|
||||
|
||||
Args:
|
||||
vessel: 容器字典
|
||||
|
||||
Returns:
|
||||
float: 液体体积(mL)
|
||||
"""
|
||||
if not vessel or "data" not in vessel:
|
||||
debug_print(f"⚠️ 容器数据为空,返回 0.0mL")
|
||||
return 0.0
|
||||
|
||||
vessel_data = vessel["data"]
|
||||
vessel_id = vessel.get("id", "unknown")
|
||||
|
||||
debug_print(f"🔍 读取容器 '{vessel_id}' 体积数据: {vessel_data}")
|
||||
|
||||
# 检查liquid_volume字段
|
||||
if "liquid_volume" in vessel_data:
|
||||
liquid_volume = vessel_data["liquid_volume"]
|
||||
|
||||
# 处理列表格式
|
||||
if isinstance(liquid_volume, list):
|
||||
if len(liquid_volume) > 0:
|
||||
volume = liquid_volume[0]
|
||||
if isinstance(volume, (int, float)):
|
||||
debug_print(f"✅ 容器 '{vessel_id}' 体积: {volume}mL (列表格式)")
|
||||
return float(volume)
|
||||
|
||||
# 处理直接数值格式
|
||||
elif isinstance(liquid_volume, (int, float)):
|
||||
debug_print(f"✅ 容器 '{vessel_id}' 体积: {liquid_volume}mL (数值格式)")
|
||||
return float(liquid_volume)
|
||||
|
||||
# 检查其他可能的体积字段
|
||||
volume_keys = ['current_volume', 'total_volume', 'volume']
|
||||
for key in volume_keys:
|
||||
if key in vessel_data:
|
||||
try:
|
||||
volume = float(vessel_data[key])
|
||||
if volume > 0:
|
||||
debug_print(f"✅ 容器 '{vessel_id}' 体积: {volume}mL (字段: {key})")
|
||||
return volume
|
||||
except (ValueError, TypeError):
|
||||
continue
|
||||
|
||||
debug_print(f"⚠️ 无法获取容器 '{vessel_id}' 的体积,返回默认值 0.0mL")
|
||||
return 0.0
|
||||
|
||||
def update_vessel_volume(vessel: dict, G: nx.DiGraph, new_volume: float, description: str = "") -> None:
|
||||
"""
|
||||
更新容器体积(同时更新vessel字典和图节点)
|
||||
|
||||
Args:
|
||||
vessel: 容器字典
|
||||
G: 网络图
|
||||
new_volume: 新体积
|
||||
description: 更新描述
|
||||
"""
|
||||
vessel_id = vessel.get("id", "unknown")
|
||||
|
||||
if description:
|
||||
debug_print(f"🔧 更新容器体积 - {description}")
|
||||
|
||||
# 更新vessel字典中的体积
|
||||
if "data" in vessel:
|
||||
if "liquid_volume" in vessel["data"]:
|
||||
current_volume = vessel["data"]["liquid_volume"]
|
||||
if isinstance(current_volume, list):
|
||||
if len(current_volume) > 0:
|
||||
vessel["data"]["liquid_volume"][0] = new_volume
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = [new_volume]
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = new_volume
|
||||
else:
|
||||
vessel["data"]["liquid_volume"] = new_volume
|
||||
else:
|
||||
vessel["data"] = {"liquid_volume": new_volume}
|
||||
|
||||
# 同时更新图中的容器数据
|
||||
if vessel_id in G.nodes():
|
||||
if 'data' not in G.nodes[vessel_id]:
|
||||
G.nodes[vessel_id]['data'] = {}
|
||||
|
||||
vessel_node_data = G.nodes[vessel_id]['data']
|
||||
current_node_volume = vessel_node_data.get('liquid_volume', 0.0)
|
||||
|
||||
if isinstance(current_node_volume, list):
|
||||
if len(current_node_volume) > 0:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'][0] = new_volume
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = [new_volume]
|
||||
else:
|
||||
G.nodes[vessel_id]['data']['liquid_volume'] = new_volume
|
||||
|
||||
debug_print(f"📊 容器 '{vessel_id}' 体积已更新为: {new_volume:.2f}mL")
|
||||
|
||||
def generate_wash_solid_protocol(
|
||||
G: nx.DiGraph,
|
||||
vessel: str,
|
||||
vessel: Union[str, dict], # 🔧 修改:支持vessel字典
|
||||
solvent: str,
|
||||
volume: float,
|
||||
filtrate_vessel: str = "",
|
||||
volume: Union[float, str] = "50",
|
||||
filtrate_vessel: Union[str, dict] = "", # 🔧 修改:支持vessel字典
|
||||
temp: float = 25.0,
|
||||
stir: bool = False,
|
||||
stir_speed: float = 0.0,
|
||||
time: float = 0.0,
|
||||
repeats: int = 1
|
||||
time: Union[str, float] = "0",
|
||||
repeats: int = 1,
|
||||
volume_spec: str = "",
|
||||
repeats_spec: str = "",
|
||||
mass: str = "",
|
||||
event: str = "",
|
||||
**kwargs
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
生成固体清洗的协议序列
|
||||
生成固体清洗协议 - 支持vessel字典和体积运算
|
||||
|
||||
Args:
|
||||
G: 有向图,节点为设备和容器
|
||||
vessel: 装有固体物质的容器名称
|
||||
solvent: 用于清洗固体的溶剂名称
|
||||
volume: 清洗溶剂的体积
|
||||
filtrate_vessel: 滤液要收集到的容器名称,可选参数
|
||||
temp: 清洗时的温度,可选参数
|
||||
stir: 是否在清洗过程中搅拌,默认为 False
|
||||
stir_speed: 搅拌速度,可选参数
|
||||
time: 清洗的时间,可选参数
|
||||
repeats: 清洗操作的重复次数,默认为 1
|
||||
G: 有向图,节点为设备和容器,边为流体管道
|
||||
vessel: 清洗容器字典(从XDL传入)或容器ID字符串
|
||||
solvent: 清洗溶剂名称
|
||||
volume: 溶剂体积(每次清洗)
|
||||
filtrate_vessel: 滤液收集容器字典或容器ID字符串
|
||||
temp: 清洗温度(°C)
|
||||
stir: 是否搅拌
|
||||
stir_speed: 搅拌速度(RPM)
|
||||
time: 搅拌时间
|
||||
repeats: 清洗重复次数
|
||||
volume_spec: 体积规格(small/medium/large)
|
||||
repeats_spec: 重复次数规格(few/several/many)
|
||||
mass: 固体质量(用于计算溶剂用量)
|
||||
event: 事件描述
|
||||
**kwargs: 其他可选参数
|
||||
|
||||
Returns:
|
||||
List[Dict[str, Any]]: 固体清洗操作的动作序列
|
||||
|
||||
Raises:
|
||||
ValueError: 当找不到必要的设备时抛出异常
|
||||
|
||||
Examples:
|
||||
wash_solid_protocol = generate_wash_solid_protocol(
|
||||
G, "reactor", "ethanol", 100.0, "waste_flask", 60.0, True, 300.0, 600.0, 3
|
||||
)
|
||||
"""
|
||||
|
||||
# 🔧 核心修改:从vessel参数中提取vessel_id
|
||||
vessel_id = extract_vessel_id(vessel)
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
|
||||
# 🔧 处理filtrate_vessel参数
|
||||
filtrate_vessel_id = extract_vessel_id(filtrate_vessel) if filtrate_vessel else ""
|
||||
|
||||
debug_print("🧼" * 20)
|
||||
debug_print("🚀 开始生成固体清洗协议(支持vessel字典和体积运算)✨")
|
||||
debug_print(f"📝 输入参数:")
|
||||
debug_print(f" 🥽 vessel: {vessel_display} (ID: {vessel_id})")
|
||||
debug_print(f" 🧪 solvent: {solvent}")
|
||||
debug_print(f" 💧 volume: {volume}")
|
||||
debug_print(f" 🗑️ filtrate_vessel: {filtrate_vessel_id}")
|
||||
debug_print(f" ⏰ time: {time}")
|
||||
debug_print(f" 🔄 repeats: {repeats}")
|
||||
debug_print("🧼" * 20)
|
||||
|
||||
# 🔧 新增:记录清洗前的容器状态
|
||||
debug_print("🔍 记录清洗前容器状态...")
|
||||
if isinstance(vessel, dict):
|
||||
original_volume = get_vessel_liquid_volume(vessel)
|
||||
debug_print(f"📊 清洗前液体体积: {original_volume:.2f}mL")
|
||||
else:
|
||||
original_volume = 0.0
|
||||
debug_print(f"📊 vessel为字符串格式,无法获取体积信息")
|
||||
|
||||
# 📋 快速验证
|
||||
if not vessel_id or vessel_id not in G.nodes(): # 🔧 使用 vessel_id
|
||||
debug_print("❌ 容器验证失败! 😱")
|
||||
raise ValueError("vessel 参数无效")
|
||||
|
||||
if not solvent:
|
||||
debug_print("❌ 溶剂不能为空! 😱")
|
||||
raise ValueError("solvent 参数不能为空")
|
||||
|
||||
debug_print("✅ 基础验证通过 🎯")
|
||||
|
||||
# 🔄 参数解析
|
||||
debug_print("📍 步骤1: 参数解析... ⚡")
|
||||
final_volume = parse_volume_input(volume, volume_spec, mass)
|
||||
final_time = parse_time_input(time)
|
||||
|
||||
# 重复次数处理(简化)
|
||||
if repeats_spec:
|
||||
spec_map = {'few': 2, 'several': 3, 'many': 4, 'thorough': 5}
|
||||
final_repeats = next((v for k, v in spec_map.items() if k in repeats_spec.lower()), repeats)
|
||||
else:
|
||||
final_repeats = max(1, min(repeats, 5)) # 限制1-5次
|
||||
|
||||
# 🕐 模拟时间优化
|
||||
debug_print(" ⏱️ 模拟时间优化...")
|
||||
original_time = final_time
|
||||
if final_time > 60.0:
|
||||
final_time = 60.0 # 限制最长60秒
|
||||
debug_print(f" 🎮 时间优化: {original_time}s → {final_time}s ⚡")
|
||||
|
||||
# 参数修正
|
||||
temp = max(25.0, min(temp, 80.0)) # 温度范围25-80°C
|
||||
stir_speed = max(0.0, min(stir_speed, 300.0)) if stir else 0.0 # 速度范围0-300
|
||||
|
||||
debug_print(f"🎯 最终参数: 体积={final_volume}mL, 时间={final_time}s, 重复={final_repeats}次")
|
||||
|
||||
# 🔍 查找设备
|
||||
debug_print("📍 步骤2: 查找设备... 🔍")
|
||||
try:
|
||||
solvent_source = find_solvent_source(G, solvent)
|
||||
actual_filtrate_vessel = find_filtrate_vessel(G, filtrate_vessel_id)
|
||||
debug_print(f"🎉 设备配置完成 ✨")
|
||||
debug_print(f" 🧪 溶剂源: {solvent_source}")
|
||||
debug_print(f" 🗑️ 滤液容器: {actual_filtrate_vessel}")
|
||||
except Exception as e:
|
||||
debug_print(f"❌ 设备查找失败: {str(e)} 😭")
|
||||
raise ValueError(f"设备查找失败: {str(e)}")
|
||||
|
||||
# 🚀 生成动作序列
|
||||
debug_print("📍 步骤3: 生成清洗动作... 🧼")
|
||||
action_sequence = []
|
||||
|
||||
# 验证容器是否存在
|
||||
if vessel not in G.nodes():
|
||||
raise ValueError(f"固体容器 {vessel} 不存在于图中")
|
||||
# 🔧 新增:体积变化跟踪变量
|
||||
current_volume = original_volume
|
||||
total_solvent_used = 0.0
|
||||
|
||||
if filtrate_vessel and filtrate_vessel not in G.nodes():
|
||||
raise ValueError(f"滤液容器 {filtrate_vessel} 不存在于图中")
|
||||
|
||||
# 查找转移泵设备(用于添加溶剂和转移滤液)
|
||||
pump_nodes = [node for node in G.nodes()
|
||||
if G.nodes[node].get('class') == 'virtual_transfer_pump']
|
||||
|
||||
if not pump_nodes:
|
||||
raise ValueError("没有找到可用的转移泵设备")
|
||||
|
||||
pump_id = pump_nodes[0]
|
||||
|
||||
# 查找加热设备(如果需要加热)
|
||||
heatchill_nodes = [node for node in G.nodes()
|
||||
if G.nodes[node].get('class') == 'virtual_heatchill']
|
||||
|
||||
heatchill_id = heatchill_nodes[0] if heatchill_nodes else None
|
||||
|
||||
# 查找搅拌设备(如果需要搅拌)
|
||||
stirrer_nodes = [node for node in G.nodes()
|
||||
if G.nodes[node].get('class') == 'virtual_stirrer']
|
||||
|
||||
stirrer_id = stirrer_nodes[0] if stirrer_nodes else None
|
||||
|
||||
# 查找过滤设备(用于分离固体和滤液)
|
||||
filter_nodes = [node for node in G.nodes()
|
||||
if G.nodes[node].get('class') == 'virtual_filter']
|
||||
|
||||
filter_id = filter_nodes[0] if filter_nodes else None
|
||||
|
||||
# 查找溶剂容器
|
||||
solvent_vessel = f"flask_{solvent}"
|
||||
if solvent_vessel not in G.nodes():
|
||||
# 如果没有找到特定溶剂容器,查找可用的源容器
|
||||
available_vessels = [node for node in G.nodes()
|
||||
if node.startswith('flask_') and
|
||||
G.nodes[node].get('type') == 'container']
|
||||
if available_vessels:
|
||||
solvent_vessel = available_vessels[0]
|
||||
else:
|
||||
raise ValueError(f"没有找到溶剂容器 {solvent}")
|
||||
|
||||
# 如果没有指定滤液容器,使用废液容器
|
||||
if not filtrate_vessel:
|
||||
waste_vessels = [node for node in G.nodes()
|
||||
if 'waste' in node.lower() and
|
||||
G.nodes[node].get('type') == 'container']
|
||||
filtrate_vessel = waste_vessels[0] if waste_vessels else "waste_flask"
|
||||
|
||||
# 重复清洗操作
|
||||
for repeat in range(repeats):
|
||||
repeat_num = repeat + 1
|
||||
for cycle in range(final_repeats):
|
||||
debug_print(f" 🔄 第{cycle+1}/{final_repeats}次清洗...")
|
||||
|
||||
# 步骤1:如果需要加热,先设置温度
|
||||
if temp > 25.0 and heatchill_id:
|
||||
action_sequence.append({
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_start",
|
||||
# 1. 转移溶剂
|
||||
try:
|
||||
from .pump_protocol import generate_pump_protocol_with_rinsing
|
||||
|
||||
debug_print(f" 💧 添加溶剂: {final_volume}mL {solvent}")
|
||||
transfer_actions = generate_pump_protocol_with_rinsing(
|
||||
G=G,
|
||||
from_vessel=solvent_source,
|
||||
to_vessel=vessel_id, # 🔧 使用 vessel_id
|
||||
volume=final_volume,
|
||||
amount="",
|
||||
time=0.0,
|
||||
viscous=False,
|
||||
rinsing_solvent="",
|
||||
rinsing_volume=0.0,
|
||||
rinsing_repeats=0,
|
||||
solid=False,
|
||||
flowrate=2.5,
|
||||
transfer_flowrate=0.5
|
||||
)
|
||||
|
||||
if transfer_actions:
|
||||
action_sequence.extend(transfer_actions)
|
||||
debug_print(f" ✅ 转移动作: {len(transfer_actions)}个 🚚")
|
||||
|
||||
# 🔧 新增:更新体积 - 添加溶剂后
|
||||
current_volume += final_volume
|
||||
total_solvent_used += final_volume
|
||||
|
||||
if isinstance(vessel, dict):
|
||||
update_vessel_volume(vessel, G, current_volume,
|
||||
f"第{cycle+1}次清洗添加{final_volume}mL溶剂后")
|
||||
|
||||
except Exception as e:
|
||||
debug_print(f" ❌ 转移失败: {str(e)} 😞")
|
||||
|
||||
# 2. 搅拌(如果需要)
|
||||
if stir and final_time > 0:
|
||||
debug_print(f" 🌪️ 搅拌: {final_time}s @ {stir_speed}RPM")
|
||||
stir_action = {
|
||||
"device_id": "stirrer_1",
|
||||
"action_name": "stir",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel,
|
||||
"temp": temp,
|
||||
"purpose": f"固体清洗 - 第 {repeat_num} 次"
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"time": str(time),
|
||||
"stir_time": final_time,
|
||||
"stir_speed": stir_speed,
|
||||
"settling_time": 10.0 # 🕐 缩短沉降时间
|
||||
}
|
||||
})
|
||||
|
||||
# 步骤2:添加清洗溶剂到固体容器
|
||||
action_sequence.append({
|
||||
"device_id": pump_id,
|
||||
"action_name": "transfer",
|
||||
"action_kwargs": {
|
||||
"from_vessel": solvent_vessel,
|
||||
"to_vessel": vessel,
|
||||
"volume": volume,
|
||||
"amount": f"清洗溶剂 {solvent} - 第 {repeat_num} 次",
|
||||
"time": 0.0,
|
||||
"viscous": False,
|
||||
"rinsing_solvent": "",
|
||||
"rinsing_volume": 0.0,
|
||||
"rinsing_repeats": 0,
|
||||
"solid": False
|
||||
}
|
||||
action_sequence.append(stir_action)
|
||||
debug_print(f" ✅ 搅拌动作: {final_time}s, {stir_speed}RPM 🌪️")
|
||||
|
||||
# 3. 过滤
|
||||
debug_print(f" 🌊 过滤到: {actual_filtrate_vessel}")
|
||||
filter_action = {
|
||||
"device_id": "filter_1",
|
||||
"action_name": "filter",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel_id, # 🔧 使用 vessel_id
|
||||
"filtrate_vessel": actual_filtrate_vessel,
|
||||
"temp": temp,
|
||||
"volume": final_volume
|
||||
}
|
||||
}
|
||||
action_sequence.append(filter_action)
|
||||
debug_print(f" ✅ 过滤动作: → {actual_filtrate_vessel} 🌊")
|
||||
|
||||
# 🔧 新增:更新体积 - 过滤后(液体被滤除)
|
||||
# 假设滤液完全被移除,固体残留在容器中
|
||||
filtered_volume = current_volume * 0.9 # 假设90%的液体被过滤掉
|
||||
current_volume = current_volume - filtered_volume
|
||||
|
||||
if isinstance(vessel, dict):
|
||||
update_vessel_volume(vessel, G, current_volume,
|
||||
f"第{cycle+1}次清洗过滤后")
|
||||
|
||||
# 4. 等待(缩短时间)
|
||||
wait_time = 5.0 # 🕐 缩短等待时间:10s → 5s
|
||||
action_sequence.append({
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {"time": wait_time}
|
||||
})
|
||||
|
||||
# 步骤3:如果需要搅拌,开始搅拌
|
||||
if stir and stir_speed > 0 and stirrer_id:
|
||||
if time > 0:
|
||||
# 定时搅拌
|
||||
action_sequence.append({
|
||||
"device_id": stirrer_id,
|
||||
"action_name": "stir",
|
||||
"action_kwargs": {
|
||||
"stir_time": time,
|
||||
"stir_speed": stir_speed,
|
||||
"settling_time": 30.0 # 搅拌后静置30秒
|
||||
}
|
||||
})
|
||||
else:
|
||||
# 开始搅拌(需要手动停止)
|
||||
action_sequence.append({
|
||||
"device_id": stirrer_id,
|
||||
"action_name": "start_stir",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel,
|
||||
"stir_speed": stir_speed,
|
||||
"purpose": f"固体清洗搅拌 - 第 {repeat_num} 次"
|
||||
}
|
||||
})
|
||||
|
||||
# 步骤4:如果指定了清洗时间但没有搅拌,等待清洗时间
|
||||
if time > 0 and (not stir or stir_speed == 0):
|
||||
# 这里可以添加等待操作,暂时跳过
|
||||
pass
|
||||
|
||||
# 步骤5:如果有搅拌且没有定时,停止搅拌
|
||||
if stir and stir_speed > 0 and time == 0 and stirrer_id:
|
||||
action_sequence.append({
|
||||
"device_id": stirrer_id,
|
||||
"action_name": "stop_stir",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel
|
||||
}
|
||||
})
|
||||
|
||||
# 步骤6:过滤分离固体和滤液
|
||||
if filter_id:
|
||||
action_sequence.append({
|
||||
"device_id": filter_id,
|
||||
"action_name": "filter_sample",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel,
|
||||
"filtrate_vessel": filtrate_vessel,
|
||||
"stir": False,
|
||||
"stir_speed": 0.0,
|
||||
"temp": temp,
|
||||
"continue_heatchill": temp > 25.0,
|
||||
"volume": volume
|
||||
}
|
||||
})
|
||||
else:
|
||||
# 没有专门的过滤设备,使用转移泵模拟过滤过程
|
||||
# 将滤液转移到滤液容器
|
||||
action_sequence.append({
|
||||
"device_id": pump_id,
|
||||
"action_name": "transfer",
|
||||
"action_kwargs": {
|
||||
"from_vessel": vessel,
|
||||
"to_vessel": filtrate_vessel,
|
||||
"volume": volume,
|
||||
"amount": f"转移滤液 - 第 {repeat_num} 次清洗",
|
||||
"time": 0.0,
|
||||
"viscous": False,
|
||||
"rinsing_solvent": "",
|
||||
"rinsing_volume": 0.0,
|
||||
"rinsing_repeats": 0,
|
||||
"solid": False
|
||||
}
|
||||
})
|
||||
|
||||
# 步骤7:如果加热了,停止加热(在最后一次清洗后)
|
||||
if temp > 25.0 and heatchill_id and repeat_num == repeats:
|
||||
action_sequence.append({
|
||||
"device_id": heatchill_id,
|
||||
"action_name": "heat_chill_stop",
|
||||
"action_kwargs": {
|
||||
"vessel": vessel
|
||||
}
|
||||
})
|
||||
debug_print(f" ✅ 等待: {wait_time}s ⏰")
|
||||
|
||||
return action_sequence
|
||||
# 🔧 新增:清洗完成后的最终状态报告
|
||||
if isinstance(vessel, dict):
|
||||
final_volume_vessel = get_vessel_liquid_volume(vessel)
|
||||
else:
|
||||
final_volume_vessel = current_volume
|
||||
|
||||
# 🎊 总结
|
||||
debug_print("🧼" * 20)
|
||||
debug_print(f"🎉 固体清洗协议生成完成! ✨")
|
||||
debug_print(f"📊 协议统计:")
|
||||
debug_print(f" 📋 总动作数: {len(action_sequence)} 个")
|
||||
debug_print(f" 🥽 清洗容器: {vessel_display}")
|
||||
debug_print(f" 🧪 使用溶剂: {solvent}")
|
||||
debug_print(f" 💧 单次体积: {final_volume}mL")
|
||||
debug_print(f" 🔄 清洗次数: {final_repeats}次")
|
||||
debug_print(f" 💧 总溶剂用量: {total_solvent_used:.2f}mL")
|
||||
debug_print(f"📊 体积变化统计:")
|
||||
debug_print(f" - 清洗前体积: {original_volume:.2f}mL")
|
||||
debug_print(f" - 清洗后体积: {final_volume_vessel:.2f}mL")
|
||||
debug_print(f" - 溶剂总用量: {total_solvent_used:.2f}mL")
|
||||
debug_print(f"⏱️ 预计总时间: {(final_time + 5) * final_repeats / 60:.1f} 分钟")
|
||||
debug_print("🧼" * 20)
|
||||
|
||||
return action_sequence
|
||||
|
||||
# 🔧 新增:便捷函数
|
||||
def wash_with_water(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
volume: Union[float, str] = "50",
|
||||
repeats: int = 2) -> List[Dict[str, Any]]:
|
||||
"""用水清洗固体"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"💧 水洗固体: {vessel_display} ({repeats} 次)")
|
||||
return generate_wash_solid_protocol(G, vessel, "water", volume=volume, repeats=repeats)
|
||||
|
||||
def wash_with_ethanol(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
volume: Union[float, str] = "30",
|
||||
repeats: int = 1) -> List[Dict[str, Any]]:
|
||||
"""用乙醇清洗固体"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🍺 乙醇洗固体: {vessel_display} ({repeats} 次)")
|
||||
return generate_wash_solid_protocol(G, vessel, "ethanol", volume=volume, repeats=repeats)
|
||||
|
||||
def wash_with_acetone(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
volume: Union[float, str] = "25",
|
||||
repeats: int = 1) -> List[Dict[str, Any]]:
|
||||
"""用丙酮清洗固体"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"💨 丙酮洗固体: {vessel_display} ({repeats} 次)")
|
||||
return generate_wash_solid_protocol(G, vessel, "acetone", volume=volume, repeats=repeats)
|
||||
|
||||
def wash_with_ether(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
volume: Union[float, str] = "40",
|
||||
repeats: int = 2) -> List[Dict[str, Any]]:
|
||||
"""用乙醚清洗固体"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🌬️ 乙醚洗固体: {vessel_display} ({repeats} 次)")
|
||||
return generate_wash_solid_protocol(G, vessel, "diethyl_ether", volume=volume, repeats=repeats)
|
||||
|
||||
def wash_with_cold_solvent(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
solvent: str, volume: Union[float, str] = "30",
|
||||
repeats: int = 1) -> List[Dict[str, Any]]:
|
||||
"""用冷溶剂清洗固体"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"❄️ 冷{solvent}洗固体: {vessel_display} ({repeats} 次)")
|
||||
return generate_wash_solid_protocol(G, vessel, solvent, volume=volume,
|
||||
temp=5.0, repeats=repeats)
|
||||
|
||||
def wash_with_hot_solvent(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
solvent: str, volume: Union[float, str] = "50",
|
||||
repeats: int = 1) -> List[Dict[str, Any]]:
|
||||
"""用热溶剂清洗固体"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🔥 热{solvent}洗固体: {vessel_display} ({repeats} 次)")
|
||||
return generate_wash_solid_protocol(G, vessel, solvent, volume=volume,
|
||||
temp=60.0, repeats=repeats)
|
||||
|
||||
def wash_with_stirring(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
solvent: str, volume: Union[float, str] = "50",
|
||||
stir_time: Union[str, float] = "5 min",
|
||||
repeats: int = 1) -> List[Dict[str, Any]]:
|
||||
"""带搅拌的溶剂清洗"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🌪️ 搅拌清洗: {vessel_display} with {solvent} ({repeats} 次)")
|
||||
return generate_wash_solid_protocol(G, vessel, solvent, volume=volume,
|
||||
stir=True, stir_speed=200.0,
|
||||
time=stir_time, repeats=repeats)
|
||||
|
||||
def thorough_wash(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
solvent: str, volume: Union[float, str] = "50") -> List[Dict[str, Any]]:
|
||||
"""彻底清洗(多次重复)"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"🔄 彻底清洗: {vessel_display} with {solvent} (5 次)")
|
||||
return generate_wash_solid_protocol(G, vessel, solvent, volume=volume, repeats=5)
|
||||
|
||||
def quick_rinse(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
solvent: str, volume: Union[float, str] = "20") -> List[Dict[str, Any]]:
|
||||
"""快速冲洗(单次,小体积)"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"⚡ 快速冲洗: {vessel_display} with {solvent}")
|
||||
return generate_wash_solid_protocol(G, vessel, solvent, volume=volume, repeats=1)
|
||||
|
||||
def sequential_wash(G: nx.DiGraph, vessel: Union[str, dict],
|
||||
solvents: list, volume: Union[float, str] = "40") -> List[Dict[str, Any]]:
|
||||
"""连续多溶剂清洗"""
|
||||
vessel_display = get_vessel_display_info(vessel)
|
||||
debug_print(f"📝 连续清洗: {vessel_display} with {' → '.join(solvents)}")
|
||||
|
||||
action_sequence = []
|
||||
for solvent in solvents:
|
||||
wash_actions = generate_wash_solid_protocol(G, vessel, solvent,
|
||||
volume=volume, repeats=1)
|
||||
action_sequence.extend(wash_actions)
|
||||
|
||||
return action_sequence
|
||||
|
||||
# 测试函数
|
||||
def test_wash_solid_protocol():
|
||||
"""测试固体清洗协议"""
|
||||
debug_print("🧪 === WASH SOLID PROTOCOL 测试 === ✨")
|
||||
|
||||
# 测试vessel参数处理
|
||||
debug_print("🔧 测试vessel参数处理...")
|
||||
|
||||
# 测试字典格式
|
||||
vessel_dict = {"id": "filter_flask_1", "name": "过滤瓶1",
|
||||
"data": {"liquid_volume": 25.0}}
|
||||
vessel_id = extract_vessel_id(vessel_dict)
|
||||
vessel_display = get_vessel_display_info(vessel_dict)
|
||||
volume = get_vessel_liquid_volume(vessel_dict)
|
||||
debug_print(f" 字典格式: {vessel_dict}")
|
||||
debug_print(f" → ID: {vessel_id}, 显示: {vessel_display}, 体积: {volume}mL")
|
||||
|
||||
# 测试字符串格式
|
||||
vessel_str = "filter_flask_2"
|
||||
vessel_id = extract_vessel_id(vessel_str)
|
||||
vessel_display = get_vessel_display_info(vessel_str)
|
||||
debug_print(f" 字符串格式: {vessel_str}")
|
||||
debug_print(f" → ID: {vessel_id}, 显示: {vessel_display}")
|
||||
|
||||
debug_print("✅ 测试完成 🎉")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_wash_solid_protocol()
|
||||
@@ -1,9 +1,12 @@
|
||||
import rtde_control
|
||||
import dashboard_client
|
||||
try:
|
||||
import rtde_control
|
||||
import dashboard_client
|
||||
import rtde_receive
|
||||
except ImportError as ex:
|
||||
print("Import Error, Please Install Packages in ur_arm_task.py First!", ex)
|
||||
import time
|
||||
import json
|
||||
from unilabos.devices.agv.robotiq_gripper import RobotiqGripper
|
||||
import rtde_receive
|
||||
from std_msgs.msg import Float64MultiArray
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@@ -234,71 +234,71 @@ class Laiyu:
|
||||
resp_reset = self.reset()
|
||||
return actual_mass_mg
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
'''
|
||||
样例:对单个粉筒进行称量
|
||||
'''
|
||||
|
||||
modbus = Laiyu(port="COM25")
|
||||
|
||||
mass_test = modbus.add_powder_tube(1, 'h12', 6.0)
|
||||
print(f"实际出料质量:{mass_test}mg")
|
||||
|
||||
|
||||
'''
|
||||
样例:对单个粉筒进行称量
|
||||
'''
|
||||
'''
|
||||
样例: 对一份excel文件记录的化合物进行称量
|
||||
'''
|
||||
|
||||
modbus = Laiyu(port="COM25")
|
||||
excel_file = r"C:\auto\laiyu\test1.xlsx"
|
||||
# 定义输出文件路径,用于记录实际加样多少
|
||||
output_file = r"C:\auto\laiyu\test_output.xlsx"
|
||||
|
||||
mass_test = modbus.add_powder_tube(1, 'h12', 6.0)
|
||||
print(f"实际出料质量:{mass_test}mg")
|
||||
# 定义物料名称和料筒位置关系
|
||||
compound_positions = {
|
||||
'XPhos': '1',
|
||||
'Cu(OTf)2': '2',
|
||||
'CuSO4': '3',
|
||||
'PPh3': '4',
|
||||
}
|
||||
|
||||
# read excel file
|
||||
# excel_file = r"C:\auto\laiyu\test.xlsx"
|
||||
df = pd.read_excel(excel_file, sheet_name='Sheet1')
|
||||
# 读取Excel文件中的数据
|
||||
# 遍历每一行数据
|
||||
for index, row in df.iterrows():
|
||||
# 获取物料名称和质量
|
||||
copper_name = row['copper']
|
||||
copper_mass = row['copper_mass']
|
||||
ligand_name = row['ligand']
|
||||
ligand_mass = row['ligand_mass']
|
||||
target_tube_position = row['position']
|
||||
# 获取物料位置 from compound_positions
|
||||
copper_position = compound_positions.get(copper_name)
|
||||
ligand_position = compound_positions.get(ligand_name)
|
||||
# 判断物料位置是否存在
|
||||
if copper_position is None:
|
||||
print(f"物料位置不存在:{copper_name}")
|
||||
continue
|
||||
if ligand_position is None:
|
||||
print(f"物料位置不存在:{ligand_name}")
|
||||
continue
|
||||
# 加铜
|
||||
copper_actual_mass = modbus.add_powder_tube(int(copper_position), target_tube_position, copper_mass)
|
||||
time.sleep(1)
|
||||
# 加配体
|
||||
ligand_actual_mass = modbus.add_powder_tube(int(ligand_position), target_tube_position, ligand_mass)
|
||||
time.sleep(1)
|
||||
# 保存至df
|
||||
df.at[index, 'copper_actual_mass'] = copper_actual_mass
|
||||
df.at[index, 'ligand_actual_mass'] = ligand_actual_mass
|
||||
|
||||
'''
|
||||
样例: 对一份excel文件记录的化合物进行称量
|
||||
'''
|
||||
# 保存修改后的数据到新的Excel文件
|
||||
df.to_excel(output_file, index=False)
|
||||
print(f"已保存到文件:{output_file}")
|
||||
|
||||
excel_file = r"C:\auto\laiyu\test1.xlsx"
|
||||
# 定义输出文件路径,用于记录实际加样多少
|
||||
output_file = r"C:\auto\laiyu\test_output.xlsx"
|
||||
|
||||
# 定义物料名称和料筒位置关系
|
||||
compound_positions = {
|
||||
'XPhos': '1',
|
||||
'Cu(OTf)2': '2',
|
||||
'CuSO4': '3',
|
||||
'PPh3': '4',
|
||||
}
|
||||
|
||||
# read excel file
|
||||
# excel_file = r"C:\auto\laiyu\test.xlsx"
|
||||
df = pd.read_excel(excel_file, sheet_name='Sheet1')
|
||||
# 读取Excel文件中的数据
|
||||
# 遍历每一行数据
|
||||
for index, row in df.iterrows():
|
||||
# 获取物料名称和质量
|
||||
copper_name = row['copper']
|
||||
copper_mass = row['copper_mass']
|
||||
ligand_name = row['ligand']
|
||||
ligand_mass = row['ligand_mass']
|
||||
target_tube_position = row['position']
|
||||
# 获取物料位置 from compound_positions
|
||||
copper_position = compound_positions.get(copper_name)
|
||||
ligand_position = compound_positions.get(ligand_name)
|
||||
# 判断物料位置是否存在
|
||||
if copper_position is None:
|
||||
print(f"物料位置不存在:{copper_name}")
|
||||
continue
|
||||
if ligand_position is None:
|
||||
print(f"物料位置不存在:{ligand_name}")
|
||||
continue
|
||||
# 加铜
|
||||
copper_actual_mass = modbus.add_powder_tube(int(copper_position), target_tube_position, copper_mass)
|
||||
time.sleep(1)
|
||||
# 加配体
|
||||
ligand_actual_mass = modbus.add_powder_tube(int(ligand_position), target_tube_position, ligand_mass)
|
||||
time.sleep(1)
|
||||
# 保存至df
|
||||
df.at[index, 'copper_actual_mass'] = copper_actual_mass
|
||||
df.at[index, 'ligand_actual_mass'] = ligand_actual_mass
|
||||
|
||||
# 保存修改后的数据到新的Excel文件
|
||||
df.to_excel(output_file, index=False)
|
||||
print(f"已保存到文件:{output_file}")
|
||||
|
||||
# 关闭串口
|
||||
modbus.ser.close()
|
||||
print("串口已关闭")
|
||||
# 关闭串口
|
||||
modbus.ser.close()
|
||||
print("串口已关闭")
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
13533
unilabos/devices/liquid_handling/prcxi/deck.json
Normal file
13533
unilabos/devices/liquid_handling/prcxi/deck.json
Normal file
File diff suppressed because it is too large
Load Diff
1401
unilabos/devices/liquid_handling/prcxi/prcxi.py
Normal file
1401
unilabos/devices/liquid_handling/prcxi/prcxi.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,11 @@ import sys
|
||||
import io
|
||||
# sys.path.insert(0, r'C:\kui\winprep_cli\winprep_c_Uni-lab\x64\Debug')
|
||||
|
||||
import winprep_c
|
||||
try:
|
||||
import winprep_c
|
||||
except ImportError as e:
|
||||
print("Error importing winprep_c:", e)
|
||||
print("Please ensure that the winprep_c module is correctly installed and accessible.")
|
||||
from queue import Queue
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ except Exception as e:
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..")))
|
||||
from unilabos.utils.pywinauto_util import connect_application, get_process_pid_by_name, get_ui_path_with_window_specification, print_wrapper_identifiers
|
||||
from unilabos.device_comms.universal_driver import UniversalDriver, SingleRunningExecutor
|
||||
from unilabos.devices.template_driver import universal_driver as ud
|
||||
from unilabos.device_comms import universal_driver as ud
|
||||
print(f"使用文件DEBUG运行: {e}")
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
||||
import time
|
||||
|
||||
class RamanObj:
|
||||
def __init__(self, port_laser,port_ccd, baudrate_laser=9600, baudrate_ccd=921600):
|
||||
def __init__(self, port_laser, port_ccd, baudrate_laser=9600, baudrate_ccd=921600):
|
||||
self.port_laser = port_laser
|
||||
self.port_ccd = port_ccd
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class MoveitInterface:
|
||||
tf_buffer: Buffer
|
||||
tf_listener: TransformListener
|
||||
|
||||
def __init__(self, moveit_type, joint_poses, rotation=None, device_config=None):
|
||||
def __init__(self, moveit_type, joint_poses, rotation=None, device_config=None, **kwargs):
|
||||
self.device_config = device_config
|
||||
self.rotation = rotation
|
||||
self.data_config = json.load(
|
||||
|
||||
@@ -3,7 +3,7 @@ import logging
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
class VirtualColumn:
|
||||
"""Virtual column device for RunColumn protocol"""
|
||||
"""Virtual column device for RunColumn protocol 🏛️"""
|
||||
|
||||
def __init__(self, device_id: str = None, config: Dict[str, Any] = None, **kwargs):
|
||||
# 处理可能的不同调用方式
|
||||
@@ -25,45 +25,77 @@ class VirtualColumn:
|
||||
self._column_length = self.config.get('column_length') or kwargs.get('column_length', 25.0)
|
||||
self._column_diameter = self.config.get('column_diameter') or kwargs.get('column_diameter', 2.0)
|
||||
|
||||
print(f"=== VirtualColumn {self.device_id} created with max_flow_rate={self._max_flow_rate}, length={self._column_length}cm ===")
|
||||
print(f"🏛️ === 虚拟色谱柱 {self.device_id} 已创建 === ✨")
|
||||
print(f"📏 柱参数: 流速={self._max_flow_rate}mL/min | 长度={self._column_length}cm | 直径={self._column_diameter}cm 🔬")
|
||||
|
||||
async def initialize(self) -> bool:
|
||||
"""Initialize virtual column"""
|
||||
self.logger.info(f"Initializing virtual column {self.device_id}")
|
||||
"""Initialize virtual column 🚀"""
|
||||
self.logger.info(f"🔧 初始化虚拟色谱柱 {self.device_id} ✨")
|
||||
|
||||
self.data.update({
|
||||
"status": "Idle",
|
||||
"column_state": "Ready",
|
||||
"column_state": "Ready",
|
||||
"current_flow_rate": 0.0,
|
||||
"max_flow_rate": self._max_flow_rate,
|
||||
"column_length": self._column_length,
|
||||
"column_diameter": self._column_diameter,
|
||||
"processed_volume": 0.0,
|
||||
"progress": 0.0,
|
||||
"current_status": "Ready"
|
||||
"current_status": "Ready for separation"
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 色谱柱 {self.device_id} 初始化完成 🏛️")
|
||||
self.logger.info(f"📊 设备规格: 最大流速 {self._max_flow_rate}mL/min | 柱长 {self._column_length}cm 📏")
|
||||
return True
|
||||
|
||||
async def cleanup(self) -> bool:
|
||||
"""Cleanup virtual column"""
|
||||
self.logger.info(f"Cleaning up virtual column {self.device_id}")
|
||||
"""Cleanup virtual column 🧹"""
|
||||
self.logger.info(f"🧹 清理虚拟色谱柱 {self.device_id} 🔚")
|
||||
|
||||
self.data.update({
|
||||
"status": "Offline",
|
||||
"column_state": "Offline",
|
||||
"current_status": "System offline"
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 色谱柱 {self.device_id} 清理完成 💤")
|
||||
return True
|
||||
|
||||
async def run_column(self, from_vessel: str, to_vessel: str, column: str) -> bool:
|
||||
"""Execute column chromatography run - matches RunColumn action"""
|
||||
self.logger.info(f"Running column separation: {from_vessel} -> {to_vessel} using {column}")
|
||||
async def run_column(self, from_vessel: str, to_vessel: str, column: str, **kwargs) -> bool:
|
||||
"""Execute column chromatography run - matches RunColumn action 🏛️"""
|
||||
|
||||
# 提取额外参数
|
||||
rf = kwargs.get('rf', '0.3')
|
||||
solvent1 = kwargs.get('solvent1', 'ethyl_acetate')
|
||||
solvent2 = kwargs.get('solvent2', 'hexane')
|
||||
ratio = kwargs.get('ratio', '30:70')
|
||||
|
||||
self.logger.info(f"🏛️ 开始柱层析分离: {from_vessel} → {to_vessel} 🚰")
|
||||
self.logger.info(f" 🧪 使用色谱柱: {column}")
|
||||
self.logger.info(f" 🎯 Rf值: {rf}")
|
||||
self.logger.info(f" 🧪 洗脱溶剂: {solvent1}:{solvent2} ({ratio}) 💧")
|
||||
|
||||
# 更新设备状态
|
||||
self.data.update({
|
||||
"status": "Running",
|
||||
"column_state": "Separating",
|
||||
"current_status": "Column separation in progress",
|
||||
"current_status": "🏛️ Column separation in progress",
|
||||
"progress": 0.0,
|
||||
"processed_volume": 0.0
|
||||
"processed_volume": 0.0,
|
||||
"current_from_vessel": from_vessel,
|
||||
"current_to_vessel": to_vessel,
|
||||
"current_column": column,
|
||||
"current_rf": rf,
|
||||
"current_solvents": f"{solvent1}:{solvent2} ({ratio})"
|
||||
})
|
||||
|
||||
# 模拟柱层析分离过程
|
||||
# 假设处理时间基于流速和柱子长度
|
||||
separation_time = (self._column_length * 2) / self._max_flow_rate # 简化计算
|
||||
base_time = (self._column_length * 2) / self._max_flow_rate # 简化计算
|
||||
separation_time = max(base_time, 20.0) # 最少20秒
|
||||
|
||||
self.logger.info(f"⏱️ 预计分离时间: {separation_time:.1f}秒 ⌛")
|
||||
self.logger.info(f"📏 柱参数: 长度 {self._column_length}cm | 流速 {self._max_flow_rate}mL/min 🌊")
|
||||
|
||||
steps = 20 # 分20个步骤模拟分离过程
|
||||
step_time = separation_time / steps
|
||||
@@ -74,34 +106,65 @@ class VirtualColumn:
|
||||
progress = (i + 1) / steps * 100
|
||||
volume_processed = (i + 1) * 5.0 # 假设每步处理5mL
|
||||
|
||||
# 不同阶段的状态描述
|
||||
if progress <= 25:
|
||||
phase = "🌊 样品上柱阶段"
|
||||
phase_emoji = "📥"
|
||||
elif progress <= 50:
|
||||
phase = "🧪 洗脱开始"
|
||||
phase_emoji = "💧"
|
||||
elif progress <= 75:
|
||||
phase = "⚗️ 成分分离中"
|
||||
phase_emoji = "🔄"
|
||||
else:
|
||||
phase = "🎯 收集产物"
|
||||
phase_emoji = "📤"
|
||||
|
||||
# 更新状态
|
||||
status_msg = f"{phase_emoji} {phase}: {progress:.1f}% | 💧 已处理: {volume_processed:.1f}mL"
|
||||
|
||||
self.data.update({
|
||||
"progress": progress,
|
||||
"processed_volume": volume_processed,
|
||||
"current_status": f"Column separation: {progress:.1f}% - Processing {volume_processed:.1f}mL"
|
||||
"current_status": status_msg,
|
||||
"current_phase": phase
|
||||
})
|
||||
|
||||
self.logger.info(f"Column separation progress: {progress:.1f}%")
|
||||
# 进度日志(每25%打印一次)
|
||||
if progress >= 25 and (i + 1) % 5 == 0: # 每5步(25%)打印一次
|
||||
self.logger.info(f"📊 分离进度: {progress:.0f}% | {phase} | 💧 {volume_processed:.1f}mL 完成 ✨")
|
||||
|
||||
# 分离完成
|
||||
final_status = f"✅ 柱层析分离完成: {from_vessel} → {to_vessel} | 💧 共处理 {volume_processed:.1f}mL"
|
||||
|
||||
self.data.update({
|
||||
"status": "Idle",
|
||||
"column_state": "Ready",
|
||||
"current_status": "Column separation completed",
|
||||
"progress": 100.0
|
||||
"current_status": final_status,
|
||||
"progress": 100.0,
|
||||
"final_volume": volume_processed
|
||||
})
|
||||
|
||||
self.logger.info(f"Column separation completed: {from_vessel} -> {to_vessel}")
|
||||
self.logger.info(f"🎉 柱层析分离完成! ✨")
|
||||
self.logger.info(f"📊 分离结果:")
|
||||
self.logger.info(f" 🥽 源容器: {from_vessel}")
|
||||
self.logger.info(f" 🥽 目标容器: {to_vessel}")
|
||||
self.logger.info(f" 🏛️ 使用色谱柱: {column}")
|
||||
self.logger.info(f" 💧 处理体积: {volume_processed:.1f}mL")
|
||||
self.logger.info(f" 🧪 洗脱条件: {solvent1}:{solvent2} ({ratio})")
|
||||
self.logger.info(f" 🎯 Rf值: {rf}")
|
||||
self.logger.info(f" ⏱️ 总耗时: {separation_time:.1f}秒 🏁")
|
||||
|
||||
return True
|
||||
|
||||
# 状态属性
|
||||
@property
|
||||
def status(self) -> str:
|
||||
return self.data.get("status", "Unknown")
|
||||
return self.data.get("status", "❓ Unknown")
|
||||
|
||||
@property
|
||||
def column_state(self) -> str:
|
||||
return self.data.get("column_state", "Unknown")
|
||||
return self.data.get("column_state", "❓ Unknown")
|
||||
|
||||
@property
|
||||
def current_flow_rate(self) -> float:
|
||||
@@ -129,4 +192,12 @@ class VirtualColumn:
|
||||
|
||||
@property
|
||||
def current_status(self) -> str:
|
||||
return self.data.get("current_status", "Ready")
|
||||
return self.data.get("current_status", "📋 Ready")
|
||||
|
||||
@property
|
||||
def current_phase(self) -> str:
|
||||
return self.data.get("current_phase", "🏠 待机中")
|
||||
|
||||
@property
|
||||
def final_volume(self) -> float:
|
||||
return self.data.get("final_volume", 0.0)
|
||||
@@ -5,7 +5,7 @@ from typing import Dict, Any, Optional
|
||||
|
||||
|
||||
class VirtualFilter:
|
||||
"""Virtual filter device - 完全按照 Filter.action 规范"""
|
||||
"""Virtual filter device - 完全按照 Filter.action 规范 🌊"""
|
||||
|
||||
def __init__(self, device_id: Optional[str] = None, config: Optional[Dict[str, Any]] = None, **kwargs):
|
||||
if device_id is None and 'id' in kwargs:
|
||||
@@ -31,8 +31,8 @@ class VirtualFilter:
|
||||
setattr(self, key, value)
|
||||
|
||||
async def initialize(self) -> bool:
|
||||
"""Initialize virtual filter"""
|
||||
self.logger.info(f"Initializing virtual filter {self.device_id}")
|
||||
"""Initialize virtual filter 🚀"""
|
||||
self.logger.info(f"🔧 初始化虚拟过滤器 {self.device_id} ✨")
|
||||
|
||||
# 按照 Filter.action 的 feedback 字段初始化
|
||||
self.data.update({
|
||||
@@ -43,17 +43,21 @@ class VirtualFilter:
|
||||
"current_status": "Ready for filtration", # Filter.action feedback
|
||||
"message": "Ready for filtration"
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 过滤器 {self.device_id} 初始化完成 🌊")
|
||||
return True
|
||||
|
||||
async def cleanup(self) -> bool:
|
||||
"""Cleanup virtual filter"""
|
||||
self.logger.info(f"Cleaning up virtual filter {self.device_id}")
|
||||
"""Cleanup virtual filter 🧹"""
|
||||
self.logger.info(f"🧹 清理虚拟过滤器 {self.device_id} 🔚")
|
||||
|
||||
self.data.update({
|
||||
"status": "Offline",
|
||||
"current_status": "System offline",
|
||||
"message": "System offline"
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 过滤器 {self.device_id} 清理完成 💤")
|
||||
return True
|
||||
|
||||
async def filter(
|
||||
@@ -66,64 +70,82 @@ class VirtualFilter:
|
||||
continue_heatchill: bool = False,
|
||||
volume: float = 0.0
|
||||
) -> bool:
|
||||
"""Execute filter action - 完全按照 Filter.action 参数"""
|
||||
self.logger.info(f"Filter: vessel={vessel}, filtrate_vessel={filtrate_vessel}")
|
||||
self.logger.info(f" stir={stir}, stir_speed={stir_speed}, temp={temp}")
|
||||
self.logger.info(f" continue_heatchill={continue_heatchill}, volume={volume}")
|
||||
"""Execute filter action - 完全按照 Filter.action 参数 🌊"""
|
||||
|
||||
# 🔧 新增:温度自动调整
|
||||
original_temp = temp
|
||||
if temp == 0.0:
|
||||
temp = 25.0 # 0度自动设置为室温
|
||||
self.logger.info(f"🌡️ 温度自动调整: {original_temp}°C → {temp}°C (室温) 🏠")
|
||||
elif temp < 4.0:
|
||||
temp = 4.0 # 小于4度自动设置为4度
|
||||
self.logger.info(f"🌡️ 温度自动调整: {original_temp}°C → {temp}°C (最低温度) ❄️")
|
||||
|
||||
self.logger.info(f"🌊 开始过滤操作: {vessel} → {filtrate_vessel} 🚰")
|
||||
self.logger.info(f" 🌪️ 搅拌: {stir} ({stir_speed} RPM)")
|
||||
self.logger.info(f" 🌡️ 温度: {temp}°C")
|
||||
self.logger.info(f" 💧 体积: {volume}mL")
|
||||
self.logger.info(f" 🔥 保持加热: {continue_heatchill}")
|
||||
|
||||
# 验证参数
|
||||
if temp > self._max_temp or temp < 4.0:
|
||||
error_msg = f"温度 {temp}°C 超出范围 (4-{self._max_temp}°C)"
|
||||
self.logger.error(error_msg)
|
||||
error_msg = f"🌡️ 温度 {temp}°C 超出范围 (4-{self._max_temp}°C) ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"current_status": f"Error: {error_msg}",
|
||||
"status": f"Error: 温度超出范围 ⚠️",
|
||||
"current_status": f"Error: 温度超出范围 ⚠️",
|
||||
"message": error_msg
|
||||
})
|
||||
return False
|
||||
|
||||
if stir and stir_speed > self._max_stir_speed:
|
||||
error_msg = f"搅拌速度 {stir_speed} RPM 超出范围 (0-{self._max_stir_speed} RPM)"
|
||||
self.logger.error(error_msg)
|
||||
error_msg = f"🌪️ 搅拌速度 {stir_speed} RPM 超出范围 (0-{self._max_stir_speed} RPM) ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"current_status": f"Error: {error_msg}",
|
||||
"status": f"Error: 搅拌速度超出范围 ⚠️",
|
||||
"current_status": f"Error: 搅拌速度超出范围 ⚠️",
|
||||
"message": error_msg
|
||||
})
|
||||
return False
|
||||
|
||||
if volume > self._max_volume:
|
||||
error_msg = f"过滤体积 {volume} mL 超出范围 (0-{self._max_volume} mL)"
|
||||
self.logger.error(error_msg)
|
||||
error_msg = f"💧 过滤体积 {volume} mL 超出范围 (0-{self._max_volume} mL) ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"current_status": f"Error: {error_msg}",
|
||||
"status": f"Error: 体积超出范围 ⚠️",
|
||||
"current_status": f"Error: 体积超出范围 ⚠️",
|
||||
"message": error_msg
|
||||
})
|
||||
return False
|
||||
|
||||
# 开始过滤
|
||||
filter_volume = volume if volume > 0 else 50.0
|
||||
self.logger.info(f"🚀 开始过滤 {filter_volume}mL 液体 💧")
|
||||
|
||||
self.data.update({
|
||||
"status": f"过滤中: {vessel}",
|
||||
"status": f"🌊 过滤中: {vessel}",
|
||||
"current_temp": temp,
|
||||
"filtered_volume": 0.0,
|
||||
"progress": 0.0,
|
||||
"current_status": f"Filtering {vessel} → {filtrate_vessel}",
|
||||
"message": f"Starting filtration: {vessel} → {filtrate_vessel}"
|
||||
"current_status": f"🌊 Filtering {vessel} → {filtrate_vessel}",
|
||||
"message": f"🚀 Starting filtration: {vessel} → {filtrate_vessel}"
|
||||
})
|
||||
|
||||
try:
|
||||
# 过滤过程 - 实时更新进度
|
||||
start_time = time_module.time()
|
||||
|
||||
# 根据体积和搅拌估算过滤时间
|
||||
base_time = filter_volume / 5.0 # 5mL/s 基础速度
|
||||
if stir:
|
||||
base_time *= 0.8 # 搅拌加速过滤
|
||||
self.logger.info(f"🌪️ 搅拌加速过滤,预计时间减少20% ⚡")
|
||||
if temp > 50.0:
|
||||
base_time *= 0.7 # 高温加速过滤
|
||||
self.logger.info(f"🔥 高温加速过滤,预计时间减少30% ⚡")
|
||||
|
||||
filter_time = max(base_time, 10.0) # 最少10秒
|
||||
self.logger.info(f"⏱️ 预计过滤时间: {filter_time:.1f}秒 ⌛")
|
||||
|
||||
while True:
|
||||
current_time = time_module.time()
|
||||
@@ -133,20 +155,24 @@ class VirtualFilter:
|
||||
current_filtered = (progress / 100.0) * filter_volume
|
||||
|
||||
# 更新状态 - 按照 Filter.action feedback 字段
|
||||
status_msg = f"过滤中: {vessel}"
|
||||
status_msg = f"🌊 过滤中: {vessel}"
|
||||
if stir:
|
||||
status_msg += f" | 搅拌: {stir_speed} RPM"
|
||||
status_msg += f" | {temp}°C | {progress:.1f}% | 已过滤: {current_filtered:.1f}mL"
|
||||
status_msg += f" | 🌪️ 搅拌: {stir_speed} RPM"
|
||||
status_msg += f" | 🌡️ {temp}°C | 📊 {progress:.1f}% | 💧 已过滤: {current_filtered:.1f}mL"
|
||||
|
||||
self.data.update({
|
||||
"progress": progress, # Filter.action feedback
|
||||
"current_temp": temp, # Filter.action feedback
|
||||
"filtered_volume": current_filtered, # Filter.action feedback
|
||||
"current_status": f"Filtering: {progress:.1f}% complete", # Filter.action feedback
|
||||
"current_status": f"🌊 Filtering: {progress:.1f}% complete", # Filter.action feedback
|
||||
"status": status_msg,
|
||||
"message": f"Filtering: {progress:.1f}% complete, {current_filtered:.1f}mL filtered"
|
||||
"message": f"🌊 Filtering: {progress:.1f}% complete, {current_filtered:.1f}mL filtered"
|
||||
})
|
||||
|
||||
# 进度日志(每25%打印一次)
|
||||
if progress >= 25 and progress % 25 < 1:
|
||||
self.logger.info(f"📊 过滤进度: {progress:.0f}% | 💧 {current_filtered:.1f}mL 完成 ✨")
|
||||
|
||||
if remaining <= 0:
|
||||
break
|
||||
|
||||
@@ -154,54 +180,57 @@ class VirtualFilter:
|
||||
|
||||
# 过滤完成
|
||||
final_temp = temp if continue_heatchill else 25.0
|
||||
final_status = f"过滤完成: {vessel} | {filter_volume}mL → {filtrate_vessel}"
|
||||
final_status = f"✅ 过滤完成: {vessel} | 💧 {filter_volume}mL → {filtrate_vessel}"
|
||||
if continue_heatchill:
|
||||
final_status += " | 继续加热搅拌"
|
||||
final_status += " | 🔥 继续加热搅拌"
|
||||
self.logger.info(f"🔥 继续保持加热搅拌状态 🌪️")
|
||||
|
||||
self.data.update({
|
||||
"status": final_status,
|
||||
"progress": 100.0, # Filter.action feedback
|
||||
"current_temp": final_temp, # Filter.action feedback
|
||||
"filtered_volume": filter_volume, # Filter.action feedback
|
||||
"current_status": f"Filtration completed: {filter_volume}mL", # Filter.action feedback
|
||||
"message": f"Filtration completed: {filter_volume}mL filtered from {vessel}"
|
||||
"current_status": f"✅ Filtration completed: {filter_volume}mL", # Filter.action feedback
|
||||
"message": f"✅ Filtration completed: {filter_volume}mL filtered from {vessel}"
|
||||
})
|
||||
|
||||
self.logger.info(f"Filtration completed: {filter_volume}mL from {vessel} to {filtrate_vessel}")
|
||||
self.logger.info(f"🎉 过滤完成! 💧 {filter_volume}mL 从 {vessel} 过滤到 {filtrate_vessel} ✨")
|
||||
self.logger.info(f"📊 最终状态: 温度 {final_temp}°C | 进度 100% | 体积 {filter_volume}mL 🏁")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error during filtration: {str(e)}")
|
||||
error_msg = f"过滤过程中发生错误: {str(e)} 💥"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"过滤错误: {str(e)}",
|
||||
"current_status": f"Filtration failed: {str(e)}",
|
||||
"message": f"Filtration failed: {str(e)}"
|
||||
"status": f"❌ 过滤错误: {str(e)}",
|
||||
"current_status": f"❌ Filtration failed: {str(e)}",
|
||||
"message": f"❌ Filtration failed: {str(e)}"
|
||||
})
|
||||
return False
|
||||
|
||||
# === 核心状态属性 - 按照 Filter.action feedback 字段 ===
|
||||
@property
|
||||
def status(self) -> str:
|
||||
return self.data.get("status", "Unknown")
|
||||
return self.data.get("status", "❓ Unknown")
|
||||
|
||||
@property
|
||||
def progress(self) -> float:
|
||||
"""Filter.action feedback 字段"""
|
||||
"""Filter.action feedback 字段 📊"""
|
||||
return self.data.get("progress", 0.0)
|
||||
|
||||
@property
|
||||
def current_temp(self) -> float:
|
||||
"""Filter.action feedback 字段"""
|
||||
"""Filter.action feedback 字段 🌡️"""
|
||||
return self.data.get("current_temp", 25.0)
|
||||
|
||||
@property
|
||||
def filtered_volume(self) -> float:
|
||||
"""Filter.action feedback 字段"""
|
||||
"""Filter.action feedback 字段 💧"""
|
||||
return self.data.get("filtered_volume", 0.0)
|
||||
|
||||
@property
|
||||
def current_status(self) -> str:
|
||||
"""Filter.action feedback 字段"""
|
||||
"""Filter.action feedback 字段 📋"""
|
||||
return self.data.get("current_status", "")
|
||||
|
||||
@property
|
||||
|
||||
@@ -4,7 +4,7 @@ import time as time_module # 重命名time模块,避免与参数冲突
|
||||
from typing import Dict, Any
|
||||
|
||||
class VirtualHeatChill:
|
||||
"""Virtual heat chill device for HeatChillProtocol testing"""
|
||||
"""Virtual heat chill device for HeatChillProtocol testing 🌡️"""
|
||||
|
||||
def __init__(self, device_id: str = None, config: Dict[str, Any] = None, **kwargs):
|
||||
# 处理可能的不同调用方式
|
||||
@@ -31,94 +31,149 @@ class VirtualHeatChill:
|
||||
for key, value in kwargs.items():
|
||||
if key not in skip_keys and not hasattr(self, key):
|
||||
setattr(self, key, value)
|
||||
|
||||
print(f"🌡️ === 虚拟温控设备 {self.device_id} 已创建 === ✨")
|
||||
print(f"🔥 温度范围: {self._min_temp}°C ~ {self._max_temp}°C | 🌪️ 最大搅拌: {self._max_stir_speed} RPM")
|
||||
|
||||
async def initialize(self) -> bool:
|
||||
"""Initialize virtual heat chill"""
|
||||
self.logger.info(f"Initializing virtual heat chill {self.device_id}")
|
||||
"""Initialize virtual heat chill 🚀"""
|
||||
self.logger.info(f"🔧 初始化虚拟温控设备 {self.device_id} ✨")
|
||||
|
||||
# 初始化状态信息
|
||||
self.data.update({
|
||||
"status": "Idle",
|
||||
"status": "🏠 待机中",
|
||||
"operation_mode": "Idle",
|
||||
"is_stirring": False,
|
||||
"stir_speed": 0.0,
|
||||
"remaining_time": 0.0,
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 温控设备 {self.device_id} 初始化完成 🌡️")
|
||||
self.logger.info(f"📊 设备规格: 温度范围 {self._min_temp}°C ~ {self._max_temp}°C | 搅拌范围 0 ~ {self._max_stir_speed} RPM")
|
||||
return True
|
||||
|
||||
async def cleanup(self) -> bool:
|
||||
"""Cleanup virtual heat chill"""
|
||||
self.logger.info(f"Cleaning up virtual heat chill {self.device_id}")
|
||||
"""Cleanup virtual heat chill 🧹"""
|
||||
self.logger.info(f"🧹 清理虚拟温控设备 {self.device_id} 🔚")
|
||||
|
||||
self.data.update({
|
||||
"status": "Offline",
|
||||
"status": "💤 离线",
|
||||
"operation_mode": "Offline",
|
||||
"is_stirring": False,
|
||||
"stir_speed": 0.0,
|
||||
"remaining_time": 0.0
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 温控设备 {self.device_id} 清理完成 💤")
|
||||
return True
|
||||
|
||||
async def heat_chill(self, vessel: str, temp: float, time: float, stir: bool,
|
||||
async def heat_chill(self, vessel: str, temp: float, time, stir: bool,
|
||||
stir_speed: float, purpose: str) -> bool:
|
||||
"""Execute heat chill action - 按实际时间运行,实时更新剩余时间"""
|
||||
self.logger.info(f"HeatChill: vessel={vessel}, temp={temp}°C, time={time}s, stir={stir}, stir_speed={stir_speed}")
|
||||
"""Execute heat chill action - 🔧 修复:确保参数类型正确"""
|
||||
|
||||
# 验证参数
|
||||
if temp > self._max_temp or temp < self._min_temp:
|
||||
error_msg = f"温度 {temp}°C 超出范围 ({self._min_temp}°C - {self._max_temp}°C)"
|
||||
self.logger.error(error_msg)
|
||||
# 🔧 关键修复:确保所有参数类型正确
|
||||
try:
|
||||
temp = float(temp)
|
||||
time_value = float(time) # 强制转换为浮点数
|
||||
stir_speed = float(stir_speed)
|
||||
stir = bool(stir)
|
||||
vessel = str(vessel)
|
||||
purpose = str(purpose)
|
||||
except (ValueError, TypeError) as e:
|
||||
error_msg = f"参数类型转换错误: temp={temp}({type(temp)}), time={time}({type(time)}), error={str(e)}"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"status": f"❌ 错误: {error_msg}",
|
||||
"operation_mode": "Error"
|
||||
})
|
||||
return False
|
||||
|
||||
# 确定温度操作emoji
|
||||
if temp > 25.0:
|
||||
temp_emoji = "🔥"
|
||||
operation_mode = "Heating"
|
||||
status_action = "加热"
|
||||
elif temp < 25.0:
|
||||
temp_emoji = "❄️"
|
||||
operation_mode = "Cooling"
|
||||
status_action = "冷却"
|
||||
else:
|
||||
temp_emoji = "🌡️"
|
||||
operation_mode = "Maintaining"
|
||||
status_action = "保温"
|
||||
|
||||
self.logger.info(f"🌡️ 开始温控操作: {vessel} → {temp}°C {temp_emoji}")
|
||||
self.logger.info(f" 🥽 容器: {vessel}")
|
||||
self.logger.info(f" 🎯 目标温度: {temp}°C {temp_emoji}")
|
||||
self.logger.info(f" ⏰ 持续时间: {time_value}s")
|
||||
self.logger.info(f" 🌪️ 搅拌: {stir} ({stir_speed} RPM)")
|
||||
self.logger.info(f" 📝 目的: {purpose}")
|
||||
|
||||
# 验证参数范围
|
||||
if temp > self._max_temp or temp < self._min_temp:
|
||||
error_msg = f"🌡️ 温度 {temp}°C 超出范围 ({self._min_temp}°C - {self._max_temp}°C) ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"❌ 错误: 温度超出范围 ⚠️",
|
||||
"operation_mode": "Error"
|
||||
})
|
||||
return False
|
||||
|
||||
if stir and stir_speed > self._max_stir_speed:
|
||||
error_msg = f"搅拌速度 {stir_speed} RPM 超出最大值 {self._max_stir_speed} RPM"
|
||||
self.logger.error(error_msg)
|
||||
error_msg = f"🌪️ 搅拌速度 {stir_speed} RPM 超出最大值 {self._max_stir_speed} RPM ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"status": f"❌ 错误: 搅拌速度超出范围 ⚠️",
|
||||
"operation_mode": "Error"
|
||||
})
|
||||
return False
|
||||
|
||||
# 确定操作模式
|
||||
if temp > 25.0:
|
||||
operation_mode = "Heating"
|
||||
status_action = "加热"
|
||||
elif temp < 25.0:
|
||||
operation_mode = "Cooling"
|
||||
status_action = "冷却"
|
||||
else:
|
||||
operation_mode = "Maintaining"
|
||||
status_action = "保温"
|
||||
if time_value <= 0:
|
||||
error_msg = f"⏰ 时间 {time_value}s 必须大于0 ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"❌ 错误: 时间参数无效 ⚠️",
|
||||
"operation_mode": "Error"
|
||||
})
|
||||
return False
|
||||
|
||||
# **修复**: 使用重命名的time模块
|
||||
# 🔧 修复:使用转换后的时间值
|
||||
start_time = time_module.time()
|
||||
total_time = time
|
||||
total_time = time_value # 使用转换后的浮点数
|
||||
|
||||
self.logger.info(f"🚀 开始{status_action}程序! 预计用时 {total_time:.1f}秒 ⏱️")
|
||||
|
||||
# 开始操作
|
||||
stir_info = f" | 搅拌: {stir_speed} RPM" if stir else ""
|
||||
stir_info = f" | 🌪️ 搅拌: {stir_speed} RPM" if stir else ""
|
||||
|
||||
self.data.update({
|
||||
"status": f"运行中: {status_action} {vessel} 至 {temp}°C | 剩余: {total_time:.0f}s{stir_info}",
|
||||
"status": f"{temp_emoji} 运行中: {status_action} {vessel} 至 {temp}°C | ⏰ 剩余: {total_time:.0f}s{stir_info}",
|
||||
"operation_mode": operation_mode,
|
||||
"is_stirring": stir,
|
||||
"stir_speed": stir_speed if stir else 0.0,
|
||||
"remaining_time": total_time,
|
||||
})
|
||||
|
||||
# **修复**: 在等待过程中每秒更新剩余时间
|
||||
# 在等待过程中每秒更新剩余时间
|
||||
last_logged_time = 0
|
||||
while True:
|
||||
current_time = time_module.time() # 使用重命名的time模块
|
||||
current_time = time_module.time()
|
||||
elapsed = current_time - start_time
|
||||
remaining = max(0, total_time - elapsed)
|
||||
progress = (elapsed / total_time) * 100 if total_time > 0 else 100
|
||||
|
||||
# 更新剩余时间和状态
|
||||
self.data.update({
|
||||
"remaining_time": remaining,
|
||||
"status": f"运行中: {status_action} {vessel} 至 {temp}°C | 剩余: {remaining:.0f}s{stir_info}"
|
||||
"status": f"{temp_emoji} 运行中: {status_action} {vessel} 至 {temp}°C | ⏰ 剩余: {remaining:.0f}s{stir_info}",
|
||||
"progress": progress
|
||||
})
|
||||
|
||||
# 进度日志(每25%打印一次)
|
||||
if progress >= 25 and int(progress) % 25 == 0 and int(progress) != last_logged_time:
|
||||
self.logger.info(f"📊 {status_action}进度: {progress:.0f}% | ⏰ 剩余: {remaining:.0f}s | {temp_emoji} 目标: {temp}°C ✨")
|
||||
last_logged_time = int(progress)
|
||||
|
||||
# 如果时间到了,退出循环
|
||||
if remaining <= 0:
|
||||
break
|
||||
@@ -127,71 +182,114 @@ class VirtualHeatChill:
|
||||
await asyncio.sleep(1.0)
|
||||
|
||||
# 操作完成
|
||||
final_stir_info = f" | 搅拌: {stir_speed} RPM" if stir else ""
|
||||
final_stir_info = f" | 🌪️ 搅拌: {stir_speed} RPM" if stir else ""
|
||||
|
||||
self.data.update({
|
||||
"status": f"完成: {vessel} 已达到 {temp}°C | 用时: {total_time:.0f}s{final_stir_info}",
|
||||
"status": f"✅ 完成: {vessel} 已达到 {temp}°C {temp_emoji} | ⏱️ 用时: {total_time:.0f}s{final_stir_info}",
|
||||
"operation_mode": "Completed",
|
||||
"remaining_time": 0.0,
|
||||
"is_stirring": False,
|
||||
"stir_speed": 0.0
|
||||
"stir_speed": 0.0,
|
||||
"progress": 100.0
|
||||
})
|
||||
|
||||
self.logger.info(f"HeatChill completed for vessel {vessel} at {temp}°C after {total_time}s")
|
||||
self.logger.info(f"🎉 温控操作完成! ✨")
|
||||
self.logger.info(f"📊 操作结果:")
|
||||
self.logger.info(f" 🥽 容器: {vessel}")
|
||||
self.logger.info(f" 🌡️ 达到温度: {temp}°C {temp_emoji}")
|
||||
self.logger.info(f" ⏱️ 总用时: {total_time:.0f}s")
|
||||
if stir:
|
||||
self.logger.info(f" 🌪️ 搅拌速度: {stir_speed} RPM")
|
||||
self.logger.info(f" 📝 操作目的: {purpose} 🏁")
|
||||
|
||||
return True
|
||||
|
||||
async def heat_chill_start(self, vessel: str, temp: float, purpose: str) -> bool:
|
||||
"""Start continuous heat chill"""
|
||||
self.logger.info(f"HeatChillStart: vessel={vessel}, temp={temp}°C")
|
||||
"""Start continuous heat chill 🔄"""
|
||||
|
||||
# 验证参数
|
||||
if temp > self._max_temp or temp < self._min_temp:
|
||||
error_msg = f"温度 {temp}°C 超出范围 ({self._min_temp}°C - {self._max_temp}°C)"
|
||||
self.logger.error(error_msg)
|
||||
# 🔧 添加类型转换
|
||||
try:
|
||||
temp = float(temp)
|
||||
vessel = str(vessel)
|
||||
purpose = str(purpose)
|
||||
except (ValueError, TypeError) as e:
|
||||
error_msg = f"参数类型转换错误: {str(e)}"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"status": f"❌ 错误: {error_msg}",
|
||||
"operation_mode": "Error"
|
||||
})
|
||||
return False
|
||||
|
||||
# 确定操作模式
|
||||
# 确定温度操作emoji
|
||||
if temp > 25.0:
|
||||
temp_emoji = "🔥"
|
||||
operation_mode = "Heating"
|
||||
status_action = "持续加热"
|
||||
elif temp < 25.0:
|
||||
temp_emoji = "❄️"
|
||||
operation_mode = "Cooling"
|
||||
status_action = "持续冷却"
|
||||
else:
|
||||
temp_emoji = "🌡️"
|
||||
operation_mode = "Maintaining"
|
||||
status_action = "恒温保持"
|
||||
|
||||
self.logger.info(f"🔄 启动持续温控: {vessel} → {temp}°C {temp_emoji}")
|
||||
self.logger.info(f" 🥽 容器: {vessel}")
|
||||
self.logger.info(f" 🎯 目标温度: {temp}°C {temp_emoji}")
|
||||
self.logger.info(f" 🔄 模式: {status_action}")
|
||||
self.logger.info(f" 📝 目的: {purpose}")
|
||||
|
||||
# 验证参数
|
||||
if temp > self._max_temp or temp < self._min_temp:
|
||||
error_msg = f"🌡️ 温度 {temp}°C 超出范围 ({self._min_temp}°C - {self._max_temp}°C) ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"❌ 错误: 温度超出范围 ⚠️",
|
||||
"operation_mode": "Error"
|
||||
})
|
||||
return False
|
||||
|
||||
self.data.update({
|
||||
"status": f"启动: {status_action} {vessel} 至 {temp}°C | 持续运行",
|
||||
"status": f"🔄 启动: {status_action} {vessel} 至 {temp}°C {temp_emoji} | ♾️ 持续运行",
|
||||
"operation_mode": operation_mode,
|
||||
"is_stirring": False,
|
||||
"stir_speed": 0.0,
|
||||
"remaining_time": -1.0, # -1 表示持续运行
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 持续温控已启动! {temp_emoji} {status_action}模式 🚀")
|
||||
return True
|
||||
|
||||
async def heat_chill_stop(self, vessel: str) -> bool:
|
||||
"""Stop heat chill"""
|
||||
self.logger.info(f"HeatChillStop: vessel={vessel}")
|
||||
"""Stop heat chill 🛑"""
|
||||
|
||||
# 🔧 添加类型转换
|
||||
try:
|
||||
vessel = str(vessel)
|
||||
except (ValueError, TypeError) as e:
|
||||
error_msg = f"参数类型转换错误: {str(e)}"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
return False
|
||||
|
||||
self.logger.info(f"🛑 停止温控: {vessel}")
|
||||
|
||||
self.data.update({
|
||||
"status": f"已停止: {vessel} 温控停止",
|
||||
"status": f"🛑 已停止: {vessel} 温控停止",
|
||||
"operation_mode": "Stopped",
|
||||
"is_stirring": False,
|
||||
"stir_speed": 0.0,
|
||||
"remaining_time": 0.0,
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 温控设备已停止 {vessel} 的温度控制 🏁")
|
||||
return True
|
||||
|
||||
# 状态属性
|
||||
@property
|
||||
def status(self) -> str:
|
||||
return self.data.get("status", "Idle")
|
||||
return self.data.get("status", "🏠 待机中")
|
||||
|
||||
@property
|
||||
def operation_mode(self) -> str:
|
||||
@@ -207,4 +305,20 @@ class VirtualHeatChill:
|
||||
|
||||
@property
|
||||
def remaining_time(self) -> float:
|
||||
return self.data.get("remaining_time", 0.0)
|
||||
return self.data.get("remaining_time", 0.0)
|
||||
|
||||
@property
|
||||
def progress(self) -> float:
|
||||
return self.data.get("progress", 0.0)
|
||||
|
||||
@property
|
||||
def max_temp(self) -> float:
|
||||
return self._max_temp
|
||||
|
||||
@property
|
||||
def min_temp(self) -> float:
|
||||
return self._min_temp
|
||||
|
||||
@property
|
||||
def max_stir_speed(self) -> float:
|
||||
return self._max_stir_speed
|
||||
@@ -1,16 +1,20 @@
|
||||
import time
|
||||
import logging
|
||||
from typing import Union, Dict, Optional
|
||||
|
||||
|
||||
class VirtualMultiwayValve:
|
||||
"""
|
||||
虚拟九通阀门 - 0号位连接transfer pump,1-8号位连接其他设备
|
||||
虚拟九通阀门 - 0号位连接transfer pump,1-8号位连接其他设备 🔄
|
||||
"""
|
||||
def __init__(self, port: str = "VIRTUAL", positions: int = 8):
|
||||
self.port = port
|
||||
self.max_positions = positions # 1-8号位
|
||||
self.total_positions = positions + 1 # 0-8号位,共9个位置
|
||||
|
||||
# 添加日志记录器
|
||||
self.logger = logging.getLogger(f"VirtualMultiwayValve.{port}")
|
||||
|
||||
# 状态属性
|
||||
self._status = "Idle"
|
||||
self._valve_state = "Ready"
|
||||
@@ -29,6 +33,10 @@ class VirtualMultiwayValve:
|
||||
7: "port_7", # 7号位
|
||||
8: "port_8" # 8号位
|
||||
}
|
||||
|
||||
print(f"🔄 === 虚拟多通阀门已创建 === ✨")
|
||||
print(f"🎯 端口: {port} | 📊 位置范围: 0-{self.max_positions} | 🏠 初始位置: 0 (transfer_pump)")
|
||||
self.logger.info(f"🔧 多通阀门初始化: 端口={port}, 最大位置={self.max_positions}")
|
||||
|
||||
@property
|
||||
def status(self) -> str:
|
||||
@@ -47,31 +55,67 @@ class VirtualMultiwayValve:
|
||||
return self._target_position
|
||||
|
||||
def get_current_position(self) -> int:
|
||||
"""获取当前阀门位置"""
|
||||
"""获取当前阀门位置 📍"""
|
||||
return self._current_position
|
||||
|
||||
def get_current_port(self) -> str:
|
||||
"""获取当前连接的端口名称"""
|
||||
"""获取当前连接的端口名称 🔌"""
|
||||
return self.position_map.get(self._current_position, "unknown")
|
||||
|
||||
def set_position(self, command: Union[int, str]):
|
||||
"""
|
||||
设置阀门位置 - 支持0-8位置
|
||||
设置阀门位置 - 支持0-8位置 🎯
|
||||
|
||||
Args:
|
||||
command: 目标位置 (0-8) 或位置字符串
|
||||
0: transfer pump位置
|
||||
1-8: 其他设备位置
|
||||
'default': 默认位置(0号位)
|
||||
"""
|
||||
try:
|
||||
# 如果是字符串形式的位置,先转换为数字
|
||||
# 🔧 处理特殊字符串命令
|
||||
if isinstance(command, str):
|
||||
pos = int(command)
|
||||
command_lower = command.lower().strip()
|
||||
|
||||
# 处理特殊命令
|
||||
if command_lower in ['default', 'pump', 'transfer_pump', 'home']:
|
||||
pos = 0 # 默认位置为0号位(transfer pump)
|
||||
self.logger.info(f"🔧 特殊命令 '{command}' 映射到位置 {pos}")
|
||||
elif command_lower in ['open']:
|
||||
pos = 0 # open命令也映射到0号位
|
||||
self.logger.info(f"🔧 OPEN命令映射到位置 {pos}")
|
||||
elif command_lower in ['close', 'closed']:
|
||||
# 关闭命令保持当前位置
|
||||
pos = self._current_position
|
||||
self.logger.info(f"🔧 CLOSE命令保持当前位置 {pos}")
|
||||
else:
|
||||
# 尝试转换为数字
|
||||
try:
|
||||
pos = int(command)
|
||||
except ValueError:
|
||||
error_msg = f"无法识别的命令: '{command}'"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
raise ValueError(error_msg)
|
||||
else:
|
||||
pos = int(command)
|
||||
|
||||
if pos < 0 or pos > self.max_positions:
|
||||
raise ValueError(f"Position must be between 0 and {self.max_positions}")
|
||||
error_msg = f"位置必须在 0-{self.max_positions} 范围内"
|
||||
self.logger.error(f"❌ {error_msg}: 请求位置={pos}")
|
||||
raise ValueError(error_msg)
|
||||
|
||||
# 获取位置描述emoji
|
||||
if pos == 0:
|
||||
pos_emoji = "🚰"
|
||||
pos_desc = "泵位置"
|
||||
else:
|
||||
pos_emoji = "🔌"
|
||||
pos_desc = f"端口{pos}"
|
||||
|
||||
old_position = self._current_position
|
||||
old_port = self.get_current_port()
|
||||
|
||||
self.logger.info(f"🔄 阀门切换: {old_position}({old_port}) → {pos}({self.position_map.get(pos, 'unknown')}) {pos_emoji}")
|
||||
|
||||
self._status = "Busy"
|
||||
self._valve_state = "Moving"
|
||||
@@ -79,104 +123,139 @@ class VirtualMultiwayValve:
|
||||
|
||||
# 模拟阀门切换时间
|
||||
switch_time = abs(self._current_position - pos) * 0.5 # 每个位置0.5秒
|
||||
time.sleep(switch_time)
|
||||
|
||||
if switch_time > 0:
|
||||
self.logger.info(f"⏱️ 阀门移动中... 预计用时: {switch_time:.1f}秒 🔄")
|
||||
time.sleep(switch_time)
|
||||
|
||||
self._current_position = pos
|
||||
self._status = "Idle"
|
||||
self._valve_state = "Ready"
|
||||
|
||||
current_port = self.get_current_port()
|
||||
return f"Position set to {pos} ({current_port})"
|
||||
success_msg = f"✅ 阀门已切换到位置 {pos} ({current_port}) {pos_emoji}"
|
||||
|
||||
self.logger.info(success_msg)
|
||||
return success_msg
|
||||
|
||||
except ValueError as e:
|
||||
error_msg = f"❌ 阀门切换失败: {str(e)}"
|
||||
self._status = "Error"
|
||||
self._valve_state = "Error"
|
||||
return f"Error: {str(e)}"
|
||||
self.logger.error(error_msg)
|
||||
return error_msg
|
||||
|
||||
def set_to_pump_position(self):
|
||||
"""切换到transfer pump位置(0号位)"""
|
||||
"""切换到transfer pump位置(0号位)🚰"""
|
||||
self.logger.info(f"🚰 切换到泵位置...")
|
||||
return self.set_position(0)
|
||||
|
||||
def set_to_port(self, port_number: int):
|
||||
"""
|
||||
切换到指定端口位置
|
||||
切换到指定端口位置 🔌
|
||||
|
||||
Args:
|
||||
port_number: 端口号 (1-8)
|
||||
"""
|
||||
if port_number < 1 or port_number > self.max_positions:
|
||||
raise ValueError(f"Port number must be between 1 and {self.max_positions}")
|
||||
error_msg = f"端口号必须在 1-{self.max_positions} 范围内"
|
||||
self.logger.error(f"❌ {error_msg}: 请求端口={port_number}")
|
||||
raise ValueError(error_msg)
|
||||
|
||||
self.logger.info(f"🔌 切换到端口 {port_number}...")
|
||||
return self.set_position(port_number)
|
||||
|
||||
def open(self):
|
||||
"""打开阀门 - 设置到transfer pump位置(0号位)"""
|
||||
"""打开阀门 - 设置到transfer pump位置(0号位)🔓"""
|
||||
self.logger.info(f"🔓 打开阀门,设置到泵位置...")
|
||||
return self.set_to_pump_position()
|
||||
|
||||
def close(self):
|
||||
"""关闭阀门 - 对于多通阀门,设置到一个"关闭"状态"""
|
||||
"""关闭阀门 - 对于多通阀门,设置到一个"关闭"状态 🔒"""
|
||||
self.logger.info(f"🔒 关闭阀门...")
|
||||
|
||||
self._status = "Busy"
|
||||
self._valve_state = "Closing"
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
# 可以选择保持当前位置或设置特殊关闭状态
|
||||
self._status = "Idle"
|
||||
self._valve_state = "Closed"
|
||||
|
||||
return f"Valve closed at position {self._current_position}"
|
||||
close_msg = f"🔒 阀门已关闭,保持在位置 {self._current_position} ({self.get_current_port()})"
|
||||
self.logger.info(close_msg)
|
||||
return close_msg
|
||||
|
||||
def get_valve_position(self) -> int:
|
||||
"""获取阀门位置 - 兼容性方法"""
|
||||
"""获取阀门位置 - 兼容性方法 📍"""
|
||||
return self._current_position
|
||||
|
||||
def is_at_position(self, position: int) -> bool:
|
||||
"""检查是否在指定位置"""
|
||||
return self._current_position == position
|
||||
"""检查是否在指定位置 🎯"""
|
||||
result = self._current_position == position
|
||||
# 删除debug日志:self.logger.debug(f"🎯 位置检查: 当前={self._current_position}, 目标={position}, 匹配={result}")
|
||||
return result
|
||||
|
||||
def is_at_pump_position(self) -> bool:
|
||||
"""检查是否在transfer pump位置"""
|
||||
return self._current_position == 0
|
||||
"""检查是否在transfer pump位置 🚰"""
|
||||
result = self._current_position == 0
|
||||
# 删除debug日志:pump_status = "是" if result else "否"
|
||||
# 删除debug日志:self.logger.debug(f"🚰 泵位置检查: {pump_status} (当前位置: {self._current_position})")
|
||||
return result
|
||||
|
||||
def is_at_port(self, port_number: int) -> bool:
|
||||
"""检查是否在指定端口位置"""
|
||||
return self._current_position == port_number
|
||||
"""检查是否在指定端口位置 🔌"""
|
||||
result = self._current_position == port_number
|
||||
# 删除debug日志:port_status = "是" if result else "否"
|
||||
# 删除debug日志:self.logger.debug(f"🔌 端口{port_number}检查: {port_status} (当前位置: {self._current_position})")
|
||||
return result
|
||||
|
||||
def get_available_positions(self) -> list:
|
||||
"""获取可用位置列表"""
|
||||
return list(range(0, self.max_positions + 1))
|
||||
"""获取可用位置列表 📋"""
|
||||
positions = list(range(0, self.max_positions + 1))
|
||||
# 删除debug日志:self.logger.debug(f"📋 可用位置: {positions}")
|
||||
return positions
|
||||
|
||||
def get_available_ports(self) -> Dict[int, str]:
|
||||
"""获取可用端口映射"""
|
||||
"""获取可用端口映射 🗺️"""
|
||||
# 删除debug日志:self.logger.debug(f"🗺️ 端口映射: {self.position_map}")
|
||||
return self.position_map.copy()
|
||||
|
||||
def reset(self):
|
||||
"""重置阀门到transfer pump位置(0号位)"""
|
||||
"""重置阀门到transfer pump位置(0号位)🔄"""
|
||||
self.logger.info(f"🔄 重置阀门到泵位置...")
|
||||
return self.set_position(0)
|
||||
|
||||
def switch_between_pump_and_port(self, port_number: int):
|
||||
"""
|
||||
在transfer pump位置和指定端口之间切换
|
||||
在transfer pump位置和指定端口之间切换 🔄
|
||||
|
||||
Args:
|
||||
port_number: 目标端口号 (1-8)
|
||||
"""
|
||||
if self._current_position == 0:
|
||||
# 当前在pump位置,切换到指定端口
|
||||
self.logger.info(f"🔄 从泵位置切换到端口 {port_number}...")
|
||||
return self.set_to_port(port_number)
|
||||
else:
|
||||
# 当前在某个端口,切换到pump位置
|
||||
self.logger.info(f"🔄 从端口 {self._current_position} 切换到泵位置...")
|
||||
return self.set_to_pump_position()
|
||||
|
||||
def get_flow_path(self) -> str:
|
||||
"""获取当前流路路径描述"""
|
||||
"""获取当前流路路径描述 🌊"""
|
||||
current_port = self.get_current_port()
|
||||
if self._current_position == 0:
|
||||
return f"Transfer pump connected (position {self._current_position})"
|
||||
flow_path = f"🚰 转移泵已连接 (位置 {self._current_position})"
|
||||
else:
|
||||
return f"Port {self._current_position} connected ({current_port})"
|
||||
flow_path = f"🔌 端口 {self._current_position} 已连接 ({current_port})"
|
||||
|
||||
# 删除debug日志:self.logger.debug(f"🌊 当前流路: {flow_path}")
|
||||
return flow_path
|
||||
|
||||
def get_info(self) -> dict:
|
||||
"""获取阀门详细信息"""
|
||||
return {
|
||||
"""获取阀门详细信息 📊"""
|
||||
info = {
|
||||
"port": self.port,
|
||||
"max_positions": self.max_positions,
|
||||
"total_positions": self.total_positions,
|
||||
@@ -188,18 +267,25 @@ class VirtualMultiwayValve:
|
||||
"flow_path": self.get_flow_path(),
|
||||
"position_map": self.position_map
|
||||
}
|
||||
|
||||
# 删除debug日志:self.logger.debug(f"📊 阀门信息: 位置={self._current_position}, 状态={self._status}, 端口={self.get_current_port()}")
|
||||
return info
|
||||
|
||||
def __str__(self):
|
||||
return f"VirtualMultiwayValve(Position: {self._current_position}/{self.max_positions}, Port: {self.get_current_port()}, Status: {self._status})"
|
||||
current_port = self.get_current_port()
|
||||
status_emoji = "✅" if self._status == "Idle" else "🔄" if self._status == "Busy" else "❌"
|
||||
|
||||
return f"🔄 VirtualMultiwayValve({status_emoji} 位置: {self._current_position}/{self.max_positions}, 端口: {current_port}, 状态: {self._status})"
|
||||
|
||||
def set_valve_position(self, command: Union[int, str]):
|
||||
"""
|
||||
设置阀门位置 - 兼容pump_protocol调用
|
||||
设置阀门位置 - 兼容pump_protocol调用 🎯
|
||||
这是set_position的别名方法,用于兼容pump_protocol.py
|
||||
|
||||
Args:
|
||||
command: 目标位置 (0-8) 或位置字符串
|
||||
"""
|
||||
# 删除debug日志:self.logger.debug(f"🎯 兼容性调用: set_valve_position({command})")
|
||||
return self.set_position(command)
|
||||
|
||||
|
||||
@@ -207,25 +293,35 @@ class VirtualMultiwayValve:
|
||||
if __name__ == "__main__":
|
||||
valve = VirtualMultiwayValve()
|
||||
|
||||
print("=== 虚拟九通阀门测试 ===")
|
||||
print(f"初始状态: {valve}")
|
||||
print(f"当前流路: {valve.get_flow_path()}")
|
||||
print("🔄 === 虚拟九通阀门测试 === ✨")
|
||||
print(f"🏠 初始状态: {valve}")
|
||||
print(f"🌊 当前流路: {valve.get_flow_path()}")
|
||||
|
||||
# 切换到试剂瓶1(1号位)
|
||||
print(f"\n切换到1号位: {valve.set_position(1)}")
|
||||
print(f"当前状态: {valve}")
|
||||
print(f"\n🔌 切换到1号位: {valve.set_position(1)}")
|
||||
print(f"📍 当前状态: {valve}")
|
||||
|
||||
# 切换到transfer pump位置(0号位)
|
||||
print(f"\n切换到pump位置: {valve.set_to_pump_position()}")
|
||||
print(f"当前状态: {valve}")
|
||||
print(f"\n🚰 切换到pump位置: {valve.set_to_pump_position()}")
|
||||
print(f"📍 当前状态: {valve}")
|
||||
|
||||
# 切换到试剂瓶2(2号位)
|
||||
print(f"\n切换到2号位: {valve.set_to_port(2)}")
|
||||
print(f"当前状态: {valve}")
|
||||
print(f"\n🔌 切换到2号位: {valve.set_to_port(2)}")
|
||||
print(f"📍 当前状态: {valve}")
|
||||
|
||||
# 显示所有可用位置
|
||||
print(f"\n可用位置: {valve.get_available_positions()}")
|
||||
print(f"端口映射: {valve.get_available_ports()}")
|
||||
print(f"\n📋 可用位置: {valve.get_available_positions()}")
|
||||
print(f"🗺️ 端口映射: {valve.get_available_ports()}")
|
||||
|
||||
# 获取详细信息
|
||||
print(f"\n详细信息: {valve.get_info()}")
|
||||
print(f"\n📊 详细信息: {valve.get_info()}")
|
||||
|
||||
# 测试切换功能
|
||||
print(f"\n🔄 智能切换测试:")
|
||||
print(f"当前位置: {valve._current_position}")
|
||||
print(f"切换结果: {valve.switch_between_pump_and_port(3)}")
|
||||
print(f"新位置: {valve._current_position}")
|
||||
|
||||
# 重置测试
|
||||
print(f"\n🔄 重置测试: {valve.reset()}")
|
||||
print(f"📍 重置后状态: {valve}")
|
||||
@@ -3,9 +3,12 @@ import logging
|
||||
import time as time_module
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
def debug_print(message):
|
||||
"""调试输出 🔍"""
|
||||
print(f"🌪️ [ROTAVAP] {message}", flush=True)
|
||||
|
||||
class VirtualRotavap:
|
||||
"""Virtual rotary evaporator device - 简化版,只保留核心功能"""
|
||||
"""Virtual rotary evaporator device - 简化版,只保留核心功能 🌪️"""
|
||||
|
||||
def __init__(self, device_id: Optional[str] = None, config: Optional[Dict[str, Any]] = None, **kwargs):
|
||||
# 处理可能的不同调用方式
|
||||
@@ -32,13 +35,16 @@ class VirtualRotavap:
|
||||
if key not in skip_keys and not hasattr(self, key):
|
||||
setattr(self, key, value)
|
||||
|
||||
print(f"🌪️ === 虚拟旋转蒸发仪 {self.device_id} 已创建 === ✨")
|
||||
print(f"🔥 温度范围: 10°C ~ {self._max_temp}°C | 🌀 转速范围: 10 ~ {self._max_rotation_speed} RPM")
|
||||
|
||||
async def initialize(self) -> bool:
|
||||
"""Initialize virtual rotary evaporator"""
|
||||
self.logger.info(f"Initializing virtual rotary evaporator {self.device_id}")
|
||||
"""Initialize virtual rotary evaporator 🚀"""
|
||||
self.logger.info(f"🔧 初始化虚拟旋转蒸发仪 {self.device_id} ✨")
|
||||
|
||||
# 只保留核心状态
|
||||
self.data.update({
|
||||
"status": "Idle",
|
||||
"status": "🏠 待机中",
|
||||
"rotavap_state": "Ready", # Ready, Evaporating, Completed, Error
|
||||
"current_temp": 25.0,
|
||||
"target_temp": 25.0,
|
||||
@@ -47,22 +53,27 @@ class VirtualRotavap:
|
||||
"evaporated_volume": 0.0,
|
||||
"progress": 0.0,
|
||||
"remaining_time": 0.0,
|
||||
"message": "Ready for evaporation"
|
||||
"message": "🌪️ Ready for evaporation"
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 旋转蒸发仪 {self.device_id} 初始化完成 🌪️")
|
||||
self.logger.info(f"📊 设备规格: 温度范围 10°C ~ {self._max_temp}°C | 转速范围 10 ~ {self._max_rotation_speed} RPM")
|
||||
return True
|
||||
|
||||
async def cleanup(self) -> bool:
|
||||
"""Cleanup virtual rotary evaporator"""
|
||||
self.logger.info(f"Cleaning up virtual rotary evaporator {self.device_id}")
|
||||
"""Cleanup virtual rotary evaporator 🧹"""
|
||||
self.logger.info(f"🧹 清理虚拟旋转蒸发仪 {self.device_id} 🔚")
|
||||
|
||||
self.data.update({
|
||||
"status": "Offline",
|
||||
"status": "💤 离线",
|
||||
"rotavap_state": "Offline",
|
||||
"current_temp": 25.0,
|
||||
"rotation_speed": 0.0,
|
||||
"vacuum_pressure": 1.0,
|
||||
"message": "System offline"
|
||||
"message": "💤 System offline"
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 旋转蒸发仪 {self.device_id} 清理完成 💤")
|
||||
return True
|
||||
|
||||
async def evaporate(
|
||||
@@ -70,46 +81,102 @@ class VirtualRotavap:
|
||||
vessel: str,
|
||||
pressure: float = 0.1,
|
||||
temp: float = 60.0,
|
||||
time: float = 1800.0, # 30分钟默认
|
||||
stir_speed: float = 100.0
|
||||
time: float = 180.0,
|
||||
stir_speed: float = 100.0,
|
||||
solvent: str = "",
|
||||
**kwargs
|
||||
) -> bool:
|
||||
"""Execute evaporate action - 简化的蒸发流程"""
|
||||
self.logger.info(f"Evaporate: vessel={vessel}, pressure={pressure} bar, temp={temp}°C, time={time}s, rotation={stir_speed} RPM")
|
||||
|
||||
"""Execute evaporate action - 简化版 🌪️"""
|
||||
|
||||
# 🔧 新增:确保time参数是数值类型
|
||||
if isinstance(time, str):
|
||||
try:
|
||||
time = float(time)
|
||||
except ValueError:
|
||||
self.logger.error(f"❌ 无法转换时间参数 '{time}' 为数值,使用默认值180.0秒")
|
||||
time = 180.0
|
||||
elif not isinstance(time, (int, float)):
|
||||
self.logger.error(f"❌ 时间参数类型无效: {type(time)},使用默认值180.0秒")
|
||||
time = 180.0
|
||||
|
||||
# 确保time是float类型
|
||||
time = float(time)
|
||||
|
||||
# 🔧 简化处理:如果vessel就是设备自己,直接操作
|
||||
if vessel == self.device_id:
|
||||
debug_print(f"🎯 在设备 {self.device_id} 上直接执行蒸发操作")
|
||||
actual_vessel = self.device_id
|
||||
else:
|
||||
actual_vessel = vessel
|
||||
|
||||
# 参数预处理
|
||||
if solvent:
|
||||
self.logger.info(f"🧪 识别到溶剂: {solvent}")
|
||||
# 根据溶剂调整参数
|
||||
solvent_lower = solvent.lower()
|
||||
if any(s in solvent_lower for s in ['water', 'aqueous']):
|
||||
temp = max(temp, 80.0)
|
||||
pressure = max(pressure, 0.2)
|
||||
self.logger.info(f"💧 水系溶剂:调整参数 → 温度 {temp}°C, 压力 {pressure} bar")
|
||||
elif any(s in solvent_lower for s in ['ethanol', 'methanol', 'acetone']):
|
||||
temp = min(temp, 50.0)
|
||||
pressure = min(pressure, 0.05)
|
||||
self.logger.info(f"⚡ 易挥发溶剂:调整参数 → 温度 {temp}°C, 压力 {pressure} bar")
|
||||
|
||||
self.logger.info(f"🌪️ 开始蒸发操作: {actual_vessel}")
|
||||
self.logger.info(f" 🥽 容器: {actual_vessel}")
|
||||
self.logger.info(f" 🌡️ 温度: {temp}°C")
|
||||
self.logger.info(f" 💨 真空度: {pressure} bar")
|
||||
self.logger.info(f" ⏰ 时间: {time}s")
|
||||
self.logger.info(f" 🌀 转速: {stir_speed} RPM")
|
||||
if solvent:
|
||||
self.logger.info(f" 🧪 溶剂: {solvent}")
|
||||
|
||||
# 验证参数
|
||||
if temp > self._max_temp or temp < 10.0:
|
||||
error_msg = f"温度 {temp}°C 超出范围 (10-{self._max_temp}°C)"
|
||||
self.logger.error(error_msg)
|
||||
error_msg = f"🌡️ 温度 {temp}°C 超出范围 (10-{self._max_temp}°C) ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"status": f"❌ 错误: 温度超出范围",
|
||||
"rotavap_state": "Error",
|
||||
"current_temp": 25.0,
|
||||
"progress": 0.0,
|
||||
"evaporated_volume": 0.0,
|
||||
"message": error_msg
|
||||
})
|
||||
return False
|
||||
|
||||
if stir_speed > self._max_rotation_speed or stir_speed < 10.0:
|
||||
error_msg = f"旋转速度 {stir_speed} RPM 超出范围 (10-{self._max_rotation_speed} RPM)"
|
||||
self.logger.error(error_msg)
|
||||
error_msg = f"🌀 旋转速度 {stir_speed} RPM 超出范围 (10-{self._max_rotation_speed} RPM) ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"status": f"❌ 错误: 转速超出范围",
|
||||
"rotavap_state": "Error",
|
||||
"current_temp": 25.0,
|
||||
"progress": 0.0,
|
||||
"evaporated_volume": 0.0,
|
||||
"message": error_msg
|
||||
})
|
||||
return False
|
||||
|
||||
if pressure < 0.01 or pressure > 1.0:
|
||||
error_msg = f"真空度 {pressure} bar 超出范围 (0.01-1.0 bar)"
|
||||
self.logger.error(error_msg)
|
||||
error_msg = f"💨 真空度 {pressure} bar 超出范围 (0.01-1.0 bar) ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"status": f"❌ 错误: 压力超出范围",
|
||||
"rotavap_state": "Error",
|
||||
"current_temp": 25.0,
|
||||
"progress": 0.0,
|
||||
"evaporated_volume": 0.0,
|
||||
"message": error_msg
|
||||
})
|
||||
return False
|
||||
|
||||
# 开始蒸发
|
||||
# 开始蒸发 - 🔧 现在time已经确保是float类型
|
||||
self.logger.info(f"🚀 启动蒸发程序! 预计用时 {time/60:.1f}分钟 ⏱️")
|
||||
|
||||
self.data.update({
|
||||
"status": f"蒸发中: {vessel}",
|
||||
"status": f"🌪️ 蒸发中: {actual_vessel}",
|
||||
"rotavap_state": "Evaporating",
|
||||
"current_temp": temp,
|
||||
"target_temp": temp,
|
||||
@@ -118,13 +185,14 @@ class VirtualRotavap:
|
||||
"remaining_time": time,
|
||||
"progress": 0.0,
|
||||
"evaporated_volume": 0.0,
|
||||
"message": f"Evaporating {vessel} at {temp}°C, {pressure} bar, {stir_speed} RPM"
|
||||
"message": f"🌪️ Evaporating {actual_vessel} at {temp}°C, {pressure} bar, {stir_speed} RPM"
|
||||
})
|
||||
|
||||
try:
|
||||
# 蒸发过程 - 实时更新进度
|
||||
start_time = time_module.time()
|
||||
total_time = time
|
||||
last_logged_progress = 0
|
||||
|
||||
while True:
|
||||
current_time = time_module.time()
|
||||
@@ -132,18 +200,31 @@ class VirtualRotavap:
|
||||
remaining = max(0, total_time - elapsed)
|
||||
progress = min(100.0, (elapsed / total_time) * 100)
|
||||
|
||||
# 模拟蒸发体积
|
||||
evaporated_vol = progress * 0.8 # 假设最多蒸发80mL
|
||||
# 模拟蒸发体积 - 根据溶剂类型调整
|
||||
if solvent and any(s in solvent.lower() for s in ['water', 'aqueous']):
|
||||
evaporated_vol = progress * 0.6 # 水系溶剂蒸发慢
|
||||
elif solvent and any(s in solvent.lower() for s in ['ethanol', 'methanol', 'acetone']):
|
||||
evaporated_vol = progress * 1.0 # 易挥发溶剂蒸发快
|
||||
else:
|
||||
evaporated_vol = progress * 0.8 # 默认蒸发量
|
||||
|
||||
# 🔧 更新状态 - 确保包含所有必需字段
|
||||
status_msg = f"🌪️ 蒸发中: {actual_vessel} | 🌡️ {temp}°C | 💨 {pressure} bar | 🌀 {stir_speed} RPM | 📊 {progress:.1f}% | ⏰ 剩余: {remaining:.0f}s"
|
||||
|
||||
# 更新状态
|
||||
self.data.update({
|
||||
"remaining_time": remaining,
|
||||
"progress": progress,
|
||||
"evaporated_volume": evaporated_vol,
|
||||
"status": f"蒸发中: {vessel} | {temp}°C | {pressure} bar | {progress:.1f}% | 剩余: {remaining:.0f}s",
|
||||
"message": f"Evaporating: {progress:.1f}% complete, {remaining:.0f}s remaining"
|
||||
"current_temp": temp,
|
||||
"status": status_msg,
|
||||
"message": f"🌪️ Evaporating: {progress:.1f}% complete, 💧 {evaporated_vol:.1f}mL evaporated, ⏰ {remaining:.0f}s remaining"
|
||||
})
|
||||
|
||||
# 进度日志(每25%打印一次)
|
||||
if progress >= 25 and int(progress) % 25 == 0 and int(progress) != last_logged_progress:
|
||||
self.logger.info(f"📊 蒸发进度: {progress:.0f}% | 💧 已蒸发: {evaporated_vol:.1f}mL | ⏰ 剩余: {remaining:.0f}s ✨")
|
||||
last_logged_progress = int(progress)
|
||||
|
||||
# 时间到了,退出循环
|
||||
if remaining <= 0:
|
||||
break
|
||||
@@ -152,40 +233,59 @@ class VirtualRotavap:
|
||||
await asyncio.sleep(1.0)
|
||||
|
||||
# 蒸发完成
|
||||
final_evaporated = 80.0
|
||||
if solvent and any(s in solvent.lower() for s in ['water', 'aqueous']):
|
||||
final_evaporated = 60.0 # 水系溶剂
|
||||
elif solvent and any(s in solvent.lower() for s in ['ethanol', 'methanol', 'acetone']):
|
||||
final_evaporated = 100.0 # 易挥发溶剂
|
||||
else:
|
||||
final_evaporated = 80.0 # 默认
|
||||
|
||||
self.data.update({
|
||||
"status": f"蒸发完成: {vessel} | 蒸发量: {final_evaporated:.1f}mL",
|
||||
"status": f"✅ 蒸发完成: {actual_vessel} | 💧 蒸发量: {final_evaporated:.1f}mL",
|
||||
"rotavap_state": "Completed",
|
||||
"evaporated_volume": final_evaporated,
|
||||
"progress": 100.0,
|
||||
"current_temp": temp,
|
||||
"remaining_time": 0.0,
|
||||
"current_temp": 25.0, # 冷却下来
|
||||
"rotation_speed": 0.0, # 停止旋转
|
||||
"vacuum_pressure": 1.0, # 恢复大气压
|
||||
"message": f"Evaporation completed: {final_evaporated}mL evaporated from {vessel}"
|
||||
"rotation_speed": 0.0,
|
||||
"vacuum_pressure": 1.0,
|
||||
"message": f"✅ Evaporation completed: {final_evaporated}mL evaporated from {actual_vessel}"
|
||||
})
|
||||
|
||||
self.logger.info(f"Evaporation completed: {final_evaporated}mL evaporated from {vessel}")
|
||||
self.logger.info(f"🎉 蒸发操作完成! ✨")
|
||||
self.logger.info(f"📊 蒸发结果:")
|
||||
self.logger.info(f" 🥽 容器: {actual_vessel}")
|
||||
self.logger.info(f" 💧 蒸发量: {final_evaporated:.1f}mL")
|
||||
self.logger.info(f" 🌡️ 蒸发温度: {temp}°C")
|
||||
self.logger.info(f" 💨 真空度: {pressure} bar")
|
||||
self.logger.info(f" 🌀 旋转速度: {stir_speed} RPM")
|
||||
self.logger.info(f" ⏱️ 总用时: {total_time:.0f}s")
|
||||
if solvent:
|
||||
self.logger.info(f" 🧪 处理溶剂: {solvent} 🏁")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
# 出错处理
|
||||
self.logger.error(f"Error during evaporation: {str(e)}")
|
||||
error_msg = f"蒸发过程中发生错误: {str(e)} 💥"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
|
||||
self.data.update({
|
||||
"status": f"蒸发错误: {str(e)}",
|
||||
"status": f"❌ 蒸发错误: {str(e)}",
|
||||
"rotavap_state": "Error",
|
||||
"current_temp": 25.0,
|
||||
"progress": 0.0,
|
||||
"evaporated_volume": 0.0,
|
||||
"rotation_speed": 0.0,
|
||||
"vacuum_pressure": 1.0,
|
||||
"message": f"Evaporation failed: {str(e)}"
|
||||
"message": f"❌ Evaporation failed: {str(e)}"
|
||||
})
|
||||
return False
|
||||
|
||||
# === 核心状态属性 ===
|
||||
@property
|
||||
def status(self) -> str:
|
||||
return self.data.get("status", "Unknown")
|
||||
return self.data.get("status", "❓ Unknown")
|
||||
|
||||
@property
|
||||
def rotavap_state(self) -> str:
|
||||
|
||||
@@ -43,10 +43,25 @@ class VirtualSolenoidValve:
|
||||
def is_open(self) -> bool:
|
||||
return self._is_open
|
||||
|
||||
def get_valve_position(self) -> str:
|
||||
@property
|
||||
def valve_position(self) -> str:
|
||||
"""获取阀门位置状态"""
|
||||
return "OPEN" if self._is_open else "CLOSED"
|
||||
|
||||
@property
|
||||
def state(self) -> dict:
|
||||
"""获取阀门完整状态"""
|
||||
return {
|
||||
"device_id": self.device_id,
|
||||
"port": self.port,
|
||||
"voltage": self.voltage,
|
||||
"response_time": self.response_time,
|
||||
"is_open": self._is_open,
|
||||
"valve_state": self._valve_state,
|
||||
"status": self._status,
|
||||
"position": self.valve_position
|
||||
}
|
||||
|
||||
async def set_valve_position(self, command: str = None, **kwargs):
|
||||
"""
|
||||
设置阀门位置 - ROS动作接口
|
||||
@@ -91,7 +106,7 @@ class VirtualSolenoidValve:
|
||||
return {
|
||||
"success": True,
|
||||
"message": result_msg,
|
||||
"valve_position": self.get_valve_position()
|
||||
"valve_position": self.valve_position
|
||||
}
|
||||
|
||||
async def open(self, **kwargs):
|
||||
@@ -102,21 +117,25 @@ class VirtualSolenoidValve:
|
||||
"""关闭电磁阀 - ROS动作接口"""
|
||||
return await self.set_valve_position(command="CLOSED")
|
||||
|
||||
async def set_state(self, command: Union[bool, str], **kwargs):
|
||||
async def set_status(self, string: str = None, **kwargs):
|
||||
"""
|
||||
设置阀门状态 - 兼容 SendCmd 类型
|
||||
设置阀门状态 - 兼容 StrSingleInput 类型
|
||||
|
||||
Args:
|
||||
command: True/False 或 "open"/"close"
|
||||
string: "ON"/"OFF" 或 "OPEN"/"CLOSED"
|
||||
"""
|
||||
if isinstance(command, bool):
|
||||
cmd_str = "OPEN" if command else "CLOSED"
|
||||
elif isinstance(command, str):
|
||||
cmd_str = command
|
||||
else:
|
||||
return {"success": False, "message": "Invalid command type"}
|
||||
if string is None:
|
||||
return {"success": False, "message": "Missing string parameter"}
|
||||
|
||||
return await self.set_valve_position(command=cmd_str)
|
||||
# 将 string 参数转换为 command 参数
|
||||
if string.upper() in ["ON", "OPEN"]:
|
||||
command = "OPEN"
|
||||
elif string.upper() in ["OFF", "CLOSED"]:
|
||||
command = "CLOSED"
|
||||
else:
|
||||
command = string
|
||||
|
||||
return await self.set_valve_position(command=command)
|
||||
|
||||
def toggle(self):
|
||||
"""切换阀门状态"""
|
||||
@@ -129,19 +148,6 @@ class VirtualSolenoidValve:
|
||||
"""检查阀门是否关闭"""
|
||||
return not self._is_open
|
||||
|
||||
def get_state(self) -> dict:
|
||||
"""获取阀门完整状态"""
|
||||
return {
|
||||
"device_id": self.device_id,
|
||||
"port": self.port,
|
||||
"voltage": self.voltage,
|
||||
"response_time": self.response_time,
|
||||
"is_open": self._is_open,
|
||||
"valve_state": self._valve_state,
|
||||
"status": self._status,
|
||||
"position": self.get_valve_position()
|
||||
}
|
||||
|
||||
async def reset(self):
|
||||
"""重置阀门到关闭状态"""
|
||||
return await self.close()
|
||||
389
unilabos/devices/virtual/virtual_solid_dispenser.py
Normal file
389
unilabos/devices/virtual/virtual_solid_dispenser.py
Normal file
@@ -0,0 +1,389 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import re
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
class VirtualSolidDispenser:
|
||||
"""
|
||||
虚拟固体粉末加样器 - 用于处理 Add Protocol 中的固体试剂添加 ⚗️
|
||||
|
||||
特点:
|
||||
- 高兼容性:缺少参数不报错 ✅
|
||||
- 智能识别:自动查找固体试剂瓶 🔍
|
||||
- 简单反馈:成功/失败 + 消息 📊
|
||||
"""
|
||||
|
||||
def __init__(self, device_id: str = None, config: Dict[str, Any] = None, **kwargs):
|
||||
self.device_id = device_id or "virtual_solid_dispenser"
|
||||
self.config = config or {}
|
||||
|
||||
# 设备参数
|
||||
self.max_capacity = float(self.config.get('max_capacity', 100.0)) # 最大加样量 (g)
|
||||
self.precision = float(self.config.get('precision', 0.001)) # 精度 (g)
|
||||
|
||||
# 状态变量
|
||||
self._status = "Idle"
|
||||
self._current_reagent = ""
|
||||
self._dispensed_amount = 0.0
|
||||
self._total_operations = 0
|
||||
|
||||
self.logger = logging.getLogger(f"VirtualSolidDispenser.{self.device_id}")
|
||||
|
||||
print(f"⚗️ === 虚拟固体分配器 {self.device_id} 创建成功! === ✨")
|
||||
print(f"📊 设备规格: 最大容量 {self.max_capacity}g | 精度 {self.precision}g 🎯")
|
||||
|
||||
async def initialize(self) -> bool:
|
||||
"""初始化固体加样器 🚀"""
|
||||
self.logger.info(f"🔧 初始化固体分配器 {self.device_id} ✨")
|
||||
self._status = "Ready"
|
||||
self._current_reagent = ""
|
||||
self._dispensed_amount = 0.0
|
||||
|
||||
self.logger.info(f"✅ 固体分配器 {self.device_id} 初始化完成 ⚗️")
|
||||
return True
|
||||
|
||||
async def cleanup(self) -> bool:
|
||||
"""清理固体加样器 🧹"""
|
||||
self.logger.info(f"🧹 清理固体分配器 {self.device_id} 🔚")
|
||||
self._status = "Idle"
|
||||
|
||||
self.logger.info(f"✅ 固体分配器 {self.device_id} 清理完成 💤")
|
||||
return True
|
||||
|
||||
def parse_mass_string(self, mass_str: str) -> float:
|
||||
"""
|
||||
解析质量字符串为数值 (g) ⚖️
|
||||
|
||||
支持格式: "2.9 g", "19.3g", "4.5 mg", "1.2 kg" 等
|
||||
"""
|
||||
if not mass_str or not isinstance(mass_str, str):
|
||||
return 0.0
|
||||
|
||||
# 移除空格并转小写
|
||||
mass_clean = mass_str.strip().lower()
|
||||
|
||||
# 正则匹配数字和单位
|
||||
pattern = r'(\d+(?:\.\d+)?)\s*([a-z]*)'
|
||||
match = re.search(pattern, mass_clean)
|
||||
|
||||
if not match:
|
||||
self.logger.debug(f"🔍 无法解析质量字符串: {mass_str}")
|
||||
return 0.0
|
||||
|
||||
try:
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2) or 'g' # 默认单位 g
|
||||
|
||||
# 单位转换为 g
|
||||
unit_multipliers = {
|
||||
'g': 1.0,
|
||||
'gram': 1.0,
|
||||
'grams': 1.0,
|
||||
'mg': 0.001,
|
||||
'milligram': 0.001,
|
||||
'milligrams': 0.001,
|
||||
'kg': 1000.0,
|
||||
'kilogram': 1000.0,
|
||||
'kilograms': 1000.0,
|
||||
'μg': 0.000001,
|
||||
'ug': 0.000001,
|
||||
'microgram': 0.000001,
|
||||
'micrograms': 0.000001,
|
||||
}
|
||||
|
||||
multiplier = unit_multipliers.get(unit, 1.0)
|
||||
result = value * multiplier
|
||||
|
||||
self.logger.debug(f"⚖️ 质量解析: {mass_str} → {result:.6f}g (原值: {value} {unit})")
|
||||
return result
|
||||
|
||||
except (ValueError, TypeError):
|
||||
self.logger.warning(f"⚠️ 无法解析质量字符串: {mass_str}")
|
||||
return 0.0
|
||||
|
||||
def parse_mol_string(self, mol_str: str) -> float:
|
||||
"""
|
||||
解析摩尔数字符串为数值 (mol) 🧮
|
||||
|
||||
支持格式: "0.12 mol", "16.2 mmol", "25.2mmol" 等
|
||||
"""
|
||||
if not mol_str or not isinstance(mol_str, str):
|
||||
return 0.0
|
||||
|
||||
# 移除空格并转小写
|
||||
mol_clean = mol_str.strip().lower()
|
||||
|
||||
# 正则匹配数字和单位
|
||||
pattern = r'(\d+(?:\.\d+)?)\s*(m?mol)'
|
||||
match = re.search(pattern, mol_clean)
|
||||
|
||||
if not match:
|
||||
self.logger.debug(f"🔍 无法解析摩尔数字符串: {mol_str}")
|
||||
return 0.0
|
||||
|
||||
try:
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2)
|
||||
|
||||
# 单位转换为 mol
|
||||
if unit == 'mmol':
|
||||
result = value * 0.001
|
||||
else: # mol
|
||||
result = value
|
||||
|
||||
self.logger.debug(f"🧮 摩尔数解析: {mol_str} → {result:.6f}mol (原值: {value} {unit})")
|
||||
return result
|
||||
|
||||
except (ValueError, TypeError):
|
||||
self.logger.warning(f"⚠️ 无法解析摩尔数字符串: {mol_str}")
|
||||
return 0.0
|
||||
|
||||
def find_solid_reagent_bottle(self, reagent_name: str) -> str:
|
||||
"""
|
||||
查找固体试剂瓶 🔍
|
||||
|
||||
这是一个简化版本,实际使用时应该连接到系统的设备图
|
||||
"""
|
||||
if not reagent_name:
|
||||
self.logger.debug(f"🔍 未指定试剂名称,使用默认瓶")
|
||||
return "unknown_solid_bottle"
|
||||
|
||||
# 可能的固体试剂瓶命名模式
|
||||
possible_names = [
|
||||
f"solid_bottle_{reagent_name}",
|
||||
f"reagent_solid_{reagent_name}",
|
||||
f"powder_{reagent_name}",
|
||||
f"{reagent_name}_solid",
|
||||
f"{reagent_name}_powder",
|
||||
f"solid_{reagent_name}",
|
||||
]
|
||||
|
||||
# 这里简化处理,实际应该查询设备图
|
||||
selected_bottle = possible_names[0]
|
||||
self.logger.debug(f"🔍 为试剂 {reagent_name} 选择试剂瓶: {selected_bottle}")
|
||||
return selected_bottle
|
||||
|
||||
async def add_solid(
|
||||
self,
|
||||
vessel: str,
|
||||
reagent: str,
|
||||
mass: str = "",
|
||||
mol: str = "",
|
||||
purpose: str = "",
|
||||
**kwargs # 兼容额外参数
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
添加固体试剂的主要方法 ⚗️
|
||||
|
||||
Args:
|
||||
vessel: 目标容器
|
||||
reagent: 试剂名称
|
||||
mass: 质量字符串 (如 "2.9 g")
|
||||
mol: 摩尔数字符串 (如 "0.12 mol")
|
||||
purpose: 添加目的
|
||||
**kwargs: 其他兼容参数
|
||||
|
||||
Returns:
|
||||
Dict: 操作结果
|
||||
"""
|
||||
try:
|
||||
self.logger.info(f"⚗️ === 开始固体加样操作 === ✨")
|
||||
self.logger.info(f" 🥽 目标容器: {vessel}")
|
||||
self.logger.info(f" 🧪 试剂: {reagent}")
|
||||
self.logger.info(f" ⚖️ 质量: {mass}")
|
||||
self.logger.info(f" 🧮 摩尔数: {mol}")
|
||||
self.logger.info(f" 📝 目的: {purpose}")
|
||||
|
||||
# 参数验证 - 宽松处理
|
||||
if not vessel:
|
||||
vessel = "main_reactor" # 默认容器
|
||||
self.logger.warning(f"⚠️ 未指定容器,使用默认容器: {vessel} 🏠")
|
||||
|
||||
if not reagent:
|
||||
error_msg = "❌ 错误: 必须指定试剂名称"
|
||||
self.logger.error(error_msg)
|
||||
return {
|
||||
"success": False,
|
||||
"message": error_msg,
|
||||
"return_info": "missing_reagent"
|
||||
}
|
||||
|
||||
# 解析质量和摩尔数
|
||||
mass_value = self.parse_mass_string(mass)
|
||||
mol_value = self.parse_mol_string(mol)
|
||||
|
||||
self.logger.info(f"📊 解析结果 - 质量: {mass_value:.6f}g | 摩尔数: {mol_value:.6f}mol")
|
||||
|
||||
# 确定实际加样量
|
||||
if mass_value > 0:
|
||||
actual_amount = mass_value
|
||||
amount_unit = "g"
|
||||
amount_emoji = "⚖️"
|
||||
self.logger.info(f"⚖️ 按质量加样: {actual_amount:.6f} {amount_unit}")
|
||||
elif mol_value > 0:
|
||||
# 简化处理:假设分子量为100 g/mol
|
||||
assumed_mw = 100.0
|
||||
actual_amount = mol_value * assumed_mw
|
||||
amount_unit = "g (from mol)"
|
||||
amount_emoji = "🧮"
|
||||
self.logger.info(f"🧮 按摩尔数加样: {mol_value:.6f} mol → {actual_amount:.6f} g (假设分子量 {assumed_mw})")
|
||||
else:
|
||||
# 没有指定量,使用默认值
|
||||
actual_amount = 1.0
|
||||
amount_unit = "g (default)"
|
||||
amount_emoji = "🎯"
|
||||
self.logger.warning(f"⚠️ 未指定质量或摩尔数,使用默认值: {actual_amount} {amount_unit} 🎯")
|
||||
|
||||
# 检查容量限制
|
||||
if actual_amount > self.max_capacity:
|
||||
error_msg = f"❌ 错误: 请求量 {actual_amount:.3f}g 超过最大容量 {self.max_capacity}g"
|
||||
self.logger.error(error_msg)
|
||||
return {
|
||||
"success": False,
|
||||
"message": error_msg,
|
||||
"return_info": "exceeds_capacity"
|
||||
}
|
||||
|
||||
# 查找试剂瓶
|
||||
reagent_bottle = self.find_solid_reagent_bottle(reagent)
|
||||
self.logger.info(f"🔍 使用试剂瓶: {reagent_bottle}")
|
||||
|
||||
# 模拟加样过程
|
||||
self._status = "Dispensing"
|
||||
self._current_reagent = reagent
|
||||
|
||||
# 计算操作时间 (基于质量)
|
||||
operation_time = max(0.5, actual_amount * 0.1) # 每克0.1秒,最少0.5秒
|
||||
|
||||
self.logger.info(f"🚀 开始加样,预计时间: {operation_time:.1f}秒 ⏱️")
|
||||
|
||||
# 显示进度的模拟
|
||||
steps = max(3, int(operation_time))
|
||||
step_time = operation_time / steps
|
||||
|
||||
for i in range(steps):
|
||||
progress = (i + 1) / steps * 100
|
||||
await asyncio.sleep(step_time)
|
||||
if i % 2 == 0: # 每隔一步显示进度
|
||||
self.logger.debug(f"📊 加样进度: {progress:.0f}% | {amount_emoji} 正在分配 {reagent}...")
|
||||
|
||||
# 更新状态
|
||||
self._dispensed_amount = actual_amount
|
||||
self._total_operations += 1
|
||||
self._status = "Ready"
|
||||
|
||||
# 成功结果
|
||||
success_message = f"✅ 成功添加 {reagent} {actual_amount:.6f} {amount_unit} 到 {vessel}"
|
||||
|
||||
self.logger.info(f"🎉 === 固体加样完成 === ✨")
|
||||
self.logger.info(f"📊 操作结果:")
|
||||
self.logger.info(f" ✅ {success_message}")
|
||||
self.logger.info(f" 🧪 试剂瓶: {reagent_bottle}")
|
||||
self.logger.info(f" ⏱️ 用时: {operation_time:.1f}秒")
|
||||
self.logger.info(f" 🎯 总操作次数: {self._total_operations} 🏁")
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"message": success_message,
|
||||
"return_info": f"dispensed_{actual_amount:.6f}g",
|
||||
"dispensed_amount": actual_amount,
|
||||
"reagent": reagent,
|
||||
"vessel": vessel
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
error_message = f"❌ 固体加样失败: {str(e)} 💥"
|
||||
self.logger.error(error_message)
|
||||
self._status = "Error"
|
||||
|
||||
return {
|
||||
"success": False,
|
||||
"message": error_message,
|
||||
"return_info": "operation_failed"
|
||||
}
|
||||
|
||||
# 状态属性
|
||||
@property
|
||||
def status(self) -> str:
|
||||
return self._status
|
||||
|
||||
@property
|
||||
def current_reagent(self) -> str:
|
||||
return self._current_reagent
|
||||
|
||||
@property
|
||||
def dispensed_amount(self) -> float:
|
||||
return self._dispensed_amount
|
||||
|
||||
@property
|
||||
def total_operations(self) -> int:
|
||||
return self._total_operations
|
||||
|
||||
def get_device_info(self) -> Dict[str, Any]:
|
||||
"""获取设备状态信息 📊"""
|
||||
info = {
|
||||
"device_id": self.device_id,
|
||||
"status": self._status,
|
||||
"current_reagent": self._current_reagent,
|
||||
"last_dispensed_amount": self._dispensed_amount,
|
||||
"total_operations": self._total_operations,
|
||||
"max_capacity": self.max_capacity,
|
||||
"precision": self.precision
|
||||
}
|
||||
|
||||
self.logger.debug(f"📊 设备信息: 状态={self._status}, 试剂={self._current_reagent}, 加样量={self._dispensed_amount:.6f}g")
|
||||
return info
|
||||
|
||||
def __str__(self):
|
||||
status_emoji = "✅" if self._status == "Ready" else "🔄" if self._status == "Dispensing" else "❌" if self._status == "Error" else "🏠"
|
||||
return f"⚗️ VirtualSolidDispenser({status_emoji} {self.device_id}: {self._status}, 最后加样 {self._dispensed_amount:.3f}g)"
|
||||
|
||||
|
||||
# 测试函数
|
||||
async def test_solid_dispenser():
|
||||
"""测试固体加样器 🧪"""
|
||||
print("⚗️ === 固体加样器测试开始 === 🧪")
|
||||
|
||||
dispenser = VirtualSolidDispenser("test_dispenser")
|
||||
await dispenser.initialize()
|
||||
|
||||
# 测试1: 按质量加样
|
||||
print(f"\n🧪 测试1: 按质量加样...")
|
||||
result1 = await dispenser.add_solid(
|
||||
vessel="main_reactor",
|
||||
reagent="magnesium",
|
||||
mass="2.9 g"
|
||||
)
|
||||
print(f"📊 测试1结果: {result1}")
|
||||
|
||||
# 测试2: 按摩尔数加样
|
||||
print(f"\n🧮 测试2: 按摩尔数加样...")
|
||||
result2 = await dispenser.add_solid(
|
||||
vessel="main_reactor",
|
||||
reagent="sodium_nitrite",
|
||||
mol="0.28 mol"
|
||||
)
|
||||
print(f"📊 测试2结果: {result2}")
|
||||
|
||||
# 测试3: 缺少参数
|
||||
print(f"\n⚠️ 测试3: 缺少参数测试...")
|
||||
result3 = await dispenser.add_solid(
|
||||
reagent="test_compound"
|
||||
)
|
||||
print(f"📊 测试3结果: {result3}")
|
||||
|
||||
# 测试4: 超容量测试
|
||||
print(f"\n❌ 测试4: 超容量测试...")
|
||||
result4 = await dispenser.add_solid(
|
||||
vessel="main_reactor",
|
||||
reagent="heavy_compound",
|
||||
mass="150 g" # 超过100g限制
|
||||
)
|
||||
print(f"📊 测试4结果: {result4}")
|
||||
|
||||
print(f"\n📊 最终设备信息: {dispenser.get_device_info()}")
|
||||
print(f"✅ === 测试完成 === 🎉")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(test_solid_dispenser())
|
||||
@@ -4,7 +4,7 @@ import time as time_module
|
||||
from typing import Dict, Any
|
||||
|
||||
class VirtualStirrer:
|
||||
"""Virtual stirrer device for StirProtocol testing - 功能完整版"""
|
||||
"""Virtual stirrer device for StirProtocol testing - 功能完整版 🌪️"""
|
||||
|
||||
def __init__(self, device_id: str = None, config: Dict[str, Any] = None, **kwargs):
|
||||
# 处理可能的不同调用方式
|
||||
@@ -30,45 +30,69 @@ class VirtualStirrer:
|
||||
for key, value in kwargs.items():
|
||||
if key not in skip_keys and not hasattr(self, key):
|
||||
setattr(self, key, value)
|
||||
|
||||
print(f"🌪️ === 虚拟搅拌器 {self.device_id} 已创建 === ✨")
|
||||
print(f"🔧 速度范围: {self._min_speed} ~ {self._max_speed} RPM | 📱 端口: {self.port}")
|
||||
|
||||
async def initialize(self) -> bool:
|
||||
"""Initialize virtual stirrer"""
|
||||
self.logger.info(f"Initializing virtual stirrer {self.device_id}")
|
||||
"""Initialize virtual stirrer 🚀"""
|
||||
self.logger.info(f"🔧 初始化虚拟搅拌器 {self.device_id} ✨")
|
||||
|
||||
# 初始化状态信息
|
||||
self.data.update({
|
||||
"status": "Idle",
|
||||
"status": "🏠 待机中",
|
||||
"operation_mode": "Idle", # 操作模式: Idle, Stirring, Settling, Completed, Error
|
||||
"current_vessel": "", # 当前搅拌的容器
|
||||
"current_speed": 0.0, # 当前搅拌速度
|
||||
"is_stirring": False, # 是否正在搅拌
|
||||
"remaining_time": 0.0, # 剩余时间
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 搅拌器 {self.device_id} 初始化完成 🌪️")
|
||||
self.logger.info(f"📊 设备规格: 速度范围 {self._min_speed} ~ {self._max_speed} RPM")
|
||||
return True
|
||||
|
||||
async def cleanup(self) -> bool:
|
||||
"""Cleanup virtual stirrer"""
|
||||
self.logger.info(f"Cleaning up virtual stirrer {self.device_id}")
|
||||
"""Cleanup virtual stirrer 🧹"""
|
||||
self.logger.info(f"🧹 清理虚拟搅拌器 {self.device_id} 🔚")
|
||||
|
||||
self.data.update({
|
||||
"status": "Offline",
|
||||
"status": "💤 离线",
|
||||
"operation_mode": "Offline",
|
||||
"current_vessel": "",
|
||||
"current_speed": 0.0,
|
||||
"is_stirring": False,
|
||||
"remaining_time": 0.0,
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 搅拌器 {self.device_id} 清理完成 💤")
|
||||
return True
|
||||
|
||||
async def stir(self, stir_time: float, stir_speed: float, settling_time: float) -> bool:
|
||||
"""Execute stir action - 定时搅拌 + 沉降"""
|
||||
self.logger.info(f"Stir: speed={stir_speed} RPM, time={stir_time}s, settling={settling_time}s")
|
||||
async def stir(self, stir_time: float, stir_speed: float, settling_time: float, **kwargs) -> bool:
|
||||
"""Execute stir action - 定时搅拌 + 沉降 🌪️"""
|
||||
|
||||
# 🔧 类型转换 - 确保所有参数都是数字类型
|
||||
try:
|
||||
stir_time = float(stir_time)
|
||||
stir_speed = float(stir_speed)
|
||||
settling_time = float(settling_time)
|
||||
except (ValueError, TypeError) as e:
|
||||
error_msg = f"参数类型转换失败: stir_time={stir_time}, stir_speed={stir_speed}, settling_time={settling_time}, error={e}"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"❌ 错误: {error_msg}",
|
||||
"operation_mode": "Error"
|
||||
})
|
||||
return False
|
||||
|
||||
self.logger.info(f"🌪️ 开始搅拌操作: 速度 {stir_speed} RPM | 时间 {stir_time}s | 沉降 {settling_time}s")
|
||||
|
||||
# 验证参数
|
||||
if stir_speed > self._max_speed or stir_speed < self._min_speed:
|
||||
error_msg = f"搅拌速度 {stir_speed} RPM 超出范围 ({self._min_speed} - {self._max_speed} RPM)"
|
||||
self.logger.error(error_msg)
|
||||
error_msg = f"🌪️ 搅拌速度 {stir_speed} RPM 超出范围 ({self._min_speed} - {self._max_speed} RPM) ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"status": f"❌ 错误: 速度超出范围",
|
||||
"operation_mode": "Error"
|
||||
})
|
||||
return False
|
||||
@@ -77,8 +101,10 @@ class VirtualStirrer:
|
||||
start_time = time_module.time()
|
||||
total_stir_time = stir_time
|
||||
|
||||
self.logger.info(f"🚀 开始搅拌阶段: {stir_speed} RPM × {total_stir_time}s ⏱️")
|
||||
|
||||
self.data.update({
|
||||
"status": f"搅拌中: {stir_speed} RPM | 剩余: {total_stir_time:.0f}s",
|
||||
"status": f"🌪️ 搅拌中: {stir_speed} RPM | ⏰ 剩余: {total_stir_time:.0f}s",
|
||||
"operation_mode": "Stirring",
|
||||
"current_speed": stir_speed,
|
||||
"is_stirring": True,
|
||||
@@ -86,30 +112,41 @@ class VirtualStirrer:
|
||||
})
|
||||
|
||||
# 搅拌过程 - 实时更新剩余时间
|
||||
last_logged_time = 0
|
||||
while True:
|
||||
current_time = time_module.time()
|
||||
elapsed = current_time - start_time
|
||||
remaining = max(0, total_stir_time - elapsed)
|
||||
progress = (elapsed / total_stir_time) * 100 if total_stir_time > 0 else 100
|
||||
|
||||
# 更新状态
|
||||
self.data.update({
|
||||
"remaining_time": remaining,
|
||||
"status": f"搅拌中: {stir_speed} RPM | 剩余: {remaining:.0f}s"
|
||||
"status": f"🌪️ 搅拌中: {stir_speed} RPM | ⏰ 剩余: {remaining:.0f}s"
|
||||
})
|
||||
|
||||
# 进度日志(每25%打印一次)
|
||||
if progress >= 25 and int(progress) % 25 == 0 and int(progress) != last_logged_time:
|
||||
self.logger.info(f"📊 搅拌进度: {progress:.0f}% | 🌪️ {stir_speed} RPM | ⏰ 剩余: {remaining:.0f}s ✨")
|
||||
last_logged_time = int(progress)
|
||||
|
||||
# 搅拌时间到了
|
||||
if remaining <= 0:
|
||||
break
|
||||
|
||||
await asyncio.sleep(1.0)
|
||||
|
||||
self.logger.info(f"✅ 搅拌阶段完成! 🌪️ {stir_speed} RPM × {stir_time}s")
|
||||
|
||||
# === 第二阶段:沉降(如果需要)===
|
||||
if settling_time > 0:
|
||||
start_settling_time = time_module.time()
|
||||
total_settling_time = settling_time
|
||||
|
||||
self.logger.info(f"🛑 开始沉降阶段: 停止搅拌 × {total_settling_time}s ⏱️")
|
||||
|
||||
self.data.update({
|
||||
"status": f"沉降中: 停止搅拌 | 剩余: {total_settling_time:.0f}s",
|
||||
"status": f"🛑 沉降中: 停止搅拌 | ⏰ 剩余: {total_settling_time:.0f}s",
|
||||
"operation_mode": "Settling",
|
||||
"current_speed": 0.0,
|
||||
"is_stirring": False,
|
||||
@@ -117,52 +154,87 @@ class VirtualStirrer:
|
||||
})
|
||||
|
||||
# 沉降过程 - 实时更新剩余时间
|
||||
last_logged_settling = 0
|
||||
while True:
|
||||
current_time = time_module.time()
|
||||
elapsed = current_time - start_settling_time
|
||||
remaining = max(0, total_settling_time - elapsed)
|
||||
progress = (elapsed / total_settling_time) * 100 if total_settling_time > 0 else 100
|
||||
|
||||
# 更新状态
|
||||
self.data.update({
|
||||
"remaining_time": remaining,
|
||||
"status": f"沉降中: 停止搅拌 | 剩余: {remaining:.0f}s"
|
||||
"status": f"🛑 沉降中: 停止搅拌 | ⏰ 剩余: {remaining:.0f}s"
|
||||
})
|
||||
|
||||
# 进度日志(每25%打印一次)
|
||||
if progress >= 25 and int(progress) % 25 == 0 and int(progress) != last_logged_settling:
|
||||
self.logger.info(f"📊 沉降进度: {progress:.0f}% | 🛑 静置中 | ⏰ 剩余: {remaining:.0f}s ✨")
|
||||
last_logged_settling = int(progress)
|
||||
|
||||
# 沉降时间到了
|
||||
if remaining <= 0:
|
||||
break
|
||||
|
||||
await asyncio.sleep(1.0)
|
||||
|
||||
self.logger.info(f"✅ 沉降阶段完成! 🛑 静置 {settling_time}s")
|
||||
|
||||
# === 操作完成 ===
|
||||
settling_info = f" | 沉降: {settling_time:.0f}s" if settling_time > 0 else ""
|
||||
settling_info = f" | 🛑 沉降: {settling_time:.0f}s" if settling_time > 0 else ""
|
||||
|
||||
self.data.update({
|
||||
"status": f"完成: 搅拌 {stir_speed} RPM, {stir_time:.0f}s{settling_info}",
|
||||
"status": f"✅ 完成: 🌪️ 搅拌 {stir_speed} RPM × {stir_time:.0f}s{settling_info}",
|
||||
"operation_mode": "Completed",
|
||||
"current_speed": 0.0,
|
||||
"is_stirring": False,
|
||||
"remaining_time": 0.0,
|
||||
})
|
||||
|
||||
self.logger.info(f"Stir completed: {stir_speed} RPM for {stir_time}s + settling {settling_time}s")
|
||||
self.logger.info(f"🎉 搅拌操作完成! ✨")
|
||||
self.logger.info(f"📊 操作总结:")
|
||||
self.logger.info(f" 🌪️ 搅拌: {stir_speed} RPM × {stir_time}s")
|
||||
if settling_time > 0:
|
||||
self.logger.info(f" 🛑 沉降: {settling_time}s")
|
||||
self.logger.info(f" ⏱️ 总用时: {(stir_time + settling_time):.0f}s 🏁")
|
||||
|
||||
return True
|
||||
|
||||
async def start_stir(self, vessel: str, stir_speed: float, purpose: str) -> bool:
|
||||
"""Start stir action - 开始持续搅拌"""
|
||||
self.logger.info(f"StartStir: vessel={vessel}, speed={stir_speed} RPM, purpose={purpose}")
|
||||
async def start_stir(self, vessel: str, stir_speed: float, purpose: str = "") -> bool:
|
||||
"""Start stir action - 开始持续搅拌 🔄"""
|
||||
|
||||
# 验证参数
|
||||
if stir_speed > self._max_speed or stir_speed < self._min_speed:
|
||||
error_msg = f"搅拌速度 {stir_speed} RPM 超出范围 ({self._min_speed} - {self._max_speed} RPM)"
|
||||
self.logger.error(error_msg)
|
||||
# 🔧 类型转换
|
||||
try:
|
||||
stir_speed = float(stir_speed)
|
||||
vessel = str(vessel)
|
||||
purpose = str(purpose)
|
||||
except (ValueError, TypeError) as e:
|
||||
error_msg = f"参数类型转换错误: {str(e)}"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"Error: {error_msg}",
|
||||
"status": f"❌ 错误: {error_msg}",
|
||||
"operation_mode": "Error"
|
||||
})
|
||||
return False
|
||||
|
||||
self.logger.info(f"🔄 启动持续搅拌: {vessel} | 🌪️ {stir_speed} RPM")
|
||||
if purpose:
|
||||
self.logger.info(f"📝 搅拌目的: {purpose}")
|
||||
|
||||
# 验证参数
|
||||
if stir_speed > self._max_speed or stir_speed < self._min_speed:
|
||||
error_msg = f"🌪️ 搅拌速度 {stir_speed} RPM 超出范围 ({self._min_speed} - {self._max_speed} RPM) ⚠️"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
self.data.update({
|
||||
"status": f"❌ 错误: 速度超出范围",
|
||||
"operation_mode": "Error"
|
||||
})
|
||||
return False
|
||||
|
||||
purpose_info = f" | 📝 {purpose}" if purpose else ""
|
||||
|
||||
self.data.update({
|
||||
"status": f"启动: 持续搅拌 {vessel} at {stir_speed} RPM | {purpose}",
|
||||
"status": f"🔄 启动: 持续搅拌 {vessel} | 🌪️ {stir_speed} RPM{purpose_info}",
|
||||
"operation_mode": "Stirring",
|
||||
"current_vessel": vessel,
|
||||
"current_speed": stir_speed,
|
||||
@@ -170,16 +242,28 @@ class VirtualStirrer:
|
||||
"remaining_time": -1.0, # -1 表示持续运行
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 持续搅拌已启动! 🌪️ {stir_speed} RPM × ♾️ 🚀")
|
||||
return True
|
||||
|
||||
async def stop_stir(self, vessel: str) -> bool:
|
||||
"""Stop stir action - 停止搅拌"""
|
||||
self.logger.info(f"StopStir: vessel={vessel}")
|
||||
"""Stop stir action - 停止搅拌 🛑"""
|
||||
|
||||
# 🔧 类型转换
|
||||
try:
|
||||
vessel = str(vessel)
|
||||
except (ValueError, TypeError) as e:
|
||||
error_msg = f"参数类型转换错误: {str(e)}"
|
||||
self.logger.error(f"❌ {error_msg}")
|
||||
return False
|
||||
|
||||
current_speed = self.data.get("current_speed", 0.0)
|
||||
|
||||
self.logger.info(f"🛑 停止搅拌: {vessel}")
|
||||
if current_speed > 0:
|
||||
self.logger.info(f"🌪️ 之前搅拌速度: {current_speed} RPM")
|
||||
|
||||
self.data.update({
|
||||
"status": f"已停止: {vessel} 搅拌停止 | 之前速度: {current_speed} RPM",
|
||||
"status": f"🛑 已停止: {vessel} 搅拌停止 | 之前速度: {current_speed} RPM",
|
||||
"operation_mode": "Stopped",
|
||||
"current_vessel": "",
|
||||
"current_speed": 0.0,
|
||||
@@ -187,12 +271,13 @@ class VirtualStirrer:
|
||||
"remaining_time": 0.0,
|
||||
})
|
||||
|
||||
self.logger.info(f"✅ 搅拌器已停止 {vessel} 的搅拌操作 🏁")
|
||||
return True
|
||||
|
||||
# 状态属性
|
||||
@property
|
||||
def status(self) -> str:
|
||||
return self.data.get("status", "Idle")
|
||||
return self.data.get("status", "🏠 待机中")
|
||||
|
||||
@property
|
||||
def operation_mode(self) -> str:
|
||||
@@ -212,4 +297,33 @@ class VirtualStirrer:
|
||||
|
||||
@property
|
||||
def remaining_time(self) -> float:
|
||||
return self.data.get("remaining_time", 0.0)
|
||||
return self.data.get("remaining_time", 0.0)
|
||||
|
||||
@property
|
||||
def max_speed(self) -> float:
|
||||
return self._max_speed
|
||||
|
||||
@property
|
||||
def min_speed(self) -> float:
|
||||
return self._min_speed
|
||||
|
||||
def get_device_info(self) -> Dict[str, Any]:
|
||||
"""获取设备状态信息 📊"""
|
||||
info = {
|
||||
"device_id": self.device_id,
|
||||
"status": self.status,
|
||||
"operation_mode": self.operation_mode,
|
||||
"current_vessel": self.current_vessel,
|
||||
"current_speed": self.current_speed,
|
||||
"is_stirring": self.is_stirring,
|
||||
"remaining_time": self.remaining_time,
|
||||
"max_speed": self._max_speed,
|
||||
"min_speed": self._min_speed
|
||||
}
|
||||
|
||||
self.logger.debug(f"📊 设备信息: 模式={self.operation_mode}, 速度={self.current_speed} RPM, 搅拌={self.is_stirring}")
|
||||
return info
|
||||
|
||||
def __str__(self):
|
||||
status_emoji = "✅" if self.operation_mode == "Idle" else "🌪️" if self.operation_mode == "Stirring" else "🛑" if self.operation_mode == "Settling" else "❌"
|
||||
return f"🌪️ VirtualStirrer({status_emoji} {self.device_id}: {self.operation_mode}, {self.current_speed} RPM)"
|
||||
@@ -12,7 +12,7 @@ class VirtualPumpMode(Enum):
|
||||
|
||||
|
||||
class VirtualTransferPump:
|
||||
"""虚拟转移泵类 - 模拟泵的基本功能,无需实际硬件"""
|
||||
"""虚拟转移泵类 - 模拟泵的基本功能,无需实际硬件 🚰"""
|
||||
|
||||
def __init__(self, device_id: str = None, config: dict = None, **kwargs):
|
||||
"""
|
||||
@@ -42,20 +42,31 @@ class VirtualTransferPump:
|
||||
self._max_velocity = 5.0 # float
|
||||
self._current_volume = 0.0 # float
|
||||
|
||||
# 🚀 新增:快速模式设置 - 大幅缩短执行时间
|
||||
self._fast_mode = True # 是否启用快速模式
|
||||
self._fast_move_time = 1.0 # 快速移动时间(秒)
|
||||
self._fast_dispense_time = 1.0 # 快速喷射时间(秒)
|
||||
|
||||
self.logger = logging.getLogger(f"VirtualTransferPump.{self.device_id}")
|
||||
|
||||
print(f"🚰 === 虚拟转移泵 {self.device_id} 已创建 === ✨")
|
||||
print(f"💨 快速模式: {'启用' if self._fast_mode else '禁用'} | 移动时间: {self._fast_move_time}s | 喷射时间: {self._fast_dispense_time}s")
|
||||
print(f"📊 最大容量: {self.max_volume}mL | 端口: {self.port}")
|
||||
|
||||
async def initialize(self) -> bool:
|
||||
"""初始化虚拟泵"""
|
||||
self.logger.info(f"Initializing virtual pump {self.device_id}")
|
||||
"""初始化虚拟泵 🚀"""
|
||||
self.logger.info(f"🔧 初始化虚拟转移泵 {self.device_id} ✨")
|
||||
self._status = "Idle"
|
||||
self._position = 0.0
|
||||
self._current_volume = 0.0
|
||||
self.logger.info(f"✅ 转移泵 {self.device_id} 初始化完成 🚰")
|
||||
return True
|
||||
|
||||
async def cleanup(self) -> bool:
|
||||
"""清理虚拟泵"""
|
||||
self.logger.info(f"Cleaning up virtual pump {self.device_id}")
|
||||
"""清理虚拟泵 🧹"""
|
||||
self.logger.info(f"🧹 清理虚拟转移泵 {self.device_id} 🔚")
|
||||
self._status = "Idle"
|
||||
self.logger.info(f"✅ 转移泵 {self.device_id} 清理完成 💤")
|
||||
return True
|
||||
|
||||
# 基本属性
|
||||
@@ -65,12 +76,12 @@ class VirtualTransferPump:
|
||||
|
||||
@property
|
||||
def position(self) -> float:
|
||||
"""当前柱塞位置 (ml)"""
|
||||
"""当前柱塞位置 (ml) 📍"""
|
||||
return self._position
|
||||
|
||||
@property
|
||||
def current_volume(self) -> float:
|
||||
"""当前注射器中的体积 (ml)"""
|
||||
"""当前注射器中的体积 (ml) 💧"""
|
||||
return self._current_volume
|
||||
|
||||
@property
|
||||
@@ -82,22 +93,50 @@ class VirtualTransferPump:
|
||||
return self._transfer_rate
|
||||
|
||||
def set_max_velocity(self, velocity: float):
|
||||
"""设置最大速度 (ml/s)"""
|
||||
"""设置最大速度 (ml/s) 🌊"""
|
||||
self._max_velocity = max(0.1, min(50.0, velocity)) # 限制在合理范围内
|
||||
self.logger.info(f"Set max velocity to {self._max_velocity} ml/s")
|
||||
self.logger.info(f"🌊 设置最大速度为 {self._max_velocity} mL/s")
|
||||
|
||||
def get_status(self) -> str:
|
||||
"""获取泵状态"""
|
||||
"""获取泵状态 📋"""
|
||||
return self._status
|
||||
|
||||
async def _simulate_operation(self, duration: float):
|
||||
"""模拟操作延时"""
|
||||
"""模拟操作延时 ⏱️"""
|
||||
self._status = "Busy"
|
||||
await asyncio.sleep(duration)
|
||||
self._status = "Idle"
|
||||
|
||||
def _calculate_duration(self, volume: float, velocity: float = None) -> float:
|
||||
"""计算操作持续时间"""
|
||||
"""
|
||||
计算操作持续时间 ⏰
|
||||
🚀 快速模式:保留计算逻辑用于日志显示,但实际使用固定的快速时间
|
||||
"""
|
||||
if velocity is None:
|
||||
velocity = self._max_velocity
|
||||
|
||||
# 📊 计算理论时间(用于日志显示)
|
||||
theoretical_duration = abs(volume) / velocity
|
||||
|
||||
# 🚀 如果启用快速模式,使用固定的快速时间
|
||||
if self._fast_mode:
|
||||
# 根据操作类型选择快速时间
|
||||
if abs(volume) > 0.1: # 大于0.1mL的操作
|
||||
actual_duration = self._fast_move_time
|
||||
else: # 很小的操作
|
||||
actual_duration = 0.5
|
||||
|
||||
self.logger.debug(f"⚡ 快速模式: 理论时间 {theoretical_duration:.2f}s → 实际时间 {actual_duration:.2f}s")
|
||||
return actual_duration
|
||||
else:
|
||||
# 正常模式使用理论时间
|
||||
return theoretical_duration
|
||||
|
||||
def _calculate_display_duration(self, volume: float, velocity: float = None) -> float:
|
||||
"""
|
||||
计算显示用的持续时间(用于日志) 📊
|
||||
这个函数返回理论计算时间,用于日志显示
|
||||
"""
|
||||
if velocity is None:
|
||||
velocity = self._max_velocity
|
||||
return abs(volume) / velocity
|
||||
@@ -105,7 +144,7 @@ class VirtualTransferPump:
|
||||
# 新的set_position方法 - 专门用于SetPumpPosition动作
|
||||
async def set_position(self, position: float, max_velocity: float = None):
|
||||
"""
|
||||
移动到绝对位置 - 专门用于SetPumpPosition动作
|
||||
移动到绝对位置 - 专门用于SetPumpPosition动作 🎯
|
||||
|
||||
Args:
|
||||
position (float): 目标位置 (ml)
|
||||
@@ -122,56 +161,107 @@ class VirtualTransferPump:
|
||||
# 限制位置在有效范围内
|
||||
target_position = max(0.0, min(float(self.max_volume), target_position))
|
||||
|
||||
# 计算移动距离和时间
|
||||
# 计算移动距离
|
||||
volume_to_move = abs(target_position - self._position)
|
||||
duration = self._calculate_duration(volume_to_move, velocity)
|
||||
|
||||
self.logger.info(f"SET_POSITION: Moving to {target_position} ml (current: {self._position} ml), velocity: {velocity} ml/s")
|
||||
# 📊 计算显示用的时间(用于日志)
|
||||
display_duration = self._calculate_display_duration(volume_to_move, velocity)
|
||||
|
||||
# 模拟移动过程
|
||||
start_position = self._position
|
||||
steps = 10 if duration > 0.1 else 1 # 如果移动距离很小,只用1步
|
||||
step_duration = duration / steps if steps > 1 else duration
|
||||
# ⚡ 计算实际执行时间(快速模式)
|
||||
actual_duration = self._calculate_duration(volume_to_move, velocity)
|
||||
|
||||
for i in range(steps + 1):
|
||||
# 计算当前位置和进度
|
||||
progress = (i / steps) * 100 if steps > 0 else 100
|
||||
current_pos = start_position + (target_position - start_position) * (i / steps) if steps > 0 else target_position
|
||||
# 🎯 确定操作类型和emoji
|
||||
if target_position > self._position:
|
||||
operation_type = "吸液"
|
||||
operation_emoji = "📥"
|
||||
elif target_position < self._position:
|
||||
operation_type = "排液"
|
||||
operation_emoji = "📤"
|
||||
else:
|
||||
operation_type = "保持"
|
||||
operation_emoji = "📍"
|
||||
|
||||
self.logger.info(f"🎯 SET_POSITION: {operation_type} {operation_emoji}")
|
||||
self.logger.info(f" 📍 位置: {self._position:.2f}mL → {target_position:.2f}mL (移动 {volume_to_move:.2f}mL)")
|
||||
self.logger.info(f" 🌊 速度: {velocity:.2f} mL/s")
|
||||
self.logger.info(f" ⏰ 预计时间: {display_duration:.2f}s")
|
||||
|
||||
if self._fast_mode:
|
||||
self.logger.info(f" ⚡ 快速模式: 实际用时 {actual_duration:.2f}s")
|
||||
|
||||
# 🚀 模拟移动过程
|
||||
if volume_to_move > 0.01: # 只有当移动距离足够大时才显示进度
|
||||
start_position = self._position
|
||||
steps = 5 if actual_duration > 0.5 else 2 # 根据实际时间调整步数
|
||||
step_duration = actual_duration / steps
|
||||
|
||||
# 更新状态
|
||||
self._status = "Moving" if i < steps else "Idle"
|
||||
self._position = current_pos
|
||||
self._current_volume = current_pos
|
||||
self.logger.info(f"🚀 开始{operation_type}... {operation_emoji}")
|
||||
|
||||
# 等待一小步时间
|
||||
if i < steps and step_duration > 0:
|
||||
await asyncio.sleep(step_duration)
|
||||
for i in range(steps + 1):
|
||||
# 计算当前位置和进度
|
||||
progress = (i / steps) * 100 if steps > 0 else 100
|
||||
current_pos = start_position + (target_position - start_position) * (i / steps) if steps > 0 else target_position
|
||||
|
||||
# 更新状态
|
||||
if i < steps:
|
||||
self._status = f"{operation_type}中"
|
||||
status_emoji = "🔄"
|
||||
else:
|
||||
self._status = "Idle"
|
||||
status_emoji = "✅"
|
||||
|
||||
self._position = current_pos
|
||||
self._current_volume = current_pos
|
||||
|
||||
# 显示进度(每25%或最后一步)
|
||||
if i == 0:
|
||||
self.logger.debug(f" 🔄 {operation_type}开始: {progress:.0f}%")
|
||||
elif progress >= 50 and i == steps // 2:
|
||||
self.logger.debug(f" 🔄 {operation_type}进度: {progress:.0f}%")
|
||||
elif i == steps:
|
||||
self.logger.info(f" ✅ {operation_type}完成: {progress:.0f}% | 当前位置: {current_pos:.2f}mL")
|
||||
|
||||
# 等待一小步时间
|
||||
if i < steps and step_duration > 0:
|
||||
await asyncio.sleep(step_duration)
|
||||
else:
|
||||
# 移动距离很小,直接完成
|
||||
self._position = target_position
|
||||
self._current_volume = target_position
|
||||
self.logger.info(f" 📍 微调完成: {target_position:.2f}mL")
|
||||
|
||||
# 确保最终位置准确
|
||||
self._position = target_position
|
||||
self._current_volume = target_position
|
||||
self._status = "Idle"
|
||||
|
||||
self.logger.info(f"SET_POSITION: Reached position {self._position} ml, current volume: {self._current_volume} ml")
|
||||
# 📊 最终状态日志
|
||||
if volume_to_move > 0.01:
|
||||
self.logger.info(f"🎉 SET_POSITION 完成! 📍 最终位置: {self._position:.2f}mL | 💧 当前体积: {self._current_volume:.2f}mL")
|
||||
|
||||
# 返回符合action定义的结果
|
||||
return {
|
||||
"success": True,
|
||||
"message": f"Successfully moved to position {self._position} ml"
|
||||
"message": f"✅ 成功移动到位置 {self._position:.2f}mL ({operation_type})",
|
||||
"final_position": self._position,
|
||||
"final_volume": self._current_volume,
|
||||
"operation_type": operation_type
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
error_msg = f"Failed to set position: {str(e)}"
|
||||
error_msg = f"❌ 设置位置失败: {str(e)}"
|
||||
self.logger.error(error_msg)
|
||||
return {
|
||||
"success": False,
|
||||
"message": error_msg
|
||||
"message": error_msg,
|
||||
"final_position": self._position,
|
||||
"final_volume": self._current_volume
|
||||
}
|
||||
|
||||
# 其他泵操作方法
|
||||
async def pull_plunger(self, volume: float, velocity: float = None):
|
||||
"""
|
||||
拉取柱塞(吸液)
|
||||
拉取柱塞(吸液) 📥
|
||||
|
||||
Args:
|
||||
volume (float): 要拉取的体积 (ml)
|
||||
@@ -181,23 +271,29 @@ class VirtualTransferPump:
|
||||
actual_volume = new_position - self._position
|
||||
|
||||
if actual_volume <= 0:
|
||||
self.logger.warning("Cannot pull - already at maximum volume")
|
||||
self.logger.warning("⚠️ 无法吸液 - 已达到最大容量")
|
||||
return
|
||||
|
||||
duration = self._calculate_duration(actual_volume, velocity)
|
||||
display_duration = self._calculate_display_duration(actual_volume, velocity)
|
||||
actual_duration = self._calculate_duration(actual_volume, velocity)
|
||||
|
||||
self.logger.info(f"Pulling {actual_volume} ml (from {self._position} to {new_position})")
|
||||
self.logger.info(f"📥 开始吸液: {actual_volume:.2f}mL")
|
||||
self.logger.info(f" 📍 位置: {self._position:.2f}mL → {new_position:.2f}mL")
|
||||
self.logger.info(f" ⏰ 预计时间: {display_duration:.2f}s")
|
||||
|
||||
await self._simulate_operation(duration)
|
||||
if self._fast_mode:
|
||||
self.logger.info(f" ⚡ 快速模式: 实际用时 {actual_duration:.2f}s")
|
||||
|
||||
await self._simulate_operation(actual_duration)
|
||||
|
||||
self._position = new_position
|
||||
self._current_volume = new_position
|
||||
|
||||
self.logger.info(f"Pulled {actual_volume} ml, current volume: {self._current_volume} ml")
|
||||
self.logger.info(f"✅ 吸液完成: {actual_volume:.2f}mL | 💧 当前体积: {self._current_volume:.2f}mL")
|
||||
|
||||
async def push_plunger(self, volume: float, velocity: float = None):
|
||||
"""
|
||||
推出柱塞(排液)
|
||||
推出柱塞(排液) 📤
|
||||
|
||||
Args:
|
||||
volume (float): 要推出的体积 (ml)
|
||||
@@ -207,35 +303,44 @@ class VirtualTransferPump:
|
||||
actual_volume = self._position - new_position
|
||||
|
||||
if actual_volume <= 0:
|
||||
self.logger.warning("Cannot push - already at minimum volume")
|
||||
self.logger.warning("⚠️ 无法排液 - 已达到最小容量")
|
||||
return
|
||||
|
||||
duration = self._calculate_duration(actual_volume, velocity)
|
||||
display_duration = self._calculate_display_duration(actual_volume, velocity)
|
||||
actual_duration = self._calculate_duration(actual_volume, velocity)
|
||||
|
||||
self.logger.info(f"Pushing {actual_volume} ml (from {self._position} to {new_position})")
|
||||
self.logger.info(f"📤 开始排液: {actual_volume:.2f}mL")
|
||||
self.logger.info(f" 📍 位置: {self._position:.2f}mL → {new_position:.2f}mL")
|
||||
self.logger.info(f" ⏰ 预计时间: {display_duration:.2f}s")
|
||||
|
||||
await self._simulate_operation(duration)
|
||||
if self._fast_mode:
|
||||
self.logger.info(f" ⚡ 快速模式: 实际用时 {actual_duration:.2f}s")
|
||||
|
||||
await self._simulate_operation(actual_duration)
|
||||
|
||||
self._position = new_position
|
||||
self._current_volume = new_position
|
||||
|
||||
self.logger.info(f"Pushed {actual_volume} ml, current volume: {self._current_volume} ml")
|
||||
self.logger.info(f"✅ 排液完成: {actual_volume:.2f}mL | 💧 当前体积: {self._current_volume:.2f}mL")
|
||||
|
||||
# 便捷操作方法
|
||||
async def aspirate(self, volume: float, velocity: float = None):
|
||||
"""吸液操作"""
|
||||
"""吸液操作 📥"""
|
||||
await self.pull_plunger(volume, velocity)
|
||||
|
||||
async def dispense(self, volume: float, velocity: float = None):
|
||||
"""排液操作"""
|
||||
"""排液操作 📤"""
|
||||
await self.push_plunger(volume, velocity)
|
||||
|
||||
async def transfer(self, volume: float, aspirate_velocity: float = None, dispense_velocity: float = None):
|
||||
"""转移操作(先吸后排)"""
|
||||
"""转移操作(先吸后排) 🔄"""
|
||||
self.logger.info(f"🔄 开始转移操作: {volume:.2f}mL")
|
||||
|
||||
# 吸液
|
||||
await self.aspirate(volume, aspirate_velocity)
|
||||
|
||||
# 短暂停顿
|
||||
self.logger.debug("⏸️ 短暂停顿...")
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
# 排液
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import socket
|
||||
import json
|
||||
import base64
|
||||
import argparse
|
||||
import sys
|
||||
import json
|
||||
import socket
|
||||
import time
|
||||
|
||||
|
||||
@@ -96,17 +94,20 @@ class ZhidaClient:
|
||||
def abort(self) -> dict:
|
||||
return self._send_command({"command": "abort"})
|
||||
|
||||
"""
|
||||
a,b,c
|
||||
1,2,4
|
||||
2,4,5
|
||||
"""
|
||||
|
||||
client = ZhidaClient()
|
||||
# 连接
|
||||
client.connect()
|
||||
# 获取状态
|
||||
print(client.status)
|
||||
if __name__ == "__main__":
|
||||
|
||||
"""
|
||||
a,b,c
|
||||
1,2,4
|
||||
2,4,5
|
||||
"""
|
||||
|
||||
client = ZhidaClient()
|
||||
# 连接
|
||||
client.connect()
|
||||
# 获取状态
|
||||
print(client.status)
|
||||
|
||||
|
||||
# 命令格式:python zhida.py <subcommand> [options]
|
||||
# 命令格式:python zhida.py <subcommand> [options]
|
||||
|
||||
@@ -10,22 +10,92 @@ class Point3D(BaseModel):
|
||||
# Start Protocols
|
||||
|
||||
class PumpTransferProtocol(BaseModel):
|
||||
from_vessel: str
|
||||
to_vessel: str
|
||||
volume: float
|
||||
# === 核心参数(保持必需) ===
|
||||
from_vessel: dict
|
||||
to_vessel: dict
|
||||
|
||||
# === 所有其他参数都改为可选,添加默认值 ===
|
||||
volume: float = 0.0 # 🔧 改为-1,表示转移全部体积
|
||||
amount: str = ""
|
||||
time: float = 0
|
||||
time: float = 0.0
|
||||
viscous: bool = False
|
||||
rinsing_solvent: str = "air"
|
||||
rinsing_volume: float = 5000
|
||||
rinsing_repeats: int = 2
|
||||
rinsing_solvent: str = ""
|
||||
rinsing_volume: float = 0.0
|
||||
rinsing_repeats: int = 0
|
||||
solid: bool = False
|
||||
flowrate: float = 500
|
||||
transfer_flowrate: float = 2500
|
||||
flowrate: float = 2.5
|
||||
transfer_flowrate: float = 0.5
|
||||
|
||||
# === 新版XDL兼容参数(可选) ===
|
||||
rate_spec: str = ""
|
||||
event: str = ""
|
||||
through: str = ""
|
||||
|
||||
def model_post_init(self, __context):
|
||||
"""后处理:智能参数处理和兼容性调整"""
|
||||
|
||||
# 如果指定了 amount 但volume是默认值,尝试解析 amount
|
||||
if self.amount and self.volume == 0.0:
|
||||
parsed_volume = self._parse_amount_to_volume(self.amount)
|
||||
if parsed_volume > 0:
|
||||
self.volume = parsed_volume
|
||||
|
||||
# 如果指定了 time 但没有明确设置流速,根据时间计算流速
|
||||
if self.time > 0 and self.volume > 0:
|
||||
if self.flowrate == 2.5 and self.transfer_flowrate == 0.5:
|
||||
calculated_flowrate = self.volume / self.time
|
||||
self.flowrate = min(calculated_flowrate, 10.0)
|
||||
self.transfer_flowrate = min(calculated_flowrate, 5.0)
|
||||
|
||||
# 🔧 核心修复:如果flowrate为0(ROS2传入),使用默认值
|
||||
if self.flowrate <= 0:
|
||||
self.flowrate = 2.5
|
||||
if self.transfer_flowrate <= 0:
|
||||
self.transfer_flowrate = 0.5
|
||||
|
||||
# 根据 rate_spec 调整流速
|
||||
if self.rate_spec == "dropwise":
|
||||
self.flowrate = min(self.flowrate, 0.1)
|
||||
self.transfer_flowrate = min(self.transfer_flowrate, 0.1)
|
||||
elif self.rate_spec == "slowly":
|
||||
self.flowrate = min(self.flowrate, 0.5)
|
||||
self.transfer_flowrate = min(self.transfer_flowrate, 0.3)
|
||||
elif self.rate_spec == "quickly":
|
||||
self.flowrate = max(self.flowrate, 5.0)
|
||||
self.transfer_flowrate = max(self.transfer_flowrate, 2.0)
|
||||
|
||||
def _parse_amount_to_volume(self, amount: str) -> float:
|
||||
"""解析 amount 字符串为体积"""
|
||||
if not amount:
|
||||
return 0.0
|
||||
|
||||
amount = amount.lower().strip()
|
||||
|
||||
# 处理特殊关键词
|
||||
if amount == "all":
|
||||
return 0.0 # 🔧 "all"也表示转移全部
|
||||
|
||||
# 提取数字
|
||||
import re
|
||||
numbers = re.findall(r'[\d.]+', amount)
|
||||
if numbers:
|
||||
volume = float(numbers[0])
|
||||
|
||||
# 单位转换
|
||||
if 'ml' in amount or 'milliliter' in amount:
|
||||
return volume
|
||||
elif 'l' in amount and 'ml' not in amount:
|
||||
return volume * 1000
|
||||
elif 'μl' in amount or 'microliter' in amount:
|
||||
return volume / 1000
|
||||
else:
|
||||
return volume
|
||||
|
||||
return 0.0
|
||||
|
||||
|
||||
class CleanProtocol(BaseModel):
|
||||
vessel: str
|
||||
vessel: dict
|
||||
solvent: str
|
||||
volume: float
|
||||
temp: float
|
||||
@@ -35,10 +105,10 @@ class CleanProtocol(BaseModel):
|
||||
class SeparateProtocol(BaseModel):
|
||||
purpose: str
|
||||
product_phase: str
|
||||
from_vessel: str
|
||||
separation_vessel: str
|
||||
to_vessel: str
|
||||
waste_phase_to_vessel: str
|
||||
from_vessel: dict
|
||||
separation_vessel: dict
|
||||
to_vessel: dict
|
||||
waste_phase_to_vessel: dict
|
||||
solvent: str
|
||||
solvent_volume: float
|
||||
through: str
|
||||
@@ -49,17 +119,96 @@ class SeparateProtocol(BaseModel):
|
||||
|
||||
|
||||
class EvaporateProtocol(BaseModel):
|
||||
vessel: str
|
||||
pressure: float
|
||||
temp: float
|
||||
time: float
|
||||
stir_speed: float
|
||||
# === 核心参数(必需) ===
|
||||
vessel: dict = Field(..., description="蒸发容器名称")
|
||||
|
||||
# === 所有其他参数都改为可选,添加默认值 ===
|
||||
pressure: float = Field(0.1, description="真空度 (bar),默认0.1 bar")
|
||||
temp: float = Field(60.0, description="加热温度 (°C),默认60°C")
|
||||
time: float = Field(180.0, description="蒸发时间 (秒),默认1800s (30分钟)")
|
||||
stir_speed: float = Field(100.0, description="旋转速度 (RPM),默认100 RPM")
|
||||
|
||||
# === 新版XDL兼容参数(可选) ===
|
||||
solvent: str = Field("", description="溶剂名称(用于识别蒸发的溶剂类型)")
|
||||
|
||||
def model_post_init(self, __context):
|
||||
"""后处理:智能参数处理和兼容性调整"""
|
||||
|
||||
# 参数范围验证和修正
|
||||
if self.pressure <= 0 or self.pressure > 1.0:
|
||||
logger.warning(f"真空度 {self.pressure} bar 超出范围,修正为 0.1 bar")
|
||||
self.pressure = 0.1
|
||||
|
||||
if self.temp < 10.0 or self.temp > 200.0:
|
||||
logger.warning(f"温度 {self.temp}°C 超出范围,修正为 60°C")
|
||||
self.temp = 60.0
|
||||
|
||||
if self.time <= 0:
|
||||
logger.warning(f"时间 {self.time}s 无效,修正为 1800s")
|
||||
self.time = 1800.0
|
||||
|
||||
if self.stir_speed < 10.0 or self.stir_speed > 300.0:
|
||||
logger.warning(f"旋转速度 {self.stir_speed} RPM 超出范围,修正为 100 RPM")
|
||||
self.stir_speed = 100.0
|
||||
|
||||
# 根据溶剂类型调整参数
|
||||
if self.solvent:
|
||||
self._adjust_parameters_by_solvent()
|
||||
|
||||
def _adjust_parameters_by_solvent(self):
|
||||
"""根据溶剂类型调整蒸发参数"""
|
||||
solvent_lower = self.solvent.lower()
|
||||
|
||||
# 水系溶剂:较高温度,较低真空度
|
||||
if any(s in solvent_lower for s in ['water', 'aqueous', 'h2o']):
|
||||
if self.temp == 60.0: # 如果是默认值,则调整
|
||||
self.temp = 80.0
|
||||
if self.pressure == 0.1:
|
||||
self.pressure = 0.2
|
||||
|
||||
# 有机溶剂:根据沸点调整
|
||||
elif any(s in solvent_lower for s in ['ethanol', 'methanol', 'acetone']):
|
||||
if self.temp == 60.0:
|
||||
self.temp = 50.0
|
||||
if self.pressure == 0.1:
|
||||
self.pressure = 0.05
|
||||
|
||||
# 高沸点溶剂:更高温度
|
||||
elif any(s in solvent_lower for s in ['dmso', 'dmi', 'toluene']):
|
||||
if self.temp == 60.0:
|
||||
self.temp = 100.0
|
||||
if self.pressure == 0.1:
|
||||
self.pressure = 0.01
|
||||
|
||||
|
||||
class EvacuateAndRefillProtocol(BaseModel):
|
||||
vessel: str
|
||||
gas: str
|
||||
repeats: int
|
||||
# === 必需参数 ===
|
||||
vessel: dict = Field(..., description="目标容器名称")
|
||||
gas: str = Field(..., description="气体名称")
|
||||
|
||||
# 🔧 删除 repeats 参数,直接在代码中硬编码为 3 次
|
||||
|
||||
def model_post_init(self, __context):
|
||||
"""后处理:参数验证和兼容性调整"""
|
||||
|
||||
# 验证气体名称
|
||||
if not self.gas.strip():
|
||||
logger.warning("气体名称为空,使用默认值 'nitrogen'")
|
||||
self.gas = "nitrogen"
|
||||
|
||||
# 标准化气体名称
|
||||
gas_aliases = {
|
||||
'n2': 'nitrogen',
|
||||
'ar': 'argon',
|
||||
'air': 'air',
|
||||
'o2': 'oxygen',
|
||||
'co2': 'carbon_dioxide',
|
||||
'h2': 'hydrogen'
|
||||
}
|
||||
|
||||
gas_lower = self.gas.lower().strip()
|
||||
if gas_lower in gas_aliases:
|
||||
self.gas = gas_aliases[gas_lower]
|
||||
|
||||
|
||||
class AGVTransferProtocol(BaseModel):
|
||||
@@ -70,7 +219,7 @@ class AGVTransferProtocol(BaseModel):
|
||||
|
||||
#=============新添加的新的协议================
|
||||
class AddProtocol(BaseModel):
|
||||
vessel: str
|
||||
vessel: dict
|
||||
reagent: str
|
||||
volume: float
|
||||
mass: float
|
||||
@@ -82,52 +231,292 @@ class AddProtocol(BaseModel):
|
||||
purpose: str
|
||||
|
||||
class CentrifugeProtocol(BaseModel):
|
||||
vessel: str
|
||||
vessel: dict
|
||||
speed: float
|
||||
time: float
|
||||
temp: float
|
||||
|
||||
class FilterProtocol(BaseModel):
|
||||
vessel: str
|
||||
filtrate_vessel: str
|
||||
stir: bool
|
||||
stir_speed: float
|
||||
temp: float
|
||||
continue_heatchill: bool
|
||||
volume: float
|
||||
# === 必需参数 ===
|
||||
vessel: dict = Field(..., description="过滤容器名称")
|
||||
|
||||
# === 可选参数 ===
|
||||
filtrate_vessel: dict = Field("", description="滤液容器名称(可选,自动查找)")
|
||||
|
||||
def model_post_init(self, __context):
|
||||
"""后处理:参数验证"""
|
||||
# 验证容器名称
|
||||
if not self.vessel.strip():
|
||||
raise ValueError("vessel 参数不能为空")
|
||||
|
||||
class HeatChillProtocol(BaseModel):
|
||||
vessel: str
|
||||
temp: float
|
||||
time: float
|
||||
stir: bool
|
||||
stir_speed: float
|
||||
purpose: str
|
||||
# === 必需参数 ===
|
||||
vessel: dict = Field(..., description="加热容器名称")
|
||||
|
||||
# === 可选参数 - 温度相关 ===
|
||||
temp: float = Field(25.0, description="目标温度 (°C)")
|
||||
temp_spec: str = Field("", description="温度规格(如 'room temperature', 'reflux')")
|
||||
|
||||
# === 可选参数 - 时间相关 ===
|
||||
time: float = Field(300.0, description="加热时间 (秒)")
|
||||
time_spec: str = Field("", description="时间规格(如 'overnight', '2 h')")
|
||||
|
||||
# === 可选参数 - 其他XDL参数 ===
|
||||
pressure: str = Field("", description="压力规格(如 '1 mbar'),不做特殊处理")
|
||||
reflux_solvent: str = Field("", description="回流溶剂名称,不做特殊处理")
|
||||
|
||||
# === 可选参数 - 搅拌相关 ===
|
||||
stir: bool = Field(False, description="是否搅拌")
|
||||
stir_speed: float = Field(300.0, description="搅拌速度 (RPM)")
|
||||
purpose: str = Field("", description="操作目的")
|
||||
|
||||
def model_post_init(self, __context):
|
||||
"""后处理:参数验证和解析"""
|
||||
|
||||
# 验证必需参数
|
||||
if not self.vessel.strip():
|
||||
raise ValueError("vessel 参数不能为空")
|
||||
|
||||
# 温度解析:优先使用 temp_spec,然后是 temp
|
||||
if self.temp_spec:
|
||||
self.temp = self._parse_temp_spec(self.temp_spec)
|
||||
|
||||
# 时间解析:优先使用 time_spec,然后是 time
|
||||
if self.time_spec:
|
||||
self.time = self._parse_time_spec(self.time_spec)
|
||||
|
||||
# 参数范围验证
|
||||
if self.temp < -50.0 or self.temp > 300.0:
|
||||
logger.warning(f"温度 {self.temp}°C 超出范围,修正为 25°C")
|
||||
self.temp = 25.0
|
||||
|
||||
if self.time < 0:
|
||||
logger.warning(f"时间 {self.time}s 无效,修正为 300s")
|
||||
self.time = 300.0
|
||||
|
||||
if self.stir_speed < 0 or self.stir_speed > 1500.0:
|
||||
logger.warning(f"搅拌速度 {self.stir_speed} RPM 超出范围,修正为 300 RPM")
|
||||
self.stir_speed = 300.0
|
||||
|
||||
def _parse_temp_spec(self, temp_spec: str) -> float:
|
||||
"""解析温度规格为具体温度"""
|
||||
|
||||
temp_spec = temp_spec.strip().lower()
|
||||
|
||||
# 特殊温度规格
|
||||
special_temps = {
|
||||
"room temperature": 25.0, # 室温
|
||||
"reflux": 78.0, # 默认回流温度(乙醇沸点)
|
||||
"ice bath": 0.0, # 冰浴
|
||||
"boiling": 100.0, # 沸腾
|
||||
"hot": 60.0, # 热
|
||||
"warm": 40.0, # 温热
|
||||
"cold": 10.0, # 冷
|
||||
}
|
||||
|
||||
if temp_spec in special_temps:
|
||||
return special_temps[temp_spec]
|
||||
|
||||
# 解析带单位的温度(如 "256 °C")
|
||||
import re
|
||||
temp_pattern = r'(\d+(?:\.\d+)?)\s*°?[cf]?'
|
||||
match = re.search(temp_pattern, temp_spec)
|
||||
|
||||
if match:
|
||||
return float(match.group(1))
|
||||
|
||||
return 25.0 # 默认室温
|
||||
|
||||
def _parse_time_spec(self, time_spec: str) -> float:
|
||||
"""解析时间规格为秒数"""
|
||||
|
||||
time_spec = time_spec.strip().lower()
|
||||
|
||||
# 特殊时间规格
|
||||
special_times = {
|
||||
"overnight": 43200.0, # 12小时
|
||||
"several hours": 10800.0, # 3小时
|
||||
"few hours": 7200.0, # 2小时
|
||||
"long time": 3600.0, # 1小时
|
||||
"short time": 300.0, # 5分钟
|
||||
}
|
||||
|
||||
if time_spec in special_times:
|
||||
return special_times[time_spec]
|
||||
|
||||
# 解析带单位的时间(如 "2 h")
|
||||
import re
|
||||
time_pattern = r'(\d+(?:\.\d+)?)\s*([a-zA-Z]+)'
|
||||
match = re.search(time_pattern, time_spec)
|
||||
|
||||
if match:
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2).lower()
|
||||
|
||||
unit_multipliers = {
|
||||
's': 1.0,
|
||||
'sec': 1.0,
|
||||
'second': 1.0,
|
||||
'seconds': 1.0,
|
||||
'min': 60.0,
|
||||
'minute': 60.0,
|
||||
'minutes': 60.0,
|
||||
'h': 3600.0,
|
||||
'hr': 3600.0,
|
||||
'hour': 3600.0,
|
||||
'hours': 3600.0,
|
||||
}
|
||||
|
||||
multiplier = unit_multipliers.get(unit, 3600.0) # 默认按小时计算
|
||||
return value * multiplier
|
||||
|
||||
return 300.0 # 默认5分钟
|
||||
|
||||
|
||||
class HeatChillStartProtocol(BaseModel):
|
||||
vessel: str
|
||||
temp: float
|
||||
purpose: str
|
||||
# === 必需参数 ===
|
||||
vessel: dict = Field(..., description="加热容器名称")
|
||||
|
||||
# === 可选参数 - 温度相关 ===
|
||||
temp: float = Field(25.0, description="目标温度 (°C)")
|
||||
temp_spec: str = Field("", description="温度规格(如 'room temperature', 'reflux')")
|
||||
|
||||
# === 可选参数 - 其他XDL参数 ===
|
||||
pressure: str = Field("", description="压力规格(如 '1 mbar'),不做特殊处理")
|
||||
reflux_solvent: str = Field("", description="回流溶剂名称,不做特殊处理")
|
||||
|
||||
# === 可选参数 - 搅拌相关 ===
|
||||
stir: bool = Field(False, description="是否搅拌")
|
||||
stir_speed: float = Field(300.0, description="搅拌速度 (RPM)")
|
||||
purpose: str = Field("", description="操作目的")
|
||||
|
||||
|
||||
class HeatChillStopProtocol(BaseModel):
|
||||
vessel: str
|
||||
# === 必需参数 ===
|
||||
vessel: dict = Field(..., description="加热容器名称")
|
||||
|
||||
|
||||
class StirProtocol(BaseModel):
|
||||
stir_time: float
|
||||
stir_speed: float
|
||||
settling_time: float
|
||||
# === 必需参数 ===
|
||||
vessel: dict = Field(..., description="搅拌容器名称")
|
||||
|
||||
# === 可选参数 ===
|
||||
time: str = Field("5 min", description="搅拌时间(如 '0.5 h', '30 min')")
|
||||
event: str = Field("", description="事件标识(如 'A', 'B')")
|
||||
time_spec: str = Field("", description="时间规格(如 'several minutes', 'overnight')")
|
||||
|
||||
def model_post_init(self, __context):
|
||||
"""后处理:参数验证和时间解析"""
|
||||
|
||||
# 验证必需参数
|
||||
if not self.vessel.strip():
|
||||
raise ValueError("vessel 参数不能为空")
|
||||
|
||||
# 优先使用 time_spec,然后是 time
|
||||
if self.time_spec:
|
||||
self.time = self.time_spec
|
||||
|
||||
# 时间解析和验证
|
||||
if self.time:
|
||||
try:
|
||||
# 解析时间字符串为秒数
|
||||
parsed_time = self._parse_time_string(self.time)
|
||||
if parsed_time <= 0:
|
||||
logger.warning(f"时间 '{self.time}' 解析结果无效,使用默认值 300s")
|
||||
self.time = "5 min"
|
||||
except Exception as e:
|
||||
logger.warning(f"时间 '{self.time}' 解析失败: {e},使用默认值 300s")
|
||||
self.time = "5 min"
|
||||
|
||||
def _parse_time_string(self, time_str: str) -> float:
|
||||
"""解析时间字符串为秒数"""
|
||||
import re
|
||||
|
||||
time_str = time_str.strip().lower()
|
||||
|
||||
# 特殊时间规格
|
||||
special_times = {
|
||||
"several minutes": 300.0, # 5分钟
|
||||
"few minutes": 180.0, # 3分钟
|
||||
"overnight": 43200.0, # 12小时
|
||||
"room temperature": 300.0, # 默认5分钟
|
||||
}
|
||||
|
||||
if time_str in special_times:
|
||||
return special_times[time_str]
|
||||
|
||||
# 正则表达式匹配数字和单位
|
||||
pattern = r'(\d+\.?\d*)\s*([a-zA-Z]+)'
|
||||
match = re.match(pattern, time_str)
|
||||
|
||||
if not match:
|
||||
return 300.0 # 默认5分钟
|
||||
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2).lower()
|
||||
|
||||
# 时间单位转换
|
||||
unit_multipliers = {
|
||||
's': 1.0,
|
||||
'sec': 1.0,
|
||||
'second': 1.0,
|
||||
'seconds': 1.0,
|
||||
'min': 60.0,
|
||||
'minute': 60.0,
|
||||
'minutes': 60.0,
|
||||
'h': 3600.0,
|
||||
'hr': 3600.0,
|
||||
'hour': 3600.0,
|
||||
'hours': 3600.0,
|
||||
'd': 86400.0,
|
||||
'day': 86400.0,
|
||||
'days': 86400.0,
|
||||
}
|
||||
|
||||
multiplier = unit_multipliers.get(unit, 60.0) # 默认按分钟计算
|
||||
return value * multiplier
|
||||
|
||||
def get_time_in_seconds(self) -> float:
|
||||
"""获取时间(秒)"""
|
||||
return self._parse_time_string(self.time)
|
||||
|
||||
class StartStirProtocol(BaseModel):
|
||||
vessel: str
|
||||
stir_speed: float
|
||||
purpose: str
|
||||
# === 必需参数 ===
|
||||
vessel: dict = Field(..., description="搅拌容器名称")
|
||||
|
||||
# === 可选参数,添加默认值 ===
|
||||
stir_speed: float = Field(200.0, description="搅拌速度 (RPM),默认200 RPM")
|
||||
purpose: str = Field("", description="搅拌目的(可选)")
|
||||
|
||||
def model_post_init(self, __context):
|
||||
"""后处理:参数验证和修正"""
|
||||
|
||||
# 验证必需参数
|
||||
if not self.vessel.strip():
|
||||
raise ValueError("vessel 参数不能为空")
|
||||
|
||||
# 修正参数范围
|
||||
if self.stir_speed < 10.0:
|
||||
logger.warning(f"搅拌速度 {self.stir_speed} RPM 过低,修正为 100 RPM")
|
||||
self.stir_speed = 100.0
|
||||
elif self.stir_speed > 1500.0:
|
||||
logger.warning(f"搅拌速度 {self.stir_speed} RPM 过高,修正为 1000 RPM")
|
||||
self.stir_speed = 1000.0
|
||||
|
||||
class StopStirProtocol(BaseModel):
|
||||
vessel: str
|
||||
# === 必需参数 ===
|
||||
vessel: dict = Field(..., description="搅拌容器名称")
|
||||
|
||||
def model_post_init(self, __context):
|
||||
"""后处理:参数验证"""
|
||||
|
||||
# 验证必需参数
|
||||
if not self.vessel.strip():
|
||||
raise ValueError("vessel 参数不能为空")
|
||||
|
||||
class TransferProtocol(BaseModel):
|
||||
from_vessel: str
|
||||
to_vessel: str
|
||||
from_vessel: dict
|
||||
to_vessel: dict
|
||||
volume: float
|
||||
amount: str = ""
|
||||
time: float = 0
|
||||
@@ -138,14 +527,14 @@ class TransferProtocol(BaseModel):
|
||||
solid: bool = False
|
||||
|
||||
class CleanVesselProtocol(BaseModel):
|
||||
vessel: str
|
||||
vessel: dict
|
||||
solvent: str
|
||||
volume: float
|
||||
temp: float
|
||||
repeats: int = 1
|
||||
|
||||
class DissolveProtocol(BaseModel):
|
||||
vessel: str
|
||||
vessel: dict
|
||||
solvent: str
|
||||
volume: float
|
||||
amount: str = ""
|
||||
@@ -154,8 +543,8 @@ class DissolveProtocol(BaseModel):
|
||||
stir_speed: float = 0.0
|
||||
|
||||
class FilterThroughProtocol(BaseModel):
|
||||
from_vessel: str
|
||||
to_vessel: str
|
||||
from_vessel: dict
|
||||
to_vessel: dict
|
||||
filter_through: str
|
||||
eluting_solvent: str = ""
|
||||
eluting_volume: float = 0.0
|
||||
@@ -163,28 +552,92 @@ class FilterThroughProtocol(BaseModel):
|
||||
residence_time: float = 0.0
|
||||
|
||||
class RunColumnProtocol(BaseModel):
|
||||
from_vessel: str
|
||||
to_vessel: str
|
||||
from_vessel: dict
|
||||
to_vessel: dict
|
||||
column: str
|
||||
|
||||
class WashSolidProtocol(BaseModel):
|
||||
vessel: str
|
||||
solvent: str
|
||||
volume: float
|
||||
filtrate_vessel: str = ""
|
||||
temp: float = 25.0
|
||||
stir: bool = False
|
||||
stir_speed: float = 0.0
|
||||
time: float = 0.0
|
||||
repeats: int = 1
|
||||
# === 必需参数 ===
|
||||
vessel: dict = Field(..., description="装有固体的容器名称")
|
||||
solvent: str = Field(..., description="清洗溶剂名称")
|
||||
volume: float = Field(..., description="清洗溶剂体积 (mL)")
|
||||
|
||||
# === 可选参数,添加默认值 ===
|
||||
filtrate_vessel: dict = Field("", description="滤液收集容器(可选,自动查找)")
|
||||
temp: float = Field(25.0, description="清洗温度 (°C),默认25°C")
|
||||
stir: bool = Field(False, description="是否搅拌,默认False")
|
||||
stir_speed: float = Field(0.0, description="搅拌速度 (RPM),默认0")
|
||||
time: float = Field(0.0, description="清洗时间 (秒),默认0")
|
||||
repeats: int = Field(1, description="重复次数,默认1")
|
||||
|
||||
def model_post_init(self, __context):
|
||||
"""后处理:参数验证和修正"""
|
||||
|
||||
# 验证必需参数
|
||||
if not self.vessel.strip():
|
||||
raise ValueError("vessel 参数不能为空")
|
||||
|
||||
if not self.solvent.strip():
|
||||
raise ValueError("solvent 参数不能为空")
|
||||
|
||||
if self.volume <= 0:
|
||||
raise ValueError("volume 必须大于0")
|
||||
|
||||
# 修正参数范围
|
||||
if self.temp < 0 or self.temp > 200:
|
||||
logger.warning(f"温度 {self.temp}°C 超出范围,修正为 25°C")
|
||||
self.temp = 25.0
|
||||
|
||||
if self.stir_speed < 0 or self.stir_speed > 500:
|
||||
logger.warning(f"搅拌速度 {self.stir_speed} RPM 超出范围,修正为 0")
|
||||
self.stir_speed = 0.0
|
||||
|
||||
if self.time < 0:
|
||||
logger.warning(f"时间 {self.time}s 无效,修正为 0")
|
||||
self.time = 0.0
|
||||
|
||||
if self.repeats < 1:
|
||||
logger.warning(f"重复次数 {self.repeats} 无效,修正为 1")
|
||||
self.repeats = 1
|
||||
elif self.repeats > 10:
|
||||
logger.warning(f"重复次数 {self.repeats} 过多,修正为 10")
|
||||
self.repeats = 10
|
||||
|
||||
class AdjustPHProtocol(BaseModel):
|
||||
vessel: dict = Field(..., description="目标容器")
|
||||
ph_value: float = Field(..., description="目标pH值") # 改为 ph_value
|
||||
reagent: str = Field(..., description="酸碱试剂名称")
|
||||
# 移除其他可选参数,使用默认值
|
||||
|
||||
class ResetHandlingProtocol(BaseModel):
|
||||
solvent: str = Field(..., description="溶剂名称")
|
||||
|
||||
class DryProtocol(BaseModel):
|
||||
compound: str = Field(..., description="化合物名称")
|
||||
vessel: dict = Field(..., description="目标容器")
|
||||
|
||||
class RecrystallizeProtocol(BaseModel):
|
||||
ratio: str = Field(..., description="溶剂比例(如 '1:1', '3:7')")
|
||||
solvent1: str = Field(..., description="第一种溶剂名称")
|
||||
solvent2: str = Field(..., description="第二种溶剂名称")
|
||||
vessel: dict = Field(..., description="目标容器")
|
||||
volume: float = Field(..., description="总体积 (mL)")
|
||||
|
||||
class HydrogenateProtocol(BaseModel):
|
||||
temp: str = Field(..., description="反应温度(如 '45 °C')")
|
||||
time: str = Field(..., description="反应时间(如 '2 h')")
|
||||
vessel: dict = Field(..., description="反应容器")
|
||||
|
||||
__all__ = [
|
||||
"Point3D", "PumpTransferProtocol", "CleanProtocol", "SeparateProtocol",
|
||||
"EvaporateProtocol", "EvacuateAndRefillProtocol", "AGVTransferProtocol",
|
||||
"CentrifugeProtocol", "AddProtocol", "FilterProtocol",
|
||||
"HeatChillProtocol", "HeatChillStartProtocol", "HeatChillStopProtocol",
|
||||
"HeatChillProtocol",
|
||||
"HeatChillStartProtocol", "HeatChillStopProtocol",
|
||||
"StirProtocol", "StartStirProtocol", "StopStirProtocol",
|
||||
"TransferProtocol", "CleanVesselProtocol", "DissolveProtocol",
|
||||
"FilterThroughProtocol", "RunColumnProtocol", "WashSolidProtocol"
|
||||
"FilterThroughProtocol", "RunColumnProtocol", "WashSolidProtocol",
|
||||
"AdjustPHProtocol", "ResetHandlingProtocol", "DryProtocol",
|
||||
"RecrystallizeProtocol", "HydrogenateProtocol"
|
||||
]
|
||||
# End Protocols
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
io_snrd:
|
||||
description: IO Board with 16 IOs
|
||||
class:
|
||||
module: ilabos.device_comms.SRND_16_IO:SRND_16_IO
|
||||
type: python
|
||||
hardware_interface:
|
||||
name: modbus_client
|
||||
extra_info: []
|
||||
read: read_io_coil
|
||||
write: write_io_coil
|
||||
#io_snrd:
|
||||
# description: IO Board with 16 IOs
|
||||
# class:
|
||||
# module: unilabos.device_comms.SRND_16_IO:SRND_16_IO
|
||||
# type: python
|
||||
# hardware_interface:
|
||||
# name: modbus_client
|
||||
# extra_info: []
|
||||
# read: read_io_coil
|
||||
# write: write_io_coil
|
||||
@@ -1,7 +1,106 @@
|
||||
serial:
|
||||
description: Serial communication interface, used when sharing same serial port for multiple devices
|
||||
category:
|
||||
- serial
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-handle_serial_request:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
request: null
|
||||
response: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: handle_serial_request的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
request:
|
||||
type: string
|
||||
response:
|
||||
type: string
|
||||
required:
|
||||
- request
|
||||
- response
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: handle_serial_request参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-read_data:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: read_data的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: read_data参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-send_command:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
command: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: send_command的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: send_command参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
module: unilabos.ros.nodes.presets.serial_node:ROS2SerialNode
|
||||
status_types: {}
|
||||
type: ros2
|
||||
schema:
|
||||
properties: {}
|
||||
config_info: []
|
||||
description: Serial communication interface, used when sharing same serial port
|
||||
for multiple devices
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
baudrate:
|
||||
default: 9600
|
||||
type: integer
|
||||
device_id:
|
||||
type: string
|
||||
port:
|
||||
type: string
|
||||
resource_tracker:
|
||||
type: string
|
||||
required:
|
||||
- device_id
|
||||
- port
|
||||
type: object
|
||||
data:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
73
unilabos/registry/devices/camera.yaml
Normal file
73
unilabos/registry/devices/camera.yaml
Normal file
@@ -0,0 +1,73 @@
|
||||
camera:
|
||||
category:
|
||||
- camera
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-destroy_node:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 用于安全地关闭摄像头设备,释放摄像头资源,停止视频采集和发布服务。调用此函数将清理OpenCV摄像头连接并销毁ROS2节点。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: destroy_node参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-timer_callback:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 定时器回调函数的参数schema。此函数负责定期采集摄像头视频帧,将OpenCV格式的图像转换为ROS Image消息格式,并发布到指定的视频话题。默认以10Hz频率执行,确保视频流的连续性和实时性。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: timer_callback参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
module: unilabos.ros.nodes.presets.camera:VideoPublisher
|
||||
status_types: {}
|
||||
type: ros2
|
||||
config_info: []
|
||||
description: VideoPublisher摄像头设备节点,用于实时视频采集和流媒体发布。该设备通过OpenCV连接本地摄像头(如USB摄像头、内置摄像头等),定时采集视频帧并将其转换为ROS2的sensor_msgs/Image消息格式发布到视频话题。主要用于实验室自动化系统中的视觉监控、图像分析、实时观察等应用场景。支持可配置的摄像头索引、发布频率等参数。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
camera_index:
|
||||
default: 0
|
||||
type: string
|
||||
device_id:
|
||||
default: video_publisher
|
||||
type: string
|
||||
period:
|
||||
default: 0.1
|
||||
type: number
|
||||
resource_tracker:
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
data:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
version: 1.0.0
|
||||
@@ -1,67 +1,411 @@
|
||||
# 光学表征设备:红外、紫外可见、拉曼等
|
||||
raman_home_made:
|
||||
description: Raman spectroscopy device
|
||||
class:
|
||||
module: unilabos.devices.raman_uv.home_made_raman:RamanObj
|
||||
type: python
|
||||
status_types:
|
||||
status: String
|
||||
action_value_mappings:
|
||||
raman_cmd:
|
||||
type: SendCmd
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
additionalProperties: false
|
||||
type: object
|
||||
hplc.agilent:
|
||||
description: HPLC device
|
||||
category:
|
||||
- characterization_optic
|
||||
class:
|
||||
module: unilabos.devices.hplc.AgilentHPLC:HPLCDriver
|
||||
type: python
|
||||
status_types:
|
||||
device_status: String
|
||||
could_run: Bool
|
||||
driver_init_ok: Bool
|
||||
is_running: Bool
|
||||
finish_status: String
|
||||
status_text: String
|
||||
action_value_mappings:
|
||||
auto-check_status:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 检查安捷伦HPLC设备状态的函数。用于监控设备的运行状态、连接状态、错误信息等关键指标。该函数定期查询设备状态,确保系统稳定运行,及时发现和报告设备异常。适用于自动化流程中的设备监控、故障诊断、系统维护等场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: check_status参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-extract_data_from_txt:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
file_path: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 从文本文件中提取分析数据的函数。用于解析安捷伦HPLC生成的结果文件,提取峰面积、保留时间、浓度等关键分析数据。支持多种文件格式的自动识别和数据结构化处理,为后续数据分析和报告生成提供标准化的数据格式。适用于批量数据处理、结果验证、质量控制等分析工作流程。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
file_path:
|
||||
type: string
|
||||
required:
|
||||
- file_path
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: extract_data_from_txt参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-start_sequence:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
params: null
|
||||
resource: null
|
||||
wf_name: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 启动安捷伦HPLC分析序列的函数。用于执行预定义的分析方法序列,包括样品进样、色谱分离、检测等完整的分析流程。支持参数配置、资源分配、工作流程管理等功能,实现全自动的样品分析。适用于批量样品处理、标准化分析、质量检测等需要连续自动分析的应用场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
params:
|
||||
type: string
|
||||
resource:
|
||||
type: object
|
||||
wf_name:
|
||||
type: string
|
||||
required:
|
||||
- wf_name
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: start_sequence参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-try_close_sub_device:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
device_name: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 尝试关闭HPLC子设备的函数。用于安全地关闭泵、检测器、进样器等各个子模块,确保设备正常断开连接并保护硬件安全。该函数提供错误处理和状态确认机制,避免强制关闭可能造成的设备损坏。适用于设备维护、系统重启、紧急停机等需要安全关闭设备的场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
device_name:
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: try_close_sub_device参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-try_open_sub_device:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
device_name: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 尝试打开HPLC子设备的函数。用于初始化和连接泵、检测器、进样器等各个子模块,建立设备通信并进行自检。该函数提供连接验证和错误恢复机制,确保子设备正常启动并准备就绪。适用于设备初始化、系统启动、设备重连等需要建立设备连接的场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
device_name:
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: try_open_sub_device参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
execute_command_from_outer:
|
||||
type: SendCmd
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
properties:
|
||||
device_status:
|
||||
type: string
|
||||
could_run:
|
||||
type: boolean
|
||||
driver_init_ok:
|
||||
type: boolean
|
||||
is_running:
|
||||
type: boolean
|
||||
finish_status:
|
||||
type: string
|
||||
status_text:
|
||||
type: string
|
||||
required:
|
||||
- device_status
|
||||
- could_run
|
||||
- driver_init_ok
|
||||
- is_running
|
||||
- finish_status
|
||||
- status_text
|
||||
additionalProperties: false
|
||||
type: object
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.hplc.AgilentHPLC:HPLCDriver
|
||||
status_types:
|
||||
could_run: bool
|
||||
data_file: list
|
||||
device_status: str
|
||||
driver_init_ok: bool
|
||||
finish_status: str
|
||||
is_running: bool
|
||||
status_text: str
|
||||
success: bool
|
||||
type: python
|
||||
config_info: []
|
||||
description: 安捷伦高效液相色谱(HPLC)分析设备,用于复杂化合物的分离、检测和定量分析。该设备通过UI自动化技术控制安捷伦ChemStation软件,实现全自动的样品分析流程。具备序列启动、设备状态监控、数据文件提取、结果处理等功能。支持多样品批量处理和实时状态反馈,适用于药物分析、环境检测、食品安全、化学研究等需要高精度色谱分析的实验室应用。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
driver_debug:
|
||||
default: false
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
could_run:
|
||||
type: boolean
|
||||
data_file:
|
||||
type: array
|
||||
device_status:
|
||||
type: string
|
||||
driver_init_ok:
|
||||
type: boolean
|
||||
finish_status:
|
||||
type: string
|
||||
is_running:
|
||||
type: boolean
|
||||
status_text:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- status_text
|
||||
- device_status
|
||||
- could_run
|
||||
- driver_init_ok
|
||||
- is_running
|
||||
- success
|
||||
- finish_status
|
||||
- data_file
|
||||
type: object
|
||||
version: 1.0.0
|
||||
raman_home_made:
|
||||
category:
|
||||
- characterization_optic
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-ccd_time:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
int_time: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 设置CCD检测器积分时间的函数。用于配置拉曼光谱仪的信号采集时间,控制光谱数据的质量和信噪比。较长的积分时间可获得更高的信号强度和更好的光谱质量,但会增加测量时间。该函数允许根据样品特性和测量要求动态调整检测参数,优化测量效果。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
int_time:
|
||||
type: string
|
||||
required:
|
||||
- int_time
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: ccd_time参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-laser_on_power:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
output_voltage_laser: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 设置激光器输出功率的函数。用于控制拉曼光谱仪激光器的功率输出,调节激光强度以适应不同样品的测量需求。适当的激光功率能够获得良好的拉曼信号同时避免样品损伤。该函数支持精确的功率控制,确保测量结果的稳定性和重现性。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
output_voltage_laser:
|
||||
type: string
|
||||
required:
|
||||
- output_voltage_laser
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: laser_on_power参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-raman_without_background:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
int_time: null
|
||||
laser_power: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 执行无背景扣除的拉曼光谱测量函数。用于直接采集样品的拉曼光谱信号,不进行背景校正处理。该函数配置积分时间和激光功率参数,获取原始光谱数据用于后续的数据处理分析。适用于对光谱数据质量要求较高或需要自定义背景处理流程的测量场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
int_time:
|
||||
type: string
|
||||
laser_power:
|
||||
type: string
|
||||
required:
|
||||
- int_time
|
||||
- laser_power
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: raman_without_background参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-raman_without_background_average:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
average: null
|
||||
int_time: null
|
||||
laser_power: null
|
||||
sample_name: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 执行多次平均的无背景拉曼光谱测量函数。通过多次测量取平均值来提高光谱数据的信噪比和测量精度,减少随机噪声影响。该函数支持自定义平均次数、积分时间、激光功率等参数,并可为样品指定名称便于数据管理。适用于对测量精度要求较高的定量分析和研究应用。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
average:
|
||||
type: string
|
||||
int_time:
|
||||
type: string
|
||||
laser_power:
|
||||
type: string
|
||||
sample_name:
|
||||
type: string
|
||||
required:
|
||||
- sample_name
|
||||
- int_time
|
||||
- laser_power
|
||||
- average
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: raman_without_background_average参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
raman_cmd:
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.raman_uv.home_made_raman:RamanObj
|
||||
status_types: {}
|
||||
type: python
|
||||
config_info: []
|
||||
description: 拉曼光谱分析设备,用于物质的分子结构和化学成分表征。该设备集成激光器和CCD检测器,通过串口通信控制激光功率和光谱采集。具备背景扣除、多次平均、自动数据处理等功能,支持高精度的拉曼光谱测量。适用于材料表征、化学分析、质量控制、研究开发等需要分子指纹识别和结构分析的实验应用。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
baudrate_ccd:
|
||||
default: 921600
|
||||
type: string
|
||||
baudrate_laser:
|
||||
default: 9600
|
||||
type: string
|
||||
port_ccd:
|
||||
type: string
|
||||
port_laser:
|
||||
type: string
|
||||
required:
|
||||
- port_laser
|
||||
- port_ccd
|
||||
type: object
|
||||
data:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,9 +1,35 @@
|
||||
hotel.thermo_orbitor_rs2_hotel:
|
||||
description: Thermo Orbitor RS2 Hotel
|
||||
class:
|
||||
category:
|
||||
- hotel
|
||||
class:
|
||||
action_value_mappings: {}
|
||||
module: unilabos.devices.resource_container.container:HotelContainer
|
||||
status_types:
|
||||
rotation: String
|
||||
type: python
|
||||
config_info: []
|
||||
description: Thermo Orbitor RS2 Hotel容器设备,用于实验室样品的存储和管理。该设备通过HotelContainer类实现容器的旋转控制和状态监控,主要用于存储实验样品、试剂瓶或其他实验器具,支持旋转功能以便于样品的自动化存取。适用于需要有序存储和快速访问大量样品的实验室自动化场景。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
device_config:
|
||||
type: object
|
||||
rotation:
|
||||
type: object
|
||||
required:
|
||||
- rotation
|
||||
- device_config
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
rotation:
|
||||
type: string
|
||||
required:
|
||||
- rotation
|
||||
type: object
|
||||
model:
|
||||
type: device
|
||||
mesh: thermo_orbitor_rs2_hotel
|
||||
|
||||
type: device
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,56 +1,385 @@
|
||||
laiyu_add_solid:
|
||||
description: Laiyu Add Solid
|
||||
category:
|
||||
- laiyu_add_solid
|
||||
class:
|
||||
module: unilabos.devices.laiyu_add_solid.laiyu:Laiyu
|
||||
type: python
|
||||
status_types: {}
|
||||
action_value_mappings:
|
||||
add_powder_tube:
|
||||
feedback: {}
|
||||
goal:
|
||||
compound_mass: compound_mass
|
||||
powder_tube_number: powder_tube_number
|
||||
target_tube_position: target_tube_position
|
||||
goal_default:
|
||||
compound_mass: 0.0
|
||||
powder_tube_number: 0
|
||||
target_tube_position: ''
|
||||
handles: []
|
||||
result:
|
||||
actual_mass_mg: actual_mass_mg
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: SolidDispenseAddPowderTube_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
compound_mass:
|
||||
type: number
|
||||
powder_tube_number:
|
||||
maximum: 2147483647
|
||||
minimum: -2147483648
|
||||
type: integer
|
||||
target_tube_position:
|
||||
type: string
|
||||
required:
|
||||
- powder_tube_number
|
||||
- target_tube_position
|
||||
- compound_mass
|
||||
title: SolidDispenseAddPowderTube_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
actual_mass_mg:
|
||||
type: number
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- actual_mass_mg
|
||||
- success
|
||||
title: SolidDispenseAddPowderTube_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SolidDispenseAddPowderTube
|
||||
type: object
|
||||
type: SolidDispenseAddPowderTube
|
||||
auto-calculate_crc:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
data: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: Modbus CRC-16校验码计算函数。计算Modbus RTU通信协议所需的CRC-16校验码,确保数据传输的完整性和可靠性。该函数实现标准的CRC-16算法,用于构造完整的Modbus指令帧。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
data:
|
||||
type: string
|
||||
required:
|
||||
- data
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: calculate_crc参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-send_command:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
command: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: Modbus指令发送函数。构造完整的Modbus RTU指令帧(包含CRC校验),发送给分装设备并等待响应。该函数处理底层通信协议,确保指令的正确传输和响应接收,支持最长3分钟的响应等待时间。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: send_command参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
discharge:
|
||||
feedback: {}
|
||||
goal:
|
||||
float_input: float_input
|
||||
goal_default:
|
||||
float_in: 0.0
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: FloatSingleInput_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
float_in:
|
||||
type: number
|
||||
required:
|
||||
- float_in
|
||||
title: FloatSingleInput_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: FloatSingleInput_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: FloatSingleInput
|
||||
type: object
|
||||
type: FloatSingleInput
|
||||
move_to_plate:
|
||||
feedback: {}
|
||||
goal:
|
||||
string: string
|
||||
goal_default:
|
||||
string: ''
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: StrSingleInput_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
string:
|
||||
type: string
|
||||
required:
|
||||
- string
|
||||
title: StrSingleInput_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: StrSingleInput_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: StrSingleInput
|
||||
type: object
|
||||
type: StrSingleInput
|
||||
move_to_xyz:
|
||||
type: Point3DSeparateInput
|
||||
feedback: {}
|
||||
goal:
|
||||
x: x
|
||||
y: y
|
||||
z: z
|
||||
feedback: {}
|
||||
goal_default:
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: Point3DSeparateInput_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
x:
|
||||
type: number
|
||||
y:
|
||||
type: number
|
||||
z:
|
||||
type: number
|
||||
required:
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
title: Point3DSeparateInput_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: Point3DSeparateInput_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: Point3DSeparateInput
|
||||
type: object
|
||||
type: Point3DSeparateInput
|
||||
pick_powder_tube:
|
||||
type: IntSingleInput
|
||||
feedback: {}
|
||||
goal:
|
||||
int_input: int_input
|
||||
feedback: {}
|
||||
goal_default:
|
||||
int_input: 0
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: IntSingleInput_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
int_input:
|
||||
maximum: 2147483647
|
||||
minimum: -2147483648
|
||||
type: integer
|
||||
required:
|
||||
- int_input
|
||||
title: IntSingleInput_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: IntSingleInput_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: IntSingleInput
|
||||
type: object
|
||||
type: IntSingleInput
|
||||
put_powder_tube:
|
||||
type: IntSingleInput
|
||||
feedback: {}
|
||||
goal:
|
||||
int_input: int_input
|
||||
feedback: {}
|
||||
goal_default:
|
||||
int_input: 0
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: IntSingleInput_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
int_input:
|
||||
maximum: 2147483647
|
||||
minimum: -2147483648
|
||||
type: integer
|
||||
required:
|
||||
- int_input
|
||||
title: IntSingleInput_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: IntSingleInput_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: IntSingleInput
|
||||
type: object
|
||||
type: IntSingleInput
|
||||
reset:
|
||||
type: EmptyIn
|
||||
feedback: {}
|
||||
goal: {}
|
||||
feedback: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
add_powder_tube:
|
||||
type: SolidDispenseAddPowderTube
|
||||
goal:
|
||||
powder_tube_number: powder_tube_number
|
||||
target_tube_position: target_tube_position
|
||||
compound_mass: compound_mass
|
||||
feedback: {}
|
||||
result:
|
||||
actual_mass_mg: actual_mass_mg
|
||||
move_to_plate:
|
||||
type: StrSingleInput
|
||||
goal:
|
||||
string: string
|
||||
feedback: {}
|
||||
result: {}
|
||||
discharge:
|
||||
type: FloatSingleInput
|
||||
goal:
|
||||
float_input: float_input
|
||||
feedback: {}
|
||||
result: {}
|
||||
|
||||
schema:
|
||||
properties: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
required:
|
||||
- return_info
|
||||
title: EmptyIn_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: EmptyIn
|
||||
type: object
|
||||
type: EmptyIn
|
||||
module: unilabos.devices.laiyu_add_solid.laiyu:Laiyu
|
||||
status_types:
|
||||
status: str
|
||||
type: python
|
||||
config_info: []
|
||||
description: 来渝固体粉末自动分装设备,用于实验室化学试剂的精确称量和分装。该设备通过Modbus RTU协议与控制系统通信,集成了精密天平、三轴运动平台、粉筒管理系统等组件。支持多种粉末试剂的自动拿取、精确称量、定点分装和归位操作。具备高精度称量、位置控制和批量处理能力,适用于化学合成、药物研发、材料制备等需要精确固体试剂配制的实验室应用场景。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
baudrate:
|
||||
default: 115200
|
||||
type: string
|
||||
port:
|
||||
type: string
|
||||
timeout:
|
||||
default: 0.5
|
||||
type: string
|
||||
required:
|
||||
- port
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,56 +1,704 @@
|
||||
moveit.toyo_xyz:
|
||||
description: Toyo XYZ
|
||||
class:
|
||||
module: unilabos.devices.ros_dev.moveit_interface:MoveitInterface
|
||||
type: python
|
||||
action_value_mappings:
|
||||
set_position:
|
||||
type: SendCmd
|
||||
goal:
|
||||
command: command
|
||||
feedback: { }
|
||||
result: { }
|
||||
pick_and_place:
|
||||
type: SendCmd
|
||||
goal:
|
||||
command: command
|
||||
feedback: { }
|
||||
result: { }
|
||||
set_status:
|
||||
type: SendCmd
|
||||
goal:
|
||||
command: command
|
||||
feedback: { }
|
||||
result: { }
|
||||
|
||||
model:
|
||||
type: device
|
||||
mesh: toyo_xyz
|
||||
|
||||
moveit.arm_slider:
|
||||
description: Arm with Slider
|
||||
model:
|
||||
type: device
|
||||
mesh: arm_slider
|
||||
category:
|
||||
- moveit_config
|
||||
class:
|
||||
module: unilabos.devices.ros_dev.moveit_interface:MoveitInterface
|
||||
type: python
|
||||
action_value_mappings:
|
||||
set_position:
|
||||
type: SendCmd
|
||||
goal:
|
||||
command: command
|
||||
auto-check_tf_update_actions:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: check_tf_update_actions的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: check_tf_update_actions参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-moveit_joint_task:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
joint_names: null
|
||||
joint_positions: null
|
||||
move_group: null
|
||||
retry: 10
|
||||
speed: 1
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: moveit_joint_task的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
joint_names:
|
||||
type: string
|
||||
joint_positions:
|
||||
type: string
|
||||
move_group:
|
||||
type: string
|
||||
retry:
|
||||
default: 10
|
||||
type: string
|
||||
speed:
|
||||
default: 1
|
||||
type: string
|
||||
required:
|
||||
- move_group
|
||||
- joint_positions
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: moveit_joint_task参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-moveit_task:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
cartesian: false
|
||||
move_group: null
|
||||
offsets:
|
||||
- 0
|
||||
- 0
|
||||
- 0
|
||||
position: null
|
||||
quaternion: null
|
||||
retry: 10
|
||||
speed: 1
|
||||
target_link: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: moveit_task的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
cartesian:
|
||||
default: false
|
||||
type: string
|
||||
move_group:
|
||||
type: string
|
||||
offsets:
|
||||
default:
|
||||
- 0
|
||||
- 0
|
||||
- 0
|
||||
type: string
|
||||
position:
|
||||
type: string
|
||||
quaternion:
|
||||
type: string
|
||||
retry:
|
||||
default: 10
|
||||
type: string
|
||||
speed:
|
||||
default: 1
|
||||
type: string
|
||||
target_link:
|
||||
type: string
|
||||
required:
|
||||
- move_group
|
||||
- position
|
||||
- quaternion
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: moveit_task参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-post_init:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
ros_node: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: post_init的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
ros_node:
|
||||
type: string
|
||||
required:
|
||||
- ros_node
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: post_init参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-resource_manager:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
parent_link: null
|
||||
resource: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: resource_manager的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
parent_link:
|
||||
type: string
|
||||
resource:
|
||||
type: string
|
||||
required:
|
||||
- resource
|
||||
- parent_link
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: resource_manager参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-wait_for_resource_action:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: wait_for_resource_action的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: wait_for_resource_action参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
pick_and_place:
|
||||
type: SendCmd
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
set_position:
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
set_status:
|
||||
type: SendCmd
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.ros_dev.moveit_interface:MoveitInterface
|
||||
status_types: {}
|
||||
type: python
|
||||
config_info: []
|
||||
description: 机械臂与滑块运动系统,基于MoveIt2运动规划框架的多自由度机械臂控制设备。该系统集成机械臂和线性滑块,通过ROS2和MoveIt2实现精确的轨迹规划和协调运动控制。支持笛卡尔空间和关节空间的运动规划、碰撞检测、逆运动学求解等功能。适用于复杂的pick-and-place操作、精密装配、多工位协作等需要高精度多轴协调运动的实验室自动化应用。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
device_config:
|
||||
type: string
|
||||
joint_poses:
|
||||
type: string
|
||||
moveit_type:
|
||||
type: string
|
||||
rotation:
|
||||
type: string
|
||||
required:
|
||||
- moveit_type
|
||||
- joint_poses
|
||||
type: object
|
||||
data:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
model:
|
||||
mesh: arm_slider
|
||||
type: device
|
||||
version: 1.0.0
|
||||
moveit.toyo_xyz:
|
||||
category:
|
||||
- moveit_config
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-check_tf_update_actions:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: check_tf_update_actions的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: check_tf_update_actions参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-moveit_joint_task:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
joint_names: null
|
||||
joint_positions: null
|
||||
move_group: null
|
||||
retry: 10
|
||||
speed: 1
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: moveit_joint_task的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
joint_names:
|
||||
type: string
|
||||
joint_positions:
|
||||
type: string
|
||||
move_group:
|
||||
type: string
|
||||
retry:
|
||||
default: 10
|
||||
type: string
|
||||
speed:
|
||||
default: 1
|
||||
type: string
|
||||
required:
|
||||
- move_group
|
||||
- joint_positions
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: moveit_joint_task参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-moveit_task:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
cartesian: false
|
||||
move_group: null
|
||||
offsets:
|
||||
- 0
|
||||
- 0
|
||||
- 0
|
||||
position: null
|
||||
quaternion: null
|
||||
retry: 10
|
||||
speed: 1
|
||||
target_link: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: moveit_task的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
cartesian:
|
||||
default: false
|
||||
type: string
|
||||
move_group:
|
||||
type: string
|
||||
offsets:
|
||||
default:
|
||||
- 0
|
||||
- 0
|
||||
- 0
|
||||
type: string
|
||||
position:
|
||||
type: string
|
||||
quaternion:
|
||||
type: string
|
||||
retry:
|
||||
default: 10
|
||||
type: string
|
||||
speed:
|
||||
default: 1
|
||||
type: string
|
||||
target_link:
|
||||
type: string
|
||||
required:
|
||||
- move_group
|
||||
- position
|
||||
- quaternion
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: moveit_task参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-post_init:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
ros_node: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: post_init的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
ros_node:
|
||||
type: string
|
||||
required:
|
||||
- ros_node
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: post_init参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-resource_manager:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
parent_link: null
|
||||
resource: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: resource_manager的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
parent_link:
|
||||
type: string
|
||||
resource:
|
||||
type: string
|
||||
required:
|
||||
- resource
|
||||
- parent_link
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: resource_manager参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-wait_for_resource_action:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: wait_for_resource_action的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: wait_for_resource_action参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
pick_and_place:
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
set_position:
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
set_status:
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.ros_dev.moveit_interface:MoveitInterface
|
||||
status_types: {}
|
||||
type: python
|
||||
config_info: []
|
||||
description: 东洋XYZ三轴运动平台,基于MoveIt2运动规划框架的精密定位设备。该设备通过ROS2和MoveIt2实现三维空间的精确运动控制,支持复杂轨迹规划、多点定位、速度控制等功能。具备高精度定位、平稳运动、实时轨迹监控等特性。适用于精密加工、样品定位、检测扫描、自动化装配等需要高精度三维运动控制的实验室和工业应用场景。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
device_config:
|
||||
type: string
|
||||
joint_poses:
|
||||
type: string
|
||||
moveit_type:
|
||||
type: string
|
||||
rotation:
|
||||
type: string
|
||||
required:
|
||||
- moveit_type
|
||||
- joint_poses
|
||||
type: object
|
||||
data:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
model:
|
||||
mesh: toyo_xyz
|
||||
type: device
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,73 +1,479 @@
|
||||
separator.homemade:
|
||||
description: Separator device with homemade grbl controller
|
||||
class:
|
||||
module: unilabos.devices.separator.homemade_grbl_conductivity:SeparatorController
|
||||
type: python
|
||||
status_types:
|
||||
sensordata: Float64
|
||||
status: String
|
||||
action_value_mappings:
|
||||
stir:
|
||||
type: Stir
|
||||
goal:
|
||||
stir_time: stir_time,
|
||||
stir_speed: stir_speed
|
||||
settling_time: settling_time
|
||||
feedback:
|
||||
status: status
|
||||
result:
|
||||
success: success
|
||||
valve_open_cmd:
|
||||
type: SendCmd
|
||||
goal:
|
||||
command: command
|
||||
feedback:
|
||||
status: status
|
||||
result":
|
||||
success: success
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
description: The status of the device
|
||||
sensordata:
|
||||
type: number
|
||||
description: 电导传感器数据
|
||||
required:
|
||||
- status
|
||||
- sensordata
|
||||
additionalProperties: false
|
||||
|
||||
rotavap.one:
|
||||
description: Rotavap device
|
||||
category:
|
||||
- organic_miscellaneous
|
||||
class:
|
||||
module: unilabos.devices.rotavap.rotavap_one:RotavapOne
|
||||
type: python
|
||||
status_types:
|
||||
pump_time: Float64
|
||||
rotate_time: Float64
|
||||
action_value_mappings:
|
||||
auto-cmd_write:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
cmd: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: cmd_write的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
cmd:
|
||||
type: string
|
||||
required:
|
||||
- cmd
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: cmd_write参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-main_loop:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: main_loop的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: main_loop参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_pump_time:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
time: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: set_pump_time的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
time:
|
||||
type: string
|
||||
required:
|
||||
- time
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_pump_time参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_rotate_time:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
time: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: set_rotate_time的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
time:
|
||||
type: string
|
||||
required:
|
||||
- time
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_rotate_time参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
set_timer:
|
||||
type: SendCmd
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
temperature:
|
||||
type: number
|
||||
description: 旋蒸水浴温度
|
||||
pump_time:
|
||||
type: number
|
||||
description: The pump time of the device
|
||||
rotate_time:
|
||||
type: number
|
||||
description: The rotate time of the device
|
||||
required:
|
||||
- pump_time
|
||||
- rotate_time
|
||||
additionalProperties: false
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.rotavap.rotavap_one:RotavapOne
|
||||
status_types: {}
|
||||
type: python
|
||||
config_info: []
|
||||
description: 旋转蒸发仪设备,用于有机化学实验中的溶剂回收和浓缩操作。该设备通过串口通信控制,集成旋转和真空泵功能,支持定时控制和自动化操作。具备旋转速度调节、真空度控制、温度管理等功能,实现高效的溶剂蒸发和回收。适用于有机合成、天然产物提取、药物制备等需要溶剂去除和浓缩的实验室应用场景。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
port:
|
||||
type: string
|
||||
rate:
|
||||
default: 9600
|
||||
type: string
|
||||
required:
|
||||
- port
|
||||
type: object
|
||||
data:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
version: 1.0.0
|
||||
separator.homemade:
|
||||
category:
|
||||
- organic_miscellaneous
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-read_sensor_loop:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: read_sensor_loop的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: read_sensor_loop参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-valve_open:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
condition: null
|
||||
value: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: valve_open的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
condition:
|
||||
type: string
|
||||
value:
|
||||
type: string
|
||||
required:
|
||||
- condition
|
||||
- value
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: valve_open参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-write:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
data: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: write的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
data:
|
||||
type: string
|
||||
required:
|
||||
- data
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: write参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
stir:
|
||||
feedback:
|
||||
status: status
|
||||
goal:
|
||||
settling_time: settling_time
|
||||
stir_speed: stir_speed
|
||||
stir_time: stir_time,
|
||||
goal_default:
|
||||
event: ''
|
||||
settling_time: ''
|
||||
stir_speed: 0.0
|
||||
stir_time: 0.0
|
||||
time: ''
|
||||
time_spec: ''
|
||||
vessel:
|
||||
category: ''
|
||||
children: []
|
||||
config: ''
|
||||
data: ''
|
||||
id: ''
|
||||
name: ''
|
||||
parent: ''
|
||||
pose:
|
||||
orientation:
|
||||
w: 1.0
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
position:
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
sample_id: ''
|
||||
type: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: Stir_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
event:
|
||||
type: string
|
||||
settling_time:
|
||||
type: string
|
||||
stir_speed:
|
||||
type: number
|
||||
stir_time:
|
||||
type: number
|
||||
time:
|
||||
type: string
|
||||
time_spec:
|
||||
type: string
|
||||
vessel:
|
||||
properties:
|
||||
category:
|
||||
type: string
|
||||
children:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
config:
|
||||
type: string
|
||||
data:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
parent:
|
||||
type: string
|
||||
pose:
|
||||
properties:
|
||||
orientation:
|
||||
properties:
|
||||
w:
|
||||
type: number
|
||||
x:
|
||||
type: number
|
||||
y:
|
||||
type: number
|
||||
z:
|
||||
type: number
|
||||
required:
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
- w
|
||||
title: Quaternion
|
||||
type: object
|
||||
position:
|
||||
properties:
|
||||
x:
|
||||
type: number
|
||||
y:
|
||||
type: number
|
||||
z:
|
||||
type: number
|
||||
required:
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
title: Point
|
||||
type: object
|
||||
required:
|
||||
- position
|
||||
- orientation
|
||||
title: Pose
|
||||
type: object
|
||||
sample_id:
|
||||
type: string
|
||||
type:
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- sample_id
|
||||
- children
|
||||
- parent
|
||||
- type
|
||||
- category
|
||||
- pose
|
||||
- config
|
||||
- data
|
||||
title: Resource
|
||||
type: object
|
||||
required:
|
||||
- vessel
|
||||
- time
|
||||
- event
|
||||
- time_spec
|
||||
- stir_time
|
||||
- stir_speed
|
||||
- settling_time
|
||||
title: Stir_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- success
|
||||
- message
|
||||
- return_info
|
||||
title: Stir_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: Stir
|
||||
type: object
|
||||
type: Stir
|
||||
valve_open_cmd:
|
||||
feedback:
|
||||
status: status
|
||||
goal:
|
||||
command: command
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.separator.homemade_grbl_conductivity:SeparatorController
|
||||
status_types: {}
|
||||
type: python
|
||||
config_info: []
|
||||
description: 液-液分离器设备,基于自制Grbl控制器的自动化分离系统。该设备集成搅拌、沉降、阀门控制和电导率传感器,通过串口通信实现精确的分离操作控制。支持自动搅拌、分层沉降、基于传感器反馈的智能分液等功能。适用于有机化学中的萃取分离、相分离、液-液提取等需要精确分离控制的实验应用。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
baudrate_executor:
|
||||
default: 115200
|
||||
type: integer
|
||||
baudrate_sensor:
|
||||
default: 115200
|
||||
type: integer
|
||||
port_executor:
|
||||
type: string
|
||||
port_sensor:
|
||||
type: string
|
||||
required:
|
||||
- port_executor
|
||||
- port_sensor
|
||||
type: object
|
||||
data:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,85 +1,816 @@
|
||||
syringe_pump_with_valve.runze:
|
||||
description: Runze Syringe pump with valve
|
||||
solenoid_valve:
|
||||
category:
|
||||
- pump_and_valve
|
||||
class:
|
||||
module: unilabos.devices.pump_and_valve.runze_backbone:RunzeSyringePump
|
||||
action_value_mappings:
|
||||
auto-close:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: close的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: close参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-is_closed:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: is_closed的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: is_closed参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-is_open:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: is_open的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: is_open参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-open:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: open参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-read_data:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: read_data的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: read_data参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-send_command:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
command: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: send_command的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: send_command参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
set_valve_position:
|
||||
feedback: {}
|
||||
goal:
|
||||
string: position
|
||||
goal_default:
|
||||
string: ''
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: StrSingleInput_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
string:
|
||||
type: string
|
||||
required:
|
||||
- string
|
||||
title: StrSingleInput_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: StrSingleInput_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: StrSingleInput
|
||||
type: object
|
||||
type: StrSingleInput
|
||||
module: unilabos.devices.pump_and_valve.solenoid_valve:SolenoidValve
|
||||
status_types:
|
||||
status: str
|
||||
valve_position: str
|
||||
type: python
|
||||
config_info: []
|
||||
description: 电磁阀控制设备,用于精确的流体路径控制和开关操作。该设备通过串口通信控制电磁阀的开关状态,支持远程操作和状态监测。具备快速响应、可靠密封、状态反馈等特性,广泛应用于流体输送、样品进样、路径切换等需要精确流体控制的实验室自动化应用。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
io_device_port:
|
||||
type: string
|
||||
required:
|
||||
- io_device_port
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
valve_position:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
- valve_position
|
||||
type: object
|
||||
version: 1.0.0
|
||||
solenoid_valve.mock:
|
||||
category:
|
||||
- pump_and_valve
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-is_closed:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: is_closed的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: is_closed参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-is_open:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: is_open的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: is_open参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_valve_position:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
position: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: set_valve_position的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
position:
|
||||
type: string
|
||||
required:
|
||||
- position
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_valve_position参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
close:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
required:
|
||||
- return_info
|
||||
title: EmptyIn_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: EmptyIn
|
||||
type: object
|
||||
type: EmptyIn
|
||||
open:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
required:
|
||||
- return_info
|
||||
title: EmptyIn_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: EmptyIn
|
||||
type: object
|
||||
type: EmptyIn
|
||||
module: unilabos.devices.pump_and_valve.solenoid_valve_mock:SolenoidValveMock
|
||||
status_types:
|
||||
status: str
|
||||
valve_position: str
|
||||
type: python
|
||||
config_info: []
|
||||
description: 模拟电磁阀设备,用于系统测试和开发调试。该设备模拟真实电磁阀的开关操作和状态变化,提供与实际设备相同的控制接口和反馈机制。支持流体路径的虚拟控制,便于在没有实际硬件的情况下进行流体系统的集成测试和算法验证。适用于系统开发、流程调试和培训演示等场景。
|
||||
handles:
|
||||
- data_type: fluid
|
||||
handler_key: in
|
||||
io_type: target
|
||||
label: in
|
||||
side: NORTH
|
||||
- data_type: fluid
|
||||
handler_key: out
|
||||
io_type: source
|
||||
label: out
|
||||
side: SOUTH
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
port:
|
||||
default: COM6
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
valve_position:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
- valve_position
|
||||
type: object
|
||||
version: 1.0.0
|
||||
syringe_pump_with_valve.runze:
|
||||
category:
|
||||
- pump_and_valve
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-close:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: close的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: close参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-initialize:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: initialize的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: initialize参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-pull_plunger:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
volume: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: pull_plunger的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
volume:
|
||||
type: number
|
||||
required:
|
||||
- volume
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: pull_plunger参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-push_plunger:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
volume: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: push_plunger的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
volume:
|
||||
type: number
|
||||
required:
|
||||
- volume
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: push_plunger参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-query_aux_input_status_1:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: query_aux_input_status_1的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: query_aux_input_status_1参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-query_aux_input_status_2:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: query_aux_input_status_2的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: query_aux_input_status_2参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-query_backlash_position:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: query_backlash_position的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: query_backlash_position参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-query_command_buffer_status:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: query_command_buffer_status的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: query_command_buffer_status参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-query_software_version:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: query_software_version的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: query_software_version参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-send_command:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
full_command: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: send_command的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
full_command:
|
||||
type: string
|
||||
required:
|
||||
- full_command
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: send_command参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_baudrate:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
baudrate: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: set_baudrate的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
baudrate:
|
||||
type: string
|
||||
required:
|
||||
- baudrate
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_baudrate参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_max_velocity:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
velocity: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: set_max_velocity的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
velocity:
|
||||
type: number
|
||||
required:
|
||||
- velocity
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_max_velocity参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_position:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
max_velocity: null
|
||||
position: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: set_position的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
max_velocity:
|
||||
type: number
|
||||
position:
|
||||
type: number
|
||||
required:
|
||||
- position
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_position参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_valve_position:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
position: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: set_valve_position的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
position:
|
||||
type: string
|
||||
required:
|
||||
- position
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_valve_position参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_velocity_grade:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
velocity: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: set_velocity_grade的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
velocity:
|
||||
type: string
|
||||
required:
|
||||
- velocity
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_velocity_grade参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-stop_operation:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: stop_operation的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: stop_operation参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-wait_error:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: wait_error的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: wait_error参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
hardware_interface:
|
||||
name: hardware_interface
|
||||
read: send_command
|
||||
write: send_command
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
description: The status of the device
|
||||
position:
|
||||
type: number
|
||||
description: The volume of the syringe
|
||||
speed_max:
|
||||
type: number
|
||||
description: The speed of the syringe
|
||||
valve_position:
|
||||
type: string
|
||||
description: The position of the valve
|
||||
required:
|
||||
- status
|
||||
- position
|
||||
- valve_position
|
||||
additionalProperties: false
|
||||
|
||||
solenoid_valve.mock:
|
||||
description: Mock solenoid valve
|
||||
class:
|
||||
module: unilabos.devices.pump_and_valve.solenoid_valve_mock:SolenoidValveMock
|
||||
type: python
|
||||
module: unilabos.devices.pump_and_valve.runze_backbone:RunzeSyringePump
|
||||
status_types:
|
||||
status: String
|
||||
valve_position: String
|
||||
action_value_mappings:
|
||||
open:
|
||||
type: EmptyIn
|
||||
goal: {}
|
||||
feedback: {}
|
||||
result: {}
|
||||
close:
|
||||
type: EmptyIn
|
||||
goal: {}
|
||||
feedback: {}
|
||||
result: {}
|
||||
handles:
|
||||
- handler_key: in
|
||||
label: in
|
||||
io_type: target
|
||||
data_type: fluid
|
||||
side: NORTH
|
||||
- handler_key: out
|
||||
label: out
|
||||
io_type: source
|
||||
data_type: fluid
|
||||
side: SOUTH
|
||||
max_velocity: float
|
||||
mode: int
|
||||
plunger_position: String
|
||||
position: float
|
||||
status: str
|
||||
valve_position: str
|
||||
velocity_end: String
|
||||
velocity_grade: String
|
||||
velocity_init: String
|
||||
type: python
|
||||
config_info: []
|
||||
description: 润泽精密注射泵设备,集成阀门控制的高精度流体输送系统。该设备通过串口通信控制,支持多种运行模式和精确的体积控制。具备可变速度控制、精密定位、阀门切换、实时状态监控等功能。适用于微量液体输送、精密进样、流速控制、化学反应进料等需要高精度流体操作的实验室自动化应用。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
type: object
|
||||
properties:
|
||||
port:
|
||||
type: string
|
||||
description: "通信端口"
|
||||
default: "COM6"
|
||||
required:
|
||||
- port
|
||||
|
||||
solenoid_valve:
|
||||
description: Solenoid valve
|
||||
class:
|
||||
module: unilabos.devices.pump_and_valve.solenoid_valve:SolenoidValve
|
||||
type: python
|
||||
status_types:
|
||||
status: String
|
||||
valve_position: String
|
||||
action_value_mappings:
|
||||
set_valve_position:
|
||||
type: StrSingleInput
|
||||
goal:
|
||||
string: position
|
||||
feedback: {}
|
||||
result: {}
|
||||
config:
|
||||
properties:
|
||||
address:
|
||||
default: '1'
|
||||
type: string
|
||||
max_volume:
|
||||
default: 25.0
|
||||
type: number
|
||||
mode:
|
||||
type: string
|
||||
port:
|
||||
type: string
|
||||
required:
|
||||
- port
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
max_velocity:
|
||||
type: number
|
||||
mode:
|
||||
type: integer
|
||||
plunger_position:
|
||||
type: string
|
||||
position:
|
||||
type: number
|
||||
status:
|
||||
type: string
|
||||
valve_position:
|
||||
type: string
|
||||
velocity_end:
|
||||
type: string
|
||||
velocity_grade:
|
||||
type: string
|
||||
velocity_init:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
- mode
|
||||
- max_velocity
|
||||
- velocity_grade
|
||||
- velocity_init
|
||||
- velocity_end
|
||||
- valve_position
|
||||
- position
|
||||
- plunger_position
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,29 +1,109 @@
|
||||
# 仙工智能底盘(知行使用)
|
||||
agv.SEER:
|
||||
description: SEER AGV
|
||||
category:
|
||||
- robot_agv
|
||||
class:
|
||||
module: unilabos.devices.agv.agv_navigator:AgvNavigator
|
||||
type: python
|
||||
status_types:
|
||||
pose: Float64MultiArray
|
||||
status: String
|
||||
action_value_mappings:
|
||||
auto-send:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
cmd: null
|
||||
ex_data: ''
|
||||
obj: receive_socket
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: AGV底层通信命令发送函数。通过TCP socket连接向AGV发送底层控制命令,支持pose(位置)、status(状态)、nav(导航)等命令类型。用于获取AGV当前位置坐标、运行状态或发送导航指令。该函数封装了AGV的通信协议,将命令转换为十六进制数据包并处理响应解析。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
cmd:
|
||||
type: string
|
||||
ex_data:
|
||||
default: ''
|
||||
type: string
|
||||
obj:
|
||||
default: receive_socket
|
||||
type: string
|
||||
required:
|
||||
- cmd
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: send参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
send_nav_task:
|
||||
type: SendCmd
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
properties:
|
||||
pose:
|
||||
type: array
|
||||
items:
|
||||
type: number
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.agv.agv_navigator:AgvNavigator
|
||||
status_types:
|
||||
pose: list
|
||||
status: str
|
||||
type: python
|
||||
config_info: []
|
||||
description: SEER AGV自动导引车设备,用于实验室内物料和设备的自主移动运输。该AGV通过TCP socket与导航系统通信,具备精确的定位和路径规划能力。支持实时位置监控、状态查询和导航任务执行,可在预设的实验室环境中自主移动至指定位置。适用于样品运输、设备转移、多工位协作等实验室自动化物流场景。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
host:
|
||||
type: string
|
||||
required:
|
||||
- host
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
pose:
|
||||
type: array
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- pose
|
||||
- status
|
||||
additionalProperties: false
|
||||
type: object
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,37 +1,176 @@
|
||||
robotic_arm.UR:
|
||||
description: UR robotic arm
|
||||
category:
|
||||
- robot_arm
|
||||
class:
|
||||
module: unilabos.devices.agv.ur_arm_task:UrArmTask
|
||||
type: python
|
||||
status_types:
|
||||
arm_pose: Float64MultiArray
|
||||
gripper_pose: Float64
|
||||
arm_status: String
|
||||
gripper_status: String
|
||||
action_value_mappings:
|
||||
auto-arm_init:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 机械臂初始化函数。执行UR机械臂的完整初始化流程,包括上电、释放制动器、解除保护停止状态等。该函数确保机械臂从安全停止状态恢复到可操作状态,是机械臂使用前的必要步骤。初始化完成后机械臂将处于就绪状态,可以接收后续的运动指令。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: arm_init参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-load_pose_data:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
data: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 从JSON字符串加载位置数据函数。接收包含机械臂位置信息的JSON格式字符串,解析并存储位置数据供后续运动任务使用。位置数据通常包含多个预定义的工作位置坐标,用于实现精确的多点运动控制。适用于动态配置机械臂工作位置的场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
data:
|
||||
type: string
|
||||
required:
|
||||
- data
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: load_pose_data参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-load_pose_file:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
file: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 从文件加载位置数据函数。读取指定的JSON文件并加载其中的机械臂位置信息。该函数支持从外部配置文件中获取预设的工作位置,便于位置数据的管理和重用。适用于需要从固定配置文件中读取复杂位置序列的应用场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
file:
|
||||
type: string
|
||||
required:
|
||||
- file
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: load_pose_file参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-reload_pose:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 重新加载位置数据函数。重新读取并解析之前设置的位置文件,更新内存中的位置数据。该函数用于在位置文件被修改后刷新机械臂的位置配置,无需重新初始化整个系统。适用于动态更新机械臂工作位置的场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: reload_pose参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
move_pos_task:
|
||||
type: SendCmd
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
properties:
|
||||
arm_pose:
|
||||
type: array
|
||||
items:
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.agv.ur_arm_task:UrArmTask
|
||||
status_types:
|
||||
arm_pose: list
|
||||
arm_status: str
|
||||
gripper_pose: float
|
||||
gripper_status: str
|
||||
type: python
|
||||
config_info: []
|
||||
description: Universal Robots机械臂设备,用于实验室精密操作和自动化作业。该设备集成了UR机械臂本体、Robotiq夹爪和RTDE通信接口,支持六自由度精确运动控制和力觉反馈。具备实时位置监控、状态反馈、轨迹规划等功能,可执行复杂的多点位运动任务。适用于样品抓取、精密装配、实验器具操作等需要高精度和高重复性的实验室自动化场景。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
host:
|
||||
type: string
|
||||
retry:
|
||||
default: 30
|
||||
type: string
|
||||
required:
|
||||
- host
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
arm_pose:
|
||||
type: array
|
||||
arm_status:
|
||||
type: string
|
||||
gripper_pose:
|
||||
type: number
|
||||
gripper_pose:
|
||||
type: number
|
||||
arm_status:
|
||||
type: string
|
||||
description: 机械臂设备状态
|
||||
gripper_status:
|
||||
type: string
|
||||
description: 机械爪设备状态
|
||||
required:
|
||||
gripper_status:
|
||||
type: string
|
||||
required:
|
||||
- arm_pose
|
||||
- gripper_pose
|
||||
- arm_status
|
||||
- gripper_status
|
||||
additionalProperties: false
|
||||
type: object
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,37 +1,596 @@
|
||||
gripper.mock:
|
||||
description: Mock gripper
|
||||
class:
|
||||
module: unilabos.devices.gripper.mock:MockGripper
|
||||
type: python
|
||||
status_types:
|
||||
position: Float64
|
||||
torque: Float64
|
||||
status: String
|
||||
action_value_mappings:
|
||||
push_to:
|
||||
type: GripperCommand
|
||||
goal:
|
||||
command.position: position
|
||||
command.max_effort: torque
|
||||
feedback:
|
||||
position: position
|
||||
effort: torque
|
||||
result:
|
||||
position: position
|
||||
effort: torque
|
||||
|
||||
gripper.misumi_rz:
|
||||
description: Misumi RZ gripper
|
||||
category:
|
||||
- robot_gripper
|
||||
class:
|
||||
module: unilabos.devices.motor:Grasp.EleGripper
|
||||
type: python
|
||||
status_types:
|
||||
status: String
|
||||
action_value_mappings:
|
||||
auto-data_loop:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: data_loop的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: data_loop参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-data_reader:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: data_reader的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: data_reader参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-gripper_move:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
force: null
|
||||
pos: null
|
||||
speed: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 夹爪抓取运动控制函数。控制夹爪的开合运动,支持位置、速度、力矩的精确设定。位置参数控制夹爪开合程度,速度参数控制运动快慢,力矩参数控制夹持强度。该函数提供安全的力控制,避免损坏被抓取物体,适用于各种形状和材质的物品抓取。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
force:
|
||||
type: string
|
||||
pos:
|
||||
type: string
|
||||
speed:
|
||||
type: string
|
||||
required:
|
||||
- pos
|
||||
- speed
|
||||
- force
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: gripper_move参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-init_gripper:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 夹爪初始化函数。执行Misumi RZ夹爪的完整初始化流程,包括Modbus通信建立、电机参数配置、传感器校准等。该函数确保夹爪系统从安全状态恢复到可操作状态,是夹爪使用前的必要步骤。初始化完成后夹爪将处于就绪状态,可接收抓取和旋转指令。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: init_gripper参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-modbus_crc:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
data: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: modbus_crc的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
data:
|
||||
type: string
|
||||
required:
|
||||
- data
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: modbus_crc参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-move_and_rotate:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
grasp_F: null
|
||||
grasp_pos: null
|
||||
grasp_v: null
|
||||
spin_F: null
|
||||
spin_pos: null
|
||||
spin_v: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: move_and_rotate的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
grasp_F:
|
||||
type: string
|
||||
grasp_pos:
|
||||
type: string
|
||||
grasp_v:
|
||||
type: string
|
||||
spin_F:
|
||||
type: string
|
||||
spin_pos:
|
||||
type: string
|
||||
spin_v:
|
||||
type: string
|
||||
required:
|
||||
- spin_pos
|
||||
- grasp_pos
|
||||
- spin_v
|
||||
- grasp_v
|
||||
- spin_F
|
||||
- grasp_F
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: move_and_rotate参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-node_gripper_move:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
cmd: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 节点夹爪移动任务函数。接收逗号分隔的命令字符串,解析位置、速度、力矩参数并执行夹爪抓取动作。该函数等待运动完成并返回执行结果,提供同步的运动控制接口。适用于需要可靠完成确认的精密抓取操作。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
cmd:
|
||||
type: string
|
||||
required:
|
||||
- cmd
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: node_gripper_move参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-node_rotate_move:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
cmd: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 节点旋转移动任务函数。接收逗号分隔的命令字符串,解析角度、速度、力矩参数并执行夹爪旋转动作。该函数等待旋转完成并返回执行结果,提供同步的旋转控制接口。适用于需要精确角度定位和完成确认的旋转操作。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
cmd:
|
||||
type: string
|
||||
required:
|
||||
- cmd
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: node_rotate_move参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-read_address:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
address: null
|
||||
data_len: null
|
||||
id: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: read_address的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
address:
|
||||
type: string
|
||||
data_len:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
- address
|
||||
- data_len
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: read_address参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-rotate_move_abs:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
force: null
|
||||
pos: null
|
||||
speed: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 夹爪绝对位置旋转控制函数。控制夹爪主轴旋转到指定的绝对角度位置,支持360度连续旋转。位置参数指定目标角度,速度参数控制旋转速率,力矩参数设定旋转阻力限制。该函数提供高精度的角度定位,适用于需要精确方向控制的操作场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
force:
|
||||
type: string
|
||||
pos:
|
||||
type: string
|
||||
speed:
|
||||
type: string
|
||||
required:
|
||||
- pos
|
||||
- speed
|
||||
- force
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: rotate_move_abs参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-send_cmd:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
address: null
|
||||
data: null
|
||||
fun: null
|
||||
id: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: send_cmd的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
address:
|
||||
type: string
|
||||
data:
|
||||
type: string
|
||||
fun:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
- fun
|
||||
- address
|
||||
- data
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: send_cmd参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-wait_for_gripper:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: wait_for_gripper的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: wait_for_gripper参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-wait_for_gripper_init:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: wait_for_gripper_init的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: wait_for_gripper_init参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-wait_for_rotate:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: wait_for_rotate的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: wait_for_rotate参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
execute_command_from_outer:
|
||||
type: SendCmd
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.motor.Grasp:EleGripper
|
||||
status_types:
|
||||
status: str
|
||||
type: python
|
||||
config_info: []
|
||||
description: Misumi RZ系列电子夹爪设备,集成旋转和抓取双重功能的精密夹爪系统。该设备通过Modbus RTU协议与控制系统通信,支持位置、速度、力矩的精确控制。具备高精度的位置反馈、实时状态监控和故障检测功能。适用于需要精密抓取和旋转操作的实验室自动化场景,如样品管理、精密装配、器件操作等应用。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
baudrate:
|
||||
default: 115200
|
||||
type: string
|
||||
id:
|
||||
default: 9
|
||||
type: string
|
||||
port:
|
||||
type: string
|
||||
pos_error:
|
||||
default: -11
|
||||
type: string
|
||||
required:
|
||||
- port
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
type: object
|
||||
version: 1.0.0
|
||||
gripper.mock:
|
||||
category:
|
||||
- robot_gripper
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-edit_id:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
params: '{}'
|
||||
resource:
|
||||
Gripper1: {}
|
||||
wf_name: gripper_run
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 模拟夹爪资源ID编辑函数。用于测试和演示资源管理功能,模拟修改夹爪资源的标识信息。该函数接收工作流名称、参数和资源对象,模拟真实的资源更新过程并返回修改后的资源信息。适用于系统测试和开发调试场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
params:
|
||||
default: '{}'
|
||||
type: string
|
||||
resource:
|
||||
default:
|
||||
Gripper1: {}
|
||||
type: object
|
||||
wf_name:
|
||||
default: gripper_run
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: edit_id参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
push_to:
|
||||
feedback:
|
||||
effort: torque
|
||||
position: position
|
||||
goal:
|
||||
command.max_effort: torque
|
||||
command.position: position
|
||||
goal_default:
|
||||
command:
|
||||
max_effort: 0.0
|
||||
position: 0.0
|
||||
handles: []
|
||||
result:
|
||||
effort: torque
|
||||
position: position
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
effort:
|
||||
type: number
|
||||
position:
|
||||
type: number
|
||||
reached_goal:
|
||||
type: boolean
|
||||
stalled:
|
||||
type: boolean
|
||||
required:
|
||||
- position
|
||||
- effort
|
||||
- stalled
|
||||
- reached_goal
|
||||
title: GripperCommand_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
properties:
|
||||
max_effort:
|
||||
type: number
|
||||
position:
|
||||
type: number
|
||||
required:
|
||||
- position
|
||||
- max_effort
|
||||
title: GripperCommand
|
||||
type: object
|
||||
required:
|
||||
- command
|
||||
title: GripperCommand_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
effort:
|
||||
type: number
|
||||
position:
|
||||
type: number
|
||||
reached_goal:
|
||||
type: boolean
|
||||
stalled:
|
||||
type: boolean
|
||||
required:
|
||||
- position
|
||||
- effort
|
||||
- stalled
|
||||
- reached_goal
|
||||
title: GripperCommand_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: GripperCommand
|
||||
type: object
|
||||
type: GripperCommand
|
||||
module: unilabos.devices.gripper.mock:MockGripper
|
||||
status_types:
|
||||
position: float
|
||||
status: str
|
||||
torque: float
|
||||
velocity: float
|
||||
type: python
|
||||
config_info: []
|
||||
description: 模拟夹爪设备,用于系统测试和开发调试。该设备模拟真实夹爪的位置、速度、力矩等物理特性,支持虚拟的抓取和移动操作。提供与真实夹爪相同的接口和状态反馈,便于在没有实际硬件的情况下进行系统集成测试和算法验证。适用于软件开发、系统调试和培训演示等场景。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
position:
|
||||
type: number
|
||||
status:
|
||||
type: string
|
||||
torque:
|
||||
type: number
|
||||
velocity:
|
||||
type: number
|
||||
required:
|
||||
- position
|
||||
- velocity
|
||||
- torque
|
||||
- status
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,57 +1,640 @@
|
||||
linear_motion.grbl:
|
||||
description: Grbl CNC
|
||||
category:
|
||||
- robot_linear_motion
|
||||
class:
|
||||
module: unilabos.devices.cnc.grbl_sync:GrblCNC
|
||||
type: python
|
||||
action_value_mappings:
|
||||
move_through_points: &move_through_points
|
||||
type: NavigateThroughPoses
|
||||
goal:
|
||||
poses[].pose.position: positions[]
|
||||
feedback:
|
||||
current_pose.pose.position: position
|
||||
navigation_time.sec: time_spent
|
||||
estimated_time_remaining.sec: time_remaining
|
||||
number_of_poses_remaining: pose_number_remaining
|
||||
auto-initialize:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
set_spindle_speed:
|
||||
type: SingleJointPosition
|
||||
schema:
|
||||
description: CNC设备初始化函数。执行Grbl CNC的完整初始化流程,包括归零操作、轴校准和状态复位。该函数将所有轴移动到原点位置(0,0,0),确保设备处于已知的参考状态。初始化完成后设备进入空闲状态,可接收后续的运动指令。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: initialize参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_position:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
position: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: CNC绝对位置设定函数。控制CNC设备移动到指定的三维坐标位置(x,y,z)。该函数支持安全限位检查,防止超出设备工作范围。移动过程中会监控设备状态,确保安全到达目标位置。适用于精确定位和轨迹控制操作。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
position:
|
||||
type: string
|
||||
required:
|
||||
- position
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_position参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-stop_operation:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: CNC操作停止函数。立即停止当前正在执行的所有CNC运动,包括轴移动和主轴旋转。该函数用于紧急停止或任务中断,确保设备和工件的安全。停止后设备将保持当前位置,等待新的指令。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: stop_operation参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-wait_error:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: wait_error的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: wait_error参数
|
||||
type: object
|
||||
type: UniLabJsonCommandAsync
|
||||
move_through_points:
|
||||
feedback:
|
||||
current_pose.pose.position: position
|
||||
estimated_time_remaining.sec: time_remaining
|
||||
navigation_time.sec: time_spent
|
||||
number_of_poses_remaining: pose_number_remaining
|
||||
goal:
|
||||
position: spindle_speed
|
||||
poses[].pose.position: positions[]
|
||||
goal_default:
|
||||
behavior_tree: ''
|
||||
poses:
|
||||
- header:
|
||||
frame_id: ''
|
||||
stamp:
|
||||
nanosec: 0
|
||||
sec: 0
|
||||
pose:
|
||||
orientation:
|
||||
w: 1.0
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
position:
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
current_pose:
|
||||
properties:
|
||||
header:
|
||||
properties:
|
||||
frame_id:
|
||||
type: string
|
||||
stamp:
|
||||
properties:
|
||||
nanosec:
|
||||
maximum: 4294967295
|
||||
minimum: 0
|
||||
type: integer
|
||||
sec:
|
||||
maximum: 2147483647
|
||||
minimum: -2147483648
|
||||
type: integer
|
||||
required:
|
||||
- sec
|
||||
- nanosec
|
||||
title: Time
|
||||
type: object
|
||||
required:
|
||||
- stamp
|
||||
- frame_id
|
||||
title: Header
|
||||
type: object
|
||||
pose:
|
||||
properties:
|
||||
orientation:
|
||||
properties:
|
||||
w:
|
||||
type: number
|
||||
x:
|
||||
type: number
|
||||
y:
|
||||
type: number
|
||||
z:
|
||||
type: number
|
||||
required:
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
- w
|
||||
title: Quaternion
|
||||
type: object
|
||||
position:
|
||||
properties:
|
||||
x:
|
||||
type: number
|
||||
y:
|
||||
type: number
|
||||
z:
|
||||
type: number
|
||||
required:
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
title: Point
|
||||
type: object
|
||||
required:
|
||||
- position
|
||||
- orientation
|
||||
title: Pose
|
||||
type: object
|
||||
required:
|
||||
- header
|
||||
- pose
|
||||
title: PoseStamped
|
||||
type: object
|
||||
distance_remaining:
|
||||
type: number
|
||||
estimated_time_remaining:
|
||||
properties:
|
||||
nanosec:
|
||||
maximum: 4294967295
|
||||
minimum: 0
|
||||
type: integer
|
||||
sec:
|
||||
maximum: 2147483647
|
||||
minimum: -2147483648
|
||||
type: integer
|
||||
required:
|
||||
- sec
|
||||
- nanosec
|
||||
title: Duration
|
||||
type: object
|
||||
navigation_time:
|
||||
properties:
|
||||
nanosec:
|
||||
maximum: 4294967295
|
||||
minimum: 0
|
||||
type: integer
|
||||
sec:
|
||||
maximum: 2147483647
|
||||
minimum: -2147483648
|
||||
type: integer
|
||||
required:
|
||||
- sec
|
||||
- nanosec
|
||||
title: Duration
|
||||
type: object
|
||||
number_of_poses_remaining:
|
||||
maximum: 32767
|
||||
minimum: -32768
|
||||
type: integer
|
||||
number_of_recoveries:
|
||||
maximum: 32767
|
||||
minimum: -32768
|
||||
type: integer
|
||||
required:
|
||||
- current_pose
|
||||
- navigation_time
|
||||
- estimated_time_remaining
|
||||
- number_of_recoveries
|
||||
- distance_remaining
|
||||
- number_of_poses_remaining
|
||||
title: NavigateThroughPoses_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
behavior_tree:
|
||||
type: string
|
||||
poses:
|
||||
items:
|
||||
properties:
|
||||
header:
|
||||
properties:
|
||||
frame_id:
|
||||
type: string
|
||||
stamp:
|
||||
properties:
|
||||
nanosec:
|
||||
maximum: 4294967295
|
||||
minimum: 0
|
||||
type: integer
|
||||
sec:
|
||||
maximum: 2147483647
|
||||
minimum: -2147483648
|
||||
type: integer
|
||||
required:
|
||||
- sec
|
||||
- nanosec
|
||||
title: Time
|
||||
type: object
|
||||
required:
|
||||
- stamp
|
||||
- frame_id
|
||||
title: Header
|
||||
type: object
|
||||
pose:
|
||||
properties:
|
||||
orientation:
|
||||
properties:
|
||||
w:
|
||||
type: number
|
||||
x:
|
||||
type: number
|
||||
y:
|
||||
type: number
|
||||
z:
|
||||
type: number
|
||||
required:
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
- w
|
||||
title: Quaternion
|
||||
type: object
|
||||
position:
|
||||
properties:
|
||||
x:
|
||||
type: number
|
||||
y:
|
||||
type: number
|
||||
z:
|
||||
type: number
|
||||
required:
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
title: Point
|
||||
type: object
|
||||
required:
|
||||
- position
|
||||
- orientation
|
||||
title: Pose
|
||||
type: object
|
||||
required:
|
||||
- header
|
||||
- pose
|
||||
title: PoseStamped
|
||||
type: object
|
||||
type: array
|
||||
required:
|
||||
- poses
|
||||
- behavior_tree
|
||||
title: NavigateThroughPoses_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
result:
|
||||
properties: {}
|
||||
required: []
|
||||
title: Empty
|
||||
type: object
|
||||
required:
|
||||
- result
|
||||
title: NavigateThroughPoses_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: NavigateThroughPoses
|
||||
type: object
|
||||
type: NavigateThroughPoses
|
||||
set_spindle_speed:
|
||||
feedback:
|
||||
position: spindle_speed
|
||||
goal:
|
||||
position: spindle_speed
|
||||
goal_default:
|
||||
max_velocity: 0.0
|
||||
min_duration:
|
||||
nanosec: 0
|
||||
sec: 0
|
||||
position: 0.0
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
position:
|
||||
type: array
|
||||
items:
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
error:
|
||||
type: number
|
||||
header:
|
||||
properties:
|
||||
frame_id:
|
||||
type: string
|
||||
stamp:
|
||||
properties:
|
||||
nanosec:
|
||||
maximum: 4294967295
|
||||
minimum: 0
|
||||
type: integer
|
||||
sec:
|
||||
maximum: 2147483647
|
||||
minimum: -2147483648
|
||||
type: integer
|
||||
required:
|
||||
- sec
|
||||
- nanosec
|
||||
title: Time
|
||||
type: object
|
||||
required:
|
||||
- stamp
|
||||
- frame_id
|
||||
title: Header
|
||||
type: object
|
||||
position:
|
||||
type: number
|
||||
velocity:
|
||||
type: number
|
||||
required:
|
||||
- header
|
||||
- position
|
||||
- velocity
|
||||
- error
|
||||
title: SingleJointPosition_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
max_velocity:
|
||||
type: number
|
||||
min_duration:
|
||||
properties:
|
||||
nanosec:
|
||||
maximum: 4294967295
|
||||
minimum: 0
|
||||
type: integer
|
||||
sec:
|
||||
maximum: 2147483647
|
||||
minimum: -2147483648
|
||||
type: integer
|
||||
required:
|
||||
- sec
|
||||
- nanosec
|
||||
title: Duration
|
||||
type: object
|
||||
position:
|
||||
type: number
|
||||
required:
|
||||
- position
|
||||
- min_duration
|
||||
- max_velocity
|
||||
title: SingleJointPosition_Goal
|
||||
type: object
|
||||
result:
|
||||
properties: {}
|
||||
required: []
|
||||
title: SingleJointPosition_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SingleJointPosition
|
||||
type: object
|
||||
type: SingleJointPosition
|
||||
module: unilabos.devices.cnc.grbl_sync:GrblCNC
|
||||
status_types:
|
||||
position: unilabos.messages:Point3D
|
||||
spindle_speed: float
|
||||
status: str
|
||||
type: python
|
||||
config_info: []
|
||||
description: Grbl数控机床(CNC)设备,用于实验室精密加工和三轴定位操作。该设备基于Grbl固件,通过串口通信控制步进电机实现X、Y、Z三轴的精确运动。支持绝对定位、轨迹规划、主轴控制和实时状态监控。具备安全限位保护和运动平滑控制功能。适用于精密钻孔、铣削、雕刻、样品制备等需要高精度定位和加工的实验室应用场景。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
address:
|
||||
default: '1'
|
||||
type: string
|
||||
limits:
|
||||
default:
|
||||
- -150
|
||||
- 150
|
||||
- -200
|
||||
- 0
|
||||
- -80
|
||||
- 0
|
||||
type: array
|
||||
port:
|
||||
type: string
|
||||
required:
|
||||
- port
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
position:
|
||||
type: string
|
||||
spindle_speed:
|
||||
type: number
|
||||
description: The position of the device
|
||||
spindle_speed:
|
||||
type: number
|
||||
description: The spindle speed of the device
|
||||
required:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
- position
|
||||
- spindle_speed
|
||||
additionalProperties: false
|
||||
|
||||
|
||||
type: object
|
||||
version: 1.0.0
|
||||
motor.iCL42:
|
||||
description: iCL42 motor
|
||||
category:
|
||||
- robot_linear_motion
|
||||
class:
|
||||
module: unilabos.devices.motor.iCL42:iCL42Driver
|
||||
type: python
|
||||
status_types:
|
||||
motor_position: Int64
|
||||
is_executing_run: Bool
|
||||
success: Bool
|
||||
action_value_mappings:
|
||||
auto-execute_run_motor:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
mode: null
|
||||
position: null
|
||||
velocity: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 步进电机执行运动函数。直接执行电机运动命令,包括位置设定、速度控制和路径规划。该函数处理底层的电机控制协议,消除警告信息,设置运动参数并启动电机运行。适用于需要直接控制电机运动的应用场景。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
mode:
|
||||
type: string
|
||||
position:
|
||||
type: number
|
||||
velocity:
|
||||
type: integer
|
||||
required:
|
||||
- mode
|
||||
- position
|
||||
- velocity
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: execute_run_motor参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-init_device:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: iCL42电机设备初始化函数。建立与iCL42步进电机驱动器的串口通信连接,配置通信参数包括波特率、数据位、校验位等。该函数是电机使用前的必要步骤,确保驱动器处于可控状态并准备接收运动指令。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: init_device参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-run_motor:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
mode: null
|
||||
position: null
|
||||
velocity: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: 步进电机运动控制函数。根据指定的运动模式、目标位置和速度参数控制电机运动。支持多种运动模式和精确的位置控制,自动处理运动轨迹规划和执行。该函数提供异步执行和状态反馈,确保运动的准确性和可靠性。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
mode:
|
||||
type: string
|
||||
position:
|
||||
type: number
|
||||
velocity:
|
||||
type: integer
|
||||
required:
|
||||
- mode
|
||||
- position
|
||||
- velocity
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: run_motor参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
execute_command_from_outer:
|
||||
type: SendCmd
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
success: success
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.motor.iCL42:iCL42Driver
|
||||
status_types:
|
||||
is_executing_run: bool
|
||||
motor_position: int
|
||||
success: bool
|
||||
type: python
|
||||
config_info: []
|
||||
description: iCL42步进电机驱动器,用于实验室设备的精密线性运动控制。该设备通过串口通信控制iCL42型步进电机驱动器,支持多种运动模式和精确的位置、速度控制。具备位置反馈、运行状态监控和故障检测功能。适用于自动进样器、样品传送、精密定位平台等需要准确线性运动控制的实验室自动化设备。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
device_address:
|
||||
default: 1
|
||||
type: integer
|
||||
device_com:
|
||||
default: COM9
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
is_executing_run:
|
||||
type: boolean
|
||||
motor_position:
|
||||
type: integer
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- motor_position
|
||||
- is_executing_run
|
||||
- success
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,5 +1,315 @@
|
||||
lh_joint_publisher:
|
||||
category:
|
||||
- sim_nodes
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-check_tf_update_actions:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: check_tf_update_actions的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: check_tf_update_actions参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-find_resource_parent:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
resource_id: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: find_resource_parent的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
resource_id:
|
||||
type: string
|
||||
required:
|
||||
- resource_id
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: find_resource_parent参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-inverse_kinematics:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
parent_id: null
|
||||
x: null
|
||||
x_joint: null
|
||||
y: null
|
||||
y_joint: null
|
||||
z: null
|
||||
z_joint: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: inverse_kinematics的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
parent_id:
|
||||
type: string
|
||||
x:
|
||||
type: string
|
||||
x_joint:
|
||||
type: object
|
||||
y:
|
||||
type: string
|
||||
y_joint:
|
||||
type: object
|
||||
z:
|
||||
type: string
|
||||
z_joint:
|
||||
type: object
|
||||
required:
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
- parent_id
|
||||
- x_joint
|
||||
- y_joint
|
||||
- z_joint
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: inverse_kinematics参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-lh_joint_action_callback:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
goal_handle: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: lh_joint_action_callback的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
goal_handle:
|
||||
type: string
|
||||
required:
|
||||
- goal_handle
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: lh_joint_action_callback参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-lh_joint_pub_callback:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: lh_joint_pub_callback的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: lh_joint_pub_callback参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-move_joints:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
option: null
|
||||
resource_names: null
|
||||
speed: 0.1
|
||||
x: null
|
||||
x_joint: null
|
||||
y: null
|
||||
y_joint: null
|
||||
z: null
|
||||
z_joint: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: move_joints的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
option:
|
||||
type: string
|
||||
resource_names:
|
||||
type: string
|
||||
speed:
|
||||
default: 0.1
|
||||
type: string
|
||||
x:
|
||||
type: string
|
||||
x_joint:
|
||||
type: string
|
||||
y:
|
||||
type: string
|
||||
y_joint:
|
||||
type: string
|
||||
z:
|
||||
type: string
|
||||
z_joint:
|
||||
type: string
|
||||
required:
|
||||
- resource_names
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
- option
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: move_joints参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-move_to:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
joint_positions: null
|
||||
parent_id: null
|
||||
speed: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: move_to的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
joint_positions:
|
||||
type: string
|
||||
parent_id:
|
||||
type: string
|
||||
speed:
|
||||
type: string
|
||||
required:
|
||||
- joint_positions
|
||||
- speed
|
||||
- parent_id
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: move_to参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-resource_move:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
channels: null
|
||||
link_name: null
|
||||
resource_id: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: resource_move的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
channels:
|
||||
type: array
|
||||
link_name:
|
||||
type: string
|
||||
resource_id:
|
||||
type: string
|
||||
required:
|
||||
- resource_id
|
||||
- link_name
|
||||
- channels
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: resource_move参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-send_resource_action:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
link_name: null
|
||||
resource_id_list: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: send_resource_action的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
link_name:
|
||||
type: string
|
||||
resource_id_list:
|
||||
type: array
|
||||
required:
|
||||
- resource_id_list
|
||||
- link_name
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: send_resource_action参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
module: unilabos.devices.ros_dev.liquid_handler_joint_publisher:LiquidHandlerJointPublisher
|
||||
status_types: {}
|
||||
type: ros2
|
||||
|
||||
config_info: []
|
||||
description: 液体处理器关节发布器,用于ROS2仿真系统中的液体处理设备运动控制。该节点通过发布关节状态驱动仿真模型中的机械臂运动,支持三维坐标到关节空间的逆运动学转换、多关节协调控制、资源跟踪和TF变换。具备精确的位置控制、速度调节、pick-and-place操作等功能。适用于液体处理系统的虚拟仿真、运动规划验证、系统集成测试等应用场景。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
device_id:
|
||||
default: lh_joint_publisher
|
||||
type: string
|
||||
rate:
|
||||
default: 50
|
||||
type: string
|
||||
resource_tracker:
|
||||
type: string
|
||||
resources_config:
|
||||
type: array
|
||||
required:
|
||||
- resources_config
|
||||
- resource_tracker
|
||||
type: object
|
||||
data:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,65 +1,758 @@
|
||||
heaterstirrer.dalong:
|
||||
description: DaLong heater stirrer
|
||||
chiller:
|
||||
category:
|
||||
- temperature
|
||||
class:
|
||||
module: unilabos.devices.heaterstirrer.dalong:HeaterStirrer_DaLong
|
||||
type: python
|
||||
status_types:
|
||||
temp: Float64
|
||||
temp_warning: Float64
|
||||
stir_speed: Float64
|
||||
action_value_mappings:
|
||||
set_temp_warning:
|
||||
type: SendCmd
|
||||
goal:
|
||||
command: temp
|
||||
auto-build_modbus_frame:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
device_address: null
|
||||
function_code: null
|
||||
register_address: null
|
||||
value: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: build_modbus_frame的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
device_address:
|
||||
type: integer
|
||||
function_code:
|
||||
type: integer
|
||||
register_address:
|
||||
type: integer
|
||||
value:
|
||||
type: integer
|
||||
required:
|
||||
- device_address
|
||||
- function_code
|
||||
- register_address
|
||||
- value
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: build_modbus_frame参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-convert_temperature_to_modbus_value:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
decimal_points: 1
|
||||
temperature: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: convert_temperature_to_modbus_value的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
decimal_points:
|
||||
default: 1
|
||||
type: integer
|
||||
temperature:
|
||||
type: number
|
||||
required:
|
||||
- temperature
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: convert_temperature_to_modbus_value参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-modbus_crc:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
data: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: modbus_crc的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
data:
|
||||
type: string
|
||||
required:
|
||||
- data
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: modbus_crc参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-stop:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: stop的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: stop参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
set_temperature:
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
set_temp_target:
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
goal:
|
||||
command: temp
|
||||
module: unilabos.devices.temperature.chiller:Chiller
|
||||
status_types: {}
|
||||
type: python
|
||||
config_info: []
|
||||
description: 实验室制冷设备,用于精确的温度控制和冷却操作。该设备通过Modbus RTU协议与控制系统通信,支持精确的温度设定和监控。具备快速降温、恒温控制和温度保持功能,广泛应用于需要低温环境的化学反应、样品保存、结晶操作等实验场景。提供稳定可靠的冷却性能,确保实验过程的温度精度。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
port:
|
||||
type: string
|
||||
rate:
|
||||
default: 9600
|
||||
type: string
|
||||
required:
|
||||
- port
|
||||
type: object
|
||||
data:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
version: 1.0.0
|
||||
heaterstirrer.dalong:
|
||||
category:
|
||||
- temperature
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-close:
|
||||
feedback: {}
|
||||
result:
|
||||
success: success
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: close的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: close参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_stir_speed:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
speed: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: set_stir_speed的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
speed:
|
||||
type: number
|
||||
required:
|
||||
- speed
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_stir_speed参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-set_temp_inner:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
temp: null
|
||||
type: warning
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: set_temp_inner的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
temp:
|
||||
type: number
|
||||
type:
|
||||
default: warning
|
||||
type: string
|
||||
required:
|
||||
- temp
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: set_temp_inner参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
heatchill:
|
||||
type: HeatChill
|
||||
goal:
|
||||
vessel: vessel
|
||||
temp: temp
|
||||
time: time
|
||||
purpose: purpose
|
||||
feedback:
|
||||
status: status
|
||||
result:
|
||||
success: success
|
||||
|
||||
chiller:
|
||||
description: Chiller
|
||||
class:
|
||||
module: unilabos.devices.temperature.chiller:Chiller
|
||||
type: python
|
||||
action_value_mappings:
|
||||
set_temperature:
|
||||
type: SendCmd
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
purpose: purpose
|
||||
temp: temp
|
||||
time: time
|
||||
vessel: vessel
|
||||
goal_default:
|
||||
pressure: ''
|
||||
purpose: ''
|
||||
reflux_solvent: ''
|
||||
stir: false
|
||||
stir_speed: 0.0
|
||||
temp: 0.0
|
||||
temp_spec: ''
|
||||
time: ''
|
||||
time_spec: ''
|
||||
vessel:
|
||||
category: ''
|
||||
children: []
|
||||
config: ''
|
||||
data: ''
|
||||
id: ''
|
||||
name: ''
|
||||
parent: ''
|
||||
pose:
|
||||
orientation:
|
||||
w: 1.0
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
position:
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
sample_id: ''
|
||||
type: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
tempsensor:
|
||||
description: Temperature sensor
|
||||
class:
|
||||
module: unilabos.devices.temperature.sensor_node:TempSensorNode
|
||||
type: python
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: HeatChill_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
pressure:
|
||||
type: string
|
||||
purpose:
|
||||
type: string
|
||||
reflux_solvent:
|
||||
type: string
|
||||
stir:
|
||||
type: boolean
|
||||
stir_speed:
|
||||
type: number
|
||||
temp:
|
||||
type: number
|
||||
temp_spec:
|
||||
type: string
|
||||
time:
|
||||
type: string
|
||||
time_spec:
|
||||
type: string
|
||||
vessel:
|
||||
properties:
|
||||
category:
|
||||
type: string
|
||||
children:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
config:
|
||||
type: string
|
||||
data:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
parent:
|
||||
type: string
|
||||
pose:
|
||||
properties:
|
||||
orientation:
|
||||
properties:
|
||||
w:
|
||||
type: number
|
||||
x:
|
||||
type: number
|
||||
y:
|
||||
type: number
|
||||
z:
|
||||
type: number
|
||||
required:
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
- w
|
||||
title: Quaternion
|
||||
type: object
|
||||
position:
|
||||
properties:
|
||||
x:
|
||||
type: number
|
||||
y:
|
||||
type: number
|
||||
z:
|
||||
type: number
|
||||
required:
|
||||
- x
|
||||
- y
|
||||
- z
|
||||
title: Point
|
||||
type: object
|
||||
required:
|
||||
- position
|
||||
- orientation
|
||||
title: Pose
|
||||
type: object
|
||||
sample_id:
|
||||
type: string
|
||||
type:
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- sample_id
|
||||
- children
|
||||
- parent
|
||||
- type
|
||||
- category
|
||||
- pose
|
||||
- config
|
||||
- data
|
||||
title: Resource
|
||||
type: object
|
||||
required:
|
||||
- vessel
|
||||
- temp
|
||||
- time
|
||||
- temp_spec
|
||||
- time_spec
|
||||
- pressure
|
||||
- reflux_solvent
|
||||
- stir
|
||||
- stir_speed
|
||||
- purpose
|
||||
title: HeatChill_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- success
|
||||
- message
|
||||
- return_info
|
||||
title: HeatChill_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: HeatChill
|
||||
type: object
|
||||
type: HeatChill
|
||||
set_temp_target:
|
||||
feedback: {}
|
||||
goal:
|
||||
command: temp
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
set_temp_warning:
|
||||
feedback: {}
|
||||
goal:
|
||||
command: temp
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.heaterstirrer.dalong:HeaterStirrer_DaLong
|
||||
status_types:
|
||||
value: Float64
|
||||
warning: Float64
|
||||
status: str
|
||||
stir_speed: float
|
||||
temp: float
|
||||
temp_target: float
|
||||
temp_warning: float
|
||||
type: python
|
||||
config_info: []
|
||||
description: 大龙加热搅拌器,集成加热和搅拌双重功能的实验室设备。该设备通过串口通信控制,支持精确的温度调节、搅拌速度控制和安全保护功能。具备实时温度监测、目标温度设定、安全温度报警等特性。适用于化学合成、样品制备、反应控制等需要同时进行加热和搅拌的实验操作,提供稳定均匀的反应环境。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
baudrate:
|
||||
default: 9600
|
||||
type: integer
|
||||
port:
|
||||
default: COM6
|
||||
type: string
|
||||
temp_warning:
|
||||
default: 50.0
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
stir_speed:
|
||||
type: number
|
||||
temp:
|
||||
type: number
|
||||
temp_target:
|
||||
type: number
|
||||
temp_warning:
|
||||
type: number
|
||||
required:
|
||||
- status
|
||||
- stir_speed
|
||||
- temp
|
||||
- temp_warning
|
||||
- temp_target
|
||||
type: object
|
||||
version: 1.0.0
|
||||
tempsensor:
|
||||
category:
|
||||
- temperature
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-build_modbus_request:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
device_id: null
|
||||
function_code: null
|
||||
register_address: null
|
||||
register_count: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: build_modbus_request的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
device_id:
|
||||
type: string
|
||||
function_code:
|
||||
type: string
|
||||
register_address:
|
||||
type: string
|
||||
register_count:
|
||||
type: string
|
||||
required:
|
||||
- device_id
|
||||
- function_code
|
||||
- register_address
|
||||
- register_count
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: build_modbus_request参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-calculate_crc:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
data: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: calculate_crc的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
data:
|
||||
type: string
|
||||
required:
|
||||
- data
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: calculate_crc参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-read_modbus_response:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
response: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: read_modbus_response的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
response:
|
||||
type: string
|
||||
required:
|
||||
- response
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: read_modbus_response参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-send_prototype_command:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default:
|
||||
command: null
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: send_prototype_command的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: send_prototype_command参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
set_warning:
|
||||
type: SendCmd
|
||||
feedback: {}
|
||||
goal:
|
||||
command: command
|
||||
feedback: {}
|
||||
goal_default:
|
||||
command: ''
|
||||
handles: []
|
||||
result:
|
||||
success: success
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
title: SendCmd_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
command:
|
||||
type: string
|
||||
required:
|
||||
- command
|
||||
title: SendCmd_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: SendCmd_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: SendCmd
|
||||
type: object
|
||||
type: SendCmd
|
||||
module: unilabos.devices.temperature.sensor_node:TempSensorNode
|
||||
status_types:
|
||||
value: float
|
||||
type: python
|
||||
config_info: []
|
||||
description: 高精度温度传感器设备,用于实验室环境和设备的温度监测。该传感器通过Modbus RTU协议与控制系统通信,提供实时准确的温度数据。具备高精度测量、报警温度设定、数据稳定性好等特点。适用于反应器监控、环境温度监测、设备保护等需要精确温度测量的实验场景,为实验安全和数据可靠性提供保障。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
address:
|
||||
type: string
|
||||
baudrate:
|
||||
default: 9600
|
||||
type: string
|
||||
port:
|
||||
type: string
|
||||
warning:
|
||||
type: string
|
||||
required:
|
||||
- port
|
||||
- warning
|
||||
- address
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
value:
|
||||
type: number
|
||||
required:
|
||||
- value
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,81 +1,358 @@
|
||||
vacuum_pump.mock:
|
||||
description: Mock vacuum pump
|
||||
class:
|
||||
module: unilabos.devices.pump_and_valve.vacuum_pump_mock:VacuumPumpMock
|
||||
type: python
|
||||
status_types:
|
||||
status: String
|
||||
action_value_mappings:
|
||||
open:
|
||||
type: EmptyIn
|
||||
goal: {}
|
||||
feedback: {}
|
||||
result: {}
|
||||
close:
|
||||
type: EmptyIn
|
||||
goal: {}
|
||||
feedback: {}
|
||||
result: {}
|
||||
set_status:
|
||||
type: StrSingleInput
|
||||
goal:
|
||||
string: string
|
||||
feedback: {}
|
||||
result: {}
|
||||
handles:
|
||||
- handler_key: out
|
||||
label: out
|
||||
data_type: fluid
|
||||
io_type: source
|
||||
data_source: handle
|
||||
data_key: fluid_in
|
||||
init_param_schema:
|
||||
type: object
|
||||
properties:
|
||||
port:
|
||||
type: string
|
||||
description: "通信端口"
|
||||
default: "COM6"
|
||||
required:
|
||||
- port
|
||||
|
||||
gas_source.mock:
|
||||
description: Mock gas source
|
||||
category:
|
||||
- vacuum_and_purge
|
||||
class:
|
||||
module: unilabos.devices.pump_and_valve.vacuum_pump_mock:VacuumPumpMock
|
||||
type: python
|
||||
status_types:
|
||||
status: String
|
||||
action_value_mappings:
|
||||
open:
|
||||
type: EmptyIn
|
||||
goal: {}
|
||||
auto-is_closed:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: is_closed的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: is_closed参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-is_open:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: is_open的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: is_open参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
close:
|
||||
type: EmptyIn
|
||||
goal: {}
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
required:
|
||||
- return_info
|
||||
title: EmptyIn_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: EmptyIn
|
||||
type: object
|
||||
type: EmptyIn
|
||||
open:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
required:
|
||||
- return_info
|
||||
title: EmptyIn_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: EmptyIn
|
||||
type: object
|
||||
type: EmptyIn
|
||||
set_status:
|
||||
type: StrSingleInput
|
||||
feedback: {}
|
||||
goal:
|
||||
string: string
|
||||
feedback: {}
|
||||
goal_default:
|
||||
string: ''
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: StrSingleInput_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
string:
|
||||
type: string
|
||||
required:
|
||||
- string
|
||||
title: StrSingleInput_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: StrSingleInput_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: StrSingleInput
|
||||
type: object
|
||||
type: StrSingleInput
|
||||
module: unilabos.devices.pump_and_valve.vacuum_pump_mock:VacuumPumpMock
|
||||
status_types:
|
||||
status: str
|
||||
type: python
|
||||
config_info: []
|
||||
description: 模拟气体源设备,用于系统测试和开发调试。该设备模拟真实气体源的开关控制和状态监测功能,支持气体供应的启停操作。提供与真实气体源相同的接口和状态反馈,便于在没有实际硬件的情况下进行系统集成测试和算法验证。适用于气路系统调试、软件开发和实验流程验证等场景。
|
||||
handles:
|
||||
- handler_key: out
|
||||
label: out
|
||||
data_type: fluid
|
||||
io_type: source
|
||||
data_source: executor
|
||||
data_key: fluid_out
|
||||
- data_key: fluid_out
|
||||
data_source: executor
|
||||
data_type: fluid
|
||||
handler_key: out
|
||||
io_type: source
|
||||
label: out
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
type: object
|
||||
properties:
|
||||
port:
|
||||
type: string
|
||||
description: "通信端口"
|
||||
default: "COM6"
|
||||
required:
|
||||
- port
|
||||
config:
|
||||
properties:
|
||||
port:
|
||||
default: COM6
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
type: object
|
||||
version: 1.0.0
|
||||
vacuum_pump.mock:
|
||||
category:
|
||||
- vacuum_and_purge
|
||||
class:
|
||||
action_value_mappings:
|
||||
auto-is_closed:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: is_closed的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: is_closed参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-is_open:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: is_open的参数schema
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: is_open参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
close:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
required:
|
||||
- return_info
|
||||
title: EmptyIn_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: EmptyIn
|
||||
type: object
|
||||
type: EmptyIn
|
||||
open:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
required:
|
||||
- return_info
|
||||
title: EmptyIn_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: EmptyIn
|
||||
type: object
|
||||
type: EmptyIn
|
||||
set_status:
|
||||
feedback: {}
|
||||
goal:
|
||||
string: string
|
||||
goal_default:
|
||||
string: ''
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: StrSingleInput_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
string:
|
||||
type: string
|
||||
required:
|
||||
- string
|
||||
title: StrSingleInput_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: StrSingleInput_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: StrSingleInput
|
||||
type: object
|
||||
type: StrSingleInput
|
||||
module: unilabos.devices.pump_and_valve.vacuum_pump_mock:VacuumPumpMock
|
||||
status_types:
|
||||
status: str
|
||||
type: python
|
||||
config_info: []
|
||||
description: 模拟真空泵设备,用于系统测试和开发调试。该设备模拟真实真空泵的抽气功能和状态控制,支持真空系统的启停操作和状态监测。提供与真实真空泵相同的接口和控制逻辑,便于在没有实际硬件的情况下进行真空系统的集成测试。适用于真空工艺调试、软件开发和实验流程验证等场景。
|
||||
handles:
|
||||
- data_key: fluid_in
|
||||
data_source: handle
|
||||
data_type: fluid
|
||||
handler_key: out
|
||||
io_type: source
|
||||
label: out
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
port:
|
||||
default: COM6
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
required:
|
||||
- status
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,27 +1,183 @@
|
||||
zhida_hplc:
|
||||
description: Zhida HPLC
|
||||
category:
|
||||
- zhida_hplc
|
||||
class:
|
||||
module: unilabos.devices.zhida_hplc.zhida:ZhidaClient
|
||||
type: python
|
||||
status_types:
|
||||
status: String
|
||||
action_value_mappings:
|
||||
abort:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
required:
|
||||
- return_info
|
||||
title: EmptyIn_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: EmptyIn
|
||||
type: object
|
||||
type: EmptyIn
|
||||
auto-close:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: HPLC设备连接关闭函数。安全地断开与智达HPLC设备的TCP socket连接,释放网络资源。该函数确保连接的正确关闭,避免网络资源泄露。通常在设备使用完毕或系统关闭时调用。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: close参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
auto-connect:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: HPLC设备连接建立函数。与智达HPLC设备建立TCP socket通信连接,配置通信超时参数。该函数是设备使用前的必要步骤,建立成功后可进行状态查询、方法获取、任务启动等操作。连接失败时会抛出异常。
|
||||
properties:
|
||||
feedback: {}
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
type: object
|
||||
result: {}
|
||||
required:
|
||||
- goal
|
||||
title: connect参数
|
||||
type: object
|
||||
type: UniLabJsonCommand
|
||||
get_methods:
|
||||
feedback: {}
|
||||
goal: {}
|
||||
goal_default: {}
|
||||
handles: []
|
||||
result: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties: {}
|
||||
required: []
|
||||
title: EmptyIn_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
required:
|
||||
- return_info
|
||||
title: EmptyIn_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: EmptyIn
|
||||
type: object
|
||||
type: EmptyIn
|
||||
start:
|
||||
type: StrSingleInput
|
||||
feedback: {}
|
||||
goal:
|
||||
string: string
|
||||
feedback: {}
|
||||
goal_default:
|
||||
string: ''
|
||||
handles: []
|
||||
result: {}
|
||||
abort:
|
||||
type: EmptyIn
|
||||
goal: {}
|
||||
feedback: {}
|
||||
result: {}
|
||||
get_methods:
|
||||
type: EmptyIn
|
||||
goal: {}
|
||||
feedback: {}
|
||||
result: {}
|
||||
|
||||
schema:
|
||||
properties: {}
|
||||
schema:
|
||||
description: ''
|
||||
properties:
|
||||
feedback:
|
||||
properties: {}
|
||||
required: []
|
||||
title: StrSingleInput_Feedback
|
||||
type: object
|
||||
goal:
|
||||
properties:
|
||||
string:
|
||||
type: string
|
||||
required:
|
||||
- string
|
||||
title: StrSingleInput_Goal
|
||||
type: object
|
||||
result:
|
||||
properties:
|
||||
return_info:
|
||||
type: string
|
||||
success:
|
||||
type: boolean
|
||||
required:
|
||||
- return_info
|
||||
- success
|
||||
title: StrSingleInput_Result
|
||||
type: object
|
||||
required:
|
||||
- goal
|
||||
title: StrSingleInput
|
||||
type: object
|
||||
type: StrSingleInput
|
||||
module: unilabos.devices.zhida_hplc.zhida:ZhidaClient
|
||||
status_types:
|
||||
methods: dict
|
||||
status: dict
|
||||
type: python
|
||||
config_info: []
|
||||
description: 智达高效液相色谱(HPLC)分析设备,用于实验室样品的分离、检测和定量分析。该设备通过TCP socket与HPLC控制系统通信,支持远程控制和状态监控。具备自动进样、梯度洗脱、多检测器数据采集等功能,可执行复杂的色谱分析方法。适用于化学分析、药物检测、环境监测、生物样品分析等需要高精度分离分析的实验室应用场景。
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema:
|
||||
config:
|
||||
properties:
|
||||
host:
|
||||
default: 192.168.1.47
|
||||
type: string
|
||||
port:
|
||||
default: 5792
|
||||
type: string
|
||||
timeout:
|
||||
default: 10.0
|
||||
type: string
|
||||
required: []
|
||||
type: object
|
||||
data:
|
||||
properties:
|
||||
methods:
|
||||
type: object
|
||||
status:
|
||||
type: object
|
||||
required:
|
||||
- status
|
||||
- methods
|
||||
type: object
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
import copy
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import inspect
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import yaml
|
||||
|
||||
from unilabos.ros.msgs.message_converter import msg_converter_manager, ros_action_to_json_schema
|
||||
from unilabos.resources.graphio import resource_plr_to_ulab, tree_to_list
|
||||
from unilabos.ros.msgs.message_converter import msg_converter_manager, ros_action_to_json_schema, String
|
||||
from unilabos.utils import logger
|
||||
from unilabos.utils.decorator import singleton
|
||||
from unilabos.utils.import_manager import get_enhanced_class_info, get_class
|
||||
from unilabos.utils.type_check import NoAliasDumper
|
||||
|
||||
DEFAULT_PATHS = [Path(__file__).absolute().parent]
|
||||
|
||||
@@ -32,7 +38,7 @@ class Registry:
|
||||
# 其他状态变量
|
||||
# self.is_host_mode = False # 移至BasicConfig中
|
||||
|
||||
def setup(self):
|
||||
def setup(self, complete_registry=False):
|
||||
# 检查是否已调用过setup
|
||||
if self._setup_called:
|
||||
logger.critical("[UniLab Registry] setup方法已被调用过,不允许多次调用")
|
||||
@@ -60,7 +66,9 @@ class Registry:
|
||||
},
|
||||
"feedback": {},
|
||||
"result": {"success": "success"},
|
||||
"schema": ros_action_to_json_schema(self.ResourceCreateFromOuter),
|
||||
"schema": ros_action_to_json_schema(
|
||||
self.ResourceCreateFromOuter, "用于创建或更新物料资源,每次传入多个物料信息。"
|
||||
),
|
||||
"goal_default": yaml.safe_load(
|
||||
io.StringIO(get_yaml_from_goal_type(self.ResourceCreateFromOuter.Goal))
|
||||
),
|
||||
@@ -81,18 +89,28 @@ class Registry:
|
||||
},
|
||||
"feedback": {},
|
||||
"result": {"success": "success"},
|
||||
"schema": ros_action_to_json_schema(self.ResourceCreateFromOuterEasy),
|
||||
"schema": ros_action_to_json_schema(
|
||||
self.ResourceCreateFromOuterEasy, "用于创建或更新物料资源,每次传入一个物料信息。"
|
||||
),
|
||||
"goal_default": yaml.safe_load(
|
||||
io.StringIO(get_yaml_from_goal_type(self.ResourceCreateFromOuterEasy.Goal))
|
||||
),
|
||||
"handles": {
|
||||
"output": [{
|
||||
"handler_key": "labware",
|
||||
"label": "Labware",
|
||||
"data_type": "resource",
|
||||
"data_source": "handle",
|
||||
"data_key": "liquid"
|
||||
}]
|
||||
"output": [
|
||||
{
|
||||
"handler_key": "labware",
|
||||
"label": "Labware",
|
||||
"data_type": "resource",
|
||||
"data_source": "handle",
|
||||
"data_key": "liquid",
|
||||
}
|
||||
]
|
||||
},
|
||||
# todo: support nested keys, switch to non ros message schema
|
||||
"placeholder_keys": {
|
||||
"res_id": "unilabos_resources", # 将当前实验室的全部物料id作为下拉框可选择
|
||||
"device_id": "unilabos_devices", # 将当前实验室的全部设备id作为下拉框可选择
|
||||
"parent": "unilabos_resources", # 将当前实验室的全部物料id作为下拉框可选择
|
||||
},
|
||||
},
|
||||
"test_latency": {
|
||||
@@ -100,17 +118,21 @@ class Registry:
|
||||
"goal": {},
|
||||
"feedback": {},
|
||||
"result": {"latency_ms": "latency_ms", "time_diff_ms": "time_diff_ms"},
|
||||
"schema": ros_action_to_json_schema(self.EmptyIn),
|
||||
"schema": ros_action_to_json_schema(
|
||||
self.EmptyIn, "用于测试延迟的动作,返回延迟时间和时间差。"
|
||||
),
|
||||
"goal_default": {},
|
||||
"handles": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
"version": "1.0.0",
|
||||
"category": [],
|
||||
"config_info": [],
|
||||
"icon": "icon_device.webp",
|
||||
"registry_type": "device",
|
||||
"handles": [],
|
||||
"init_param_schema": {},
|
||||
"schema": {"properties": {}, "additionalProperties": False, "type": "object"},
|
||||
"file_path": "/",
|
||||
}
|
||||
}
|
||||
@@ -121,33 +143,60 @@ class Registry:
|
||||
sys_path = path.parent
|
||||
logger.debug(f"[UniLab Registry] Path {i+1}/{len(self.registry_paths)}: {sys_path}")
|
||||
sys.path.append(str(sys_path))
|
||||
self.load_device_types(path)
|
||||
self.load_resource_types(path)
|
||||
self.load_device_types(path, complete_registry)
|
||||
self.load_resource_types(path, complete_registry)
|
||||
logger.info("[UniLab Registry] 注册表设置完成")
|
||||
# 标记setup已被调用
|
||||
self._setup_called = True
|
||||
|
||||
def load_resource_types(self, path: os.PathLike):
|
||||
def load_resource_types(self, path: os.PathLike, complete_registry: bool):
|
||||
abs_path = Path(path).absolute()
|
||||
resource_path = abs_path / "resources"
|
||||
files = list(resource_path.glob("*/*.yaml"))
|
||||
logger.debug(f"[UniLab Registry] resources: {resource_path.exists()}, total: {len(files)}")
|
||||
current_resource_number = len(self.resource_type_registry) + 1
|
||||
for i, file in enumerate(files):
|
||||
data = yaml.safe_load(open(file, encoding="utf-8"))
|
||||
with open(file, encoding="utf-8", mode="r") as f:
|
||||
data = yaml.safe_load(io.StringIO(f.read()))
|
||||
complete_data = {}
|
||||
if data:
|
||||
# 为每个资源添加文件路径信息
|
||||
for resource_id, resource_info in data.items():
|
||||
resource_info["file_path"] = str(file.absolute()).replace("\\", "/")
|
||||
if "description" not in resource_info:
|
||||
resource_info["description"] = ""
|
||||
if "version" not in resource_info:
|
||||
resource_info["version"] = "1.0.0"
|
||||
if "category" not in resource_info:
|
||||
resource_info["category"] = [file.stem]
|
||||
elif file.stem not in resource_info["category"]:
|
||||
resource_info["category"].append(file.stem)
|
||||
if "config_info" not in resource_info:
|
||||
resource_info["config_info"] = []
|
||||
if "icon" not in resource_info:
|
||||
resource_info["icon"] = ""
|
||||
if "handles" not in resource_info:
|
||||
resource_info["handles"] = []
|
||||
if "init_param_schema" not in resource_info:
|
||||
resource_info["init_param_schema"] = {}
|
||||
if complete_registry:
|
||||
class_info = resource_info.get("class", {})
|
||||
if len(class_info) and "module" in class_info:
|
||||
if class_info.get("type") == "pylabrobot":
|
||||
res_class = get_class(class_info["module"])
|
||||
if callable(res_class) and not isinstance(
|
||||
res_class, type
|
||||
): # 有的是类,有的是函数,这里暂时只登记函数类的
|
||||
res_instance = res_class(res_class.__name__)
|
||||
res_ulr = tree_to_list([resource_plr_to_ulab(res_instance)])
|
||||
resource_info["config_info"] = res_ulr
|
||||
resource_info["registry_type"] = "resource"
|
||||
complete_data[resource_id] = copy.deepcopy(dict(sorted(resource_info.items()))) # 稍后dump到文件
|
||||
|
||||
complete_data = dict(sorted(complete_data.items()))
|
||||
complete_data = copy.deepcopy(complete_data)
|
||||
if complete_registry:
|
||||
with open(file, "w", encoding="utf-8") as f:
|
||||
yaml.dump(complete_data, f, allow_unicode=True, default_flow_style=False, Dumper=NoAliasDumper)
|
||||
|
||||
self.resource_type_registry.update(data)
|
||||
logger.debug(
|
||||
f"[UniLab Registry] Resource-{current_resource_number} File-{i+1}/{len(files)} "
|
||||
@@ -157,6 +206,54 @@ class Registry:
|
||||
else:
|
||||
logger.debug(f"[UniLab Registry] Res File-{i+1}/{len(files)} Not Valid YAML File: {file.absolute()}")
|
||||
|
||||
def _extract_class_docstrings(self, module_string: str) -> Dict[str, str]:
|
||||
"""
|
||||
从模块字符串中提取类和方法的docstring信息
|
||||
|
||||
Args:
|
||||
module_string: 模块字符串,格式为 "module.path:ClassName"
|
||||
|
||||
Returns:
|
||||
包含类和方法docstring信息的字典
|
||||
"""
|
||||
docstrings = {"class_docstring": "", "methods": {}}
|
||||
|
||||
if not module_string or ":" not in module_string:
|
||||
return docstrings
|
||||
|
||||
try:
|
||||
module_path, class_name = module_string.split(":", 1)
|
||||
|
||||
# 动态导入模块
|
||||
module = importlib.import_module(module_path)
|
||||
|
||||
# 获取类
|
||||
if hasattr(module, class_name):
|
||||
cls = getattr(module, class_name)
|
||||
|
||||
# 获取类的docstring
|
||||
class_doc = inspect.getdoc(cls)
|
||||
if class_doc:
|
||||
docstrings["class_docstring"] = class_doc.strip()
|
||||
|
||||
# 获取所有方法的docstring
|
||||
for method_name, method in inspect.getmembers(cls, predicate=inspect.isfunction):
|
||||
method_doc = inspect.getdoc(method)
|
||||
if method_doc:
|
||||
docstrings["methods"][method_name] = method_doc.strip()
|
||||
|
||||
# 也获取属性方法的docstring
|
||||
for method_name, method in inspect.getmembers(cls, predicate=lambda x: isinstance(x, property)):
|
||||
if hasattr(method, "fget") and method.fget:
|
||||
method_doc = inspect.getdoc(method.fget)
|
||||
if method_doc:
|
||||
docstrings["methods"][method_name] = method_doc.strip()
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"[UniLab Registry] 无法提取docstring信息,模块: {module_string}, 错误: {str(e)}")
|
||||
|
||||
return docstrings
|
||||
|
||||
def _replace_type_with_class(self, type_name: str, device_id: str, field_name: str) -> Any:
|
||||
"""
|
||||
将类型名称替换为实际的类对象
|
||||
@@ -176,7 +273,14 @@ class Registry:
|
||||
if not type_name or type_name == "":
|
||||
logger.warning(f"[UniLab Registry] 设备 {device_id} 的 {field_name} 类型为空,跳过替换")
|
||||
return type_name
|
||||
if "." in type_name:
|
||||
convert_manager = { # 将python基本对象转为ros2基本对象
|
||||
"str": "String",
|
||||
"bool": "Bool",
|
||||
"int": "Int64",
|
||||
"float": "Float64",
|
||||
}
|
||||
type_name = convert_manager.get(type_name, type_name) # 替换为ROS2类型
|
||||
if ":" in type_name:
|
||||
type_class = msg_converter_manager.get_class(type_name)
|
||||
else:
|
||||
type_class = msg_converter_manager.search_class(type_name)
|
||||
@@ -186,7 +290,97 @@ class Registry:
|
||||
logger.error(f"[UniLab Registry] 无法找到类型 '{type_name}' 用于设备 {device_id} 的 {field_name}")
|
||||
sys.exit(1)
|
||||
|
||||
def load_device_types(self, path: os.PathLike):
|
||||
def _generate_schema_from_info(
|
||||
self,
|
||||
param_name: str,
|
||||
param_type: str,
|
||||
param_default: Any,
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
根据参数信息生成JSON Schema
|
||||
"""
|
||||
prop_schema = {}
|
||||
# 根据类型设置schema FIXME 不完整
|
||||
if param_type:
|
||||
param_type_lower = param_type.lower()
|
||||
if param_type_lower in ["str", "string"]:
|
||||
prop_schema["type"] = "string"
|
||||
elif param_type_lower in ["int", "integer"]:
|
||||
prop_schema["type"] = "integer"
|
||||
elif param_type_lower in ["float", "number"]:
|
||||
prop_schema["type"] = "number"
|
||||
elif param_type_lower in ["bool", "boolean"]:
|
||||
prop_schema["type"] = "boolean"
|
||||
elif param_type_lower in ["list", "array"]:
|
||||
prop_schema["type"] = "array"
|
||||
elif param_type_lower in ["dict", "object"]:
|
||||
prop_schema["type"] = "object"
|
||||
else:
|
||||
# 默认为字符串类型
|
||||
prop_schema["type"] = "string"
|
||||
else:
|
||||
# 如果没有类型信息,默认为字符串
|
||||
prop_schema["type"] = "string"
|
||||
|
||||
# 设置默认值
|
||||
if param_default is not None:
|
||||
prop_schema["default"] = param_default
|
||||
|
||||
return prop_schema
|
||||
|
||||
def _generate_status_types_schema(self, status_types: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
根据状态类型生成JSON Schema
|
||||
"""
|
||||
status_schema = {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
}
|
||||
for status_name, status_type in status_types.items():
|
||||
status_schema["properties"][status_name] = self._generate_schema_from_info(
|
||||
status_name, status_type["return_type"], None
|
||||
)
|
||||
status_schema["required"].append(status_name)
|
||||
return status_schema
|
||||
|
||||
def _generate_unilab_json_command_schema(
|
||||
self, method_args: List[Dict[str, Any]], method_name: str
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
根据UniLabJsonCommand方法信息生成JSON Schema,暂不支持嵌套类型
|
||||
|
||||
Args:
|
||||
method_args: 方法信息字典,包含args等
|
||||
method_name: 方法名称
|
||||
|
||||
Returns:
|
||||
JSON Schema格式的参数schema
|
||||
"""
|
||||
schema = {
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": [],
|
||||
}
|
||||
for arg_info in method_args:
|
||||
param_name = arg_info.get("name", "")
|
||||
param_type = arg_info.get("type", "")
|
||||
param_default = arg_info.get("default")
|
||||
param_required = arg_info.get("required", True)
|
||||
schema["properties"][param_name] = self._generate_schema_from_info(param_name, param_type, param_default)
|
||||
if param_required:
|
||||
schema["required"].append(param_name)
|
||||
|
||||
return {
|
||||
"title": f"{method_name}参数",
|
||||
"description": f"",
|
||||
"type": "object",
|
||||
"properties": {"goal": schema, "feedback": {}, "result": {}},
|
||||
"required": ["goal"],
|
||||
}
|
||||
|
||||
def load_device_types(self, path: os.PathLike, complete_registry: bool):
|
||||
# return
|
||||
abs_path = Path(path).absolute()
|
||||
devices_path = abs_path / "devices"
|
||||
device_comms_path = abs_path / "device_comms"
|
||||
@@ -199,12 +393,26 @@ class Registry:
|
||||
from unilabos.app.web.utils.action_utils import get_yaml_from_goal_type
|
||||
|
||||
for i, file in enumerate(files):
|
||||
data = yaml.safe_load(open(file, encoding="utf-8"))
|
||||
with open(file, encoding="utf-8", mode="r") as f:
|
||||
data = yaml.safe_load(io.StringIO(f.read()))
|
||||
complete_data = {}
|
||||
action_str_type_mapping = {
|
||||
"UniLabJsonCommand": "UniLabJsonCommand",
|
||||
"UniLabJsonCommandAsync": "UniLabJsonCommandAsync",
|
||||
}
|
||||
status_str_type_mapping = {}
|
||||
if data:
|
||||
# 在添加到注册表前处理类型替换
|
||||
for device_id, device_config in data.items():
|
||||
# 添加文件路径信息 - 使用规范化的完整文件路径
|
||||
device_config["file_path"] = str(file.absolute()).replace("\\", "/")
|
||||
if "version" not in device_config:
|
||||
device_config["version"] = "1.0.0"
|
||||
if "category" not in device_config:
|
||||
device_config["category"] = [file.stem]
|
||||
elif file.stem not in device_config["category"]:
|
||||
device_config["category"].append(file.stem)
|
||||
if "config_info" not in device_config:
|
||||
device_config["config_info"] = []
|
||||
if "description" not in device_config:
|
||||
device_config["description"] = ""
|
||||
if "icon" not in device_config:
|
||||
@@ -213,42 +421,145 @@ class Registry:
|
||||
device_config["handles"] = []
|
||||
if "init_param_schema" not in device_config:
|
||||
device_config["init_param_schema"] = {}
|
||||
device_config["registry_type"] = "device"
|
||||
if "class" in device_config:
|
||||
# 处理状态类型
|
||||
if "status_types" in device_config["class"]:
|
||||
for status_name, status_type in device_config["class"]["status_types"].items():
|
||||
device_config["class"]["status_types"][status_name] = self._replace_type_with_class(
|
||||
status_type, device_id, f"状态 {status_name}"
|
||||
)
|
||||
|
||||
# 处理动作值映射
|
||||
if "action_value_mappings" in device_config["class"]:
|
||||
if "status_types" not in device_config["class"]:
|
||||
device_config["class"]["status_types"] = {}
|
||||
if "action_value_mappings" not in device_config["class"]:
|
||||
device_config["class"]["action_value_mappings"] = {}
|
||||
enhanced_info = {}
|
||||
if complete_registry:
|
||||
device_config["class"]["status_types"].clear()
|
||||
enhanced_info = get_enhanced_class_info(device_config["class"]["module"], use_dynamic=True)
|
||||
device_config["class"]["status_types"].update(
|
||||
{k: v["return_type"] for k, v in enhanced_info["status_methods"].items()}
|
||||
)
|
||||
for status_name, status_type in device_config["class"]["status_types"].items():
|
||||
if status_type in ["Any", "None", "Unknown"]:
|
||||
status_type = "String" # 替换成ROS的String,便于显示
|
||||
device_config["class"]["status_types"][status_name] = status_type
|
||||
target_type = self._replace_type_with_class(status_type, device_id, f"状态 {status_name}")
|
||||
if target_type in [
|
||||
dict,
|
||||
list,
|
||||
]: # 对于嵌套类型返回的对象,暂时处理成字符串,无法直接进行转换
|
||||
target_type = String
|
||||
status_str_type_mapping[status_type] = target_type
|
||||
device_config["class"]["status_types"] = dict(
|
||||
sorted(device_config["class"]["status_types"].items())
|
||||
)
|
||||
if complete_registry:
|
||||
# 保存原有的description信息
|
||||
old_descriptions = {}
|
||||
for action_name, action_config in device_config["class"]["action_value_mappings"].items():
|
||||
if "handles" not in action_config:
|
||||
action_config["handles"] = []
|
||||
if "type" in action_config:
|
||||
action_config["type"] = self._replace_type_with_class(
|
||||
action_config["type"], device_id, f"动作 {action_name}"
|
||||
if "description" in action_config.get("schema", {}):
|
||||
description = action_config["schema"]["description"]
|
||||
if len(description):
|
||||
old_descriptions[action_name] = action_config["schema"]["description"]
|
||||
|
||||
device_config["class"]["action_value_mappings"] = {
|
||||
k: v
|
||||
for k, v in device_config["class"]["action_value_mappings"].items()
|
||||
if not k.startswith("auto-")
|
||||
}
|
||||
# 处理动作值映射
|
||||
device_config["class"]["action_value_mappings"].update(
|
||||
{
|
||||
f"auto-{k}": {
|
||||
"type": "UniLabJsonCommandAsync" if v["is_async"] else "UniLabJsonCommand",
|
||||
"goal": {},
|
||||
"feedback": {},
|
||||
"result": {},
|
||||
"schema": self._generate_unilab_json_command_schema(v["args"], k),
|
||||
"goal_default": {i["name"]: i["default"] for i in v["args"]},
|
||||
"handles": [],
|
||||
}
|
||||
# 不生成已配置action的动作
|
||||
for k, v in enhanced_info["action_methods"].items()
|
||||
if k not in device_config["class"]["action_value_mappings"]
|
||||
}
|
||||
)
|
||||
|
||||
# 恢复原有的description信息(auto开头的不修改)
|
||||
for action_name, description in old_descriptions.items():
|
||||
if action_name in device_config["class"]["action_value_mappings"]: # 有一些会被删除
|
||||
device_config["class"]["action_value_mappings"][action_name]["schema"][
|
||||
"description"
|
||||
] = description
|
||||
device_config["init_param_schema"] = {}
|
||||
device_config["init_param_schema"]["config"] = self._generate_unilab_json_command_schema(
|
||||
enhanced_info["init_params"], "__init__"
|
||||
)["properties"]["goal"]
|
||||
device_config["init_param_schema"]["data"] = self._generate_status_types_schema(
|
||||
enhanced_info["status_methods"]
|
||||
)
|
||||
|
||||
device_config.pop("schema", None)
|
||||
device_config["class"]["action_value_mappings"] = dict(
|
||||
sorted(device_config["class"]["action_value_mappings"].items())
|
||||
)
|
||||
for action_name, action_config in device_config["class"]["action_value_mappings"].items():
|
||||
if "handles" not in action_config:
|
||||
action_config["handles"] = []
|
||||
if "type" in action_config:
|
||||
action_type_str: str = action_config["type"]
|
||||
# 通过Json发放指令,而不是通过特殊的ros action进行处理
|
||||
if not action_type_str.startswith("UniLabJsonCommand"):
|
||||
target_type = self._replace_type_with_class(
|
||||
action_type_str, device_id, f"动作 {action_name}"
|
||||
)
|
||||
if action_config["type"] is not None:
|
||||
action_str_type_mapping[action_type_str] = target_type
|
||||
if target_type is not None:
|
||||
action_config["goal_default"] = yaml.safe_load(
|
||||
io.StringIO(get_yaml_from_goal_type(action_config["type"].Goal))
|
||||
io.StringIO(get_yaml_from_goal_type(target_type.Goal))
|
||||
)
|
||||
action_config["schema"] = ros_action_to_json_schema(action_config["type"])
|
||||
action_config["schema"] = ros_action_to_json_schema(target_type)
|
||||
else:
|
||||
logger.warning(
|
||||
f"[UniLab Registry] 设备 {device_id} 的动作 {action_name} 类型为空,跳过替换"
|
||||
)
|
||||
|
||||
self.device_type_registry.update(data)
|
||||
|
||||
for device_id in data.keys():
|
||||
complete_data[device_id] = copy.deepcopy(dict(sorted(device_config.items()))) # 稍后dump到文件
|
||||
for status_name, status_type in device_config["class"]["status_types"].items():
|
||||
device_config["class"]["status_types"][status_name] = status_str_type_mapping[status_type]
|
||||
for action_name, action_config in device_config["class"]["action_value_mappings"].items():
|
||||
action_config["type"] = action_str_type_mapping[action_config["type"]]
|
||||
for additional_action in ["_execute_driver_command", "_execute_driver_command_async"]:
|
||||
device_config["class"]["action_value_mappings"][additional_action] = {
|
||||
"type": self._replace_type_with_class(
|
||||
"StrSingleInput", device_id, f"动作 {additional_action}"
|
||||
),
|
||||
"goal": {"string": "string"},
|
||||
"feedback": {},
|
||||
"result": {},
|
||||
"schema": ros_action_to_json_schema(
|
||||
self._replace_type_with_class(
|
||||
"StrSingleInput", device_id, f"动作 {additional_action}"
|
||||
)
|
||||
),
|
||||
"goal_default": yaml.safe_load(
|
||||
io.StringIO(
|
||||
get_yaml_from_goal_type(
|
||||
self._replace_type_with_class(
|
||||
"StrSingleInput", device_id, f"动作 {additional_action}"
|
||||
).Goal
|
||||
)
|
||||
)
|
||||
),
|
||||
"handles": [],
|
||||
}
|
||||
if "registry_type" not in device_config:
|
||||
device_config["registry_type"] = "device"
|
||||
device_config["file_path"] = str(file.absolute()).replace("\\", "/")
|
||||
device_config["registry_type"] = "device"
|
||||
logger.debug(
|
||||
f"[UniLab Registry] Device-{current_device_number} File-{i+1}/{len(files)} Add {device_id} "
|
||||
+ f"[{data[device_id].get('name', '未命名设备')}]"
|
||||
)
|
||||
current_device_number += 1
|
||||
complete_data = dict(sorted(complete_data.items()))
|
||||
complete_data = copy.deepcopy(complete_data)
|
||||
with open(file, "w", encoding="utf-8") as f:
|
||||
yaml.dump(complete_data, f, allow_unicode=True, default_flow_style=False, Dumper=NoAliasDumper)
|
||||
self.device_type_registry.update(data)
|
||||
else:
|
||||
logger.debug(
|
||||
f"[UniLab Registry] Device File-{i+1}/{len(files)} Not Valid YAML File: {file.absolute()}"
|
||||
@@ -257,7 +568,35 @@ class Registry:
|
||||
def obtain_registry_device_info(self):
|
||||
devices = []
|
||||
for device_id, device_info in self.device_type_registry.items():
|
||||
msg = {"id": device_id, **device_info}
|
||||
device_info_copy = copy.deepcopy(device_info)
|
||||
if "class" in device_info_copy and "action_value_mappings" in device_info_copy["class"]:
|
||||
action_mappings = device_info_copy["class"]["action_value_mappings"]
|
||||
for action_name, action_config in action_mappings.items():
|
||||
if "schema" in action_config and action_config["schema"]:
|
||||
schema = action_config["schema"]
|
||||
# 确保schema结构存在
|
||||
if (
|
||||
"properties" in schema
|
||||
and "goal" in schema["properties"]
|
||||
and "properties" in schema["properties"]["goal"]
|
||||
):
|
||||
schema["properties"]["goal"]["properties"] = {
|
||||
"unilabos_device_id": {
|
||||
"type": "string",
|
||||
"default": "",
|
||||
"description": "UniLabOS设备ID,用于指定执行动作的具体设备实例",
|
||||
},
|
||||
**schema["properties"]["goal"]["properties"],
|
||||
}
|
||||
# 将 placeholder_keys 信息添加到 schema 中
|
||||
if "placeholder_keys" in action_config and action_config.get("schema", {}).get(
|
||||
"properties", {}
|
||||
).get("goal", {}):
|
||||
action_config["schema"]["properties"]["goal"]["_unilabos_placeholder_info"] = action_config[
|
||||
"placeholder_keys"
|
||||
]
|
||||
|
||||
msg = {"id": device_id, **device_info_copy}
|
||||
devices.append(msg)
|
||||
return devices
|
||||
|
||||
@@ -273,7 +612,7 @@ class Registry:
|
||||
lab_registry = Registry()
|
||||
|
||||
|
||||
def build_registry(registry_paths=None):
|
||||
def build_registry(registry_paths=None, complete_registry=False):
|
||||
"""
|
||||
构建或获取Registry单例实例
|
||||
|
||||
@@ -297,6 +636,6 @@ def build_registry(registry_paths=None):
|
||||
lab_registry.registry_paths.append(path)
|
||||
|
||||
# 初始化注册表
|
||||
lab_registry.setup()
|
||||
lab_registry.setup(complete_registry)
|
||||
|
||||
return lab_registry
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
OTDeck:
|
||||
description: Opentrons deck
|
||||
class:
|
||||
category:
|
||||
- deck
|
||||
class:
|
||||
module: pylabrobot.resources.opentrons.deck:OTDeck
|
||||
type: pylabrobot
|
||||
config_info: []
|
||||
description: Opentrons deck
|
||||
file_path: C:/Users/10230/PycharmProjects/Uni-Lab-OS/unilabos/registry/resources/opentrons/deck.yaml
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema: {}
|
||||
model:
|
||||
mesh: opentrons_liquid_handler
|
||||
type: device
|
||||
mesh: opentrons_liquid_handler
|
||||
registry_type: resource
|
||||
version: 1.0.0
|
||||
|
||||
@@ -1,5 +1,39 @@
|
||||
Opentrons_96_adapter_Vb:
|
||||
description: Opentrons 96 adapter Vb
|
||||
class:
|
||||
category:
|
||||
- plate_adapters
|
||||
class:
|
||||
module: pylabrobot.resources.opentrons.plate_adapters:Opentrons_96_adapter_Vb
|
||||
type: pylabrobot
|
||||
type: pylabrobot
|
||||
config_info:
|
||||
- children: []
|
||||
class: ''
|
||||
config:
|
||||
barcode: null
|
||||
category: plate_adapter
|
||||
model: Opentrons_96_adapter_Vb
|
||||
rotation:
|
||||
type: Rotation
|
||||
x: 0
|
||||
y: 0
|
||||
z: 0
|
||||
size_x: 127.76
|
||||
size_y: 85.48
|
||||
size_z: 18.55
|
||||
type: PlateAdapter
|
||||
data: {}
|
||||
id: Opentrons_96_adapter_Vb
|
||||
name: Opentrons_96_adapter_Vb
|
||||
parent: null
|
||||
position:
|
||||
x: 0
|
||||
y: 0
|
||||
z: 0
|
||||
sample_id: null
|
||||
type: container
|
||||
description: Opentrons 96 adapter Vb
|
||||
file_path: C:/Users/10230/PycharmProjects/Uni-Lab-OS/unilabos/registry/resources/opentrons/plate_adapters.yaml
|
||||
handles: []
|
||||
icon: ''
|
||||
init_param_schema: {}
|
||||
registry_type: resource
|
||||
version: 1.0.0
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,28 +1,35 @@
|
||||
container:
|
||||
description: regular organic container
|
||||
icon: Flask.webp
|
||||
class:
|
||||
category:
|
||||
- container
|
||||
class:
|
||||
module: unilabos.resources.container:RegularContainer
|
||||
type: unilabos
|
||||
config_info: []
|
||||
description: regular organic container
|
||||
file_path: C:/Users/10230/PycharmProjects/Uni-Lab-OS/unilabos/registry/resources/organic/container.yaml
|
||||
handles:
|
||||
- handler_key: top
|
||||
label: top
|
||||
io_type: target
|
||||
data_type: fluid
|
||||
side: NORTH
|
||||
data_source: handle
|
||||
data_key: fluid_in
|
||||
- handler_key: bottom
|
||||
label: bottom
|
||||
io_type: source
|
||||
data_type: fluid
|
||||
side: SOUTH
|
||||
data_source: handle
|
||||
data_key: fluid_out
|
||||
- handler_key: bind
|
||||
label: bind
|
||||
io_type: target
|
||||
data_type: mechanical
|
||||
side: SOUTH
|
||||
data_source: handle
|
||||
data_key: mechanical_port
|
||||
- data_key: fluid_in
|
||||
data_source: handle
|
||||
data_type: fluid
|
||||
handler_key: top
|
||||
io_type: target
|
||||
label: top
|
||||
side: NORTH
|
||||
- data_key: fluid_out
|
||||
data_source: handle
|
||||
data_type: fluid
|
||||
handler_key: bottom
|
||||
io_type: source
|
||||
label: bottom
|
||||
side: SOUTH
|
||||
- data_key: mechanical_port
|
||||
data_source: handle
|
||||
data_type: mechanical
|
||||
handler_key: bind
|
||||
io_type: target
|
||||
label: bind
|
||||
side: SOUTH
|
||||
icon: Flask.webp
|
||||
init_param_schema: {}
|
||||
registry_type: resource
|
||||
version: 1.0.0
|
||||
|
||||
@@ -248,7 +248,7 @@ def dict_to_nested_dict(nodes: dict, devices_only: bool = False) -> dict:
|
||||
root_nodes = {
|
||||
node["id"]: node
|
||||
for node in nodes_list
|
||||
if node.get("parent", node.get("parent_name")) in [None, "", "None", np.nan]
|
||||
if node.get("parent", node.get("parent_name")) in [None, "", "None", np.nan] or len(nodes_list) == 1
|
||||
}
|
||||
|
||||
# 如果存在多个根节点,返回所有根节点
|
||||
@@ -429,6 +429,20 @@ def resource_ulab_to_plr(resource: dict, plr_model=False) -> "ResourcePLR":
|
||||
|
||||
|
||||
def resource_plr_to_ulab(resource_plr: "ResourcePLR", parent_name: str = None):
|
||||
def replace_plr_type_to_ulab(source: str):
|
||||
replace_info = {
|
||||
"plate": "plate",
|
||||
"well": "well",
|
||||
"tip_spot": "container",
|
||||
"trash": "container",
|
||||
"deck": "deck",
|
||||
"tip_rack": "container",
|
||||
}
|
||||
if source in replace_info:
|
||||
return replace_info[source]
|
||||
else:
|
||||
print("转换pylabrobot的时候,出现未知类型", source)
|
||||
return "container"
|
||||
def resource_plr_to_ulab_inner(d: dict, all_states: dict) -> dict:
|
||||
r = {
|
||||
"id": d["name"],
|
||||
@@ -436,7 +450,7 @@ def resource_plr_to_ulab(resource_plr: "ResourcePLR", parent_name: str = None):
|
||||
"sample_id": None,
|
||||
"children": [resource_plr_to_ulab_inner(child, all_states) for child in d["children"]],
|
||||
"parent": d["parent_name"] if d["parent_name"] else parent_name if parent_name else None,
|
||||
"type": "device", # FIXME plr自带的type是python class name
|
||||
"type": replace_plr_type_to_ulab(d.get("category")), # FIXME plr自带的type是python class name
|
||||
"class": d.get("class", ""),
|
||||
"position": (
|
||||
{"x": d["location"]["x"], "y": d["location"]["y"], "z": d["location"]["z"]}
|
||||
@@ -447,7 +461,6 @@ def resource_plr_to_ulab(resource_plr: "ResourcePLR", parent_name: str = None):
|
||||
"data": all_states[d["name"]],
|
||||
}
|
||||
return r
|
||||
|
||||
d = resource_plr.serialize()
|
||||
all_states = resource_plr.serialize_all_state()
|
||||
r = resource_plr_to_ulab_inner(d, all_states)
|
||||
|
||||
@@ -55,7 +55,7 @@ def ros2_device_node(
|
||||
"read": "read_data",
|
||||
"extra_info": [],
|
||||
}
|
||||
|
||||
# FIXME 后面要删除
|
||||
for k, v in cls.__dict__.items():
|
||||
if not k.startswith("_") and isinstance(v, property):
|
||||
# noinspection PyUnresolvedReferences
|
||||
|
||||
@@ -132,7 +132,11 @@ _msg_converter: Dict[Type, Any] = {
|
||||
Bool: lambda x: Bool(data=bool(x)),
|
||||
str: str,
|
||||
String: lambda x: String(data=str(x)),
|
||||
Point: lambda x: Point(x=x.x, y=x.y, z=x.z) if not isinstance(x, dict) else Point(x=x.get("x", 0.0), y=x.get("y", 0.0), z=x.get("z", 0.0)),
|
||||
Point: lambda x: (
|
||||
Point(x=x.x, y=x.y, z=x.z)
|
||||
if not isinstance(x, dict)
|
||||
else Point(x=float(x.get("x", 0.0)), y=float(x.get("y", 0.0)), z=float(x.get("z", 0.0)))
|
||||
),
|
||||
Resource: lambda x: Resource(
|
||||
id=x.get("id", ""),
|
||||
name=x.get("name", ""),
|
||||
@@ -142,7 +146,13 @@ _msg_converter: Dict[Type, Any] = {
|
||||
type=x.get("type", ""),
|
||||
category=x.get("class", "") or x.get("type", ""),
|
||||
pose=(
|
||||
Pose(position=Point(x=float(x.get("position", {}).get("x", 0.0)), y=float(x.get("position", {}).get("y", 0.0)), z=float(x.get("position", {}).get("z", 0.0))))
|
||||
Pose(
|
||||
position=Point(
|
||||
x=float(x.get("position", {}).get("x", 0.0)),
|
||||
y=float(x.get("position", {}).get("y", 0.0)),
|
||||
z=float(x.get("position", {}).get("z", 0.0)),
|
||||
)
|
||||
)
|
||||
if x.get("position", None) is not None
|
||||
else Pose()
|
||||
),
|
||||
@@ -151,6 +161,7 @@ _msg_converter: Dict[Type, Any] = {
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def json_or_yaml_loads(data: str) -> Any:
|
||||
try:
|
||||
return json.loads(data)
|
||||
@@ -161,6 +172,7 @@ def json_or_yaml_loads(data: str) -> Any:
|
||||
pass
|
||||
raise e
|
||||
|
||||
|
||||
# ROS消息到Python转换器
|
||||
_msg_converter_back: Dict[Type, Any] = {
|
||||
float: float,
|
||||
@@ -343,7 +355,7 @@ def convert_to_ros_msg(ros_msg_type: Union[Type, Any], obj: Any) -> Any:
|
||||
if hasattr(ros_msg, key):
|
||||
attr = getattr(ros_msg, key)
|
||||
if isinstance(attr, (float, int, str, bool)):
|
||||
setattr(ros_msg, key, value)
|
||||
setattr(ros_msg, key, type(attr)(value))
|
||||
elif isinstance(attr, (list, tuple)) and isinstance(value, Iterable):
|
||||
td = ros_msg.SLOT_TYPES[ind].value_type
|
||||
if isinstance(td, NamespacedType):
|
||||
@@ -355,7 +367,7 @@ def convert_to_ros_msg(ros_msg_type: Union[Type, Any], obj: Any) -> Any:
|
||||
logger.warning(f"Not Supported type: {td}")
|
||||
setattr(ros_msg, key, []) # FIXME
|
||||
elif "array.array" in str(type(attr)):
|
||||
if attr.typecode == "f":
|
||||
if attr.typecode == "f" or attr.typecode == "d":
|
||||
setattr(ros_msg, key, [float(i) for i in value])
|
||||
else:
|
||||
setattr(ros_msg, key, value)
|
||||
@@ -496,47 +508,90 @@ def convert_from_ros_msg_with_mapping(ros_msg: Any, value_mapping: Dict[str, str
|
||||
Python字典
|
||||
"""
|
||||
data: Dict[str, Any] = {}
|
||||
|
||||
# # 🔧 添加调试信息
|
||||
# print(f"🔍 convert_from_ros_msg_with_mapping 开始")
|
||||
# print(f"🔍 ros_msg 类型: {type(ros_msg)}")
|
||||
# print(f"🔍 ros_msg 内容: {ros_msg}")
|
||||
# print(f"🔍 value_mapping: {value_mapping}")
|
||||
# print("-" * 60)
|
||||
|
||||
for msg_name, attr_name in value_mapping.items():
|
||||
# print(f"🔍 处理映射: {msg_name} -> {attr_name}")
|
||||
|
||||
msg_path = msg_name.split(".")
|
||||
current = ros_msg
|
||||
|
||||
|
||||
# print(f"🔍 msg_path: {msg_path}")
|
||||
# print(f"🔍 current 初始值: {current} (类型: {type(current)})")
|
||||
|
||||
try:
|
||||
if not attr_name.endswith("[]"):
|
||||
# 处理单值映射
|
||||
for name in msg_path:
|
||||
current = getattr(current, name)
|
||||
data[attr_name] = convert_from_ros_msg(current)
|
||||
# print(f"🔍 处理单值映射")
|
||||
for i, name in enumerate(msg_path):
|
||||
# print(f"🔍 步骤 {i}: 获取属性 '{name}' 从 {type(current)}")
|
||||
if hasattr(current, name):
|
||||
current = getattr(current, name)
|
||||
# print(f"🔍 获取到: {current} (类型: {type(current)})")
|
||||
else:
|
||||
# print(f"❌ 属性 '{name}' 不存在于 {type(current)}")
|
||||
break
|
||||
|
||||
converted_value = convert_from_ros_msg(current)
|
||||
# print(f"🔍 转换后的值: {converted_value} (类型: {type(converted_value)})")
|
||||
data[attr_name] = converted_value
|
||||
# print(f"✅ 设置 data['{attr_name}'] = {converted_value}")
|
||||
else:
|
||||
# 处理列表值映射
|
||||
for name in msg_path:
|
||||
# print(f"🔍 处理列表值映射")
|
||||
for i, name in enumerate(msg_path):
|
||||
# print(f"🔍 列表步骤 {i}: 处理 '{name}' 从 {type(current)}")
|
||||
if name.endswith("[]"):
|
||||
base_name = name[:-2]
|
||||
# print(f"🔍 数组字段 base_name: '{base_name}'")
|
||||
if hasattr(current, base_name):
|
||||
current = list(getattr(current, base_name))
|
||||
# print(f"🔍 获取数组: {current} (长度: {len(current)})")
|
||||
else:
|
||||
# print(f"❌ 数组字段 '{base_name}' 不存在")
|
||||
current = []
|
||||
break
|
||||
else:
|
||||
if isinstance(current, list):
|
||||
# print(f"🔍 从列表中获取属性 '{name}'")
|
||||
next_level = []
|
||||
for item in current:
|
||||
if hasattr(item, name):
|
||||
next_level.append(getattr(item, name))
|
||||
current = next_level
|
||||
# print(f"🔍 列表处理结果: {current} (长度: {len(current)})")
|
||||
elif hasattr(current, name):
|
||||
current = getattr(current, name)
|
||||
# print(f"🔍 获取到属性: {current} (类型: {type(current)})")
|
||||
else:
|
||||
# print(f"❌ 属性 '{name}' 不存在")
|
||||
current = []
|
||||
break
|
||||
|
||||
attr_key = attr_name[:-2]
|
||||
if current:
|
||||
data[attr_key] = [convert_from_ros_msg(item) for item in current]
|
||||
except (AttributeError, TypeError):
|
||||
converted_list = [convert_from_ros_msg(item) for item in current]
|
||||
data[attr_key] = converted_list
|
||||
# print(f"✅ 设置 data['{attr_key}'] = {converted_list}")
|
||||
else:
|
||||
print(f"⚠️ 列表为空,跳过 '{attr_key}'")
|
||||
except (AttributeError, TypeError) as e:
|
||||
# print(f"❌ 映射转换错误 {msg_name} -> {attr_name}: {e}")
|
||||
logger.debug(f"Mapping conversion error for {msg_name} -> {attr_name}")
|
||||
continue
|
||||
|
||||
# print(f"🔍 当前 data 状态: {data}")
|
||||
# print("-" * 40)
|
||||
|
||||
#print(f"🔍 convert_from_ros_msg_with_mapping 结束")
|
||||
#print(f"🔍 最终 data: {data}")
|
||||
#print("=" * 60)
|
||||
return data
|
||||
|
||||
|
||||
@@ -571,30 +626,30 @@ from unilabos.utils.import_manager import ImportManager
|
||||
from unilabos.config.config import ROSConfig
|
||||
|
||||
basic_type_map = {
|
||||
'bool': {'type': 'boolean'},
|
||||
'int8': {'type': 'integer', 'minimum': -128, 'maximum': 127},
|
||||
'uint8': {'type': 'integer', 'minimum': 0, 'maximum': 255},
|
||||
'int16': {'type': 'integer', 'minimum': -32768, 'maximum': 32767},
|
||||
'uint16': {'type': 'integer', 'minimum': 0, 'maximum': 65535},
|
||||
'int32': {'type': 'integer', 'minimum': -2147483648, 'maximum': 2147483647},
|
||||
'uint32': {'type': 'integer', 'minimum': 0, 'maximum': 4294967295},
|
||||
'int64': {'type': 'integer'},
|
||||
'uint64': {'type': 'integer', 'minimum': 0},
|
||||
'double': {'type': 'number'},
|
||||
'float': {'type': 'number'},
|
||||
'float32': {'type': 'number'},
|
||||
'float64': {'type': 'number'},
|
||||
'string': {'type': 'string'},
|
||||
'boolean': {'type': 'boolean'},
|
||||
'char': {'type': 'string', 'maxLength': 1},
|
||||
'byte': {'type': 'integer', 'minimum': 0, 'maximum': 255},
|
||||
"bool": {"type": "boolean"},
|
||||
"int8": {"type": "integer", "minimum": -128, "maximum": 127},
|
||||
"uint8": {"type": "integer", "minimum": 0, "maximum": 255},
|
||||
"int16": {"type": "integer", "minimum": -32768, "maximum": 32767},
|
||||
"uint16": {"type": "integer", "minimum": 0, "maximum": 65535},
|
||||
"int32": {"type": "integer", "minimum": -2147483648, "maximum": 2147483647},
|
||||
"uint32": {"type": "integer", "minimum": 0, "maximum": 4294967295},
|
||||
"int64": {"type": "integer"},
|
||||
"uint64": {"type": "integer", "minimum": 0},
|
||||
"double": {"type": "number"},
|
||||
"float": {"type": "number"},
|
||||
"float32": {"type": "number"},
|
||||
"float64": {"type": "number"},
|
||||
"string": {"type": "string"},
|
||||
"boolean": {"type": "boolean"},
|
||||
"char": {"type": "string", "maxLength": 1},
|
||||
"byte": {"type": "integer", "minimum": 0, "maximum": 255},
|
||||
}
|
||||
|
||||
|
||||
def ros_field_type_to_json_schema(type_info: Type | str, slot_type: str=None) -> Dict[str, Any]:
|
||||
def ros_field_type_to_json_schema(type_info: Type | str, slot_type: str = None) -> Dict[str, Any]:
|
||||
"""
|
||||
将 ROS 字段类型转换为 JSON Schema 类型定义
|
||||
|
||||
|
||||
Args:
|
||||
type_info: ROS 类型
|
||||
slot_type: ROS 类型
|
||||
@@ -603,10 +658,7 @@ def ros_field_type_to_json_schema(type_info: Type | str, slot_type: str=None) ->
|
||||
对应的 JSON Schema 类型定义
|
||||
"""
|
||||
if isinstance(type_info, UnboundedSequence):
|
||||
return {
|
||||
'type': 'array',
|
||||
'items': ros_field_type_to_json_schema(type_info.value_type)
|
||||
}
|
||||
return {"type": "array", "items": ros_field_type_to_json_schema(type_info.value_type)}
|
||||
if isinstance(type_info, NamespacedType):
|
||||
cls_name = ".".join(type_info.namespaces) + ":" + type_info.name
|
||||
type_class = msg_converter_manager.get_class(cls_name)
|
||||
@@ -614,20 +666,20 @@ def ros_field_type_to_json_schema(type_info: Type | str, slot_type: str=None) ->
|
||||
elif isinstance(type_info, BasicType):
|
||||
return ros_field_type_to_json_schema(type_info.typename)
|
||||
elif isinstance(type_info, UnboundedString):
|
||||
return basic_type_map['string']
|
||||
return basic_type_map["string"]
|
||||
elif isinstance(type_info, str):
|
||||
if type_info in basic_type_map:
|
||||
return basic_type_map[type_info]
|
||||
|
||||
# 处理时间和持续时间类型
|
||||
if type_info in ('time', 'duration', 'builtin_interfaces/Time', 'builtin_interfaces/Duration'):
|
||||
if type_info in ("time", "duration", "builtin_interfaces/Time", "builtin_interfaces/Duration"):
|
||||
return {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'sec': {'type': 'integer', 'description': '秒'},
|
||||
'nanosec': {'type': 'integer', 'description': '纳秒'}
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"sec": {"type": "integer", "description": "秒"},
|
||||
"nanosec": {"type": "integer", "description": "纳秒"},
|
||||
},
|
||||
'required': ['sec', 'nanosec']
|
||||
"required": ["sec", "nanosec"],
|
||||
}
|
||||
else:
|
||||
return ros_message_to_json_schema(type_info)
|
||||
@@ -638,9 +690,7 @@ def ros_field_type_to_json_schema(type_info: Type | str, slot_type: str=None) ->
|
||||
# 'type': 'array',
|
||||
# 'items': ros_field_type_to_json_schema(item_type)
|
||||
# }
|
||||
|
||||
|
||||
|
||||
# # 处理复杂类型(尝试加载并处理)
|
||||
# try:
|
||||
# # 如果它是一个完整的消息类型规范 (包名/msg/类型名)
|
||||
@@ -655,34 +705,31 @@ def ros_field_type_to_json_schema(type_info: Type | str, slot_type: str=None) ->
|
||||
# logger.debug(f"无法解析类型 {field_type}: {str(e)}")
|
||||
# return {'type': 'object', 'description': f'未知类型: {field_type}'}
|
||||
|
||||
|
||||
def ros_message_to_json_schema(msg_class: Any) -> Dict[str, Any]:
|
||||
"""
|
||||
将 ROS 消息类转换为 JSON Schema
|
||||
|
||||
|
||||
Args:
|
||||
msg_class: ROS 消息类
|
||||
|
||||
|
||||
Returns:
|
||||
对应的 JSON Schema 定义
|
||||
"""
|
||||
schema = {
|
||||
'type': 'object',
|
||||
'properties': {},
|
||||
'required': []
|
||||
}
|
||||
|
||||
schema = {"type": "object", "properties": {}, "required": []}
|
||||
|
||||
# 获取类名作为标题
|
||||
if hasattr(msg_class, '__name__'):
|
||||
schema['title'] = msg_class.__name__
|
||||
|
||||
if hasattr(msg_class, "__name__"):
|
||||
schema["title"] = msg_class.__name__
|
||||
|
||||
# 获取消息的字段和字段类型
|
||||
try:
|
||||
for ind, slot_info in enumerate(msg_class._fields_and_field_types.items()):
|
||||
slot_name, slot_type = slot_info
|
||||
type_info = msg_class.SLOT_TYPES[ind]
|
||||
field_schema = ros_field_type_to_json_schema(type_info, slot_type)
|
||||
schema['properties'][slot_name] = field_schema
|
||||
schema['required'].append(slot_name)
|
||||
schema["properties"][slot_name] = field_schema
|
||||
schema["required"].append(slot_name)
|
||||
# if hasattr(msg_class, 'get_fields_and_field_types'):
|
||||
# fields_and_types = msg_class.get_fields_and_field_types()
|
||||
#
|
||||
@@ -707,62 +754,66 @@ def ros_message_to_json_schema(msg_class: Any) -> Dict[str, Any]:
|
||||
# schema['required'].append(clean_name)
|
||||
except Exception as e:
|
||||
# 如果获取字段类型失败,添加错误信息
|
||||
schema['description'] = f"解析消息字段时出错: {str(e)}"
|
||||
schema["description"] = f"解析消息字段时出错: {str(e)}"
|
||||
logger.error(f"解析 {msg_class.__name__} 消息字段失败: {str(e)}")
|
||||
|
||||
|
||||
return schema
|
||||
|
||||
def ros_action_to_json_schema(action_class: Any) -> Dict[str, Any]:
|
||||
|
||||
def ros_action_to_json_schema(action_class: Any, description="") -> Dict[str, Any]:
|
||||
"""
|
||||
将 ROS Action 类转换为 JSON Schema
|
||||
|
||||
|
||||
Args:
|
||||
action_class: ROS Action 类
|
||||
|
||||
description: 描述
|
||||
|
||||
Returns:
|
||||
完整的 JSON Schema 定义
|
||||
"""
|
||||
if not hasattr(action_class, 'Goal') or not hasattr(action_class, 'Feedback') or not hasattr(action_class, 'Result'):
|
||||
if (
|
||||
not hasattr(action_class, "Goal")
|
||||
or not hasattr(action_class, "Feedback")
|
||||
or not hasattr(action_class, "Result")
|
||||
):
|
||||
raise ValueError(f"{action_class.__name__} 不是有效的 ROS Action 类")
|
||||
|
||||
|
||||
# 创建基础 schema
|
||||
schema = {
|
||||
'$schema': 'http://json-schema.org/draft-07/schema#',
|
||||
'title': action_class.__name__,
|
||||
'description': f"ROS Action {action_class.__name__} 的 JSON Schema",
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'goal': {
|
||||
'description': 'Action 目标 - 从客户端发送到服务器',
|
||||
"title": action_class.__name__,
|
||||
"description": description,
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"goal": {
|
||||
# 'description': 'Action 目标 - 从客户端发送到服务器',
|
||||
**ros_message_to_json_schema(action_class.Goal)
|
||||
},
|
||||
'feedback': {
|
||||
'description': 'Action 反馈 - 执行过程中从服务器发送到客户端',
|
||||
"feedback": {
|
||||
# 'description': 'Action 反馈 - 执行过程中从服务器发送到客户端',
|
||||
**ros_message_to_json_schema(action_class.Feedback)
|
||||
},
|
||||
'result': {
|
||||
'description': 'Action 结果 - 完成后从服务器发送到客户端',
|
||||
"result": {
|
||||
# 'description': 'Action 结果 - 完成后从服务器发送到客户端',
|
||||
**ros_message_to_json_schema(action_class.Result)
|
||||
}
|
||||
},
|
||||
},
|
||||
'required': ['goal']
|
||||
"required": ["goal"],
|
||||
}
|
||||
|
||||
|
||||
return schema
|
||||
|
||||
|
||||
def convert_ros_action_to_jsonschema(
|
||||
action_name_or_type: Union[str, Type],
|
||||
output_file: Optional[str] = None,
|
||||
format: str = 'json'
|
||||
action_name_or_type: Union[str, Type], output_file: Optional[str] = None, format: str = "json"
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
将 ROS Action 类型转换为 JSON Schema,并可选地保存到文件
|
||||
|
||||
|
||||
Args:
|
||||
action_name_or_type: ROS Action 类型名称或类
|
||||
output_file: 可选,输出 JSON Schema 的文件路径
|
||||
format: 输出格式,'json' 或 'yaml'
|
||||
|
||||
|
||||
Returns:
|
||||
JSON Schema 定义(字典)
|
||||
"""
|
||||
@@ -772,21 +823,21 @@ def convert_ros_action_to_jsonschema(
|
||||
action_type = get_ros_type_by_msgname(action_name_or_type)
|
||||
else:
|
||||
action_type = action_name_or_type
|
||||
|
||||
|
||||
# 生成 JSON Schema
|
||||
schema = ros_action_to_json_schema(action_type)
|
||||
|
||||
|
||||
# 如果指定了输出文件,将 Schema 保存到文件
|
||||
if output_file:
|
||||
if format.lower() == 'json':
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
if format.lower() == "json":
|
||||
with open(output_file, "w", encoding="utf-8") as f:
|
||||
json.dump(schema, f, indent=2, ensure_ascii=False)
|
||||
elif format.lower() == 'yaml':
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
elif format.lower() == "yaml":
|
||||
with open(output_file, "w", encoding="utf-8") as f:
|
||||
yaml.safe_dump(schema, f, default_flow_style=False, allow_unicode=True)
|
||||
else:
|
||||
raise ValueError(f"不支持的格式: {format},请使用 'json' 或 'yaml'")
|
||||
|
||||
|
||||
return schema
|
||||
|
||||
|
||||
@@ -795,14 +846,14 @@ if __name__ == "__main__":
|
||||
# 示例:转换 NavigateToPose action
|
||||
try:
|
||||
from nav2_msgs.action import NavigateToPose
|
||||
|
||||
|
||||
# 转换为 JSON Schema 并打印
|
||||
schema = convert_ros_action_to_jsonschema(NavigateToPose)
|
||||
print(json.dumps(schema, indent=2, ensure_ascii=False))
|
||||
|
||||
|
||||
# 保存到文件
|
||||
# convert_ros_action_to_jsonschema(NavigateToPose, "navigate_to_pose_schema.json")
|
||||
|
||||
|
||||
# 或者使用字符串形式的 action 名称
|
||||
# schema = convert_ros_action_to_jsonschema("nav2_msgs/action/NavigateToPose")
|
||||
except ImportError:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import copy
|
||||
import io
|
||||
import json
|
||||
import threading
|
||||
import time
|
||||
@@ -10,6 +11,7 @@ from concurrent.futures import ThreadPoolExecutor
|
||||
import asyncio
|
||||
|
||||
import rclpy
|
||||
import yaml
|
||||
from rclpy.node import Node
|
||||
from rclpy.action import ActionServer, ActionClient
|
||||
from rclpy.action.server import ServerGoalHandle
|
||||
@@ -166,7 +168,10 @@ class PropertyPublisher:
|
||||
self.print_publish = print_publish
|
||||
|
||||
self._value = None
|
||||
self.publisher_ = node.create_publisher(msg_type, f"{name}", 10)
|
||||
try:
|
||||
self.publisher_ = node.create_publisher(msg_type, f"{name}", 10)
|
||||
except AttributeError as ex:
|
||||
logger.error(f"创建发布者失败,可能由于注册表有误,类型: {msg_type},错误: {ex}\n{traceback.format_exc()}")
|
||||
self.timer = node.create_timer(self.timer_period, self.publish_property)
|
||||
self.__loop = get_event_loop()
|
||||
str_msg_type = str(msg_type)[8:-2]
|
||||
@@ -302,6 +307,8 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
# 创建动作服务
|
||||
if self.create_action_server:
|
||||
for action_name, action_value_mapping in self._action_value_mappings.items():
|
||||
if action_name.startswith("auto-") or str(action_value_mapping.get("type", "")).startswith("UniLabJsonCommand"):
|
||||
continue
|
||||
self.create_ros_action_server(action_name, action_value_mapping)
|
||||
|
||||
# 创建线程池执行器
|
||||
@@ -622,7 +629,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
execution_success = False
|
||||
action_return_value = None
|
||||
|
||||
self.lab_logger().info(f"执行动作: {action_name}")
|
||||
##### self.lab_logger().info(f"执行动作: {action_name}")
|
||||
goal = goal_handle.request
|
||||
|
||||
# 从目标消息中提取参数, 并调用对应的方法
|
||||
@@ -649,15 +656,18 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
if v in ["unilabos_msgs/Resource", "sequence<unilabos_msgs/Resource>"]:
|
||||
self.lab_logger().info(f"查询资源状态: Key: {k} Type: {v}")
|
||||
current_resources = []
|
||||
# TODO: resource后面需要分组
|
||||
only_one_resource = False
|
||||
try:
|
||||
if len(action_kwargs[k]) > 1:
|
||||
for i in action_kwargs[k]:
|
||||
r = ResourceGet.Request()
|
||||
r.id = i["id"]
|
||||
r.id = i["id"] # splash optional
|
||||
r.with_children = True
|
||||
response = await self._resource_clients["resource_get"].call_async(r)
|
||||
current_resources.extend(response.resources)
|
||||
else:
|
||||
only_one_resource = True
|
||||
r = ResourceGet.Request()
|
||||
r.id = (
|
||||
action_kwargs[k]["id"]
|
||||
@@ -675,17 +685,20 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
type_hint = action_paramtypes[k]
|
||||
final_type = get_type_class(type_hint)
|
||||
# 判断 ACTION 是否需要特殊的物料类型如 pylabrobot.resources.Resource,并做转换
|
||||
final_resource = [convert_resources_to_type([i], final_type)[0] for i in resources_list]
|
||||
if only_one_resource:
|
||||
final_resource = convert_resources_to_type(resources_list, final_type)
|
||||
else:
|
||||
final_resource = [convert_resources_to_type([i], final_type)[0] for i in resources_list]
|
||||
action_kwargs[k] = self.resource_tracker.figure_resource(final_resource)
|
||||
|
||||
self.lab_logger().info(f"准备执行: {action_kwargs}, 函数: {ACTION.__name__}")
|
||||
##### self.lab_logger().info(f"准备执行: {action_kwargs}, 函数: {ACTION.__name__}")
|
||||
time_start = time.time()
|
||||
time_overall = 100
|
||||
|
||||
# 将阻塞操作放入线程池执行
|
||||
if asyncio.iscoroutinefunction(ACTION):
|
||||
try:
|
||||
self.lab_logger().info(f"异步执行动作 {ACTION}")
|
||||
##### self.lab_logger().info(f"异步执行动作 {ACTION}")
|
||||
future = ROS2DeviceNode.run_async_func(ACTION, trace_error=False, **action_kwargs)
|
||||
|
||||
def _handle_future_exception(fut):
|
||||
@@ -695,7 +708,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
execution_success = True
|
||||
except Exception as e:
|
||||
execution_error = traceback.format_exc()
|
||||
error(f"异步任务 {ACTION.__name__} 报错了")
|
||||
##### error(f"异步任务 {ACTION.__name__} 报错了")
|
||||
error(traceback.format_exc())
|
||||
|
||||
future.add_done_callback(_handle_future_exception)
|
||||
@@ -703,7 +716,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
self.lab_logger().error(f"创建异步任务失败: {traceback.format_exc()}")
|
||||
raise e
|
||||
else:
|
||||
self.lab_logger().info(f"同步执行动作 {ACTION}")
|
||||
##### self.lab_logger().info(f"同步执行动作 {ACTION}")
|
||||
future = self._executor.submit(ACTION, **action_kwargs)
|
||||
|
||||
def _handle_future_exception(fut):
|
||||
@@ -758,7 +771,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
self.lab_logger().info(f"动作 {action_name} 已取消")
|
||||
return action_type.Result()
|
||||
|
||||
self.lab_logger().info(f"动作执行完成: {action_name}")
|
||||
##### self.lab_logger().info(f"动作执行完成: {action_name}")
|
||||
del future
|
||||
|
||||
# 向Host更新物料当前状态
|
||||
@@ -794,7 +807,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
|
||||
# 发布结果
|
||||
goal_handle.succeed()
|
||||
self.lab_logger().info(f"设置动作成功: {action_name}")
|
||||
##### self.lab_logger().info(f"设置动作成功: {action_name}")
|
||||
|
||||
result_values = {}
|
||||
for msg_name, attr_name in action_value_mapping["result"].items():
|
||||
@@ -813,7 +826,7 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
elif attr_name == "return_info":
|
||||
setattr(result_msg, attr_name, serialize_result_info(execution_error, execution_success, action_return_value))
|
||||
|
||||
self.lab_logger().info(f"动作 {action_name} 完成并返回结果")
|
||||
##### self.lab_logger().info(f"动作 {action_name} 完成并返回结果")
|
||||
return result_msg
|
||||
|
||||
return execute_callback
|
||||
@@ -838,6 +851,8 @@ class BaseROS2DeviceNode(Node, Generic[T]):
|
||||
class DeviceInitError(Exception):
|
||||
pass
|
||||
|
||||
class JsonCommandInitError(Exception):
|
||||
pass
|
||||
|
||||
class ROS2DeviceNode:
|
||||
"""
|
||||
@@ -914,11 +929,18 @@ class ROS2DeviceNode:
|
||||
driver_class.__module__.startswith("pylabrobot")
|
||||
or driver_class.__name__ == "LiquidHandlerAbstract"
|
||||
or driver_class.__name__ == "LiquidHandlerBiomek"
|
||||
or driver_class.__name__ == "PRCXI9300Handler"
|
||||
)
|
||||
|
||||
# TODO: 要在创建之前预先请求服务器是否有当前id的物料,放到resource_tracker中,让pylabrobot进行创建
|
||||
# 创建设备类实例
|
||||
if use_pylabrobot_creator:
|
||||
# 先对pylabrobot的子资源进行加载,不然subclass无法认出
|
||||
# 在下方对于加载Deck等Resource要手动import
|
||||
# noinspection PyUnresolvedReferences
|
||||
from unilabos.devices.liquid_handling.prcxi.prcxi import PRCXI9300Deck
|
||||
# noinspection PyUnresolvedReferences
|
||||
from unilabos.devices.liquid_handling.prcxi.prcxi import PRCXI9300Container
|
||||
self._driver_creator = PyLabRobotCreator(
|
||||
driver_class, children=children, resource_tracker=self.resource_tracker
|
||||
)
|
||||
@@ -954,12 +976,51 @@ class ROS2DeviceNode:
|
||||
self._ros_node: BaseROS2DeviceNode
|
||||
self._ros_node.lab_logger().info(f"初始化完成 {self._ros_node.uuid} {self.driver_is_ros}")
|
||||
self.driver_instance._ros_node = self._ros_node # type: ignore
|
||||
self.driver_instance._execute_driver_command = self._execute_driver_command # type: ignore
|
||||
self.driver_instance._execute_driver_command_async = self._execute_driver_command_async # type: ignore
|
||||
if hasattr(self.driver_instance, "post_init"):
|
||||
try:
|
||||
self.driver_instance.post_init(self._ros_node) # type: ignore
|
||||
except Exception as e:
|
||||
self._ros_node.lab_logger().error(f"设备后初始化失败: {e}")
|
||||
|
||||
def _execute_driver_command(self, string: str):
|
||||
try:
|
||||
target = json.loads(string)
|
||||
except Exception as ex:
|
||||
try:
|
||||
target = yaml.safe_load(io.StringIO(string))
|
||||
except Exception as ex2:
|
||||
raise JsonCommandInitError(f"执行动作时JSON/YAML解析失败: \n{ex}\n{ex2}\n原内容: {string}\n{traceback.format_exc()}")
|
||||
try:
|
||||
function_name = target["function_name"]
|
||||
function_args = target["function_args"]
|
||||
assert isinstance(function_args, dict), "执行动作时JSON必须为dict类型\n原JSON: {string}"
|
||||
function = getattr(self.driver_instance, function_name)
|
||||
assert callable(function), f"执行动作时JSON中的function_name对应的函数不可调用: {function_name}\n原JSON: {string}"
|
||||
return function(**function_args)
|
||||
except KeyError as ex:
|
||||
raise JsonCommandInitError(f"执行动作时JSON缺少function_name或function_args: {ex}\n原JSON: {string}\n{traceback.format_exc()}")
|
||||
|
||||
async def _execute_driver_command_async(self, string: str):
|
||||
try:
|
||||
target = json.loads(string)
|
||||
except Exception as ex:
|
||||
try:
|
||||
target = yaml.safe_load(io.StringIO(string))
|
||||
except Exception as ex2:
|
||||
raise JsonCommandInitError(f"执行动作时JSON/YAML解析失败: \n{ex}\n{ex2}\n原内容: {string}\n{traceback.format_exc()}")
|
||||
try:
|
||||
function_name = target["function_name"]
|
||||
function_args = target["function_args"]
|
||||
assert isinstance(function_args, dict), "执行动作时JSON必须为dict类型\n原JSON: {string}"
|
||||
function = getattr(self.driver_instance, function_name)
|
||||
assert callable(function), f"执行动作时JSON中的function_name对应的函数不可调用: {function_name}\n原JSON: {string}"
|
||||
assert asyncio.iscoroutinefunction(function), f"执行动作时JSON中的function并非异步: {function_name}\n原JSON: {string}"
|
||||
return await function(**function_args)
|
||||
except KeyError as ex:
|
||||
raise JsonCommandInitError(f"执行动作时JSON缺少function_name或function_args: {ex}\n原JSON: {string}\n{traceback.format_exc()}")
|
||||
|
||||
def _start_loop(self):
|
||||
def run_event_loop():
|
||||
loop = asyncio.new_event_loop()
|
||||
|
||||
61
unilabos/ros/nodes/presets/camera.py
Normal file
61
unilabos/ros/nodes/presets/camera.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import rclpy
|
||||
from rclpy.node import Node
|
||||
import cv2
|
||||
from sensor_msgs.msg import Image
|
||||
from cv_bridge import CvBridge
|
||||
from unilabos.ros.nodes.base_device_node import BaseROS2DeviceNode, DeviceNodeResourceTracker
|
||||
|
||||
class VideoPublisher(BaseROS2DeviceNode):
|
||||
def __init__(self, device_id='video_publisher', camera_index=0, period: float = 0.1, resource_tracker: DeviceNodeResourceTracker = None):
|
||||
# 初始化BaseROS2DeviceNode,使用自身作为driver_instance
|
||||
BaseROS2DeviceNode.__init__(
|
||||
self,
|
||||
driver_instance=self,
|
||||
device_id=device_id,
|
||||
status_types={},
|
||||
action_value_mappings={},
|
||||
hardware_interface="camera",
|
||||
print_publish=False,
|
||||
resource_tracker=resource_tracker,
|
||||
)
|
||||
# 创建一个发布者,发布到 /video 话题,消息类型为 sensor_msgs/Image,队列长度设为 10
|
||||
self.publisher_ = self.create_publisher(Image, f'/{device_id}/video', 10)
|
||||
# 初始化摄像头(默认设备索引为 0)
|
||||
self.cap = cv2.VideoCapture(camera_index)
|
||||
if not self.cap.isOpened():
|
||||
self.get_logger().error("无法打开摄像头")
|
||||
# 用于将 OpenCV 的图像转换为 ROS 图像消息
|
||||
self.bridge = CvBridge()
|
||||
# 设置定时器,10 Hz 发布一次
|
||||
timer_period = period # 单位:秒
|
||||
self.timer = self.create_timer(timer_period, self.timer_callback)
|
||||
|
||||
def timer_callback(self):
|
||||
ret, frame = self.cap.read()
|
||||
if not ret:
|
||||
self.get_logger().error("读取视频帧失败")
|
||||
return
|
||||
# 将 OpenCV 图像转换为 ROS Image 消息,注意图像编码需与摄像头数据匹配,这里使用 bgr8
|
||||
img_msg = self.bridge.cv2_to_imgmsg(frame, encoding="bgr8")
|
||||
self.publisher_.publish(img_msg)
|
||||
# self.get_logger().info("已发布视频帧")
|
||||
|
||||
def destroy_node(self):
|
||||
# 释放摄像头资源
|
||||
if self.cap.isOpened():
|
||||
self.cap.release()
|
||||
super().destroy_node()
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
node = VideoPublisher()
|
||||
try:
|
||||
rclpy.spin(node)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
node.destroy_node()
|
||||
rclpy.shutdown()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -459,6 +459,8 @@ class HostNode(BaseROS2DeviceNode):
|
||||
self.devices_instances[device_id] = d
|
||||
# noinspection PyProtectedMember
|
||||
for action_name, action_value_mapping in d._ros_node._action_value_mappings.items():
|
||||
if action_name.startswith("auto-") or str(action_value_mapping.get("type", "")).startswith("UniLabJsonCommand"):
|
||||
continue
|
||||
action_id = f"/devices/{device_id}/{action_name}"
|
||||
if action_id not in self._action_clients:
|
||||
action_type = action_value_mapping["type"]
|
||||
@@ -561,12 +563,13 @@ class HostNode(BaseROS2DeviceNode):
|
||||
if hasattr(bridge, "publish_device_status"):
|
||||
bridge.publish_device_status(self.device_status, device_id, property_name)
|
||||
self.lab_logger().debug(
|
||||
f"[Host Node] Status updated: {device_id}.{property_name} = {msg.data}"
|
||||
f"[Host Node] Status updated: {device_id}.{property_name} = {msg.data}"
|
||||
)
|
||||
|
||||
def send_goal(
|
||||
self,
|
||||
device_id: str,
|
||||
action_type: str,
|
||||
action_name: str,
|
||||
action_kwargs: Dict[str, Any],
|
||||
goal_uuid: Optional[str] = None,
|
||||
@@ -577,16 +580,30 @@ class HostNode(BaseROS2DeviceNode):
|
||||
|
||||
Args:
|
||||
device_id: 设备ID
|
||||
action_type: 动作类型
|
||||
action_name: 动作名称
|
||||
action_kwargs: 动作参数
|
||||
goal_uuid: 目标UUID,如果为None则自动生成
|
||||
server_info: 服务器发送信息,包含发送时间戳等
|
||||
"""
|
||||
action_id = f"/devices/{device_id}/{action_name}"
|
||||
if action_type.startswith("UniLabJsonCommand"):
|
||||
if action_name.startswith("auto-"):
|
||||
action_name = action_name[5:]
|
||||
action_id = f"/devices/{device_id}/_execute_driver_command"
|
||||
action_kwargs = {
|
||||
"string": json.dumps({
|
||||
"function_name": action_name,
|
||||
"function_args": action_kwargs,
|
||||
})
|
||||
}
|
||||
if action_type.startswith("UniLabJsonCommandAsync"):
|
||||
action_id = f"/devices/{device_id}/_execute_driver_command_async"
|
||||
else:
|
||||
action_id = f"/devices/{device_id}/{action_name}"
|
||||
if action_name == "test_latency" and server_info is not None:
|
||||
self.server_latest_timestamp = server_info.get("send_timestamp", 0.0)
|
||||
if action_id not in self._action_clients:
|
||||
self.lab_logger().error(f"[Host Node] ActionClient {action_id} not found.")
|
||||
return
|
||||
raise ValueError(f"ActionClient {action_id} not found.")
|
||||
|
||||
action_client: ActionClient = self._action_clients[action_id]
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import time
|
||||
import asyncio
|
||||
import traceback
|
||||
from types import MethodType
|
||||
from typing import Union
|
||||
|
||||
import rclpy
|
||||
@@ -19,9 +17,11 @@ from unilabos.ros.msgs.message_converter import (
|
||||
get_action_type,
|
||||
convert_to_ros_msg,
|
||||
convert_from_ros_msg,
|
||||
convert_from_ros_msg_with_mapping,
|
||||
convert_from_ros_msg_with_mapping, String,
|
||||
)
|
||||
from unilabos.ros.nodes.base_device_node import BaseROS2DeviceNode, DeviceNodeResourceTracker, ROS2DeviceNode
|
||||
from unilabos.utils.log import error
|
||||
from unilabos.utils.type_check import serialize_result_info
|
||||
|
||||
|
||||
class ROS2ProtocolNode(BaseROS2DeviceNode):
|
||||
@@ -33,7 +33,15 @@ class ROS2ProtocolNode(BaseROS2DeviceNode):
|
||||
|
||||
# create_action_server = False # Action Server要自己创建
|
||||
|
||||
def __init__(self, device_id: str, children: dict, protocol_type: Union[str, list[str]], resource_tracker: DeviceNodeResourceTracker, *args, **kwargs):
|
||||
def __init__(
|
||||
self,
|
||||
device_id: str,
|
||||
children: dict,
|
||||
protocol_type: Union[str, list[str]],
|
||||
resource_tracker: DeviceNodeResourceTracker,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
self._setup_protocol_names(protocol_type)
|
||||
|
||||
# 初始化其它属性
|
||||
@@ -60,12 +68,14 @@ class ROS2ProtocolNode(BaseROS2DeviceNode):
|
||||
|
||||
for device_id, device_config in self.children.items():
|
||||
if device_config.get("type", "device") != "device":
|
||||
self.lab_logger().debug(f"[Protocol Node] Skipping type {device_config['type']} {device_id} already existed, skipping.")
|
||||
self.lab_logger().debug(
|
||||
f"[Protocol Node] Skipping type {device_config['type']} {device_id} already existed, skipping."
|
||||
)
|
||||
continue
|
||||
try:
|
||||
d = self.initialize_device(device_id, device_config)
|
||||
except Exception as ex:
|
||||
self.lab_logger().error(f"[Protocol Node] Failed to initialize device {device_id}: {ex}")
|
||||
self.lab_logger().error(f"[Protocol Node] Failed to initialize device {device_id}: {ex}\n{traceback.format_exc()}")
|
||||
d = None
|
||||
if d is None:
|
||||
continue
|
||||
@@ -76,22 +86,27 @@ class ROS2ProtocolNode(BaseROS2DeviceNode):
|
||||
|
||||
# 设置硬件接口代理
|
||||
if d:
|
||||
hardware_interface = d.ros_node_instance._hardware_interface
|
||||
if (
|
||||
hasattr(d.driver_instance, d.ros_node_instance._hardware_interface["name"])
|
||||
and hasattr(d.driver_instance, d.ros_node_instance._hardware_interface["write"])
|
||||
and (d.ros_node_instance._hardware_interface["read"] is None or hasattr(d.driver_instance, d.ros_node_instance._hardware_interface["read"]))
|
||||
hasattr(d.driver_instance, hardware_interface["name"])
|
||||
and hasattr(d.driver_instance, hardware_interface["write"])
|
||||
and (hardware_interface["read"] is None or hasattr(d.driver_instance, hardware_interface["read"]))
|
||||
):
|
||||
|
||||
name = getattr(d.driver_instance, d.ros_node_instance._hardware_interface["name"])
|
||||
read = d.ros_node_instance._hardware_interface.get("read", None)
|
||||
write = d.ros_node_instance._hardware_interface.get("write", None)
|
||||
name = getattr(d.driver_instance, hardware_interface["name"])
|
||||
read = hardware_interface.get("read", None)
|
||||
write = hardware_interface.get("write", None)
|
||||
|
||||
# 如果硬件接口是字符串,通过通信设备提供
|
||||
if isinstance(name, str) and name in self.sub_devices:
|
||||
communicate_device = self.sub_devices[name]
|
||||
communicate_hardware_info = communicate_device.ros_node_instance._hardware_interface
|
||||
self._setup_hardware_proxy(d, self.sub_devices[name], read, write)
|
||||
self.lab_logger().info(f"\n通信代理:为子设备{device_id}\n 添加了{read}方法(来源:{name} {communicate_hardware_info['write']}) \n 添加了{write}方法(来源:{name} {communicate_hardware_info['read']})")
|
||||
self.lab_logger().info(
|
||||
f"\n通信代理:为子设备{device_id}\n "
|
||||
f"添加了{read}方法(来源:{name} {communicate_hardware_info['write']}) \n "
|
||||
f"添加了{write}方法(来源:{name} {communicate_hardware_info['read']})"
|
||||
)
|
||||
|
||||
def _setup_protocol_names(self, protocol_type):
|
||||
# 处理协议类型
|
||||
@@ -119,11 +134,17 @@ class ROS2ProtocolNode(BaseROS2DeviceNode):
|
||||
if d is not None and hasattr(d, "ros_node_instance"):
|
||||
node = d.ros_node_instance
|
||||
for action_name, action_mapping in node._action_value_mappings.items():
|
||||
if action_name.startswith("auto-") or str(action_mapping.get("type", "")).startswith("UniLabJsonCommand"):
|
||||
continue
|
||||
action_id = f"/devices/{device_id_abs}/{action_name}"
|
||||
if action_id not in self._action_clients:
|
||||
self._action_clients[action_id] = ActionClient(
|
||||
self, action_mapping["type"], action_id, callback_group=self.callback_group
|
||||
)
|
||||
try:
|
||||
self._action_clients[action_id] = ActionClient(
|
||||
self, action_mapping["type"], action_id, callback_group=self.callback_group
|
||||
)
|
||||
except Exception as ex:
|
||||
self.lab_logger().error(f"创建动作客户端失败: {action_id}, 错误: {ex}")
|
||||
continue
|
||||
self.lab_logger().debug(f"为子设备 {device_id} 创建动作客户端: {action_name}")
|
||||
return d
|
||||
|
||||
@@ -149,63 +170,135 @@ class ROS2ProtocolNode(BaseROS2DeviceNode):
|
||||
def _create_protocol_execute_callback(self, protocol_name, protocol_steps_generator):
|
||||
async def execute_protocol(goal_handle: ServerGoalHandle):
|
||||
"""执行完整的工作流"""
|
||||
self.get_logger().info(f'Executing {protocol_name} action...')
|
||||
# 初始化结果信息变量
|
||||
execution_error = ""
|
||||
execution_success = False
|
||||
protocol_return_value = None
|
||||
self.get_logger().info(f"Executing {protocol_name} action...")
|
||||
action_value_mapping = self._action_value_mappings[protocol_name]
|
||||
print('+'*30)
|
||||
print(protocol_steps_generator)
|
||||
# 从目标消息中提取参数, 并调用Protocol生成器(根据设备连接图)生成action步骤
|
||||
goal = goal_handle.request
|
||||
protocol_kwargs = convert_from_ros_msg_with_mapping(goal, action_value_mapping["goal"])
|
||||
try:
|
||||
print("+" * 30)
|
||||
print(protocol_steps_generator)
|
||||
# 从目标消息中提取参数, 并调用Protocol生成器(根据设备连接图)生成action步骤
|
||||
goal = goal_handle.request
|
||||
protocol_kwargs = convert_from_ros_msg_with_mapping(goal, action_value_mapping["goal"])
|
||||
|
||||
# # 🔧 添加调试信息
|
||||
# print(f"🔍 转换后的 protocol_kwargs: {protocol_kwargs}")
|
||||
# print(f"🔍 vessel 在转换后: {protocol_kwargs.get('vessel', 'NOT_FOUND')}")
|
||||
|
||||
# 向Host查询物料当前状态
|
||||
for k, v in goal.get_fields_and_field_types().items():
|
||||
if v in ["unilabos_msgs/Resource", "sequence<unilabos_msgs/Resource>"]:
|
||||
r = ResourceGet.Request()
|
||||
r.id = protocol_kwargs[k]["id"] if v == "unilabos_msgs/Resource" else protocol_kwargs[k][0]["id"]
|
||||
r.with_children = True
|
||||
response = await self._resource_clients["resource_get"].call_async(r)
|
||||
protocol_kwargs[k] = list_to_nested_dict([convert_from_ros_msg(rs) for rs in response.resources])
|
||||
# # 🔧 完全禁用Host查询,直接使用转换后的数据
|
||||
# print(f"🔧 跳过Host查询,直接使用转换后的数据")
|
||||
# 向Host查询物料当前状态
|
||||
for k, v in goal.get_fields_and_field_types().items():
|
||||
if v in ["unilabos_msgs/Resource", "sequence<unilabos_msgs/Resource>"]:
|
||||
r = ResourceGet.Request()
|
||||
resource_id = (
|
||||
protocol_kwargs[k]["id"] if v == "unilabos_msgs/Resource" else protocol_kwargs[k][0]["id"]
|
||||
)
|
||||
r.id = resource_id
|
||||
r.with_children = True
|
||||
response = await self._resource_clients["resource_get"].call_async(r)
|
||||
protocol_kwargs[k] = list_to_nested_dict(
|
||||
[convert_from_ros_msg(rs) for rs in response.resources]
|
||||
)
|
||||
|
||||
from unilabos.resources.graphio import physical_setup_graph
|
||||
self.get_logger().info(f'Working on physical setup: {physical_setup_graph}')
|
||||
protocol_steps = protocol_steps_generator(G=physical_setup_graph, **protocol_kwargs)
|
||||
self.lab_logger().info(f"🔍 最终传递给协议的 protocol_kwargs: {protocol_kwargs}")
|
||||
self.lab_logger().info(f"🔍 最终的 vessel: {protocol_kwargs.get('vessel', 'NOT_FOUND')}")
|
||||
|
||||
self.get_logger().info(f'Goal received: {protocol_kwargs}, running steps: \n{protocol_steps}')
|
||||
from unilabos.resources.graphio import physical_setup_graph
|
||||
|
||||
time_start = time.time()
|
||||
time_overall = 100
|
||||
self._busy = True
|
||||
self.lab_logger().info(f"Working on physical setup: {physical_setup_graph}")
|
||||
protocol_steps = protocol_steps_generator(G=physical_setup_graph, **protocol_kwargs)
|
||||
|
||||
self.lab_logger().info(f"Goal received: {protocol_kwargs}, running steps: \n{protocol_steps}")
|
||||
|
||||
# 逐步执行工作流
|
||||
for i, action in enumerate(protocol_steps):
|
||||
self.get_logger().info(f'Running step {i+1}: {action}')
|
||||
if type(action) == dict:
|
||||
# 如果是单个动作,直接执行
|
||||
if action["action_name"] == "wait":
|
||||
time.sleep(action["action_kwargs"]["time"])
|
||||
else:
|
||||
result = await self.execute_single_action(**action)
|
||||
elif type(action) == list:
|
||||
# 如果是并行动作,同时执行
|
||||
actions = action
|
||||
futures = [rclpy.get_global_executor().create_task(self.execute_single_action(**a)) for a in actions]
|
||||
results = [await f for f in futures]
|
||||
time_start = time.time()
|
||||
time_overall = 100
|
||||
self._busy = True
|
||||
|
||||
# 向Host更新物料当前状态
|
||||
for k, v in goal.get_fields_and_field_types().items():
|
||||
if v in ["unilabos_msgs/Resource", "sequence<unilabos_msgs/Resource>"]:
|
||||
r = ResourceUpdate.Request()
|
||||
r.resources = [
|
||||
convert_to_ros_msg(Resource, rs) for rs in nested_dict_to_list(protocol_kwargs[k])
|
||||
]
|
||||
response = await self._resource_clients["resource_update"].call_async(r)
|
||||
# 逐步执行工作流
|
||||
step_results = []
|
||||
for i, action in enumerate(protocol_steps):
|
||||
# self.get_logger().info(f"Running step {i + 1}: {action}")
|
||||
if isinstance(action, dict):
|
||||
# 如果是单个动作,直接执行
|
||||
if action["action_name"] == "wait":
|
||||
time.sleep(action["action_kwargs"]["time"])
|
||||
step_results.append({"step": i + 1, "action": "wait", "result": "completed"})
|
||||
else:
|
||||
result = await self.execute_single_action(**action)
|
||||
step_results.append({"step": i + 1, "action": action["action_name"], "result": result})
|
||||
elif isinstance(action, list):
|
||||
# 如果是并行动作,同时执行
|
||||
actions = action
|
||||
futures = [
|
||||
rclpy.get_global_executor().create_task(self.execute_single_action(**a)) for a in actions
|
||||
]
|
||||
results = [await f for f in futures]
|
||||
step_results.append(
|
||||
{
|
||||
"step": i + 1,
|
||||
"parallel_actions": [a["action_name"] for a in actions],
|
||||
"results": results,
|
||||
}
|
||||
)
|
||||
|
||||
goal_handle.succeed()
|
||||
# 向Host更新物料当前状态
|
||||
for k, v in goal.get_fields_and_field_types().items():
|
||||
if v in ["unilabos_msgs/Resource", "sequence<unilabos_msgs/Resource>"]:
|
||||
r = ResourceUpdate.Request()
|
||||
r.resources = [
|
||||
convert_to_ros_msg(Resource, rs) for rs in nested_dict_to_list(protocol_kwargs[k])
|
||||
]
|
||||
response = await self._resource_clients["resource_update"].call_async(r)
|
||||
|
||||
# 设置成功状态和返回值
|
||||
execution_success = True
|
||||
protocol_return_value = {
|
||||
"protocol_name": protocol_name,
|
||||
"steps_executed": len(protocol_steps),
|
||||
"step_results": step_results,
|
||||
"total_time": time.time() - time_start,
|
||||
}
|
||||
|
||||
goal_handle.succeed()
|
||||
|
||||
except Exception as e:
|
||||
# 捕获并记录错误信息
|
||||
execution_error = traceback.format_exc()
|
||||
execution_success = False
|
||||
error(f"协议 {protocol_name} 执行失败")
|
||||
error(traceback.format_exc())
|
||||
self.lab_logger().error(f"协议执行出错: {str(e)}")
|
||||
|
||||
# 设置动作失败
|
||||
goal_handle.abort()
|
||||
|
||||
finally:
|
||||
self._busy = False
|
||||
|
||||
# 创建结果消息
|
||||
result = action_value_mapping["type"].Result()
|
||||
result.success = True
|
||||
result.success = execution_success
|
||||
|
||||
self._busy = False
|
||||
# 获取结果消息类型信息,检查是否有return_info字段
|
||||
result_msg_types = action_value_mapping["type"].Result.get_fields_and_field_types()
|
||||
|
||||
# 设置return_info字段(如果存在)
|
||||
for attr_name in result_msg_types.keys():
|
||||
if attr_name in ["success", "reached_goal"]:
|
||||
setattr(result, attr_name, execution_success)
|
||||
elif attr_name == "return_info":
|
||||
setattr(
|
||||
result,
|
||||
attr_name,
|
||||
serialize_result_info(execution_error, execution_success, protocol_return_value),
|
||||
)
|
||||
|
||||
self.lab_logger().info(f"🤩🤩🤩🤩🤩🤩协议 {protocol_name} 完成并返回结果😎😎😎😎😎😎")
|
||||
return result
|
||||
|
||||
return execute_protocol
|
||||
|
||||
async def execute_single_action(self, device_id, action_name, action_kwargs):
|
||||
@@ -225,7 +318,7 @@ class ROS2ProtocolNode(BaseROS2DeviceNode):
|
||||
action_client = self._action_clients[action_id]
|
||||
goal_msg = convert_to_ros_msg(action_client._action_type.Goal(), action_kwargs)
|
||||
|
||||
self.lab_logger().info(f"发送动作请求到: {action_id}")
|
||||
##### self.lab_logger().info(f"发送动作请求到: {action_id}")
|
||||
action_client.wait_for_server()
|
||||
|
||||
# 等待动作完成
|
||||
@@ -237,18 +330,23 @@ class ROS2ProtocolNode(BaseROS2DeviceNode):
|
||||
return None
|
||||
|
||||
result_future = await handle.get_result_async()
|
||||
self.lab_logger().info(f"动作完成: {action_name}")
|
||||
##### self.lab_logger().info(f"动作完成: {action_name}")
|
||||
|
||||
return result_future.result
|
||||
|
||||
|
||||
"""还没有改过的部分"""
|
||||
|
||||
def _setup_hardware_proxy(self, device: ROS2DeviceNode, communication_device: ROS2DeviceNode, read_method, write_method):
|
||||
def _setup_hardware_proxy(
|
||||
self, device: ROS2DeviceNode, communication_device: ROS2DeviceNode, read_method, write_method
|
||||
):
|
||||
"""为设备设置硬件接口代理"""
|
||||
# extra_info = [getattr(device.driver_instance, info) for info in communication_device.ros_node_instance._hardware_interface.get("extra_info", [])]
|
||||
write_func = getattr(communication_device.driver_instance, communication_device.ros_node_instance._hardware_interface["write"])
|
||||
read_func = getattr(communication_device.driver_instance, communication_device.ros_node_instance._hardware_interface["read"])
|
||||
write_func = getattr(
|
||||
communication_device.driver_instance, communication_device.ros_node_instance._hardware_interface["write"]
|
||||
)
|
||||
read_func = getattr(
|
||||
communication_device.driver_instance, communication_device.ros_node_instance._hardware_interface["read"]
|
||||
)
|
||||
|
||||
def _read(*args, **kwargs):
|
||||
return read_func(*args, **kwargs)
|
||||
@@ -264,7 +362,6 @@ class ROS2ProtocolNode(BaseROS2DeviceNode):
|
||||
# bound_write = MethodType(_write, device.driver_instance)
|
||||
setattr(device.driver_instance, write_method, _write)
|
||||
|
||||
|
||||
async def _update_resources(self, goal, protocol_kwargs):
|
||||
"""更新资源状态"""
|
||||
for k, v in goal.get_fields_and_field_types().items():
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user