📄 interp_convert.cc
字号:
/********************************************************************* Description: interp_convert.cc** Derived from a work by Thomas Kramer** Author:* License: GPL Version 2* System: Linux* * Copyright (c) 2004 All rights reserved.** Last change:* $Revision: 1.22.2.2 $* $Author: cradek $* $Date: 2006/04/18 03:48:21 $********************************************************************/#ifndef _GNU_SOURCE#define _GNU_SOURCE#endif#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <ctype.h>#include <sys/types.h>#include <sys/stat.h>#include "rs274ngc.hh"#include "rs274ngc_return.hh"#include "interp_internal.hh"#include "units.h"/****************************************************************************//*! convert_arcReturned Value: int If one of the following functions returns an error code, this returns that error code. convert_arc_comp1 convert_arc_comp2 convert_arc2 If any of the following errors occur, this returns the error code shown. Otherwise, this returns INTERP_OK. 1. The block has neither an r value nor any i,j,k values: NCE_R_I_J_K_WORDS_ALL_MISSING_FOR_ARC 2. The block has both an r value and one or more i,j,k values: NCE_MIXED_RADIUS_IJK_FORMAT_FOR_ARC 3. In the ijk format the XY-plane is selected and the block has a k value: NCE_K_WORD_GIVEN_FOR_ARC_IN_XY_PLANE 4. In the ijk format the YZ-plane is selected and the block has an i value: NCE_I_WORD_GIVEN_FOR_ARC_IN_YZ_PLANE 5. In the ijk format the XZ-plane is selected and the block has a j value: NCE_J_WORD_GIVEN_FOR_ARC_IN_XZ_PLANE 6. In either format any of the following occurs. a. The XY-plane is selected and the block has no x or y value: NCE_X_AND_Y_WORDS_MISSING_FOR_ARC_IN_XY_PLANE b. The YZ-plane is selected and the block has no y or z value: NCE_Y_AND_Z_WORDS_MISSING_FOR_ARC_IN_YZ_PLANE c. The ZX-plane is selected and the block has no z or x value: NCE_X_AND_Z_WORDS_MISSING_FOR_ARC_IN_XZ_PLANE 7. The selected plane is an unknown plane: NCE_BUG_PLANE_NOT_XY_YZ__OR_XZ 8. The feed rate mode is UNITS_PER_MINUTE and feed rate is zero: NCE_CANNOT_MAKE_ARC_WITH_ZERO_FEED_RATE 9. The feed rate mode is INVERSE_TIME and the block has no f word: NCE_F_WORD_MISSING_WITH_INVERSE_TIME_ARC_MOVESide effects: This generates and executes an arc command at feed rate (and, possibly a second arc command). It also updates the setting of the position of the tool point to the end point of the move.Called by: convert_motion.This converts a helical or circular arc. The function calls:convert_arc2 (when cutter radius compensation is off) orconvert_arc_comp1 (when cutter comp is on and this is the first move) orconvert_arc_comp2 (when cutter comp is on and this is not the first move).If the ijk format is used, at least one of the offsets in the currentplane must be given in the block; it is common but not required togive both offsets. The offsets are always incremental [NCMS, page 21].*/int Interp::convert_arc(int move, //!< either G_2 (cw arc) or G_3 (ccw arc) block_pointer block, //!< pointer to a block of RS274 instructions setup_pointer settings) //!< pointer to machine settings { static char name[] = "convert_arc"; int status; int first; /* flag set ON if this is first move after comp ON */ int ijk_flag; /* flag set ON if any of i,j,k present in NC code */ double end_x; double end_y; double end_z; double AA_end; double BB_end; double CC_end; ijk_flag = ((block->i_flag || block->j_flag) || block->k_flag) ? ON : OFF; first = (settings->program_x == UNKNOWN); CHK(((block->r_flag != ON) && (ijk_flag != ON)), NCE_R_I_J_K_WORDS_ALL_MISSING_FOR_ARC); CHK(((block->r_flag == ON) && (ijk_flag == ON)), NCE_MIXED_RADIUS_IJK_FORMAT_FOR_ARC); if (settings->feed_mode == UNITS_PER_MINUTE) { CHK((settings->feed_rate == 0.0), NCE_CANNOT_MAKE_ARC_WITH_ZERO_FEED_RATE); } else if (settings->feed_mode == INVERSE_TIME) { CHK((block->f_number == -1.0), NCE_F_WORD_MISSING_WITH_INVERSE_TIME_ARC_MOVE); } if (ijk_flag) { if (settings->plane == CANON_PLANE_XY) { CHK((block->k_flag), NCE_K_WORD_GIVEN_FOR_ARC_IN_XY_PLANE); if (block->i_flag == OFF) /* i or j flag on to get here */ block->i_number = 0.0; else if (block->j_flag == OFF) block->j_number = 0.0; } else if (settings->plane == CANON_PLANE_YZ) { CHK((block->i_flag), NCE_I_WORD_GIVEN_FOR_ARC_IN_YZ_PLANE); if (block->j_flag == OFF) /* j or k flag on to get here */ block->j_number = 0.0; else if (block->k_flag == OFF) block->k_number = 0.0; } else if (settings->plane == CANON_PLANE_XZ) { CHK((block->j_flag), NCE_J_WORD_GIVEN_FOR_ARC_IN_XZ_PLANE); if (block->i_flag == OFF) /* i or k flag on to get here */ block->i_number = 0.0; else if (block->k_flag == OFF) block->k_number = 0.0; } else ERM(NCE_BUG_PLANE_NOT_XY_YZ_OR_XZ); } else; /* r format arc; no other checks needed specific to this format */ if (settings->plane == CANON_PLANE_XY) { /* checks for both formats */ CHK(((block->x_flag == OFF) && (block->y_flag == OFF)), NCE_X_AND_Y_WORDS_MISSING_FOR_ARC_IN_XY_PLANE); } else if (settings->plane == CANON_PLANE_YZ) { CHK(((block->y_flag == OFF) && (block->z_flag == OFF)), NCE_Y_AND_Z_WORDS_MISSING_FOR_ARC_IN_YZ_PLANE); } else if (settings->plane == CANON_PLANE_XZ) { CHK(((block->x_flag == OFF) && (block->z_flag == OFF)), NCE_X_AND_Z_WORDS_MISSING_FOR_ARC_IN_XZ_PLANE); } find_ends(block, settings, &end_x, &end_y, &end_z, &AA_end, &BB_end, &CC_end); settings->motion_mode = move; if (settings->plane == CANON_PLANE_XY) { if ((settings->cutter_comp_side == OFF) || (settings->cutter_comp_radius == 0.0)) { status = convert_arc2(move, block, settings, &(settings->current_x), &(settings->current_y), &(settings->current_z), end_x, end_y, end_z, AA_end, BB_end, CC_end, block->i_number, block->j_number); CHP(status); } else if (first) { status = convert_arc_comp1(move, block, settings, end_x, end_y, end_z, AA_end, BB_end, CC_end); CHP(status); } else { status = convert_arc_comp2(move, block, settings, end_x, end_y, end_z, AA_end, BB_end, CC_end); CHP(status); } } else if (settings->plane == CANON_PLANE_XZ) { status = convert_arc2(move, block, settings, &(settings->current_z), &(settings->current_x), &(settings->current_y), end_z, end_x, end_y, AA_end, BB_end, CC_end, block->k_number, block->i_number); CHP(status); } else if (settings->plane == CANON_PLANE_YZ) { status = convert_arc2(move, block, settings, &(settings->current_y), &(settings->current_z), &(settings->current_x), end_y, end_z, end_x, AA_end, BB_end, CC_end, block->j_number, block->k_number); CHP(status); } else ERM(NCE_BUG_PLANE_NOT_XY_YZ_OR_XZ); return INTERP_OK;}/****************************************************************************//*! convert_arc2Returned Value: int If arc_data_ijk or arc_data_r returns an error code, this returns that code. Otherwise, it returns INTERP_OK.Side effects: This executes an arc command at feed rate. It also updates the setting of the position of the tool point to the end point of the move. If inverse time feed rate is in effect, it also resets the feed rate.Called by: convert_arc.This converts a helical or circular arc.*/int Interp::convert_arc2(int move, //!< either G_2 (cw arc) or G_3 (ccw arc) block_pointer block, //!< pointer to a block of RS274 instructions setup_pointer settings, //!< pointer to machine settings double *current1, //!< pointer to current value of coordinate 1 double *current2, //!< pointer to current value of coordinate 2 double *current3, //!< pointer to current value of coordinate 3 double end1, //!< coordinate 1 value at end of arc double end2, //!< coordinate 2 value at end of arc double end3, //!< coordinate 3 value at end of arc double AA_end, //!< a-value at end of arc double BB_end, //!< b-value at end of arc double CC_end, //!< c-value at end of arc double offset1, //!< offset of center from current1 double offset2) //!< offset of center from current2 { static char name[] = "convert_arc2"; double center1; double center2; int status; /* status returned from CHP function call */ double tolerance; /* tolerance for difference of radii */ int turn; /* number of full or partial turns CCW in arc */ tolerance = (settings->length_units == CANON_UNITS_INCHES) ? TOLERANCE_INCH : TOLERANCE_MM; if (block->r_flag) { CHP(arc_data_r(move, *current1, *current2, end1, end2, block->r_number, ¢er1, ¢er2, &turn, tolerance)); } else { CHP(arc_data_ijk(move, *current1, *current2, end1, end2, offset1, offset2, ¢er1, ¢er2, &turn, tolerance)); } if (settings->feed_mode == INVERSE_TIME) inverse_time_rate_arc(*current1, *current2, *current3, center1, center2, turn, end1, end2, end3, block, settings); ARC_FEED(end1, end2, center1, center2, turn, end3, AA_end, BB_end, CC_end); *current1 = end1; *current2 = end2; *current3 = end3; settings->AA_current = AA_end; settings->BB_current = BB_end; settings->CC_current = CC_end; return INTERP_OK;}/****************************************************************************//*! convert_arc_comp1Returned Value: int If arc_data_comp_ijk or arc_data_comp_r returns an error code, this returns that code. Otherwise, it returns INTERP_OK.Side effects: This executes an arc command at feed rate. It also updates the setting of the position of the tool point to the end point of the move.Called by: convert_arc.This function converts a helical or circular arc, generating only onearc. The axis must be parallel to the z-axis. This is called whencutter radius compensation is on and this is the first cut after theturning on.The arc which is generated is derived from a second arc which passesthrough the programmed end point and is tangent to the cutter at itscurrent location. The generated arc moves the tool so that it staystangent to the second arc throughout the move.*/int Interp::convert_arc_comp1(int move, //!< either G_2 (cw arc) or G_3 (ccw arc) block_pointer block, //!< pointer to a block of RS274/NGC instructions setup_pointer settings, //!< pointer to machine settings double end_x, //!< x-value at end of programmed (then actual) arc double end_y, //!< y-value at end of programmed (then actual) arc double end_z, //!< z-value at end of arc double AA_end, //!< a-value at end of arc double BB_end, //!< b-value at end of arc double CC_end) //!< c-value at end of arc { static char name[] = "convert_arc_comp1"; double center_x; double center_y; double gamma; /* direction of perpendicular to arc at end */ int side; /* offset side - right or left */ int status; /* status returned from CHP function call */ double tolerance; /* tolerance for difference of radii */ double tool_radius; int turn; /* 1 for counterclockwise, -1 for clockwise */ side = settings->cutter_comp_side; tool_radius = settings->cutter_comp_radius; /* always is positive */ tolerance = (settings->length_units == CANON_UNITS_INCHES) ? TOLERANCE_INCH : TOLERANCE_MM; CHK((hypot((end_x - settings->current_x), (end_y - settings->current_y)) <= tool_radius), NCE_CUTTER_GOUGING_WITH_CUTTER_RADIUS_COMP); if (block->r_flag) { CHP(arc_data_comp_r(move, side, tool_radius, settings->current_x, settings->current_y, end_x, end_y, block->r_number, ¢er_x, ¢er_y, &turn)); } else { CHP(arc_data_comp_ijk(move, side, tool_radius, settings->current_x, settings->current_y, end_x, end_y, block->i_number, block->j_number, ¢er_x, ¢er_y, &turn, tolerance)); } gamma = (((side == LEFT) && (move == G_3)) || ((side == RIGHT) && (move == G_2))) ? atan2((center_y - end_y), (center_x - end_x)) : atan2((end_y - center_y), (end_x - center_x)); settings->program_x = end_x; settings->program_y = end_y; end_x = (end_x + (tool_radius * cos(gamma))); /* end_x reset actual */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -