#!/usr/bin/env python # -*- coding: utf-8 -*- """ 测试模拟扳手服务器 演示如何使用模拟扳手进行测试 """ from wrench_controller import WrenchController import time def test_simulator(): """测试模拟扳手""" print("="*60) print("🧪 测试模拟扳手服务器") print("="*60) print("\n请确保模拟扳手服务器已启动(运行 wrench_simulator.py)") print("按 Enter 键开始测试...") input() # 创建控制器实例 wrench = WrenchController() # 连接到扳手 if wrench.connect(): try: print("\n" + "="*60) print("步骤 1: 启用远程控制") print("="*60) wrench.enable_remote_control(True) time.sleep(0.5) # 等待响应 print("\n" + "="*60) print("步骤 2: 设定扭矩参数") print("="*60) wrench.set_torque_parameters( target_torque=300, mode=1, # M1模式 torque_tolerance=0.10, # ±10% angle_max=360, angle_min=1 ) time.sleep(0.5) # 等待响应 print("\n" + "="*60) print("步骤 3: 启动扳手(正转)") print("="*60) wrench.start_wrench(direction=1) time.sleep(0.5) # 等待响应 print("\n" + "="*60) print("步骤 4: 等待执行结果") print("="*60) result = wrench.wait_for_result(timeout=5.0) # 根据结果进行后续处理 if result and result.get("success"): print("\n✅ 扳手操作成功完成!") else: print("\n❌ 扳手操作失败!") finally: # 断开连接 wrench.disconnect() else: print("❌ 无法连接到扳手") print("请确保模拟扳手服务器已启动") if __name__ == "__main__": test_simulator()