Dobot simple pick and place

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_pick_and_place, you must teach the Home, Detect, AbovePickArea and Dropoff points, choose the correct TOOL, 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_pick_and_place program

This program is the src0.lua file of the pickit_pick_and_place project, in Application > Script programming.

-- Simple pick and place example program.
-- 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 pick area (camera on the robot),
--                  or a pose out of the camera view (fixed camera)
--   AbovePickArea  above the pick area; every pre-pick 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 PRE_PICK_MM=100 -- approach distance along the tool Z axis
local POST_PICK_MM=100 -- lift distance along the robot base Z axis
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 approach={user=0,tool=TOOL,a=10,speed=20,cp=0}

-- 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


-- 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()

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={pose={pick.pose[1],pick.pose[2],pick.pose[3]+POST_PICK_MM,
        pick.pose[4],pick.pose[5],pick.pose[6]}}

    MovJ(AbovePickArea,taught)
    MovL(pre_pick,approach)
    MovL(pick,approach)
    grip()
    MovL(post_pick,approach)
    MovL(AbovePickArea,taught)

    -- 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
    MovJ(Dropoff,taught)
    release()
    pickit_get_result()

    if not pickit_object_found() then
        goto_detection()
        pickit_find_objects_with_retries(MAX_RETRIES-1)
        pickit_get_result()
    end
end

if 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 idea of the program is the following:

  • First, the robot moves to Home and opens the gripper.

  • It is checked whether or not Pickit is in robot mode. If not, the program stops.

  • The robot moves to Detect and a detection is triggered, repeated when no object is found, up to 5 detections in total.

  • If an object is found, the robot moves to the object to pick it: from AbovePickArea, to the pre-pick pose, to the pick pose. After grasping, it lifts the object to the post-pick pose and returns to AbovePickArea.

  • The robot then moves to Detect and Pickit captures a new image. Pickit processes this image while the robot moves to Dropoff and releases the object, optimizing cycle time.

  • If no object is found in the new image, the robot detects again from Detect.

  • When no more objects are found, the robot returns to Home and the program ends. It logs the reason: the ROI is empty, no image was captured, or the Pickit license is invalid. If no object is found and the ROI is not empty, a snapshot is also saved on the Pickit system.

Note

This program does not check whether the pick, pre-pick and post-pick poses are reachable before moving. Make sure the objects to pick are within reach of the robot. The bin picking program adds a reachability check.

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 SETUP and PRODUCT to the IDs of the Pickit setup and product files to use.

  • MAX_RETRIES sets the maximum total number of detections, including the first one, when no object is found.

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 pick area. With a fixed camera, the robot is out of the camera view.

  • AbovePickArea: A point above the pick area, from which every pre-pick pose can be reached without collision.

  • Dropoff: Where to place objects.

Pick sequence settings

The pre-pick and post-pick poses are derived from the pick pose with a fixed offset:

  • PRE_PICK_MM (100 mm) is applied along the tool Z axis, so the gripper approaches the object along its own axis.

  • POST_PICK_MM (100 mm) is applied along the robot base Z axis, so the object is lifted straight up.

Adapt both offsets to your application if necessary.

The linear motions in and out of the pick area are executed with the approach motion settings, at a conservative absolute speed of 20 mm/s. 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.

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!