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

📄 taskintf.cc

📁 CNC 的开放码,EMC2 V2.2.8版
💻 CC
📖 第 1 页 / 共 3 页
字号:
/********************************************************************* Description: taskintf.cc*   Interface functions for motion.**   Derived from a work by Fred Proctor & Will Shackleford** Author:* License: GPL Version 2* System: Linux*    * Copyright (c) 2004 All rights reserved.*********************************************************************/#include <math.h>		// isnan()#include <float.h>		// DBL_MAX#include <string.h>		// memcpy() strncpy()#include <unistd.h>             // unlink()#include "usrmotintf.h"		// usrmotInit(), usrmotReadEmcmotStatus(),				// etc.#include "motion.h"		// emcmot_command_t,STATUS, etc.#include "motion_debug.h"#include "emc.hh"#include "emcglb.h"		// EMC_INIFILE#include "emc_nml.hh"#include "rcs_print.hh"#include "timer.hh"#include "inifile.hh"#include "iniaxis.hh"#include "initraj.hh"/* define this to catch isnan errors, for rtlinux FPU register    problem testing */#define ISNAN_TRAP// MOTION INTERFACE/*! \todo FIXME - this decl was originally much later in the file, movedhere temporarily for debugging */static emcmot_status_t emcmotStatus;/*  Implementation notes:  Initing:  the emcmot interface needs to be inited once, but nml_traj_init()  and nml_servo_init() can be called in any order. Similarly, the emcmot  interface needs to be exited once, but nml_traj_exit() and nml_servo_exit()  can be called in any order. They can also be called multiple times. Flags  are used to signify if initing has been done, or if the final exit has  been called.  */static emcmot_command_t emcmotCommand;static int emcmotTrajInited = 0;	// non-zero means traj called init/* FIXME is this supposed to be axes, or joints? */static int emcmotAxisInited[EMCMOT_MAX_AXIS] = { 0 };	// non-zero means axis called init__attribute__ ((unused))static int emcmotIoInited = 0;	// non-zero means io called initstatic int emcmotion_initialized = 0;	// non-zero means both						// emcMotionInit called.// saved value of velocity last sent out, so we don't send redundant requests// used by emcTrajSetVelocity(), emcMotionAbort()static double lastVel = -1.0;static double last_ini_maxvel = -1.0;// EMC_AXIS functions// local status data, not provided by emcmotstatic unsigned long localMotionHeartbeat = 0;static int localMotionCommandType = 0;static int localMotionEchoSerialNumber = 0;/* FIXME axes or joints? */static unsigned char localEmcAxisAxisType[EMCMOT_MAX_AXIS];static double localEmcAxisUnits[EMCMOT_MAX_AXIS];static double localEmcMaxAcceleration = DBL_MAX;// axes are numbered 0..NUM-1/*  In emcmot, we need to set the cycle time for traj, and the interpolation  rate, in any order, but both need to be done.  *//* FIXME: all of this stuff is really JOINTS not AXES!!! */int emcAxisSetAxis(int axis, unsigned char axisType){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    localEmcAxisAxisType[axis] = axisType;    return 0;}int emcAxisSetUnits(int axis, double units){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    localEmcAxisUnits[axis] = units;    return 0;}int emcAxisSetBacklash(int axis, double backlash){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_SET_BACKLASH;    emcmotCommand.axis = axis;    emcmotCommand.backlash = backlash;#ifdef ISNAN_TRAP    if (isnan(emcmotCommand.backlash)) {	printf("isnan error in emcAxisSetBacklash\n");	return -1;    }#endif    return usrmotWriteEmcmotCommand(&emcmotCommand);}// saved values of limits, since emcmot expects them to be set in// pairs and we set them individually.static double saveMinLimit[EMCMOT_MAX_AXIS];static double saveMaxLimit[EMCMOT_MAX_AXIS];int emcAxisSetMinPositionLimit(int axis, double limit){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_SET_POSITION_LIMITS;    emcmotCommand.axis = axis;    emcmotCommand.maxLimit = saveMaxLimit[axis];    emcmotCommand.minLimit = limit;    saveMinLimit[axis] = limit;#ifdef ISNAN_TRAP    if (isnan(emcmotCommand.maxLimit) || isnan(emcmotCommand.minLimit)) {	printf("isnan error in emcAxisSetMinPosition\n");	return -1;    }#endif    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisSetMaxPositionLimit(int axis, double limit){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_SET_POSITION_LIMITS;    emcmotCommand.axis = axis;    emcmotCommand.minLimit = saveMinLimit[axis];    emcmotCommand.maxLimit = limit;    saveMaxLimit[axis] = limit;#ifdef ISNAN_TRAP    if (isnan(emcmotCommand.maxLimit) || isnan(emcmotCommand.minLimit)) {	printf("isnan error in emcAxisSetMaxPosition\n");	return -1;    }#endif    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisSetMotorOffset(int axis, double offset) {    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_SET_MOTOR_OFFSET;    emcmotCommand.axis = axis;    emcmotCommand.motor_offset = offset;        return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisSetFerror(int axis, double ferror){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_SET_MAX_FERROR;    emcmotCommand.axis = axis;    emcmotCommand.maxFerror = ferror;#ifdef ISNAN_TRAP    if (isnan(emcmotCommand.maxFerror)) {	printf("isnan error in emcAxisSetFerror\n");	return -1;    }#endif    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisSetMinFerror(int axis, double ferror){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_SET_MIN_FERROR;    emcmotCommand.axis = axis;    emcmotCommand.minFerror = ferror;#ifdef ISNAN_TRAP    if (isnan(emcmotCommand.minFerror)) {	printf("isnan error in emcAxisSetMinFerror\n");	return -1;    }#endif    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisSetHomingParams(int axis, double home, double offset,			   double search_vel, double latch_vel,			   int use_index, int ignore_limits, int is_shared,			   int sequence){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_SET_HOMING_PARAMS;    emcmotCommand.axis = axis;    emcmotCommand.home = home;    emcmotCommand.offset = offset;    emcmotCommand.search_vel = search_vel;    emcmotCommand.latch_vel = latch_vel;    emcmotCommand.flags = 0;    emcmotCommand.home_sequence = sequence;    if (use_index) {	emcmotCommand.flags |= HOME_USE_INDEX;    }    if (ignore_limits) {	emcmotCommand.flags |= HOME_IGNORE_LIMITS;    }    if (is_shared) {	emcmotCommand.flags |= HOME_IS_SHARED;    }#ifdef ISNAN_TRAP    if (isnan(emcmotCommand.home) ||	isnan(emcmotCommand.offset) ||	isnan(emcmotCommand.search_vel) ||	isnan(emcmotCommand.latch_vel)) {	printf("isnan error in emcAxisSetHoming\n");	return -1;    }#endif    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisSetMaxVelocity(int axis, double vel){    if (axis < 0 || axis >= EMC_AXIS_MAX) {	return 0;    }    if (vel < 0.0) {	vel = 0.0;    }    AXIS_MAX_VELOCITY[axis] = vel;    emcmotCommand.command = EMCMOT_SET_JOINT_VEL_LIMIT;    emcmotCommand.axis = axis;    emcmotCommand.vel = vel;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisSetMaxAcceleration(int axis, double acc){    if (axis < 0 || axis >= EMC_AXIS_MAX) {	return 0;    }    if (acc < 0.0) {	acc = 0.0;    }    AXIS_MAX_ACCELERATION[axis] = acc;    emcmotCommand.command = EMCMOT_SET_JOINT_ACC_LIMIT;    emcmotCommand.axis = axis;    emcmotCommand.acc = acc;    return usrmotWriteEmcmotCommand(&emcmotCommand);}/* This function checks to see if any axis or the traj has   been inited already.  At startup, if none have been inited,   usrmotIniLoad and usrmotInit must be called first.  At   shutdown, after all have been halted, the usrmotExit must   be called.*/static int AxisOrTrajInited(void){    int axis;    for (axis = 0; axis < EMCMOT_MAX_AXIS; axis++) {	if (emcmotAxisInited[axis]) {	    return 1;	}    }    if (emcmotTrajInited) {	return 1;    }    return 0;}int emcAxisInit(int axis){    int retval = 0;    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    // init emcmot interface    if (!AxisOrTrajInited()) {	usrmotIniLoad(EMC_INIFILE);	if (0 != usrmotInit("emc2_task")) {	    return -1;	}    }    emcmotAxisInited[axis] = 1;    if (0 != iniAxis(axis, EMC_INIFILE)) {	retval = -1;    }    return retval;}int emcAxisHalt(int axis){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    /*! \todo FIXME-- refs global emcStatus; should make EMC_AXIS_STAT an arg here */    if (NULL != emcStatus && emcmotion_initialized	&& emcmotAxisInited[axis]) {	dumpAxis(axis, EMC_INIFILE, &emcStatus->motion.axis[axis]);    }    emcmotAxisInited[axis] = 0;    if (!AxisOrTrajInited()) {	usrmotExit();		// ours is final exit    }    return 0;}int emcAxisAbort(int axis){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_AXIS_ABORT;    emcmotCommand.axis = axis;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisActivate(int axis){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_ACTIVATE_JOINT;    emcmotCommand.axis = axis;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisDeactivate(int axis){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_DEACTIVATE_JOINT;    emcmotCommand.axis = axis;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisOverrideLimits(int axis){    // can have axis < 0, for resuming normal limit checking    if (axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_OVERRIDE_LIMITS;    emcmotCommand.axis = axis;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisEnable(int axis){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_ENABLE_AMPLIFIER;    emcmotCommand.axis = axis;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisDisable(int axis){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_DISABLE_AMPLIFIER;    emcmotCommand.axis = axis;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisHome(int axis){    if (axis < -1 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    emcmotCommand.command = EMCMOT_HOME;    emcmotCommand.axis = axis;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisJog(int axis, double vel){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    if (vel > AXIS_MAX_VELOCITY[axis]) {	vel = AXIS_MAX_VELOCITY[axis];    } else if (vel < -AXIS_MAX_VELOCITY[axis]) {	vel = -AXIS_MAX_VELOCITY[axis];    }    emcmotCommand.command = EMCMOT_JOG_CONT;    emcmotCommand.axis = axis;    emcmotCommand.vel = vel;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisIncrJog(int axis, double incr, double vel){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    if (vel > AXIS_MAX_VELOCITY[axis]) {	vel = AXIS_MAX_VELOCITY[axis];    } else if (vel < -AXIS_MAX_VELOCITY[axis]) {	vel = -AXIS_MAX_VELOCITY[axis];    }    emcmotCommand.command = EMCMOT_JOG_INCR;    emcmotCommand.axis = axis;    emcmotCommand.vel = vel;    emcmotCommand.offset = incr;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisAbsJog(int axis, double pos, double vel){    if (axis < 0 || axis >= EMCMOT_MAX_AXIS) {	return 0;    }    if (vel > AXIS_MAX_VELOCITY[axis]) {	vel = AXIS_MAX_VELOCITY[axis];    } else if (vel < -AXIS_MAX_VELOCITY[axis]) {	vel = -AXIS_MAX_VELOCITY[axis];

⌨️ 快捷键说明

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