mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-05 14:05:12 +00:00
fix:debug dummy2
This commit is contained in:
241
dummy2_debug/test_dummy2_integration.py
Normal file
241
dummy2_debug/test_dummy2_integration.py
Normal file
@@ -0,0 +1,241 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Dummy2 Unilab实际设备调用测试
|
||||
模拟通过Unilab设备管理系统调用Dummy2设备
|
||||
"""
|
||||
|
||||
import json
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
|
||||
# 添加Unilab路径
|
||||
sys.path.insert(0, '/home/hh/Uni-Lab-OS')
|
||||
|
||||
def test_device_action_simulation():
|
||||
"""模拟设备Action调用"""
|
||||
print("=" * 50)
|
||||
print("测试: 模拟设备Action调用")
|
||||
print("=" * 50)
|
||||
|
||||
try:
|
||||
from unilabos.devices.ros_dev.moveit_interface import MoveitInterface
|
||||
|
||||
# 创建MoveitInterface实例(模拟设备注册时的创建过程)
|
||||
moveit_interface = MoveitInterface(
|
||||
moveit_type='dummy2_robot',
|
||||
joint_poses='[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]',
|
||||
device_config=None
|
||||
)
|
||||
print("✓ MoveitInterface实例创建成功")
|
||||
|
||||
# 模拟moveit_joint_task action调用
|
||||
print("\n测试moveit_joint_task方法...")
|
||||
test_positions = [1.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
||||
|
||||
try:
|
||||
# 注意:这里只测试方法存在性和参数格式,不实际执行
|
||||
# 因为需要真实的ROS2节点和MoveIt2服务
|
||||
|
||||
# 检查方法是否存在
|
||||
if hasattr(moveit_interface, 'moveit_joint_task'):
|
||||
print("✓ moveit_joint_task方法存在")
|
||||
|
||||
# 检查参数
|
||||
import inspect
|
||||
sig = inspect.signature(moveit_interface.moveit_joint_task)
|
||||
params = list(sig.parameters.keys())
|
||||
print(f" 方法参数: {params}")
|
||||
|
||||
# 模拟调用参数
|
||||
call_args = {
|
||||
'move_group': 'arm',
|
||||
'joint_positions': test_positions,
|
||||
'speed': 0.3,
|
||||
'retry': 10
|
||||
}
|
||||
print(f" 调用参数: {call_args}")
|
||||
|
||||
else:
|
||||
print("✗ moveit_joint_task方法不存在")
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ moveit_joint_task测试失败: {e}")
|
||||
|
||||
# 模拟moveit_task action调用
|
||||
print("\n测试moveit_task方法...")
|
||||
try:
|
||||
if hasattr(moveit_interface, 'moveit_task'):
|
||||
print("✓ moveit_task方法存在")
|
||||
|
||||
# 检查参数
|
||||
import inspect
|
||||
sig = inspect.signature(moveit_interface.moveit_task)
|
||||
params = list(sig.parameters.keys())
|
||||
print(f" 方法参数: {params}")
|
||||
|
||||
# 模拟调用参数
|
||||
call_args = {
|
||||
'move_group': 'arm',
|
||||
'position': [0.3, 0.0, 0.4],
|
||||
'quaternion': [0.0, 0.0, 0.0, 1.0],
|
||||
'speed': 0.3,
|
||||
'retry': 10,
|
||||
'cartesian': False
|
||||
}
|
||||
print(f" 调用参数: {call_args}")
|
||||
|
||||
else:
|
||||
print("✗ moveit_task方法不存在")
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ moveit_task测试失败: {e}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ 设备Action模拟失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def test_config_consistency():
|
||||
"""测试配置一致性"""
|
||||
print("\n" + "=" * 50)
|
||||
print("测试: 配置一致性检查")
|
||||
print("=" * 50)
|
||||
|
||||
try:
|
||||
# 读取robot_arm.yaml中的Dummy2配置
|
||||
import yaml
|
||||
with open('/home/hh/Uni-Lab-OS/unilabos/registry/devices/robot_arm.yaml', 'r', encoding='utf-8') as f:
|
||||
robot_arm_config = yaml.safe_load(f)
|
||||
|
||||
dummy2_config = robot_arm_config.get('robotic_arm.Dummy2', {})
|
||||
|
||||
# 检查init_param_schema
|
||||
init_params = dummy2_config.get('init_param_schema', {}).get('config', {}).get('properties', {})
|
||||
print("设备初始化参数:")
|
||||
for param, config in init_params.items():
|
||||
print(f" {param}: {config.get('type', 'unknown')}")
|
||||
|
||||
# 检查move_group.json是否与配置匹配
|
||||
with open('/home/hh/Uni-Lab-OS/unilabos/device_mesh/devices/dummy2_robot/config/move_group.json', 'r') as f:
|
||||
move_group_data = json.load(f)
|
||||
|
||||
print(f"\nmove_group.json配置:")
|
||||
for group, config in move_group_data.items():
|
||||
print(f" 组 '{group}':")
|
||||
print(f" 关节数量: {len(config.get('joint_names', []))}")
|
||||
print(f" 基础连接: {config.get('base_link_name')}")
|
||||
print(f" 末端执行器: {config.get('end_effector_name')}")
|
||||
|
||||
print("✓ 配置一致性检查完成")
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ 配置一致性检查失败: {e}")
|
||||
|
||||
def test_action_command_parsing():
|
||||
"""测试Action命令解析"""
|
||||
print("\n" + "=" * 50)
|
||||
print("测试: Action命令解析")
|
||||
print("=" * 50)
|
||||
|
||||
try:
|
||||
from unilabos.devices.ros_dev.moveit_interface import MoveitInterface
|
||||
|
||||
moveit_interface = MoveitInterface(
|
||||
moveit_type='dummy2_robot',
|
||||
joint_poses='[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]',
|
||||
device_config=None
|
||||
)
|
||||
|
||||
# 测试set_position命令解析(这个方法调用moveit_task)
|
||||
print("测试set_position命令解析...")
|
||||
|
||||
test_command = json.dumps({
|
||||
"move_group": "arm",
|
||||
"position": [0.3, 0.0, 0.4],
|
||||
"quaternion": [0.0, 0.0, 0.0, 1.0],
|
||||
"speed": 0.3,
|
||||
"retry": 10,
|
||||
"cartesian": False
|
||||
})
|
||||
|
||||
print(f"测试命令: {test_command}")
|
||||
|
||||
if hasattr(moveit_interface, 'set_position'):
|
||||
print("✓ set_position方法存在")
|
||||
print(" (注意: 实际执行需要ROS2环境和MoveIt2服务)")
|
||||
else:
|
||||
print("✗ set_position方法不存在")
|
||||
|
||||
# 测试关节空间命令格式
|
||||
print("\n测试关节空间命令...")
|
||||
joint_command_data = {
|
||||
"move_group": "arm",
|
||||
"joint_positions": "[1.0, 0.0, 0.0, 0.0, 0.0, 0.0]",
|
||||
"speed": 0.3,
|
||||
"retry": 10
|
||||
}
|
||||
|
||||
print(f"关节命令数据: {json.dumps(joint_command_data, indent=2)}")
|
||||
|
||||
# 检查joint_positions是否需要解析
|
||||
joint_positions_str = joint_command_data["joint_positions"]
|
||||
if isinstance(joint_positions_str, str):
|
||||
joint_positions = json.loads(joint_positions_str)
|
||||
print(f"解析后的关节位置: {joint_positions}")
|
||||
print(f"关节数量: {len(joint_positions)}")
|
||||
|
||||
print("✓ 命令解析测试完成")
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ 命令解析测试失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def test_integration_summary():
|
||||
"""集成总结测试"""
|
||||
print("\n" + "=" * 50)
|
||||
print("集成总结")
|
||||
print("=" * 50)
|
||||
|
||||
print("当前Dummy2集成状态:")
|
||||
print("✓ 设备注册配置完成")
|
||||
print("✓ 设备网格配置完成")
|
||||
print("✓ MoveitInterface模块可用")
|
||||
print("✓ ROS2依赖可导入")
|
||||
print("✓ Action方法存在且可调用")
|
||||
|
||||
print("\n下一步需要完成的工作:")
|
||||
print("1. 启动Dummy2的ROS2服务 (dummy2_ws)")
|
||||
print("2. 确保MoveIt2规划服务运行")
|
||||
print("3. 配置正确的设备ID和命名空间")
|
||||
print("4. 测试实际的机械臂控制")
|
||||
|
||||
print("\n从ROS2原生控制到Unilab控制的命令映射:")
|
||||
print("原始命令:")
|
||||
print(" moveit2.move_to_configuration([1.0, 0.0, 0.0, 0.0, 0.0, 0.0])")
|
||||
|
||||
print("\nUnilab等价命令:")
|
||||
print(" device.auto-moveit_joint_task({")
|
||||
print(" 'move_group': 'arm',")
|
||||
print(" 'joint_positions': '[1.0, 0.0, 0.0, 0.0, 0.0, 0.0]',")
|
||||
print(" 'speed': 0.3,")
|
||||
print(" 'retry': 10")
|
||||
print(" })")
|
||||
|
||||
def main():
|
||||
"""主测试函数"""
|
||||
print("Dummy2 Unilab设备调用测试")
|
||||
print("=" * 60)
|
||||
|
||||
test_device_action_simulation()
|
||||
test_config_consistency()
|
||||
test_action_command_parsing()
|
||||
test_integration_summary()
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("设备调用测试完成")
|
||||
print("=" * 60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user