Dobot Pickit interface

This article documents the interface of the Dobot Pickit integration. For installation instructions, refer to the Dobot installation and setup article.

Using the Pickit functions

The Pickit functions and output variables are defined in the global.lua file of every example project. To use them in your own program, copy global.lua from an example project into your project, as described in Using Pickit in your own program. The functions communicate with Pickit through the pickit_background service, which must be running on the controller.

This API, specific to the Dobot integration uses the following conventions:

  • Distances are in millimeters, angles in degrees.

  • A pose is a table {pose={x, y, z, rx, ry, rz}}, the format DobotStudio Pro uses for Cartesian points. Functions that take a pose as argument also accept a taught point, or a table {x, y, z, rx, ry, rz}.

All functions wait for the Pickit reply before returning, except pickit_find_objects(), pickit_find_objects_with_retries(), pickit_process_image() and pickit_get_next_object(). These return immediately, so that the robot can move while Pickit detects objects, and their results are collected with pickit_get_result(). This is useful for improving cycle time by running the detection in masked time. pickit_send_event() also returns immediately, but Pickit does not reply to it, so there is no result to collect.

Pickit handles one request at a time. After one of these non-blocking functions, call pickit_get_result() before calling any other Pickit function. Only one robot program may use Pickit at a time.

Note

When a Pickit function fails unexpectedly, for example because the connection with Pickit is lost, the program stops with an error message that starts with Pickit:. See Error messages for the most common messages. Expected outcomes, such as no object found or a calibration out of tolerance, don’t stop the program: the function returns false instead.

Pickit communication functions

System functions

pickit_is_running()

Check if Pickit is set to Robot mode.

Returns

(boolean) – true if Pickit is in Robot mode.

pickit_shutdown()

Cleanly shut down the Pickit processor. This cannot be undone from the robot program: Pickit needs to be physically powered on again.

Returns

(boolean) – true if Pickit accepted the shutdown request.

Detection functions

There are two ways to trigger a detection:

In both cases, the results are collected afterwards with pickit_get_result(). For example, with tool 1 as the gripper tool:

MovJ(Detect, {cp = 0})
Wait(200)
pickit_find_objects_with_retries(5)
if pickit_get_result() then
    MovL(PickitPick, {user = 0, tool = 1, cp = 0})
end

Note

Motion commands in DobotStudio Pro are queued: the program continues while the robot is still moving. A Wait() only starts once the previous motion has finished. Call Wait() after moving to the detection pose, as in the example above, so that the robot stands still when Pickit captures the image.

See the Dobot simple pick and place example for a complete pick-and-place program, and the Dobot bin picking program example for capturing the next image while the robot places the object.

Note

Object poses communicated by Pickit have their Z axis pointing out of the object. The integration rotates them 180 degrees around their X axis, so that PickitPick has its Z axis pointing into the object, like the Z axis of the Dobot flange.

If the Z axis of your tool points away from the object when picking, undo this rotation in the global.lua file of your project, by changing the following line:

PICKIT_PICK_FRAME_OFFSET={0,0,0,180,0,0}

to

PICKIT_PICK_FRAME_OFFSET={0,0,0,0,0,0}
pickit_capture_image()

Trigger Pickit to capture a camera image. Follow up with pickit_process_image() to trigger an object detection on this image. This function returns once the image is captured: keep the robot still until then. This function is suitable if the camera is robot-mounted.

Returns

(boolean) – true if an image was captured.

pickit_process_image()

Trigger an object detection on the image that was captured with pickit_capture_image(). This function is non-blocking. The robot can move while Pickit processes the image. This function is suitable if the camera is robot-mounted. Collect the results with pickit_get_result().

pickit_find_objects()

Trigger a Pickit object detection using the currently active setup and product Configuration. This single request combines pickit_capture_image() and pickit_process_image(). This function is non-blocking. The robot can move while Pickit is detecting objects, including during the image capture, which is why this function is suitable if the camera is fixed. Collect the results with pickit_get_result().

pickit_find_objects_with_retries(retries)

Repeatedly trigger a Pickit object detection (similar to pickit_find_objects()) as long as nothing is found and the ROI is not empty, up to a maximum number of detections. This function is non-blocking. Collect the results with pickit_get_result().

Arguments
  • retries (number()) – Maximum total number of detections.

pickit_get_next_object()

Request the next detected object, if multiple objects were found (see pickit_remaining_objects()). This is typically used when the current object cannot be picked, for example because it is not reachable. This function is non-blocking. Collect the results with pickit_get_result().

pickit_get_result()

Wait for the reply to the last detection request, and update the output variables. When an object was found, it also requests the pick point data (PickitPickId, PickitPickRefId and PickitPickOff) of this object, so no follow-up call is needed. Without a pending detection request, it clears the output variables and returns false immediately.

Returns

(boolean) – true if an object was found. false if no object was found, the ROI is empty, no image was captured, or the Pickit license is invalid. Use the helper functions to find out which.

pickit_has_response()

Check, without waiting, if the reply to the last detection request has arrived. This allows the robot program to do other work while Pickit is detecting objects, and only call pickit_get_result() when the reply is there. This function does not send a request to Pickit.

Returns

(boolean) – true if pickit_get_result() will return without waiting.

Configuration functions

pickit_configure(setup, product)

Load the specified setup and product Configuration on Pickit. This clears the results of the previous detection. If Pickit cannot load the configuration, the program stops with the error Pickit: Configuration failed.

Arguments
  • setup (number()) – ID of the desired setup configuration.

  • product (number()) – ID of the desired product configuration.

pickit_save_setup()

Save the currently active setup file.

Returns

(boolean) – true if the setup file was saved.

pickit_save_product()

Save the currently active product file.

Returns

(boolean) – true if the product file was saved.

pickit_set_dimensions(x, y, z)

Set the dimensions of the active product. This leaves the product file with unsaved changes, which can be stored by calling pickit_save_product(). This function requires Pickit 4.2 or newer.

The meaning of the three dimensions depends on the product:

Arguments
  • x (number()) – First dimension [mm].

  • y (number()) – Second dimension [mm].

  • z (number()) – Third dimension [mm].

Each dimension is between 0 (not used) and 10000 mm.

Returns

(boolean) – true if the dimensions were set.

pickit_set_cylinder_dim(length, diameter)

Attention

This function is deprecated from Pickit 4.2: use pickit_set_dimensions() instead.

Set the dimensions of a Teach cylinder model. This leaves the product file with unsaved changes, which can be stored by calling pickit_save_product().

Arguments
  • length (number()) – Cylinder length [mm].

  • diameter (number()) – Cylinder diameter [mm].

Returns

(boolean) – true if the dimensions were set.

pickit_teach_roi(method, pose_frame, pose)

Build the ROI box of the active setup. This leaves the setup file with unsaved changes, which can be stored by calling pickit_save_setup(). Whether the ROI box is attached to the camera or to the robot base is set in the Pickit setup, as described here, and is not changed by this function.

Arguments
  • method (number()) –

    ROI method:

  • pose_frame (number()) –

    Frame that pose is expressed in:

    • ROI_POSE_IN_CAMERA or 1: the camera frame.

    • ROI_POSE_IN_ROBOT_BASE or 2: the robot base frame.

  • pose (pose()) –

    Depends on the method:

    • For ROI_METHOD_MANUAL, the new ROI frame: give the pose for a corner of the new ROI box, with the Z axis pointing up. Or place the ROI frame at a detected object by passing PickitPickRaw (not PickitPick, which is flipped 180°).

    • Ignored by the other methods: pass 0.

Returns

(boolean) – true if the ROI box was built.

For example, the following lines place the ROI frame at the object that was detected last, and save the setup:

if pickit_teach_roi(ROI_METHOD_MANUAL, ROI_POSE_IN_ROBOT_BASE, PickitPickRaw) then
    pickit_save_setup()
end
pickit_build_background()

Build the background cloud used by one of the Advanced filters.

Returns

(boolean) – true if the background cloud was built.

Calibration functions

pickit_configure_calibration(method, mount, pose)

Configure the next robot-camera calibration. All three arguments must be passed. With METHOD_DEFAULT, the settings from the web interface are used. Learn more about the arguments here.

Arguments
  • method (number()) –

    Calibration method:

    • Single pose: METHOD_SINGLE_POSE or 0

    • Multi pose: METHOD_MULTI_POSE or 1

    • Manual: METHOD_MANUAL or 2

    • Default: METHOD_DEFAULT or 3 to use the settings from the web interface and ignore the other two arguments.

  • mount (number()) –

    Camera mount:

    • CAMERA_MOUNT_FIXED or 0

    • CAMERA_MOUNT_ON_ROBOT or 1

  • pose (pose()) –

    Depends on the method:

    • For METHOD_SINGLE_POSE, the helper transformation.

    • For METHOD_MANUAL, the full calibration transform. The pose must be expressed in the robot base frame for a fixed camera, and in the robot flange frame for a robot-mounted camera.

    • Ignored by the other methods: pass {0, 0, 0, 0, 0, 0}.

Returns

(boolean) – true if Pickit accepted the calibration configuration.

METHOD_SINGLE_POSE together with CAMERA_MOUNT_ON_ROBOT is not supported: the program stops with an error.

pickit_find_calibration_plate()

Trigger a detection of the robot-camera calibration plate. This locates the plate, it does not compute the calibration.

pickit_compute_calibration()

Compute the robot-camera calibration from the collected calibration plate detections. On success, the Calibration results are updated.

Returns

(boolean) – true if the calibration was computed.

pickit_validate_calibration(distance_tol, angle_tol)

Validate the current robot-camera calibration. The Calibration results hold the measured errors, also when these are out of tolerance.

Arguments
  • distance_tol (number()) – Distance tolerance [mm].

  • angle_tol (number()) – Angle tolerance [deg].

Returns

(boolean) – true if the measured distance and angle errors are below the specified tolerances. false when the errors are out of tolerance, or when Pickit could not validate the calibration. In the latter case, the calibration results are nil.

Running a calibration from a robot program

For example, a multi-pose calibration with a fixed camera consists of the following sequence:

pickit_configure_calibration(METHOD_MULTI_POSE, CAMERA_MOUNT_FIXED, {0, 0, 0, 0, 0, 0})
-- For each calibration pose P1 to P10:
MovJ(P1, {cp = 0})
Wait(1000)
pickit_find_calibration_plate()
-- ...
if pickit_compute_calibration() then
    print("Calibration error: "..PickitCalErrPos.." mm, "..PickitCalErrAng.." deg")
end

How many times pickit_find_calibration_plate() is called depends on the calibration method: not at all for METHOD_MANUAL, once for single pose, multiple times for multi pose. For METHOD_MANUAL, pickit_compute_calibration() is not called either.

The Dobot calibration program example implements the multi-pose sequence with ten taught poses.

Monitoring functions

pickit_save_snapshot(subfolder_id)

Save a snapshot with the latest detection results.

Arguments
  • subfolder_id (number()) – Number of the subfolder of the robot snapshot folder (1 to 255). If 0, the snapshot is saved directly in the robot folder.

Returns

(boolean) – true if the snapshot was saved.

pickit_send_event(event_code, payload, pose)

Send an event to Pickit, to keep statistics of the robot application in the Pickit Trends monitoring tool (available from Pickit 4.2 onwards).

Pickit does not reply to events, so this function returns immediately, and the background service sends the event.

Arguments
  • event_code (number()) –

    Event code:

    • PICKIT_EVENT_PICK_SUCCESS or 123: an object was picked.

    • PICKIT_EVENT_PICK_FAILURE or 124: picking an object failed.

    • PICKIT_EVENT_UNREACHABLE_OBJECT or 125: the robot cannot reach the detected object.

    • PICKIT_EVENT_ROBOT_COLLISION_CAUGHT or 126: the robot caught a collision.

    • PICKIT_EVENT_BIN_FINISHED or 131: the bin is empty.

    • PICKIT_EVENT_CYCLE_COMPLETED or 132: a robot cycle was completed.

  • payload (number()) – A number for the event, for example the number of objects picked from the bin for PICKIT_EVENT_BIN_FINISHED. Pass 0 if not used.

  • pose (pose()) – A pose for the event, for example PickitPick for PICKIT_EVENT_PICK_SUCCESS, PICKIT_EVENT_PICK_FAILURE and PICKIT_EVENT_UNREACHABLE_OBJECT. Pass 0 to send the current robot flange pose.

Returns

(boolean) – true when the event is handed to the background service.

Pickit helper functions

The following functions don’t communicate with Pickit. They use the results of the last call to pickit_get_result(), and can be used to make your robot program more readable. See Dobot simple pick and place on how they are typically used in a robot program.

pickit_object_found()
Returns

(boolean) – true if a valid object was detected. The detection results are only valid in this case.

pickit_empty_roi()
Returns

(boolean) – true if the ROI is empty.

pickit_no_image_captured()

Check if no image was captured by Pickit. If so, check the camera connection.

Returns

(boolean) – true if no image was captured.

pickit_license_invalid()

Check if the detection could not run because a Pickit license module is missing or expired.

Returns

(boolean) – true if a required license is missing or expired.

pickit_remaining_objects()
Returns

(number) – Number of remaining objects that can be requested with pickit_get_next_object().

Pose functions

These functions help to compute poses relative to a Pickit result, for example the approach pose before a pick.

pickit_pose_multiply(a, b)

Multiply two poses: b is relative to a, and the result is b expressed in the frame that a is expressed in. For example, the following line computes the pose 100 mm before the pick pose, along the Z axis of the tool:

local pre_pick = pickit_pose_multiply(PickitPick, {0, 0, -100, 0, 0, 0})
Arguments
  • a (pose()) – First pose.

  • b (pose()) – Second pose, relative to a.

Returns

(pose) – Product of a and b.

pickit_pose_inverse(p)
Arguments
  • p (pose()) – Pose to invert.

Returns

(pose) – Inverse of p.

Pickit output variables

The following global variables hold the results of Pickit responses. Reading them does not communicate with Pickit.

Detection results

These variables are updated by pickit_get_result(). They are nil when no valid object was detected, and are cleared when a new detection is triggered.

PickitPick

(pose) – Pick pose of the detected object, expressed in the robot base frame. Its Z axis points into the object, like the Z axis of the tool.

PickitPickRaw

(pose) – Pick pose of the detected object as communicated by Pickit, expressed in the robot base frame. Its Z axis points out of the object: unlike PickitPick, it is not rotated by 180° (PICKIT_PICK_FRAME_OFFSET) around the X axis. Use it for example to build the ROI box at a detected object with pickit_teach_roi().

PickitPickId

(number) – ID of the pick point that was selected for the detected object.

PickitPickRefId

(number) – ID of the selected pick point’s reference pick point.

PickitPickOff

(pose) – Pick point offset of the detected object. See Using pick offset in a robot program.

PickitObjType

(number) – Object type:

  • For a Teach detection, ID type of the detected object.

  • For a Flex/Pattern detection, the object type of the detected object. These are declared as PICKIT_TYPE_* constants in global.lua, and also listed here.

  • In a Bags detection, a value holding information about the bag pattern and the detected layer orientation.

PickitObjDim

(table) – Object dimensions in mm, as {length or diameter, width or diameter, height or diameter}. For a square or circle, the second dimension equals the first. For a cylinder, the third dimension equals the second (the diameter). For a sphere, all three dimensions are the diameter.

PickitObjAge

(number) – Amount of time that has passed between the capturing of the camera image and the moment the object information is sent to the robot [s].

More detailed information about these outputs can be found here.

Calibration results

These variables are updated by pickit_compute_calibration() and pickit_validate_calibration(), so read them right after the call.

PickitCal

(pose) – Calibration transform (robot_T_camera) computed by pickit_compute_calibration().

PickitCalErr

(pose) – Calibration error measured by pickit_validate_calibration().

PickitCalErrPos

(number) – Distance calibration error [mm].

PickitCalErrAng

(number) – Angle calibration error [deg].

More detailed information about these outputs can be found here.

Pickit status

PickitLastStatus

(number) – Status of the last Pickit reply. The possible values are declared as constants in global.lua, and are documented here.

Use it to find out why a function returned false. For example, pickit_save_product() returns false and PickitLastStatus is PICKIT_CONFIG_FAILED when Pickit could not save the product file.

Using pick offset in a robot program

When using multiple pick points or flexible pick orientations, it can be useful to adjust the drop-off point with the pick offset (PickitPickOff) to get a consistent drop-off position regardless of the pick point used. See also Smart placing examples.

The following lines of code correct the drop-off point Dropoff with the pick offset. Dropoff is taught in user coordinate system 0 with the gripper tool, here tool 1.

local dropoff = pickit_pose_multiply(Dropoff, PickitPickOff)
MovJ(dropoff, {user = 0, tool = 1})

Timeouts

When Pickit does not reply in time, the program stops with the error Pickit: No reply from Pickit (timeout or connection lost), and the background service reconnects to Pickit. The time to wait depends on the function:

Timeout

Default

Functions

PICKIT_TIMEOUT_SHORT_MS

5 s

System and configuration functions (except pickit_teach_roi()), pickit_get_next_object(), pickit_send_event(), and the pick point data request of pickit_get_result().

PICKIT_TIMEOUT_LONG_MS

30 s

pickit_find_objects(), pickit_capture_image(), pickit_process_image(), pickit_teach_roi() and pickit_save_snapshot(). For pickit_find_objects_with_retries(), 30 s per detection.

PICKIT_TIMEOUT_CALIB_MS

60 s

Calibration functions.

The defaults fit most applications. If a detection takes longer, for example in a complex scene, increase the timeouts in two places, with the same values:

  • In the global.lua file of every project that uses Pickit: PICKIT_TIMEOUT_SHORT_MS, PICKIT_TIMEOUT_LONG_MS and PICKIT_TIMEOUT_CALIB_MS.

  • In the src0.lua file of the pickit_background project: TIMEOUT_SHORT_MS, TIMEOUT_LONG_MS and TIMEOUT_CALIB_MS. Restart the background process afterwards.

If a program is stopped while waiting for a Pickit reply, the next Pickit function call waits until this reply arrives or times out, and logs Pickit: waiting for the previous request to finish (request <n>, response <m>).

Error messages

The following table lists the most common error messages that stop a program, as mentioned in the note at the beginning of this page.

Message

Cause and solution

Pickit: Pickit background service is not running: start it in Settings > Background Process

The pickit_background process is not running. Start it as described in Run the background process.

Pickit: Pickit background service is not connected to Pickit

The background service is running, but cannot reach Pickit. Check that Pickit is powered on, the network cable, the IP configuration and the PICKIT_HOST value.

Pickit: No reply from Pickit (timeout or connection lost)

Pickit did not reply in time, or the connection was lost while waiting. Check the connection and the timeouts.

Pickit: Configuration failed

Pickit could not load the setup or product. Check that the IDs passed to pickit_configure() exist on Pickit.

Pickit: Calibration plate not found

Pickit could not detect the calibration plate at the current robot pose. Check that the plate is fully in view of the camera.

Pickit: Detection error status <n>

Pickit replied to a detection request with an unexpected status <n>. The statuses are listed here.

Collect previous result first

A Pickit function was called while a detection request was still pending. Call pickit_get_result() first.

Create PickitRequest and PickitResponse as string global variables, as documented in README.md

PickitRequest or PickitResponse does not exist on the controller, is not of type string, or does not hold the expected number of values. Create them as described in Creating the global variables.

Pickit: Invalid PickitResponse: <value>

PickitResponse does not hold 18 comma-separated numbers. Check its value in Monitor > Global variable, and create it again as described in Creating the global variables if needed.