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

📄 emccanon.cc

📁 CNC 的开放码,EMC2 V2.2.8版
💻 CC
📖 第 1 页 / 共 5 页
字号:
        tmax = MAX4(tu, tv, tw, tmax);        if(dx || dy || dz)            dtot = sqrt(dx * dx + dy * dy + dz * dz);        else            dtot = sqrt(du * du + dv * dv + dw * dw);	if (tmax <= 0.0) {	    vel = currentLinearFeedRate;	} else {	    vel = dtot / tmax;	}    }    // Pure angular move:    else if (!cartesian_move && angular_move) {	ta = da? fabs(da / FROM_EXT_ANG(AXIS_MAX_VELOCITY[3])):0.0;	tb = db? fabs(db / FROM_EXT_ANG(AXIS_MAX_VELOCITY[4])):0.0;	tc = dc? fabs(dc / FROM_EXT_ANG(AXIS_MAX_VELOCITY[5])):0.0;        tmax = MAX3(ta, tb, tc);	dtot = sqrt(da * da + db * db + dc * dc);	if (tmax <= 0.0) {	    vel = currentAngularFeedRate;	} else {	    vel = dtot / tmax;	}    }    // Combination angular and linear move:    else if (cartesian_move && angular_move) {	tx = dx? fabs(dx / FROM_EXT_LEN(AXIS_MAX_VELOCITY[0])): 0.0;	ty = dy? fabs(dy / FROM_EXT_LEN(AXIS_MAX_VELOCITY[1])): 0.0;	tz = dz? fabs(dz / FROM_EXT_LEN(AXIS_MAX_VELOCITY[2])): 0.0;	ta = da? fabs(da / FROM_EXT_ANG(AXIS_MAX_VELOCITY[3])):0.0;	tb = db? fabs(db / FROM_EXT_ANG(AXIS_MAX_VELOCITY[4])):0.0;	tc = dc? fabs(dc / FROM_EXT_ANG(AXIS_MAX_VELOCITY[5])):0.0;	tu = du? fabs(du / FROM_EXT_LEN(AXIS_MAX_VELOCITY[6])): 0.0;	tv = dv? fabs(dv / FROM_EXT_LEN(AXIS_MAX_VELOCITY[7])): 0.0;	tw = dw? fabs(dw / FROM_EXT_LEN(AXIS_MAX_VELOCITY[8])): 0.0;        tmax = MAX9(tx, ty, tz,                    ta, tb, tc,                    tu, tv, tw);/*  According to NIST IR6556 Section 2.1.2.5 Paragraph A    a combnation move is handled like a linear move, except    that the angular axes are allowed sufficient time to    complete their motion coordinated with the motion of    the linear axes.*/        if(dx || dy || dz)            dtot = sqrt(dx * dx + dy * dy + dz * dz);        else            dtot = sqrt(du * du + dv * dv + dw * dw);	if (tmax <= 0.0) {	    vel = currentLinearFeedRate;	} else {	    vel = dtot / tmax;	}    }    if(debug_velacc)         printf("cartesian %d ang %d vel %g\n", cartesian_move, angular_move, vel);    return vel;}#include <vector>struct pt { double x, y, z, a, b, c, u, v, w; int line_no;};static std::vector<struct pt>& chained_points(void) {    static std::vector<struct pt> points;    return points;}static void flush_segments(void) {    if(chained_points().empty()) return;    struct pt &pos = chained_points().back();    double x = pos.x, y = pos.y, z = pos.z;    double a = pos.a, b = pos.b, c = pos.c;    double u = pos.u, v = pos.v, w = pos.w;        int line_no = pos.line_no;#ifdef SHOW_JOINED_SEGMENTS    for(unsigned int i=0; i != chained_points().size(); i++) { printf("."); }    printf("\n");#endif    double ini_maxvel = getStraightVelocity(x, y, z, a, b, c, u, v, w),           vel = ini_maxvel;    if (cartesian_move && !angular_move) {	if (vel > currentLinearFeedRate) {	    vel = currentLinearFeedRate;	}    } else if (!cartesian_move && angular_move) {	if (vel > currentAngularFeedRate) {	    vel = currentAngularFeedRate;	}    } else if (cartesian_move && angular_move) {	if (vel > currentLinearFeedRate) {	    vel = currentLinearFeedRate;	}    }    EMC_TRAJ_LINEAR_MOVE linearMoveMsg;    linearMoveMsg.feed_mode = feed_mode;    // now x, y, z, and b are in absolute mm or degree units    linearMoveMsg.end.tran.x = TO_EXT_LEN(x);    linearMoveMsg.end.tran.y = TO_EXT_LEN(y);    linearMoveMsg.end.tran.z = TO_EXT_LEN(z);    linearMoveMsg.end.u = TO_EXT_LEN(u);    linearMoveMsg.end.v = TO_EXT_LEN(v);    linearMoveMsg.end.w = TO_EXT_LEN(w);    // fill in the orientation    linearMoveMsg.end.a = TO_EXT_ANG(a);    linearMoveMsg.end.b = TO_EXT_ANG(b);    linearMoveMsg.end.c = TO_EXT_ANG(c);    linearMoveMsg.vel = toExtVel(vel);    linearMoveMsg.ini_maxvel = toExtVel(ini_maxvel);    double acc = getStraightAcceleration(x, y, z, a, b, c, u, v, w);    linearMoveMsg.acc = toExtAcc(acc);    linearMoveMsg.type = EMC_MOTION_TYPE_FEED;    int save = interp_list.get_next_line_number();    interp_list.set_line_number(line_no);    interp_list.append(linearMoveMsg);    interp_list.set_line_number(save);    canonUpdateEndPoint(x, y, z, a, b, c, u, v, w);    chained_points().clear();}static boollinkable(double x, double y, double z,          double a, double b, double c,          double u, double v, double w) {    struct pt &pos = chained_points().back();    if(canonMotionMode != CANON_CONTINUOUS || canonMotionTolerance == 0)        return false;    if(chained_points().size() > 100) return false;    if(a != pos.a) return false;    if(b != pos.b) return false;    if(c != pos.c) return false;    if(u != pos.u) return false;    if(v != pos.v) return false;    if(w != pos.w) return false;    if(x==canonEndPoint.x && y==canonEndPoint.y && z==canonEndPoint.z) return false;        for(std::vector<struct pt>::iterator it = chained_points().begin();            it != chained_points().end(); it++) {        PM_CARTESIAN M(x-canonEndPoint.x, y-canonEndPoint.y, z-canonEndPoint.z),                     B(canonEndPoint.x, canonEndPoint.y, canonEndPoint.z),                     P(it->x, it->y, it->z);        double t0 = dot(M, P-B) / dot(M, M);        if(t0 < 0) t0 = 0;        if(t0 > 1) t0 = 1;        double D = mag(P - (B + t0 * M));        if(D > canonMotionTolerance) return false;    }    return true;}static voidsee_segment(double x, double y, double z,             double a, double b, double c,            double u, double v, double w) {    bool changed_abc = (a != canonEndPoint.a)        || (b != canonEndPoint.b)        || (c != canonEndPoint.c);    bool changed_uvw = (u != canonEndPoint.u)        || (v != canonEndPoint.v)        || (w != canonEndPoint.w);    if(!chained_points().empty() && !linkable(x, y, z, a, b, c, u, v, w)) {        flush_segments();    }    pt pos = {x, y, z, a, b, c, u, v, w, interp_list.get_next_line_number()};    chained_points().push_back(pos);    if(changed_abc || changed_uvw) {        flush_segments();    }}void FINISH() {    flush_segments();}void STRAIGHT_TRAVERSE(double x, double y, double z,		       double a, double b, double c,                       double u, double v, double w){    double vel, acc;    EMC_TRAJ_LINEAR_MOVE linearMoveMsg;    linearMoveMsg.feed_mode = 0;    // convert to mm units    x = FROM_PROG_LEN(x);    y = FROM_PROG_LEN(y);    z = FROM_PROG_LEN(z);    a = FROM_PROG_ANG(a);    b = FROM_PROG_ANG(b);    c = FROM_PROG_ANG(c);    u = FROM_PROG_LEN(u);    v = FROM_PROG_LEN(v);    w = FROM_PROG_LEN(w);    x += programOrigin.x;    y += programOrigin.y;    z += programOrigin.z;    a += programOrigin.a;    b += programOrigin.b;    c += programOrigin.c;    u += programOrigin.u;    v += programOrigin.v;    w += programOrigin.w;    x += currentXToolOffset;    z += currentZToolOffset;    // now x, y, z, and b are in absolute mm or degree units    linearMoveMsg.end.tran.x = TO_EXT_LEN(x);    linearMoveMsg.end.tran.y = TO_EXT_LEN(y);    linearMoveMsg.end.tran.z = TO_EXT_LEN(z);    // fill in the orientation    linearMoveMsg.end.a = TO_EXT_ANG(a);    linearMoveMsg.end.b = TO_EXT_ANG(b);    linearMoveMsg.end.c = TO_EXT_ANG(c);    linearMoveMsg.end.u = TO_EXT_LEN(u);    linearMoveMsg.end.v = TO_EXT_LEN(v);    linearMoveMsg.end.w = TO_EXT_LEN(w);    linearMoveMsg.type = EMC_MOTION_TYPE_TRAVERSE;    flush_segments();    vel = getStraightVelocity(x, y, z, a, b, c, u, v, w);    acc = getStraightAcceleration(x, y, z, a, b, c, u, v, w);    linearMoveMsg.vel = linearMoveMsg.ini_maxvel = toExtVel(vel);    linearMoveMsg.acc = toExtAcc(acc);    linearMoveMsg.type = EMC_MOTION_TYPE_TRAVERSE;    int old_feed_mode = feed_mode;    if(feed_mode)	STOP_SPEED_FEED_SYNCH();    if(vel && acc)         interp_list.append(linearMoveMsg);    if(old_feed_mode)	START_SPEED_FEED_SYNCH(currentLinearFeedRate, 1);    canonUpdateEndPoint(x, y, z, a, b, c, u, v, w);}void STRAIGHT_FEED(double x, double y, double z,                    double a, double b, double c,                   double u, double v, double w){    EMC_TRAJ_LINEAR_MOVE linearMoveMsg;    linearMoveMsg.feed_mode = feed_mode;    // convert to mm units    x = FROM_PROG_LEN(x);    y = FROM_PROG_LEN(y);    z = FROM_PROG_LEN(z);    a = FROM_PROG_ANG(a);    b = FROM_PROG_ANG(b);    c = FROM_PROG_ANG(c);    u = FROM_PROG_LEN(u);    v = FROM_PROG_LEN(v);    w = FROM_PROG_LEN(w);    x += programOrigin.x;    y += programOrigin.y;    z += programOrigin.z;    a += programOrigin.a;    b += programOrigin.b;    c += programOrigin.c;    u += programOrigin.u;    v += programOrigin.v;    w += programOrigin.w;    x += currentXToolOffset;    z += currentZToolOffset;    see_segment(x, y, z, a, b, c, u, v, w);}void RIGID_TAP(double x, double y, double z){    double ini_maxvel, vel, acc;    EMC_TRAJ_RIGID_TAP rigidTapMsg;    // convert to mm units    x = FROM_PROG_LEN(x);    y = FROM_PROG_LEN(y);    z = FROM_PROG_LEN(z);        x += programOrigin.x;    y += programOrigin.y;    z += programOrigin.z;    x += currentXToolOffset;    z += currentZToolOffset;    rigidTapMsg.pos.tran.x = TO_EXT_LEN(x);    rigidTapMsg.pos.tran.y = TO_EXT_LEN(y);    rigidTapMsg.pos.tran.z = TO_EXT_LEN(z);    vel = getStraightVelocity(x, y, z,                               canonEndPoint.a, canonEndPoint.b, canonEndPoint.c,                               canonEndPoint.u, canonEndPoint.v, canonEndPoint.w);    ini_maxvel = vel;        acc = getStraightAcceleration(x, y, z,                                   canonEndPoint.a, canonEndPoint.b, canonEndPoint.c,                                  canonEndPoint.u, canonEndPoint.v, canonEndPoint.w);        rigidTapMsg.vel = toExtVel(vel);    rigidTapMsg.ini_maxvel = toExtVel(ini_maxvel);    rigidTapMsg.acc = toExtAcc(acc);    flush_segments();    interp_list.append(rigidTapMsg);    // don't move the endpoint because after this move, we are back where we started}/*  STRAIGHT_PROBE is exactly the same as STRAIGHT_FEED, except that it  uses a probe message instead of a linear move message.*/void STRAIGHT_PROBE(double x, double y, double z,                     double a, double b, double c,                    double u, double v, double w){    double ini_maxvel, vel, acc;    EMC_TRAJ_PROBE probeMsg;    // convert to mm units    x = FROM_PROG_LEN(x);    y = FROM_PROG_LEN(y);    z = FROM_PROG_LEN(z);    a = FROM_PROG_ANG(a);    b = FROM_PROG_ANG(b);    c = FROM_PROG_ANG(c);    u = FROM_PROG_LEN(u);    v = FROM_PROG_LEN(v);    w = FROM_PROG_LEN(w);    x += programOrigin.x;    y += programOrigin.y;    z += programOrigin.z;    a += programOrigin.a;    b += programOrigin.b;    c += programOrigin.c;    u += programOrigin.u;    v += programOrigin.v;    w += programOrigin.w;    x += currentXToolOffset;    z += currentZToolOffset;    // now x, y, z, and b are in absolute mm or degree units    probeMsg.pos.tran.x = TO_EXT_LEN(x);    probeMsg.pos.tran.y = TO_EXT_LEN(y);    probeMsg.pos.tran.z = TO_EXT_LEN(z);    // fill in the orientation    probeMsg.pos.a = TO_EXT_ANG(a);    probeMsg.pos.b = TO_EXT_ANG(b);    probeMsg.pos.c = TO_EXT_ANG(c);    probeMsg.pos.u = TO_EXT_LEN(u);    probeMsg.pos.v = TO_EXT_LEN(v);    probeMsg.pos.w = TO_EXT_LEN(w);    flush_segments();    ini_maxvel = vel = getStraightVelocity(x, y, z, a, b, c, u, v, w);    if (cartesian_move && !angular_move) {	if (vel > currentLinearFeedRate) {	    vel = currentLinearFeedRate;	}    } else if (!cartesian_move && angular_move) {	if (vel > currentAngularFeedRate) {	    vel = currentAngularFeedRate;	}    } else if (cartesian_move && angular_move) {	if (vel > currentLinearFeedRate) {	    vel = currentLinearFeedRate;	}    }    acc = getStraightAcceleration(x, y, z, a, b, c, u, v, w);    probeMsg.vel = toExtVel(vel);    probeMsg.ini_maxvel = toExtVel(ini_maxvel);    probeMsg.acc = toExtAcc(acc);    probeMsg.type = EMC_MOTION_TYPE_PROBING;    interp_list.append(probeMsg);    canonUpdateEndPoint(x, y, z, a, b, c, u, v, w);}/* Machining Attributes */void SET_MOTION_CONTROL_MODE(CANON_MOTION_MODE mode, double tolerance){    EMC_TRAJ_SET_TERM_COND setTermCondMsg;    flush_segments();    canonMotionMode = mode;    canonMotionTolerance =  FROM_PROG_LEN(tolerance);    switch (mode) {    case CANON_CONTINUOUS:        setTermCondMsg.cond = EMC_TRAJ_TERM_COND_BLEND;        setTermCondMsg.tolerance = TO_EXT_LEN(canonMotionTolerance);        break;    default:        setTermCondMsg.cond = EMC_TRAJ_TERM_COND_STOP;        break;    }    interp_list.append(setTermCondMsg);}CANON_MOTION_MODE GET_MOTION_CONTROL_MODE(){    return canonMotionMode;}double GET_MOTION_CONTROL_TOLERANCE(){    return canonMotionTolerance;}void SELECT_PLANE(CANON_PLANE in_plane){    activePlane = in_plane;}void SET_CUTTER_RADIUS_COMPENSATION(double radius){    // nothing need be done here}void START_CUTTER_RADIUS_COMPENSATION(int side){    // nothing need be done here}void STOP_CUTTER_RADIUS_COMPENSATION(){    // nothing need be done here}

⌨️ 快捷键说明

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