本节介绍如何为现有后处理器自定义设置参考坐标系。例如,为KUKA机器人设置自定义参考坐标系。

你可以使用已编译的后置处理器,并仅重新实现必要的功能数(例如setFrame setTool 或 setSpeed)。

Note:请确保你的自定义后处理器名称与引用的原始后处理器名称不同。当你更新RoboDK时,安装程序会将默认后处理器覆盖回原始版本,但不会删除或修改Posts文件夹中的自定义后处理器。

在本示例中,我们假设需要自定义库卡(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)控制器生成程序时,可通过多种方式设置坐标系或参考框架。以下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('; --------------------------')