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

No object is close enough to attach to Tool

ins_event_attach = {'Type': INS_TYPE_EVENT, 'Behavior': EVENT_ATTACH,'ToolPtr':str(RDK.Item("Tool1").item)}
program.setParam("Add", ins_event_attach )

with the Code above, i was trying to attach an object to my tool "debugGreifer"

When I debug the instruction in the GUI, I get a message in the lower left corner that "no object is close enough to Tool1".

The coordinate origin is in the lower right corner of the object. The contact point of the object surface and the tool is less than 1-2mm away from each other. The distance between the contact point and the coordinate origin of the object is more than 1m.
The reference frame in which the object is located is subordinate to the reference frame of the robot base.

I have tried it with different distances up to the collision. always the same.

If I modify the instruction manually, I have to change "Measure distanve as: " from "Default" to "TCP vs Object Position" or "TCP vs Object Surface" and select the corresponding object manually. Then it works.

How do I do this now if I want to generate an instruction automatically?

best regards
You can include the parameter AttachDistance to your JSON dictionary.

ins_event_attach = {'Type': INS_TYPE_EVENT, 'AttachDistance': 9999, 'Behavior': EVENT_ATTACH,'ToolPtr':str(RDK.Item("Tool1").item)}
program.setParam("Add", ins_event_attach)
You can inspect the parameters you have access to for each type of instruction by retrieving the id:
ins_count = prog.InstructionCount()
for ins_id in range(ins_count):
    # Get specific data related to an instruction
    # This operation always retuns a dict (json)
    instruction_dict = prog.setParam(ins_id)

    # Print instruction data
    #indented_values = json.dumps(instruction_dict, indent=4)
    print("\n\nInstruction: " + str(ins_id))
This example should print the JSON dictionary available for each instruction:
Hello Albert,
I have tried it and it does not work.
I have created a program instruction in the GUI which creates the desired task.
I then read this with a Python script and tried to add it again automatically.

Also no success.
Here the described example

#Console Output:
#Output 1 Instruction from gui

{'AttachDistance': 200, 'AttachStrategy': 4, 'Behavior': 0, 'FramePtr': '0', 'Name': 'Attach to debugGreifer', 'ObjectList': '2036147372688', 'ToolPtr': '2036147192288', 'Type': 7}

#Console Output:
#Output 2 Instruction created via python
{'AttachDistance': 200, 'AttachStrategy': 0, 'Behavior': 0, 'FramePtr': '0', 'Name': 'Attach to debugGreifer', 'ObjectList': '', 'ToolPtr': '2036147192288', 'Type': 7}

instruction_dict = prog.setParam( prog.InstructionCount()-1 )
print(instruction_dict) # Output 1
ins_event_attach = instruction_dict
prog.setParam("Add", ins_event_attach)
instruction_dict2 = prog.setParam(prog.InstructionCount()-1)
print(instruction_dict2) # Output 2

Do you know were my error is?
I understand you were trying to change the AttachDistance variable.

What do you mean by no success?
it means with python only the default attach simulation event can be created.(see picture 1)
This event always tells me when running that "no object is close enough".
Even if the distance is 1 mm between tool and object

Only when I have manually edited the event in the gui, the obj will be attached to the tool (see picture 2)

In my last post I tried to read the edited event (picture 2) and create a new one with the parameters via python.
The result was again an event with the default settings as in picture 1

(the images are not displayed in the correct order. Please pay attention to the image name)

Attached Files Image(s)
The option to attach a given list of objects can be controlled using the AttachStrategy variable. You can set it to 4 to have the same effect you are testing using the UI and provide a list item/object pointers (str(item.item), which can be separated by comma).
I have already tried this without success.
AttachStrategy always becomes 0
ObjectList loses its value

In the attachment is an example project with python code.
# Type help("robodk.robolink") or help("robodk.robomath") for more information
# Press F5 to run the script
# Documentation:
# Reference:
# Note: It is not required to keep a copy of this file, your Python script is saved with your RDK project

# You can also use the new version of the API:
from robodk import robolink    # RoboDK API
from robodk import robomath    # Robot toolbox
RDK = robolink.Robolink()

# Forward and backwards compatible use of the RoboDK API:
# Remove these 2 lines to follow python programming guidelines
from robodk import *      # RoboDK API
from robolink import *    # Robot toolbox
# Link to RoboDK
# RDK = Robolink()

program = RDK.ItemUserPick("Select a Program to modify", ITEM_TYPE_PROGRAM)

ins_id = 0

ins_count = program.InstructionCount()


while ins_id < ins_count:

    instruction_dict = program.setParam(ins_id)

    instructType = instruction_dict.get('Type')
    if instructType == 7:
        ins_event_attach = instruction_dict
        RDK.ShowMessage("Created manually" + str(ins_event_attach) )      
        program.setParam("Add", ins_event_attach )
        instruction_dict_new = program.setParam(-1)
        RDK.ShowMessage("Created with python" +str(instruction_dict_new))
    ins_id += 1
# Provoking an exception will display the console output if you run this script from RoboDK
raise Exception('End of program .')

The python code looks for the simulation event in prog2 and then adds a copy of the event to the program.
The image is the output I get.
As you can see, some values are missing and AttachStrategy is again 0

Attached Files
.rdk   debug_add_sim_instruction.rdk (Size: 226.15 KB / Downloads: 14)
Thank you for such clear explanation of the issue. This was a bug, we just fixed it on our end. A new release will be published this week with this fix and you should be able to properly create event instructions.

You'll find the new release available here:
Ah, good that the reaction is so fast. I am looking forward to the release!
The release is now available!

Let us know if you still have issues.

Users browsing this thread:
1 Guest(s)