command.c
来自「CNC 的开放码,EMC2 V2.2.8版」· C语言 代码 · 共 1,479 行 · 第 1/4 页
C
1,479 行
joint->free_tp_enable = 1; SET_JOINT_ERROR_FLAG(joint, 0); /* clear axis homed flag(s) if we don't have forward kins. Otherwise, a transition into coordinated mode will incorrectly assume the homed position. Do all if they've all been moved since homing, otherwise just do this one */ clearHomes(joint_num); break; case EMCMOT_JOG_ABS: /* do an absolute jog */ /* check axis range */ rtapi_print_msg(RTAPI_MSG_DBG, "JOG_ABS"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num); if (joint == 0) { break; } /* must be in free mode and enabled */ if (GET_MOTION_COORD_FLAG()) { reportError("Can't jog axis in coordinated mode."); SET_JOINT_ERROR_FLAG(joint, 1); break; } if (!GET_MOTION_ENABLE_FLAG()) { reportError("Can't jog axis when not enabled."); SET_JOINT_ERROR_FLAG(joint, 1); break; } if (emcmotStatus->homing_active) { reportError("Can't jog any axis while homing."); SET_JOINT_ERROR_FLAG(joint, 1); break; } if (joint->wheel_jog_active) { /* can't do two kinds of jog at once */ break; } if (emcmotStatus->net_feed_scale < 0.0001 ) { /* don't jog if feedhold is on or if feed override is zero */ break; } /* don't jog further onto limits */ if (!jog_ok(joint_num, emcmotCommand->vel)) { SET_JOINT_ERROR_FLAG(joint, 1); break; } /*! \todo FIXME-- use 'goal' instead */ joint->free_pos_cmd = emcmotCommand->offset; /* don't jog past limits */ refresh_jog_limits(joint); if (joint->free_pos_cmd > joint->max_jog_limit) { joint->free_pos_cmd = joint->max_jog_limit; } if (joint->free_pos_cmd < joint->min_jog_limit) { joint->free_pos_cmd = joint->min_jog_limit; } /* set velocity of jog */ joint->free_vel_lim = fabs(emcmotCommand->vel); /* lock out other jog sources */ joint->kb_jog_active = 1; /* and let it go */ joint->free_tp_enable = 1; SET_JOINT_ERROR_FLAG(joint, 0); /* clear axis homed flag(s) if we don't have forward kins. Otherwise, a transition into coordinated mode will incorrectly assume the homed position. Do all if they've all been moved since homing, otherwise just do this one */ clearHomes(joint_num); break; case EMCMOT_SET_TERM_COND: /* sets termination condition for motion emcmotDebug->queue */ rtapi_print_msg(RTAPI_MSG_DBG, "SET_TERM_COND"); tpSetTermCond(&emcmotDebug->queue, emcmotCommand->termCond, emcmotCommand->tolerance); break; case EMCMOT_SET_SPINDLESYNC: tpSetSpindleSync(&emcmotDebug->queue, emcmotCommand->spindlesync, emcmotCommand->flags); break; case EMCMOT_SET_LINE: /* emcmotDebug->queue up a linear move */ /* requires coordinated mode, enable off, not on limits */ rtapi_print_msg(RTAPI_MSG_DBG, "SET_LINE"); if (!GET_MOTION_COORD_FLAG() || !GET_MOTION_ENABLE_FLAG()) { reportError ("need to be enabled, in coord mode for linear move"); emcmotStatus->commandStatus = EMCMOT_COMMAND_INVALID_COMMAND; SET_MOTION_ERROR_FLAG(1); break; } else if (!inRange(emcmotCommand->pos)) { if(emcmotCommand->id > 0) reportError("linear move on line %d would exceed limits", emcmotCommand->id); else reportError("linear move in MDI would exceed limits"); emcmotStatus->commandStatus = EMCMOT_COMMAND_INVALID_PARAMS; tpAbort(&emcmotDebug->queue); SET_MOTION_ERROR_FLAG(1); break; } else if (!limits_ok()) { reportError("can't do linear move with limits exceeded"); emcmotStatus->commandStatus = EMCMOT_COMMAND_INVALID_PARAMS; tpAbort(&emcmotDebug->queue); SET_MOTION_ERROR_FLAG(1); break; } /* append it to the emcmotDebug->queue */ tpSetId(&emcmotDebug->queue, emcmotCommand->id); if (-1 == tpAddLine(&emcmotDebug->queue, emcmotCommand->pos, emcmotCommand->motion_type, emcmotCommand->vel, emcmotCommand->ini_maxvel, emcmotCommand->acc, emcmotStatus->enables_new)) { reportError("can't add linear move"); emcmotStatus->commandStatus = EMCMOT_COMMAND_BAD_EXEC; tpAbort(&emcmotDebug->queue); SET_MOTION_ERROR_FLAG(1); break; } else { SET_MOTION_ERROR_FLAG(0); /* set flag that indicates all axes need rehoming, if any axis is moved in joint mode, for machines with no forward kins */ rehomeAll = 1; } break; case EMCMOT_SET_CIRCLE: /* emcmotDebug->queue up a circular move */ /* requires coordinated mode, enable on, not on limits */ rtapi_print_msg(RTAPI_MSG_DBG, "SET_CIRCLE"); if (!GET_MOTION_COORD_FLAG() || !GET_MOTION_ENABLE_FLAG()) { reportError ("need to be enabled, in coord mode for circular move"); emcmotStatus->commandStatus = EMCMOT_COMMAND_INVALID_COMMAND; SET_MOTION_ERROR_FLAG(1); break; } else if (!inRange(emcmotCommand->pos)) { if(emcmotCommand->id > 0) reportError("circular move on line %d would exceed limits", emcmotCommand->id); else reportError("circular move in MDI would exceed limits"); emcmotStatus->commandStatus = EMCMOT_COMMAND_INVALID_PARAMS; tpAbort(&emcmotDebug->queue); SET_MOTION_ERROR_FLAG(1); break; } else if (!limits_ok()) { reportError("can't do circular move with limits exceeded"); emcmotStatus->commandStatus = EMCMOT_COMMAND_INVALID_PARAMS; tpAbort(&emcmotDebug->queue); SET_MOTION_ERROR_FLAG(1); break; } /* append it to the emcmotDebug->queue */ tpSetId(&emcmotDebug->queue, emcmotCommand->id); if (-1 == tpAddCircle(&emcmotDebug->queue, emcmotCommand->pos, emcmotCommand->center, emcmotCommand->normal, emcmotCommand->turn, emcmotCommand->motion_type, emcmotCommand->vel, emcmotCommand->ini_maxvel, emcmotCommand->acc, emcmotStatus->enables_new)) { reportError("can't add circular move"); emcmotStatus->commandStatus = EMCMOT_COMMAND_BAD_EXEC; tpAbort(&emcmotDebug->queue); SET_MOTION_ERROR_FLAG(1); break; } else { SET_MOTION_ERROR_FLAG(0); /* set flag that indicates all axes need rehoming, if any axis is moved in joint mode, for machines with no forward kins */ rehomeAll = 1; } break; case EMCMOT_SET_VEL: /* set the velocity for subsequent moves */ /* can do it at any time */ rtapi_print_msg(RTAPI_MSG_DBG, "SET_VEL"); emcmotStatus->vel = emcmotCommand->vel; tpSetVmax(&emcmotDebug->queue, emcmotStatus->vel, emcmotCommand->ini_maxvel); break; case EMCMOT_SET_VEL_LIMIT: rtapi_print_msg(RTAPI_MSG_DBG, "SET_VEL_LIMIT"); emcmot_config_change(); /* set the absolute max velocity for all subsequent moves */ /* can do it at any time */ emcmotConfig->limitVel = emcmotCommand->vel; tpSetVlimit(&emcmotDebug->queue, emcmotConfig->limitVel); break; case EMCMOT_SET_JOINT_VEL_LIMIT: rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_VEL_LIMIT"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num); emcmot_config_change(); /* check axis range */ if (joint == 0) { break; } joint->vel_limit = emcmotCommand->vel; joint->big_vel = 10 * emcmotCommand->vel; break; case EMCMOT_SET_JOINT_ACC_LIMIT: rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_ACC_LIMIT"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num); emcmot_config_change(); /* check axis range */ if (joint == 0) { break; } joint->acc_limit = emcmotCommand->acc; break; case EMCMOT_SET_ACC: /* set the max acceleration */ /* can do it at any time */ rtapi_print_msg(RTAPI_MSG_DBG, "SET_ACCEL"); emcmotStatus->acc = emcmotCommand->acc; tpSetAmax(&emcmotDebug->queue, emcmotStatus->acc); break; case EMCMOT_PAUSE: /* pause the motion */ /* can happen at any time */ rtapi_print_msg(RTAPI_MSG_DBG, "PAUSE"); tpPause(&emcmotDebug->queue); emcmotStatus->paused = 1; break; case EMCMOT_RESUME: /* resume paused motion */ /* can happen at any time */ rtapi_print_msg(RTAPI_MSG_DBG, "RESUME"); emcmotDebug->stepping = 0; tpResume(&emcmotDebug->queue); emcmotStatus->paused = 0; break; case EMCMOT_STEP: /* resume paused motion until id changes */ /* can happen at any time */ rtapi_print_msg(RTAPI_MSG_DBG, "STEP"); if(emcmotStatus->paused) { emcmotDebug->idForStep = emcmotStatus->id; emcmotDebug->stepping = 1; tpResume(&emcmotDebug->queue); emcmotStatus->paused = 1; } else { reportError("MOTION: can't STEP while already executing"); } break; case EMCMOT_FEED_SCALE: /* override speed */ /* can happen at any time */ rtapi_print_msg(RTAPI_MSG_DBG, "FEED SCALE"); if (emcmotCommand->scale < 0.0) { emcmotCommand->scale = 0.0; /* clamp it */ } emcmotStatus->feed_scale = emcmotCommand->scale; break; case EMCMOT_FS_ENABLE: /* enable/disable overriding speed */ /* can happen at any time */ if ( emcmotCommand->mode != 0 ) { rtapi_print_msg(RTAPI_MSG_DBG, "FEED SCALE: ON"); emcmotStatus->enables_new |= FS_ENABLED; } else { rtapi_print_msg(RTAPI_MSG_DBG, "FEED SCALE: OFF"); emcmotStatus->enables_new &= ~FS_ENABLED; } break; case EMCMOT_FH_ENABLE: /* enable/disable feed hold */ /* can happen at any time */ if ( emcmotCommand->mode != 0 ) { rtapi_print_msg(RTAPI_MSG_DBG, "FEED HOLD: ENABLED"); emcmotStatus->enables_new |= FH_ENABLED; } else { rtapi_print_msg(RTAPI_MSG_DBG, "FEED HOLD: DISABLED"); emcmotStatus->enables_new &= ~FH_ENABLED; } break; case EMCMOT_SPINDLE_SCALE: /* override spindle speed */ /* can happen at any time */ rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE SCALE"); if (emcmotCommand->scale < 0.0) { emcmotCommand->scale = 0.0; /* clamp it */ } emcmotStatus->spindle_scale = emcmotCommand->scale; break; case EMCMOT_SS_ENABLE: /* enable/disable overriding spindle speed */ /* can happen at any time */ if ( emcmotCommand->mode != 0 ) { rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE SCALE: ON"); emcmotStatus->enables_new |= SS_ENABLED; } else { rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE SCALE: OFF"); emcmotStatus->enables_new &= ~SS_ENABLED; } break; case EMCMOT_AF_ENABLE: /* enable/disable adaptive feedrate override from HAL pin */ /* can happen at any time */ if ( emcmotCommand->flags != 0 ) { rtapi_print_msg(RTAPI_MSG_DBG, "ADAPTIVE FEED: ON"); emcmotStatus->enables_new |= AF_ENABLED; } else { rtapi_print_msg(RTAPI_MSG_DBG, "ADAPTIVE FEED: OFF"); emcmotStatus->enables_new &= ~AF_ENABLED; } break; case EMCMOT_DISABLE: /* go into disable */ /* can happen at any time */ /* reset the emcmotDebug->enabling flag to defer disable until controller cycle (it *will* be honored) */ rtapi_print_msg(RTAPI_MSG_DBG, "DISABLE"); emcmotDebug->enabling = 0; if (kinType == KINEMATICS_INVERSE_ONLY) { emcmotDebug->teleoperating = 0; emcmotDebug->coordinating = 0; } break; case EMCMOT_ENABLE: /* come out of disable */ /* can happen at any time */ /* set the emcmotDebug->enabling flag to defer enable until controller cycle */ rtapi_print_msg(RTAPI_MSG_DBG, "ENABLE"); if ( *(emcmot_hal_data->enable) == 0 ) { reportError("can't enable motion, enable input is false"); } else { emcmotDebug->enabling = 1; if (kinType == KINEMATICS_INVERSE_ONLY) { emcmotDebug->teleoperating = 0; emcmotDebug->coordinating = 0; } } break; case EMCMOT_ACTIVATE_JOINT: /* make axis active, so that amps will be enabled when system is enabled or disabled */ /* can be done at any time */ rtapi_print_msg(RTAPI_MSG_DBG, "ACTIVATE_JOINT"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num); if (joint == 0) { break; } SET_JOINT_ACTIVE_FLAG(joint, 1); break; case EMCMOT_DEACTIVATE_JOINT: /* make axis inactive, so that amps won't be affected when system is enabled or disabled */ /* can be done at any time */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?