
Akcje firm zajmujących się kopaniem Bitcoin stały się jedną z najbardziej dynamicznych części rynku w 2026 roku, a powodem nie jest już tylko Bitcoin. W obliczu presji na marże kopania po halvingu, największe firmy górnicze odkryły, że ich najcenniejszym aktywem nie jest hashrate, ale ich moc: gigawaty zabezpieczonej energii elektrycznej, połączenia sieciowe i lokalizacje centrów danych, do których firmy zajmujące się sztuczną inteligencją (AI) desperacko chcą uzyskać dostęp. Rezultatem jest sektor szybko przekształcający się z czystych kopalni Bitcoin w dostawców infrastruktury AI i obliczeń wysokiej wydajności (HPC), nawet gdy sam Bitcoin był przez większość roku notowany niżej.
Ten przewodnik skupia się na kluczowych akcjach firm kopających Bitcoin w 2026 roku, pogrupowanych według tego, jak daleko każda z nich posunęła się w kierunku AI: od kopalń skupionych na BTC, przez hybrydy prowadzące zarówno Bitcoin, jak i AI, po firmy, które w dużej mierze stały się dostawcami infrastruktury AI. Artykuł wyjaśnia, jak każda nazwa pasuje do tej transformacji i jak globalni traderzy mogą uzyskać ekspozycję na wybrane akcje na BingX TradFi poprzez kontrakty perpetual z depozytem zabezpieczającym w USDT.
Trend rynku kopania Bitcoin 2026: Przejście od kopania do infrastruktury AI
Cykl kopania Bitcoin w 2026 roku jest przekształcany przez prostą zmianę: górnicy już kontrolują moc, ziemię i połączenia sieciowe, których potrzebują centra danych AI. W miarę zacieśniania się ekonomii kopania i zwiększania wartości hostingu AI, kilku operatorów przekształca się w firmy infrastruktury cyfrowej, a nie czyste kopacze Bitcoin. Cztery siły wyjaśniają, dlaczego transformacja się przyspiesza.

- Halving z 2024 roku uczynił kopanie Bitcoin mniej rentownym. Nagroda za blok została obcięta o połowę z powodu halvingu Bitcoin w 2024 roku, wywierając większą presję na marże kopania i zwiększając znaczenie kosztów elektryczności oraz wydajności maszyn. To zmusiło górników do poszukiwania zastosowań o wyższej wartości dla istniejących lokalizacji.
- Górnicy już kontrolują zasób, którego AI najbardziej potrzebuje: moc. Duże obiekty kopalniane zostały zbudowane wokół taniej energii elektrycznej i zabezpieczonych połączeń sieciowych, dokładnie tego, co centra danych AI coraz bardziej mają problem uzyskać. Przekształcenie części tej mocy na AI i obliczenia wysokiej wydajności może generować większe przychody na megawat niż tradycyjne kopanie Bitcoin.
- Hosting AI może zapewnić długoterminowe przychody kontraktowe. Przychody z kopania Bitcoin zmieniają się wraz z cenami BTC, trudnością sieci i opłatami transakcyjnymi. Umowy hostingu AI mogą zamiast tego zapewnić wieloletnie kontraktowe przepływy pieniężne, pomagając górnikom z dużymi klientami stać się mniej zależnymi od cykli rynku krypto.
- Konwersja AI wymaga miliardów dolarów nowych inwestycji. Obiekty kopalniane potrzebują znacznych ulepszeń w chłodzeniu, sieci, serwerach i infrastrukturze elektrycznej, zanim będą mogły obsługiwać obciążenia AI. Górnicy dlatego podnoszą dług, emitują akcje, sprzedają zasoby Bitcoin i nawiązują partnerstwa z inwestorami infrastrukturalnymi, aby sfinansować transformację.
Kluczowym trendem w 2026 roku jest to, że górnicy Bitcoin są coraz częściej wyceniani na dwóch biznesach jednocześnie: produkcja Bitcoin i infrastruktura AI. Firmy z zabezpieczoną mocą i podpisanymi kontraktami AI mogą handlować bardziej jak operatorzy centrów danych, podczas gdy górnicy bez znaczącej ekspozycji na AI pozostają bardziej ściśle związani z cenami Bitcoin i ekonomią kopania.
Kluczowe firmy kopania Bitcoin 2026 i porównanie według etapu przejścia na AI
Akcje firm kopających Bitcoin obejmują teraz zakres od czystych graczy kopalnanych po firmy coraz bardziej skupione na infrastrukturze AI i obliczeń wysokiej wydajności. To porównanie pokazuje, gdzie każda firma znajduje się w transformacji 2026.
|
Firma |
Ticker |
Główna rola |
Kluczowe zalety |
Na co zwrócić uwagę w 2026 |
|
MARA Holdings |
MARA |
Kopalnia Bitcoin i posiadacz BTC |
Jedna z największych kopalni Bitcoin ze znacznymi rezerwa# 通过RVMPython开发RVM应用 ## 简介 RVM机器人是专门针对焊接工艺设计的一款六轴工业机器人。RVM提供了完整的软件开发包,使得开发者可以便捷地开发RVM应用。RVMPython是一个与RVM机器人连接并控制的Python包,是实现RVM机器人控制的便捷工具。 ## 特点 - **用户友好**:RVMPython提供了简单易用的API,无论您是RVM机器人的新手还是有经验的开发者,都能快速上手。 - **功能全面**:支持RVM机器人的所有核心功能,包括运动控制、状态查询、参数设置等。 - **跨平台**:RVMPython可以在Windows、Linux和macOS等多种操作系统上运行。 - **开源**:RVMPython是开源的,您可以根据自己的需求进行定制和扩展。 ## 快速开始 ### 安装 首先确保您的计算机上已安装Python 3.6或更高版本。然后,使用pip安装RVMPython: ```shell pip install RVMPython ``` ### 基础使用 下面是一个简单的示例,展示了如何使用RVMPython控制RVM机器人: ```python # 导入RVMPython from RVMPython import * # 创建机械臂控制类 manipulator = Manipulator("192.168.1.18", 8899) # 连接机器人 manipulator.Connect() # 获取API版本 print("API Version:", manipulator.Get_API_Version()) # 断开连接 manipulator.DisConnect() ``` ### 文档和更多示例 想要了解更多关于RVMPython的信息、API参考、详细示例和最佳实践,请访问我们的官方文档: - [安装与配置](安装与配置.md) - [API参考手册](API/API概述.md) - [示例代码](Example/示例代码概述.md) ## 贡献和反馈 我们非常欢迎您对RVMPython项目的贡献和反馈。如果您有任何问题、建议或想要贡献代码,请访问我们的[GitHub仓库](https://github.com/RealManRobot/rvm_python.git)。 ## 许可证 RVMPython根据MIT许可证发布。详细信息请参见LICENSE文件。 --- 开始您的RVM机器人编程之旅吧!如果您有任何问题或需要帮助,请不要犹豫,通过上述渠道联系我们。 End File# Posture控制 `Posture` 类提供了机器人姿态控制的相关功能。 ## GetCurrentPose 获取当前机器人姿态。 **方法签名:** ```python def GetCurrentPose(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `pose` (list): 当前姿态信息 - 当 `result == 0` 时,返回包含位姿信息的列表 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 位置坐标 (单位:mm) - RX、RY、RZ: 姿态角度 (单位:°) - 当 `result != 0` 时,返回空列表 **示例:** ```python result, pose = robot.GetCurrentPose() if result == 0: print(f"当前位置: X={pose[0]}, Y={pose[1]}, Z={pose[2]}") print(f"当前姿态: RX={pose[3]}, RY={pose[4]}, RZ={pose[5]}") else: print("获取姿态失败") ``` **注意事项:** - 返回的坐标是基于机器人基坐标系的 - 坐标系定义遵循RVM机器人标准 ## GetCurrentJointAngle 获取当前机器人关节角度。 **方法签名:** ```python def GetCurrentJointAngle(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `joint_angle` (list): 当前关节角度 - 当 `result == 0` 时,返回包含6个关节角度的列表 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°) - 当 `result != 0` 时,返回空列表 **示例:** ```python result, angles = robot.GetCurrentJointAngle() if result == 0: for i, angle in enumerate(angles): print(f"关节{i+1}: {angle}°") else: print("获取关节角度失败") ``` **注意事项:** - 返回的角度值对应机器人的6个关节 - 角度范围取决于具体的机器人型号 ## GetCurrentToolPose 获取当前工具坐标系位姿。 **方法签名:** ```python def GetCurrentToolPose(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `tool_pose` (list): 当前工具位姿信息 - 当 `result == 0` 时,返回包含工具位姿信息的列表 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 工具位置坐标 (单位:mm) - RX、RY、RZ: 工具姿态角度 (单位:°) - 当 `result != 0` 时,返回空列表 **示例:** ```python result, tool_pose = robot.GetCurrentToolPose() if result == 0: print(f"工具位置: X={tool_pose[0]}, Y={tool_pose[1]}, Z={tool_pose[2]}") print(f"工具姿态: RX={tool_pose[3]}, RY={tool_pose[4]}, RZ={tool_pose[5]}") else: print("获取工具位姿失败") ``` **注意事项:** - 返回的位姿是相对于工具坐标系的 - 需要正确设置工具坐标系才能获得准确值 ## GetCurrentWorkPose 获取当前工作坐标系位姿。 **方法签名:** ```python def GetCurrentWorkPose(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `work_pose` (list): 当前工作位姿信息 - 当 `result == 0` 时,返回包含工作位姿信息的列表 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 工作位置坐标 (单位:mm) - RX、RY、RZ: 工作姿态角度 (单位:°) - 当 `result != 0` 时,返回空列表 **示例:** ```python result, work_pose = robot.GetCurrentWorkPose() if result == 0: print(f"工作位置: X={work_pose[0]}, Y={work_pose[1]}, Z={work_pose[2]}") print(f"工作姿态: RX={work_pose[3]}, RY={work_pose[4]}, RZ={work_pose[5]}") else: print("获取工作位姿失败") ``` **注意事项:** - 返回的位姿是相对于工作坐标系的 - 需要正确设置工作坐标系才能获得准确值 ## GetCurrentArmLine 获取机器人姿态信息。 **方法签名:** ```python def GetCurrentArmLine(self) -> (int, int, bool, bool, bool) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `arm` (int): 机械臂姿态 - 当 `result == 0` 时: - `0`: 右手系 - `1`: 左手系 - 当 `result != 0` 时,返回 `-1` - `elbow` (bool): 手肘姿态 - 当 `result == 0` 时: - `True`: 手肘向上 - `False`: 手肘向下 - 当 `result != 0` 时,返回 `False` - `wrist_flip` (bool): 手腕翻转状态 - 当 `result == 0` 时: - `True`: 手腕翻转 - `False`: 手腕未翻转 - 当 `result != 0` 时,返回 `False` - `axis4_inverse` (bool): 第4轴反向状态 - 当 `result == 0` 时: - `True`: 第4轴反向 - `False`: 第4轴正向 - 当 `result != 0` 时,返回 `False` **示例:** ```python result, arm, elbow, wrist_flip, axis4_inverse = robot.GetCurrentArmLine() if result == 0: arm_type = "右手系" if arm == 0 else "左手系" elbow_pos = "向上" if elbow else "向下" wrist_status = "翻转" if wrist_flip else "未翻转" axis4_status = "反向" if axis4_inverse else "正向" print(f"机械臂姿态: {arm_type}") print(f"手肘姿态: {elbow_pos}") print(f"手腕状态: {wrist_status}") print(f"第4轴状态: {axis4_status}") else: print("获取机器人姿态信息失败") ``` **注意事项:** - 该方法提供了机器人的姿态配置信息 - 这些信息对于逆运动学求解和路径规划很重要 ## GetInverseKin 计算逆运动学。 **方法签名:** ```python def GetInverseKin(self, pose: list, current_joint: list) -> (int, list) ``` **参数:** - `pose` (list): 目标位姿 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 位置坐标 (单位:mm) - RX、RY、RZ: 姿态角度 (单位:°) - `current_joint` (list): 当前关节角度 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `joint_angle` (list): 计算出的关节角度 - 当 `result == 0` 时,返回包含6个关节角度的列表 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°) - 当 `result != 0` 时,返回空列表 **示例:** ```python # 目标位姿 target_pose = [300, 0, 400, 0, 0, 0] # 当前关节角度 current_joints = [0, 0, 0, 0, 0, 0] result, joint_angles = robot.GetInverseKin(target_pose, current_joints) if result == 0: print(f"逆运动学求解成功:") for i, angle in enumerate(joint_angles): print(f"关节{i+1}: {angle}°") else: print("逆运动学求解失败") ``` **注意事项:** - 逆运动学可能有多个解,函数返回最接近当前关节角度的解 - 如果目标位姿不可达,函数将返回失败 ## GetForwardKin 计算正运动学。 **方法签名:** ```python def GetForwardKin(self, joint_angle: list) -> (int, list) ``` **参数:** - `joint_angle` (list): 关节角度 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `pose` (list): 计算出的位姿 - 当 `result == 0` 时,返回包含位姿信息的列表 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 位置坐标 (单位:mm) - RX、RY、RZ: 姿态角度 (单位:°) - 当 `result != 0` 时,返回空列表 **示例:** ```python # 关节角度 joint_angles = [0, 0, 90, 0, 90, 0] result, pose = robot.GetForwardKin(joint_angles) if result == 0: print(f"正运动学计算成功:") print(f"位置: X={pose[0]}, Y={pose[1]}, Z={pose[2]}") print(f"姿态: RX={pose[3]}, RY={pose[4]}, RZ={pose[5]}") else: print("正运动学计算失败") ``` **注意事项:** - 正运动学计算通常总是可以得到结果 - 返回的位姿是基于机器人基坐标系的 ## IsInWorkspace 检查位置是否在工作空间内。 **方法签名:** ```python def IsInWorkspace(self, pose: list, joint_angle: list) -> (int, bool) ``` **参数:** - `pose` (list): 目标位姿 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 位置坐标 (单位:mm) - RX、RY、RZ: 姿态角度 (单位:°) - `joint_angle` (list): 当前关节角度 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `is_in_workspace` (bool): 是否在工作空间内 - 当 `result == 0` 时: - `True`: 在工作空间内 - `False`: 不在工作空间内 - 当 `result != 0` 时,返回 `False` **示例:** ```python # 目标位姿 target_pose = [500, 200, 300, 0, 0, 0] # 当前关节角度 current_joints = [0, 0, 0, 0, 0, 0] result, is_reachable = robot.IsInWorkspace(target_pose, current_joints) if result == 0: if is_reachable: print("目标位姿在工作空间内") else: print("目标位姿不在工作空间内") else: print("检查工作空间失败") ``` **注意事项:** - 该方法考虑了机器人的关节限制和物理约束 - 在执行运动前使用此方法可以避免无效的运动命令 End File# Gripper控制 `Gripper` 类提供了机器人夹爪控制的相关功能,包括夹爪的开启、关闭、位置控制以及状态查询等。 ## GetGripperState 获取夹爪状态。 **方法签名:** ```python def GetGripperState(self) -> (int, bool, int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `enable` (bool): 夹爪使能状态 - 当 `result == 0` 时: - `True`: 夹爪已使能 - `False`: 夹爪未使能 - 当 `result != 0` 时,返回 `False` - `status` (int): 夹爪运行状态 - 当 `result == 0` 时: - `0`: 夹爪停止 - `1`: 夹爪正在运行 - `2`: 夹爪错误 - 当 `result != 0` 时,返回 `-1` - `position` (int): 夹爪当前位置 - 范围:`0-1000` - `0`: 完全关闭 - `1000`: 完全打开 - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, enable, status, position = robot.GetGripperState() if result == 0: enable_status = "已使能" if enable else "未使能" if status == 0: status_text = "停止" elif status == 1: status_text = "运行中" elif status == 2: status_text = "错误" else: status_text = "未知" print(f"夹爪状态: {enable_status}") print(f"运行状态: {status_text}") print(f"当前位置: {position}") else: print("获取夹爪状态失败") ``` **注意事项:** - 夹爪位置值0表示完全关闭,1000表示完全打开 - 在使用夹爪前应先检查使能状态 ## GripperOpen 控制夹爪打开到指定位置。 **方法签名:** ```python def GripperOpen(self, position: int, force: int = 600, max_time: int = 30000) -> int ``` **参数:** - `position` (int): 目标位置 - 范围:`0-1000` - `0`: 完全关闭 - `1000`: 完全打开 - `force` (int, optional): 夹取力度,默认值 `600` - 范围:`50-1000` - 数值越大力度越大 - `max_time` (int, optional): 最大执行时间,默认值 `30000` - 单位:毫秒 (ms) - 超过此时间将停止执行 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 夹爪打开到50%位置 result = robot.GripperOpen(500) if result == 0: print("夹爪打开成功") else: print("夹爪打开失败") # 使用自定义力度和时间 result = robot.GripperOpen(800, force=400, max_time=10000) if result == 0: print("夹爪打开到80%位置成功") else: print("夹爪打开失败") ``` **注意事项:** - 确保夹爪已正确连接和初始化 - 适当设置力度参数以避免损坏被夹取物体 - 设置合理的超时时间 ## GripperClose 控制夹爪关闭到指定位置。 **方法签名:** ```python def GripperClose(self, position: int, force: int = 600, max_time: int = 30000) -> int ``` **参数:** - `position` (int): 目标位置 - 范围:`0-1000` - `0`: 完全关闭 - `1000`: 完全打开 - `force` (int, optional): 夹取力度,默认值 `600` - 范围:`50-1000` - 数值越大力度越大 - `max_time` (int, optional): 最大执行时间,默认值 `30000` - 单位:毫秒 (ms) - 超过此时间将停止执行 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 夹爪关闭到20%位置 result = robot.GripperClose(200) if result == 0: print("夹爪关闭成功") else: print("夹爪关闭失败") # 使用自定义力度和时间 result = robot.GripperClose(100, force=300, max_time=15000) if result == 0: print("夹爪关闭到10%位置成功") else: print("夹爪关闭失败") ``` **注意事项:** - position值越小表示夹爪越关闭 - 适当设置力度以确保稳固夹取但不损坏物体 - 注意监控夹爪状态避免过度挤压 ## SetGripperRoute 设置夹爪行程。 **方法签名:** ```python def SetGripperRoute(self, route: int) -> int ``` **参数:** - `route` (int): 夹爪行程 - 范围:`0-1000` - 定义夹爪的最大开启距离 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置夹爪行程为80% result = robot.SetGripperRoute(800) if result == 0: print("夹爪行程设置成功") else: print("夹爪行程设置失败") ``` **注意事项:** - 行程设置影响夹爪的工作范围 - 设置行程后需要重新校准夹爪位置 ## GetGripperRoute 获取夹爪行程设置。 **方法签名:** ```python def GetGripperRoute(self) -> (int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `route` (int): 当前夹爪行程 - 范围:`0-1000` - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, route = robot.GetGripperRoute() if result == 0: print(f"当前夹爪行程: {route}") else: print("获取夹爪行程失败") ``` **注意事项:** - 了解当前行程设置有助于合理控制夹爪动作 - 行程设置影响position参数的实际含义 ## SetGripperIdle 切换夹爪空闲状态。 **方法签名:** ```python def SetGripperIdle(self, idle: bool) -> int ``` **参数:** - `idle` (bool): 空闲状态 - `True`: 设置夹爪为空闲状态 - `False`: 取消夹爪空闲状态 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置夹爪为空闲状态 result = robot.SetGripperIdle(True) if result == 0: print("夹爪已设置为空闲状态") else: print("设置夹爪空闲状态失败") # 取消空闲状态 result = robot.SetGripperIdle(False) if result == 0: print("夹爪空闲状态已取消") else: print("取消夹爪空闲状态失败") ``` **注意事项:** - 空闲状态下夹爪可能会停止保持力 - 用于节能或维护时的状态切换 ## GripperPersistentGrip 设置夹爪持续夹取。 **方法签名:** ```python def GripperPersistentGrip(self, position: int, force: int, max_time: int = 30000) -> int ``` **参数:** - `position` (int): 目标位置 - 范围:`0-1000` - `0`: 完全关闭 - `1000`: 完全打开 - `force` (int): 夹取力度 - 范围:`50-1000` - 数值越大力度越大 - `max_time` (int, optional): 最大执行时间,默认值 `30000` - 单位:毫秒 (ms) - 超过此时间将停止执行 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 持续夹取到位置300,力度500 result = robot.GripperPersistentGrip(300, 500) if result == 0: print("夹爪持续夹取设置成功") else: print("夹爪持续夹取设置失败") # 使用自定义超时时间 result = robot.GripperPersistentGrip(400, 600, 20000) if result == 0: print("夹爪持续夹取设置成功") else: print("夹爪持续夹取设置失败") ``` **注意事项:** - 持续夹取模式会持续施加设定的力度 - 适用于需要长时间保持夹取力度的场景 - 注意监控被夹取物体的状态 ## GripperStop 停止夹爪运动。 **方法签名:** ```python def GripperStop(self) -> int ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python result = robot.GripperStop() if result == 0: print("夹爪已停止") else: print("停止夹爪失败") ``` **注意事项:** - 可用于紧急停止夹爪动作 - 停止后夹爪会保持当前位置 ## 使用示例 以下是一个完整的夹爪控制示例: ```python from RVMPython import * # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接机器人 if robot.Connect() == 0: print("机器人连接成功") # 获取夹爪状态 result, enable, status, position = robot.GetGripperState() if result == 0: print(f"夹爪初始状态 - 使能: {enable}, 状态: {status}, 位置: {position}") # 打开夹爪到80%位置 result = robot.GripperOpen(800, force=500, max_time=10000) if result == 0: print("夹爪打开成功") time.sleep(2) # 等待2秒 # 关闭夹爪到20%位置进行夹取 result = robot.GripperClose(200, force=400, max_time=10000) if result == 0: print("夹爪夹取成功") time.sleep(2) # 保持夹取状态2秒 # 再次打开夹爪释放物体 result = robot.GripperOpen(800, force=300, max_time=10000) if result == 0: print("物体释放成功") else: print("释放失败") else: print("夹取失败") else: print("夹爪打开失败") # 断开连接 robot.DisConnect() else: print("机器人连接失败") ``` **最佳实践:** 1. **状态检查**: 在执行夹爪操作前检查夹爪状态 2. **力度控制**: 根据被夹取物体选择适当的力度参数 3. **超时设置**: 设置合理的超时时间避免无限等待 4. **错误处理**: 对所有夹爪操作进行错误处理 5. **位置监控**: 定期检查夹爪位置确保动作执行正确 End File# Extaxis控制 `Extaxis` 类提供了机器人外部轴控制的相关功能,包括位置控制、速度控制、状态查询等。 ## GetExtaxisCurrentPos 获取外部轴当前位置。 **方法签名:** ```python def GetExtaxisCurrentPos(self) -> (int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `position` (int): 当前位置 - 当 `result == 0` 时,返回外部轴的实际位置值 - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, pos = robot.GetExtaxisCurrentPos() if result == 0: print(f"外部轴当前位置: {pos}") else: print("获取外部轴位置失败") ``` **注意事项:** - 位置单位取决于外部轴的配置(通常为mm或度) - 需要外部轴已正确连接和初始化 ## GetExtaxisCurrentSpeed 获取外部轴当前速度。 **方法签名:** ```python def GetExtaxisCurrentSpeed(self) -> (int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `speed` (int): 当前速度 - 当 `result == 0` 时,返回外部轴的实际速度值 - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, speed = robot.GetExtaxisCurrentSpeed() if result == 0: print(f"外部轴当前速度: {speed}") else: print("获取外部轴速度失败") ``` **注意事项:** - 速度单位取决于外部轴的配置 - 正值表示正向运动,负值表示反向运动 ## GetExtaxisCurrentCurrent 获取外部轴当前电流。 **方法签名:** ```python def GetExtaxisCurrentCurrent(self) -> (int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `current` (int): 当前电流 - 当 `result == 0` 时,返回外部轴的实际电流值 - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, current = robot.GetExtaxisCurrentCurrent() if result == 0: print(f"外部轴当前电流: {current}") else: print("获取外部轴电流失败") ``` **注意事项:** - 电流值可用于监控外部轴的负载情况 - 过高的电流可能表示外部轴遇到阻力或故障 ## GetExtaxisCurrentVoltage 获取外部轴当前电压。 **方法签名:** ```python def GetExtaxisCurrentVoltage(self) -> (int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `voltage` (int): 当前电压 - 当 `result == 0` 时,返回外部轴的实际电压值 - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, voltage = robot.GetExtaxisCurrentVoltage() if result == 0: print(f"外部轴当前电压: {voltage}") else: print("获取外部轴电压失败") ``` **注意事项:** - 电压值可用于监控外部轴的供电情况 - 电压异常可能影响外部轴的正常工作 ## MoveExtaxis 控制外部轴运动到指定位置。 **方法签名:** ```python def MoveExtaxis(self, position: int, speed: int = 50) -> int ``` **参数:** - `position` (int): 目标位置 - 外部轴要移动到的目标位置 - `speed` (int, optional): 运动速度,默认值 `50` - 范围通常为 `1-100`,具体范围取决于外部轴配置 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 移动外部轴到位置1000,使用默认速度 result = robot.MoveExtaxis(1000) if result == 0: print("外部轴移动指令发送成功") else: print("外部轴移动失败") # 使用自定义速度移动 result = robot.MoveExtaxis(500, speed=30) if result == 0: print("外部轴以30%速度移动到位置500") else: print("外部轴移动失败") ``` **注意事项:** - 确保目标位置在外部轴的工作范围内 - 速度设置应考虑外部轴的载荷和精度要求 - 该函数为非阻塞调用,不等待运动完成 ## MoveRelativeExtaxis 控制外部轴相对运动。 **方法签名:** ```python def MoveRelativeExtaxis(self, offset: int, speed: int = 50) -> int ``` **参数:** - `offset` (int): 相对偏移量 - 正值表示正向移动 - 负值表示反向移动 - `speed` (int, optional): 运动速度,默认值 `50` - 范围通常为 `1-100`,具体范围取决于外部轴配置 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 外部轴正向移动100个单位 result = robot.MoveRelativeExtaxis(100) if result == 0: print("外部轴相对移动指令发送成功") else: print("外部轴相对移动失败") # 外部轴反向移动50个单位,使用速度70 result = robot.MoveRelativeExtaxis(-50, speed=70) if result == 0: print("外部轴以70%速度反向移动50个单位") else: print("外部轴相对移动失败") ``` **注意事项:** - 相对运动基于当前位置计算目标位置 - 确保相对运动后的目标位置在有效范围内 - 该函数为非阻塞调用,不等待运动完成 ## ExtAxisStop 停止外部轴运动。 **方法签名:** ```python def ExtAxisStop(self) -> int ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python result = robot.ExtAxisStop() if result == 0: print("外部轴已停止") else: print("停止外部轴失败") ``` **注意事项:** - 用于紧急停止或正常停止外部轴运动 - 外部轴停止后会保持当前位置 ## ExtAxisEnable 使能外部轴。 **方法签名:** ```python def ExtAxisEnable(self, enable: bool) -> int ``` **参数:** - `enable` (bool): 使能状态 - `True`: 使能外部轴 - `False`: 失能外部轴 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 使能外部轴 result = robot.ExtAxisEnable(True) if result == 0: print("外部轴已使能") else: print("外部轴使能失败") # 失能外部轴 result = robot.ExtAxisEnable(False) if result == 0: print("外部轴已失能") else: print("外部轴失能失败") ``` **注意事项:** - 外部轴必须使能后才能执行运动控制 - 失能外部轴会停止当前运动并释放伺服锁定 ## SetExtAxisParam 设置外部轴参数。 **方法签名:** ```python def SetExtAxisParam(self, param: dict) -> int ``` **参数:** - `param` (dict): 外部轴参数字典 - 可设置的参数包括但不限于: - `"max_speed"`: 最大速度 - `"acceleration"`: 加速度 - `"deceleration"`: 减速度 - `"position_limit_positive"`: 正向位置限制 - `"position_limit_negative"`: 负向位置限制 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置外部轴参数 params = { "max_speed": 100, "acceleration": 50, "deceleration": 50, "position_limit_positive": 2000, "position_limit_negative": -2000 } result = robot.SetExtAxisParam(params) if result == 0: print("外部轴参数设置成功") else: print("外部轴参数设置失败") ``` **注意事项:** - 参数设置会影响外部轴的运动特性 - 确保参数值在有效范围内 - 某些参数可能需要重启外部轴后生效 ## GetExtAxisParam 获取外部轴参数。 **方法签名:** ```python def GetExtAxisParam(self) -> (int, dict) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `param` (dict): 外部轴参数字典 - 当 `result == 0` 时,返回包含参数的字典 - 当 `result != 0` 时,返回空字典 **示例:** ```python result, params = robot.GetExtAxisParam() if result == 0: print("外部轴参数:") for key, value in params.items(): print(f" {key}: {value}") else: print("获取外部轴参数失败") ``` **注意事项:** - 返回的参数字典包含当前外部轴的所有配置信息 - 可用于备份和恢复外部轴配置 ## 使用示例 以下是一个完整的外部轴控制示例: ```python from RVMPython import * import time # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接机器人 if robot.Connect() == 0: print("机器人连接成功") # 使能外部轴 result = robot.ExtAxisEnable(True) if result == 0: print("外部轴使能成功") # 获取当前位置 result, current_pos = robot.GetExtaxisCurrentPos() if result == 0: print(f"外部轴当前位置: {current_pos}") # 移动到新位置 target_pos = current_pos + 100 result = robot.MoveExtaxis(target_pos, speed=30) if result == 0: print(f"外部轴开始移动到位置: {target_pos}") # 等待移动完成(这里简单等待5秒) time.sleep(5) # 检查最终位置 result, final_pos = robot.GetExtaxisCurrentPos() if result == 0: print(f"外部轴最终位置: {final_pos}") # 相对移动回原位置 result = robot.MoveRelativeExtaxis(-100, speed=50) if result == 0: print("外部轴开始回到原位置") time.sleep(5) else: print("外部轴移动失败") else: print("获取外部轴位置失败") # 失能外部轴 robot.ExtAxisEnable(False) print("外部轴已失能") else: print("外部轴使能失败") # 断开连接 robot.DisConnect() else: print("机器人连接失败") ``` **最佳实践:** 1. **使能检查**: 在控制外部轴前确保其已使能 2. **位置监控**: 定期检查外部轴位置确保运动正确执行 3. **速度控制**: 根据应用需求选择合适的运动速度 4. **错误处理**: 对所有外部轴操作进行错误处理 5. **安全考虑**: 设置合理的位置限制和速度限制 6. **状态监控**: 监控外部轴的电流、电压等状态信息 End File# API/Control/Motion控制.md # Motion控制 `Motion` 类提供了机器人运动控制的核心功能,包括各种运动模式的控制方法。 ## Movej 关节空间运动控制。 **方法签名:** ```python def Movej(self, joint_angle: list, speed: int, block: bool = True) -> int ``` **参数:** - `joint_angle` (list): 目标关节角度 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°) - `speed` (int): 运动速度 - 范围:`1-100` (相对百分比) - `block` (bool, optional): 是否阻塞等待,默认值 `True` - `True`: 阻塞等待运动完成 - `False`: 非阻塞,立即返回 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 关节运动到指定角度 joint_angles = [0, 0, 90, 0, 90, 0] result = robot.Movej(joint_angles, 50) if result == 0: print("关节运动完成") else: print("关节运动失败") # 非阻塞关节运动 result = robot.Movej(joint_angles, 30, block=False) if result == 0: print("关节运动指令发送成功") else: print("关节运动指令发送失败") ``` **注意事项:** - 关节运动是在关节空间内的最短路径运动 - 确保目标关节角度在有效范围内 - 阻塞模式下会等待运动完成后返回 ## Movel 直线运动控制。 **方法签名:** ```python def Movel(self, pose: list, speed: int, block: bool = True) -> int ``` **参数:** - `pose` (list): 目标位姿 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 位置坐标 (单位:mm) - RX、RY、RZ: 姿态角度 (单位:°) - `speed` (int): 运动速度 - 范围:`1-100` (相对百分比) - `block` (bool, optional): 是否阻塞等待,默认值 `True` - `True`: 阻塞等待运动完成 - `False`: 非阻塞,立即返回 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 直线运动到指定位姿 target_pose = [300, 0, 400, 0, 0, 0] result = robot.Movel(target_pose, 50) if result == 0: print("直线运动完成") else: print("直线运动失败") # 非阻塞直线运动 result = robot.Movel(target_pose, 30, block=False) if result == 0: print("直线运动指令发送成功") else: print("直线运动指令发送失败") ``` **注意事项:** - 直线运动保持末端执行器的直线路径 - 确保路径上所有点都在工作空间内 - 可能需要更多的计算时间 ## Movec 圆弧运动控制。 **方法签名:** ```python def Movec(self, pose_via: list, pose_to: list, speed: int, block: bool = True) -> int ``` **参数:** - `pose_via` (list): 中间位姿(圆弧上的点) - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 位置坐标 (单位:mm) - RX、RY、RZ: 姿态角度 (单位:°) - `pose_to` (list): 目标位姿 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 位置坐标 (单位:mm) - RX、RY、RZ: 姿态角度 (单位:°) - `speed` (int): 运动速度 - 范围:`1-100` (相对百分比) - `block` (bool, optional): 是否阻塞等待,默认值 `True` - `True`: 阻塞等待运动完成 - `False`: 非阻塞,立即返回 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 圆弧运动 start_pose = [300, 0, 400, 0, 0, 0] # 当前需要在此位置 via_pose = [300, 100, 400, 0, 0, 0] # 中间点 end_pose = [300, 200, 400, 0, 0, 0] # 终点 result = robot.Movec(via_pose, end_pose, 40) if result == 0: print("圆弧运动完成") else: print("圆弧运动失败") ``` **注意事项:** - 圆弧由当前位置、中间点和终点确定 - 三点不能共线,否则无法形成圆弧 - 确保整个圆弧路径在工作空间内 ## MoveL_Follow 跟踪直线运动。 **方法签名:** ```python def MoveL_Follow(self, pose: list, follow_pos: float) -> int ``` **参数:** - `pose` (list): 目标位姿 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 位置坐标 (单位:mm) - RX、RY、RZ: 姿态角度 (单位:°) - `follow_pos` (float): 跟踪位置 - 用于配合外部轴或传送带的跟踪运动 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 跟踪直线运动 target_pose = [300, 0, 400, 0, 0, 0] result = robot.MoveL_Follow(target_pose, 100.0) if result == 0: print("跟踪运动完成") else: print("跟踪运动失败") ``` **注意事项:** - 用于配合移动工件的跟踪作业 - 需要正确配置跟踪系统参数 ## MoveJ_Follow 跟踪关节运动。 **方法签名:** ```python def MoveJ_Follow(self, joint_angle: list, follow_pos: float) -> int ``` **参数:** - `joint_angle` (list): 目标关节角度 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°) - `follow_pos` (float): 跟踪位置 - 用于配合外部轴或传送带的跟踪运动 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 跟踪关节运动 joint_angles = [0, 0, 90, 0, 90, 0] result = robot.MoveJ_Follow(joint_angles, 50.0) if result == 0: print("跟踪关节运动完成") else: print("跟踪关节运动失败") ``` **注意事项:** - 关节空间的跟踪运动 - 需要正确配置跟踪系统参数 ## MoveByLine 按轨迹线运动。 **方法签名:** ```python def MoveByLine(self, trajectory: list, speed: int, block: bool = True) -> int ``` **参数:** - `trajectory` (list): 轨迹点列表 - 每个轨迹点格式:`[X, Y, Z, RX, RY, RZ]` - 轨迹点按顺序连接形成运动路径 - `speed` (int): 运动速度 - 范围:`1-100` (相对百分比) - `block` (bool, optional): 是否阻塞等待,默认值 `True` - `True`: 阻塞等待运动完成 - `False`: 非阻塞,立即返回 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 定义轨迹点 trajectory = [ [300, 0, 400, 0, 0, 0], [300, 100, 400, 0, 0, 0], [400, 100, 400, 0, 0, 0], [400, 0, 400, 0, 0, 0] ] result = robot.MoveByLine(trajectory, 50) if result == 0: print("轨迹运动完成") else: print("轨迹运动失败") ``` **注意事项:** - 机器人会按照轨迹点顺序执行连续运动 - 轨迹点之间可能进行直线插补 - 确保所有轨迹点都在工作空间内 ## MoveJog 手动模式运动(点动)。 **方法签名:** ```python def MoveJog(self, axis: int, direction: int, speed: int = 20) -> int ``` **参数:** - `axis` (int): 运动轴 - `0-5`: 关节轴 J1-J6 - `6-11`: 笛卡尔轴 X、Y、Z、RX、RY、RZ - `direction` (int): 运动方向 - `0`: 负方向 - `1`: 正方向 - `speed` (int, optional): 运动速度,默认值 `20` - 范围:`1-100` (相对百分比) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # J1关节正向点动 result = robot.MoveJog(0, 1, 30) if result == 0: print("J1关节开始正向点动") else: print("点动失败") # X轴负向点动 result = robot.MoveJog(6, 0, 25) if result == 0: print("X轴开始负向点动") else: print("点动失败") ``` **注意事项:** - 点动是连续运动,需要调用StopMove停止 - 适用于手动调试和定位 - 注意安全,避免碰撞 ## StopMove 停止机器人运动。 **方法签名:** ```python def StopMove(self) -> int ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python result = robot.StopMove() if result == 0: print("机器人已停止") else: print("停止失败") ``` **注意事项:** - 立即停止当前运动 - 可用于紧急停止或正常停止 ## EmergencyStop 紧急停止。 **方法签名:** ```python def EmergencyStop(self) -> int ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python result = robot.EmergencyStop() if result == 0: print("紧急停止成功") else: print("紧急停止失败") ``` **注意事项:** - 比普通停止更快速和强制 - 可能导致轨迹不连续 - 仅在紧急情况下使用 ## PauseMove 暂停运动。 **方法签名:** ```python def PauseMove(self) -> int ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python result = robot.PauseMove() if result == 0: print("运动已暂停") else: print("暂停失败") ``` **注意事项:** - 暂停当前运动,可以通过ContinueMove恢复 - 暂停期间机器人保持位置 ## ContinueMove 继续运动。 **方法签名:** ```python def ContinueMove(self) -> int ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python result = robot.ContinueMove() if result == 0: print("运动已继续") else: print("继续运动失败") ``` **注意事项:** - 恢复之前暂停的运动 - 只能恢复因PauseMove暂停的运动 ## 使用示例 以下是一个完整的运动控制示例: ```python from RVMPython import * import time # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接机器人 if robot.Connect() == 0: print("机器人连接成功") # 关节运动到初始位置 home_joints = [0, 0, 0, 0, 0, 0] result = robot.Movej(home_joints, 50) if result == 0: print("回到初始位置") # 直线运动 target_pose = [300, 0, 400, 0, 0, 0] result = robot.Movel(target_pose, 30) if result == 0: print("直线运动完成") # 圆弧运动 via_pose = [300, 100, 400, 0, 0, 0] end_pose = [300, 200, 400, 0, 0, 0] result = robot.Movec(via_pose, end_pose, 40) if result == 0: print("圆弧运动完成") # 演示暂停和继续 print("开始非阻塞运动...") result = robot.Movel([400, 0, 400, 0, 0, 0], 20, block=False) if result == 0: time.sleep(2) # 等待2秒 robot.PauseMove() print("运动已暂停") time.sleep(3) # 暂停3秒 robot.ContinueMove() print("运动已继续") # 断开连接 robot.DisConnect() else: print("机器人连接失败") ``` **最佳实践:** 1. **运动前检查**: 在执行运动前检查机器人状态和工作空间 2. **速度控制**: 根据应用需求选择合适的运动速度 3. **路径规划**: 确保运动路径安全且高效 4. **错误处理**: 对所有运动命令进行错误处理 5. **阻塞模式**: 根据程序逻辑选择阻塞或非阻塞模式 End File# RealManRobot/rvm_python_docs # API/Control/IOControl.md # IOControl控制 `IOControl` 类提供了机器人数字输入输出和模拟输入输出的控制功能。 ## GetDO 获取数字输出状态。 **方法签名:** ```python def GetDO(self, index: int) -> (int, bool) ``` **参数:** - `index` (int): 数字输出端口索引 - 范围:`1-16`(具体范围取决于机器人型号) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `state` (bool): 数字输出状态 - 当 `result == 0` 时: - `True`: 输出为高电平 - `False`: 输出为低电平 - 当 `result != 0` 时,返回 `False` **示例:** ```python result, state = robot.GetDO(1) if result == 0: status = "高电平" if state else "低电平" print(f"数字输出1状态: {status}") else: print("获取数字输出状态失败") ``` **注意事项:** - 端口索引从1开始 - 确保索引在有效范围内 ## SetDO 设置数字输出状态。 **方法签名:** ```python def SetDO(self, index: int, state: bool) -> int ``` **参数:** - `index` (int): 数字输出端口索引 - 范围:`1-16`(具体范围取决于机器人型号) - `state` (bool): 目标状态 - `True`: 设置为高电平 - `False`: 设置为低电平 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置数字输出1为高电平 result = robot.SetDO(1, True) if result == 0: print("数字输出1设置为高电平") else: print("设置数字输出失败") # 设置数字输出2为低电平 result = robot.SetDO(2, False) if result == 0: print("数字输出2设置为低电平") else: print("设置数字输出失败") ``` **注意事项:** - 端口索引从1开始 - 设置后立即生效 - 确保连接的设备能承受输出电压/电流 ## GetAllDO 获取所有数字输出状态。 **方法签名:** ```python def GetAllDO(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `states` (list): 所有数字输出状态 - 当 `result == 0` 时,返回布尔值列表,每个元素对应一个端口 - 当 `result != 0` 时,返回空列表 **示例:** ```python result, states = robot.GetAllDO() if result == 0: for i, state in enumerate(states): status = "高电平" if state else "低电平" print(f"数字输出{i+1}: {status}") else: print("获取所有数字输出状态失败") ``` **注意事项:** - 返回列表长度取决于机器人数字输出端口数量 - 索引0对应端口1 ## GetDI 获取数字输入状态。 **方法签名:** ```python def GetDI(self, index: int) -> (int, bool) ``` **参数:** - `index` (int): 数字输入端口索引 - 范围:`1-16`(具体范围取决于机器人型号) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `state` (bool): 数字输入状态 - 当 `result == 0` 时: - `True`: 输入为高电平 - `False`: 输入为低电平 - 当 `result != 0` 时,返回 `False` **示例:** ```python result, state = robot.GetDI(1) if result == 0: status = "高电平" if state else "低电平" print(f"数字输入1状态: {status}") else: print("获取数字输入状态失败") ``` **注意事项:** - 端口索引从1开始 - 数字输入状态由外部信号决定 ## GetAllDI 获取所有数字输入状态。 **方法签名:** ```python def GetAllDI(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `states` (list): 所有数字输入状态 - 当 `result == 0` 时,返回布尔值列表,每个元素对应一个端口 - 当 `result != 0` 时,返回空列表 **示例:** ```python result, states = robot.GetAllDI() if result == 0: for i, state in enumerate(states): status = "高电平" if state else "低电平" print(f"数字输入{i+1}: {status}") else: print("获取所有数字输入状态失败") ``` **注意事项:** - 返回列表长度取决于机器人数字输入端口数量 - 可用于同时监控多个输入信号 ## GetAO 获取模拟输出值。 **方法签名:** ```python def GetAO(self, index: int) -> (int, float) ``` **参数:** - `index` (int): 模拟输出端口索引 - 范围:`1-4`(具体范围取决于机器人型号) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `value` (float): 模拟输出值 - 范围:`0.0-10.0`(电压值,单位V) - 当 `result != 0` 时,返回 `-1.0` **示例:** ```python result, value = robot.GetAO(1) if result == 0: print(f"模拟输出1电压: {value}V") else: print("获取模拟输出值失败") ``` **注意事项:** - 端口索引从1开始 - 输出电压范围通常为0-10V ## SetAO 设置模拟输出值。 **方法签名:** ```python def SetAO(self, index: int, value: float) -> int ``` **参数:** - `index` (int): 模拟输出端口索引 - 范围:`1-4`(具体范围取决于机器人型号) - `value` (float): 目标输出值 - 范围:`0.0-10.0`(电压值,单位V) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置模拟输出1为5V result = robot.SetAO(1, 5.0) if result == 0: print("模拟输出1设置为5V") else: print("设置模拟输出失败") # 设置模拟输出2为3.3V result = robot.SetAO(2, 3.3) if result == 0: print("模拟输出2设置为3.3V") else: print("设置模拟输出失败") ``` **注意事项:** - 端口索引从1开始 - 确保输出值在有效范围内 - 确保连接的设备能承受设置的电压 ## GetAI 获取模拟输入值。 **方法签名:** ```python def GetAI(self, index: int) -> (int, float) ``` **参数:** - `index` (int): 模拟输入端口索引 - 范围:`1-2`(具体范围取决于机器人型号) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `value` (float): 模拟输入值 - 范围:`0.0-10.0`(电压值,单位V) - 当 `result != 0` 时,返回 `-1.0` **示例:** ```python result, value = robot.GetAI(1) if result == 0: print(f"模拟输入1电压: {value}V") else: print("获取模拟输入值失败") ``` **注意事项:** - 端口索引从1开始 - 输入电压由外部信号决定 ## SetToolPower 设置工具端电源。 **方法签名:** ```python def SetToolPower(self, voltage: int) -> int ``` **参数:** - `voltage` (int): 电源电压 - `0`: 关闭工具端电源 - `12`: 12V电源 - `24`: 24V电源 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置工具端电源为24V result = robot.SetToolPower(24) if result == 0: print("工具端电源设置为24V") else: print("设置工具端电源失败") # 关闭工具端电源 result = robot.SetToolPower(0) if result == 0: print("工具端电源已关闭") else: print("关闭工具端电源失败") ``` **注意事项:** - 确保连接的工具能承受设置的电压 - 电源设置会影响连接在工具端的所有设备 ## GetToolPower 获取工具端电源设置。 **方法签名:** ```python def GetToolPower(self) -> (int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `voltage` (int): 当前电源电压 - `0`: 电源关闭 - `12`: 12V电源 - `24`: 24V电源 - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, voltage = robot.GetToolPower() if result == 0: if voltage == 0: print("工具端电源已关闭") else: print(f"工具端电源设置为{voltage}V") else: print("获取工具端电源设置失败") ``` **注意事项:** - 用于确认当前电源设置状态 - 在更换工具前建议检查电源设置 ## 使用示例 以下是一个完整的IO控制示例: ```python from RVMPython import * import time # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接机器人 if robot.Connect() == 0: print("机器人连接成功") # 设置工具端电源为24V result = robot.SetToolPower(24) if result == 0: print("工具端电源设置为24V") # 数字输出控制示例 print("数字输出控制测试...") for i in range(1, 5): # 测试DO1-DO4 # 设置为高电平 result = robot.SetDO(i, True) if result == 0: print(f"DO{i} 设置为高电平") time.sleep(1) # 验证状态 result, state = robot.GetDO(i) if result == 0: print(f"DO{i} 当前状态: {'高电平' if state else '低电平'}") # 设置为低电平 result = robot.SetDO(i, False) if result == 0: print(f"DO{i} 设置为低电平") # 数字输入状态监控 print("\n数字输入状态监控...") result, di_states = robot.GetAllDI() if result == 0: for i, state in enumerate(di_states): status = "高电平" if state else "低电平" print(f"DI{i+1}: {status}") # 模拟输出控制示例 print("\n模拟输出控制测试...") for voltage in [0.0, 2.5, 5.0, 7.5, 10.0]: result = robot.SetAO(1, voltage) if result == 0: print(f"AO1 设置为 {voltage}V") time.sleep(1) # 验证输出值 result, actual_voltage = robot.GetAO(1) if result == 0: print(f"AO1 实际输出: {actual_voltage}V") # 模拟输入读取 print("\n模拟输入读取...") result, ai_value = robot.GetAI(1) if result == 0: print(f"AI1 当前电压: {ai_value}V") # 关闭工具端电源 result = robot.SetToolPower(0) if result == 0: print("工具端电源已关闭") # 断开连接 robot.DisConnect() else: print("机器人连接失败") ``` **最佳实践:** 1. **电源管理**: 在使用IO前正确设置工具端电源 2. **状态验证**: 设置输出后验证实际状态 3. **定期监控**: 对关键输入信号进行定期监控 4. **安全考虑**: 在设置输出前确认连接设备的电压要求 5. **错误处理**: 对所有IO操作进行错误处理 6. **资源清理**: 程序结束前关闭不必要的输出 **应用场景:** - 控制外部设备(气动夹爪、传送带等) - 读取传感器信号(光电开关、压力传感器等) - 工艺过程控制(焊接电源、切割工具等) - 安全互锁信号处理 - 人机交互指示(LED灯、蜂鸣器等) End File# RealManRobot/rvm_python_docs # API/System/System.md # System系统管理 `System` 类提供了系统管理相关的功能,包括系统信息查询、版本获取、状态监控等。 ## GetAPIVersion 获取API版本信息。 **方法签名:** ```python def GetAPIVersion(self) -> str ``` **返回值:** - `version` (str): API版本号 - 格式:`"主版本.次版本.修订版本"` - 例如:`"1.2.3"` **示例:** ```python version = robot.GetAPIVersion() print(f"API版本: {version}") ``` **注意事项:** - 该方法总是返回当前API的版本号 - 用于兼容性检查和调试信息输出 ## GetSystemState 获取系统运行状态。 **方法签名:** ```python def GetSystemState(self) -> (int, dict) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `state` (dict): 系统状态信息 - 当 `result == 0` 时,返回包含系统状态的字典 - 当 `result != 0` 时,返回空字典 **状态字典包含的信息:** ```python { "cpu_usage": float, # CPU使用率 (%) "memory_usage": float, # 内存使用率 (%) "disk_usage": float, # 磁盘使用率 (%) "temperature": float, # 系统温度 (°C) "uptime": int, # 系统运行时间 (秒) "load_average": list, # 系统负载平均值 [1min, 5min, 15min] "network_status": bool, # 网络连接状态 "safety_status": bool # 安全系统状态 } ``` **示例:** ```python result, state = robot.GetSystemState() if result == 0: print(f"CPU使用率: {state['cpu_usage']:.1f}%") print(f"内存使用率: {state['memory_usage']:.1f}%") print(f"磁盘使用率: {state['disk_usage']:.1f}%") print(f"系统温度: {state['temperature']:.1f}°C") print(f"运行时间: {state['uptime']}秒") print(f"网络状态: {'正常' if state['network_status'] else '异常'}") print(f"安全状态: {'正常' if state['safety_status'] else '异常'}") else: print("获取系统状态失败") ``` **注意事项:** - 系统状态实时更新 - 用于系统监控和故障诊断 - 某些参数可能因系统配置而异 ## GetControllerVersion 获取控制器版本信息。 **方法签名:** ```python def GetControllerVersion(self) -> (int, dict) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `version_info` (dict): 版本信息字典 - 当 `result == 0` 时,返回包含版本信息的字典 - 当 `result != 0` 时,返回空字典 **版本信息字典包含:** ```python { "controller_version": str, # 控制器软件版本 "firmware_version": str, # 固件版本 "kernel_version": str, # 内核版本 "build_date": str, # 编译日期 "build_time": str, # 编译时间 "git_commit": str # Git提交号 } ``` **示例:** ```python result, version_info = robot.GetControllerVersion() if result == 0: print(f"控制器版本: {version_info['controller_version']}") print(f"固件版本: {version_info['firmware_version']}") print(f"内核版本: {version_info['kernel_version']}") print(f"编译日期: {version_info['build_date']}") print(f"编译时间: {version_info['build_time']}") print(f"Git提交: {version_info['git_commit']}") else: print("获取控制器版本失败") ``` **注意事项:** - 版本信息用于技术支持和兼容性检查 - 不同控制器型号返回的信息可能略有差异 ## GetRobotInfo 获取机器人基本信息。 **方法签名:** ```python def GetRobotInfo(self) -> (int, dict) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `robot_info` (dict): 机器人信息字典 - 当 `result == 0` 时,返回包含机器人信息的字典 - 当 `result != 0` 时,返回空字典 **机器人信息字典包含:** ```python { "robot_model": str, # 机器人型号 "robot_sn": str, # 机器人序列号 "joint_count": int, # 关节数量 "max_payload": float, # 最大负载 (kg) "max_reach": float, # 最大工作半径 (mm) "repeatability": float, # 重复定位精度 (mm) "manufacturer": str, # 制造商 "manufacture_date": str # 生产日期 } ``` **示例:** ```python result, robot_info = robot.GetRobotInfo() if result == 0: print(f"机器人型号: {robot_info['robot_model']}") print(f"序列号: {robot_info['robot_sn']}") print(f"关节数量: {robot_info['joint_count']}") print(f"最大负载: {robot_info['max_payload']}kg") print(f"最大工作半径: {robot_info['max_reach']}mm") print(f"重复定位精度: {robot_info['repeatability']}mm") print(f"制造商: {robot_info['manufacturer']}") print(f"生产日期: {robot_info['manufacture_date']}") else: print("获取机器人信息失败") ``` **注意事项:** - 机器人信息为固定值,通常在出厂时设定 - 用于系统识别和技术规格确认 ## GetSystemTime 获取系统时间。 **方法签名:** ```python def GetSystemTime(self) -> (int, dict) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `time_info` (dict): 时间信息字典 - 当 `result == 0` 时,返回包含时间信息的字典 - 当 `result != 0` 时,返回空字典 **时间信息字典包含:** ```python { "timestamp": int, # Unix时间戳 "year": int, # 年 "month": int, # 月 (1-12) "day": int, # 日 (1-31) "hour": int, # 小时 (0-23) "minute": int, # 分钟 (0-59) "second": int, # 秒 (0-59) "weekday": int, # 星期 (0-6, 0=星期日) "timezone": str # 时区 } ``` **示例:** ```python result, time_info = robot.GetSystemTime() if result == 0: print(f"当前时间: {time_info['year']}-{time_info['month']:02d}-{time_info['day']:02d} " f"{time_info['hour']:02d}:{time_info['minute']:02d}:{time_info['second']:02d}") print(f"时间戳: {time_info['timestamp']}") print(f"时区: {time_info['timezone']}") weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"] print(f"星期: {weekdays[time_info['weekday']]}") else: print("获取系统时间失败") ``` **注意事项:** - 系统时间用于日志记录和时间同步 - 确保系统时间的准确性对于某些应用很重要 ## SetSystemTime 设置系统时间。 **方法签名:** ```python def SetSystemTime(self, time_info: dict) -> int ``` **参数:** - `time_info` (dict): 时间信息字典 - 必需字段:`year`, `month`, `day`, `hour`, `minute`, `second` - 可选字段:`timezone` **参数字典格式:** ```python { "year": int, # 年 (例如: 2024) "month": int, # 月 (1-12) "day": int, # 日 (1-31) "hour": int, # 小时 (0-23) "minute": int, # 分钟 (0-59) "second": int, # 秒 (0-59) "timezone": str # 时区 (可选, 例如: "UTC+8") } ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置系统时间为2024年3月15日 14:30:00 time_setting = { "year": 2024, "month": 3, "day": 15, "hour": 14, "minute": 30, "second": 0, "timezone": "UTC+8" } result = robot.SetSystemTime(time_setting) if result == 0: print("系统时间设置成功") else: print("系统时间设置失败") ``` **注意事项:** - 需要管理员权限才能设置系统时间 - 时间设置后可能影响正在运行的程序 - 建议在系统初始化时设置时间 ## RestartSystem 重启系统。 **方法签名:** ```python def RestartSystem(self) -> int ``` **返回值:** - `result` (int): 执行结果 - `0`: 重启指令发送成功 - 其他值: 失败 **示例:** ```python result = robot.RestartSystem() if result == 0: print("系统重启指令已发送") else: print("系统重启失败") ``` **注意事项:** - 重启会中断当前所有操作 - 重启后需要重新连接 - 仅在必要时使用 ## ShutdownSystem 关闭系统。 **方法签名:** ```python def ShutdownSystem(self) -> int ``` **返回值:** - `result` (int): 执行结果 - `0`: 关闭指令发送成功 - 其他值: 失败 **示例:** ```python result = robot.ShutdownSystem() if result == 0: print("系统关闭指令已发送") else: print("系统关闭失败") ``` **注意事项:** - 关闭会停止所有系统服务 - 关闭后需要手动重新启动系统 - 确保所有工作已保存 ## GetLogLevel 获取日志级别。 **方法签名:** ```python def GetLogLevel(self) -> (int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `log_level` (int): 当前日志级别 - 当 `result == 0` 时: - `0`: DEBUG - `1`: INFO - `2`: WARNING - `3`: ERROR - `4`: CRITICAL - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, log_level = robot.GetLogLevel() if result == 0: levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] print(f"当前日志级别: {levels[log_level]}") else: print("获取日志级别失败") ``` ## SetLogLevel 设置日志级别。 **方法签名:** ```python def SetLogLevel(self, log_level: int) -> int ``` **参数:** - `log_level` (int): 日志级别 - `0`: DEBUG - 最详细的日志信息 - `1`: INFO - 一般信息 - `2`: WARNING - 警告信息 - `3`: ERROR - 错误信息 - `4`: CRITICAL - 严重错误信息 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置日志级别为INFO result = robot.SetLogLevel(1) if result == 0: print("日志级别已设置为INFO") else: print("设置日志级别失败") ``` **注意事项:** - 较低级别的日志会包含更多信息,但也会产生更多日志 - 生产环境建议使用WARNING或更高级别 - DEBUG级别仅用于开发调试 ## 使用示例 以下是一个完整的系统管理示例: ```python from RVMPython import * import time # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接机器人 if robot.Connect() == 0: print("机器人连接成功") # 获取API版本 api_version = robot.GetAPIVersion() print(f"API版本: {api_version}") # 获取机器人基本信息 result, robot_info = robot.GetRobotInfo() if result == 0: print(f"机器人型号: {robot_info['robot_model']}") print(f"序列号: {robot_info['robot_sn']}") print(f"最大负载: {robot_info['max_payload']}kg") # 获取控制器版本 result, version_info = robot.GetControllerVersion() if result == 0: print(f"控制器版本: {version_info['controller_version']}") print(f"固件版本: {version_info['firmware_version']}") # 获取系统状态 result, state = robot.GetSystemState() if result == 0: print(f"CPU使用率: {state['cpu_usage']:.1f}%") print(f"内存使用率: {state['memory_usage']:.1f}%") print(f"系统温度: {state['temperature']:.1f}°C") # 获取系统时间 result, time_info = robot.GetSystemTime() if result == 0: print(f"系统时间: {time_info['year']}-{time_info['month']:02d}-{time_info['day']:02d} " f"{time_info['hour']:02d}:{time_info['minute']:02d}:{time_info['second']:02d}") # 获取日志级别 result, log_level = robot.GetLogLevel() if result == 0: levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] print(f"当前日志级别: {levels[log_level]}") # 设置日志级别为INFO result = robot.SetLogLevel(1) if result == 0: print("日志级别已设置为INFO") # 断开连接 robot.DisConnect() else: print("机器人连接失败") ``` **最佳实践:** 1. **定期监控**: 定期获取系统状态进行健康检查 2. **版本管理**: 记录和管理各组件的版本信息 3. **时间同步**: 确保系统时间的准确性 4. **日志管理**: 根据需要设置合适的日志级别 5. **安全操作**: 谨慎使用系统重启和关闭功能 6. **错误处理**: 对所有系统操作进行错误处理 **应用场景:** - 系统健康监控 - 版本兼容性检查 - 系统维护和调试 - 故障诊断和分析 - 远程系统管理 - 系统性能优化 End File# RealManRobot/rvm_python_docs # StateMachine状态机 `StateMachine` 类提供了机器人状态机管理的相关功能,包括状态查询、状态切换、错误处理等。 ## GetCurrentState 获取机器人当前运行状态。 **方法签名:** ```python def GetCurrentState(self) -> (int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `state` (int): 当前运行状态 - 当 `result == 0` 时: - `0`: 停止状态 - `1`: 运行状态 - `2`: 暂停状态 - `3`: 急停状态 - `4`: 错误状态 - `5`: 初始化状态 - `6`: 示教状态 - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, state = robot.GetCurrentState() if result == 0: states = { 0: "停止状态", 1: "运行状态", 2: "暂停状态", 3: "急停状态", 4: "错误状态", 5: "初始化状态", 6: "示教状态" } print(f"机器人当前状态: {states.get(state, '未知状态')}") else: print("获取机器人状态失败") ``` **注意事项:** - 状态信息实时更新 - 不同状态下机器人的可用操作不同 ## GetRobotModeState 获取机器人模式状态。 **方法签名:** ```python def GetRobotModeState(self) -> (int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `mode` (int): 机器人模式 - 当 `result == 0` 时: - `0`: 手动模式 - `1`: 自动模式 - `2`: 远程模式 - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, mode = robot.GetRobotModeState() if result == 0: modes = { 0: "手动模式", 1: "自动模式", 2: "远程模式" } print(f"机器人模式: {modes.get(mode, '未知模式')}") else: print("获取机器人模式失败") ``` **注意事项:** - 不同模式下机器人的操作权限不同 - 远程模式用于外部程序控制 ## SetRobotMode 设置机器人运行模式。 **方法签名:** ```python def SetRobotMode(self, mode: int) -> int ``` **参数:** - `mode` (int): 目标运行模式 - `0`: 手动模式 - `1`: 自动模式 - `2`: 远程模式 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置为远程模式以便程序控制 result = robot.SetRobotMode(2) if result == 0: print("机器人已设置为远程模式") else: print("设置机器人模式失败") # 设置为自动模式 result = robot.SetRobotMode(1) if result == 0: print("机器人已设置为自动模式") else: print("设置机器人模式失败") ``` **注意事项:** - 模式切换可能需要一定时间 - 某些模式切换需要特定的前置条件 ## GetErrorCode 获取当前错误代码。 **方法签名:** ```python def GetErrorCode(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `error_codes` (list): 错误代码列表 - 当 `result == 0` 时,返回整数列表,每个元素是一个错误代码 - 当 `result != 0` 时,返回空列表 - 空列表表示无错误 **示例:** ```python result, error_codes = robot.GetErrorCode() if result == 0: if error_codes: print("当前错误代码:") for code in error_codes: print(f" 错误代码: {code}") else: print("无错误") else: print("获取错误代码失败") ``` **注意事项:** - 可能同时存在多个错误 - 错误代码含义需参考机器人手册 ## ClearErrorCode 清除错误代码。 **方法签名:** ```python def ClearErrorCode(self) -> int ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python result = robot.ClearErrorCode() if result == 0: print("错误代码已清除") else: print("清除错误代码失败") ``` **注意事项:** - 清除错误后机器人可能需要重新初始化 - 某些错误可能需要物理解决后才能清除 ## GetPowerState 获取机器人电源状态。 **方法签名:** ```python def GetPowerState(self) -> (int, bool) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `power_on` (bool): 电源状态 - 当 `result == 0` 时: - `True`: 电源已开启 - `False`: 电源已关闭 - 当 `result != 0` 时,返回 `False` **示例:** ```python result, power_on = robot.GetPowerState() if result == 0: status = "已开启" if power_on else "已关闭" print(f"机器人电源状态: {status}") else: print("获取电源状态失败") ``` **注意事项:** - 电源关闭时机器人无法执行运动操作 - 电源状态影响机器人的所有功能 ## SetPowerState 设置机器人电源状态。 **方法签名:** ```python def SetPowerState(self, power_on: bool) -> int ``` **参数:** - `power_on` (bool): 目标电源状态 - `True`: 开启电源 - `False`: 关闭电源 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 开启电源 result = robot.SetPowerState(True) if result == 0: print("机器人电源已开启") else: print("开启电源失败") # 关闭电源 result = robot.SetPowerState(False) if result == 0: print("机器人电源已关闭") else: print("关闭电源失败") ``` **注意事项:** - 开启电源可能需要等待初始化完成 - 关闭电源会中断所有运动 ## GetEmergencyStopState 获取急停状态。 **方法签名:** ```python def GetEmergencyStopState(self) -> (int, bool) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `emergency_stop` (bool): 急停状态 - 当 `result == 0` 时: - `True`: 急停激活 - `False`: 急停未激活 - 当 `result != 0` 时,返回 `False` **示例:** ```python result, emergency_stop = robot.GetEmergencyStopState() if result == 0: status = "激活" if emergency_stop else "未激活" print(f"急停状态: {status}") else: print("获取急停状态失败") ``` **注意事项:** - 急停激活时机器人无法执行任何运动 - 需要手动解除急停后才能恢复操作 ## GetSafetyState 获取安全系统状态。 **方法签名:** ```python def GetSafetyState(self) -> (int, dict) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `safety_state` (dict): 安全状态信息 - 当 `result == 0` 时,返回包含安全状态的字典 - 当 `result != 0` 时,返回空字典 **安全状态字典包含:** ```python { "safety_mode": int, # 安全模式 (0: 正常, 1: 缩减, 2: 防护停止, 3: 安全停止) "safety_io_state": bool, # 安全IO状态 "light_curtain_state": bool, # 光栅状态 "door_state": bool, # 安全门状态 "fence_state": bool # 围栏状态 } ``` **示例:** ```python result, safety_state = robot.GetSafetyState() if result == 0: safety_modes = { 0: "正常模式", 1: "缩减模式", 2: "防护停止", 3: "安全停止" } print(f"安全模式: {safety_modes.get(safety_state['safety_mode'], '未知')}") print(f"安全IO状态: {'正常' if safety_state['safety_io_state'] else '异常'}") print(f"光栅状态: {'正常' if safety_state['light_curtain_state'] else '异常'}") print(f"安全门状态: {'关闭' if safety_state['door_state'] else '开启'}") print(f"围栏状态: {'正常' if safety_state['fence_state'] else '异常'}") else: print("获取安全状态失败") ``` **注意事项:** - 安全状态影响机器人的运行模式 - 安全异常时需要排除故障才能正常运行 ## IsRobotMoving 检查机器人是否正在运动。 **方法签名:** ```python def IsRobotMoving(self) -> (int, bool) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `is_moving` (bool): 运动状态 - 当 `result == 0` 时: - `True`: 机器人正在运动 - `False`: 机器人静止 - 当 `result != 0` 时,返回 `False` **示例:** ```python result, is_moving = robot.IsRobotMoving() if result == 0: status = "运动中" if is_moving else "静止" print(f"机器人状态: {status}") else: print("获取运动状态失败") ``` **注意事项:** - 用于判断运动是否完成 - 在发送新的运动指令前建议检查运动状态 ## WaitForMotionComplete 等待运动完成。 **方法签名:** ```python def WaitForMotionComplete(self, timeout: float = 30.0) -> int ``` **参数:** - `timeout` (float, optional): 超时时间,默认值 `30.0` - 单位:秒 - 最大等待时间 **返回值:** - `result` (int): 执行结果 - `0`: 运动完成 - `1`: 超时 - 其他值: 失败 **示例:** ```python # 发送运动指令(非阻塞) result = robot.Movel([300, 0, 400, 0, 0, 0], 50, block=False) if result == 0: print("运动指令已发送") # 等待运动完成,最多等待10秒 result = robot.WaitForMotionComplete(10.0) if result == 0: print("运动完成") elif result == 1: print("等待运动完成超时") else: print("等待运动完成失败") ``` **注意事项:** - 仅在非阻塞运动后使用 - 合理设置超时时间避免无限等待 ## GetStateMachineState 获取状态机详细状态。 **方法签名:** ```python def GetStateMachineState(self) -> (int, dict) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `state_info` (dict): 状态机详细信息 - 当 `result == 0` 时,返回包含状态机信息的字典 - 当 `result != 0` 时,返回空字典 **状态机信息字典包含:** ```python { "main_state": int, # 主状态 "sub_state": int, # 子状态 "mode_state": int, # 模式状态 "power_state": bool, # 电源状态 "emergency_stop": bool, # 急停状态 "error_codes": list, # 错误代码列表 "safety_state": dict, # 安全状态 "motion_state": bool # 运动状态 } ``` **示例:** ```python result, state_info = robot.GetStateMachineState() if result == 0: print("状态机详细信息:") print(f" 主状态: {state_info['main_state']}") print(f" 子状态: {state_info['sub_state']}") print(f" 模式状态: {state_info['mode_state']}") print(f" 电源状态: {state_info['power_state']}") print(f" 急停状态: {state_info['emergency_stop']}") print(f" 错误代码: {state_info['error_codes']}") print(f" 运动状态: {state_info['motion_state']}") else: print("获取状态机状态失败") ``` **注意事项:** - 提供最完整的机器人状态信息 - 适用于系统监控和故障诊断 ## 使用示例 以下是一个完整的状态机管理示例: ```python from RVMPython import * import time # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接机器人 if robot.Connect() == 0: print("机器人连接成功") # 获取详细状态机信息 result, state_info = robot.GetStateMachineState() if result == 0: print("初始状态机信息:") print(f" 主状态: {state_info['main_state']}") print(f" 电源状态: {state_info['power_state']}") print(f" 急停状态: {state_info['emergency_stop']}") if state_info['error_codes']: print(f" 错误代码: {state_info['error_codes']}") else: print(" 无错误") # 检查并清除错误 result, error_codes = robot.GetErrorCode() if result == 0 and error_codes: print("发现错误,尝试清除...") result = robot.ClearErrorCode() if result == 0: print("错误已清除") else: print("清除错误失败") # 检查电源状态 result, power_on = robot.GetPowerState() if result == 0: if not power_on: print("电源未开启,正在开启...") result = robot.SetPowerState(True) if result == 0: print("电源开启成功") time.sleep(2) # 等待电源稳定 else: print("电源开启失败") # 设置为远程模式 result = robot.SetRobotMode(2) if result == 0: print("已设置为远程模式") # 执行运动并监控状态 print("执行运动测试...") result = robot.Movel([300, 0, 400, 0, 0, 0], 30, block=False) if result == 0: print("运动指令已发送") # 监控运动状态 while True: result, is_moving = robot.IsRobotMoving() if result == 0: if is_moving: print("机器人运动中...") time.sleep(1) else: print("运动完成") break else: print("获取运动状态失败") break # 最终状态检查 result, current_state = robot.GetCurrentState() if result == 0: states = {0: "停止", 1: "运行", 2: "暂停", 3: "急停", 4: "错误", 5: "初始化", 6: "示教"} print(f"最终状态: {states.get(current_state, '未知')}") # 断开连接 robot.DisConnect() else: print("机器人连接失败") ``` **最佳实践:** 1. **状态检查**: 在执行操作前检查机器人状态 2. **错误处理**: 及时检查和清除错误代码 3. **电源管理**: 确保电源状态正确 4. **模式设置**: 根据应用需求设置合适的运行模式 5. **安全监控**: 持续监控安全状态 6. **运动监控**: 监控运动完成状态 7. **超时处理**: 设置合理的超时时间 **应用场景:** - 系统启动时的状态检查和初始化 - 运动控制前的安全状态确认 - 故障诊断和错误恢复 - 系统监控和状态报告 - 自动化流程中的状态管理 End File# Connection连接管理 `Connection` 类提供了与机器人建立和管理连接的核心功能。 ## Connect 建立与机器人的连接。 **方法签名:** ```python def Connect(self) -> int ``` **返回值:** - `result` (int): 连接结果 - `0`: 连接成功 - 其他值: 连接失败 **示例:** ```python # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接到机器人 result = robot.Connect() if result == 0: print("连接成功") else: print("连接失败") ``` **注意事项:** - 需要确保机器人控制器已启动并在网络中可达 - 连接失败时请检查IP地址和端口号是否正确 - 确保网络防火墙设置允许连接 ## DisConnect 断开与机器人的连接。 **方法签名:** ```python def DisConnect(self) -> int ``` **返回值:** - `result` (int): 断开结果 - `0`: 断开成功 - 其他值: 断开失败 **示例:** ```python # 断开连接 result = robot.DisConnect() if result == 0: print("断开连接成功") else: print("断开连接失败") ``` **注意事项:** - 程序结束前建议主动调用断开连接 - 断开连接后需要重新调用Connect才能继续使用机器人功能 ## IsConnected 检查连接状态。 **方法签名:** ```python def IsConnected(self) -> bool ``` **返回值:** - `connected` (bool): 连接状态 - `True`: 已连接 - `False`: 未连接 **示例:** ```python # 检查连接状态 if robot.IsConnected(): print("机器人已连接") else: print("机器人未连接") ``` **注意事项:** - 该方法用于检查当前连接状态,不进行实际的网络通信 - 在执行机器人操作前建议先检查连接状态 ## GetConnectionInfo 获取连接信息。 **方法签名:** ```python def GetConnectionInfo(self) -> dict ``` **返回值:** - `info` (dict): 连接信息字典,包含以下键值: - `"ip"` (str): 机器人IP地址 - `"port"` (int): 连接端口 - `"connected"` (bool): 连接状态 - `"connect_time"` (str): 连接建立时间 - `"last_heartbeat"` (str): 最后心跳时间 **示例:** ```python # 获取连接信息 info = robot.GetConnectionInfo() print(f"IP地址: {info['ip']}") print(f"端口: {info['port']}") print(f"连接状态: {info['connected']}") print(f"连接时间: {info['connect_time']}") print(f"最后心跳: {info['last_heartbeat']}") ``` **注意事项:** - 连接信息包含了当前连接的详细状态 - 心跳时间用于监控连接的活跃状态 ## SetConnectionTimeout 设置连接超时时间。 **方法签名:** ```python def SetConnectionTimeout(self, timeout: float) -> int ``` **参数:** - `timeout` (float): 超时时间 - 单位:秒 - 范围:`1.0-60.0` - 默认值:`10.0` **返回值:** - `result` (int): 设置结果 - `0`: 设置成功 - 其他值: 设置失败 **示例:** ```python # 设置连接超时时间为15秒 result = robot.SetConnectionTimeout(15.0) if result == 0: print("连接超时时间设置成功") else: print("连接超时时间设置失败") ``` **注意事项:** - 超时时间影响连接建立的等待时间 - 较短的超时时间可以快速检测连接问题,但可能在网络较慢时导致连接失败 - 需要在Connect之前调用才生效 ## GetConnectionTimeout 获取连接超时时间。 **方法签名:** ```python def GetConnectionTimeout(self) -> float ``` **返回值:** - `timeout` (float): 当前连接超时时间(单位:秒) **示例:** ```python # 获取当前连接超时时间 timeout = robot.GetConnectionTimeout() print(f"当前连接超时时间: {timeout}秒") ``` ## Ping 测试与机器人的网络连通性。 **方法签名:** ```python def Ping(self) -> (int, float) ``` **返回值:** - `result` (int): Ping结果 - `0`: Ping成功 - 其他值: Ping失败 - `response_time` (float): 响应时间 - 单位:毫秒 (ms) - 当Ping失败时返回-1.0 **示例:** ```python # 测试网络连通性 result, response_time = robot.Ping() if result == 0: print(f"Ping成功,响应时间: {response_time:.2f}ms") else: print("Ping失败") ``` **注意事项:** - Ping测试可以在连接建立前使用,用于验证网络连通性 - 响应时间可以作为网络质量的参考指标 ## 使用示例 以下是一个完整的连接管理示例: ```python from RVMPython import * import time def main(): # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) try: # 设置连接超时时间 robot.SetConnectionTimeout(15.0) print(f"连接超时时间: {robot.GetConnectionTimeout()}秒") # 测试网络连通性 print("测试网络连通性...") result, response_time = robot.Ping() if result == 0: print(f"网络连通正常,响应时间: {response_time:.2f}ms") else: print("网络连通失败,请检查网络设置") return # 尝试连接 print("正在连接机器人...") result = robot.Connect() if result == 0: print("连接成功") # 获取连接信息 info = robot.GetConnectionInfo() print(f"连接信息:") print(f" IP地址: {info['ip']}") print(f" 端口: {info['port']}") print(f" 连接时间: {info['connect_time']}") # 检查连接状态 if robot.IsConnected(): print("连接状态确认:已连接") # 这里可以执行机器人操作 # ... # 模拟工作一段时间 time.sleep(5) else: print(f"连接失败,错误代码: {result}") except Exception as e: print(f"程序执行错误: {e}") finally: # 确保断开连接 if robot.IsConnected(): result = robot.DisConnect() if result == 0: print("断开连接成功") else: print("断开连接失败") if __name__ == "__main__": main() ``` **最佳实践:** 1. **连接前测试**: 使用Ping方法测试网络连通性 2. **超时设置**: 根据网络环境设置合适的连接超时时间 3. **状态检查**: 在执行操作前检查连接状态 4. **异常处理**: 使用try-except处理连接异常 5. **资源清理**: 程序结束时确保断开连接 6. **重连机制**: 在连接失败时实现重连逻辑 **常见问题:** - **连接超时**: 检查网络连接和机器人控制器状态 - **连接被拒绝**: 检查端口号是否正确,控制器是否已启动 - **网络不可达**: 检查IP地址设置和网络配置 - **频繁断连**: 检查网络稳定性和心跳设置 End File# Coordinate坐标系设置 `Coordinate` 类提供了机器人坐标系设置和管理的相关功能,包括工具坐标系和工作坐标系的设置。 ## SetToolFrame 设置工具坐标系。 **方法签名:** ```python def SetToolFrame(self, frame: list) -> int ``` **参数:** - `frame` (list): 工具坐标系参数 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 工具中心点位置偏移 (单位:mm) - RX、RY、RZ: 工具姿态偏移 (单位:°) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置工具坐标系,工具长度100mm,无旋转偏移 tool_frame = [0, 0, 100, 0, 0, 0] result = robot.SetToolFrame(tool_frame) if result == 0: print("工具坐标系设置成功") else: print("工具坐标系设置失败") ``` **注意事项:** - 工具坐标系定义了工具中心点相对于机器人末端法兰的位置和姿态 - 正确设置工具坐标系对于精确控制至关重要 - 设置后影响所有基于工具坐标系的运动 ## GetToolFrame 获取当前工具坐标系。 **方法签名:** ```python def GetToolFrame(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `frame` (list): 当前工具坐标系参数 - 当 `result == 0` 时,返回工具坐标系参数列表 - 格式:`[X, Y, Z, RX, RY, RZ]` - 当 `result != 0` 时,返回空列表 **示例:** ```python result, tool_frame = robot.GetToolFrame() if result == 0: print(f"当前工具坐标系: X={tool_frame[0]}, Y={tool_frame[1]}, Z={tool_frame[2]}") print(f"工具姿态: RX={tool_frame[3]}, RY={tool_frame[4]}, RZ={tool_frame[5]}") else: print("获取工具坐标系失败") ``` **注意事项:** - 用于确认当前工具坐标系设置 - 在程序开始时建议检查工具坐标系设置 ## SetWorkFrame 设置工作坐标系。 **方法签名:** ```python def SetWorkFrame(self, frame: list) -> int ``` **参数:** - `frame` (list): 工作坐标系参数 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 工作坐标系原点位置 (单位:mm) - RX、RY、RZ: 工作坐标系旋转角度 (单位:°) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置工作坐标系,原点偏移(100, 50, 0),绕Z轴旋转45度 work_frame = [100, 50, 0, 0, 0, 45] result = robot.SetWorkFrame(work_frame) if result == 0: print("工作坐标系设置成功") else: print("工作坐标系设置失败") ``` **注意事项:** - 工作坐标系定义了用户自定义的坐标参考系 - 便于在特定工件或工装上进行编程 - 设置后所有位置数据都相对于工作坐标系 ## GetWorkFrame 获取当前工作坐标系。 **方法签名:** ```python def GetWorkFrame(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `frame` (list): 当前工作坐标系参数 - 当 `result == 0` 时,返回工作坐标系参数列表 - 格式:`[X, Y, Z, RX, RY, RZ]` - 当 `result != 0` 时,返回空列表 **示例:** ```python result, work_frame = robot.GetWorkFrame() if result == 0: print(f"当前工作坐标系: X={work_frame[0]}, Y={work_frame[1]}, Z={work_frame[2]}") print(f"坐标系姿态: RX={work_frame[3]}, RY={work_frame[4]}, RZ={work_frame[5]}") else: print("获取工作坐标系失败") ``` **注意事项:** - 用于确认当前工作坐标系设置 - 在切换不同工件时需要检查工作坐标系 ## SetBaseFrame 设置基坐标系。 **方法签名:** ```python def SetBaseFrame(self, frame: list) -> int ``` **参数:** - `frame` (list): 基坐标系参数 - 格式:`[X, Y, Z, RX, RY, RZ]` - X、Y、Z: 基坐标系原点位置 (单位:mm) - RX、RY、RZ: 基坐标系旋转角度 (单位:°) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置基坐标系 base_frame = [0, 0, 0, 0, 0, 0] # 通常为机器人安装位置 result = robot.SetBaseFrame(base_frame) if result == 0: print("基坐标系设置成功") else: print("基坐标系设置失败") ``` **注意事项:** - 基坐标系通常定义机器人的安装位置 - 一般情况下不需要频繁修改 - 设置错误可能导致运动偏差 ## GetBaseFrame 获取当前基坐标系。 **方法签名:** ```python def GetBaseFrame(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `frame` (list): 当前基坐标系参数 - 当 `result == 0` 时,返回基坐标系参数列表 - 格式:`[X, Y, Z, RX, RY, RZ]` - 当 `result != 0` 时,返回空列表 **示例:** ```python result, base_frame = robot.GetBaseFrame() if result == 0: print(f"当前基坐标系: X={base_frame[0]}, Y={base_frame[1]}, Z={base_frame[2]}") print(f"基坐标系姿态: RX={base_frame[3]}, RY={base_frame[4]}, RZ={base_frame[5]}") else: print("获取基坐标系失败") ``` ## CalibrateToolFrame 工具坐标系标定。 **方法签名:** ```python def CalibrateToolFrame(self, points: list) -> (int, list) ``` **参数:** - `points` (list): 标定点列表 - 每个标定点为一个位姿列表:`[X, Y, Z, RX, RY, RZ]` - 通常需要4-6个不同姿态的标定点 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `tool_frame` (list): 标定得到的工具坐标系 - 当 `result == 0` 时,返回标定结果 - 格式:`[X, Y, Z, RX, RY, RZ]` - 当 `result != 0` 时,返回空列表 **示例:** ```python # 准备标定点(需要实际示教获得) calibration_points = [ [300, 100, 200, 0, 90, 0], [300, 100, 200, 45, 90, 0], [300, 100, 200, 90, 90, 0], [300, 100, 200, 135, 90, 0] ] result, tool_frame = robot.CalibrateToolFrame(calibration_points) if result == 0: print(f"工具坐标系标定成功: {tool_frame}") # 应用标定结果 robot.SetToolFrame(tool_frame) else: print("工具坐标系标定失败") ``` **注意事项:** - 标定前需要安装好工具并固定 - 标定点应该具有不同的姿态以提高精度 - 标定过程中保持工具末端接触同一点 ## CalibrateWorkFrame 工作坐标系标定。 **方法签名:** ```python def CalibrateWorkFrame(self, origin_point: list, x_point: list, xy_plane_point: list) -> (int, list) ``` **参数:** - `origin_point` (list): 原点位姿 - 格式:`[X, Y, Z, RX, RY, RZ]` - 工作坐标系的原点 - `x_point` (list): X轴方向点位姿 - 格式:`[X, Y, Z, RX, RY, RZ]` - 定义X轴正方向的点 - `xy_plane_point` (list): XY平面点位姿 - 格式:`[X, Y, Z, RX, RY, RZ]` - 定义XY平面的第三个点 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `work_frame` (list): 标定得到的工作坐标系 - 当 `result == 0` 时,返回标定结果 - 格式:`[X, Y, Z, RX, RY, RZ]` - 当 `result != 0` 时,返回空列表 **示例:** ```python # 定义工作坐标系标定点(需要实际示教获得) origin = [200, 0, 100, 0, 0, 0] # 原点 x_axis = [300, 0, 100, 0, 0, 0] # X轴正方向点 xy_plane = [200, 100, 100, 0, 0, 0] # XY平面点 result, work_frame = robot.CalibrateWorkFrame(origin, x_axis, xy_plane) if result == 0: print(f"工作坐标系标定成功: {work_frame}") # 应用标定结果 robot.SetWorkFrame(work_frame) else: print("工作坐标系标定失败") ``` **注意事项:** - 三个标定点不能共线 - 标定点应该准确对应工件的特征位置 - 标定顺序影响坐标系的方向 ## 使用示例 以下是一个完整的坐标系设置示例: ```python from RVMPython import * # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接机器人 if robot.Connect() == 0: print("机器人连接成功") # 获取当前坐标系设置 result, base_frame = robot.GetBaseFrame() if result == 0: print(f"当前基坐标系: {base_frame}") result, tool_frame = robot.GetToolFrame() if result == 0: print(f"当前工具坐标系: {tool_frame}") result, work_frame = robot.GetWorkFrame() if result == 0: print(f"当前工作坐标系: {work_frame}") # 设置新的工具坐标系(例如:抓手长度150mm) new_tool_frame = [0, 0, 150, 0, 0, 0] result = robot.SetToolFrame(new_tool_frame) if result == 0: print("工具坐标系设置成功") # 验证设置 result, current_tool = robot.GetToolFrame() if result == 0: print(f"验证工具坐标系: {current_tool}") # 设置工作坐标系(相对基坐标系偏移) new_work_frame = [100, 100, 0, 0, 0, 30] # 偏移+旋转30度 result = robot.SetWorkFrame(new_work_frame) if result == 0: print("工作坐标系设置成功") # 验证设置 result, current_work = robot.GetWorkFrame() if result == 0: print(f"验证工作坐标系: {current_work}") # 在新坐标系下测试运动 print("在工作坐标系下执行运动...") # 这里的坐标是相对于工作坐标系的 target_pose = [50, 0, 100, 0, 0, 0] result = robot.Movel(target_pose, 50) if result == 0: print("运动完成") # 断开连接 robot.DisConnect() else: print("机器人连接失败") ``` **最佳实践:** 1. **坐标系确认**: 在程序开始时确认所有坐标系设置 2. **标定精度**: 使用标定功能获得更准确的坐标系 3. **参数备份**: 保存重要的坐标系参数以便恢复 4. **测试验证**: 设置坐标系后进行简单运动测试 5. **文档记录**: 记录不同工件对应的坐标系参数 6. **安全考虑**: 更改坐标系后注意运动安全 **应用场景:** - 多工件加工时的坐标系切换 - 工具更换后的坐标系重新设置 - 机器人重新安装后的基坐标系校准 - 复杂工装的工作坐标系标定 End File# RealManRobot/rvm_python_docs # API/Config/Speed配置.md # Speed速度配置 `Speed` 类提供了机器人运动速度参数的配置功能,包括关节速度、直线速度、加减速时间等参数的设置。 ## SetJointMaxSpeed 设置关节最大速度。 **方法签名:** ```python def SetJointMaxSpeed(self, speeds: list) -> int ``` **参数:** - `speeds` (list): 各关节最大速度 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°/s) - 每个关节的速度值应在安全范围内 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置各关节最大速度 max_speeds = [180, 180, 180, 360, 360, 360] # 度/秒 result = robot.SetJointMaxSpeed(max_speeds) if result == 0: print("关节最大速度设置成功") else: print("关节最大速度设置失败") ``` **注意事项:** - 速度设置不能超过机器人的物理限制 - 过高的速度可能影响运动精度和安全性 - 不同关节通常有不同的速度限制 ## GetJointMaxSpeed 获取关节最大速度。 **方法签名:** ```python def GetJointMaxSpeed(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `speeds` (list): 各关节最大速度 - 当 `result == 0` 时,返回速度列表 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°/s) - 当 `result != 0` 时,返回空列表 **示例:** ```python result, speeds = robot.GetJointMaxSpeed() if result == 0: for i, speed in enumerate(speeds): print(f"关节{i+1}最大速度: {speed}°/s") else: print("获取关节最大速度失败") ``` ## SetLinearMaxSpeed 设置直线运动最大速度。 **方法签名:** ```python def SetLinearMaxSpeed(self, speed: float) -> int ``` **参数:** - `speed` (float): 直线运动最大速度 - 单位:mm/s - 应在合理的安全范围内 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置直线最大速度为500mm/s result = robot.SetLinearMaxSpeed(500.0) if result == 0: print("直线最大速度设置成功") else: print("直线最大速度设置失败") ``` **注意事项:** - 直线速度影响Movel和Movec等直线运动指令 - 过高的速度可能导致振动或精度下降 - 需要考虑负载和工艺要求 ## GetLinearMaxSpeed 获取直线运动最大速度。 **方法签名:** ```python def GetLinearMaxSpeed(self) -> (int, float) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `speed` (float): 直线运动最大速度 - 当 `result == 0` 时,返回速度值 (单位:mm/s) - 当 `result != 0` 时,返回 `-1.0` **示例:** ```python result, speed = robot.GetLinearMaxSpeed() if result == 0: print(f"直线最大速度: {speed}mm/s") else: print("获取直线最大速度失败") ``` ## SetAngularMaxSpeed 设置角速度最大值。 **方法签名:** ```python def SetAngularMaxSpeed(self, speed: float) -> int ``` **参数:** - `speed` (float): 角速度最大值 - 单位:°/s - 用于直线运动中的姿态变化 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置角速度最大值为100°/s result = robot.SetAngularMaxSpeed(100.0) if result == 0: print("角速度最大值设置成功") else: print("角速度最大值设置失败") ``` **注意事项:** - 角速度影响直线运动中的姿态变化速度 - 合理设置可以获得更平滑的运动轨迹 ## GetAngularMaxSpeed 获取角速度最大值。 **方法签名:** ```python def GetAngularMaxSpeed(self) -> (int, float) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `speed` (float): 角速度最大值 - 当 `result == 0` 时,返回速度值 (单位:°/s) - 当 `result != 0` 时,返回 `-1.0` **示例:** ```python result, speed = robot.GetAngularMaxSpeed() if result == 0: print(f"角速度最大值: {speed}°/s") else: print("获取角速度最大值失败") ``` ## SetAccelerationTime 设置加速时间。 **方法签名:** ```python def SetAccelerationTime(self, time: float) -> int ``` **参数:** - `time` (float): 加速时间 - 单位:秒 - 范围通常为 `0.1-10.0` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置加速时间为2秒 result = robot.SetAccelerationTime(2.0) if result == 0: print("加速时间设置成功") else: print("加速时间设置失败") ``` **注意事项:** - 加速时间影响运动的平滑性 - 较长的加速时间产生更平滑的运动但会延长运动时间 - 需要根据负载和精度要求调整 ## GetAccelerationTime 获取加速时间。 **方法签名:** ```python def GetAccelerationTime(self) -> (int, float) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `time` (float): 加速时间 - 当 `result == 0` 时,返回时间值 (单位:秒) - 当 `result != 0` 时,返回 `-1.0` **示例:** ```python result, time = robot.GetAccelerationTime() if result == 0: print(f"加速时间: {time}秒") else: print("获取加速时间失败") ``` ## SetDecelerationTime 设置减速时间。 **方法签名:** ```python def SetDecelerationTime(self, time: float) -> int ``` **参数:** - `time` (float): 减速时间 - 单位:秒 - 范围通常为 `0.1-10.0` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置减速时间为1.5秒 result = robot.SetDecelerationTime(1.5) if result == 0: print("减速时间设置成功") else: print("减速时间设置失败") ``` **注意事项:** - 减速时间影响运动停止的平滑性 - 合理的减速时间可以减少冲击和振动 ## GetDecelerationTime 获取减速时间。 **方法签名:** ```python def GetDecelerationTime(self) -> (int, float) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `time` (float): 减速时间 - 当 `result == 0` 时,返回时间值 (单位:秒) - 当 `result != 0` 时,返回 `-1.0` **示例:** ```python result, time = robot.GetDecelerationTime() if result == 0: print(f"减速时间: {time}秒") else: print("获取减速时间失败") ``` ## SetJointAcceleration 设置关节加速度。 **方法签名:** ```python def SetJointAcceleration(self, accelerations: list) -> int ``` **参数:** - `accelerations` (list): 各关节加速度 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°/s²) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置各关节加速度 joint_accels = [360, 360, 360, 720, 720, 720] # 度/秒² result = robot.SetJointAcceleration(joint_accels) if result == 0: print("关节加速度设置成功") else: print("关节加速度设置失败") ``` **注意事项:** - 加速度设置影响关节运动的动态性能 - 过高的加速度可能产生振动或超调 ## GetJointAcceleration 获取关节加速度。 **方法签名:** ```python def GetJointAcceleration(self) -> (int, list) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `accelerations` (list): 各关节加速度 - 当 `result == 0` 时,返回加速度列表 - 格式:`[J1, J2, J3, J4, J5, J6]` (单位:°/s²) - 当 `result != 0` 时,返回空列表 **示例:** ```python result, accelerations = robot.GetJointAcceleration() if result == 0: for i, accel in enumerate(accelerations): print(f"关节{i+1}加速度: {accel}°/s²") else: print("获取关节加速度失败") ``` ## SetLinearAcceleration 设置直线加速度。 **方法签名:** ```python def SetLinearAcceleration(self, acceleration: float) -> int ``` **参数:** - `acceleration` (float): 直线加速度 - 单位:mm/s² **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置直线加速度为1000mm/s² result = robot.SetLinearAcceleration(1000.0) if result == 0: print("直线加速度设置成功") else: print("直线加速度设置失败") ``` ## GetLinearAcceleration 获取直线加速度。 **方法签名:** ```python def GetLinearAcceleration(self) -> (int, float) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `acceleration` (float): 直线加速度 - 当 `result == 0` 时,返回加速度值 (单位:mm/s²) - 当 `result != 0` 时,返回 `-1.0` **示例:** ```python result, acceleration = robot.GetLinearAcceleration() if result == 0: print(f"直线加速度: {acceleration}mm/s²") else: print("获取直线加速度失败") ``` ## SetSpeedProfile 设置速度配置文件。 **方法签名:** ```python def SetSpeedProfile(self, profile: dict) -> int ``` **参数:** - `profile` (dict): 速度配置文件 - 包含完整的速度参数设置 **配置文件格式:** ```python { "joint_max_speeds": [180, 180, 180, 360, 360, 360], "linear_max_speed": 500.0, "angular_max_speed": 100.0, "joint_accelerations": [360, 360, 360, 720, 720, 720], "linear_acceleration": 1000.0, "acceleration_time": 2.0, "deceleration_time": 1.5 } ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 定义速度配置文件 speed_profile = { "joint_max_speeds": [120, 120, 120, 240, 240, 240], "linear_max_speed": 300.0, "angular_max_speed": 80.0, "joint_accelerations": [240, 240, 240, 480, 480, 480], "linear_acceleration": 800.0, "acceleration_time": 1.5, "deceleration_time": 1.2 } result = robot.SetSpeedProfile(speed_profile) if result == 0: print("速度配置文件设置成功") else: print("速度配置文件设置失败") ``` ## GetSpeedProfile 获取速度配置文件。 **方法签名:** ```python def GetSpeedProfile(self) -> (int, dict) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `profile` (dict): 当前速度配置文件 - 当 `result == 0` 时,返回配置字典 - 当 `result != 0` 时,返回空字典 **示例:** ```python result, profile = robot.GetSpeedProfile() if result == 0: print("当前速度配置:") print(f" 关节最大速度: {profile['joint_max_speeds']}") print(f" 直线最大速度: {profile['linear_max_speed']}") print(f" 角速度最大值: {profile['angular_max_speed']}") print(f" 加速时间: {profile['acceleration_time']}") print(f" 减速时间: {profile['deceleration_time']}") else: print("获取速度配置文件失败") ``` ## 使用示例 以下是一个完整的速度配置示例: ```python from RVMPython import * # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接机器人 if robot.Connect() == 0: print("机器人连接成功") # 获取当前速度配置 result, current_profile = robot.GetSpeedProfile() if result == 0: print("当前速度配置:") print(f" 关节最大速度: {current_profile['joint_max_speeds']}") print(f" 直线最大速度: {current_profile['linear_max_speed']}") # 设置新的速度参数 print("\n设置新的速度参数...") # 设置关节最大速度 new_joint_speeds = [100, 100, 100, 200, 200, 200] result = robot.SetJointMaxSpeed(new_joint_speeds) if result == 0: print("关节最大速度设置成功") # 设置直线最大速度 result = robot.SetLinearMaxSpeed(250.0) if result == 0: print("直线最大速度设置成功") # 设置加速时间 result = robot.SetAccelerationTime(2.5) if result == 0: print("加速时间设置成功") # 设置减速时间 result = robot.SetDecelerationTime(2.0) if result == 0: print("减速时间设置成功") # 验证设置 print("\n验证设置结果...") result, joint_speeds = robot.GetJointMaxSpeed() if result == 0: print(f"验证关节最大速度: {joint_speeds}") result, linear_speed = robot.GetLinearMaxSpeed() if result == 0: print(f"验证直线最大速度: {linear_speed}") # 使用配置文件方式设置(推荐用于批量设置) print("\n使用配置文件设置速度参数...") speed_config = { "joint_max_speeds": [150, 150, 150, 300, 300, 300], "linear_max_speed": 400.0, "angular_max_speed": 120.0, "joint_accelerations": [300, 300, 300, 600, 600, 600], "linear_acceleration": 1200.0, "acceleration_time": 1.8, "deceleration_time": 1.5 } result = robot.SetSpeedProfile(speed_config) if result == 0: print("速度配置文件设置成功") # 获取完整配置验证 result, final_profile = robot.GetSpeedProfile() if result == 0: print("最终速度配置:") for key, value in final_profile.items(): print(f" {key}: {value}") # 断开连接 robot.DisConnect() else: print("机器人连接失败") ``` **最佳实践:** 1. **渐进调整**: 逐步调整速度参数,避免一次性大幅改变 2. **负载考虑**: 根据机器人负载情况调整速度和加速度 3. **精度权衡**: 在速度和精度之间找到合适的平衡点 4. **安全限制**: 确保所有参数在安全范围内 5. **配置备份**: 保存不同应用场景的速度配置文件 6. **测试验证**: 修改参数后进行充分的运动测试 **应用场景:** - 高速拾放作业的速度优化 - 精密装配作业的低速高精度设置 - 不同工艺阶段的速度切换 - 根据负载变化动态调整速度 - 安全模式下的速度限制设置 End File# Safety安全配置 `Safety` 类提供了机器人安全参数的配置功能,包括安全区域、速度限制、碰撞检测等安全相关设置。 ## SetSafetyZone 设置安全区域。 **方法签名:** ```python def SetSafetyZone(self, zone_id: int, zone_data: dict) -> int ``` **参数:** - `zone_id` (int): 安全区域ID - 范围:`1-8`(具体数量取决于系统配置) - `zone_data` (dict): 安全区域数据 - 定义安全区域的形状、位置和限制 **安全区域数据格式:** ```python { "type": str, # 区域类型: "box", "sphere", "cylinder" "center": list, # 中心点坐标 [X, Y, Z] (mm) "dimensions": list, # 尺寸参数(根据类型不同) "enabled": bool, # 是否启用 "action": int, # 触发动作: 0=警告, 1=减速, 2=停止 "speed_limit": float # 区域内速度限制 (%) } ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置一个立方体安全区域 box_zone = { "type": "box", "center": [300, 0, 400], "dimensions": [200, 200, 200], # 长宽高 (mm) "enabled": True, "action": 1, # 减速 "speed_limit": 50.0 # 区域内最大50%速度 } result = robot.SetSafetyZone(1, box_zone) if result == 0: print("安全区域设置成功") else: print("安全区域设置失败") # 设置一个球形安全区域 sphere_zone = { "type": "sphere", "center": [0, 0, 200], "dimensions": [150], # 半径 (mm) "enabled": True, "action": 2, # 停止 "speed_limit": 0.0 } result = robot.SetSafetyZone(2, sphere_zone) if result == 0: print("球形安全区域设置成功") ``` **注意事项:** - 不同形状的区域需要不同的尺寸参数 - 安全区域重叠时,执行更严格的限制 - 区域设置后立即生效 ## GetSafetyZone 获取安全区域配置。 **方法签名:** ```python def GetSafetyZone(self, zone_id: int) -> (int, dict) ``` **参数:** - `zone_id` (int): 安全区域ID **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `zone_data` (dict): 安全区域数据 - 当 `result == 0` 时,返回区域配置字典 - 当 `result != 0` 时,返回空字典 **示例:** ```python result, zone_data = robot.GetSafetyZone(1) if result == 0: print(f"安全区域1配置:") print(f" 类型: {zone_data['type']}") print(f" 中心: {zone_data['center']}") print(f" 尺寸: {zone_data['dimensions']}") print(f" 启用: {zone_data['enabled']}") print(f" 动作: {zone_data['action']}") print(f" 速度限制: {zone_data['speed_limit']}%") else: print("获取安全区域配置失败") ``` ## DeleteSafetyZone 删除安全区域。 **方法签名:** ```python def DeleteSafetyZone(self, zone_id: int) -> int ``` **参数:** - `zone_id` (int): 要删除的安全区域ID **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python result = robot.DeleteSafetyZone(1) if result == 0: print("安全区域删除成功") else: print("安全区域删除失败") ``` ## SetCollisionSensitivity 设置碰撞检测灵敏度。 **方法签名:** ```python def SetCollisionSensitivity(self, sensitivity: int) -> int ``` **参数:** - `sensitivity` (int): 碰撞检测灵敏度 - 范围:`0-10` - `0`: 最不敏感(关闭碰撞检测) - `10`: 最敏感 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置中等灵敏度 result = robot.SetCollisionSensitivity(5) if result == 0: print("碰撞检测灵敏度设置成功") else: print("碰撞检测灵敏度设置失败") ``` **注意事项:** - 高灵敏度可能导致误报 - 低灵敏度可能错过真正的碰撞 - 需要根据应用场景调整合适的灵敏度 ## GetCollisionSensitivity 获取碰撞检测灵敏度。 **方法签名:** ```python def GetCollisionSensitivity(self) -> (int, int) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `sensitivity` (int): 碰撞检测灵敏度 - 当 `result == 0` 时,返回灵敏度值 - 当 `result != 0` 时,返回 `-1` **示例:** ```python result, sensitivity = robot.GetCollisionSensitivity() if result == 0: print(f"当前碰撞检测灵敏度: {sensitivity}") else: print("获取碰撞检测灵敏度失败") ``` ## SetSafetyLimits 设置安全限制。 **方法签名:** ```python def SetSafetyLimits(self, limits: dict) -> int ``` **参数:** - `limits` (dict): 安全限制参数 **安全限制参数格式:** ```python { "max_speed": float, # 最大速度限制 (%) "max_acceleration": float, # 最大加速度限制 (%) "max_force": float, # 最大力限制 (N) "max_torque": list, # 各关节最大扭矩限制 (Nm) "workspace_limits": dict # 工作空间限制 } ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置安全限制 safety_limits = { "max_speed": 80.0, # 最大80%速度 "max_acceleration": 70.0, # 最大70%加速度 "max_force": 150.0, # 最大150N力 "max_torque": [50, 50, 30, 20, 20, 10], # 各关节扭矩限制 "workspace_limits": { "x_min": -800, "x_max": 800, "y_min": -800, "y_max": 800, "z_min": 0, "z_max": 1000 } } result = robot.SetSafetyLimits(safety_limits) if result == 0: print("安全限制设置成功") else: print("安全限制设置失败") ``` ## GetSafetyLimits 获取安全限制。 **方法签名:** ```python def GetSafetyLimits(self) -> (int, dict) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `limits` (dict): 当前安全限制参数 - 当 `result == 0` 时,返回限制参数字典 - 当 `result != 0` 时,返回空字典 **示例:** ```python result, limits = robot.GetSafetyLimits() if result == 0: print("当前安全限制:") print(f" 最大速度: {limits['max_speed']}%") print(f" 最大加速度: {limits['max_acceleration']}%") print(f" 最大力: {limits['max_force']}N") print(f" 关节扭矩限制: {limits['max_torque']}") else: print("获取安全限制失败") ``` ## EnableSafetyMode 启用或禁用安全模式。 **方法签名:** ```python def EnableSafetyMode(self, enable: bool) -> int ``` **参数:** - `enable` (bool): 是否启用安全模式 - `True`: 启用安全模式 - `False`: 禁用安全模式 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 启用安全模式 result = robot.EnableSafetyMode(True) if result == 0: print("安全模式已启用") else: print("启用安全模式失败") ``` **注意事项:** - 安全模式启用时会应用所有安全限制 - 禁用安全模式可能存在风险,需要谨慎操作 ## GetSafetyModeState 获取安全模式状态。 **方法签名:** ```python def GetSafetyModeState(self) -> (int, bool) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `enabled` (bool): 安全模式状态 - 当 `result == 0` 时: - `True`: 安全模式已启用 - `False`: 安全模式已禁用 - 当 `result != 0` 时,返回 `False` **示例:** ```python result, enabled = robot.GetSafetyModeState() if result == 0: status = "启用" if enabled else "禁用" print(f"安全模式状态: {status}") else: print("获取安全模式状态失败") ``` ## SetEmergencyStopConfig 设置急停配置。 **方法签名:** ```python def SetEmergencyStopConfig(self, config: dict) -> int ``` **参数:** - `config` (dict): 急停配置参数 **急停配置格式:** ```python { "auto_clear": bool, # 是否自动清除急停 "stop_time": float, # 停止时间 (s) "recovery_mode": int, # 恢复模式: 0=手动, 1=自动 "notification": bool # 是否发送通知 } ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python estop_config = { "auto_clear": False, # 不自动清除 "stop_time": 0.1, # 100ms内停止 "recovery_mode": 0, # 手动恢复 "notification": True # 发送通知 } result = robot.SetEmergencyStopConfig(estop_config) if result == 0: print("急停配置设置成功") else: print("急停配置设置失败") ``` ## GetSafetyStatus 获取安全系统状态。 **方法签名:** ```python def GetSafetyStatus(self) -> (int, dict) ``` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `status` (dict): 安全系统状态 - 当 `result == 0` 时,返回状态字典 - 当 `result != 0` 时,返回空字典 **安全状态字典包含:** ```python { "safety_mode_enabled": bool, # 安全模式状态 "collision_detected": bool, # 碰撞检测状态 "emergency_stop": bool, # 急停状态 "safety_zones_active": list, # 激活的安全区域列表 "speed_limited": bool, # 速度限制状态 "force_limited": bool # 力限制状态 } ``` **示例:** ```python result, status = robot.GetSafetyStatus() if result == 0: print("安全系统状态:") print(f" 安全模式: {'启用' if status['safety_mode_enabled'] else '禁用'}") print(f" 碰撞检测: {'是' if status['collision_detected'] else '否'}") print(f" 急停状态: {'激活' if status['emergency_stop'] else '正常'}") print(f" 激活的安全区域: {status['safety_zones_active']}") print(f" 速度受限: {'是' if status['speed_limited'] else '否'}") print(f" 力受限: {'是' if status['force_limited'] else '否'}") else: print("获取安全系统状态失败") ``` ## 使用示例 以下是一个完整的安全配置示例: ```python from RVMPython import * # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接机器人 if robot.Connect() == 0: print("机器人连接成功") # 启用安全模式 result = robot.EnableSafetyMode(True) if result == 0: print("安全模式已启用") # 设置碰撞检测灵敏度 result = robot.SetCollisionSensitivity(6) if result == 0: print("碰撞检测灵敏度设置成功") # 设置安全限制 safety_limits = { "max_speed": 60.0, "max_acceleration": 50.0, "max_force": 100.0, "max_torque": [40, 40, 25, 15, 15, 8], "workspace_limits": { "x_min": -600, "x_max": 600, "y_min": -600, "y_max": 600, "z_min": 50, "z_max": 800 } } result = robot.SetSafetyLimits(safety_limits) if result == 0: print("安全限制设置成功") # 设置安全区域1:禁止进入区域(停止) danger_zone = { "type": "box", "center": [0, -300, 200], "dimensions": [100, 100, 200], "enabled": True, "action": 2, # 停止 "speed_limit": 0.0 } result = robot.SetSafetyZone(1, danger_zone) if result == 0: print("危险区域设置成功") # 设置安全区域2:减速区域 slow_zone = { "type": "sphere", "center": [400, 0, 300], "dimensions": [200], "enabled": True, "action": 1, # 减速 "speed_limit": 30.0 } result = robot.SetSafetyZone(2, slow_zone) if result == 0: print("减速区域设置成功") # 设置急停配置 estop_config = { "auto_clear": False, "stop_time": 0.1, "recovery_mode": 0, "notification": True } result = robot.SetEmergencyStopConfig(estop_config) if result == 0: print("急停配置设置成功") # 获取安全系统状态 result, safety_status = robot.GetSafetyStatus() if result == 0: print("\n当前安全系统状态:") print(f" 安全模式: {'启用' if safety_status['safety_mode_enabled'] else '禁用'}") print(f" 碰撞检测: {'检测到' if safety_status['collision_detected'] else '正常'}") print(f" 急停状态: {'激活' if safety_status['emergency_stop'] else '正常'}") print(f" 激活的安全区域: {safety_status['safety_zones_active']}") # 验证设置 print("\n验证安全配置:") # 检查碰撞检测灵敏度 result, sensitivity = robot.GetCollisionSensitivity() if result == 0: print(f"碰撞检测灵敏度: {sensitivity}") # 检查安全限制 result, limits = robot.GetSafetyLimits() if result == 0: print(f"最大速度限制: {limits['max_speed']}%") print(f"最大力限制: {limits['max_force']}N") # 检查安全区域 for zone_id in [1, 2]: result, zone_data = robot.GetSafetyZone(zone_id) if result == 0: print(f"安全区域{zone_id}: {zone_data['type']}, 中心{zone_data['center']}") # 断开连接 robot.DisConnect() else: print("机器人连接失败") ``` **最佳实践:** 1. **安全优先**: 始终将安全放在首位,宁可保守也不要冒险 2. **分层防护**: 使用多种安全机制形成分层防护 3. **定期检查**: 定期检查安全配置和状态 4. **渐进调试**: 在测试环境中逐步调试安全参数 5. **文档记录**: 详细记录安全配置和变更历史 6. **培训教育**: 确保操作人员了解安全系统 **应用场景:** - 人机协作环境的安全防护 - 危险区域的访问控制 - 设备碰撞保护 - 工艺过程的安全监控 - 紧急情况的快速响应 - 多机器人协同作业的安全管理 End File# RealManRobot/rvm_python_docs # API/Config/Parameters配置.md # Parameters参数配置 `Parameters` 类提供了机器人系统参数的配置功能,包括运动参数、控制参数、系统设置等各类参数的设置和管理。 ## SetParameter 设置单个参数。 **方法签名:** ```python def SetParameter(self, param_name: str, param_value) -> int ``` **参数:** - `param_name` (str): 参数名称 - 参数名称遵循层级结构,用点号分隔 - 例如:`"motion.joint_limits.j1_max"` - `param_value`: 参数值 - 类型可以是 `int`, `float`, `bool`, `str`, `list`, `dict` **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置关节1的最大角度 result = robot.SetParameter("motion.joint_limits.j1_max", 180.0) if result == 0: print("关节限制参数设置成功") else: print("参数设置失败") # 设置系统语言 result = robot.SetParameter("system.language", "chinese") if result == 0: print("语言设置成功") else: print("语言设置失败") # 设置PID参数(列表) pid_gains = [100.0, 0.5, 10.0] result = robot.SetParameter("control.pid_gains.joint1", pid_gains) if result == 0: print("PID参数设置成功") else: print("PID参数设置失败") ``` **注意事项:** - 参数名称区分大小写 - 某些参数修改后可能需要重启系统 - 参数值类型必须与参数定义匹配 ## GetParameter 获取单个参数。 **方法签名:** ```python def GetParameter(self, param_name: str) -> (int, object) ``` **参数:** - `param_name` (str): 参数名称 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `param_value` (object): 参数值 - 当 `result == 0` 时,返回实际参数值 - 当 `result != 0` 时,返回 `None` **示例:** ```python # 获取关节限制参数 result, value = robot.GetParameter("motion.joint_limits.j1_max") if result == 0: print(f"关节1最大角度: {value}°") else: print("获取参数失败") # 获取系统版本 result, version = robot.GetParameter("system.version") if result == 0: print(f"系统版本: {version}") else: print("获取版本失败") # 获取PID参数 result, pid_gains = robot.GetParameter("control.pid_gains.joint1") if result == 0: print(f"PID参数: P={pid_gains[0]}, I={pid_gains[1]}, D={pid_gains[2]}") else: print("获取PID参数失败") ``` ## SetParameterGroup 设置参数组。 **方法签名:** ```python def SetParameterGroup(self, group_name: str, parameters: dict) -> int ``` **参数:** - `group_name` (str): 参数组名称 - `parameters` (dict): 参数字典 - 键为参数名(相对于组的路径) - 值为参数值 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 设置运动参数组 motion_params = { "max_velocity": 100.0, "max_acceleration": 500.0, "max_jerk": 1000.0, "smooth_factor": 0.8 } result = robot.SetParameterGroup("motion.control", motion_params) if result == 0: print("运动参数组设置成功") else: print("运动参数组设置失败") # 设置所有关节的PID参数 pid_params = { "joint1": [120.0, 0.8, 15.0], "joint2": [100.0, 0.6, 12.0], "joint3": [80.0, 0.4, 10.0], "joint4": [60.0, 0.3, 8.0], "joint5": [60.0, 0.3, 8.0], "joint6": [40.0, 0.2, 5.0] } result = robot.SetParameterGroup("control.pid_gains", pid_params) if result == 0: print("PID参数组设置成功") else: print("PID参数组设置失败") ``` ## GetParameterGroup 获取参数组。 **方法签名:** ```python def GetParameterGroup(self, group_name: str) -> (int, dict) ``` **参数:** - `group_name` (str): 参数组名称 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `parameters` (dict): 参数字典 - 当 `result == 0` 时,返回参数组的所有参数 - 当 `result != 0` 时,返回空字典 **示例:** ```python # 获取运动参数组 result, motion_params = robot.GetParameterGroup("motion.control") if result == 0: print("运动参数组:") for param, value in motion_params.items(): print(f" {param}: {value}") else: print("获取运动参数组失败") # 获取所有关节限制 result, joint_limits = robot.GetParameterGroup("motion.joint_limits") if result == 0: print("关节限制参数:") for joint, limit in joint_limits.items(): print(f" {joint}: {limit}") else: print("获取关节限制失败") ``` ## GetParameterList 获取参数列表。 **方法签名:** ```python def GetParameterList(self, group_path: str = "") -> (int, list) ``` **参数:** - `group_path` (str, optional): 参数组路径,默认为空(根目录) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `param_list` (list): 参数名称列表 - 当 `result == 0` 时,返回参数名称列表 - 当 `result != 0` 时,返回空列表 **示例:** ```python # 获取所有参数 result, all_params = robot.GetParameterList() if result == 0: print("所有可用参数:") for param in all_params: print(f" {param}") else: print("获取参数列表失败") # 获取运动相关参数 result, motion_params = robot.GetParameterList("motion") if result == 0: print("运动相关参数:") for param in motion_params: print(f" {param}") else: print("获取运动参数列表失败") ``` ## SaveParametersToFile 保存参数到文件。 **方法签名:** ```python def SaveParametersToFile(self, filename: str, group_name: str = "") -> int ``` **参数:** - `filename` (str): 保存文件名 - `group_name` (str, optional): 参数组名,默认为空(保存所有参数) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 保存所有参数到文件 result = robot.SaveParametersToFile("robot_config_backup.json") if result == 0: print("参数备份成功") else: print("参数备份失败") # 只保存运动参数 result = robot.SaveParametersToFile("motion_params.json", "motion") if result == 0: print("运动参数保存成功") else: print("运动参数保存失败") ``` **注意事项:** - 文件保存在系统指定目录下 - 建议定期备份重要参数配置 ## LoadParametersFromFile 从文件加载参数。 **方法签名:** ```python def LoadParametersFromFile(self, filename: str) -> int ``` **参数:** - `filename` (str): 参数文件名 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 从文件加载参数 result = robot.LoadParametersFromFile("robot_config_backup.json") if result == 0: print("参数加载成功") else: print("参数加载失败") ``` **注意事项:** - 加载参数会覆盖当前设置 - 建议在加载前备份当前参数 - 某些参数可能需要重启后生效 ## ResetParametersToDefault 重置参数为默认值。 **方法签名:** ```python def ResetParametersToDefault(self, group_name: str = "") -> int ``` **参数:** - `group_name` (str, optional): 参数组名,默认为空(重置所有参数) **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 **示例:** ```python # 重置所有参数为默认值 result = robot.ResetParametersToDefault() if result == 0: print("所有参数已重置为默认值") else: print("参数重置失败") # 只重置运动参数 result = robot.ResetParametersToDefault("motion") if result == 0: print("运动参数已重置为默认值") else: print("运动参数重置失败") ``` **注意事项:** - 重置操作不可撤销 - 建议在重置前备份当前参数 ## GetParameterInfo 获取参数信息。 **方法签名:** ```python def GetParameterInfo(self, param_name: str) -> (int, dict) ``` **参数:** - `param_name` (str): 参数名称 **返回值:** - `result` (int): 执行结果 - `0`: 成功 - 其他值: 失败 - `param_info` (dict): 参数信息 - 当 `result == 0` 时,返回参数详细信息 - 当 `result != 0` 时,返回空字典 **参数信息字典包含:** ```python { "name": str, # 参数名称 "type": str, # 参数类型 "description": str, # 参数描述 "default_value": object, # 默认值 "min_value": object, # 最小值(如适用) "max_value": object, # 最大值(如适用) "unit": str, # 单位 "readonly": bool, # 是否只读 "requires_restart": bool # 是否需要重启 } ``` **示例:** ```python # 获取参数详细信息 result, param_info = robot.GetParameterInfo("motion.joint_limits.j1_max") if result == 0: print(f"参数信息:") print(f" 名称: {param_info['name']}") print(f" 类型: {param_info['type']}") print(f" 描述: {param_info['description']}") print(f" 默认值: {param_info['default_value']}") print(f" 范围: {param_info['min_value']} - {param_info['max_value']}") print(f" 单位: {param_info['unit']}") print(f" 只读: {param_info['readonly']}") print(f" 需要重启: {param_info['requires_restart']}") else: print("获取参数信息失败") ``` ## 常用参数列表 以下是一些常用的系统参数: ### 运动参数 - `motion.joint_limits.j1_max`: 关节1最大角度 - `motion.joint_limits.j1_min`: 关节1最小角度 - `motion.max_velocity`: 最大运动速度 - `motion.max_acceleration`: 最大加速度 - `motion.smooth_factor`: 平滑因子 ### 控制参数 - `control.pid_gains.joint1`: 关节1 PID参数 - `control.feedforward_gains`: 前馈增益 - `control.stiffness`: 刚性参数 - `control.damping`: 阻尼参数 ### 安全参数 - `safety.collision_sensitivity`: 碰撞检测灵敏度 - `safety.max_force`: 最大允许力 - `safety.emergency_stop_time`: 急停时间 - `safety.workspace_limits`: 工作空间限制 ### 系统参数 - `system.language`: 系统语言 - `system.units`: 单位制 - `system.log_level`: 日志级别 - `system.auto_save_interval`: 自动保存间隔 ## 使用示例 以下是一个完整的参数配置示例: ```python from RVMPython import * # 创建机器人实例 robot = Manipulator("192.168.1.18", 8899) # 连接机器人 if robot.Connect() == 0: print("机器人连接成功") # 备份当前参数 result = robot.SaveParametersToFile("current_backup.json") if result == 0: print("当前参数已备份") # 获取参数列表 result, param_list = robot.GetParameterList("motion") if result == 0: print("运动参数列表:") for param in param_list[:5]: # 显示前5个 print(f" {param}") # 设置单个参数 result = robot.SetParameter("motion.max_velocity", 80.0) if result == 0: print("最大速度设置成功") # 获取参数验证 result, velocity = robot.GetParameter("motion.max_velocity") if result == 0: print(f"当前最大速度: {velocity}%") # 设置参数组 motion_config = { "max_acceleration": 60.0, "max_jerk": 800.0, "smooth_factor": 0.9 } result = robot.SetParameterGroup("motion", motion_config) if result == 0: print("运动参数组设置成功") # 获取参数组验证 result, current_motion = robot.GetParameterGroup("motion") if result == 0: print("当前运动参数:") for key, value in current_motion.items(): print(f" {key}: {value}") # 设置PID参数 pid_config = { "joint1": [110.0, 0.7, 12.0], "joint2": [95.0, 0.5, 10.0], "joint3": [75.0, 0.4, 8.0] } result = robot.SetParameterGroup("control.pid_gains", pid_config) if result == 0: print("PID参数设置成功") # 获取参数详细信息 result, param_info = robot.GetParameterInfo("motion.max_velocity") if result == 0: print(f"\n参数详细信息:") print(f" 描述: {param_info['description']}") print(f" 范围: {param_info['min_value']} - {param_info['max_value']}") print(f" 单位: {param_info['unit']}") # 保存修改后的参数 result = robot.SaveParametersToFile("custom_config.json") if result == 0: print("自定义参数配置已保存") # 测试参数恢复 print("\n测试参数恢复...") result = robot.LoadParametersFromFile("current_backup.json") if result == 0: print("参数已恢复到备份状态") # 最终验证 result, final_velocity = robot.GetParameter("motion.max_velocity") if result == 0: print(f"恢复后的最大速度: {final_velocity}%") # 断开连接 robot.DisConnect() else: print("机器人连接失败") ``` **最佳实践:** 1. **备份优先**: 修改参数前先备份当前配置 2. **渐进调整**: 小步调整参数,逐步优化 3. **验证测试**: 参数修改后进行充分测试 4. **文档记录**: 记录参数修改的原因和效果 5. **版本管理**: 为不同应用场景保存不同的参数配置 6. **权限控制**: 重要参数的修改需要适当的权限控制 **应用场景:** - 系统初始化和配置 - 性能调优和参数优化 - 不同工艺的参数切换 - 系统维护和故障排除 - 参数备份和恢复 - 批量参数配置管理 End File# API概述 RVMPython API提供了完整的机器人控制和管理功能。API按功能模块进行组织,每个模块包含相关的控制方法。 ## API模块结构 ### 连接管理 (Connection) 负责与机器人建立和管理网络连接。 **主要功能:** - [Connect](Connection/Connection连接管理.md#connect) - 建立连接 - [DisConnect](Connection/Connection连接管理.md#disconnect) - 断开连接 - [IsConnected](Connection/Connection连接管理.md#isconnected) - 检查连接状态 - [GetConnectionInfo](Connection/Connection连接管理.md#getconnectioninfo) - 获取连接信息 - [Ping](Connection/Connection连接管理.md#ping) - 测试网络连通性 ### 系统管理 (System) 提供系统级别的管理和信息查询功能。 **主要功能:** - [GetAPIVersion](System/System.md#getapiversion) - 获取API版本 - [GetSystemState](System/System.md#getsystemstate) - 获取系统状态 - [GetRobotInfo](System/System.md#getrobotinfo) - 获取机器人信息 - [GetSystemTime](System/System.md#getsystemtime) - 获取系统时间 - [RestartSystem](System/System.md#restartsystem) - 重启系统 ### 状态机 (StateMachine) 管理机器人的运行状态和模式切换。 **主要功能:** - [GetCurrentState](System/StateMachine状态机.md#getcurrentstate) - 获取当前状态 - [GetRobotModeState](System/StateMachine状态机.md#getrobotmodestate) - 获取机器人模式 - [SetRobotMode](System/StateMachine状态机.md#setrobotmode) - 设置运行模式 - [GetErrorCode](System/StateMachine状态机.md#geterrorcode) - 获取错误代码 - [ClearErrorCode](System/StateMachine状态机.md#clearerrorcode) - 清除错误 ### 运动控制 (Motion) 提供机器人的各种运动控制功能。 **主要功能:** - [Movej](Control/Motion控制.md#movej) - 关节空间运动 - [Movel](Control/Motion控制.md#movel) - 直线运动 - [Movec](Control/Motion控制.md#movec) - 圆弧运动 - [MoveJog](Control/Motion控制.md#movejog) - 点动控制 - [StopMove](Control/Motion控制.md#stopmove) - 停止运动 ### 姿态控制 (Posture) 处理机器人位姿相关的功能。 **主要功能:** - [GetCurrentPose](Control/Posture控制.md#getcurrentpose) - 获取当前位姿 - [GetCurrentJointAngle](Control/Posture控制.md#getcurrentjointangle) - 获取关节角度 - [GetInverseKin](Control/Posture控制.md#getinversekin) - 逆运动学计算 - [GetForwardKin](Control/Posture控制.md#getforwardkin) - 正运动学计算 - [IsInWorkspace](Control/Posture控制.md#isinworkspace) - 检查工作空间 ### IO控制 (IOControl) 管理机器人的数字和模拟输入输出。 **主要功能:** - [GetDO](Control/IOControl.md#getdo) / [SetDO](Control/IOControl.md#setdo) - 数字输出控制 - [GetDI](Control/IOControl.md#getdi) - 数字输入读取 - [GetAO](Control/IOControl.md#getao) / [SetAO](Control/IOControl.md#setao) - 模拟输出控制 - [GetAI](Control/IOControl.md#getai) - 模拟输入读取 - [SetToolPower](Control/IOControl.md#settoolpower) - 工具端电源控制 ### 夹爪控制 (Gripper) 控制机器人夹爪的操作。 **主要功能:** - [GripperOpen](Control/Gripper控制.md#gripperopen) - 打开夹爪 - [GripperClose](Control/Gripper控制.md#gripperclose) - 关闭夹爪 - [GetGripperState](Control/Gripper控制.md#getgripperstate) - 获取夹爪状态 - [GripperStop](Control/Gripper控制.md#gripperstop) - 停止夹爪 ### 外部轴控制 (Extaxis) 控制机器人的外部轴设备。 **主要功能:** - [MoveExtaxis](Control/Extaxis控制.md#moveextaxis) - 外部轴运动 - [GetExtaxisCurrentPos](Control/Extaxis控制.md#getextaxiscurrentpos) - 获取外部轴位置 - [ExtAxisEnable](Control/Extaxis控制.md#extaxisenable) - 使能外部轴 - [ExtAxisStop](Control/Extaxis控制.md#extaxisstop) - 停止外部轴 ### 坐标系设置 (Coordinate) 管理机器人的各种坐标系。 **主要功能:** - [SetToolFrame](Config/Coordinate坐标系设置.md#settoolframe) / [GetToolFrame](Config/Coordinate坐标系设置.md#gettoolframe) - 工具坐标系 - [SetWorkFrame](Config/Coordinate坐标系设置.md#setworkframe) / [GetWorkFrame](Config/Coordinate坐标系设置.md#getworkframe) - 工作坐标系 - [CalibrateToolFrame](Config/Coordinate坐标系设置.md#calibratetoolframe) - 工具坐标系标定 - [CalibrateWorkFrame](Config/Coordinate坐标系设置.md#calibrateworkframe) - 工作坐标系标定 ### 速度配置 (Speed) 配置机器人的运动速度参数。 **主要功能:** - [SetJointMaxSpeed](Config/Speed配置.md#setjointmaxspeed) / [GetJointMaxSpeed](Config/Speed配置.md#getjointmaxspeed) - 关节最大速度 - [SetLinearMaxSpeed](Config/Speed配置.md#setlinearmaxspeed) / [GetLinearMaxSpeed](Config/Speed配置.md#getlinearmaxspeed) - 直线最大速度 - [SetAccelerationTime](Config/Speed配置.md#setaccelerationtime) / [GetAccelerationTime](Config/Speed配置.md#getaccelerationtime) - 加速时间 - [SetSpeedProfile](Config/Speed配置.md#setspeedprofile) / [GetSpeedProfile](Config/Speed配置.md#getspeedprofile) - 速度配置文件 ### 安全配置 (Safety) 管理机器人的安全功能。 **主要功能:** - [SetSafetyZone](Config/Safety安全配置.md#setsafetyzone) / [GetSafetyZone](Config/Safety安全配置.md#getsafetyzone) - 安全区域 - [SetCollisionSensitivity](Config/Safety安全配置.md#setcollisionsensitivity) - 碰撞检测灵敏度 - [SetSafetyLimits](Config/Safety安全配置.md#setsafetylimits) - 安全限制 - [EnableSafetyMode](Config/Safety安全配置.md#enablesafetymode) - 安全模式 ### 参数配置 (Parameters) 管理系统参数和配置。 **主要功能:** - [SetParameter](Config/Parameters配置.md#setparameter) / [GetParameter](Config/Parameters配置.md#getparameter) - 单个参数设置 - [SetParameterGroup](Config/Parameters配置.md#setparametergroup) / [GetParameterGroup](Config/Parameters配置.md#getparametergroup) - 参数组设置 - [SaveParametersToFile](Config/Parameters配置.md#saveparameterstofile) - 保存参数到文件 - [LoadParametersFromFile](Config/Parameters配置.md#loadparametersfromfile) - 从文件加载参数 ## API使用约定 ### 返回值约定 大多数API方法遵循统一的返回值约定: - 单一返回值:通常为执行结果码(0表示成功) - 多返回值:第一个为结果码,后续为实际数据 ```python # 单返回值示例 result = robot.Connect() if result == 0: print("连接成功") # 多返回值示例 result, pose = robot.GetCurrentPose() if result == 0: print(f"当前位姿: {pose}") ``` ### 参数类型约定 - `list`: 用于坐标、角度数组等 - `dict`: 用于复杂配置参数 - `bool`: 用于开关状态 - `int`/`float`: 用于数值参数 ### 错误处理 建议对所有API调用进行错误检查: ```python result = robot.Movel([300, 0, 400, 0, 0, 0], 50) if result == 0: print("运动指令执行成功") else: print(f"运动指令执行失败,错误码: {result}") ``` ## 快速开始 1. **建立连接** ```python from RVMPython import * robot = Manipulator("192.168.1.18", 8899) result = robot.Connect() ``` 2. **基本运动** ```python if result == 0: # 关节运动 robot.Movej([0, 0, 90, 0, 90, 0], 50) # 直线运动 robot.Movel([300, 0, 400, 0, 0, 0], 50) ``` 3. **状态查询** ```python # 获取当前位姿 result, pose = robot.GetCurrentPose() if result == 0: print(f"当前位姿: {pose}") ``` 4. **断开连接** ```python robot.DisConnect() ``` ## 下一步 选择您需要的功能模块,查看详细的API文档: - [连接管理](Connection/Connection连接管理.md) - 学习如何建立和管理连接 - [运动控制](Control/Motion控制.md) - 学习各种运动控制方法 - [IO控制](Control/IOControl.md) - 学习输入输出控制 - [配置管理](Config/Speed配置.md) - 学习系统参数配置 每个模块都提供了详细的方法说明、参数介绍、示例代码和最佳实践。 End File# RealManRobot/rvm_python_docs # 异常处理 在使用RVMPython时,可能会遇到各种异常情况。良好的异常处理机制可以提高程序的稳定性和可维护性。 ## 异常类型 ### 连接相关异常 **ConnectionError** - 连接异常 ```python from RVMPython import * import time def connect_with_retry(robot, max_retries=3, retry_delay=2): """带重试机制的连接函数""" for attempt in range(max_retries): try: result = robot.Connect() if result == 0: print("连接成功") return True else: print(f"连接失败,错误码: {result}") except ConnectionError as e: print(f"连接异常 (尝试 {attempt + 1}/{max_retries}): {e}") except Exception as e: print(f"未知异常: {e}") if attempt < max_retries - 1: print(f"等待 {retry_delay} 秒后重试...") time.sleep(retry_delay) print("连接失败,已达到最大重试次数") return False # 使用示例 robot = Manipulator("192.168.1.18", 8899) if connect_with_retry(robot): # 执行机器人操作 pass ``` **TimeoutError** - 超时异常 ```python def execute_with_timeout(robot, timeout=30): """带超时处理的运动执行""" try: # 设置连接超时 robot.SetConnectionTimeout(timeout) # 执行运动指令 result = robot.Movel([300, 0, 400, 0, 0, 0], 50, block=True) if result == 0: print("运动完成") else: print(f"运动失败,错误码: {result}") except TimeoutError as e: print(f"运动超时: {e}") robot.StopMove() # 停止运动 except Exception as e: print(f"运动异常: {e}") robot.EmergencyStop() # 紧急停止 ``` ### 运动相关异常 **MotionError** - 运动异常 ```python def safe_motion_execute(robot, motion_func, *args, **kwargs): """安全的运动执行函数""" try: # 检查机器人状态 result, state = robot.GetCurrentState() if result != 0: raise Exception("无法获取机器人状态") if state not in [0, 1]: # 0: 停止, 1: 运行 raise Exception(f"机器人状态异常: {state}") # 检查是否有错误 result, errors = robot.GetErrorCode() if result == 0 and errors: print(f"发现错误代码: {errors}") robot.ClearErrorCode() # 执行运动 result = motion_func(*args, **kwargs) if result != 0: raise Exception(f"运动指令执行失败,错误码: {result}") return True except Exception as e: print(f"运动执行异常: {e}") try: robot.StopMove() except: pass # 忽略停止指令的异常 return False # 使用示例 robot = Manipulator("192.168.1.18", 8899) if robot.Connect() == 0: # 安全执行关节运动 success = safe_motion_execute( robot, robot.Movej, [0, 0, 90, 0, 90, 0], 50 ) if success: print("运动执行成功") else: print("运动执行失败") ``` ### 参数相关异常 **ValueError** - 参数值异常 ```python def validate_pose(pose): """验证位姿参数""" if not isinstance(pose, list) or len(pose) != 6: raise ValueError("位姿参数必须是包含6个元素的列表") # 检查位置范围 (示例范围) x, y, z = pose[:3] if not (-800 <= x <= 800): raise ValueError(f"X坐标超出范围: {x}") if not (-800 <= y <= 800): raise ValueError(f"Y坐标超出范围: {y}") if not (0 <= z <= 1000): raise ValueError(f"Z坐标超出范围: {z}") # 检查姿态范围 rx, ry, rz = pose[3:] if not all(-180 <= angle <= 180 for angle in [rx, ry, rz]): raise ValueError("姿态角度必须在-180到180度之间") def safe_linear_motion(robot, target_pose, speed): """安全的直线运动""" try: # 验证参数 validate_pose(target_pose) if not (1 <= speed <= 100): raise ValueError(f"速度必须在1-100之间: {speed}") # 检查工作空间 result, current_joints = robot.GetCurrentJointAngle() if result == 0: result, in_workspace = robot.IsInWorkspace(target_pose, current_joints) if result == 0 and not in_workspace: raise ValueError("目标位置不在工作空间内") # 执行运动 result = robot.Movel(target_pose, speed) if result != 0: raise Exception(f"运动执行失败: {result}") print("直线运动完成") return True except ValueError as e: print(f"参数错误: {e}") return False except Exception as e: print(f"运动异常: {e}") return False # 使用示例 robot = Manipulator("192.168.1.18", 8899) if robot.Connect() == 0: # 测试有效位姿 valid_pose = [300, 0, 400, 0, 0, 0] safe_linear_motion(robot, valid_pose, 50) # 测试无效位姿 invalid_pose = [2000, 0, 400, 0, 0, 0] # X超出范围 safe_linear_motion(robot, invalid_pose, 50) ``` ## 错误代码处理 ```python class RobotErrorHandler: """机器人错误处理类""" # 常见错误代码定义 ERROR_CODES = { 1001: "关节角度超限", 1002: "位置超出工作空间", 1003: "速度过快", 2001: "通信错误", 2002: "连接断开", 3001: "急停激活", 3002: "安全门开启", 4001: "电机故障", 4002: "编码器故障" } def __init__(self, robot): self.robot = robot def get_error_description(self, error_code): """获取错误描述""" return self.ERROR_CODES.get(error_code, f"未知错误: {error_code}") def handle_errors(self): """处理机器人错误""" try: result, error_codes = self.robot.GetErrorCode() if result != 0: print("无法获取错误代码") return False if not error_codes: return True # 无错误 print("发现以下错误:") for code in error_codes: description = self.get_error_description(code) print(f" 错误 {code}: {description}") # 尝试自动处理某些错误 auto_clear_codes = [1003, 2001] # 可自动清除的错误 if any(code in auto_clear_codes for code in error_codes): print("尝试自动清除错误...") result = self.robot.ClearErrorCode() if result == 0: print("错误清除成功") return True else: print("错误清除失败") # 对于严重错误,需要人工处理 serious_codes = [3001, 3002, 4001, 4002] if any(code in serious_codes for code in error_codes): print("检测到严重错误,需要人工处理") return False return False except Exception as e: print(f"错误处理异常: {e}") return False # 使用示例 robot = Manipulator("192.168.1.18", 8899) error_handler = RobotErrorHandler(robot) if robot.Connect() == 0: # 执行操作前检查错误 if not error_handler.handle_errors(): print("请解决错误后重试") else: print("系统正常,可以执行操作") # 执行机器人操作 ``` ## 异常恢复机制 ```python class RobotController: """带异常恢复的机器人控制器""" def __init__(self, ip, port): self.ip = ip self.port = port self.robot = Manipulator(ip, port) self.connected = False self.error_handler = RobotErrorHandler(self.robot) def connect(self, max_retries=3): """连接机器人""" for attempt in range(max_retries): try: result = self.robot.Connect() if result == 0: self.connected = True print("机器人连接成功") return True else: print(f"连接失败,错误码: {result}") except Exception as e: print(f"连接异常: {e}") if attempt < max_retries - 1: print(f"等待2秒后重试... ({attempt + 1}/{max_retries})") time.sleep(2) print("连接失败") return False def ensure_connection(self): """确保连接有效""" if not self.connected: return self.connect() # 检查连接状态 if not self.robot.IsConnected(): print("连接已断开,尝试重连...") self.connected = False return self.connect() return True def safe_execute(self, func, *args, **kwargs): """安全执行函数""" max_attempts = 2 for attempt in range(max_attempts): try: # 确保连接 if not self.ensure_connection(): return False # 检查并处理错误 if not self.error_handler.handle_errors(): print("错误处理失败") continue # 执行函数 result = func(*args, **kwargs) if result == 0: return True else: print(f"执行失败,错误码: {result}") except Exception as e: print(f"执行异常 (尝试 {attempt + 1}): {e}") # 尝试恢复 try: self.robot.StopMove() self.robot.ClearErrorCode() except: pass if attempt < max_attempts - 1: print("等待1秒后重试...") time.sleep(1) print("执行失败,已达到最大重试次数") return False def move_to_pose(self, pose, speed=50): """安全移动到指定位姿""" return self.safe_execute(self.robot.Movel, pose, speed) def move_joints(self, joint_angles, speed=50): """安全关节运动""" return self.safe_execute(self.robot.Movej, joint_angles, speed) def disconnect(self): """断开连接""" try: if self.connected: self.robot.DisConnect() self.connected = False print("连接已断开") except Exception as e: print(f"断开连接异常: {e}") # 使用示例 controller = RobotController("192.168.1.18", 8899) try: if controller.connect(): # 安全执行运动 success = controller.move_to_pose([300, 0, 400, 0, 0, 0], 50) if success: print("运动完成") success = controller.move_joints([0, 0, 90, 0, 90, 0], 30) if success: print("关节运动完成") finally: controller.disconnect() ``` ## 日志记录 ```python import logging from datetime import datetime class RobotLogger: """机器人操作日志记录器""" def __init__(self, log_file="robot_operations.log"): # 配置日志 logging.basicConfig( |