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

📄 kkem.c

📁 非常重要的嵌入式单片机开发语言 是美国德州仪器的MSP430系列的系统语言4
💻 C
📖 第 1 页 / 共 4 页
字号:
}

/*=========================================================
  unit_command()                         (G-code group #06)
       displacement unit system

  command format :
    G20...;           input in inch
    G21...;           input in mm
=========================================================*/
static BOOL unit_command()
{    if (gUnit)
     {    nUnit = 21-gUnit;
          nDot  = (nUnit) ? 4 : 3;
          local_to_absolute((LPAXIS)&CNC_lastX,(LPAXIS)&CNC_last);
     }
     gUnit=nUnit;
     return(FALSE);
}

/*=========================================================
  cutter_command()                       (G-code group #07)
       cutter compensation

  command format :
    G40...;           cutter compensation cancel
    G41...;           cutter compensation left
    G42...;           cutter compensation right
=========================================================*/
static BOOL cutter_command()
{    if (gCut) nCut=gCut-40;
     gCut=nCut;
     return(FALSE);
}

/*=========================================================
  tool_command()                         (G-code group #08)
         tool length compensation

  command format :
    G43...;           tool length compensation + direction
    G44...;           tool length compensation - direction
    G49...;           tool length compensation cancel
=========================================================*/
static BOOL tool_command()
{    if (gTool) nTool=(gTool==49)?0:(gTool-42);
     gTool=nTool;
     return(FALSE);
}

/*=========================================================
  cycle_command()                        (G-code group #09)
        can-cycle commands

  command format :
    G80...;             can-cycle cancel
    G81/.../G89...;     can-cycle commands
    Gnn(undefined);     calling   commands
=========================================================*/
static BOOL cycle_command()
{    int n;
     if (gCycle) nCycle=(gCycle==80)?0:gCycle;
     gCycle=nCycle;
                       /* call subprogram (#9000+gCycle) */
     if      (gCycle)       n=gCycle;
     else if (lpCmd->g[20]) n=lpCmd->g[20];
     else if (lpCmd->g[21]) n=lpCmd->g[21];
     else if (lpCmd->g[22]) n=lpCmd->g[22];
     else                   return(FALSE);
     if (open_CNC_file(n+9000))
          CNC_stack[CNC_level].nloop=(gCycle)?((int)vL):1;
     return(TRUE);
}

/*=========================================================
  return_command()                       (G-code group #10)
         return flag in can-cycle commands

  command format :
    G98  ...;     return to start point after can cycle
    G99  ...;     return to reference after can cycle
=========================================================*/
static BOOL return_command()
{    if (gReturn) nReturn=gReturn-98;
     gReturn=nReturn;
     return(FALSE);
}

/*=========================================================
  scaling_command()                      (G-code group #11)
          coordination system scaling

  command format :
    G51X_Y_Z_P_;
    G51X_Y_Z_I_J_K_;
    G50...;
=========================================================*/
static BOOL scaling_command()
{    int i; float x;
     if (!gScale)    { gScale=nScale; return(FALSE); }
     nScale=gScale-50; gScale=nScale;
     if (nScale)
     {    get_axis_absolute((LPAXIS)&CNC_scale0);
          x=get_value_input('P',3);
          if (fP) { for (i=0; i<6; i++) CNC_scalef.v[i]=x; }
          else    { get_center_input((LPAXIS)&CNC_scalef); }
     }
     return(TRUE);
}

/*=========================================================
  macro_command()                        (G-code group #12)
        user-macro commands

  command format :
    G65...;     single user-macro command
    G66...;     setting user-macro mode
    G67...;     user-macro mode cancel
=========================================================*/
static BOOL macro_command()
{    if  (gMacro) nMacro=67-gMacro;
     gMacro=nMacro;
     if (nMacro==2) nMacro=0;
     if (!gMacro) return(FALSE);
                                   /* call subprogram #P */
     if (open_CNC_file((int)vP)) CNC_stack[CNC_level].nloop=(int)vL;
     return(TRUE);
}

/*=========================================================
  speed_command()                       (G-code group #13)
        spindle speed system

  command format :
    G96...;  constant surface speed control
    G97...;  constant surface speed control cancel
=========================================================*/
static BOOL speed_command()
{    if (gSpeed) nSpeed=97-gSpeed;
     gSpeed=nSpeed;
     return(FALSE);
}

/*=========================================================
  working_command()                      (G-code group #14)
          working coordinate system

  command format :
    G54...;    working coordinate system #1 selection
    G55...;    working coordinate system #2 selection
    G56...;    working coordinate system #3 selection
    G57...;    working coordinate system #4 selection
    G58...;    working coordinate system #5 selection
    G59...;    working coordinate system #6 selection
=========================================================*/
static BOOL working_command()
{    if (gWork) nWork=gWork-53;
     gWork=nWork;
     return(FALSE);
}

/*=========================================================
  stop_command()                         (G-code group #15)
        stop command between blocks

  command format :
    G61...;    exact stop mode
    G62...;    automatic corner override
    G63...;    tapping mode
    G64...;    cutting mode
=========================================================*/
static BOOL stop_command()
{    if (gStop) nStop=64-gStop;
     gStop=nStop;
     return(FALSE);
}

/*=========================================================
  rotate_command()                       (G-code group #16)
         coordinate system rotation

  command format :
    G68X_Y_Z_R_;
    G69...;
=========================================================*/
static BOOL rotate_command()
{    CNCaxis_t a;
     if (gRotate)
     {    nRotate=69-gRotate;
          if (nRotate)
          {    get_axis_absolute((LPAXIS)&a);
               CNC_rotate.x0 = a.v[CNC_nx];
               CNC_rotate.y0 = a.v[CNC_ny];
               CNC_rotate.nx = CNC_nx;
               CNC_rotate.ny = CNC_ny;
               CNC_rotate.ang = get_value_input('R',3);
               CNC_rotate.sin = sin(CNC_rotate.ang*PI/180.);
               CNC_rotate.cos = cos(CNC_rotate.ang*PI/180.);
          }
          gRotate=nRotate;
          local_to_absolute((LPAXIS)&CNC_lastX,(LPAXIS)&CNC_last);
          return(TRUE);
     }
     gRotate=nRotate;
     return(FALSE);
}

/*=========================================================
  polar_command()                        (G-code group #17)
        polar coordinate system

  command format :
    G16...;           polar coordination
    G15...;           polar coordination cannel
=========================================================*/
static BOOL polar_command()
{    if (gPolar)
     {    nPolar=gPolar-15;
          CNC_polar.nx=CNC_nx; CNC_polar.ny=CNC_ny;
          local_to_absolute((LPAXIS)&CNC_lastX,(LPAXIS)&CNC_last);
     }
     gPolar=nPolar;
     return(FALSE);
}

/*=========================================================
  offset_command()                       (G-code group #18)
         offset compensation

  command format :
    G45...;           tool offset increase
    G46...;           tool offset decrease
    G47...;           tool offset double increase
    G48...;           tool offset double decrease
=========================================================*/
static BOOL offset_command()
{    if (gOffset) gOffset-=44;
     return(FALSE);
}

/*=========================================================
  data_command()                       (G-code group #19)
       data setting command

  command format :
    G10...;           data setting
*** G11...;           definition of G10 command
=========================================================*/
static BOOL data_command()
{    int index,array,n; char c;
     if (gData!=10) return(FALSE);
                                         /* data setting */
     index=(int)vL; array=(int)vP;
     for (n=0; n<25; n++)
     {    if (lpCmd->f[n]==0)     continue;
          if ((c='A'+n)>='G') c++;
          if ((c=='P')||(c=='L')) continue;
          set_G10_table(index,array,c,(double)(lpCmd->v[n]));
     }
     return(TRUE);
}


static BOOL skip_command()
{    if (fO) CNC_lead=0;
     if (CNC_lead && (PLC_status&bLeadSkip))  return(TRUE);
     if (gSkip    && (PLC_status&bBlockSkip)) return(TRUE);
     return(FALSE);
}


int ncode;
{    lpCmd->code=ncode;
     preset_calculation();
     scale_calculation();
     offset_calculation();
     stop_calculation();
}
                           /***** preset calculation *****/
static void preset_calculation()
{                                         /* code update */
     if (fD) CNC_Dcode=vD; else vD=CNC_Dcode;
     if (fH) CNC_Hcode=vH; else vH=CNC_Hcode;
     if (fM) CNC_Mcode=vM; else vM=CNC_Mcode;
     if (fO) CNC_Ocode=vO; else vO=CNC_Ocode;
     if (fT) CNC_Tcode=vT; else vT=CNC_Tcode;
                           /* preset cutter compensation */
     if (CNC_Hcode && nCut) lpCmd->xcut=CNC_Htable[CNC_Hcode];
     else                   lpCmd->xcut=0.L;
     if (nCut==2)           lpCmd->xcut=-lpCmd->xcut;
     lpCmd->ncut=1;    lpCmd->ycut=0.;
     lpCmd->nx=CNC_nx; lpCmd->ny=CNC_ny;
     lpCmd->start=lpCmd->stop=0;
     lpCmd->offset=aNull; lpCmd->tool=aNull;
                                 /* feedrate calculation */
     if (fF)
     {    if (fF==2)      CNC_Fcode=CNC_G01max*vF/100.;
          else if (gFeed)
          {    if (nUnit) CNC_Fcode=get_value_input('F',4)*CNC_Scode*INCH;
               else       CNC_Fcode=get_value_input('F',3)*CNC_Scode;
          } else
          {    if (nUnit) CNC_Fcode=get_value_input('F',4)*INCH;
               else       CNC_Fcode=get_value_input('F',3);
          }
     }
     vF=CNC_Fcode;
     if (vF<0.1) { vF=0.1; CNC_Fcode=0.1; }
                                    /* speed calculation */
     if (fS)
     {    if     (gSpeed)  CNC_Scode=get_value_input('S',nDot);
          else if (fS==2)  CNC_Scode=CNC_RPMmax*vS/100.;
          else             CNC_Scode=vS;
     } else
          vS=CNC_Scode;
     if (vS<0.1) { vS=0.1; CNC_Scode=0.1; }
}
                            /***** scale calculation *****/
static void scale_calculation()
{    if (lpCmd->code>=4) return;
     if (gScale)
     {    if (CNC_scalef.v[CNC_nx]<0.)
          {    if (lpCmd->xcut)   lpCmd->xcut= -(lpCmd->xcut);
               if (lpCmd->code>1) lpCmd->code=5-(lpCmd->code);
          }
          if (CNC_scalef.v[CNC_ny]<0.)
          {    if (lpCmd->xcut)   lpCmd->xcut= -(lpCmd->xcut);
               if (lpCmd->code>1) lpCmd->code=5-(lpCmd->code);
          }
     }
}
                           /***** offset calculation *****/

⌨️ 快捷键说明

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