MODBUS 통신으로 URscript 와 pyqt 연동 프로그래밍

스트립트의 자유도란...

by DEV2KNG


May 3, 2022, 4:03 a.m.


MODBUS 통신으로 URscript 와 pyqt 연동

URscript 와 pyqt5를 활용하여 MODBUS 통신을 간단하게 구현해보았습니다.


가공 공정이 필요한 상황을 가정하여 가공기가 작동 중일 때 건조도를 체크하여 적제하고,

가공기 작동이 끝나면 자동으로 팔레타이징 동작까지 이어지는 코드입니다.


코드의 특장점은 배열의 특성을 살려 포스 적제 시 웨이포인트를 배열에 저장하여, 

추후 적제 물건을 다시 옮길 시 다른 확인 작업 없이 리스트에서 웨이포인트를 바로 가져와서 활용할 수 있습니다.


아직 부족한 점이 많은 코드지만 통신, pyqt, 스크립트 모두 활용하여 구현했다는 것에 의의를 두고 있습니다.


# waypoint
def set_xyz_position(x_point, y_point, z_point):
default_postion = p[x_point, y_point, z_point, 2.224, -2.262, 0.03]
return default_postion
end

before_item_count = 0
after_item_count = 0

working_flag = False
workend_flag = False
conveyor_flag = False


pick_point_up = set_xyz_position(0.05, -0.25, 0.13)
pick_point_down = set_xyz_position(0.05, -0.25, 0.07)
return_point_up = set_xyz_position(-0.25, -0.25, 0.13)
return_point_down = set_xyz_position(-0.25, -0.25, 0.08)
before_work_item = set_xyz_position(0.23, -0.29, 0.13) # 포스 사용 예정
working_item_up = set_xyz_position(0.23, -0.23, 0.13) # 하나만 적재가능
working_item_down = set_xyz_position(0.23, -0.17, 0.02) # 하나만 적재가능

waypoint_list = [pick_point_up, pick_point_up, pick_point_up]


# 시작 프로그램

set_standard_digital_out(0, False)
set_standard_digital_out(1, False)
rg_grip(45, 30)
# set_standard_analog_out(1, 1.0)
# while (get_standard_digital_in(2) == False):
# sync()
# end
# movej(pick_point_up)
# movel(pick_point_down)
# sync()
# rg_grip(25, 30)
# movel(pick_point_up)
# sync()

# popup(str_cat("",get_standard_analog_in(0)), "건조도", False, False, blocking=True)
# if get_standard_analog_in(0) > 7:
# movej(working_item_up)
# movel(working_item_down)
# sync()
# rg_grip(45, 30)
# movel(working_item_up)
# sync()
# working_flag = True
# else :
# movej(return_point_up)
# movel(return_point_down)
# sync()
# rg_grip(45, 30)
# end

def dry_check():
# 매번 초기화 되어야하는 웨이포인트
work_flag = read_port_register(128)
if (work_flag == 1):
y_postion = -0.29 + 0.06 * after_item_count
after_work_item_up = set_xyz_position(0.29, y_postion, 0.13) # 팔레타이징
after_work_item_down = set_xyz_position(0.29, y_postion, 0.02) # 팔레타이징
popup("작업 진행중...","작업상태", False, False, blocking=False)
sync()
# 0 & 0 상태
if get_standard_digital_out(0) == False and get_standard_digital_out(1) == False:
if conveyor_flag == True:
movej(pick_point_up)
movel(pick_point_down)
sync()
rg_grip(25, 30)
movel(pick_point_up)
sync()
popup(str_cat("",get_standard_analog_in(0)), "건조도", False, False, blocking=False)
if get_standard_analog_in(0) > 7:
movel(pick_point_up)
movej(working_item_up)
movel(working_item_down)
sync()
rg_grip(45, 40)
movel(working_item_up)
sync()
global conveyor_flag = False
set_standard_digital_out(1, True)
sync()
else :
movej(return_point_up)
movel(return_point_down)
sync()
rg_grip(45, 30)
end
end

# 0 & 1 상태 ( 작동 중 )
elif get_standard_digital_out(0) == False and get_standard_digital_out(1) == True:
if conveyor_flag == True:
movej(pick_point_up)
movel(pick_point_down)
sync()
rg_grip(25, 30)
movel(pick_point_up)
sync()
popup(str_cat("",get_standard_analog_in(0)), "건조도", False, False, blocking=False)
if get_standard_analog_in(0) > 7:
movel(pick_point_up)
movej(before_work_item)
sync()
force_active(-3)
waypoint_list[before_item_count] = get_actual_tcp_pose()
rg_grip(45, 30)
global before_item_count = before_item_count + 1
global conveyor_flag = False
movel(before_work_item)
sync()
else :
movej(return_point_up)
movel(return_point_down)
sync()
rg_grip(45, 30)
end
end

# 1 & 1 상태 (작업완료)
elif get_standard_digital_out(0) == True and get_standard_digital_out(1) == True:
movej(working_item_up)
movel(working_item_down)
sync()
rg_grip(25, 30)
movel(working_item_up)
write_port_register(129, 0)
movej(after_work_item_up)
movel(after_work_item_down)
sync()
rg_grip(45, 30)
movel(after_work_item_up)
sync()
global after_item_count = after_item_count + 1
if after_item_count == 3:
popup("작업대가 꽉 찼습니다. 비워주세요.", "주의", False, False, blocking=True)
global after_item_count = 0
end

# 작업 대기줄에 작업물이 있다면
if before_item_count > 0:
movej(before_work_item)
movel(waypoint_list[before_item_count-1]) # 상대위치
sync()
rg_grip(25, 30)
movel(before_work_item)
movej(working_item_up)
movel(working_item_down)
sync()
rg_grip(45, 30)
movel(working_item_up)
sync()
global before_item_count = before_item_count - 1
set_standard_digital_out(0, False)
set_standard_digital_out(1, True)
# popup("작업이 완료되었습니다. 작업물의 상태를 확인하여 주세요.", "확인 필요", False, False, blocking=True)
# 작업 대기줄에 작업물이 없고, 컨베어엔 있을 때
elif conveyor_flag == True:
movej(pick_point_up)
movel(pick_point_down)
sync()
rg_grip(25, 30)
movel(pick_point_up)
sync()
popup(str_cat("",get_standard_analog_in(0)), "건조도", False, False, blocking=False)
if get_standard_analog_in(0) > 7:
movel(pick_point_up)
movej(working_item_up)
movel(working_item_down)
sync()
rg_grip(45, 40)
movel(working_item_up)
sync()
global conveyor_flag = False
set_standard_digital_out(0, False)
set_standard_digital_out(1, True)
else :
movej(return_point_up)
movel(return_point_down)
sync()
rg_grip(45, 30)
end

# 작업물이 없다면 작업 소강상태
else:
set_standard_digital_out(0, False)
set_standard_digital_out(1, False)
end
# 0 & 1 또는 예상치 못한 error 발생 상태
else :
popup("장비 상태가 불량합니다 점검해주세요.", "작업 경고", False, False, blocking=True)
end
else:
popup("작업 대기중...","작업상태", False, False, blocking=False)
end
if get_standard_digital_out(0) == False:
write_port_register(129, 0)
sync()
end
if get_standard_digital_out(1) == False:
write_port_register(130, 0)
sync()
end
if get_standard_digital_out(0) == True:
write_port_register(129, 1)
sync()
end
if get_standard_digital_out(1) == True:
write_port_register(130, 1)
sync()
end
end


def force_active(force_power):
sleep(0.3)
zero_ftsensor()
sleep(0.2)
sleep(0.02)
zero_ftsensor()
force_mode(p[0.0,0.0,0.0,0.0,0.0,0.0], [0, 0, 1, 0, 0, 0], [0.0, 0.0, force_power, 0.0, 0.0, 0.0], 2, [0.1, 0.1, 0.15, 0.35, 0.35, 0.35])
# 절대값으로 반환
if force_power < 0:
force_power = -force_power
end
while (not(force()> 2 * force_power)):
sync()
end
end_force_mode()
stopl(5.0)
end

thread conveyor_thread():
while (True):
set_standard_analog_out(1, 1.0)
while (get_standard_digital_in(2) == False):
sync()
end
set_standard_analog_out(1, 0.0)
while (get_standard_digital_in(2) == True):
sync()
end
end
end

conveyor_thr = run conveyor_thread()

thread working_thread():
while (True):
if get_standard_digital_out(1) == True:
sleep(10)
set_standard_digital_out(0, True)
write_port_register(129, 1)
end
sleep(0.1)
end
end

working_thr = run working_thread()

thread EventThread():
while (True):
if get_standard_digital_in(2) == True:
global conveyor_flag = True
sync()
elif get_standard_analog_in(0) > 7:
set_standard_analog_out(0, 10.0)
sync()
elif get_standard_digital_in(0) > 3:
set_standard_analog_out(0, 5.0)
sync()
elif get_standard_analog_in(0) > 0:
set_analog_out(0, 0)
sync()
end
end
end

eventThread = run EventThread()

로봇 파이썬

Download: script work_sim_network.script
Leave a Comment: