halui.cc
来自「CNC 的开放码,EMC2 V2.2.8版」· CC 代码 · 共 1,793 行 · 第 1/5 页
CC
1,793 行
hal_bit_t abort; //pin for aborting hal_bit_t mdi_commands[MDI_MAX];} old_halui_data; //pointer to the HAL-structstatic char *mdi_commands[MDI_MAX];static int num_mdi_commands=0;static int comp_id, done; /* component ID, main while loop */static int num_axes = 3; //number of axes, taken from the ini [TRAJ] sectionstatic double maxFeedOverride=1;static double minSpindleOverride=1.0;// no variation allowed by default (old behaviour)static double maxSpindleOverride=1.0;// the real values come from the inistatic EMC_TASK_MODE_ENUM halui_old_mode = EMC_TASK_MODE_MANUAL;static int halui_sent_mdi = 0;// the NML channels to the EMC taskstatic RCS_CMD_CHANNEL *emcCommandBuffer = 0;static RCS_STAT_CHANNEL *emcStatusBuffer = 0;EMC_STAT *emcStatus = 0;// the NML channel for errorsstatic NML *emcErrorBuffer = 0;// the serial number to use. By starting high we'll not clash with other guis so easily.// XXX it would be nice to have a real fix here. XXXstatic int emcCommandSerialNumber = 100000;// default value for timeout, 0 means wait forever// use same timeout value as in tkemc & ministatic double receiveTimeout = 1.;static double doneTimeout = 60.;static void quit(int sig){ done = 1;}static int emcTaskNmlGet(){ int retval = 0; // try to connect to EMC cmd if (emcCommandBuffer == 0) { emcCommandBuffer = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "xemc", EMC_NMLFILE); if (!emcCommandBuffer->valid()) { delete emcCommandBuffer; emcCommandBuffer = 0; retval = -1; } } // try to connect to EMC status if (emcStatusBuffer == 0) { emcStatusBuffer = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "xemc", EMC_NMLFILE); if (!emcStatusBuffer->valid()) { delete emcStatusBuffer; emcStatusBuffer = 0; emcStatus = 0; retval = -1; } else { emcStatus = (EMC_STAT *) emcStatusBuffer->get_address(); } } return retval;}static int emcErrorNmlGet(){ int retval = 0; if (emcErrorBuffer == 0) { emcErrorBuffer = new NML(nmlErrorFormat, "emcError", "xemc", EMC_NMLFILE); if (!emcErrorBuffer->valid()) { delete emcErrorBuffer; emcErrorBuffer = 0; retval = -1; } } return retval;}static int tryNml(){ double end; int good;#define RETRY_TIME 10.0 // seconds to wait for subsystems to come up#define RETRY_INTERVAL 1.0 // seconds between wait tries for a subsystem if (EMC_DEBUG & EMC_DEBUG_NML == 0) { set_rcs_print_destination(RCS_PRINT_TO_NULL); // inhibit diag // messages } end = RETRY_TIME; good = 0; do { if (0 == emcTaskNmlGet()) { good = 1; break; } esleep(RETRY_INTERVAL); end -= RETRY_INTERVAL; } while (end > 0.0); if (EMC_DEBUG & EMC_DEBUG_NML == 0) { set_rcs_print_destination(RCS_PRINT_TO_STDOUT); // inhibit diag // messages } if (!good) { return -1; } if (EMC_DEBUG & EMC_DEBUG_NML == 0) { set_rcs_print_destination(RCS_PRINT_TO_NULL); // inhibit diag // messages } end = RETRY_TIME; good = 0; do { if (0 == emcErrorNmlGet()) { good = 1; break; } esleep(RETRY_INTERVAL); end -= RETRY_INTERVAL; } while (end > 0.0); if (EMC_DEBUG & EMC_DEBUG_NML == 0) { set_rcs_print_destination(RCS_PRINT_TO_STDOUT); // inhibit diag // messages } if (!good) { return -1; } return 0;#undef RETRY_TIME#undef RETRY_INTERVAL}static int updateStatus(){ NMLTYPE type; if (0 == emcStatus || 0 == emcStatusBuffer || !emcStatusBuffer->valid()) { return -1; } switch (type = emcStatusBuffer->peek()) { case -1: // error on CMS channel return -1; break; case 0: // no new data case EMC_STAT_TYPE: // new data break; default: 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 (end < receiveTimeout) { 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 (end < doneTimeout) { 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(){ //don't forget the big HAL sin ;) hal_exit(comp_id); if(emcCommandBuffer) { delete emcCommandBuffer; emcCommandBuffer = 0; } if(emcStatusBuffer) { delete emcStatusBuffer; emcStatusBuffer = 0; } if(emcErrorBuffer) { delete emcErrorBuffer; emcErrorBuffer = 0; } exit(0);}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.hint halui_export_pin_IN_bit(hal_bit_t **pin, char name[HAL_NAME_LEN+2]) { int retval; retval = hal_pin_bit_new(name, HAL_IN, 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_IN_s32(hal_s32_t **pin, char name[HAL_NAME_LEN+2]) { int retval; retval = hal_pin_s32_new(name, HAL_IN, 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_IN_float(hal_float_t **pin, char name[HAL_NAME_LEN+2]) { int retval; retval = hal_pin_float_new(name, HAL_IN, 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_OUT_bit(hal_bit_t **pin, char name[HAL_NAME_LEN+2]) { int retval; retval = hal_pin_bit_new(name, HAL_OUT, 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; int joint; int axis; /* 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) */ retval = halui_export_pin_OUT_bit(&(halui_data->machine_is_on), "halui.machine.is-on"); if (retval != HAL_SUCCESS) return retval; retval = halui_export_pin_OUT_bit(&(halui_data->estop_is_activated), "halui.estop.is-activated"); if (retval != HAL_SUCCESS) return retval; retval = halui_export_pin_OUT_bit(&(halui_data->mode_is_manual), "halui.mode.is-manual"); if (retval != HAL_SUCCESS) return retval; retval = halui_export_pin_OUT_bit(&(halui_data->mode_is_auto), "halui.mode.is-auto"); if (retval != HAL_SUCCESS) return retval; retval = halui_export_pin_OUT_bit(&(halui_data->mode_is_mdi), "halui.mode.is-mdi"); if (retval != HAL_SUCCESS) return retval; retval = halui_export_pin_OUT_bit(&(halui_data->mode_is_teleop), "halui.mode.is-teleop"); retval = halui_export_pin_OUT_bit(&(halui_data->mode_is_joint), "halui.mode.is-joint"); if (retval != HAL_SUCCESS) return retval; retval = halui_export_pin_OUT_bit(&(halui_data->mist_is_on), "halui.mist.is-on");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?