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

Create Targets from Quaternion

Hi all,

I am struggling to create robottargets within a python script from quaternions. When I create a target with the "New target"-button in RoboDK and paste the Quaternion it works fine. But I have 364 targets that need to be created and I would like to do this with a python script but I don't know how the code should look like.
I hope someone can help me with that. I already have written a small script, but this only transfers the xyz-coordinates to RoboDK but not the orientation.
I attached a 4x4 Matrix (quaternion) of one of my poses, and the script I have written.

Attached Files
.txt   pose_t_1.txt (Size: 410 bytes / Downloads: 168)
.txt   RDK_pythonscript.txt (Size: 945 bytes / Downloads: 181)
It looks like you already have a 4x4 matrix in the text file you provided.

You can create this matrix (Mat) by directly providing the all components of your matrix using a list of lists in Python:
poselist = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
pose = robomath.Mat(poselist)
if not pose.isHomogeneous():
    print("Something is wrong: this pose is not homogeneous.")

The opposite of Pose_2_ABB would be a function that takes 7 values (xyz,q1,q2,q3,q4) and returns a pose (4x4 matrix). This function could look like this:
def ABB_2_Pose(xyzq1234):
    xyz = xyzq1234[0:3]
    q1234 = xyzq1234[3:7]
    pose = quaternion_2_pose(q1234)
return pose
Hello Albert,
thanks for the quick answer! Right now I am trying to implement the first solution you provided, but somehow my program doesn't recognize the robomath module.
First the program gave me the following error:
NameError: name 'robomath' is not defined
Than I tried to import robomath with:
from robodk import robomath
But that gave me the error:
ImportError: cannot import name 'robomath' from 'robodk' (/home/robi/.local/lib/python3.8/site-packages/robodk/

I am using RoboDK version 5.3.0

Any ideas how to fix that?

Best regards
Try using this code at the top of your script for RoboDK imports:
from robolink import *
from robodk import *

This should work for all versions. You can then access all functions directly like this:

pose = Mat(4)
xyzabc = Pose_2_KUKA(pose)

Users browsing this thread:
1 Guest(s)