command.c

来自「CNC 的开放码,EMC2 V2.2.8版」· C语言 代码 · 共 1,479 行 · 第 1/4 页

C
1,479
字号
	    rtapi_print_msg(RTAPI_MSG_DBG, "DEACTIVATE_AXIS");	    rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);	    if (joint == 0) {		break;	    }	    SET_JOINT_ACTIVE_FLAG(joint, 0);	    break;/*! \todo FIXME - need to replace the ext function */	case EMCMOT_ENABLE_AMPLIFIER:	    /* enable the amplifier directly, but don't enable calculations */	    /* can be done at any time */	    rtapi_print_msg(RTAPI_MSG_DBG, "ENABLE_AMP");	    rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);	    if (joint == 0) {		break;	    }/*! \todo Another #if 0 */#if 0	    extAmpEnable(axis, 1);#endif	    break;	case EMCMOT_DISABLE_AMPLIFIER:	    /* disable the axis calculations and amplifier, but don't disable	       calculations */	    /* can be done at any time */	    rtapi_print_msg(RTAPI_MSG_DBG, "DISABLE_AMP");	    rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);	    if (joint == 0) {		break;	    }/*! \todo Another #if 0 */#if 0	    extAmpEnable(axis, 0);#endif	    break;	case EMCMOT_HOME:	    /* home the specified axis */	    /* need to be in free mode, enable on */	    /* this just sets the initial state, then the state machine in	       control.c does the rest */	    rtapi_print_msg(RTAPI_MSG_DBG, "HOME");	    rtapi_print_msg(RTAPI_MSG_DBG, " %d", joint_num);	    if (emcmotStatus->motion_state != EMCMOT_MOTION_FREE) {		/* can't home unless in free mode */		reportError("must be in joint mode to home");		return;	    }	    if (!GET_MOTION_ENABLE_FLAG()) {		break;	    }	    if(joint_num == -1) {                if(emcmotStatus->homingSequenceState == HOME_SEQUENCE_IDLE)                    emcmotStatus->homingSequenceState = HOME_SEQUENCE_START;                else                    reportError("homing sequence already in progress");		break;	    }	    if (joint == NULL) {		break;	    }            if(joint->home_state != HOME_IDLE) {                reportError("homing already in progress");            } else if(emcmotStatus->homingSequenceState != HOME_SEQUENCE_IDLE) {                reportError("homing sequence already in progress");            } else {                /* abort any movement (jog, etc) that is in progress */                joint->free_tp_enable = 0;                                /* prime the homing state machine */                joint->home_state = HOME_START;            }	    break;	case EMCMOT_ENABLE_WATCHDOG:	    rtapi_print_msg(RTAPI_MSG_DBG, "ENABLE_WATCHDOG");/*! \todo Another #if 0 */#if 0	    emcmotDebug->wdEnabling = 1;	    emcmotDebug->wdWait = emcmotCommand->wdWait;	    if (emcmotDebug->wdWait < 0) {		emcmotDebug->wdWait = 0;	    }#endif	    break;	case EMCMOT_DISABLE_WATCHDOG:	    rtapi_print_msg(RTAPI_MSG_DBG, "DISABLE_WATCHDOG");/*! \todo Another #if 0 */#if 0	    emcmotDebug->wdEnabling = 0;#endif	    break;	case EMCMOT_CLEAR_PROBE_FLAGS:	    rtapi_print_msg(RTAPI_MSG_DBG, "CLEAR_PROBE_FLAGS");	    emcmotStatus->probing = 0;	    break;	case EMCMOT_PROBE:	    /* most of this is taken from EMCMOT_SET_LINE */	    /* emcmotDebug->queue up a linear move */	    /* requires coordinated mode, enable off, not on limits */	    rtapi_print_msg(RTAPI_MSG_DBG, "PROBE");	    if (!GET_MOTION_COORD_FLAG() || !GET_MOTION_ENABLE_FLAG()) {		reportError		    ("need to be enabled, in coord mode for probe move");		emcmotStatus->commandStatus = EMCMOT_COMMAND_INVALID_COMMAND;		SET_MOTION_ERROR_FLAG(1);		break;	    } else if (!inRange(emcmotCommand->pos)) {		if(emcmotCommand->id > 0)		    reportError("probe move on line %d would exceed limits",			    emcmotCommand->id);		else		    reportError("probe 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 probe 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 probe move");		emcmotStatus->commandStatus = EMCMOT_COMMAND_BAD_EXEC;		tpAbort(&emcmotDebug->queue);		SET_MOTION_ERROR_FLAG(1);		break;	    } else {		emcmotStatus->probing = 1;		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_RIGID_TAP:	    /* most of this is taken from EMCMOT_SET_LINE */	    /* emcmotDebug->queue up a linear move */	    /* requires coordinated mode, enable off, not on limits */	    rtapi_print_msg(RTAPI_MSG_DBG, "RIGID_TAP");	    if (!GET_MOTION_COORD_FLAG() || !GET_MOTION_ENABLE_FLAG()) {		reportError		    ("need to be enabled, in coord mode for rigid tap move");		emcmotStatus->commandStatus = EMCMOT_COMMAND_INVALID_COMMAND;		SET_MOTION_ERROR_FLAG(1);		break;	    } else if (!inRange(emcmotCommand->pos)) {		if(emcmotCommand->id > 0)		    reportError("rigid tap move on line %d would exceed limits",			    emcmotCommand->id);		else		    reportError("rigid tap 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 rigid tap 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 == tpAddRigidTap(&emcmotDebug->queue, emcmotCommand->pos, emcmotCommand->vel, emcmotCommand->ini_maxvel, emcmotCommand->acc, emcmotStatus->enables_new)) {		reportError("can't add rigid tap move");		emcmotStatus->commandStatus = EMCMOT_COMMAND_BAD_EXEC;		tpAbort(&emcmotDebug->queue);		SET_MOTION_ERROR_FLAG(1);		break;	    } else {		SET_MOTION_ERROR_FLAG(0);	    }	    break;	case EMCMOT_SET_TELEOP_VECTOR:	    rtapi_print_msg(RTAPI_MSG_DBG, "SET_TELEOP_VECTOR");	    if (!GET_MOTION_TELEOP_FLAG() || !GET_MOTION_ENABLE_FLAG()) {		reportError		    ("need to be enabled, in teleop mode for teleop move");	    } else {		double velmag;		emcmotDebug->teleop_data.desiredVel = emcmotCommand->pos;		pmCartMag(emcmotDebug->teleop_data.desiredVel.tran, &velmag);		if (emcmotDebug->teleop_data.desiredVel.a > velmag) {		    velmag = emcmotDebug->teleop_data.desiredVel.a;		}		if (emcmotDebug->teleop_data.desiredVel.b > velmag) {		    velmag = emcmotDebug->teleop_data.desiredVel.b;		}		if (emcmotDebug->teleop_data.desiredVel.c > velmag) {		    velmag = emcmotDebug->teleop_data.desiredVel.c;		}		if (velmag > emcmotConfig->limitVel) {		    pmCartScalMult(emcmotDebug->teleop_data.desiredVel.tran,			emcmotConfig->limitVel / velmag,			&emcmotDebug->teleop_data.desiredVel.tran);		    emcmotDebug->teleop_data.desiredVel.a *=			emcmotConfig->limitVel / velmag;		    emcmotDebug->teleop_data.desiredVel.b *=			emcmotConfig->limitVel / velmag;		    emcmotDebug->teleop_data.desiredVel.c *=			emcmotConfig->limitVel / velmag;		}		/* flag that all joints need to be homed, if any joint is		   jogged individually later */		rehomeAll = 1;	    }	    break;	case EMCMOT_SET_DEBUG:	    rtapi_print_msg(RTAPI_MSG_DBG, "SET_DEBUG");	    emcmotConfig->debug = emcmotCommand->debug;	    emcmot_config_change();	    break;	/* needed for synchronous I/O */	case EMCMOT_SET_AOUT:	    if (emcmotCommand->now) { //we set it right away		emcmotAioWrite(emcmotCommand->out, emcmotCommand->minLimit);	    } else { // we put it on the TP queue, warning: only room for one in there, any new ones will overwrite		tpSetAout(&emcmotDebug->queue, emcmotCommand->out,		    emcmotCommand->start, emcmotCommand->end);	    }	    break;	case EMCMOT_SET_DOUT:	    rtapi_print_msg(RTAPI_MSG_DBG, "SET_DOUT");	    if (emcmotCommand->now) { //we set it right away		emcmotDioWrite(emcmotCommand->out, emcmotCommand->start);	    } else { // we put it on the TP queue, warning: only room for one in there, any new ones will overwrite		tpSetDout(&emcmotDebug->queue, emcmotCommand->out,		    emcmotCommand->start, emcmotCommand->end);	    }	    break;	case EMCMOT_SET_SPINDLE_VEL:	    rtapi_print_msg(RTAPI_MSG_DBG, "SET_SPINDLE_VEL");	    emcmotStatus->spindle.speed = emcmotCommand->vel;	    break;	    	case EMCMOT_SPINDLE_ON:	    rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_ON");	    emcmotStatus->spindle.speed = emcmotCommand->vel;	    emcmotStatus->spindle.css_factor = emcmotCommand->ini_maxvel;	    emcmotStatus->spindle.xoffset = emcmotCommand->acc;	    if (emcmotCommand->vel >= 0) {		emcmotStatus->spindle.direction = 1;	    } else {		emcmotStatus->spindle.direction = -1;	    }	    emcmotStatus->spindle.brake = 0; //disengage brake	    break;	case EMCMOT_SPINDLE_OFF:	    rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_OFF");	    emcmotStatus->spindle.speed = 0;	    emcmotStatus->spindle.direction = 0;	    emcmotStatus->spindle.brake = 1; // engage brake	    break;	case EMCMOT_SPINDLE_INCREASE:	    rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_INCREASE");	    if (emcmotStatus->spindle.speed > 0) {		emcmotStatus->spindle.speed += 100; //FIXME - make the step a HAL parameter	    } else if (emcmotStatus->spindle.speed < 0) {		emcmotStatus->spindle.speed -= 100;	    }	    break;	case EMCMOT_SPINDLE_DECREASE:	    rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_DECREASE");	    if (emcmotStatus->spindle.speed > 100) {		emcmotStatus->spindle.speed -= 100; //FIXME - make the step a HAL parameter	    } else if (emcmotStatus->spindle.speed < -100) {		emcmotStatus->spindle.speed += 100;	    }	    break;	case EMCMOT_SPINDLE_BRAKE_ENGAGE:	    rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_BRAKE_ENGAGE");	    emcmotStatus->spindle.speed = 0;	    emcmotStatus->spindle.direction = 0;	    emcmotStatus->spindle.brake = 1;	    break;	case EMCMOT_SPINDLE_BRAKE_RELEASE:	    rtapi_print_msg(RTAPI_MSG_DBG, "SPINDLE_BRAKE_RELEASE");	    emcmotStatus->spindle.brake = 0;	    break;	case EMCMOT_SET_JOINT_COMP:	    rtapi_print_msg(RTAPI_MSG_DBG, "SET_JOINT_COMP for joint %d", joint_num);	    if (joint == 0) {		break;	    }	    if (joint->comp.entries >= EMCMOT_COMP_SIZE) {		reportError("joint %d: too many compensation entries", joint_num);		break;	    }	    /* point to last entry */	    comp_entry = &(joint->comp.array[joint->comp.entries]);	    if (emcmotCommand->comp_nominal <= comp_entry[0].nominal) {		reportError("joint %d: compensation values must increase", joint_num);		break;	    }	    /* store data to new entry */	    comp_entry[1].nominal = emcmotCommand->comp_nominal;	    comp_entry[1].fwd_trim = emcmotCommand->comp_forward;	    comp_entry[1].rev_trim = emcmotCommand->comp_reverse;	    /* calculate slopes from previous entry to the new one */	    if ( comp_entry[0].nominal != -DBL_MAX ) {		/* but only if the previous entry is "real" */		tmp1 = comp_entry[1].nominal - comp_entry[0].nominal;		comp_entry[0].fwd_slope =		    (comp_entry[1].fwd_trim - comp_entry[0].fwd_trim) / tmp1;		comp_entry[0].rev_slope =		    (comp_entry[1].rev_trim - comp_entry[0].rev_trim) / tmp1;	    } else {		/* previous entry is at minus infinity, slopes are zero */		comp_entry[0].fwd_trim = comp_entry[1].fwd_trim;		comp_entry[0].rev_trim = comp_entry[1].rev_trim;	    }	    joint->comp.entries++;	    break;	default:	    rtapi_print_msg(RTAPI_MSG_DBG, "UNKNOWN");	    reportError("unrecognized command %d", emcmotCommand->command);	    emcmotStatus->commandStatus = EMCMOT_COMMAND_UNKNOWN_COMMAND;	    break;	}			/* end of: command switch */	if (emcmotStatus->commandStatus != EMCMOT_COMMAND_OK) {	    rtapi_print_msg(RTAPI_MSG_DBG, "ERRROR: %d",		emcmotStatus->commandStatus);	}	rtapi_print_msg(RTAPI_MSG_DBG, "\n");	/* synch tail count */	emcmotStatus->tail = emcmotStatus->head;	emcmotConfig->tail = emcmotConfig->head;	emcmotDebug->tail = emcmotDebug->head;    }    /* end of: if-new-command */check_stuff ( "after command_handler()" );    return;}

⌨️ 快捷键说明

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