How to get & set the "Target linked" item of a move instruction?- Printable Version +- RoboDK Forum (//www.sinclairbody.com/forum) +-- Forum: RoboDK (EN) (//www.sinclairbody.com/forum/Forum-RoboDK-EN) +--- Forum: RoboDK API (//www.sinclairbody.com/forum/Forum-RoboDK-API) +--- Thread: How to get & set the "Target linked" item of a move instruction? (/Thread-How-to-get-set-the-Target-linked-item-of-a-move-instruction) |
How to get & set the "Target linked" item of a move instruction?-Maarten-02-17-2022 How do I get the 'Target linked' item of a program's move instruction? The target and move instruction are created in the GUI, and I would like to obtain the linked target item via the API. I found I can get several parameters of the instruction using 'Instruction()':
Code:
p = RDK.Item('myProgram',ITEM_TYPE_PROGRAM)
However, this does not provide the linked target item. Also, output 'pose' appears to be defined with respect to the linked target item's first parent reference frame, but if I can't determine to which target item the instruction is linked, then I can't determine the frame of reference for 'pose' either. The second part of this question is: how do I change/set the 'Target Linked' item via the API to a different target item? (I.e. not just changing the 'pose' of the instruction, but changing the actual target item). Similar to what is achieved in the GUI's right click on instruction menu shown below: Best regards, Maarten RE: How to get & set the "Target linked" item of a move instruction?-Sam-02-18-2022 Hi Mearten, You are on the right path! Currently, it is not possible to edit the linked Target Item directly through the API. You will have to replace the instruction with a new one. Here's a sample code to give you the idea.
Code:
import robolink
You can find more information in your documentation
RE: How to get & set the "Target linked" item of a move instruction?-Maarten-02-18-2022 Hi Sam, Thanks for helping out. Isn't your code example a bit risky, since you're assuming the name of the instruction contains the name of the target?
Code:
if old_target.Name() in instruction_dict['Name']:
By default, the name of a joint move instruction indeed includes the name of the target in its form e.g. "MoveJ (targetName)". But a user is free to rename the instruction. Also, a user could rename the target after creating the instruction. Without the name of the target as part of the instruction's name, your code example would miss the link. (The code would also give a false positive for e.g. "MoveJ (target10)", which contains the name of both "target1" as well as "target10". But this could be solved by a more specific string compare.) Is there no other indicator to the linked target item in an instruction than the name of the target item as part of the name of the instruction? Best regards, Maarten RE: How to get & set the "Target linked" item of a move instruction?-Maarten-02-18-2022 I just found out that the name of a move instruction in the GUI is automagically updated to match the default name and the (updated if changed) name of the linked target, upon running these next lines in a Python script:
Code:
from robolink import * # RoboDK API
So I have e.g. a (3rd) instruction and target: "MoveJ (target1)" and "target1" I manually change in the GUI both the instruction name and target name to: "MoveJA (target1B)" and "target1C" Then I run the code above, and the name of the instruction is automatically updated to: "MoveJ (target1C)" and "target1C" 也许一些水下会刷新吗?如果the naming of instructions is actually enforced by this, it could make retrieving the linked target item from the instruction's name a viable option. RE: How to get & set the "Target linked" item of a move instruction?-Sam-02-18-2022 Indeed, the example code I provided is not robust. It is provided as a workaround until a more convenient way is added to the API. You will have to adapt it to your needs. To make it more robust, you can retrieve the desired target pose and compare it to the instruction pose. 如果the name and pose matches, most likely you are replacing the correct instruction. Other ways to approach this:
|