이섹션에서는기존포스트프로세서의참조좌표계설정을사용자지정하는방법을설명합니다. 예를들어 KUKA 로봇에사용자지정참조좌표계를설정하는경우입니다.
컴파일된포스트프로세서를사용하여필요한함수(예: setFrame, setTool, setSpeed)만쉽게재구현할수있습니다.
이예제에서는 KUKA 컨트롤러의베이스정의방식을사용자지정하고자한다고가정합니다. 예를들어참조좌표계를설정할때다음줄을출력하고싶다면:
BASE_DATA[8] = {FRAME: X:2000, Y:0, Z:0, A:0, B:0, C:0}
BAS (#BASE,8)
C:/RoboDK/Posts/ 폴더에다음몇줄을포함하는 KUKA_Custom_Post.py라는새파일을만들기만하면됩니다. 이파일은기본 KUKA_KRC2 포스트프로세서를사용하고참조좌표계설정(setFrame 함수)을재정의합니다:
from KUKA_KRC2 import RobotPost as MainPost
class RobotPost(MainPost):
def setFrame(self, pose, frame_id, frame_name):
"""Change the robot reference frame"""
self.addline('; BASE_DATA[8] = {FRAME: %s}' % (self.pose_2_str(pose)))
self.addline('BAS (#BASE,8)')
그러나특정조건에따라사용자지정필터를추가하여기본동작을사용할지사용자지정구현을사용할지필터링할수도있습니다. 이경우포스트프로세서파일은다음과같이수정할수있습니다:
from KUKA_KRC2 import RobotPost as MainPost
class RobotPost(MainPost):
def setFrame(self, pose, frame_id, frame_name):
"""Change the robot reference frame"""
if frame_name == "Frame 4": # Enter any condition here
# Trigger the call to the default method (same as not overriding the function)
super(MainPost, self).setFrame(pose, frame_id, frame_name)
return
# Implement a custom setFrame
self.addline('; ---- Setting reference: %s ----' % frame_name)
self.addline('; BASE_DATA[8] = {FRAME: %s}' % (self.pose_2_str(pose)))
self.addline('BAS (#BASE,8)')
self.addline('; --------------------------')
KUKA KRC 컨트롤러용프로그램을생성할때좌표계또는참조좌표계를설정하는방법은여러가지가있습니다. 다음 setFrame 정의는다양한옵션을사용한대체구현예를보여줍니다:
def setFrame(self, pose, frame_id, frame_name):
"""Change the robot reference frame"""
self.addline('; ---- Setting reference: %s ----' % frame_name)
# option 1: Build the kinematics based on the MACHINE_DEF array and the provided offset
#self.addline('$BASE = EK (MACHINE_DEF[2].ROOT, MACHINE_DEF[2].MECH_TYPE, { %s })' % self.pose_2_str(pose))
# option 2: Build the kinematics based on the EX_AX_DATA array and the provided offset
#self.addline('$BASE=EK(EX_AX_DATA[1].ROOT,EX_AX_DATA[1].EX_KIN, { %s })' % self.pose_2_str(pose))
# Option 3: Build the kinematics based on the EX_AX_DATA array and the pre-defined offset
#self.addline('; Using external axes')
#self.addline('; $BASE=EK(EX_AX_DATA[1].ROOT,EX_AX_DATA[1].EX_KIN,EX_AX_DATA[1].OFFSET)')
#self.addline('; $ACT_EX_AX= %i' % (self.nAxes - 6))
# Option 4: Use the BAS(#ex_BASE) init function from the BAS.src file
#self.addline('; BASE_DATA[%i] = {FRAME: %s}' % (self.BASE_ID, self.pose_2_str(pose)))
#self.addline('BAS(#ex_BASE,%i)' % self.BASE_ID)
# Option 5: Use the BAS(#BASE) init function from the BAS.src file
self.addline('; BASE_DATA[%i] = {FRAME: %s}' % (self.BASE_ID, self.pose_2_str(pose)))
self.addline('BAS (#BASE,%i)' % self.BASE_ID)
# Option 6: Directly take the base from the BASE_DATA array (usually what the BAS(#BASE) does)
# self.addline('$BASE=BASE_DATA[%i]' % self.BASE_ID)
self.addline('; --------------------------')