Breadcrumbs

생성 코드 분석

팔레트 경로생성 결과 나타난 코드에 대한 예제입니다. 생성코드는 5개의 프로덕트를 옮기는 팔레타이징 작업입니다.


Python
import math as pymath
drl_report_line(OFF)

##### define template functions
#define gripper grasp signal
def grasp_gripper():
    pass #remove pass and code here

#define gripper release signal
def release_gripper():
    pass #remove pass and code here

#define lift control function
def set_lift_z(z):
    pass #remove pass and code here

def get_lift_z():
    pass #remove pass and code here

#define device initialization
def begin_device():
    pass #remove pass and code here

#define device cleanup
def end_device():
    pass #remove pass and code here

#define Robot Initial Configuration
def initial_configuration():
    pass #remove pass and code here


#define minimum joint IK solution function
def min_jvector_sol(targetpose, coordinate):
    jcur = get_current_posj()
    sumjsol = [0, 0, 0, 0, 0, 0, 0, 0]
    for i in range(0, 8):
        jsol = ikin(targetpose, i, coordinate)
        sumjsol[i] = abs(jcur[1] - jsol[1]) + abs(jcur[2] - jsol[2]) + abs(jcur[4] - jsol[4])
    minsol_idx = sumjsol.index(min(sumjsol))
    return minsol_idx

#define job motion
def job_motion(userAppPose, userJobPose, userRetPose, userCoord, worldCoord, action):
    overwrite_user_cart_coord(worldCoord, posx(0,0,0,0,0,0), ref= DR_BASE)
    appPose = coord_transform(userAppPose, userCoord, coord_w)
    jobPose = coord_transform(userJobPose, userCoord, coord_w)
    retPose = coord_transform(userRetPose, userCoord, coord_w)
    #go to intermediate approach position
    curPose, sol = get_current_posx(DR_BASE)
    if appPose[2] <  curPose[2]:
        interPose = trans(appPose, [0,0,curPose[2]-appPose[2],0,0,0],DR_BASE)
        interPoseSol = min_jvector_sol(interPose, DR_BASE)
        movejx(interPose, vel=g_jointVel, acc=g_jointAcc, sol=interPoseSol, ref=DR_BASE)
    else:
        interPose = trans(curPose, [0,0,appPose[2]-curPose[2],0,0,0],DR_BASE)
        interPoseSol = min_jvector_sol(interPose, DR_BASE)
        movejx(interPose, vel=g_jointVel, acc=g_jointAcc, sol=interPoseSol, ref=DR_BASE)
    
    #go to approach position
    appPoseSol = min_jvector_sol(appPose, DR_BASE)
    movejx(appPose, vel=g_jointVel, acc=g_jointAcc, sol=appPoseSol, ref=DR_BASE)
    
    #go to source working pose
    movel(jobPose, vel=g_appVel, acc=g_appAcc, ref=DR_BASE)
    
    #do gripper action
    action()
    
    #go to retraction pose
    movel(retPose, vel=g_retVel, acc=g_retAcc, ref=DR_BASE)

##### global variables
g_jointVel = 30.0
g_jointAcc = 60.0
g_appVel = 500.0
g_appAcc = 1000.0
g_retVel = 500.0
g_retAcc = 1000.0
lift_zmin = 0.0
lift_zmax = 0.0
lift_z0 = 0.0
lift_zstep = 0.0
g_retAcc = 1000.0

##### job poses
#define PickPattern pattern approach pose in plate coordinate
PickPattern_app_poses = [None] * 5
PickPattern_app_poses[0] = posx(-7.7, -7.7, 157.7, 90.0, 180.0, 0.0)
PickPattern_app_poses[1] = posx(150.0, -20.7, 170.7, 90.0, 180.0, 0.0)
PickPattern_app_poses[2] = posx(507.7, -7.7, 157.7, 90.0, 180.0, 0.0)
PickPattern_app_poses[3] = posx(250.0, -20.7, 170.7, 90.0, 180.0, 0.0)
PickPattern_app_poses[4] = posx(350.0, -20.7, 170.7, 90.0, 180.0, 0.0)
#define PickPattern pattern job pose in plate coordinate
PickPattern_job_poses = [None] * 5
PickPattern_job_poses[0] = posx(50.0, 50.0, 100.0, 90.0, 180.0, 0.0)
PickPattern_job_poses[1] = posx(150.0, 50.0, 100.0, 90.0, 180.0, 0.0)
PickPattern_job_poses[2] = posx(450.0, 50.0, 100.0, 90.0, 180.0, 0.0)
PickPattern_job_poses[3] = posx(250.0, 50.0, 100.0, 90.0, 180.0, 0.0)
PickPattern_job_poses[4] = posx(350.0, 50.0, 100.0, 90.0, 180.0, 0.0)
#define PickPattern pattern retract pose in plate coordinate
PickPattern_ret_poses = [None] * 5
PickPattern_ret_poses[0] = posx(50.0, 50.0, 200.0, 90.0, 180.0, 0.0)
PickPattern_ret_poses[1] = posx(150.0, 50.0, 200.0, 90.0, 180.0, 0.0)
PickPattern_ret_poses[2] = posx(450.0, 50.0, 200.0, 90.0, 180.0, 0.0)
PickPattern_ret_poses[3] = posx(250.0, 50.0, 200.0, 90.0, 180.0, 0.0)
PickPattern_ret_poses[4] = posx(350.0, 50.0, 200.0, 90.0, 180.0, 0.0)
#calibration points
PickPattern_coord_point_org = posx(500.0, 500.0, 0.0, 0, 0, 0)
PickPattern_coord_point_u1 = posx(550.0, 500.0, 0.0, 0, 0, 0)
PickPattern_coord_point_u2 = posx(500.0, 550.0, 0.0, 0, 0, 0)
#set plate coordinate
PickPattern_coord_plate_to_base = set_user_cart_coord(PickPattern_coord_point_org, PickPattern_coord_point_u1, PickPattern_coord_point_u2, PickPattern_coord_point_org, DR_WORLD)

#define PlacePattern pattern approach pose in plate coordinate
PlacePattern_app_poses = [None] * 5
PlacePattern_app_poses[0] = posx(-7.7, -7.7, 157.7, 90.0, 180.0, 0.0)
PlacePattern_app_poses[1] = posx(150.0, -20.7, 170.7, 90.0, 180.0, 0.0)
PlacePattern_app_poses[2] = posx(507.7, -7.7, 157.7, 90.0, 180.0, 0.0)
PlacePattern_app_poses[3] = posx(250.0, -20.7, 170.7, 90.0, 180.0, 0.0)
PlacePattern_app_poses[4] = posx(350.0, -20.7, 170.7, 90.0, 180.0, 0.0)
#define PlacePattern pattern job pose in plate coordinate
PlacePattern_job_poses = [None] * 5
PlacePattern_job_poses[0] = posx(50.0, 50.0, 100.0, 90.0, 180.0, 0.0)
PlacePattern_job_poses[1] = posx(150.0, 50.0, 100.0, 90.0, 180.0, 0.0)
PlacePattern_job_poses[2] = posx(450.0, 50.0, 100.0, 90.0, 180.0, 0.0)
PlacePattern_job_poses[3] = posx(250.0, 50.0, 100.0, 90.0, 180.0, 0.0)
PlacePattern_job_poses[4] = posx(350.0, 50.0, 100.0, 90.0, 180.0, 0.0)
#define PlacePattern pattern retract pose in plate coordinate
PlacePattern_ret_poses = [None] * 5
PlacePattern_ret_poses[0] = posx(50.0, 50.0, 200.0, 90.0, 180.0, 0.0)
PlacePattern_ret_poses[1] = posx(150.0, 50.0, 200.0, 90.0, 180.0, 0.0)
PlacePattern_ret_poses[2] = posx(450.0, 50.0, 200.0, 90.0, 180.0, 0.0)
PlacePattern_ret_poses[3] = posx(250.0, 50.0, 200.0, 90.0, 180.0, 0.0)
PlacePattern_ret_poses[4] = posx(350.0, 50.0, 200.0, 90.0, 180.0, 0.0)
#calibration points
PlacePattern_coord_point_org = posx(-500.0, 500.0, 0.0, 0, 0, 0)
PlacePattern_coord_point_u1 = posx(-500.0, 550.0, 0.0, 0, 0, 0)
PlacePattern_coord_point_u2 = posx(-550.0, 500.0, 0.0, 0, 0, 0)
#set plate coordinate
PlacePattern_coord_plate_to_base = set_user_cart_coord(PlacePattern_coord_point_org, PlacePattern_coord_point_u1, PlacePattern_coord_point_u2, PlacePattern_coord_point_org, DR_WORLD)

drl_report_line(ON)
##### robot motion
begin_device()

PickPattern_productCount = 5
PlacePattern_productCount = 5
PickPattern_loopCount = 0
PlacePattern_loopCount = 0
PickPattern_productHeight = 100.0
PlacePattern_productHeight = 100.0
coord_w = set_user_cart_coord(posx(0, 0, 0, 0, 0, 0), ref = DR_WORLD) # world
##### robot initial motion
initial_configuration()

while True:
    if PickPattern_loopCount < PickPattern_productCount:
        pySimLogAction = 'data = palletsim, action = grasp, target = PickPattern[{}]'.format(PickPattern_loopCount)
        job_motion(PickPattern_app_poses[PickPattern_loopCount], PickPattern_job_poses[PickPattern_loopCount], PickPattern_ret_poses[PickPattern_loopCount], PickPattern_coord_plate_to_base, coord_w, grasp_gripper)
        PickPattern_loopCount = PickPattern_loopCount + 1

    if PlacePattern_loopCount < PlacePattern_productCount:
        pySimLogAction = 'data = palletsim, action = release'
        job_motion(PlacePattern_app_poses[PlacePattern_loopCount], PlacePattern_job_poses[PlacePattern_loopCount], PlacePattern_ret_poses[PlacePattern_loopCount], PlacePattern_coord_plate_to_base, coord_w, release_gripper)
        PlacePattern_loopCount = PlacePattern_loopCount + 1


    #check escape condition
    if PickPattern_loopCount == PickPattern_productCount and PlacePattern_loopCount == PlacePattern_productCount:
        break

#clean up device
end_device()