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

📄 taskintf.cc

📁 CNC 的开放码,EMC2 V2.2.8版
💻 CC
📖 第 1 页 / 共 3 页
字号:
    emcmotCommand.center.y = center.y;    emcmotCommand.center.z = center.z;    emcmotCommand.normal.x = normal.x;    emcmotCommand.normal.y = normal.y;    emcmotCommand.normal.z = normal.z;    emcmotCommand.turn = turn;    emcmotCommand.id = localEmcTrajMotionId;    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) ||	isnan(emcmotCommand.pos.a) ||	isnan(emcmotCommand.pos.b) ||	isnan(emcmotCommand.pos.c) ||	isnan(emcmotCommand.center.x) ||	isnan(emcmotCommand.center.y) ||	isnan(emcmotCommand.center.z) ||	isnan(emcmotCommand.normal.x) ||	isnan(emcmotCommand.normal.y) || isnan(emcmotCommand.normal.z)) {	printf("isnan error in emcTrajCircularMove\n");	return 0;		// ignore it for now, just don't send it    }#endif    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajClearProbeTrippedFlag(){    emcmotCommand.command = EMCMOT_CLEAR_PROBE_FLAGS;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajProbe(EmcPose pos, int type, double vel, double ini_maxvel, double acc){    emcmotCommand.command = EMCMOT_PROBE;    emcmotCommand.pos.tran.x = pos.tran.x;    emcmotCommand.pos.tran.y = pos.tran.y;    emcmotCommand.pos.tran.z = pos.tran.z;    emcmotCommand.pos.a = pos.a;    emcmotCommand.pos.b = pos.b;    emcmotCommand.pos.c = pos.c;    emcmotCommand.pos.u = pos.u;    emcmotCommand.pos.v = pos.v;    emcmotCommand.pos.w = pos.w;    emcmotCommand.id = localEmcTrajMotionId;    emcmotCommand.motion_type = type;    emcmotCommand.vel = vel;    emcmotCommand.ini_maxvel = ini_maxvel;    emcmotCommand.acc = acc;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcTrajRigidTap(EmcPose pos, double vel, double ini_maxvel, double acc){    emcmotCommand.command = EMCMOT_RIGID_TAP;    emcmotCommand.pos.tran.x = pos.tran.x;    emcmotCommand.pos.tran.y = pos.tran.y;    emcmotCommand.pos.tran.z = pos.tran.z;    emcmotCommand.id = localEmcTrajMotionId;    emcmotCommand.vel = vel;    emcmotCommand.ini_maxvel = ini_maxvel;    emcmotCommand.acc = acc;    return usrmotWriteEmcmotCommand(&emcmotCommand);}static int last_id = 0;static int last_id_printed = 0;static int last_status = 0;static double last_id_time;int emcTrajUpdate(EMC_TRAJ_STAT * stat){    int axis;    stat->axes = localEmcTrajAxes;    stat->axis_mask = localEmcTrajAxisMask;    stat->linearUnits = localEmcTrajLinearUnits;    stat->angularUnits = localEmcTrajAngularUnits;    stat->mode =	emcmotStatus.	motionFlag & EMCMOT_MOTION_TELEOP_BIT ? EMC_TRAJ_MODE_TELEOP	: (emcmotStatus.	   motionFlag & EMCMOT_MOTION_COORD_BIT ? EMC_TRAJ_MODE_COORD :	   EMC_TRAJ_MODE_FREE);    /* enabled if motion enabled and all axes enabled */    stat->enabled = 0;		/* start at disabled */    if (emcmotStatus.motionFlag & EMCMOT_MOTION_ENABLE_BIT) {	for (axis = 0; axis < localEmcTrajAxes; axis++) {/*! \todo Another #if 0 */#if 0				/*! \todo FIXME - the axis flag has been moved to the joint struct */	    if (!emcmotStatus.axisFlag[axis] & EMCMOT_AXIS_ENABLE_BIT) {		break;	    }#endif	    /* got here, then all are enabled */	    stat->enabled = 1;	}    }    stat->inpos =	emcmotStatus.motionFlag & EMCMOT_MOTION_INPOS_BIT ? 1 : 0;    stat->queue = emcmotStatus.depth;    stat->activeQueue = emcmotStatus.activeDepth;    stat->queueFull = emcmotStatus.queueFull;    stat->id = emcmotStatus.id;    stat->motion_type = emcmotStatus.motionType;    stat->distance_to_go = emcmotStatus.distance_to_go;    stat->current_vel = emcmotStatus.current_vel;    if (EMC_DEBUG_MOTION_TIME & EMC_DEBUG) {	if (stat->id != last_id) {	    if (last_id != last_id_printed) {		rcs_print("Motion id %d took %f seconds.\n", last_id,			  etime() - last_id_time);		last_id_printed = last_id;	    }	    last_id = stat->id;	    last_id_time = etime();	}    }    stat->paused = emcmotStatus.paused;    stat->scale = emcmotStatus.feed_scale;    stat->spindle_scale = emcmotStatus.spindle_scale;    stat->position = emcmotStatus.carte_pos_cmd;    stat->actualPosition = emcmotStatus.carte_pos_fb;    stat->velocity = emcmotStatus.vel;    stat->acceleration = emcmotStatus.acc;    stat->maxAcceleration = localEmcMaxAcceleration;    if (emcmotStatus.motionFlag & EMCMOT_MOTION_ERROR_BIT) {	stat->status = RCS_ERROR;    } else if (stat->inpos && (stat->queue == 0)) {	stat->status = RCS_DONE;    } else {	stat->status = RCS_EXEC;    }    if (EMC_DEBUG_MOTION_TIME & EMC_DEBUG) {	if (stat->status == RCS_DONE && last_status != RCS_DONE	    && stat->id != last_id_printed) {	    rcs_print("Motion id %d took %f seconds.\n", last_id,		      etime() - last_id_time);	    last_id_printed = last_id = stat->id;	    last_id_time = etime();	}    }    stat->probedPosition.tran.x = emcmotStatus.probedPos.tran.x;    stat->probedPosition.tran.y = emcmotStatus.probedPos.tran.y;    stat->probedPosition.tran.z = emcmotStatus.probedPos.tran.z;    stat->probedPosition.a = emcmotStatus.probedPos.a;    stat->probedPosition.b = emcmotStatus.probedPos.b;    stat->probedPosition.c = emcmotStatus.probedPos.c;    stat->probedPosition.u = emcmotStatus.probedPos.u;    stat->probedPosition.v = emcmotStatus.probedPos.v;    stat->probedPosition.w = emcmotStatus.probedPos.w;    stat->probeval = emcmotStatus.probeVal;    stat->probe_tripped = emcmotStatus.probeTripped;    stat->feed_override_enabled = emcmotStatus.enables_new & FS_ENABLED;    stat->spindle_override_enabled = emcmotStatus.enables_new & SS_ENABLED;    stat->adaptive_feed_enabled = emcmotStatus.enables_new & AF_ENABLED;    stat->feed_hold_enabled = emcmotStatus.enables_new & FH_ENABLED;    if (new_config) {	stat->cycleTime = emcmotConfig.trajCycleTime;	stat->kinematics_type = emcmotConfig.kinematics_type;	stat->maxVelocity = emcmotConfig.limitVel;    }    return 0;}int emcPositionLoad() {    double positions[EMCMOT_MAX_AXIS];    IniFile ini;    ini.Open(EMC_INIFILE);    const char *posfile = ini.Find("POSITION_FILE", "TRAJ");    ini.Close();    if(!posfile || !posfile[0]) return 0;    FILE *f = fopen(posfile, "r");    if(!f) return 0;    for(int i=0; i<EMCMOT_MAX_AXIS; i++) {	int r = fscanf(f, "%lf", &positions[i]);	if(r != 1) { fclose(f); return -1; }    }    fclose(f);    int result = 0;    for(int i=0; i<EMCMOT_MAX_AXIS; i++) {	if(emcAxisSetMotorOffset(i, -positions[i]) != 0) result = -1;;    }    return result;}int emcPositionSave() {    IniFile ini;    ini.Open(EMC_INIFILE);    const char *posfile = ini.Find("POSITION_FILE", "TRAJ");    ini.Close();    if(!posfile || !posfile[0]) return 0;    // like the var file, make sure the posfile is recreated according to umask    unlink(posfile);    FILE *f = fopen(posfile, "w");    if(!f) return -1;    for(int i=0; i<EMCMOT_MAX_AXIS; i++) {	int r = fprintf(f, "%.17f\n", emcmotStatus.joint_status[i].pos_fb);	if(r < 0) { fclose(f); return -1; }    }    fclose(f);    return 0;}// EMC_MOTION functionsint emcMotionInit(){    int r1;    int r2;    int r3;    int axis;    r2 = emcTrajInit(); // we want to check Traj first, the sane defaults for units are there    r1 = 0;    for (axis = 0; axis < localEmcTrajAxes; axis++) {	if (0 != emcAxisInit(axis)) {	    r1 = -1;		// at least one is busted	}    }    r3 = emcPositionLoad();    if (r1 == 0 && r2 == 0 && r3 == 0) {	emcmotion_initialized = 1;    }    return (r1 == 0 && r2 == 0 && r3 == 0) ? 0 : -1;}int emcMotionHalt(){    int r1, r2, r3, r4;    int t;    r1 = -1;    for (t = 0; t < EMCMOT_MAX_AXIS; t++) {	if (0 == emcAxisHalt(t)) {	    r1 = 0;		// at least one is okay	}    }    r2 = emcTrajDisable();    r3 = emcTrajHalt();    r4 = emcPositionSave();    emcmotion_initialized = 0;    return (r1 == 0 && r2 == 0 && r3 == 0 && r4 == 0) ? 0 : -1;}int emcMotionAbort(){    int r1;    int r2;    int r3;    int t;    r1 = -1;    for (t = 0; t < EMCMOT_MAX_AXIS; t++) {	if (0 == emcAxisAbort(t)) {	    r1 = 0;		// at least one is okay	}    }    r2 = emcTrajAbort();    r3 = emcSpindleAbort();    // reset optimization flag which suppresses duplicate speed requests    lastVel = -1.0;    return (r1 == 0 && r2 == 0 && r3 == 0) ? 0 : -1;}int emcMotionSetDebug(int debug){    emcmotCommand.command = EMCMOT_SET_DEBUG;    emcmotCommand.debug = debug;    return usrmotWriteEmcmotCommand(&emcmotCommand);}/*! \function emcMotionSetAout()        This function sends a EMCMOT_SET_AOUT message to the motion controller.    That one plans a AOUT command when motion starts or right now.    @parameter	index	which output gets modified    @parameter	now	wheather change is imediate or synched with motion    @parameter	start	value set at start of motion    @parameter	end	value set at end of motion*/int emcMotionSetAout(unsigned char index, double start, double end, unsigned char now){    emcmotCommand.command = EMCMOT_SET_AOUT;    emcmotCommand.now = now;    emcmotCommand.out = index;  /*! \todo FIXME-- if this works, set up some dedicated cmd fields instead of     borrowing these */    emcmotCommand.minLimit = start;    emcmotCommand.maxLimit = end;    return usrmotWriteEmcmotCommand(&emcmotCommand);}/*! \function emcMotionSetDout()        This function sends a EMCMOT_SET_DOUT message to the motion controller.    That one plans a DOUT command when motion starts or right now.    @parameter	index	which output gets modified    @parameter	now	wheather change is imediate or synched with motion    @parameter	start	value set at start of motion    @parameter	end	value set at end of motion*/int emcMotionSetDout(unsigned char index, unsigned char start,		     unsigned char end, unsigned char now){    emcmotCommand.command = EMCMOT_SET_DOUT;    emcmotCommand.now = now;    emcmotCommand.out = index;    emcmotCommand.start = start;    emcmotCommand.end = end;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcSpindleAbort(){    return emcSpindleOff();}int emcSpindleOn(double speed, double css_factor, double offset){    emcmotCommand.command = EMCMOT_SPINDLE_ON;    emcmotCommand.vel = speed;    emcmotCommand.ini_maxvel = css_factor;    emcmotCommand.acc = offset;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcSpindleOff(){    emcmotCommand.command = EMCMOT_SPINDLE_OFF;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcSpindleBrakeRelease(){    emcmotCommand.command = EMCMOT_SPINDLE_BRAKE_RELEASE;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcSpindleBrakeEngage(){    emcmotCommand.command = EMCMOT_SPINDLE_BRAKE_ENGAGE;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcSpindleIncrease(){    emcmotCommand.command = EMCMOT_SPINDLE_INCREASE;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcSpindleDecrease(){    emcmotCommand.command = EMCMOT_SPINDLE_DECREASE;    return usrmotWriteEmcmotCommand(&emcmotCommand);}int emcSpindleConstant(){    return 0; // nothing to do}int emcMotionUpdate(EMC_MOTION_STAT * stat){    int r1;    int r2;    int axis;    int error;    int exec;    int dio, aio;    // read the emcmot status    if (0 != usrmotReadEmcmotStatus(&emcmotStatus)) {	return -1;    }    new_config = 0;    if (emcmotStatus.config_num != emcmotConfig.config_num) {	if (0 != usrmotReadEmcmotConfig(&emcmotConfig)) {	    return -1;	}	new_config = 1;    }    if (get_emcmot_debug_info) {	if (0 != usrmotReadEmcmotDebug(&emcmotDebug)) {	    return -1;	}    }    // read the emcmot error    if (0 != usrmotReadEmcmotError(errorString)) {	// no error, so ignore    } else {	// an error to report	emcOperatorError(0, errorString);    }    // save the heartbeat and command number locally,    // for use with emcMotionUpdate    localMotionHeartbeat = emcmotStatus.heartbeat;    localMotionCommandType = emcmotStatus.commandEcho;	/*! \todo FIXME-- not NML one! */    localMotionEchoSerialNumber = emcmotStatus.commandNumEcho;    r1 = emcAxisUpdate(&stat->axis[0], EMCMOT_MAX_AXIS);    r2 = emcTrajUpdate(&stat->traj);    stat->heartbeat = localMotionHeartbeat;    stat->command_type = localMotionCommandType;    stat->echo_serial_number = localMotionEchoSerialNumber;    stat->debug = emcmotConfig.debug;        stat->spindle.enabled = emcmotStatus.spindle.speed != 0;    stat->spindle.speed = emcmotStatus.spindle.speed;    stat->spindle.brake = emcmotStatus.spindle.brake;    stat->spindle.direction = emcmotStatus.spindle.direction;    // set the status flag    error = 0;    exec = 0;    for (dio = 0; dio < EMC_MAX_DIO; dio++) {	stat->synch_di[dio] = emcmotStatus.synch_di[dio];    }    for (aio = 0; aio < EMC_MAX_AIO; aio++) {	stat->analog_input[aio] = emcmotStatus.analog_input[aio];    }    for (axis = 0; axis < stat->traj.axes; axis++) {	if (stat->axis[axis].status == RCS_ERROR) {	    error = 1;	    break;	}	if (stat->axis[axis].status == RCS_EXEC) {	    exec = 1;	    break;	}    }    if (stat->traj.status == RCS_ERROR) {	error = 1;    } else if (stat->traj.status == RCS_EXEC) {	exec = 1;    }    if (error) {	stat->status = RCS_ERROR;    } else if (exec) {	stat->status = RCS_EXEC;    } else {	stat->status = RCS_DONE;    }    return (r1 == 0 && r2 == 0) ? 0 : -1;}

⌨️ 快捷键说明

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