Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

SolveIK returns a different solution

#1
Why doesn't inverse kinematics work through API in this case?
Code:
import numpy as np
from robodk.robomath import transl, rotx, roty, rotz, Mat
from robodk.robolink import Robolink, ITEM_TYPE_ROBOT
# TM
def pose_from_xyzrxryrz(x, y, z, rx, ry, rz):
    return transl(x*1000, y*1000, z*1000) * rotx(rx) * roty(ry) * rotz(rz)
# End-effector pose
x, y, z = -0.11098, -0.30368, 0.12402  #m
rx, ry, rz = 2.303, -2.178, -0.035  #rad
pose = pose_from_xyzrxryrz(x, y, z, rx, ry, rz)
print("MT (End-Effector):\n", pose)
RDK = Robolink(args=['-NOUI'])  #RoboDK witout GUI
project_path = r'C:\Users\andre\Desktop\UR3.rdk'  # UR3 path
if not RDK.AddFile(project_path):
    raise Exception(f"Could not load project file: {project_path}")
#UR5
ROBOT = RDK.Item('UR3', ITEM_TYPE_ROBOT)
if not ROBOT.Valid():
    raise Exception("No valid robot selected!")
#INVKIN
joints = ROBOT.SolveIK(pose)
if joints is None:
    raise Exception("No solution found for the given pose!")
print("Joint Angles (IK Solution):", joints)


Attached Files Thumbnail(s)
WhatsApp Image 2024-12-18 at 15.42.43.jpeg   
Image(s)
   
#2
Calculating the inverse kinematics with SolveIK returns the solution that is closest to the current robot position. One quick workaround is to call robot.setJoints and pass joints near the preferred solution.

You can also use SolveIK_All to obtain all possible solutions and filter them.
  




Users browsing this thread:
1 Guest(s)