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

📄 control.c

📁 CNC 的开放码,EMC2 V2.2.8版
💻 C
📖 第 1 页 / 共 5 页
字号:
	SET_MOTION_ENABLE_FLAG(1);	/* clear any outstanding motion errors when going into enabled state */	SET_MOTION_ERROR_FLAG(0);    }    /* check for entering teleop mode */    if (emcmotDebug->teleoperating && !GET_MOTION_TELEOP_FLAG()) {	if (GET_MOTION_INPOS_FLAG()) {	    /* update coordinated emcmotDebug->queue position */	    tpSetPos(&emcmotDebug->queue, emcmotStatus->carte_pos_cmd);	    /* drain the cubics so they'll synch up */	    for (joint_num = 0; joint_num < num_joints; joint_num++) {		/* point to joint data */		joint = &joints[joint_num];		cubicDrain(&(joint->cubic));	    }	    /* Initialize things to do when starting teleop mode. */	    emcmotDebug->teleop_data.currentVel.tran.x = 0.0;	    emcmotDebug->teleop_data.currentVel.tran.y = 0.0;	    emcmotDebug->teleop_data.currentVel.tran.z = 0.0;	    emcmotDebug->teleop_data.currentVel.a = 0.0;	    emcmotDebug->teleop_data.currentVel.b = 0.0;	    emcmotDebug->teleop_data.currentVel.c = 0.0;	    emcmotDebug->teleop_data.desiredVel.tran.x = 0.0;	    emcmotDebug->teleop_data.desiredVel.tran.y = 0.0;	    emcmotDebug->teleop_data.desiredVel.tran.z = 0.0;	    emcmotDebug->teleop_data.desiredVel.a = 0.0;	    emcmotDebug->teleop_data.desiredVel.b = 0.0;	    emcmotDebug->teleop_data.desiredVel.c = 0.0;	    emcmotDebug->teleop_data.currentAccell.tran.x = 0.0;	    emcmotDebug->teleop_data.currentAccell.tran.y = 0.0;	    emcmotDebug->teleop_data.currentAccell.tran.z = 0.0;	    emcmotDebug->teleop_data.currentAccell.a = 0.0;	    emcmotDebug->teleop_data.currentAccell.b = 0.0;	    emcmotDebug->teleop_data.currentAccell.c = 0.0;	    emcmotDebug->teleop_data.desiredAccell.tran.x = 0.0;	    emcmotDebug->teleop_data.desiredAccell.tran.y = 0.0;	    emcmotDebug->teleop_data.desiredAccell.tran.z = 0.0;	    emcmotDebug->teleop_data.desiredAccell.a = 0.0;	    emcmotDebug->teleop_data.desiredAccell.b = 0.0;	    emcmotDebug->teleop_data.desiredAccell.c = 0.0;	    SET_MOTION_TELEOP_FLAG(1);	    SET_MOTION_ERROR_FLAG(0);	} else {	    /* not in position-- don't honor mode change */	    emcmotDebug->teleoperating = 0;	}    } else {	if (GET_MOTION_INPOS_FLAG()) {	    if (!emcmotDebug->teleoperating && GET_MOTION_TELEOP_FLAG()) {		SET_MOTION_TELEOP_FLAG(0);		if (!emcmotDebug->coordinating) {		    for (joint_num = 0; joint_num < num_joints;			joint_num++) {			/* point to joint data */			joint = &joints[joint_num];			/* update free planner positions */			joint->free_pos_cmd = joint->pos_cmd;		    }		}	    }	}	/* check for entering coordinated mode */	if (emcmotDebug->coordinating && !GET_MOTION_COORD_FLAG()) {	    if (GET_MOTION_INPOS_FLAG()) {		/* preset traj planner to current position */		tpSetPos(&emcmotDebug->queue, emcmotStatus->carte_pos_cmd);		/* drain the cubics so they'll synch up */		for (joint_num = 0; joint_num < num_joints; joint_num++) {		    /* point to joint data */		    joint = &joints[joint_num];		    cubicDrain(&(joint->cubic));		}		/* clear the override limits flags */		emcmotDebug->overriding = 0;		emcmotStatus->overrideLimitMask = 0;		SET_MOTION_COORD_FLAG(1);		SET_MOTION_TELEOP_FLAG(0);		SET_MOTION_ERROR_FLAG(0);	    } else {		/* not in position-- don't honor mode change */		emcmotDebug->coordinating = 0;	    }	}	/* check entering free space mode */	if (!emcmotDebug->coordinating && GET_MOTION_COORD_FLAG()) {	    if (GET_MOTION_INPOS_FLAG()) {		for (joint_num = 0; joint_num < num_joints; joint_num++) {		    /* point to joint data */		    joint = &joints[joint_num];		    /* set joint planner pos cmd to current location */		    joint->free_pos_cmd = joint->pos_cmd;		    /* but it can stay disabled until a move is required */		    joint->free_tp_enable = 0;		}		SET_MOTION_COORD_FLAG(0);		SET_MOTION_TELEOP_FLAG(0);		SET_MOTION_ERROR_FLAG(0);	    } else {		/* not in position-- don't honor mode change */		emcmotDebug->coordinating = 1;	    }	}    }    /*! \todo FIXME - this code is temporary - eventually this function will be       cleaned up and simplified, and 'motion_state' will become the master       for this info, instead of having to gather it from several flags */    if (!GET_MOTION_ENABLE_FLAG()) {	emcmotStatus->motion_state = EMCMOT_MOTION_DISABLED;    } else if (GET_MOTION_TELEOP_FLAG()) {	emcmotStatus->motion_state = EMCMOT_MOTION_TELEOP;    } else if (GET_MOTION_COORD_FLAG()) {	emcmotStatus->motion_state = EMCMOT_MOTION_COORD;    } else {	emcmotStatus->motion_state = EMCMOT_MOTION_FREE;    }}static void handle_jogwheels(void){    int joint_num;    emcmot_joint_t *joint;    axis_hal_t *axis_data;    int new_jog_counts, delta;    double distance, pos, stop_dist;    for (joint_num = 0; joint_num < num_joints; joint_num++) {	/* point to joint data */	axis_data = &(emcmot_hal_data->axis[joint_num]);	joint = &joints[joint_num];	if (!GET_JOINT_ACTIVE_FLAG(joint)) {	    /* if joint is not active, skip it */	    continue;	}	/* get counts from jogwheel */	new_jog_counts = *(axis_data->jog_counts);	delta = new_jog_counts - joint->old_jog_counts;	/* save value for next time */	joint->old_jog_counts = new_jog_counts;	/* initialization complete */	if ( first_pass ) {	    continue;	}	/* did the wheel move? */	if ( delta == 0 ) {	    /* no, nothing to do */	    continue;	}	/* must be in free mode and enabled */	if (GET_MOTION_COORD_FLAG()) {	    continue;	}	if (!GET_MOTION_ENABLE_FLAG()) {	    continue;	}	/* the jogwheel input for this axis must be enabled */	if ( *(axis_data->jog_enable) == 0 ) {	    continue;	}	/* must not be homing */	if (emcmotStatus->homing_active) {	    continue;	}	/* must not be doing a keyboard jog */	if (joint->kb_jog_active) {	    continue;	}	if (emcmotStatus->net_feed_scale < 0.0001 ) {	    /* don't jog if feedhold is on or if feed override is zero */	    break;	}	/* calculate distance to jog */	distance = delta * *(axis_data->jog_scale);	/* check for joint already on hard limit */	if (distance > 0.0 && GET_JOINT_PHL_FLAG(joint)) {	    continue;	}	if (distance < 0.0 && GET_JOINT_NHL_FLAG(joint)) {	    continue;	}	/* calc target position for jog */	pos = joint->free_pos_cmd + distance;	/* don't jog past limits */	refresh_jog_limits(joint);	if (pos > joint->max_jog_limit) {	    continue;	}	if (pos < joint->min_jog_limit) {	    continue;	}	/* The default is to move exactly as far as the wheel commands,	   even if that move takes much longer than the wheel movement	   that commanded it.  Some folks prefer that the move stop as	   soon as the wheel does, even if that means not moving the	   commanded distance.  Velocity mode is for those folks.  If	   the command is faster than the machine can track, excess	   command is simply dropped. */	if ( *(axis_data->jog_vel_mode) ) {            double v = joint->vel_limit * emcmotStatus->net_feed_scale;	    /* compute stopping distance at max speed */	    stop_dist = v * v / ( 2 * joint->acc_limit);	    /* if commanded position leads the actual position by more	       than stopping distance, discard excess command */	    if ( pos > joint->pos_cmd + stop_dist ) {		pos = joint->pos_cmd + stop_dist;	    } else if ( pos < joint->pos_cmd - stop_dist ) {		pos = joint->pos_cmd - stop_dist;	    }	}        /* set target position and use full velocity */        joint->free_pos_cmd = pos;        joint->free_vel_lim = joint->vel_limit;	/* lock out other jog sources */	joint->wheel_jog_active = 1;        /* and let it go */        joint->free_tp_enable = 1;	SET_JOINT_ERROR_FLAG(joint, 0);	/* clear axis homed flag(s) if we don't have forward kins.	   Otherwise, a transition into coordinated mode will incorrectly	   assume the homed position. Do all if they've all been moved	   since homing, otherwise just do this one */	clearHomes(joint_num);    }}/* Beginning of homing related code *//* Length of delay between homing motions - this is intended to   ensure that all motion has ceased and switch bouncing has   ended.  We might want to make this user adjustable, but for   now it's a constant.  It is in seconds */#define HOME_DELAY 0.100/* variable used internally by do_homing, but global so that   'home_do_moving_checks()' can access it */static int immediate_state;/* a couple of helper functions with code that would otherwise be   repeated in several different states of the homing state machine *//* 'home_start_move()' starts a move at the specified velocity.  The   length of the move is equal to twice the overall range of the axis,   but the intent is that something (like a home switch or index pulse)   will stop it before that point. */void home_start_move(emcmot_joint_t * joint, double vel){    double axis_range;    /* set up a long move */    axis_range = joint->max_pos_limit - joint->min_pos_limit;    if (vel > 0.0) {	joint->free_pos_cmd = joint->pos_cmd + 2.0 * axis_range;    } else {	joint->free_pos_cmd = joint->pos_cmd - 2.0 * axis_range;    }    joint->free_vel_lim = fabs(vel);    /* start the move */    joint->free_tp_enable = 1;}/* 'home_do_moving_checks()' is called from states where the machine   is supposed to be moving.  It checks to see if the machine has   hit a limit, or if the move has stopped.  (Normally such moves   will be terminated by the home switch or an index pulse or some   other event, if the move goes to completion, something is wrong.) */static void home_do_moving_checks(emcmot_joint_t * joint){    /* check for limit switches */    if (joint->on_pos_limit || joint->on_neg_limit) {	/* on limit, check to see if we should trip */	if (!(joint->home_flags & HOME_IGNORE_LIMITS)) {	    /* not ignoring limits, time to quit */	    reportError("hit limit in home state %d", joint->home_state);	    joint->home_state = HOME_ABORT;	    immediate_state = 1;	    return;	}    }    /* check for reached end of move */    if (!joint->free_tp_active) {	/* reached end of move without hitting switch */	joint->free_tp_enable = 0;	reportError("end of move in home state %d", joint->home_state);	joint->home_state = HOME_ABORT;	immediate_state = 1;	return;    }}static void do_homing_sequence(void){    static int home_sequence = -1;    int i;    int seen = 0;    emcmot_joint_t *joint;    /* first pass init */    if(home_sequence == -1) {        emcmotStatus->homingSequenceState = HOME_SEQUENCE_IDLE;	home_sequence = 0;    }    switch(emcmotStatus->homingSequenceState) {    case HOME_SEQUENCE_IDLE:	/* nothing to do */	break;    case HOME_SEQUENCE_START:	/* a request to home all joints */	for(i=0; i < num_joints; i++) {	    joint = &joints[i];	    if(joint->home_state != HOME_IDLE) {		/* a home is already in progress, abort the home-all */		emcmotStatus->homingSequenceState = HOME_SEQUENCE_IDLE;		return;	    }	}	/* ok to start the sequence, start at zero */	home_sequence = 0;	/* tell the world we're on the job */	emcmotStatus->homing_active = 1;	/* and drop into next state */    case HOME_SEQUENCE_START_JOINTS:	/* start all joints whose sequence number matches home_sequence */	for(i=0; i < num_joints; i++) {	    joint = &joints[i];	    if(joint->home_sequence == home_sequence) {		/* start this joint */	        joint->free_tp_enable = 0;		joint->home_state = HOME_START;		seen++;	    }	}	if(seen) {	    /* at least one joint is homing, wait for it */	    emcmotStatus->homingSequenceState = HOME_SEQUENCE_WAIT_JOINTS;	} else {	    /* no joints have this sequence number, we're done */	    emcmotStatus->homingSequenceState = HOME_IDLE;	    /* tell the world */	    emcmotStatus->homing_active = 0;	}	break;    case HOME_SEQUENCE_WAIT_JOINTS:	for(i=0; i < num_joints; i++) {	    joint = &joints[i];	    if(joint->home_sequence != home_sequence) {		/* this joint is not at the current sequence number, ignore it */		continue;	    }	    if(joint->home_state != HOME_IDLE) {		/* still busy homing, keep waiting */		seen = 1;		continue;	    }	    if(!GET_JOINT_AT_HOME_FLAG(joint)) {		/* joint should have been homed at this step, it is no longer		   homing, but its not at home - must have failed.  bail out */		emcmotStatus->homingSequenceState = HOME_SEQUENCE_IDLE;		emcmotStatus->homing_active = 0;		return;	    }	}	if(!seen) {	    /* all joints at this step have finished homing, move on to next step */	    home_sequence ++;	    emcmotStatus->homingSequenceState = HOME_SEQUENCE_START_JOINTS;	}	break;    default:	/* should never get here */	reportError("unknown state '%d' during homing sequence",	    emcmotStatus->homingSequenceState);	emcmotStatus->homingSequenceState = HOME_SEQUENCE_IDLE;

⌨️ 快捷键说明

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