Dobot user frame program
This article describes the Dobot user frame program commonly used in applications such as surface treatment, inspection, or welding. More information about the logic of this program can be found in the robot-independent part location 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.
User frames in Dobot
In DobotStudio Pro, a user frame is defined as a user coordinate system, in Settings > Coordinate system. User coordinate system 0 is the robot base, and other user coordinate systems are defined relative to it. Points taught in a user coordinate system move along with it: when the user coordinate system changes, the robot reaches the points at their new location.
In this example program, the user coordinate system is set to the pick point of the part detected by Pickit. A path taught relative to the part is then followed wherever the part lies.
Attention
The example programs contain robot poses that must be adapted to every new robot or application.
For pickit_user_frame, you must teach the Home, Detect, Point1, Point2 and Point3 points, set USER_FRAME to the ID of your user coordinate system, 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_user_frame program
This program is the src0.lua file of the pickit_user_frame project, in Application > Script programming.
The same program is used to teach the path and to execute it, selected with the TEACH setting at the top of the program.
-- User frame (part location) example program: a path taught relative to a part is
-- followed wherever Pickit detects the part.
-- The path points are taught in a Dobot user coordinate system (USER_FRAME). Each run moves that user
-- coordinate system to the detected part, so the path moves with the part.
-- Setup, once:
-- 1. Add a user coordinate system in DobotStudio with any value and set its id in USER_FRAME below.
-- This program overwrites its values.
-- 2. Teach Home and Detect (point aliases) with the tool.
-- 3. Set SETUP and PRODUCT, put a part in view, set TEACH=true and run the program: USER_FRAME is set to the
-- detected part and saved.
-- Refresh the user coordinate system page in DobotStudio to see the new value.
-- 4. Without moving the part: teach Point1, Point2, Point3 with the tool, in user coordinate system USER_FRAME.
-- Point1 is reached with a joint move, the others with linear moves. To add points, add them to PATH.
-- The robot goes from the last point to Home with a joint move: make it a safe retreat pose.
-- 5. Set TEACH=false and run.
-- The Pickit background service must be running.
local TEACH=false
local SETUP,PRODUCT=1,1
local USER_FRAME=1 -- id of the user coordinate system of the part
local MAX_RETRIES=5 -- max. total number of detections (first one included) when no part is found
local PATH={Point1,Point2,Point3}
local SETTLE_MS=200
local taught={a=10,v=10,cp=0} -- taught points keep their own user and tool
-- Motion commands are queued. Wait() starts after the previous move has finished,
-- so it makes sure the robot stands still before detecting or switching the tool.
local function goto_detection()
MovJ(Detect,taught)
Wait(SETTLE_MS)
end
-- Add the tool actions of your application after the Wait() (glue, screw, ...).
local function enable_tool()
Wait(SETTLE_MS)
-- Add enable tool code here
end
local function disable_tool()
Wait(SETTLE_MS)
-- Add disable tool code here
end
local function format_pose(p)
local s={}
for i=1,6 do s[i]=string.format("%.2f",p.pose[i]) end
return "{"..table.concat(s,", ").."}"
end
-- Checks the end points only: the moves between them are not checked.
-- frame: the part in the robot base frame. The path points are taught relative to it.
local function reachable(frame)
for i,point in ipairs(PATH) do
local pose=pickit_pose_multiply(frame,point)
if InverseKin(pose,{user=0,tool=point.tool,useJointNear=true,jointNear={joint=point.joint}})~=0 then
print("Point"..i.." is not reachable")
return false
end
end
return true
end
if not TEACH then
for i,point in ipairs(PATH) do
assert(point.user==USER_FRAME,"Teach Point"..i.." in user coordinate system "..USER_FRAME
.." (it has user "..tostring(point.user)..")")
end
end
-- Main code and loop
MovJ(Home,taught)
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()
if pickit_object_found() then
-- The user frame is the pick frame of the part (Z axis into the part, like the tool).
local frame=PickitPick
if TEACH then
SetUser(USER_FRAME,frame.pose,1) -- saved: stays after the program ends
print("User frame "..USER_FRAME.." set to the part: "..format_pose(frame))
print("Now teach the path points in user frame "..USER_FRAME.." without moving the part, then set TEACH=false")
elseif reachable(frame) then
SetUser(USER_FRAME,frame.pose) -- for this run only
MovJ(PATH[1],taught)
enable_tool()
for i=2,#PATH do MovL(PATH[i],taught) end
disable_tool()
else
print("The part is not reachable")
end
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 part was found; saving a snapshot")
pickit_save_snapshot(0)
end
MovJ(Home,taught)
Teaching
With TEACH=true, the program follows the generic trajectory teaching logic:
It is checked whether or not Pickit is in robot mode. If not, the program stops.
The robot moves to
Detectand a detection is triggered.If a part is found, the user coordinate system
USER_FRAMEis set to the pick point of the part and saved. Its origin is the pick point, and its Z axis points into the part, like the tool Z axis.The robot returns to
Home.
Once the user coordinate system is set, teach the path points without moving the part:
teach Point1, Point2 and Point3 with the tool, in user coordinate system USER_FRAME.
Note
This program uses three path points as an example, but more points can be added to PATH if needed.
The robot moves from the last point to Home with a joint motion, so make sure the last point is a safe retreat pose.
Execution
With TEACH=false, the program follows the generic trajectory execution logic:
It is checked that all path points are taught in user coordinate system
USER_FRAME. If not, the program stops with the messageTeach Point<n> in user coordinate system <USER_FRAME>.It is checked whether or not Pickit is in robot mode. If not, the program stops.
The robot moves to
Detectand a detection is triggered, repeated when no part is found, up to 5 detections in total.If a part is found, the program checks that the robot can reach every path point on the detected part. Only the points themselves are checked, not the motions between them.
If the part is reachable, the user coordinate system
USER_FRAMEis set to the detected part, for this run only. The robot moves toPoint1with a joint motion, enables the tool, follows the path to the last point with linear motions, and disables the tool. If the part is not reachable, the robot does not follow the path, and the program logs which point is not reachable.The robot returns to
Homewith a joint motion.If no part is found, the program logs the reason: the ROI is empty, no image was captured, or the Pickit license is invalid. If no part is found and the ROI is not empty, a snapshot is also saved on the Pickit system.
Set correct input arguments
At the top of the program:
Set
TEACHtotrueto teach the user coordinate system, and tofalseto execute the path.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 part is found.
Define the user frame
Add a user coordinate system in DobotStudio Pro, in Settings > Coordinate system, and set USER_FRAME at the top of the program to its ID.
Any values can be used for this frame, since the program overwrites it with the pose of the detected part.
Define fixed points
In this program, 2 fixed points are used. Teach them in the points list of the project, with the tool, and keep their names as aliases.
Home: Where the robot starts and ends the program.
Detect: Where to perform object detection from.
There are also 3 points to be taught relative to the part, in user coordinate system USER_FRAME: Point1, Point2 and Point3, as described in Teaching.
Add tool logic
Add the actions of your application tool, such as welding or sanding, to the enable_tool() and disable_tool() functions, after the Wait() that is already there.
The Wait() makes sure the robot has arrived and stands still before the tool is switched.
Trajectory motion parameters
The path is followed with the taught motion settings, at 10% speed.
Adapt this to your specific application.
Execute the user frame 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.
First run the program with TEACH=true and teach the path points, then set TEACH=false and run the program.