###############################################################################
#
# DESCRIPTION
#
# This section contains the base section for all post processors.
# It sets the default G and M codes.
# If any of the procs do not exist in the EVENT HANDLER tcl file,ie, an
# event is triggered from the event generator without the proc,
# warnings are generated.
# If there is a proc which needs to be in all post processors without the
# user modifying it, put it here,eg, mom_pprint and mom_operator_message.
#
#
# REVISIONS
#
# Date Who Reason
# 22May1998 whb Initial
# 02Jul1998 whb Update FEEDRATE_SET and commentary output
# 08Jul1998 whb close files
# 30Jul1998 MKG MOM_catch_warning automatically handles min-max errors.
# $HISTORY$
#
################################################################################
# BASE SECTION
# This section contains the base section for all post processors.
# If any of the files doesn't exit in the EVENT HANDLER tcl file,
# Warnings are generated
################################################################################
#_______________________________________________________________________________
# Default G/M codes
#_______________________________________________________________________________
set mom_sys_program_stop_code 0
set mom_sys_optional_stop_code 1
set mom_sys_end_of_program_code 2
set mom_sys_spindle_direction_code(CLW) 3
set mom_sys_spindle_direction_code(CCLW) 4
set mom_sys_spindle_direction_code(OFF) 5
set mom_sys_tool_change_code 6
set mom_sys_coolant_code(MIST) 7
set mom_sys_coolant_code(FLOOD) 8
set mom_sys_coolant_code(TAP) 8
set mom_sys_coolant_code(OFF) 9
set mom_sys_clamp_code(ON) 10
set mom_sys_clamp_code(OFF) 11
set mom_sys_clamp_code(AXISON) 10
set mom_sys_clamp_code(AXISOFF) 11
set mom_sys_rapid_code 0
set mom_sys_linear_code 1
set mom_sys_circle_code(CLW) 2
set mom_sys_circle_code(CCLW) 3
set mom_sys_delay_code(REVOLUTIONS) 4
set mom_sys_delay_code(SECONDS) 4
set mom_sys_cutcom_plane_code(XY) 17
set mom_sys_cutcom_plane_code(ZX) 18
set mom_sys_cutcom_plane_code(YZ) 19
set mom_sys_cutcom_code(OFF) 40
set mom_sys_cutcom_code(LEFT) 41
set mom_sys_cutcom_code(RIGHT) 42
set mom_sys_inch_code 70
set mom_sys_metric_code 71
set mom_sys_cycle_breakchip_code 73
set mom_sys_cycle_bore_no_drag_code 76
set mom_sys_cycle_off 80
set mom_sys_cycle_drill_code 81
set mom_sys_cycle_drill_dwell_code 82
set mom_sys_cycle_drill_deep_code 83
set mom_sys_cycle_tap_code 84
set mom_sys_cycle_bore_code 85
set mom_sys_cycle_bore_drag_code 86
set mom_sys_cycle_bore_back_code 87
set mom_sys_cycle_bore_manual_code 88
set mom_sys_cycle_bore_manual_dwell_code 89
set mom_sys_cycle_bore_dwell_code 89
set mom_sys_output_code(ABSOLUTE) 90
set mom_sys_output_code(INCREMENTAL) 91
#_______________________________________________________________________________
# Global Variable Declaration
#_______________________________________________________________________________
set mom_sys_list_file_columns 80
set mom_sys_list_file_rows 20
set mom_sys_commentary_output ON
#_______________________________________________________________________________
set PI [expr 2.0 * asin(1.0)] ; #value PI
set RAD2DEG [expr 90.0 / asin(1.0)] ; #multiplier to convert radians to degrees
set DEG2RAD [expr asin(1.0) / 90.0] ; #multiplier to convert degrees to radians
#_______________________________________________________________________________
proc MOM_start_of_program {} {
#_______________________________________________________________________________
# This procedure is executed at the very begining of the program.
# It gets called before any command is read from the task file.
#_______________________________________________________________________________
global warn_file
global mom_sys_list_file_columns
global warn_count
global list_file
OPEN_files
LIST_FILE_HEADER
puts $warn_file "MISSING EVENT HANDLER: Event Name: MOM_start_of_program"
puts $list_file "MISSING EVENT HANDLER: Event Name: MOM_start_of_program"
incr warn_count +1
}
proc MOM_end_of_program {} {
#_______________________________________________________________________________
# This procedure is executed at the end of the program after all
# the paths are traversed.
#_______________________________________________________________________________
global warn_file
global list_file
global warn_count
LIST_FILE_TRAILER
CLOSE_files
puts $warn_file "MISSING EVENT HANDLER: Event Name: MOM_end_of_program"
puts $list_file "MISSING EVENT HANDLER: Event Name: MOM_end_of_program"
incr warn_count +1
}
proc MOM_before_output {} {
#_______________________________________________________________________________
# This procedure is executed just before a line is about to be output
# to the file. It loads the line into a variable MOM_o_buffer and then calls
# this procedure. When it returns from this procedure, the variable MOM_o_buffer
# is read and written to the file.
#_______________________________________________________________________________
#########The following procedure invokes the listing file with warnings.
LIST_FILE
}
proc MOM_pprint {} {
#_______________________________________________________________________________
# This procedure is executed when the PPrint command is activated.
#_______________________________________________________________________________
PPRINT_OUTPUT
}
proc MOM_operator_message {} {
#_______________________________________________________________________________
# This procedure is executed when the Operator Message command is activated.
#_______________________________________________________________________________
global mom_operator_message
if {$mom_operator_message != "ON" && $mom_operator_message != "OFF"} {
MOM_output_literal "$mom_operator_message"
}
}
proc MOM_before_motion {} {
#_______________________________________________________________________________
# This procedure is executed before the motion event is activated.
#_______________________________________________________________________________
FEEDRATE_SET
}
proc FEEDRATE_SET {} {
#_______________________________________________________________________________
# This procedure is executed when the Feedrate is set.
#_______________________________________________________________________________
global feed
global mom_motion_type
global mom_cycle_feed_rate_mode mom_cycle_feed_rate
global mom_feed_rate_output_mode
global mom_feed_rate mom_feed_rate_per_rev mom_feed_rate_number
global mom_warning_info
global Feed_IPM Feed_IPR Feed_MMPM Feed_MMPR Feed_INV
if { $mom_motion_type != "CYCLE" } {
if { $mom_motion_type == "RAPID" || $mom_motion_type == "FROM" || \
($mom_feed_rate == 0 && $mom_feed_rate_per_rev == 0)} { return
} else {
set mode $mom_feed_rate_output_mode
set f_pm $mom_feed_rate
set f_pr $mom_feed_rate_per_rev
}
} else {
if {[hiset mom_cycle_feed_rate_mode]} {
set mode $mom_cycle_feed_rate_mode
} else {
set mode $mom_feed_rate_output_mode
}
if {[hiset mom_cycle_feed_rate]} {
set f_pm $mom_cycle_feed_rate
} else {
set f_pm $mom_feed_rate
}
if {[hiset mom_cycle_feed_rate_per_rev]} {
set f_pr $mom_cycle_feed_rate_per_rev
} else {
set f_pr $mom_feed_rate_per_rev
}
}
switch $mode {
IPM { MOM_set_address_format F Feed_IPM ; set feed $f_pm }
MMPM { MOM_set_address_format F Feed_MMPM ; set feed $f_pm }
IPR { MOM_set_address_format F Feed_IPR ; set feed $f_pr }
MMPR { MOM_set_address_format F Feed_MMPR ; set feed $f_pr }
INVERSE { MOM_set_address_format F Feed_INV ; set feed $mom_feed_rate_number }
default { set mom_warning_info "INVALID FEED RATE" ; MOM_catch_warning ; return }
}
}
proc MOM_catch_warning {} {
#_______________________________________________________________________________
# This procedure generates the warnings for missing procedures and values
# falling out of MIN/MAX.
#_______________________________________________________________________________
global mom_warning_info
global warn_file
global list_file
global warn_count
global mom_sequence_number
global mom_sequence_increment
global mom_sequence_frequency
if { [regexp "mom_seqnum" $mom_warning_info] == 1 } {
set mom_sequence_number $mom_sequence_increment
MOM_reset_sequence $mom_sequence_increment $mom_sequence_increment $mom_sequence_frequency
}
puts $warn_file "$mom_warning_info "
puts $list_file "$mom_warning_info "
flush $warn_file
flush $list_file
incr warn_count +1
}
#_______________________________________________________________________________
# The following procedures are executed to get the commentary data output and the
# warning output. The commentary output data is stored in the the file ptp_name.lpt.
# The warning data is stored in the file ptp_name_warning.out.
#_______________________________________________________________________________
proc OPEN_files {} {
global warn_file
global list_file
global mom_output_file_basename
global lpt_file_name
global warning_file_name
set lpt_file_name $mom_output_file_basename.lpt
set warn_sub_name $mom_output_file_basename
set warning_file_name [append warn_sub_name _warning.out]
if {[isset warn_file] == "y"} {
close $warn_file
}
if {[isset list_file] == "y"} {
close $list_file
}
catch {unset warn_file}
catch {unset list_file}
set warn_file [open "$warning_file_name" w ]
set list_file [open "$lpt_file_name" w ]
}
proc CLOSE_files {} {
global warn_file
global list_file
close $warn_file
close $list_file
}
proc LIST_FILE {} {
global mom_o_buffer
global space_buffer
global list_file
global mom_sys_list_file_columns
global mom_sys_list_file_rows
global warn_count
global line_count
global page_title
global page_number
global header
global spaces1
global mom_sys_commentary_output
#*****************ASSUMPTION*************************
global mom_pos
if { [catch {set mom_pos(3) }] == 1 } {
set mom_pos(3) 0
}
if { [catch {set $mom_pos(4) }] == 1 } {
set mom_pos(4) 0
}
#****************************************************
set local_o_buffer $mom_o_buffer
set commentary [ MOM_do_template comment_data CREATE ]
set outs [ concat $local_o_buffer " " ]
set list_cut [expr ( $mom_sys_list_file_columns + 1)]
if { [string length $outs] < $mom_sys_list_file_columns } {
append outs $spaces1
set outs [string range $outs 0 $list_cut]
append outs $commentary
} else {
append outs "\n$spaces1 $commentary "
incr line_count +1
}
incr line_count +1
if { $line_count == $mom_sys_list_file_rows } {
puts $list_file " \f "
puts $list_file $page_title$page_number
puts $list_file $header
incr page_number +1
set line_count 0
}
if { $mom_sys_commentary_output == "ON" } {
puts $list_file $outs
}
flush $list_file
}
proc LIST_FILE_HEADER {} {
global list_file
global mom_sys_list_file_columns
global mom_ug_version
global mom_logname
global mom_date
global mom_event_handler_file_name
global mom_definition_file_name
global mom_part_name
global ptp_file_name
global lpt_file_name
global warning_file_name
global mom_output_file_basename
global mom_output_file_suffix
global warn_count
global line_count
global page_title
global page_number
global header
global spaces1
set line_count 0
set warn_count 0
set blan " "
set header " "
set page_number 1
set page_title "UGPOST $mom_ug_version $mom_part_name $mom_date"
set sub_header1 "Page "
puts $list_file $page_title
for { set inx 0 } { $inx < [expr ($mom_sys_list_file_columns - 96)] } { incr inx +1 } {
append page_title $blan
}
append page_title $sub_header1
set mom_sys_list_file_columns [expr ($mom_sys_list_file_columns - 90)]
if { [string length $mom_output_file_suffix] == 0 } {
set ptp_file_name $mom_output_file_basename
} elseif { [string length $mom_output_file_suffix] > 0 } {
set ptp_file_name $mom_output_file_basename.$mom_output_file_suffix
}
puts $list_file "\n\n\n\n\n\n\n"
puts $list_file "\t\tUU UU GGGGG PPPPPP OOOOO SSSSS TTTTTTTT"
puts $list_file "\t\tUU UU GGGGGGG PPPPPPPP OOOOOOO SSSSSSS TTTTTTTT"
puts $list_file "\t\tUU UU GG GG PP PP OO OO SS TT "
puts $list_file "\t\tUU UU GG PP PP OO OO SS TT "
puts $list_file "\t\tUU UU GG GGGG PPPPPPP OO OO SSSSSS TT "
puts $list_file "\t\tUU UU GG GG PPPPPP OO OO SS TT "
puts $list_file "\t\tUU UU GG GG PP OO OO SS SS TT "
puts $list_file "\t\t UUUUUUU GGGGGGG PP OOOOOOO SSSSSSSS TT "
puts $list_file "\t\t UUUUU GGGGG PP OOOOO SSSSSS TT "
puts $list_file "\n\n\n\n\n\n\n"
puts $list_file " UG_POST VERSION NUMBER : $mom_ug_version"
puts $list_file " UG_POST EXECUTED BY : $mom_logname"
puts $list_file " UG_POST EXECUTION DATE : $mom_date"
puts $list_file " UG_POST POST NAME : "
puts $list_file " UG_POST TCL FILE NAME : $mom_event_handler_file_name"
puts $list_file " UG_POST DEF FILE NAME : $mom_definition_file_name"
puts $list_file " UG_POST PART FILE NAME : $mom_part_name"
puts $list_file " UG_POST PTP FILE NAME : $ptp_file_name"
puts $list_file " UG_POST LPT FILE NAME : $lpt_file_name"
puts $list_file " UG_POST WARNING FILE NAME : $warning_file_name\n"
puts $list_file "\f"
set sub_header2 " EVE-NO ABS-X ABS-Y ABS-Z 4AXIS 5AXIS FEED RPM MIN"
for { set inx 0 } { $inx < $mom_sys_list_file_columns } { incr inx +1 } {
append header $blan
}
set spaces1 $header
append header $sub_header2
puts $list_file $page_title$page_number
incr page_number +1
puts $list_file $header
###### puts $list_file
}
proc LIST_FILE_TRAILER {} {
global list_file
global warn_count
global page_title
global page_number
global mom_machine_time
global mom_tool_use
global mom_tool_count
puts $list_file "\f"
puts $list_file $page_title$page_number
puts $list_file " \n\n\n\n\n\n\n "
puts $list_file " UG_POST MACHINE TIME :[ format "%.2f" $mom_machine_time]"
puts $list_file " NUMBER OF WARNINGS : $warn_count"
if {[isset mom_tool_count] == "n"} {return}
puts $list_file "\f "
puts $list_file "******************************************************************************* *"
puts $list_file " TOOL LIST WITH TOOL USED TIME"
puts $list_file "******************************************************************************* *"
for { set nn 0 } { $nn < $mom_tool_count } {incr nn} {
puts $list_file " TOOL NUMBER [ format "%.2f %.2f" $mom_tool_use($nn,0) $mom_tool_use($nn,1)] minutes"
}
puts $list_file "******************************************************************************* *"
}
proc PPRINT_OUTPUT {} {
global mom_pprint
global mom_operator_message_status
global ptp_file_name
global lpt_file_name
global need_commentary
global op_mess_text
global list_file
global mom_o_buffer
global mom_sys_commentary_output
if {$mom_operator_message_status == "ON"} {
MOM_output_literal $mom_pprint
} elseif {$mom_operator_message_status == "OFF"} {
set brac_start [string first \( $mom_pprint]
set brac_end [string first \) $mom_pprint]
if { ($brac_start > 0) && ($brac_end > 0) } {
MOM_set_seq_off
MOM_close_output_file $ptp_file_name
MOM_output_literal $mom_pprint
MOM_open_output_file $ptp_file_name
MOM_set_seq_on
set brack [ string range $mom_pprint $brac_start $brac_end]
set mom_sys_commentary_output OFF
MOM_output_literal $brack
set mom_sys_commentary_output ON
} else {
MOM_set_seq_off
MOM_close_output_file $ptp_file_name
MOM_output_literal $mom_pprint
MOM_open_output_file $ptp_file_name
MOM_set_seq_on
}
}
}
#_______________________________________________________________________________
# utility to return "y" if the variable v1 is set, else "n"
# example set xx [isset yy] returns xx as "y" or "n"
# example if {[isset yy] == "y"} {puts "yy"}
#_______________________________________________________________________________
proc isset { v1 } {
upvar $v1 v2
if { [catch { set v2 }] == 0} { return y } else { return n }
}
#_______________________________________________________________________________
# utility to return TRUE(1) if the variable v1 is set, else FALSE(0)
# example set xx [hiset yy] returns xx as TRUE(1) or FALSE(0)
# example if {[hiset yy]} {puts "yy"}
#_______________________________________________________________________________
proc hiset { v1 } {
upvar $v1 v2
if { [catch { set v2 }] == 0} { return 1 } else { return 0 }
}
#_______________________________________________________________________________
# utility to return a variable v1 after formatting it per f1
# example set x [fmt $y "%.3f"] returns x after formatting y per %.3f
#_______________________________________________________________________________
proc fmt { v1 f1 } {
set v2 [format $f1 $v1] ; return $v2
}