📄 halui.cc
字号:
return -1;}static void thisQuit(){ 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; } 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*/// comment out for now, not used, causes a warning//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;//}// polarities for axis jogging, from ini filestatic int jogPol[EMC_AXIS_MAX];int halui_export_pin_RD_bit(hal_bit_t **pin, char name[HAL_NAME_LEN+2]) { int retval; retval = hal_pin_bit_new(name, HAL_RD, pin, comp_id); if (retval != HAL_SUCCESS) { rtapi_print_msg(RTAPI_MSG_ERR,"HALUI: ERROR: halui pin %s export failed with err=%i\n", name, retval); hal_exit(comp_id); return -1; } return HAL_SUCCESS;}int halui_export_pin_WR_bit(hal_bit_t **pin, char name[HAL_NAME_LEN+2]) { int retval; retval = hal_pin_bit_new(name, HAL_WR, pin, comp_id); if (retval != HAL_SUCCESS) { rtapi_print_msg(RTAPI_MSG_ERR,"HALUI: ERROR: halui pin %s export failed with err=%i\n", name, retval); hal_exit(comp_id); return -1; } return HAL_SUCCESS;}/********************************************************************** Description: halui_hal_init(void)** Side Effects: Exports HAL pins.** Called By: main********************************************************************/int halui_hal_init(void){ int retval; /* STEP 1: initialise the hal component */ comp_id = hal_init("halui"); if (comp_id < 0) { rtapi_print_msg(RTAPI_MSG_ERR, "HALUI: ERROR: hal_init() failed\n"); return -1; } /* STEP 2: allocate shared memory for halui data */ halui_data = (halui_str *) hal_malloc(sizeof(halui_str)); if (halui_data == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "HALUI: ERROR: hal_malloc() failed\n"); hal_exit(comp_id); return -1; } /* STEP 3a: export the out-pin(s) */ //halui.machine.is-on //pin for machine is On/Off retval = halui_export_pin_WR_bit(&(halui_data->machine_is_on), "halui.machine.is-on"); if (retval != HAL_SUCCESS) return -1; //halui.estop.is-activated //pin for machine is On/Off retval = halui_export_pin_WR_bit(&(halui_data->estop_is_activated), "halui.estop.is-activated"); if (retval != HAL_SUCCESS) return -1; //halui.mode.is-manual //pin for mode in manual mode retval = halui_export_pin_WR_bit(&(halui_data->mode_is_manual), "halui.mode.is-manual"); if (retval != HAL_SUCCESS) return -1; //halui.mode.is-auto //pin for mode in auto mode retval = halui_export_pin_WR_bit(&(halui_data->mode_is_auto), "halui.mode.is-auto"); if (retval != HAL_SUCCESS) return -1; //halui.mode.is-mdi //pin for mode in MDI mode retval = halui_export_pin_WR_bit(&(halui_data->mode_is_mdi), "halui.mode.is-mdi"); if (retval != HAL_SUCCESS) return -1; //halui.mist.is-on //pin signifiying mist is turned on retval = halui_export_pin_WR_bit(&(halui_data->mist_is_on), "halui.mist.is-on"); if (retval != HAL_SUCCESS) return -1; //halui.flood.is-on //pin signifiying flood is turned on retval = halui_export_pin_WR_bit(&(halui_data->flood_is_on), "halui.flood.is-on"); if (retval != HAL_SUCCESS) return -1; //halui.lube.is-on //pin signifiying lube is turned on retval = halui_export_pin_WR_bit(&(halui_data->lube_is_on), "halui.lube.is-on"); if (retval != HAL_SUCCESS) return -1; /* STEP 3b: export the in-pin(s) */ //halui.machine.on //pin for setting machine On retval = halui_export_pin_RD_bit(&(halui_data->machine_on), "halui.machine.on"); if (retval != HAL_SUCCESS) return -1; //halui.machine.off //pin for setting machine Off retval = halui_export_pin_RD_bit(&(halui_data->machine_off), "halui.machine.off"); if (retval != HAL_SUCCESS) return -1; //halui.estop.activate //pin for activating ESTOP retval = halui_export_pin_RD_bit(&(halui_data->estop_activate), "halui.estop.activate"); if (retval != HAL_SUCCESS) return -1; //halui.estop.reset //pin for resetting ESTOP retval = halui_export_pin_RD_bit(&(halui_data->estop_reset), "halui.estop.reset"); if (retval != HAL_SUCCESS) return -1; //halui.mode.manual //pin for activating manual mode retval = halui_export_pin_RD_bit(&(halui_data->mode_manual), "halui.mode.manual"); if (retval != HAL_SUCCESS) return -1; //halui.mode.auto //pin for activating auto mode retval = halui_export_pin_RD_bit(&(halui_data->mode_auto), "halui.mode.auto"); if (retval != HAL_SUCCESS) return -1; //halui.mode.mdi //pin for activating mdi mode retval = halui_export_pin_RD_bit(&(halui_data->mode_mdi), "halui.mode.mdi"); if (retval != HAL_SUCCESS) return -1; //halui.mist.on //pin for activating mist retval = halui_export_pin_RD_bit(&(halui_data->mist_on), "halui.mist.on"); if (retval != HAL_SUCCESS) return -1; //halui.mist.off //pin for deactivating mist retval = halui_export_pin_RD_bit(&(halui_data->mist_off), "halui.mist.off"); if (retval != HAL_SUCCESS) return -1; //halui.flood.on //pin for activating flood retval = halui_export_pin_RD_bit(&(halui_data->flood_on), "halui.flood.on"); if (retval != HAL_SUCCESS) return -1; //halui.flood.off //pin for deactivating flood retval = halui_export_pin_RD_bit(&(halui_data->flood_off), "halui.flood.off"); if (retval != HAL_SUCCESS) return -1; //halui.lube.on //pin for activating lube retval = halui_export_pin_RD_bit(&(halui_data->lube_on), "halui.lube.on"); if (retval != HAL_SUCCESS) return -1; //halui.lube.off //pin for deactivating lube retval = halui_export_pin_RD_bit(&(halui_data->lube_off), "halui.lube.off"); if (retval != HAL_SUCCESS) return -1; 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 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 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 sendMistOn(){ EMC_COOLANT_MIST_ON emc_coolant_mist_on_msg; emc_coolant_mist_on_msg.serial_number = ++emcCommandSerialNumber; emcCommandBuffer->write(emc_coolant_mist_on_msg); if (emcWaitType == EMC_WAIT_RECEIVED) { return emcCommandWaitReceived(emcCommandSerialNumber); } else if (emcWaitType == EMC_WAIT_DONE) { return emcCommandWaitDone(emcCommandSerialNumber); } return 0;}static int sendMistOff(){ EMC_COOLANT_MIST_OFF emc_coolant_mist_off_msg; emc_coolant_mist_off_msg.serial_number = ++emcCommandSerialNumber; emcCommandBuffer->write(emc_coolant_mist_off_msg); if (emcWaitType == EMC_WAIT_RECEIVED) { return emcCommandWaitReceived(emcCommandSerialNumber); } else if (emcWaitType == EMC_WAIT_DONE) { return emcCommandWaitDone(emcCommandSerialNumber); } return 0;}static int sendFloodOn(){ EMC_COOLANT_FLOOD_ON emc_coolant_flood_on_msg; emc_coolant_flood_on_msg.serial_number = ++emcCommandSerialNumber; emcCommandBuffer->write(emc_coolant_flood_on_msg); if (emcWaitType == EMC_WAIT_RECEIVED) { return emcCommandWaitReceived(emcCommandSerialNumber); } else if (emcWaitType == EMC_WAIT_DONE) { return emcCommandWaitDone(emcCommandSerialNumber); } return 0;}static int sendFloodOff(){ EMC_COOLANT_FLOOD_OFF emc_coolant_flood_off_msg; emc_coolant_flood_off_msg.serial_number = ++emcCommandSerialNumber; emcCommandBuffer->write(emc_coolant_flood_off_msg); if (emcWaitType == EMC_WAIT_RECEIVED) { return emcCommandWaitReceived(emcCommandSerialNumber); } else if (emcWaitType == EMC_WAIT_DONE) { return emcCommandWaitDone(emcCommandSerialNumber); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -