interp_convert.cc

来自「CNC 的开放码,EMC2 V2.2.8版」· CC 代码 · 共 1,654 行 · 第 1/5 页

CC
1,654
字号
  settings->w_current = (settings->w_current + settings->w_origin_offset);  x = USER_TO_PROGRAM_LEN(parameters[5201 + (origin * 20)]);  y = USER_TO_PROGRAM_LEN(parameters[5202 + (origin * 20)]);  z = USER_TO_PROGRAM_LEN(parameters[5203 + (origin * 20)]);  a = USER_TO_PROGRAM_ANG(parameters[5204 + (origin * 20)]);  b = USER_TO_PROGRAM_ANG(parameters[5205 + (origin * 20)]);  c = USER_TO_PROGRAM_ANG(parameters[5206 + (origin * 20)]);  u = USER_TO_PROGRAM_LEN(parameters[5207 + (origin * 20)]);  v = USER_TO_PROGRAM_LEN(parameters[5208 + (origin * 20)]);  w = USER_TO_PROGRAM_LEN(parameters[5209 + (origin * 20)]);  settings->origin_offset_x = x;  settings->origin_offset_y = y;  settings->origin_offset_z = z;  settings->AA_origin_offset = a;  settings->BB_origin_offset = b;  settings->CC_origin_offset = c;  settings->u_origin_offset = u;  settings->v_origin_offset = v;  settings->w_origin_offset = w;  settings->current_x = (settings->current_x - x);  settings->current_y = (settings->current_y - y);  settings->current_z = (settings->current_z - z);  settings->AA_current = (settings->AA_current - a);  settings->BB_current = (settings->BB_current - b);  settings->CC_current = (settings->CC_current - c);  settings->u_current = (settings->u_current - u);  settings->v_current = (settings->v_current - v);  settings->w_current = (settings->w_current - w);  SET_ORIGIN_OFFSETS(x + settings->axis_offset_x,                     y + settings->axis_offset_y,                     z + settings->axis_offset_z,                     a + settings->AA_axis_offset,                     b + settings->BB_axis_offset,                     c + settings->CC_axis_offset,                     u + settings->u_axis_offset,                     v + settings->v_axis_offset,                     w + settings->w_axis_offset);  return INTERP_OK;}/****************************************************************************//*! convert_cutter_compensationReturned Value: int   If convert_cutter_compensation_on or convert_cutter_compensation_off      is called and returns an error code, this returns that code.   If any of the following errors occur, this returns the error shown.   Otherwise, it returns INTERP_OK.   1. g_code is not G_40, G_41, or G_42:      NCE_BUG_CODE_NOT_G40_G41_OR_G42Side effects:   The value of cutter_comp_side in the machine model mode is   set to RIGHT, LEFT, or OFF. The currently active tool table index in   the machine model (which is the index of the slot whose diameter   value is used in cutter radius compensation) is updated.Since cutter radius compensation is performed in the interpreter, nocall is made to any canonical function regarding cutter radius compensation.Called by: convert_g*/int Interp::convert_cutter_compensation(int g_code,      //!< must be G_40, G_41, or G_42                                                    block_pointer block,     //!< pointer to a block of RS274 instructions                                       setup_pointer settings)  //!< pointer to machine settings             {  static char name[] = "convert_cutter_compensation";  int status;  if (g_code == G_40) {    CHP(convert_cutter_compensation_off(settings));  } else if (g_code == G_41) {    CHP(convert_cutter_compensation_on(LEFT, block, settings));  } else if (g_code == G_42) {    CHP(convert_cutter_compensation_on(RIGHT, block, settings));  } else if (g_code == G_41_1) {    CHP(convert_cutter_compensation_on(LEFT, block, settings));  } else if (g_code == G_42_1) {    CHP(convert_cutter_compensation_on(RIGHT, block, settings));  } else    ERS("BUG: Code not G40, G41, G41.1, G42, G42.2");  return INTERP_OK;}/****************************************************************************//*! convert_cutter_compensation_offReturned Value: int (INTERP_OK)Side effects:   A comment is made that cutter radius compensation is turned off.   The machine model of the cutter radius compensation mode is set to OFF.   The value of cutter_comp_firstmove in the machine model is set to ON.     This serves as a flag when cutter radius compensation is     turned on again.Called by: convert_cutter_compensation*/int Interp::convert_cutter_compensation_off(setup_pointer settings)      //!< pointer to machine settings{#ifdef DEBUG_EMC  COMMENT("interpreter: cutter radius compensation off");#endif  if(settings->cutter_comp_side != OFF && settings->cutter_comp_radius > 0.0) {      settings->current_x = settings->program_x;      settings->current_y = settings->program_y;      settings->current_z = settings->program_z;  }  settings->cutter_comp_side = OFF;  settings->cutter_comp_firstmove = ON;  return INTERP_OK;}/****************************************************************************//*! convert_cutter_compensation_onReturned Value: int   If any of the following errors occur, this returns the error code shown.   Otherwise, it returns INTERP_OK.   1. The selected plane is not the XY plane:      NCE_CANNOT_TURN_CUTTER_RADIUS_COMP_ON_OUT_OF_XY_PLANE   2. Cutter radius compensation is already on:      NCE_CANNOT_TURN_CUTTER_RADIUS_COMP_ON_WHEN_ONSide effects:   A COMMENT function call is made (conditionally) saying that the   interpreter is switching mode so that cutter radius compensation is on.   The value of cutter_comp_radius in the machine model mode is   set to the absolute value of the radius given in the tool table.   The value of cutter_comp_side in the machine model mode is   set to RIGHT or LEFT. The currently active tool table index in   the machine model is updated.Called by: convert_cutter_compensationcheck_other_codes checks that a d word occurs only in a block with g41or g42.Cutter radius compensation is carried out in the interpreter, so nocall is made to a canonical function (although there is a canonicalfunction, START_CUTTER_RADIUS_COMPENSATION, that could be called ifthe primitive level could execute it).This version uses a D word if there is one in the block, but it doesnot require a D word, since the sample programs which the interpreteris supposed to handle do not have them.  Logically, the D word isoptional, since the D word is always (except in cases we have neverheard of) the slot number of the tool in the spindle. Not requiring aD word is contrary to [Fanuc, page 116] and [NCMS, page 79], however.Both manuals require the use of the D-word with G41 and G42.This version handles a negative offset radius, which may beencountered if the programmed tool path is a center line path forcutting a profile and the path was constructed using a nominal tooldiameter. Then the value in the tool table for the diameter is set tobe the difference between the actual diameter and the nominaldiameter. If the actual diameter is less than the nominal, the valuein the table is negative. The method of handling a negative radius isto switch the side of the offset and use a positive radius. Thisrequires that the profile use arcs (not straight lines) to go aroundconvex corners.*//* Set *result to the integer nearest to value; return TRUE if value is * within .0001 of an integer */static int is_near_int(int *result, double value) {    *result = (int)(value + .5);    return fabs(*result - value) < .0001;}int Interp::convert_cutter_compensation_on(int side,     //!< side of path cutter is on (LEFT or RIGHT)                                          block_pointer block,  //!< pointer to a block of RS274 instructions                                           setup_pointer settings)       //!< pointer to machine settings              {  static char name[] = "convert_cutter_compensation_on";  double radius;  int index, orientation;  CHK((settings->plane != CANON_PLANE_XY && settings->plane != CANON_PLANE_XZ),      NCE_RADIUS_COMP_ONLY_IN_XY_OR_XZ);  CHK((settings->cutter_comp_side != OFF),      NCE_CANNOT_TURN_CUTTER_RADIUS_COMP_ON_WHEN_ON);  if(block->g_modes[7] == G_41_1 || block->g_modes[7] == G_42_1) {      CHKF((block->d_flag != ON),              (_("G%d.1 with no D word"), block->g_modes[7]/10 ));      radius = block->d_number_float / 2;      if(block->l_number != -1) {          orientation = block->l_number;      } else {          orientation = 0;      }  } else {      if(block->d_flag == OFF) {          index = settings->current_slot;      } else {          int tool;          CHKF(!is_near_int(&tool, block->d_number_float),                  (_("G%d requires D word to be a whole number"),                   block->g_modes[7]/10));          CHK((tool < 0), NCE_NEGATIVE_D_WORD_TOOL_RADIUS_INDEX_USED);          CHK((tool > _setup.tool_max), NCE_TOOL_RADIUS_INDEX_TOO_BIG);          index = tool;      }      radius = USER_TO_PROGRAM_LEN(settings->tool_table[index].diameter) / 2.0;      orientation = settings->tool_table[index].orientation;  }  if (radius < 0.0) { /* switch side & make radius positive if radius negative */    radius = -radius;    if (side == RIGHT)      side = LEFT;    else      side = RIGHT;  }#ifdef DEBUG_EMC  if (side == RIGHT)    COMMENT("interpreter: cutter radius compensation on right");  else    COMMENT("interpreter: cutter radius compensation on left");#endif  settings->cutter_comp_radius = radius;  settings->cutter_comp_orientation = orientation;  settings->cutter_comp_side = side;  return INTERP_OK;}/****************************************************************************//*! convert_distance_modeReturned Value: int   If any of the following errors occur, this returns the error shown.   Otherwise, it returns INTERP_OK.   1. g_code isn't G_90 or G_91: NCE_BUG_CODE_NOT_G90_OR_G91Side effects:   The interpreter switches the machine settings to indicate the current   distance mode (absolute or incremental).   The canonical machine to which commands are being sent does not have   an incremental mode, so no command setting the distance mode is   generated in this function. A comment function call explaining the   change of mode is made (conditionally), however, if there is a change.Called by: convert_g.*/int Interp::convert_distance_mode(int g_code,    //!< g_code being executed (must be G_90 or G_91)                                 setup_pointer settings)        //!< pointer to machine settings                 {  static char name[] = "convert_distance_mode";  if (g_code == G_90) {    if (settings->distance_mode != MODE_ABSOLUTE) {#ifdef DEBUG_EMC      COMMENT("interpreter: distance mode changed to absolute");#endif      settings->distance_mode = MODE_ABSOLUTE;    }  } else if (g_code == G_91) {    if (settings->distance_mode != MODE_INCREMENTAL) {#ifdef DEBUG_EMC      COMMENT("interpreter: distance mode changed to incremental");#endif      settings->distance_mode = MODE_INCREMENTAL;    }  } else    ERM(NCE_BUG_CODE_NOT_G90_OR_G91);  return INTERP_OK;}/****************************************************************************//*! convert_dwellReturned Value: int (INTERP_OK)Side effects:   A dwell command is executed.Called by: convert_g.*/int Interp::convert_dwell(double time)   //!< time in seconds to dwell  */{  DWELL(time);  return INTERP_OK;}/****************************************************************************//*! convert_feed_modeReturned Value: int   If any of the following errors occur, this returns an error code.   Otherwise, it returns INTERP_OK.   1.  g_code isn't G_93, G_94 or G_95Side effects:   The interpreter switches the machine settings to indicate the current   feed mode (UNITS_PER_MINUTE or INVERSE_TIME).   The canonical machine to which commands are being sent does not have   a feed mode, so no command setting the distance mode is generated in   this function. A comment function call is made (conditionally)   explaining the change in mode, however.Called by: execute_block.*/int Interp::convert_feed_mode(int g_code,        //!< g_code being executed (must be G_93, G_94 or G_95)                             setup_pointer settings)    //!< pointer to machine settings                 {  static char name[

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?