# 导入必要的库import math# 定义快装接头的参数inch_to_mm = 25.4inch_length = 1inch_width = 1inch_thickness = 0.03937 # 1毫米=0.03937英寸mm_length = inch_length * inch_to_mmmm_width = inch_width * inch_to_mmmm_thickness = inch_thickness * inch_to_mm# 计算槽的尺寸和角度slot_width = mm_width + 2 * mm_thicknessslot_length = mm_length + mm_thicknessslot_angle = math.atan(mm_thickness / mm_width) # 计算斜面角度slot_depth = mm_thickness * math.tan(slot_angle) # 计算槽深# 设置切割参数cutting_tool_radius = 2 # 切割刀半径,单位:毫米cutting_tool_height = mm_thickness # 切割刀高度,单位:毫米feed_rate = 100 # 进给速率,单位:毫米/分钟cutting_speed = 1000 # 切割速度,单位:转/分钟# 计算切割路径start_point = (0, 0) # 起始点,单位:毫米end_point = (mm_length, mm_width) # 终点,单位:毫米cutting_path = [(start_point[0], start_point[1]), (start_point[0], end_point[1]), (end_point[0], end_point[1]), (end_point[0], start_point[1])] # 四边形路径,单位:毫米# 输出程序代码print(f"G90") # 使用绝对坐标模式进行切割print(f"G21") # 设置切割单位为毫米print(f"G28") # 返回参考点位置print(f"G92 X{start_point[0]} Y{start_point[1]} Z{mm_thickness}") # 设置当前位置为起始点,并设置切割高度为mm_thicknessprint(f"G0 X{start_point[0]} Y{start_point[1]} F{feed_rate}") # 快速移动到起始点位置print(f"G1 X{cutting_path[0][0]} Y{cutting_path[0][1]} F{feed_rate}") # 沿着切割路径移动到第一个点位置,并设置进给速率为feed_ratefor i in range(1, len(cutting_path)): # 从第二个点开始循环遍历切割路径 print(f"G1 X{cutting_path[i][0]} Y{cutting_path[i][1]} F{feed_rate}") # 沿着切割路径移动到下一个点位置,并设置进给速率为feed_rateprint(f"G1 X{end_point[0]} Y{end_point[1]} F{feed_rate}") # 沿着切割路径移动到终点位置,并设置进给速率为feed_rate