command.c
来自「CNC 的开放码,EMC2 V2.2.8版」· C语言 代码 · 共 1,479 行 · 第 1/4 页
C
1,479 行
rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->axis); /* check for coord or free space motion active */ if (GET_MOTION_TELEOP_FLAG()) { emcmotDebug->teleop_data.desiredVel.tran.x = 0.0; emcmotDebug->teleop_data.desiredVel.tran.y = 0.0; emcmotDebug->teleop_data.desiredVel.tran.z = 0.0; emcmotDebug->teleop_data.desiredVel.a = 0.0; emcmotDebug->teleop_data.desiredVel.b = 0.0; emcmotDebug->teleop_data.desiredVel.c = 0.0; } else if (GET_MOTION_COORD_FLAG()) { tpAbort(&emcmotDebug->queue); SET_MOTION_ERROR_FLAG(0); } else { for (joint_num = 0; joint_num < num_joints; joint_num++) { /* point to joint struct */ joint = &joints[joint_num]; /* tell joint planner to stop */ joint->free_tp_enable = 0; /* stop homing if in progress */ if ( joint->home_state != HOME_IDLE ) { joint->home_state = HOME_ABORT; } } } /* clear axis errors (regardless of mode */ for (joint_num = 0; joint_num < num_joints; joint_num++) { /* point to joint struct */ joint = &joints[joint_num]; /* update status flags */ SET_JOINT_ERROR_FLAG(joint, 0); SET_JOINT_FAULT_FLAG(joint, 0); } break; case EMCMOT_AXIS_ABORT: /* abort one axis */ /* can happen at any time */ /* this command stops a single axis. It is only usefull in free mode, so in coord or teleop mode it does nothing. */ rtapi_print_msg(RTAPI_MSG_DBG, "AXIS_ABORT"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->axis); if (GET_MOTION_TELEOP_FLAG()) { /* do nothing in teleop mode */ } else if (GET_MOTION_COORD_FLAG()) { /* do nothing in coord mode */ } else { /* validate joint */ if (joint == 0) { break; } /* tell joint planner to stop */ joint->free_tp_enable = 0; /* stop homing if in progress */ if ( joint->home_state != HOME_IDLE ) { joint->home_state = HOME_ABORT; } /* update status flags */ SET_JOINT_ERROR_FLAG(joint, 0); } break; case EMCMOT_FREE: /* change the mode to free axis motion */ /* can be done at any time */ /* this code doesn't actually make the transition, it merely requests the transition by clearing a couple of flags */ /* reset the emcmotDebug->coordinating flag to defer transition to controller cycle */ rtapi_print_msg(RTAPI_MSG_DBG, "FREE"); emcmotDebug->coordinating = 0; emcmotDebug->teleoperating = 0; break; case EMCMOT_COORD: /* change the mode to coordinated axis motion */ /* can be done at any time */ /* this code doesn't actually make the transition, it merely tests a condition and then sets a flag requesting the transition */ /* set the emcmotDebug->coordinating flag to defer transition to controller cycle */ rtapi_print_msg(RTAPI_MSG_DBG, "COORD"); emcmotDebug->coordinating = 1; emcmotDebug->teleoperating = 0; if (kinType != KINEMATICS_IDENTITY) { if (!checkAllHomed()) { reportError ("all axes must be homed before going into coordinated mode"); emcmotDebug->coordinating = 0; break; } } break; case EMCMOT_TELEOP: /* change the mode to teleop motion */ /* can be done at any time */ /* this code doesn't actually make the transition, it merely tests a condition and then sets a flag requesting the transition */ /* set the emcmotDebug->teleoperating flag to defer transition to controller cycle */ rtapi_print_msg(RTAPI_MSG_DBG, "TELEOP"); emcmotDebug->teleoperating = 1; if (kinType != KINEMATICS_IDENTITY) { if (!checkAllHomed()) { reportError ("all axes must be homed before going into teleop mode"); emcmotDebug->teleoperating = 0; break; } } break; case EMCMOT_SET_NUM_AXES: /* set the global NUM_AXES, which must be between 1 and EMCMOT_MAX_AXIS, inclusive */ /* this sets a global - I hate globals - hopefully this can be moved into the config structure, or dispensed with completely */ rtapi_print_msg(RTAPI_MSG_DBG, "SET_NUM_AXES"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->axis); if (( emcmotCommand->axis <= 0 ) || ( emcmotCommand->axis > EMCMOT_MAX_AXIS )) { break; } num_axes = emcmotCommand->axis; emcmotConfig->numAxes = num_axes; break; case EMCMOT_SET_WORLD_HOME: rtapi_print_msg(RTAPI_MSG_DBG, "SET_WORLD_HOME"); emcmotStatus->world_home = emcmotCommand->pos; break; case EMCMOT_SET_HOMING_PARAMS: rtapi_print_msg(RTAPI_MSG_DBG, "SET_HOMING_PARAMS"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num); emcmot_config_change(); if (joint == 0) { break; } joint->home_offset = emcmotCommand->offset; joint->home = emcmotCommand->home; joint->home_search_vel = emcmotCommand->search_vel; joint->home_latch_vel = emcmotCommand->latch_vel; joint->home_flags = emcmotCommand->flags; joint->home_sequence = emcmotCommand->home_sequence; break; case EMCMOT_OVERRIDE_LIMITS: /* this command can be issued with axix < 0 to re-enable limits, but they are automatically re-enabled at the end of the next jog */ rtapi_print_msg(RTAPI_MSG_DBG, "OVERRIDE_LIMITS"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->axis); if (emcmotCommand->axis < 0) { /* don't override limits */ rtapi_print_msg(RTAPI_MSG_DBG, "override off"); emcmotStatus->overrideLimitMask = 0; } else { rtapi_print_msg(RTAPI_MSG_DBG, "override on"); emcmotStatus->overrideLimitMask = 0; for (joint_num = 0; joint_num < num_joints; joint_num++) { /* point at joint data */ joint = &joints[joint_num]; /* only override limits that are currently tripped */ if ( GET_JOINT_NHL_FLAG(joint) ) { emcmotStatus->overrideLimitMask |= (1 << (joint_num*2)); } if ( GET_JOINT_PHL_FLAG(joint) ) { emcmotStatus->overrideLimitMask |= (2 << (joint_num*2)); } } } emcmotDebug->overriding = 0; for (joint_num = 0; joint_num < num_joints; joint_num++) { /* point at joint data */ joint = &joints[joint_num]; /* clear joint errors */ SET_JOINT_ERROR_FLAG(joint, 0); } break; case EMCMOT_SET_MOTOR_OFFSET: rtapi_print_msg(RTAPI_MSG_DBG, "SET_MOTOR_OFFSET"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", emcmotCommand->axis); if(joint == 0) { break; } joint->motor_offset = emcmotCommand->motor_offset; break; case EMCMOT_SET_POSITION_LIMITS: /* sets soft limits for an axis */ rtapi_print_msg(RTAPI_MSG_DBG, "SET_POSITION_LIMITS"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num); emcmot_config_change(); /* set the position limits for the axis */ /* can be done at any time */ if (joint == 0) { break; } joint->min_pos_limit = emcmotCommand->minLimit; joint->max_pos_limit = emcmotCommand->maxLimit; break; case EMCMOT_SET_BACKLASH: /* sets backlash for an axis */ rtapi_print_msg(RTAPI_MSG_DBG, "SET_BACKLASH"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num); emcmot_config_change(); /* set the backlash for the axis */ /* can be done at any time */ if (joint == 0) { break; } joint->backlash = emcmotCommand->backlash; break; /* Max and min ferror work like this: limiting ferror is determined by slope of ferror line, = maxFerror/limitVel -> limiting ferror = maxFerror/limitVel * vel. If ferror < minFerror then OK else if ferror < limiting ferror then OK else ERROR */ case EMCMOT_SET_MAX_FERROR: rtapi_print_msg(RTAPI_MSG_DBG, "SET_MAX_FERROR"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num); emcmot_config_change(); if (joint == 0 || emcmotCommand->maxFerror < 0.0) { break; } joint->max_ferror = emcmotCommand->maxFerror; break; case EMCMOT_SET_MIN_FERROR: rtapi_print_msg(RTAPI_MSG_DBG, "SET_MIN_FERROR"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num); emcmot_config_change(); if (joint == 0 || emcmotCommand->minFerror < 0.0) { break; } joint->min_ferror = emcmotCommand->minFerror; break; case EMCMOT_JOG_CONT: /* do a continuous jog, implemented as an incremental jog to the limit. When the user lets go of the button an abort will stop the jog. */ rtapi_print_msg(RTAPI_MSG_DBG, "JOG_CONT"); rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num); /* check axis range */ 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; } /* set destination of jog */ refresh_jog_limits(joint); if (emcmotCommand->vel > 0.0) { joint->free_pos_cmd = joint->max_jog_limit; } else { 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; /*! \todo FIXME - should we really be clearing errors here? */ 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_INCR: /* do an incremental jog */ /* check axis range */ rtapi_print_msg(RTAPI_MSG_DBG, "JOG_INCR"); 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; } /* set target position for jog */ if (emcmotCommand->vel > 0.0) { tmp1 = joint->free_pos_cmd + emcmotCommand->offset; } else { tmp1 = joint->free_pos_cmd - emcmotCommand->offset; } /* don't jog past limits */ refresh_jog_limits(joint); if (tmp1 > joint->max_jog_limit) { break; } if (tmp1 < joint->min_jog_limit) { break; } /* set target position */ joint->free_pos_cmd = tmp1; /* 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 */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?