import pybullet as p import time import math from datetime import datetime from datetime import datetime clid = p.connect(p.SHARED_MEMORY) if (clid<0): p.connect(p.GUI) p.loadURDF("plane.urdf",[0,0,-0.3]) husky = p.loadURDF("husky/husky.urdf",[0.290388,0.329902,-0.310270],[0.002328,-0.000984,0.996491,0.083659]) for i in range (p.getNumJoints(husky)): print(p.getJointInfo(husky,i)) kukaId = p.loadURDF("kuka_iiwa/model_free_base.urdf", 0.193749,0.345564,0.120208,0.002327,-0.000988,0.996491,0.083659) ob = kukaId jointPositions=[ 3.559609, 0.411182, 0.862129, 1.744441, 0.077299, -1.129685, 0.006001 ] for jointIndex in range (p.getNumJoints(ob)): p.resetJointState(ob,jointIndex,jointPositions[jointIndex]) #put kuka on top of husky cid = p.createConstraint(husky,-1,kukaId,-1,p.JOINT_FIXED,[0,0,0],[0,0,0],[0.,0.,-.5],[0,0,0,1]) baseorn = p.getQuaternionFromEuler([3.1415,0,0.3]) baseorn = [0,0,0,1] #[0, 0, 0.707, 0.707] #p.resetBasePositionAndOrientation(kukaId,[0,0,0],baseorn)#[0,0,0,1]) kukaEndEffectorIndex = 6 numJoints = p.getNumJoints(kukaId) if (numJoints!=7): exit() #lower limits for null space ll=[-.967,-2 ,-2.96,0.19,-2.96,-2.09,-3.05] #upper limits for null space ul=[.967,2 ,2.96,2.29,2.96,2.09,3.05] #joint ranges for null space jr=[5.8,4,5.8,4,5.8,4,6] #restposes for null space rp=[0,0,0,0.5*math.pi,0,-math.pi*0.5*0.66,0] #joint damping coefficents jd=[0.1,0.1,0.1,0.1,0.1,0.1,0.1] for i in range (numJoints): p.resetJointState(kukaId,i,rp[i]) p.setGravity(0,0,-10) t=0. prevPose=[0,0,0] prevPose1=[0,0,0] hasPrevPose = 0 useNullSpace = 0 useOrientation =0 #If we set useSimulation=0, it sets the arm pose to be the IK result directly without using dynamic control. #This can be used to test the IK result accuracy. useSimulation = 0 useRealTimeSimulation = 1 p.setRealTimeSimulation(useRealTimeSimulation) #trailDuration is duration (in seconds) after debug lines will be removed automatically #use 0 for no-removal trailDuration = 15 basepos =[0,0,0] ang = 0 ang=0 def accurateCalculateInverseKinematics( kukaId, endEffectorId, targetPos, threshold, maxIter): closeEnough = False iter = 0 dist2 = 1e30 while (not closeEnough and iter