proc main {} {
global mom_sys_tool_name
global mom_path_mode
global mom_output_unit
# 初始化输出文件
set outFile [open "output_Baxis_advanced.nc" "w"]
# 写入G代码头部信息
puts $outFile "G21 ; Set units to mm"
puts $outFile "G17 ; Select XY plane"
puts $outFile "G90 ; Absolute programming"
# 初始化旋转轴位置和偏置
set b_axis 0
set x_offset 0
set y_offset 0
set z_offset 0
# 写入刀具信息
puts $outFile "T1 M6 ; Tool change to T1"
puts $outFile "S5000 M3 ; Spindle on clockwise at 5000 rpm"
# 处理刀具路径
foreach path [mom_get_path] {
set x [lindex $path 0]
set y [lindex $path 1]
set z [lindex $path 2]
set b [lindex $path 3] ; B轴的位置
set x_off [lindex $path 4]
set y_off [lindex $path 5]
set z_off [lindex $path 6]
# 判断B轴是否发生变化
if {$b != $b_axis} {
puts $outFile "G0 B$b ; Rotate to new B position"
set b_axis $b
}
# 更新坐标偏置
if {$x_off != $x_offset || $y_off != $y_offset || $z_off != $z_offset} {
puts $outFile "G65 P9001 X$x_off Y$y_off Z$z_off ; Set coordinate offset"
set x_offset $x_off
set y_offset $y_off
set z_offset $z_off
}