I am trying to rewrite a scene from kinematics tutorials called ikPathGeneration, but instead of using Lua like the example, I want to do it in Python.
I am doing this just for learning purposes.
The example uses a UR10 robot, with 6 pairs joint-link. There's a tip dummy and a target dummy.
I simply rewrote the same code using Python, but I am not able to generate a path and the robot does not move. No errors appear in the sandbox below, but when I print the path generated, it is empty.
Could someone tell me what am I doing different from the example that returns no errors but does not generate a path?
Code: Select all
#python
def sysCall_init():
sim = require('sim')
simIK = require('simIK')
self.simBase = sim.getObject('.')
self.simTip = sim.getObject('./tip')
self.simTarget = sim.getObject('/target')
# Prepare an IK group using simIK.addElementFromScene
self.ikEnv = simIK.createEnvironment()
self.ikGroup = simIK.createGroup(self.ikEnv)
self.ikElement, self.simToIkMap, self.ikToSimMap = simIK.addElementFromScene(
self.ikEnv, self.ikGroup, self.simBase, self.simTip, self.simTarget, simIK.constraint_pose
)
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)
def sysCall_thread():
simJoints = []
for i in range(6):
simJoints.append(sim.getObject('./joint', {'index': i}))
sim.step()
dynModel = sim.isDynamicallyEnabled(simJoints[0])
ikTip = self.simToIkMap[self.simTip]
ikJoints = []
for joint in simJoints:
ikJoints.append(self.simToIkMap[joint])
# Generate a path with 300 configurations:
path = simIK.generatePath(self.ikEnv, self.ikGroup, ikJoints, ikTip, 300)
simIK.eraseEnvironment(self.ikEnv)
# Hop through the path configurations:
while True:
hopThroughConfigs(path, simJoints, False, dynModel)
hopThroughConfigs(path, simJoints, True, dynModel)