📄 emccanon.cc
字号:
read-ahead time */ set_offset_msg.offset.tran.x = TO_EXT_LEN(currentXToolOffset); set_offset_msg.offset.tran.y = 0.0; set_offset_msg.offset.tran.z = TO_EXT_LEN(currentZToolOffset); set_offset_msg.offset.a = 0.0; set_offset_msg.offset.b = 0.0; set_offset_msg.offset.c = 0.0; if(css_maximum && spindleOn) { EMC_SPINDLE_ON emc_spindle_on_msg; emc_spindle_on_msg.speed = css_maximum; emc_spindle_on_msg.factor = css_numerator; emc_spindle_on_msg.xoffset = TO_EXT_LEN(currentXToolOffset); interp_list.append(emc_spindle_on_msg); } interp_list.append(set_offset_msg);}/* CHANGE_TOOL results from M6, for example */void CHANGE_TOOL(int slot){ EMC_TRAJ_LINEAR_MOVE linearMoveMsg; linearMoveMsg.feed_mode = feed_mode; EMC_TOOL_LOAD load_tool_msg; flush_segments(); /* optional move to tool change position. This * is a mess because we really want a configurable chain * of events to happen when a tool change is called for. * Since they'll probably involve motion, we can't just * do it in HAL. This is basic support for making one * move to a particular coordinate before the tool change * is called. */ if (HAVE_TOOL_CHANGE_POSITION) { double vel, acc, x, y, z, a, b, c; x = FROM_EXT_LEN(TOOL_CHANGE_POSITION.tran.x); y = FROM_EXT_LEN(TOOL_CHANGE_POSITION.tran.y); z = FROM_EXT_LEN(TOOL_CHANGE_POSITION.tran.z); a = FROM_EXT_ANG(TOOL_CHANGE_POSITION.a); b = FROM_EXT_ANG(TOOL_CHANGE_POSITION.b); c = FROM_EXT_ANG(TOOL_CHANGE_POSITION.c); // XXX for now, don't move uvw for a tool change vel = getStraightVelocity(x, y, z, a, b, c, canonEndPoint.u, canonEndPoint.v, canonEndPoint.w); acc = getStraightAcceleration(x, y, z, a, b, c, canonEndPoint.u, canonEndPoint.v, canonEndPoint.w); linearMoveMsg.end.tran.x = TO_EXT_LEN(x); linearMoveMsg.end.tran.y = TO_EXT_LEN(y); linearMoveMsg.end.tran.z = TO_EXT_LEN(z); linearMoveMsg.end.a = TO_EXT_ANG(a); linearMoveMsg.end.b = TO_EXT_ANG(b); linearMoveMsg.end.c = TO_EXT_ANG(c); linearMoveMsg.end.u = TO_EXT_LEN(canonEndPoint.u); linearMoveMsg.end.v = TO_EXT_LEN(canonEndPoint.v); linearMoveMsg.end.w = TO_EXT_LEN(canonEndPoint.w); linearMoveMsg.vel = linearMoveMsg.ini_maxvel = toExtVel(vel); linearMoveMsg.acc = toExtAcc(acc); linearMoveMsg.type = EMC_MOTION_TYPE_TOOLCHANGE; linearMoveMsg.feed_mode = 0; int old_feed_mode = feed_mode; if(feed_mode) STOP_SPEED_FEED_SYNCH(); if(vel && acc) interp_list.append(linearMoveMsg); if(old_feed_mode) START_SPEED_FEED_SYNCH(currentLinearFeedRate, 1); canonUpdateEndPoint(x, y, z, a, b, c, canonEndPoint.u, canonEndPoint.v, canonEndPoint.w); } /* regardless of optional moves above, we'll always send a load tool message */ interp_list.append(load_tool_msg);}/* SELECT_TOOL results from T1, for example */void SELECT_TOOL(int slot){ EMC_TOOL_PREPARE prep_for_tool_msg; prep_for_tool_msg.tool = slot; interp_list.append(prep_for_tool_msg);}/* Misc Functions */void CLAMP_AXIS(CANON_AXIS axis){ /*! \todo FIXME-- unimplemented */}/* setString and addString initializes or adds src to dst, never exceeding dst's maxlen chars.*/static char *setString(char *dst, const char *src, int maxlen){ dst[0] = 0; strncat(dst, src, maxlen - 1); dst[maxlen - 1] = 0; return dst;}static char *addString(char *dst, const char *src, int maxlen){ int dstlen = strlen(dst); int srclen = strlen(src); int actlen; if (srclen >= maxlen - dstlen) { actlen = maxlen - dstlen - 1; dst[maxlen - 1] = 0; } else { actlen = srclen; } strncat(dst, src, actlen); return dst;}/* The probe file is opened with a hot-comment (PROBEOPEN <filename>), and the results of each probed point are written to that file. The file is closed with a (PROBECLOSE) comment.*/static FILE *probefile = NULL;void COMMENT(char *comment){ // nothing need be done here, but you can play tricks with hot comments char msg[LINELEN]; char probefilename[LINELEN]; char *ptr; // set RPY orientation for subsequent moves if (!strncmp(comment, "RPY", strlen("RPY"))) { PM_RPY rpy; // it's RPY <R> <P> <Y> if (3 != sscanf(comment, "%*s %lf %lf %lf", &rpy.r, &rpy.p, &rpy.y)) { // print current orientation printf("rpy = %f %f %f, quat = %f %f %f %f\n", rpy.r, rpy.p, rpy.y, quat.s, quat.x, quat.y, quat.z); } else { // set and print orientation quat = rpy; printf("rpy = %f %f %f, quat = %f %f %f %f\n", rpy.r, rpy.p, rpy.y, quat.s, quat.x, quat.y, quat.z); } return; } // open probe output file if (!strncmp(comment, "PROBEOPEN", strlen("PROBEOPEN"))) { // position ptr to first char after PROBEOPEN ptr = &comment[strlen("PROBEOPEN")]; // and step over white space to name, or NULL while (isspace(*ptr)) { ptr++; } setString(probefilename, ptr, LINELEN); if (NULL == (probefile = fopen(probefilename, "w"))) { // pop up a warning message setString(msg, "can't open probe file ", LINELEN); addString(msg, probefilename, LINELEN); MESSAGE(msg); probefile = NULL; } return; } // close probe output file if (!strncmp(comment, "PROBECLOSE", strlen("PROBECLOSE"))) { if (probefile != NULL) { fclose(probefile); probefile = NULL; } return; } return;}// refers to feed ratevoid DISABLE_FEED_OVERRIDE(){ EMC_TRAJ_SET_FO_ENABLE set_fo_enable_msg; flush_segments(); set_fo_enable_msg.mode = 0; interp_list.append(set_fo_enable_msg);}void ENABLE_FEED_OVERRIDE(){ EMC_TRAJ_SET_FO_ENABLE set_fo_enable_msg; flush_segments(); set_fo_enable_msg.mode = 1; interp_list.append(set_fo_enable_msg);}//refers to adaptive feed override (HAL input, usefull for EDM for example)void DISABLE_ADAPTIVE_FEED(){ EMC_MOTION_ADAPTIVE emcmotAdaptiveMsg; flush_segments(); emcmotAdaptiveMsg.status = 0; interp_list.append(emcmotAdaptiveMsg);}void ENABLE_ADAPTIVE_FEED(){ EMC_MOTION_ADAPTIVE emcmotAdaptiveMsg; flush_segments(); emcmotAdaptiveMsg.status = 1; interp_list.append(emcmotAdaptiveMsg);}//refers to spindle speedvoid DISABLE_SPEED_OVERRIDE(){ EMC_TRAJ_SET_SO_ENABLE set_so_enable_msg; flush_segments(); set_so_enable_msg.mode = 0; interp_list.append(set_so_enable_msg);}void ENABLE_SPEED_OVERRIDE(){ EMC_TRAJ_SET_SO_ENABLE set_so_enable_msg; flush_segments(); set_so_enable_msg.mode = 1; interp_list.append(set_so_enable_msg);}void ENABLE_FEED_HOLD(){ EMC_TRAJ_SET_FH_ENABLE set_feed_hold_msg; flush_segments(); set_feed_hold_msg.mode = 1; interp_list.append(set_feed_hold_msg);}void DISABLE_FEED_HOLD(){ EMC_TRAJ_SET_FH_ENABLE set_feed_hold_msg; flush_segments(); set_feed_hold_msg.mode = 0; interp_list.append(set_feed_hold_msg);}void FLOOD_OFF(){ EMC_COOLANT_FLOOD_OFF flood_off_msg; flush_segments(); interp_list.append(flood_off_msg);}void FLOOD_ON(){ EMC_COOLANT_FLOOD_ON flood_on_msg; flush_segments(); interp_list.append(flood_on_msg);}void MESSAGE(char *s){ EMC_OPERATOR_DISPLAY operator_display_msg; flush_segments(); operator_display_msg.id = 0; strncpy(operator_display_msg.display, s, LINELEN); operator_display_msg.display[LINELEN - 1] = 0; interp_list.append(operator_display_msg);}void MIST_OFF(){ EMC_COOLANT_MIST_OFF mist_off_msg; flush_segments(); interp_list.append(mist_off_msg);}void MIST_ON(){ EMC_COOLANT_MIST_ON mist_on_msg; flush_segments(); interp_list.append(mist_on_msg);}void PALLET_SHUTTLE(){ /*! \todo FIXME-- unimplemented */}void TURN_PROBE_OFF(){ // don't do anything-- this is called when the probing is done}void TURN_PROBE_ON(){ EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG clearMsg; interp_list.append(clearMsg);}void UNCLAMP_AXIS(CANON_AXIS axis){ /*! \todo FIXME-- unimplemented */}/* Program Functions */void PROGRAM_STOP(){ /* implement this as a pause. A resume will cause motion to proceed. */ EMC_TASK_PLAN_PAUSE pauseMsg; flush_segments(); interp_list.append(pauseMsg);}void SET_BLOCK_DELETE(bool state){ block_delete = state; //state == ON, means we don't interpret lines starting with "/"}bool GET_BLOCK_DELETE(){ return block_delete; //state == ON, means we don't interpret lines starting with "/"}void SET_OPTIONAL_PROGRAM_STOP(bool state){ optional_program_stop = state; //state == ON, means we stop}bool GET_OPTIONAL_PROGRAM_STOP(){ return optional_program_stop; //state == ON, means we stop}void OPTIONAL_PROGRAM_STOP(){ EMC_TASK_PLAN_OPTIONAL_STOP stopMsg; flush_segments(); interp_list.append(stopMsg);}void PROGRAM_END(){ flush_segments(); EMC_TASK_PLAN_END endMsg; interp_list.append(endMsg);}/* returns the current x, y, z origin offsets */CANON_VECTOR GET_PROGRAM_ORIGIN(){ CANON_VECTOR origin; /* and convert from mm units to interpreter units */ origin.x = TO_PROG_LEN(programOrigin.x); origin.y = TO_PROG_LEN(programOrigin.y); origin.z = TO_PROG_LEN(programOrigin.z); return origin; /* in program units */}/* returns the current active units */CANON_UNITS GET_LENGTH_UNITS(){ return lengthUnits;}CANON_PLANE GET_PLANE(){ return activePlane;}double GET_EXTERNAL_TOOL_LENGTH_XOFFSET(){ return TO_PROG_LEN(currentXToolOffset);}double GET_EXTERNAL_TOOL_LENGTH_ZOFFSET(){ return TO_PROG_LEN(currentZToolOffset);}/* INIT_CANON() Initialize canonical local variables to defaults */void INIT_CANON(){ double units; chained_points().clear(); // initialize locals to original values programOrigin.x = 0.0; programOrigin.y = 0.0; programOrigin.z = 0.0; programOrigin.a = 0.0; programOrigin.b = 0.0; programOrigin.c = 0.0; activePlane = CANON_PLANE_XY; canonEndPoint.x = 0.0; canonEndPoint.y = 0.0; canonEndPoint.z = 0.0; canonEndPoint.a = 0.0; canonEndPoint.b = 0.0; canonEndPoint.c = 0.0; SET_MOTION_CONTROL_MODE(CANON_CONTINUOUS, 0); spindleSpeed = 0.0; preppedTool = 0; cartesian_move = 0; angular_move = 0; currentLinearFeedRate = 0.0; currentAngularFeedRate = 0.0; currentXToolOffset = 0.0; currentZToolOffset = 0.0; /* to set the units, note that GET_EXTERNAL_LENGTH_UNITS() returns traj->linearUnits, which is already set from the .ini file in iniTraj(). This is a floating point number, in user units per mm. We can compare this against known values and set the symbolic values accordingly. If it doesn't match, we have an error. */ units = GET_EXTERNAL_LENGTH_UNITS(); if (fabs(units - 1.0 / 25.4) < 1.0e-3) { lengthUnits = CANON_UNITS_INCHES; } else if (fabs(units - 1.0) < 1.0e-3) { lengthUnits = CANON_UNITS_MM; } else { CANON_ERROR ("non-standard length units, setting interpreter to mm"); lengthUnits = CANON_UNITS_MM; }}/* Sends error message */void CANON_ERROR(const char *fmt, ...){ va_list ap;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -