want to use IK mode to control the RG2 moving above Shape0.
After clicking to start simulating and running Python code,
the UR5 had no move, then there was an error message showed :
[Connectivity >> ZMQ remote API server@addOnScript:error] ?: script execution was terminated externally.
I'm sure it's not the problem of Python API because I successfully ran ikPathGeneration.ttt using Python API.
How can I fix this problem?
Looking forward your help.
This is my scene file, https://drive.google.com/file/d/1qK3tBF ... drive_link
This is my Python code.
Code: Select all
#python
import time
from coppeliasim_zmqremoteapi_client import RemoteAPIClient
import numpy as np
import math
import ctypes
def hopThroughConfigs(path, joints, reverse, dynModel):
lb = sim.setStepping(True)
total_configs = len(path) // 6 # each configuration holds 6 values
if not reverse:
s = 0
g = total_configs
incr = 1
else:
s = total_configs - 1
g = -1
incr = -1
for i in range(s, g, incr):
for j in range(len(joints)):
if dynModel:
sim.setJointTargetPosition(joints[j], path[i*6 + j])
else:
sim.setJointPosition(joints[j], path[i*6 + j])
sim.step()
sim.setStepping(lb)
if __name__ == "__main__":
# Verify and load the DLL
dll_path = "C:\Program Files\CoppeliaRobotics\CoppeliaSimEdu\coppeliaSim.dll"
try:
ctypes.CDLL(dll_path)
print("DLL loaded successfully")
except Exception as e:
print(f"Error loading DLL: {e}")
exit()
# Connect to CoppeliaSim
client = RemoteAPIClient(port=23000)
sim = client.require('sim')
simIK = client.require('simIK')
# 获取对象句柄
simBase = sim.getObject('/UR5')
simTip = sim.getObject('/UR5/tip')
simGoal = sim.getObject('/target')
print(simBase, simTip, simGoal)
# 获取6个关节的句柄
simJoints = []
for i in range(6):
joint_handle = sim.getObject('/UR5/joint', {'index': i})
simJoints.append(joint_handle)
# 跳过第一步仿真以确保命令反映实际情况
sim.step()
# 检查是否为动力学模型
dynModel = sim.isDynamicallyEnabled(simJoints[0])
# 创建IK环境
ikEnv = simIK.createEnvironment()
ikGroup = simIK.createGroup(ikEnv)
# 从场景添加IK元素
ikElement, simToIkMap, ikToSimMap = simIK.addElementFromScene(
ikEnv, ikGroup, simBase, simTip, simGoal, simIK.constraint_pose
)
# 获取IK环境中的对象句柄
ikTip = simToIkMap[simTip]
ikJoints = [simToIkMap[joint] for joint in simJoints]
# 生成路径
path = simIK.generatePath(ikEnv, ikGroup, ikJoints, ikTip, 300)
# 清理IK环境
simIK.eraseEnvironment(ikEnv)
print('Move to target position....')
hopThroughConfigs(path, simJoints, False, dynModel)
hopThroughConfigs(path, simJoints, True, dynModel)