# *FEEDS_SPEEDS.TCL ############################################################################### # feeds_speeds.tcl - DBC Event Handler for database stored as ascii file ############################################################################### # Revisions # Date Who Reason # 03/24/99 Murthy Mandaleeka Initial # 05/19/99 Murthy Mandaleeka New Environment Variable # 07/21/99 Subhash Included dbc_general_ascii.tcl file # 07/21/99 Subhash Used general functions for # opening and reading dat files. # 08/06/99 Subhash Changed some functions to improve performance # 08/19/99 Subhash Changed the logic so that feed and speed value # is picked from a range depending on depth of cut # 09/01/99 Gopal Srinath In the retrieve proc removed call to # MOM_abort. # 01/15/02 Murthy Mandaleeka Relate more feed types as percentages of Cut feed. # 06/06/02 Murthy Mandaleeka Update depth of cut for Cavity Milling Operations # 17Feb2004 rlm Add support for execute_query # 24May2004 Murthy Mandaleeka Fix StepOver Feedrate Percent problem. # 06Dec2004 rlm 1369488 Add DBC_execute_query_for_count # 16Dec2004 rlm 2044460 Add more Cut Depth variables # 26Oct2018 Shorbojeet Das PR8340732: Add customization support for double precision control. ################################################################################ # # The format of each line in the text file is: # # libref optype ptmtl tlmtl speed feed # # libref is a string # optype is "Milling" "Turning" "Drilling" # ptmtl is code number for now # tlmtl is "HSS" "Carbide" "CBN" # depth is a double # speed is a double # feed is a double # # The DB_ID of a DB_ALIAS is its field number in the line (0-based) ############################################################################### #MOM_set_debug_mode ON #--------------------------------------------- # Non DBC Global Variables #--------------------------------------------- #set dbFileName "[MOM_ask_env_var UGII_CAM_LIBRARY_FEEDS_SPEEDS_DATA_DIR]feeds_speeds.dat" ; # The ASCII Database File set DEBUG 1 set fPointer "" #--------------------------------------------- # Global variables set by DBC for Input/Output #--------------------------------------------- set dbc_lhs_exp "" set dbc_rhs_exp "" set dbc_relop "" set dbc_query "" set dbc_subqry1 "" set dbc_subqry2 "" set dbc_boolop "" set dbc_class_name "" set dbc_attr_count 0 set dbc_attr_id "" set dbc_query_count 0 set dbc_libref "" set dbc_var_list "" set dbc_tool_diameter "" set dbc_tool_height "" set dbc_part_units "english" ; # ( english : 0 , metric : 1) set dbc_cutmthd_libref "" set dbc_part_material_libref "" set dbc_tool_material_libref "" # Default double precision value format. set double_precision_format "g" # # Express feedrates for the following feed types # as percentages of Cut feedrate. # A value of 0 indicates no relation to Cut feedrate. # set dbc_engage_percent 90 set dbc_first_cut_percent 60 set dbc_approach_percent 0 set dbc_step_over_percent 0 set dbc_retract_percent 0 set dbc_departure_percent 0 set dbc_return_percent 0 set asc_debug 0 proc ASC_t_create_filename {env_var_name filename} \ { # # Creates a complete filename by evaluating an environment variable # for the directory information # set env_var [MOM_ask_env_var $env_var_name] if { $env_var == "" } \ { set message "Can't read environment variable $env_var_name" MOM_abort "\n $message" } set fname "" set fname [append fname $env_var $filename] return $fname } #--------------------------------------------- proc MOM__boot {} { #--------------------------------------------- # source some general procedures # # dbc_ascii_general.tcl # set filename \ [ASC_t_create_filename "UGII_UG_LIBRARY_DIR" "dbc_ascii_general.tcl"] if { [catch {source $filename}] == "1" } \ { set message "Can't load .tcl file: $filename" MOM_abort "\n $message" } } proc MOM__halt {} \ { } #--------------------------------------------- proc DBC_init_db {} { #--------------------------------------------- global DEBUG global dataBase global dbFileName global fPointer global asc_file_name set asc_file_name "" set asc_part_units "" set data_unit 0 set mode 0 # # Set the filename for ASCII Data File # ASC_set_data_file_name # Changed to improve performance # And load the file into memory # ASC_load_data_file $asc_file_name $data_unit $mode } #--------------------------------------------- proc ASC_set_data_file_name {} { #--------------------------------------------- global dbc_part_units global asc_file_name global asc_part_units MOM_ask_part_units ;# writes to dbc_part_units set env_var UGII_CAM_LIBRARY_FEEDS_SPEEDS_DATA_DIR set asc_file_name [ASC_t_create_filename "$env_var" "feeds_speeds.dat"] set asc_part_units $dbc_part_units } #--------------------------------------------- proc ASC_get_depthofcut { DB_ROW DPTH_OF_CUT} { #--------------------------------------------- upvar $DB_ROW db_row upvar $DPTH_OF_CUT dpth_of_cut global dbc_part_units MOM_ask_part_units if { $dbc_part_units == "english" } \ { set dpth_of_cut [ASC_ask_att_val DPT_CUT_IN $db_row "%$::double_precision_format" 0 flag] } else \ { set dpth_of_cut [ASC_ask_att_val DPT_CUT_MM $db_row "%$::double_precision_format" 0 flag] } } #--------------------------------------------- proc ASC_get_feedspeed { DB_ROW FEED_VALUE SPEED_VALUE } { #--------------------------------------------- upvar $DB_ROW db_row upvar $FEED_VALUE asc_feed_value upvar $SPEED_VALUE asc_speed_value global dbc_part_units global dbc_surface_speed global dbc_feed_per_tooth if { $dbc_part_units == "english"} \ { set asc_speed_value [ASC_ask_att_val SURF_SPEED_FPM $db_row \ "%$::double_precision_format" 0 flag] set asc_feed_value [ASC_ask_att_val FEED_IPT $db_row \ "%$::double_precision_format" 0 flag] } else \ { set asc_speed_value [ASC_ask_att_val SURF_SPEED_MPM $db_row \ "%$::double_precision_format" 0 flag] set asc_feed_value [ASC_ask_att_val FEED_MMPT $db_row \ "%$::double_precision_format" 0 flag] } } #--------------------------------------------- proc ASC_get_depthofcut_from_oper {LOCAL_DEPTH_OF_CUT} { #--------------------------------------------- upvar $LOCAL_DEPTH_OF_CUT local_depth_of_cut global dbc_cut_level_max_depth global dbc_depth_per_cut global dbc_depth_of_cut global dbc_max_cut_depth global dbc_cut_depth global dbc_range_1_depth_per_cut global dbc_global_cut_depth global dbc_multi_depth_cut_increment if { [info exist dbc_cut_level_max_depth] } \ { set local_depth_of_cut $dbc_cut_level_max_depth } elseif { [info exist dbc_range_1_depth_per_cut] } \ { set local_depth_of_cut $dbc_range_1_depth_per_cut } elseif { [info exist dbc_depth_per_cut] } \ { set local_depth_of_cut $dbc_depth_per_cut } elseif { [info exist dbc_depth_of_cut] } \ { set local_depth_of_cut $dbc_depth_of_cut } elseif { [info exist dbc_max_cut_depth] } \ { set local_depth_of_cut $dbc_max_cut_depth } elseif { [info exist dbc_cut_depth] } \ { set local_depth_of_cut $dbc_cut_depth } elseif { [info exist dbc_global_cut_depth] } \ { set local_depth_of_cut $dbc_global_cut_depth } elseif { [info exist dbc_multi_depth_cut_increment] } \ { set local_depth_of_cut $dbc_multi_depth_cut_increment } else { set local_depth_of_cut 0} } #------------------------------------------------------------------------ proc DBC_create_query { } { #------------------------------------------------------------------------ global DEBUG global dbc_query global dbc_subqry1 global dbc_subqry2 global dbc_boolop # set dbc_query "$dbc_subqry1 $dbc_boolop $dbc_subqry2" ASC_create_query } #--------------------------------------------- proc DBC_translate_att_alias {} { #--------------------------------------------- ASC_translate_att_alias } #--------------------------------------------- proc DBC_create_criterion {} { #--------------------------------------------- ASC_create_criterion } #------------------------------------------------------------------------ proc DBC_execute_query { } { #------------------------------------------------------------------------ global asc_database_count ASC_execute_query } #------------------------------------------------------------------------ proc DBC_execute_query_for_count { } { #------------------------------------------------------------------------ global asc_database_count ASC_execute_query_for_count } #--------------------------------------------- proc DBC_retrieve {} { #--------------------------------------------- global DEBUG global dbc_event_error global dbc_part_units global dbc_cutmthd_libref global dbc_part_material_libref global dbc_tool_material_libref global dbc_tool_height global dbc_tool_diameter global dbc_surface_speed global dbc_feed_per_tooth global dbc_engage_percent global dbc_first_cut_percent global fPointer global dbFileName global asc_database_count global asc_database global asc_file_name global file_unit global asc_units global asc_next_line ASC_get_depthofcut_from_oper local_depth_of_cut set hig_dpth_cut [expr $local_depth_of_cut + 99] set low_dpth_cut 0 set index 0 set record_indx 0 set low_record_indx 0 set hig_record_indx 0 set initialize_flag 1 set asc_feeds_file_name $asc_file_name set asc_next_line "" if { $dbc_part_units == "english" } \ { set file_unit $asc_units(inch) } else \ { set file_unit $asc_units(mm) } ## Changed function to improve performance set ret_code [catch {open $asc_feeds_file_name "r"} fp] if { $ret_code } \ { return 1 } ASC_init_database # # Loop over all the DATA records # # The db_row variable has to be initialized (see also ASC_translate_att_alias) set db_row 0 set found 2 set present_record_index 0 set local_depth_of_cut [format "%4.4f" $local_depth_of_cut] while {[ASC_read_next_db_object $fp $asc_file_name $file_unit $db_row] >= 0} \ { set ascii_cutmethd_libref [ ASC_ask_att_val OPERTYPE \ $db_row "" 0 flag] set ascii_part_material_libref [ASC_ask_att_val PARTMAT $db_row \ "" 0 flag] set ascii_tool_material_libref [ASC_ask_att_val TOOLMAT $db_row \ "" 0 flag] incr present_record_index # Find the row for the desired record if { $dbc_cutmthd_libref == $ascii_cutmethd_libref && \ $dbc_part_material_libref == $ascii_part_material_libref && \ $dbc_tool_material_libref == $ascii_tool_material_libref } \ { set found 0 set break_flag 1 ASC_get_depthofcut db_row dpth_cut set dpth_cut [format "%4.4f" $dpth_cut] if { $dpth_cut == $local_depth_of_cut } \ { # Obtained the record. Get the values... set record_indx $db_row ASC_get_feedspeed record_indx dbc_feed_per_tooth dbc_surface_speed return 0 } elseif { $dpth_cut < $local_depth_of_cut && \ $dpth_cut > $low_dpth_cut} \ { ## Exact match not found set low_record_indx $present_record_index set low_dpth_cut $dpth_cut # Store the low feeds and speed value in tmp var for future ref. ASC_get_feedspeed db_row low_feed_per_tooth low_surface_speed } elseif { $dpth_cut > $local_depth_of_cut && \ $dpth_cut < $hig_dpth_cut } \ { set hig_record_indx $present_record_index set hig_dpth_cut $dpth_cut # Store the high feeds and speed value in tmp var for future ref. ASC_get_feedspeed db_row hig_feed_per_tooth hig_surface_speed } else \ { if { $break_flag == 1} { set break_flag 2} } if {$break_flag == 2} { break } } } close $fp if { $found != 0 } \ { set dbc_event_error "No appropriate feed speed data found" return } if {$record_indx} \ { set final_indx $record_indx } else \ { if {!$low_record_indx} \ { set dbc_feed_per_tooth $hig_feed_per_tooth set dbc_surface_speed $hig_surface_speed } elseif {!$hig_record_indx} \ { set dbc_feed_per_tooth $low_feed_per_tooth set dbc_surface_speed $low_surface_speed } else \ { # Exact Match for Depth of Cut not found set low_diff [expr $local_depth_of_cut - $low_dpth_cut] set hig_diff [expr $hig_dpth_cut - $local_depth_of_cut] if {$low_diff < $hig_diff} \ { # Actual depth of cut is closer to next higher depth of cut in data file set dbc_feed_per_tooth $low_feed_per_tooth set dbc_surface_speed $low_surface_speed } else \ { # Actual depth of cut is closer to previous lower depth of cut in data file set dbc_feed_per_tooth $hig_feed_per_tooth set dbc_surface_speed $hig_surface_speed } } } } # To enable the new customization mechanism. # This should ALWAYS be the last line in the file. MOM_extend_for_customization UGII_CAM_CUSTOM_LIBRARY_FEEDS_SPEEDS_ASCII_DIR dbc_custom_ascii_feeds_speeds.tcl