📄 halui.cc
字号:
/********************************************************************* Description: halui.cc* HAL User-Interface component.* This file exports various UI related hal pins, and communicates * with EMC through NML messages** Derived from a work by Fred Proctor & Will Shackleford (emcsh.cc)* some of the functions (sendFooBar() are adapted from there)** Author: Alex Joni* License: GPL Version 2* System: Linux** Copyright (c) 2006 All rights reserved.** Last change:* $Revision: 1.6 $* $Author: alex_joni $* $Date: 2006/03/28 19:58:54 $********************************************************************/#include <stdio.h>#include <string.h>#include <stdlib.h>#include <signal.h>#include <math.h>#include "hal.h" /* access to HAL functions/definitions */#include "rtapi.h" /* rtapi_print_msg */#include "rcs.hh"#include "posemath.h" // PM_POSE, TO_RAD#include "emc.hh" // EMC NML#include "canon.hh" // CANON_UNITS, CANON_UNITS_INCHES,MM,CM#include "emcglb.h" // EMC_NMLFILE, TRAJ_MAX_VELOCITY, etc.#include "emccfg.h" // DEFAULT_TRAJ_MAX_VELOCITY#include "inifile.hh" // INIFILE/* Using halui: halui {-ini <ini file>} With -ini <inifile>, uses inifile instead of emc.ini. Once executed, it connects to NML buffers, exports various HAL pins and communicates changes to EMC. It also sets certain HAL pins based on status values. Naming: All pins will be named after the following scheme: halui.name.<number>.action name refers to the name of the component, currently one of: - machine - estop - mode - mist - flood - lube - jog - program - probe ... <number> if more than one component of the same type exists action usually on/off or is-on for the status (this uses the NIST way of control, each action is done by momentary pushbuttons, and thus more than one source of control is allowed: e.g. multiple UI's, GUI's ) Exported pins (list not complete, names up for debate):- machine: halui.machine.on bit //pin for setting machine On halui.machine.off bit //pin for setting machine Off halui.machine.is-on bit //pin for machine is On/Off- estop: halui.estop.activate bit //pin for resetting Estop (emc internal) On/Off halui.estop.reset bit //pin for resetting Estop (emc internal) On/Off halui.estop.is-reset bit //pin for resetting Estop (emc internal) On/Off - mode: halui.mode.manual bit //pin for requesting manual mode halui.mode.is_manual bit //pin for manual mode is on halui.mode.auto bit //pin for requesting auto mode halui.mode.is_auto bit //pin for auto mode is on halui.mode.mdi bit //pin for requesting mdi mode halui.mode.is_mdi bit //pin for mdi mode is on- mist, flood, lube: halui.mist.on bit //pin for starting mist halui.mist.off bit //pin for stoping mist halui.mist.is-on bit //pin for mist is on halui.flood.on bit //pin for starting flood halui.flood.off bit //pin for stoping flood halui.flood.is-on bit //pin for flood is on halui.lube.on bit //pin for starting lube halui.lube.off bit //pin for stoping lube halui.lube.is-on bit //pin for lube is on- spindle: halui.spindle.start bit halui.spindle.stop bit halui.spindle.forward bit halui.spindle.reverse bit halui.spindle.increase bit halui.spindle.decrease bit halui.spindle.brake-on bit //pin for activating spindle-brake halui.spindle.brake-off bit //pin for deactivating spindle/brake halui.spindle.brake-is-on bit //status pin that tells us if brake is on- joint: halui.joint.0.home bit //works both ways .. halui.joint.7.home bit //works both ways halui.joint.x.on-min-limit-soft bit halui.joint.x.on-max-limit-soft bit halui.joint.x.on-min-limit-hard bit halui.joint.x.on-max-limit-hard bit halui.joint.x.fault bit halui.joint.x.homed bit- jogging: halui.jog.speed float //set jog speed halui.jog.0.minus bit halui.jog.0.plus bit .. halui.jog.7.jog-minus bit halui.jog.7.jog-plus bit halui.feed_override float- tool: halui.tool.number u16 //current selected tool halui.tool.length-offset float //current applied tool-length-offset- program: halui.program.is-idle bit halui.program.is-running bit halui.program.is-paused bit halui.program.run bit halui.program.pause bit halui.program.resume bit halui.program.step bit- probe: halui.probe.start bit halui.probe.clear bit halui.probe.is-tripped bit halui.probe.has-value float*/struct halui_str { hal_bit_t *machine_on; //pin for setting machine On hal_bit_t *machine_off; //pin for setting machine Off hal_bit_t *machine_is_on; //pin for machine is On/Off // (check iocontrol.cc for a proper description) hal_bit_t *estop_activate; //pin for activating EMC ESTOP hal_bit_t *estop_reset; //pin for resetting ESTOP hal_bit_t *estop_is_activated; //pin for status ESTOP is activated hal_bit_t *mode_manual; //pin for requesting manual mode hal_bit_t *mode_is_manual; //pin for manual mode is on hal_bit_t *mode_auto; //pin for requesting auto mode hal_bit_t *mode_is_auto; //pin for auto mode is on hal_bit_t *mode_mdi; //pin for requesting mdi mode hal_bit_t *mode_is_mdi; //pin for mdi mode is on hal_bit_t *mist_on; //pin for starting mist hal_bit_t *mist_off; //pin for stoping mist hal_bit_t *mist_is_on; //pin for mist is on hal_bit_t *flood_on; //pin for starting flood hal_bit_t *flood_off; //pin for stoping flood hal_bit_t *flood_is_on; //pin for flood is on hal_bit_t *lube_on; //pin for starting lube hal_bit_t *lube_off; //pin for stoping lube hal_bit_t *lube_is_on; //pin for lube is on} * halui_data; struct local_halui_str { hal_bit_t machine_on; //pin for setting machine On hal_bit_t machine_off; //pin for setting machine Off hal_bit_t machine_is_on; //pin for machine is On/Off hal_bit_t estop_activate; //pin for activating EMC ESTOP hal_bit_t estop_reset; //pin for resetting ESTOP hal_bit_t estop_is_reset; //pin for status ESTOp is resetted hal_bit_t estop_is_activated; //pin for status ESTOP is activated hal_bit_t mode_manual; //pin for requesting manual mode hal_bit_t mode_is_manual; //pin for manual mode is on hal_bit_t mode_auto; //pin for requesting auto mode hal_bit_t mode_is_auto; //pin for auto mode is on hal_bit_t mode_mdi; //pin for requesting mdi mode hal_bit_t mode_is_mdi; //pin for mdi mode is on hal_bit_t mist_on; //pin for starting mist hal_bit_t mist_off; //pin for stoping mist hal_bit_t mist_is_on; //pin for mist is on hal_bit_t flood_on; //pin for starting flood hal_bit_t flood_off; //pin for stoping flood hal_bit_t flood_is_on; //pin for flood is on hal_bit_t lube_on; //pin for starting lube hal_bit_t lube_off; //pin for stoping lube hal_bit_t lube_is_on; //pin for lube is on} old_halui_data; //pointer to the HAL-structstatic int comp_id; /* component ID */// 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 current command numbers, set up updateStatus(), used in main()static int emcCommandSerialNumber = 0;static int saveEmcCommandSerialNumber = 0;// default value for timeout, 0 means wait foreverstatic double emcTimeout = 0.0;static enum { EMC_WAIT_NONE = 1, EMC_WAIT_RECEIVED, EMC_WAIT_DONE} emcWaitType = EMC_WAIT_DONE;/* clean out for now, causes warningsstatic enum { EMC_UPDATE_NONE = 1, EMC_UPDATE_AUTO} emcUpdateType = EMC_UPDATE_AUTO; */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() || EMC_STAT_TYPE != emcStatusBuffer->peek()) { 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 // 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 (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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -