ส่วนนี้แสดงวิธีปรับแต่งการกำหนดเฟรมของหน่วยประมวลผลที่มีอยู่ ตัวอย่างเช่น การกำหนดเฟรมแบบกำหนดเองสำหรับหุ่นยนต์ KUKA
คุณสามารถใช้หน่วยประมวลผลที่คอมไพล์ไว้แล้ว และเขียนใหม่เฉพาะฟังก์ชันที่จำเป็นได้อย่างง่ายดาย (เช่น setFrame, setTool หรือ setSpeed)
ในตัวอย่างนี้ สมมติว่าเราต้องการปรับแต่งวิธีการกำหนดเบสสำหรับตัวควบคุม KUKA ตัวอย่างเช่น หากคุณต้องการให้บรรทัดต่อไปนี้ถูกส่งออกเมื่อกำหนดเฟรม:
BASE_DATA[8] = {FRAME: X:2000, Y:0, Z:0, A:0, B:0, C:0}
BAS (#BASE,8)
คุณเพียงแค่ต้องสร้างไฟล์ใหม่ชื่อ KUKA_Custom_Post.py ในโฟลเดอร์ C:/RoboDK/Posts/ ด้วยโค้ดเพียงไม่กี่บรรทัดต่อไปนี้ ซึ่งใช้หน่วยประมวลผลมาตรฐาน 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('; --------------------------')