⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emcsh.cc

📁 Source code for an Numeric Cmputer
💻 CC
📖 第 1 页 / 共 5 页
字号:
	return -1;    }    switch (type = emcErrorBuffer->read()) {    case -1:	// error reading channel	return -1;	break;    case 0:	// nothing new	break;    case EMC_OPERATOR_ERROR_TYPE:	strncpy(error_string,		((EMC_OPERATOR_ERROR *) (emcErrorBuffer->get_address()))->		error, LINELEN - 1);	error_string[LINELEN - 1] = 0;	break;    case EMC_OPERATOR_TEXT_TYPE:	strncpy(operator_text_string,		((EMC_OPERATOR_TEXT *) (emcErrorBuffer->get_address()))->		text, LINELEN - 1);	operator_text_string[LINELEN - 1] = 0;	break;    case EMC_OPERATOR_DISPLAY_TYPE:	strncpy(operator_display_string,		((EMC_OPERATOR_DISPLAY *) (emcErrorBuffer->					   get_address()))->display,		LINELEN - 1);	operator_display_string[LINELEN - 1] = 0;	break;    case NML_ERROR_TYPE:	strncpy(error_string,		((NML_ERROR *) (emcErrorBuffer->get_address()))->error,		NML_ERROR_LEN - 1);	error_string[NML_ERROR_LEN - 1] = 0;	break;    case NML_TEXT_TYPE:	strncpy(operator_text_string,		((NML_TEXT *) (emcErrorBuffer->get_address()))->text,		NML_TEXT_LEN - 1);	operator_text_string[NML_TEXT_LEN - 1] = 0;	break;    case NML_DISPLAY_TYPE:	strncpy(operator_display_string,		((NML_DISPLAY *) (emcErrorBuffer->get_address()))->display,		NML_DISPLAY_LEN - 1);	operator_display_string[NML_DISPLAY_LEN - 1] = 0;	break;    default:	// if not recognized, set the error string	sprintf(error_string, "unrecognized error %ld", type);	return -1;	break;    }    return 0;}#define EMC_COMMAND_DELAY   0.1	// how long to sleep between checks/*  emcCommandWaitReceived() waits until the EMC reports that it got  the command with the indicated serial_number.  emcCommandWaitDone() waits until the EMC reports that it got the  command with the indicated serial_number, and it's done, or error.*/static int emcCommandWaitReceived(int serial_number){    double end = 0.0;    while (emcTimeout <= 0.0 || end < emcTimeout) {	updateStatus();	if (emcStatus->echo_serial_number == serial_number) {	    return 0;	}	esleep(EMC_COMMAND_DELAY);	end += EMC_COMMAND_DELAY;    }    return -1;}static int emcCommandWaitDone(int serial_number){    double end = 0.0;    // first get it there    if (0 != emcCommandWaitReceived(serial_number)) {	return -1;    }    // now wait until it, or subsequent command (e.g., abort) is done    while (emcTimeout <= 0.0 || end < emcTimeout) {	updateStatus();	if (emcStatus->status == RCS_DONE) {	    return 0;	}	if (emcStatus->status == RCS_ERROR) {	    return -1;	}	esleep(EMC_COMMAND_DELAY);	end += EMC_COMMAND_DELAY;    }    return -1;}static void thisQuit(ClientData clientData){    EMC_NULL emc_null_msg;    if (0 != emcStatusBuffer) {	// wait until current message has been received	emcCommandWaitReceived(emcCommandSerialNumber);    }    if (0 != emcCommandBuffer) {	// send null message to reset serial number to original	emc_null_msg.serial_number = saveEmcCommandSerialNumber;	emcCommandBuffer->write(emc_null_msg);    }    // clean up NML buffers    if (emcErrorBuffer != 0) {	delete emcErrorBuffer;	emcErrorBuffer = 0;    }    if (emcStatusBuffer != 0) {	delete emcStatusBuffer;	emcStatusBuffer = 0;	emcStatus = 0;    }    if (emcCommandBuffer != 0) {	delete emcCommandBuffer;	emcCommandBuffer = 0;    }    Tcl_Exit(0);    exit(0);}/*  Unit conversion  Length and angle units in the EMC status buffer are in user units, as  defined in the INI file in [TRAJ] LINEAR,ANGULAR_UNITS. These may differ  from the program units, and when they are the display is confusing.  It may be desirable to synchronize the display units with the program  units automatically, and also to break this sync and allow independent  display of position values.  The global variable "linearUnitConversion" is set by the Tcl commands  emc_linear_unit_conversion to correspond to either "inch",  "mm", "cm", "auto", or "custom". This forces numbers to be returned in the  units specified, in program units when "auto" is set, or not converted  at all if "custom" is specified.  Ditto for "angularUnitConversion", set by emc_angular_unit_conversion  to "deg", "rad", "grad", "auto", or "custom".  With no args, emc_linear/angular_unit_conversion return the setting.  The functions convertLinearUnits and convertAngularUnits take a length  or angle value, typically from the emcStatus structure, and convert it  as indicated by linearUnitConversion and angularUnitConversion, resp.*/static enum {    LINEAR_UNITS_CUSTOM = 1,    LINEAR_UNITS_AUTO,    LINEAR_UNITS_MM,    LINEAR_UNITS_INCH,    LINEAR_UNITS_CM} linearUnitConversion = LINEAR_UNITS_AUTO;static enum {    ANGULAR_UNITS_CUSTOM = 1,    ANGULAR_UNITS_AUTO,    ANGULAR_UNITS_DEG,    ANGULAR_UNITS_RAD,    ANGULAR_UNITS_GRAD} angularUnitConversion = ANGULAR_UNITS_AUTO;#define CLOSE(a,b,eps) ((a)-(b) < +(eps) && (a)-(b) > -(eps))#define LINEAR_CLOSENESS 0.0001#define ANGULAR_CLOSENESS 0.0001#define INCH_PER_MM (1.0/25.4)#define CM_PER_MM 0.1#define GRAD_PER_DEG (100.0/90.0)#define RAD_PER_DEG TO_RAD	// from posemath.h/*  to convert linear units, values are converted to mm, then to desired  units*/static double convertLinearUnits(double u){    double in_mm;    /* convert u to mm */    in_mm = u / emcStatus->motion.traj.linearUnits;    /* convert u to display units */    switch (linearUnitConversion) {    case LINEAR_UNITS_MM:	return in_mm;	break;    case LINEAR_UNITS_INCH:	return in_mm * INCH_PER_MM;	break;    case LINEAR_UNITS_CM:	return in_mm * CM_PER_MM;	break;    case LINEAR_UNITS_AUTO:	switch (emcStatus->task.programUnits) {	case CANON_UNITS_MM:	    return in_mm;	    break;	case CANON_UNITS_INCHES:	    return in_mm * INCH_PER_MM;	    break;	case CANON_UNITS_CM:	    return in_mm * CM_PER_MM;	    break;	}	break;    case LINEAR_UNITS_CUSTOM:	return u;	break;    }    // If it ever gets here we have an error.    return u;}/*! \todo Another #if 0 */#if 0static double convertAngularUnits(double u){    double in_deg;    /* convert u to deg */    in_deg = u / emcStatus->motion.traj.angularUnits;    /* convert u to display units */    switch (angularUnitConversion) {    case ANGULAR_UNITS_DEG:	return in_deg;	break;    case ANGULAR_UNITS_RAD:	return in_deg * RAD_PER_DEG;	break;    case ANGULAR_UNITS_GRAD:	return in_deg * GRAD_PER_DEG;	break;    case ANGULAR_UNITS_AUTO:	return in_deg;		/*! \todo FIXME-- program units always degrees now */	break;    case ANGULAR_UNITS_CUSTOM:	return u;	break;    }    /* should never get here */    return u;}#endif// polarities for axis jogging, from ini filestatic int jogPol[EMC_AXIS_MAX];static int sendDebug(int level){    EMC_SET_DEBUG debug_msg;    debug_msg.debug = level;    debug_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(debug_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendEstop(){    EMC_TASK_SET_STATE state_msg;    state_msg.state = EMC_TASK_STATE_ESTOP;    state_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(state_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendEstopReset(){    EMC_TASK_SET_STATE state_msg;    state_msg.state = EMC_TASK_STATE_ESTOP_RESET;    state_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(state_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendMachineOn(){    EMC_TASK_SET_STATE state_msg;    state_msg.state = EMC_TASK_STATE_ON;    state_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(state_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendMachineOff(){    EMC_TASK_SET_STATE state_msg;    state_msg.state = EMC_TASK_STATE_OFF;    state_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(state_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendManual(){    EMC_TASK_SET_MODE mode_msg;    mode_msg.mode = EMC_TASK_MODE_MANUAL;    mode_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(mode_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendAuto(){    EMC_TASK_SET_MODE mode_msg;    mode_msg.mode = EMC_TASK_MODE_AUTO;    mode_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(mode_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendMdi(){    EMC_TASK_SET_MODE mode_msg;    mode_msg.mode = EMC_TASK_MODE_MDI;    mode_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(mode_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendOverrideLimits(int axis){    EMC_AXIS_OVERRIDE_LIMITS lim_msg;    lim_msg.axis = axis;	// neg means off, else on for all    lim_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(lim_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int axisJogging = -1;static int sendJogStop(int axis){    EMC_AXIS_ABORT emc_axis_abort_msg;        // in case of TELEOP mode we really need to send an TELEOP_VECTOR message    // not a simple AXIS_ABORT, as more than one axis would be moving    // (hint TELEOP mode is for nontrivial kinematics)    EMC_TRAJ_SET_TELEOP_VECTOR emc_set_teleop_vector;    if (axis < 0 || axis >= EMC_AXIS_MAX) {	return -1;    }    if (emcStatus->motion.traj.mode != EMC_TRAJ_MODE_TELEOP) {	emc_axis_abort_msg.serial_number = ++emcCommandSerialNumber;	emc_axis_abort_msg.axis = axis;	emcCommandBuffer->write(emc_axis_abort_msg);	if (emcWaitType == EMC_WAIT_RECEIVED) {	    return emcCommandWaitReceived(emcCommandSerialNumber);	} else if (emcWaitType == EMC_WAIT_DONE) {	    return emcCommandWaitDone(emcCommandSerialNumber);	}	axisJogging = -1;    }    else {	emc_set_teleop_vector.serial_number = ++emcCommandSerialNumber;	emc_set_teleop_vector.vector.tran.x = 0;	emc_set_teleop_vector.vector.tran.y = 0;	emc_set_teleop_vector.vector.tran.z = 0;	emc_set_teleop_vector.vector.a = 0;	emc_set_teleop_vector.vector.b = 0;	emc_set_teleop_vector.vector.c = 0;	emcCommandBuffer->write(emc_set_teleop_vector);	if (emcWaitType == EMC_WAIT_RECEIVED) {	    return emcCommandWaitReceived(emcCommandSerialNumber);	} else if (emcWaitType == EMC_WAIT_DONE) {	    return emcCommandWaitDone(emcCommandSerialNumber);	}	// \todo FIXME - should remember a list of jogging axes, and remove the last one	axisJogging = -1;	    }    return 0;}static int sendJogCont(int axis, double speed){    EMC_AXIS_JOG emc_axis_jog_msg;    EMC_TRAJ_SET_TELEOP_VECTOR emc_set_teleop_vector;    if (axis < 0 || axis >= EMC_AXIS_MAX) {	return -1;    }    if (emcStatus->motion.traj.mode != EMC_TRAJ_MODE_TELEOP) {	if (0 == jogPol[axis]) {	    speed = -speed;

⌨️ 快捷键说明

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