Dobot bin picking program
This program requires that Pickit is installed and set up with your robot. For installation instructions, refer to the Dobot installation and setup article.
Attention
The example programs contain robot poses that must be adapted to every new robot or application.
For pickit_bin_picking, you must teach the Home, Detect, AbovePickArea and Dropoff points, choose the correct TOOL, set BIN_ENTRY_Z and BIN_EXIT_Z for your bin, and fill in the correct SETUP and PRODUCT IDs.
When executing such programs for the first time, do so at low speed to check for potential collisions.
The pickit_bin_picking program
This program is the src0.lua file of the pickit_bin_picking project, in Application > Script programming.
-- Bin picking example program
-- Compared to pickit_pick_and_place it adds:
-- - a five-point extraction path: BinEntry -> PrePick -> PickitPick -> PostPick -> BinExit;
-- - a reachability check: an unreachable object is skipped with pickit_get_next_object();
-- - a pick success check: after a failed pick the place motion is skipped.
-- Teach these points (point aliases), all with the gripper tool:
-- Home safe start and end pose
-- Detect where to detect from: camera view on the bin (camera on the robot),
-- or a pose out of the camera view (fixed camera)
-- AbovePickArea above the bin; every BinEntry and BinExit pose can be reached from here
-- Dropoff where to release the object
-- The Pickit background service must be running.
local SETUP,PRODUCT=1,1
local MAX_RETRIES=5 -- max. total number of detections (first one included) when no object is found
local MAX_PICK_FAILS=3 -- stop after this many failed picks in a row
local PRE_PICK_MM=100 -- approach distance along the tool Z axis
local POST_PICK_MM=100 -- retreat distance along the tool Z axis
local BIN_ENTRY_Z=300 -- robot base Z of BinEntry: choose a value higher than the bin (mm)
local BIN_EXIT_Z=300 -- robot base Z of BinExit: choose a value higher than the bin (mm)
local TOOL=1 -- tool (TCP) of the gripper, used for the computed pick poses
local SETTLE_MS=200
local taught={a=10,v=10,cp=0} -- taught points keep their own user and tool
local in_bin={user=0,tool=TOOL,a=10,speed=50,cp=0} -- BinEntry, BinExit
local approach={user=0,tool=TOOL,a=10,speed=20,cp=0} -- PrePick, PickitPick, PostPick
-- Motion commands are queued. Wait() starts after the previous move has finished,
-- so it makes sure the robot stands still before detecting or gripping.
local function goto_detection()
MovJ(Detect,taught)
Wait(SETTLE_MS)
end
-- Add your gripper code after the Wait(). Motion commands are queued: the Wait() makes sure the robot has
-- arrived and stands still before the gripper switches. Return only when the gripper has finished.
local function grip()
Wait(SETTLE_MS)
-- Add gripper code here
end
local function release()
Wait(SETTLE_MS)
-- Add gripper release code here
end
-- Return false when a gripper sensor shows that nothing was picked. Without a sensor, return true.
local function object_picked()
Wait(SETTLE_MS)
-- Add gripper sensor code here
return true
end
-- Checks the end points only: the linear moves between them are not checked.
local function reachable(poses)
for _,pose in ipairs(poses) do
local err=InverseKin(pose,{user=0,tool=TOOL,useJointNear=true,jointNear={joint=AbovePickArea.joint}})
if err~=0 then return false end
end
return true
end
-- Main code and loop
MovJ(Home,taught)
release()
assert(pickit_is_running(),"Pickit is not in ROBOT mode: enable it in the Pickit web interface")
pickit_configure(SETUP,PRODUCT)
goto_detection()
pickit_find_objects_with_retries(MAX_RETRIES)
pickit_get_result()
local picks,fails,unreachable=0,0,false
while pickit_object_found() do
local pick=PickitPick
local pre_pick=pickit_pose_multiply(pick,{0,0,-PRE_PICK_MM,0,0,0})
local post_pick=pickit_pose_multiply(pick,{0,0,-POST_PICK_MM,0,0,0})
-- BinEntry and BinExit: straight above PrePick and PostPick, same orientation.
local bin_entry={pose={pre_pick.pose[1],pre_pick.pose[2],BIN_ENTRY_Z,
pre_pick.pose[4],pre_pick.pose[5],pre_pick.pose[6]}}
local bin_exit={pose={post_pick.pose[1],post_pick.pose[2],BIN_EXIT_Z,
post_pick.pose[4],post_pick.pose[5],post_pick.pose[6]}}
unreachable=not reachable({bin_entry,pre_pick,pick,post_pick,bin_exit})
if unreachable then
print("Object is not reachable, trying the next one")
pickit_get_next_object()
pickit_get_result()
else
MovJ(AbovePickArea,taught)
MovL(bin_entry,in_bin)
MovL(pre_pick,approach)
MovL(pick,approach)
grip()
MovL(post_pick,approach)
MovL(bin_exit,in_bin)
MovL(AbovePickArea,taught)
local picked=object_picked()
-- Capture the next image while holding the object, process it while placing.
-- If the capture fails, nothing is pending and pickit_get_result() returns false: detect again below.
goto_detection()
if pickit_capture_image() then pickit_process_image() end
if picked then
picks=picks+1; fails=0
MovJ(Dropoff,taught)
release()
else
fails=fails+1
print("Pick failed ("..fails.." in a row), skipping the place motion")
release()
end
pickit_get_result()
if fails>=MAX_PICK_FAILS then break end
if not pickit_object_found() then
goto_detection()
pickit_find_objects_with_retries(MAX_RETRIES-1)
pickit_get_result()
end
end
end
print("Objects picked: "..picks)
if fails>=MAX_PICK_FAILS then
print("Too many failed picks in a row")
elseif unreachable then
print("None of the detected objects is reachable")
elseif pickit_empty_roi() then
print("The ROI is empty")
elseif pickit_no_image_captured() then
print("Failed to capture a camera image")
elseif pickit_license_invalid() then
print("Pickit license is missing or invalid")
else
print("The ROI is not empty but no object was found; saving a snapshot")
pickit_save_snapshot(0)
end
MovJ(Home,taught)
The structure of this program is similar to the simple pick and place program. It adds three features that are useful when picking from a bin:
Five-point extraction path. The robot enters and leaves the bin along the five-point extraction path recommended for picking in deep bins:
BinEntry, pre-pick, pick, post-pick andBinExit. More information about the five-point extraction path can be found in the robot-independent bin picking program.Reachability check. Before moving, the program checks that the robot can reach the five points of the extraction path. If not, the object is skipped and the program requests the next detected object. Only the points themselves are checked, not the linear motions between them.
Pick check. After a pick,
object_picked()reports whether the gripper holds the object (if your gripper supports this feature). If not, the robot skips the place motion. AfterMAX_PICK_FAILSfailed picks in a row, the program stops.
When no more objects are found, the robot returns to Home and the program ends.
It logs the number of picked objects and the reason it stopped: too many failed picks, no reachable object, an empty ROI, no captured image, or an invalid Pickit license.
If no object is found and the ROI is not empty, a snapshot is also saved on the Pickit system.
Define the tool for picking
Create a tool coordinate system in DobotStudio Pro with the actual TCP values of the gripper.
Set TOOL at the top of the program to the number of this tool.
In this program, tool 1 is used.
Set correct input arguments
At the top of the program:
Set
SETUPandPRODUCTto the IDs of the Pickit setup and product files to use.MAX_RETRIESsets the maximum total number of detections, including the first one, when no object is found.MAX_PICK_FAILSsets the number of failed picks in a row after which the program stops.
Define fixed points
In this program, 4 fixed points are used. Teach them in the points list of the project, with the gripper tool, and keep their names as aliases.
Home: Where the robot starts and ends the program.
Detect: Where to perform object detection from. With a robot-mounted camera, the camera looks at the bin. With a fixed camera, the robot is out of the camera view.
AbovePickArea: A point high above the bin, from which every
BinEntryandBinExitpose can be reached without collision.Dropoff: Where to place objects.
Pick sequence settings
The five-point extraction path can be modified with these four settings at the top of the program:
PRE_PICK_MM: the offset of the pre-pick pose from the pick pose, along the tool Z axis.POST_PICK_MM: the offset of the post-pick pose from the pick pose, along the tool Z axis.BIN_ENTRY_Z: the height ofBinEntryin the robot base frame, straight above the pre-pick pose.BIN_EXIT_Z: the height ofBinExitin the robot base frame, straight above the post-pick pose.
Choose BIN_ENTRY_Z and BIN_EXIT_Z higher than the bin rim.
The motions in and out of the bin are executed with conservative absolute speeds: 50 mm/s for BinEntry and BinExit (in_bin motion settings), and 20 mm/s for the pre-pick, pick and post-pick poses (approach motion settings).
The taught points are reached with the taught motion settings, at 10% speed.
Change these values if necessary.
Add grasping/releasing logic
Add your gripper code to the grip() and release() functions, after the Wait() that is already there.
The Wait() makes sure the robot has arrived and stands still before the gripper is actuated.
Make sure both functions only return once the gripper has finished.
If the gripper can sense whether it holds an object, add this check to the object_picked() function, so that it returns false after a failed pick.
Without a sensor, leave it as it is: it always returns true.
Execute the picking program
Attention
Before running the robot program for the first time, make sure that:
There exists a valid robot-camera calibration.
The Tool Center Point (TCP) has been correctly specified.
The robot speed is set to a low value, so unexpected behavior can be identified early enough to prevent the robot from colliding with people or the environment.
Pickit is in robot mode, which is enabled in the Pickit web interface.
Now you can run the program. Happy picking!