本节介绍如何修改机器人后处理器,以便在执行3D 打印的运动指令前计算挤出机速度。另外,也可以在机器人控制器上通过挤出机程序调用(驱动挤出机的默认指令)进行这些操作。
通过自定义机器人后处理器,可以在将程序发送至机器人之前,更轻松地集成3D打印挤出机。为实现这一目标,我们需要在机器人后置处理器生成程序时进行相关计算并输出定制化代码。
Note:部分后处理器(如ABB RAPID IRC5、KUKA KRC2和Comau后处理器)默认已实现这些建议的修改。
第一步是拦截挤出机调用,并在后处理器的RunCode部分读取新的挤出机值(E值)。以下部分处理为程序生成的所有程序调用:
def RunCode(self, code, is_function_call = False):
if is_function_call:
if code.startswith("Extruder("):
# Intercept the extruder command.
# if the program call is Extruder(123.56)
# we extract the number as a string
# and convert it to a number
self.PRINT_E_NEW = float(code[9:-1])
# Skip the program call generation
return
else:
self.addline(code + "()")
else:
# Output program code
self.addline(code)
挤出机数值(长度/E)在机器人后处理器中被保存为PRINT_E_NEW变量。
我们需要在每个新的线性运动指令处触发名为new_move的函数调用。可以在MoveL命令的开头添加这个调用:
def MoveL(self, pose, joints, conf_RLF=None):
"""Add a linear movement"""
# Handle 3D printing Extruder integration
self.new_move(pose)
...
我们还必须在后处理器的文件头部添加以下变量以计算挤出机增量:
# 3D Printing Extruder Setup Parameters:
PRINT_E_AO = 5 # Analog Output ID to command the extruder flow
PRINT_SPEED_2_SIGNAL = 0.10 # Ratio to convert the speed/flow to an analog output signal
PRINT_FLOW_MAX_SIGNAL = 24 # Maximum signal to provide to the Extruder
PRINT_ACCEL_MMSS = -1 # Acceleration, -1 assumes constant speed if we use rounding/blending
# Internal 3D Printing Parameters
PRINT_POSE_LAST = None # Last pose printed
PRINT_E_LAST = 0 # Last Extruder length
PRINT_E_NEW = None # New Extruder Length
PRINT_LAST_SIGNAL = None # Last extruder signal
最后,我们需要定义一个新的程序,该程序将根据运动间距、机器人速度和机器人加速度生成适当的挤出机进给指令。这需要假设挤出机进给是由特定的模拟输出或自定义程序调用驱动的。
我们需要在 def MoveL 程序定义前添加以下代码。
Important:在RoboDK中为机器人编程时使用四舍五入值有助于保持恒定速度并减少加速度行为的影响。此时,时间可按距离/速度计算得出。
def calculate_time(self, distance, Vmax, Amax=-1):
"""Calculate the time to move a distance with Amax acceleration and Vmax speed"""
if Amax < 0:
# Assume constant speed (appropriate smoothing/rounding parameter must be set)
Ttot = distance/Vmax
else:
# Assume we accelerate and decelerate
tacc = Vmax/Amax;
Xacc = 0.5*Amax*tacc*tacc;
if distance <= 2*Xacc:
# Vmax is not reached
tacc = sqrt(distance/Amax)
Ttot = tacc*2
else:
# Vmax is reached
Xvmax = distance - 2*Xacc
Tvmax = Xvmax/Vmax
Ttot = 2*tacc + Tvmax
return Ttot
def new_move(self, new_pose):
"""Implement the action on the extruder for 3D printing, if applicable"""
if self.PRINT_E_NEW isNone or new_pose is None:
return
# Skip the first move and remember the pose
if self.PRINT_POSE_LAST isNone:
self.PRINT_POSE_LAST = new_pose
return
# Calculate the increase of material for the next movement
add_material = self.PRINT_E_NEW - self.PRINT_E_LAST
self.PRINT_E_LAST = self.PRINT_E_NEW
# Calculate the robot speed and Extruder signal
extruder_signal = 0
if add_material > 0:
distance_mm = norm(subs3(self.PRINT_POSE_LAST.Pos(), new_pose.Pos()))
# Calculate movement time in seconds
time_s = self.calculate_time(distance_mm, self.SPEED_MMS, self.PRINT_ACCEL_MMSS)
# Avoid division by 0
if time_s > 0:
# This may look redundant but it allows you to account for accelerations and we can apply small speed adjustments
speed_mms = distance_mm / time_s
# Calculate the extruder speed in RPM*Ratio (PRINT_SPEED_2_SIGNAL)
extruder_signal = speed_mms * self.PRINT_SPEED_2_SIGNAL
# Make sure the signal is within the accepted values
extruder_signal = max(0,min(self.PRINT_FLOW_MAX_SIGNAL, extruder_signal))
# Update the extruder speed when required
if self.PRINT_LAST_SIGNAL isNone or abs(extruder_signal - self.PRINT_LAST_SIGNAL) > 1e-6:
self.PRINT_LAST_SIGNAL = extruder_signal
# Use the built-in setDO function to set an analog output
self.setDO(self.PRINT_E_AO, "%.3f" % extruder_signal)
# Alternatively, provoke a program call and handle the integration with the robot controller
#self.addline('ExtruderSpeed(%.3f)' % extruder_signal)
# Remember the last pose
self.PRINT_POSE_LAST = new_pose