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

📄 halui.cc

📁 Source code for an Numeric Cmputer
💻 CC
📖 第 1 页 / 共 4 页
字号:
    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendProgramResume(){    EMC_TASK_PLAN_RESUME emc_task_plan_resume_msg;    emc_task_plan_resume_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(emc_task_plan_resume_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendProgramStep(){    EMC_TASK_PLAN_STEP emc_task_plan_step_msg;    emc_task_plan_step_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(emc_task_plan_step_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendMdiCmd(char *mdi){    EMC_TASK_PLAN_EXECUTE emc_task_plan_execute_msg;    strcpy(emc_task_plan_execute_msg.command, mdi);    emc_task_plan_execute_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(emc_task_plan_execute_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendToolSetOffset(int tool, double length, double diameter){    EMC_TOOL_SET_OFFSET emc_tool_set_offset_msg;    emc_tool_set_offset_msg.tool = tool;    emc_tool_set_offset_msg.length = length;    emc_tool_set_offset_msg.diameter = diameter;    emc_tool_set_offset_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(emc_tool_set_offset_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendAxisEnable(int axis, int val){    EMC_AXIS_ENABLE emc_axis_enable_msg;    EMC_AXIS_DISABLE emc_axis_disable_msg;    if (val) {	emc_axis_enable_msg.axis = axis;	emc_axis_enable_msg.serial_number = ++emcCommandSerialNumber;	emcCommandBuffer->write(emc_axis_enable_msg);    } else {	emc_axis_disable_msg.axis = axis;	emc_axis_disable_msg.serial_number = ++emcCommandSerialNumber;	emcCommandBuffer->write(emc_axis_disable_msg);    }    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendAxisLoadComp(int axis, const char *file){    EMC_AXIS_LOAD_COMP emc_axis_load_comp_msg;    strcpy(emc_axis_load_comp_msg.file, file);    emc_axis_load_comp_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(emc_axis_load_comp_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendAxisAlter(int axis, double alter){    EMC_AXIS_ALTER emc_axis_alter_msg;    emc_axis_alter_msg.alter = alter;    emc_axis_alter_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(emc_axis_alter_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendSetTeleopEnable(int enable){    EMC_TRAJ_SET_TELEOP_ENABLE emc_set_teleop_enable_msg;    emc_set_teleop_enable_msg.enable = enable;    emc_set_teleop_enable_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(emc_set_teleop_enable_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendClearProbeTrippedFlag(){    EMC_TRAJ_CLEAR_PROBE_TRIPPED_FLAG emc_clear_probe_tripped_flag_msg;    emc_clear_probe_tripped_flag_msg.serial_number =	++emcCommandSerialNumber;    emcCommandBuffer->write(emc_clear_probe_tripped_flag_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}static int sendProbe(double x, double y, double z){    EMC_TRAJ_PROBE emc_probe_msg;    emc_probe_msg.pos.tran.x = x;    emc_probe_msg.pos.tran.y = y;    emc_probe_msg.pos.tran.z = z;    emc_probe_msg.serial_number = ++emcCommandSerialNumber;    emcCommandBuffer->write(emc_probe_msg);    if (emcWaitType == EMC_WAIT_RECEIVED) {	return emcCommandWaitReceived(emcCommandSerialNumber);    } else if (emcWaitType == EMC_WAIT_DONE) {	return emcCommandWaitDone(emcCommandSerialNumber);    }    return 0;}//end of commenting out */static int iniLoad(const char *filename){    Inifile inifile;    const char *inistring;    char displayString[LINELEN] = "";    int t;    int i;    // open it    if (inifile.open(filename) == false) {	return -1;    }    if (NULL != (inistring = inifile.find("DEBUG", "EMC"))) {	// copy to global	if (1 != sscanf(inistring, "%i", &EMC_DEBUG)) {	    EMC_DEBUG = 0;	}    } else {	// not found, use default	EMC_DEBUG = 0;    }    if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) {	// copy to global	strcpy(EMC_NMLFILE, inistring);    } else {	// not found, use default    }    for (t = 0; t < EMC_AXIS_MAX; t++) {	jogPol[t] = 1;		// set to default	sprintf(displayString, "AXIS_%d", t);	if (NULL != (inistring =		     inifile.find("JOGGING_POLARITY", displayString)) &&	    1 == sscanf(inistring, "%d", &i) && i == 0) {	    // it read as 0, so override default	    jogPol[t] = 0;	}    }    if (NULL != (inistring = inifile.find("LINEAR_UNITS", "DISPLAY"))) {	if (!strcmp(inistring, "AUTO")) {	    linearUnitConversion = LINEAR_UNITS_AUTO;	} else if (!strcmp(inistring, "INCH")) {	    linearUnitConversion = LINEAR_UNITS_INCH;	} else if (!strcmp(inistring, "MM")) {	    linearUnitConversion = LINEAR_UNITS_MM;	} else if (!strcmp(inistring, "CM")) {	    linearUnitConversion = LINEAR_UNITS_CM;	}    } else {	// not found, leave default alone    }    if (NULL != (inistring = inifile.find("ANGULAR_UNITS", "DISPLAY"))) {	if (!strcmp(inistring, "AUTO")) {	    angularUnitConversion = ANGULAR_UNITS_AUTO;	} else if (!strcmp(inistring, "DEG")) {	    angularUnitConversion = ANGULAR_UNITS_DEG;	} else if (!strcmp(inistring, "RAD")) {	    angularUnitConversion = ANGULAR_UNITS_RAD;	} else if (!strcmp(inistring, "GRAD")) {	    angularUnitConversion = ANGULAR_UNITS_GRAD;	}    } else {	// not found, leave default alone    }    // close it    inifile.close();    return 0;}static void hal_init_pins(){    old_halui_data.machine_on = *(halui_data->machine_on) = 0;    old_halui_data.machine_off = *(halui_data->machine_off) = 0;    old_halui_data.estop_activate = *(halui_data->estop_activate) = 0;    old_halui_data.estop_reset = *(halui_data->estop_reset) = 0;}// this function looks if any of the hal pins has changed// and sends appropiate messages if sostatic void check_hal_changes(){    //check if machine_on pin has changed (the rest work exactly the same)    if (*(halui_data->machine_on) != old_halui_data.machine_on) {	if (*(halui_data->machine_on) != 0) //if transition to 1	    sendMachineOn();                //send MachineOn NML command	old_halui_data.machine_on = *(halui_data->machine_on);    }    if (*(halui_data->machine_off) != old_halui_data.machine_off) {	if (*(halui_data->machine_off) != 0)	    sendMachineOff();	old_halui_data.machine_off = *(halui_data->machine_off);    }    if (*(halui_data->estop_activate) != old_halui_data.estop_activate) {	if (*(halui_data->estop_activate) != 0)	    sendEstop();	old_halui_data.estop_activate = *(halui_data->estop_activate);    }    if (*(halui_data->estop_reset) != old_halui_data.estop_reset) {	if (*(halui_data->estop_reset) != 0)	    sendEstopReset();	old_halui_data.estop_reset = *(halui_data->estop_reset);    }    if (*(halui_data->mode_manual) != old_halui_data.mode_manual) {	if (*(halui_data->mode_manual) != 0)	    sendManual();	old_halui_data.mode_manual = *(halui_data->mode_manual);    }    if (*(halui_data->mode_auto) != old_halui_data.mode_auto) {	if (*(halui_data->mode_auto) != 0)	    sendAuto();	old_halui_data.mode_auto = *(halui_data->mode_auto);    }    if (*(halui_data->mode_mdi) != old_halui_data.mode_mdi) {	if (*(halui_data->mode_mdi) != 0)	    sendMdi();	old_halui_data.mode_mdi = *(halui_data->mode_mdi);    }    if (*(halui_data->mist_on) != old_halui_data.mist_on) {	if (*(halui_data->mist_on) != 0)	    sendMistOn();	old_halui_data.mist_on = *(halui_data->mist_on);    }    if (*(halui_data->mist_off) != old_halui_data.mist_off) {	if (*(halui_data->mist_off) != 0)	    sendMistOff();	old_halui_data.mist_off = *(halui_data->mist_off);    }    if (*(halui_data->flood_on) != old_halui_data.flood_on) {	if (*(halui_data->flood_on) != 0)	    sendFloodOn();	old_halui_data.flood_on = *(halui_data->flood_on);    }    if (*(halui_data->flood_off) != old_halui_data.flood_off) {	if (*(halui_data->flood_off) != 0)	    sendFloodOff();	old_halui_data.flood_off = *(halui_data->flood_off);    }    if (*(halui_data->lube_on) != old_halui_data.lube_on) {	if (*(halui_data->lube_on) != 0)	    sendLubeOn();	old_halui_data.lube_on = *(halui_data->lube_on);    }    if (*(halui_data->lube_off) != old_halui_data.lube_off) {	if (*(halui_data->lube_off) != 0)	    sendLubeOff();	old_halui_data.lube_off = *(halui_data->lube_off);    }}// this function looks at the received NML status message// and modifies the appropiate HAL pinsstatic void modify_hal_pins(){    if (emcStatus->task.state == EMC_TASK_STATE_ON) {	*(halui_data->machine_is_on)=1;    } else {	*(halui_data->machine_is_on)=0;    }    if (emcStatus->task.state == EMC_TASK_STATE_ESTOP) {	*(halui_data->estop_is_activated)=1;    } else {	*(halui_data->estop_is_activated)=0;    }    if (emcStatus->task.mode == EMC_TASK_MODE_MANUAL) {	*(halui_data->mode_is_manual)=1;    } else {	*(halui_data->mode_is_manual)=0;    }    if (emcStatus->task.mode == EMC_TASK_MODE_AUTO) {	*(halui_data->mode_is_auto)=1;    } else {	*(halui_data->mode_is_auto)=0;    }    if (emcStatus->task.mode == EMC_TASK_MODE_MDI) {	*(halui_data->mode_is_mdi)=1;    } else {	*(halui_data->mode_is_mdi)=0;    }    *(halui_data->mist_is_on)=emcStatus->io.coolant.mist;    *(halui_data->flood_is_on)=emcStatus->io.coolant.flood;    *(halui_data->lube_is_on)=emcStatus->io.lube.on;}int main(int argc, char *argv[]){    short done;        // process command line args    if (0 != emcGetArgs(argc, argv)) {	rcs_print_error("error in argument list\n");	exit(1);    }    // get configuration information    iniLoad(EMC_INIFILE);    // init NML    if (0 != tryNml()) {	rcs_print_error("can't connect to emc\n");	thisQuit();	exit(1);    }    //init HAL and export pins    halui_hal_init();    //initialize safe values    hal_init_pins();        // get current serial number, and save it for restoring when we quit    // so as not to interfere with real operator interface    updateStatus();    emcCommandSerialNumber = emcStatus->echo_serial_number;    saveEmcCommandSerialNumber = emcStatus->echo_serial_number;    done = 0;    while (!done) {	check_hal_changes(); //if anything changed send NML messages	modify_hal_pins(); //if status changed modify HAL too		esleep(EMC_IO_CYCLE_TIME); //sleep for a while		updateStatus();    }    thisQuit();    return 0;}

⌨️ 快捷键说明

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