📄 taskintf.cc
字号:
} emcmotCommand.command = EMCMOT_JOG_ABS; emcmotCommand.axis = axis; emcmotCommand.vel = vel; emcmotCommand.offset = pos; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcAxisLoadComp(int axis, const char *file, int type){ return usrmotLoadComp(axis, file, type);}static emcmot_config_t emcmotConfig;int get_emcmot_debug_info = 0;/* these globals are set in emcMotionUpdate(), then referenced in emcAxisUpdate(), emcTrajUpdate() to save calls to usrmotReadEmcmotStatus */static emcmot_debug_t emcmotDebug;static char errorString[EMCMOT_ERROR_LEN];static int new_config = 0;/*! \todo FIXME - debugging - uncomment the following line to log changes in AXIS_FLAG */// #define WATCH_FLAGS 1int emcAxisUpdate(EMC_AXIS_STAT stat[], int numAxes){/*! \todo FIXME - this function accesses data that has been moved. Once I know what it is used for I'll fix it */ int axis; emcmot_joint_status_t *joint;#ifdef WATCH_FLAGS static int old_joint_flag[8];#endif // check for valid range if (numAxes <= 0 || numAxes > EMCMOT_MAX_AXIS) { return -1; } for (axis = 0; axis < numAxes; axis++) { /* point to joint data */ joint = &(emcmotStatus.joint_status[axis]); stat[axis].axisType = localEmcAxisAxisType[axis]; stat[axis].units = localEmcAxisUnits[axis]; if (new_config) { stat[axis].backlash = joint->backlash; stat[axis].minPositionLimit = joint->min_pos_limit; stat[axis].maxPositionLimit = joint->max_pos_limit; stat[axis].minFerror = joint->min_ferror; stat[axis].maxFerror = joint->max_ferror;/*! \todo FIXME - should all homing config params be included here? */ stat[axis].homeOffset = joint->home_offset; } stat[axis].setpoint = joint->pos_cmd; /*! \todo FIXME - output is the DAC output, now part of HAL */ stat[axis].output = 0.0; stat[axis].input = joint->pos_fb; if (get_emcmot_debug_info) { stat[axis].ferrorCurrent = joint->ferror; stat[axis].ferrorHighMark = joint->ferror_high_mark; } stat[axis].homing = (joint->flag & EMCMOT_AXIS_HOMING_BIT ? 1 : 0); stat[axis].homed = (joint->flag & EMCMOT_AXIS_HOMED_BIT ? 1 : 0); stat[axis].fault = (joint->flag & EMCMOT_AXIS_FAULT_BIT ? 1 : 0); stat[axis].enabled = (joint->flag & EMCMOT_AXIS_ENABLE_BIT ? 1 : 0);/* FIXME - soft limits are now applied to the command, and should never happen */ stat[axis].minSoftLimit = 0; stat[axis].maxSoftLimit = 0; stat[axis].minHardLimit = (joint->flag & EMCMOT_AXIS_MIN_HARD_LIMIT_BIT ? 1 : 0); stat[axis].maxHardLimit = (joint->flag & EMCMOT_AXIS_MAX_HARD_LIMIT_BIT ? 1 : 0); stat[axis].overrideLimits = !!(emcmotStatus.overrideLimitMask); // one // for // all/*! \todo Another #if 0 */#if 0 /*! \todo FIXME - per-axis Vscale temporarily? removed */ stat[axis].scale = emcmotStatus.axVscale[axis];#endif#ifdef WATCH_FLAGS if (old_joint_flag[axis] != joint->flag) { printf("joint %d flag: %04X -> %04X\n", axis, old_joint_flag[axis], joint->flag); old_joint_flag[axis] = joint->flag; }#endif if (joint->flag & EMCMOT_AXIS_ERROR_BIT) { if (stat[axis].status != RCS_ERROR) { rcs_print_error("Error on axis %d, command number %d\n", axis, emcmotStatus.commandNumEcho); stat[axis].status = RCS_ERROR; } } else if (joint->flag & EMCMOT_AXIS_INPOS_BIT) { stat[axis].status = RCS_DONE; } else { stat[axis].status = RCS_EXEC; } } return 0;}// EMC_TRAJ functions// local status data, not provided by emcmotstatic int localEmcTrajAxes = 0;static int localEmcTrajAxisMask = 0;static double localEmcTrajLinearUnits = 1.0;static double localEmcTrajAngularUnits = 1.0;static int localEmcTrajMotionId = 0;int emcTrajSetAxes(int axes, int axismask){ if(axes == 0) { if(axismask & 256) axes = 9; else if(axismask & 128) axes = 8; else if(axismask & 64) axes = 7; else if(axismask & 32) axes = 6; else if(axismask & 16) axes = 5; else if(axismask & 8) axes = 4; else if(axismask & 4) axes = 3; else if(axismask & 2) axes = 2; else if(axismask & 1) axes = 1; } if (axes <= 0 || axes > EMCMOT_MAX_AXIS || axismask >= (1<<axes)) { rcs_print("emcTrajSetAxes failing: axes=%d axismask=%x\n", axes, axismask); return -1; } localEmcTrajAxes = axes; localEmcTrajAxisMask = axismask; emcmotCommand.command = EMCMOT_SET_NUM_AXES; emcmotCommand.axis = axes; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetUnits(double linearUnits, double angularUnits){ if (linearUnits <= 0.0 || angularUnits <= 0.0) { return -1; } localEmcTrajLinearUnits = linearUnits; localEmcTrajAngularUnits = angularUnits; return 0;}int emcTrajSetMode(int mode){ switch (mode) { case EMC_TRAJ_MODE_FREE: emcmotCommand.command = EMCMOT_FREE; return usrmotWriteEmcmotCommand(&emcmotCommand); case EMC_TRAJ_MODE_COORD: emcmotCommand.command = EMCMOT_COORD; return usrmotWriteEmcmotCommand(&emcmotCommand); case EMC_TRAJ_MODE_TELEOP: emcmotCommand.command = EMCMOT_TELEOP; return usrmotWriteEmcmotCommand(&emcmotCommand); default: return -1; }}int emcTrajSetTeleopVector(EmcPose vel){ emcmotCommand.command = EMCMOT_SET_TELEOP_VECTOR; emcmotCommand.pos = vel; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetVelocity(double vel, double ini_maxvel){ int retval; if (vel < 0.0) { vel = 0.0; } else if (vel > TRAJ_MAX_VELOCITY) { vel = TRAJ_MAX_VELOCITY; } if (ini_maxvel < 0.0) { ini_maxvel = 0.0; } else if (vel > TRAJ_MAX_VELOCITY) { ini_maxvel = TRAJ_MAX_VELOCITY; } emcmotCommand.command = EMCMOT_SET_VEL; emcmotCommand.vel = vel; emcmotCommand.ini_maxvel = ini_maxvel; retval = usrmotWriteEmcmotCommand(&emcmotCommand); if (0 == retval) { lastVel = vel; last_ini_maxvel = ini_maxvel; } return retval;}int emcTrajSetAcceleration(double acc){ if (acc < 0.0) { acc = 0.0; } else if (acc > localEmcMaxAcceleration) { acc = localEmcMaxAcceleration; } emcmotCommand.command = EMCMOT_SET_ACC; emcmotCommand.acc = acc; return usrmotWriteEmcmotCommand(&emcmotCommand);}/* emcmot has no limits on max velocity, acceleration so we'll save them here and apply them in the functions above */int emcTrajSetMaxVelocity(double vel){ if (vel < 0.0) { vel = 0.0; } TRAJ_MAX_VELOCITY = vel; emcmotCommand.command = EMCMOT_SET_VEL_LIMIT; emcmotCommand.vel = vel; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetMaxAcceleration(double acc){ if (acc < 0.0) { acc = 0.0; } localEmcMaxAcceleration = acc; return 0;}int emcTrajSetHome(EmcPose home){ emcmotCommand.command = EMCMOT_SET_WORLD_HOME; emcmotCommand.pos = home;#ifdef ISNAN_TRAP if (isnan(emcmotCommand.pos.tran.x) || isnan(emcmotCommand.pos.tran.y) || isnan(emcmotCommand.pos.tran.z)) { printf("isnan error in emcTrajSetHome\n"); return 0; // ignore it for now, just don't send it }#endif return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetScale(double scale){ if (scale < 0.0) { scale = 0.0; } emcmotCommand.command = EMCMOT_FEED_SCALE; emcmotCommand.scale = scale; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetSpindleScale(double scale){ if (scale < 0.0) { scale = 0.0; } emcmotCommand.command = EMCMOT_SPINDLE_SCALE; emcmotCommand.scale = scale; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetFOEnable(unsigned char mode){ emcmotCommand.command = EMCMOT_FS_ENABLE; emcmotCommand.mode = mode; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetFHEnable(unsigned char mode){ emcmotCommand.command = EMCMOT_FH_ENABLE; emcmotCommand.mode = mode; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetSOEnable(unsigned char mode){ emcmotCommand.command = EMCMOT_SS_ENABLE; emcmotCommand.mode = mode; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetAFEnable(unsigned char enable){ emcmotCommand.command = EMCMOT_AF_ENABLE; if ( enable ) { emcmotCommand.flags = 1; } else { emcmotCommand.flags = 0; } return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetMotionId(int id){ if (EMC_DEBUG_MOTION_TIME & EMC_DEBUG) { if (id != localEmcTrajMotionId) { rcs_print("Outgoing motion id is %d.\n", id); } } localEmcTrajMotionId = id; return 0;}int emcTrajInit(){ int retval = 0; // init emcmot interface if (!AxisOrTrajInited()) { usrmotIniLoad(EMC_INIFILE); if (0 != usrmotInit("emc2_task")) { return -1; } } emcmotTrajInited = 1; // initialize parameters from ini file if (0 != iniTraj(EMC_INIFILE)) { retval = -1; } return retval;}int emcTrajHalt(){ emcmotTrajInited = 0; if (!AxisOrTrajInited()) { usrmotExit(); // ours is final exit } return 0;}int emcTrajEnable(){ emcmotCommand.command = EMCMOT_ENABLE; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajDisable(){ emcmotCommand.command = EMCMOT_DISABLE; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajAbort(){ emcmotCommand.command = EMCMOT_ABORT; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajPause(){ emcmotCommand.command = EMCMOT_PAUSE; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajStep(){ emcmotCommand.command = EMCMOT_STEP; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajResume(){ emcmotCommand.command = EMCMOT_RESUME; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajDelay(double delay){ /* nothing need be done here - it's done in task controller */ return 0;}double emcTrajGetLinearUnits(){ return localEmcTrajLinearUnits;}double emcTrajGetAngularUnits(){ return localEmcTrajAngularUnits;}int emcTrajSetSpindleSync(double fpr, bool wait_for_index) { emcmotCommand.command = EMCMOT_SET_SPINDLESYNC; emcmotCommand.spindlesync = fpr; emcmotCommand.flags = wait_for_index; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajSetTermCond(int cond, double tolerance){ emcmotCommand.command = EMCMOT_SET_TERM_COND; emcmotCommand.termCond = (cond == EMC_TRAJ_TERM_COND_STOP ? EMCMOT_TERM_COND_STOP : EMCMOT_TERM_COND_BLEND); emcmotCommand.tolerance = tolerance; return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajLinearMove(EmcPose end, int type, double vel, double ini_maxvel, double acc){ emcmotCommand.command = EMCMOT_SET_LINE; emcmotCommand.pos = end; emcmotCommand.id = localEmcTrajMotionId; emcmotCommand.motion_type = type; emcmotCommand.vel = vel; emcmotCommand.ini_maxvel = ini_maxvel; emcmotCommand.acc = acc;#ifdef ISNAN_TRAP if (isnan(emcmotCommand.pos.tran.x) || isnan(emcmotCommand.pos.tran.y) || isnan(emcmotCommand.pos.tran.z)) { printf("isnan error in emcTrajLinearMove\n"); return 0; // ignore it for now, just don't send it }#endif return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajCircularMove(EmcPose end, PM_CARTESIAN center, PM_CARTESIAN normal, int turn, int type, double vel, double ini_maxvel, double acc){ emcmotCommand.command = EMCMOT_SET_CIRCLE; emcmotCommand.pos = end; emcmotCommand.motion_type = type; emcmotCommand.center.x = center.x;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -