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

# How to get the xyz values for the target position of a movement from a program

Hello,
I hope you can help me.

I want to read the xyz values for the target position of a movement from a program.
The program was generated from a CAM file and is functional without errors in RoboDK.

Example:

#Example move command
instruction_dict = program.setParam(5)

print(instruction_dict)
#{'Joints': '109.507535,-13.721288,122.115482,-115.355384,92.927156,-78.386586', 'MoveType': 1, 'Name': 'MoveJ 1', 'Pose': 'transl(-298.576,-198.535,136)*rotx(-180)*rotz(-4.981)', 'TargetPtr': '0', 'Type': 0}

print(instruction_dict['Pose'])
#transl(-298.576,-198.535,136)*rotx(-180)*rotz(-4.981)

print(str(Pose_2_TxyzRxyz(instruction_dict.Pose()))) #AttributeError: 'dict' object has no attribute 'Pose'

#what is missing to get x y z?

print(x)# -298.576
print(y)#-198.535
print(x)#136

best regards
Jonas Veller
It is better if you use the Instruction function:
https://robodk.com/doc/en/PythonAPI/robo...nstruction

So you can do:
Code:
```ins_name, ins_type, move_type, isjointtarget, pose, joints = prog.Instruction(0) if ins_type == INS_TYPE_MOVE:     print(pose)```
You could also use the eval function on the pose string. However, if you use the global robomath context you should convert degrees to radians. You can create a custom context for that specific eval function. Example:
Code:
```from robodk import robomath import math context = {} context["transl"] = robomath.transl context["rotx"] = lambda rx: robomath.rotx(rx * math.pi / 180.0) context["roty"] = lambda ry: robomath.roty(ry * math.pi / 180.0) context["rotz"] = lambda rz: robomath.rotz(rz * math.pi / 180.0) # pose = eval("transl(100,0,0)*rotx(180)*roty(90)", context) pose = eval(instruction["Pose"], context) print(pose)```
Perfect that has solved my problem:

ins_name, ins_type, move_type, isjointtarget, pose, joints = prog.Instruction(0)

Thank you
Hello again,

ins_name, ins_type, move_type, isjointtarget, pose, joints = prog.Instruction(0)

works for MoveJ instruction.
Now I have come across a MoveC instruction, where I unfortunately get no further.
Unlike MoveJ Instrucktion, MoveC does give me only poses in the as Strings.

instruction_dict = program.setParam(ins_id)
print(instruction_dict)
#{'Joints': '103.670178,-13.553023,108.458609,-121.166389,87.567876,-90.806867', 'Joints2': '103.675661,-13.502296,108.406457,-121.160885,87.566737,-90.807845', 'MoveType': 3, 'Name': 'MoveC 7', 'Pose': 'transl(505,803.679,19.343)*rotx(180)*rotz(-4.981)', 'Pose2': 'transl(505,802.972,19.050)*rotx(-180)*rotz(-4.981)', 'Type': 1}

print(program.Instruction(ins_id))
#('MoveC 7', 1, None, None, None, None)

Do i miss something or is using the specific eval function from Albert the only way?

Best regards
Jonas
The other method I mentioned with the setParam function offers more flexibility such as dealing with circular movements and many other features.

The code I shared in my first response using eval should work. Did you try it?

You can create a function to facilitate reusing this code. Example:
Code:
```def String2Pose(posestring):     from robodk import robomath     import math     context = {}     context["transl"] = robomath.transl     context["rotx"] = lambda rx: robomath.rotx(rx * math.pi / 180.0)     context["roty"] = lambda ry: robomath.roty(ry * math.pi / 180.0)     context["rotz"] = lambda rz: robomath.rotz(rz * math.pi / 180.0)     # pose = eval("transl(100,0,0)*rotx(180)*roty(90)", context)     pose = eval(posestring, context)     return pose pose = String2Pose(instruction["Pose"]) pose2 = String2Pose(instruction["Pose2"])```
Thanks Albert the Code you shared works much better.

 Users browsing this thread: 1 Guest(s)