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

📄 kkem.c

📁 非常重要的嵌入式单片机开发语言 是美国德州仪器的MSP430系列的系统语言4
💻 C
📖 第 1 页 / 共 4 页
字号:
               case 98 : case 99 :
                                     lpCmd->g[10]=n;  break;
               case 50 : case 51 :
                                     lpCmd->g[11]=n;  break;
               case 65 : case 66 : case 67 :
                                     lpCmd->g[12]=n;  break;
               case 96 : case 97 :
                                     lpCmd->g[13]=n;  break;
               case 54 : case 55 : case 56 : case 57 : case 58 :
               case 59 :             lpCmd->g[14]=n;  break;
               case 61 : case 62 : case 63 : case 64 :
                                     lpCmd->g[15]=n;  break;
               case 68 : case 69 :
                                     lpCmd->g[16]=n;  break;
               case 15 : case 16 :
                                     lpCmd->g[17]=n;  break;
               case 45 : case 46 : case 47 : case 48 :
                                     lpCmd->g[18]=n;  break;
               case 10 : case 11 :
                                     lpCmd->g[19]=n;  break;
               default :
                    if (n<20)      { lpCmd->g[20]=n;  break; }
                    if (n<80)      { lpCmd->g[21]=n;  break; }
                    if (n<100)     { lpCmd->g[22]=n;  break; }
                                     lpCmd->g[23]=n;  break;
               }
          }
     }
     return(FALSE);
}

/*=========================================================
  calling_command()                                (M-code)
          call subprogram command
          return TRUE if skip other command

  M98PxxxxLnnnn : call subprogram "Oxxxx.CNC" nnnn's times
  M99           : subprogram return
=========================================================*/
static BOOL calling_command()
{    if (!fM) return(FALSE);
     switch ((int)vM)
     {
     case 98 :                        /* call subprogram */
          if (open_CNC_file((int)vP)) CNC_stack[CNC_level].nloop=(int)vL;
          return(TRUE);
     case 99 :                         /* subroutine end */
          close_CNC_file();
          return(TRUE);
     default :                          /* others M code */
          break;
     }
     return(FALSE);
}

/*=========================================================
  MST_command()                                  (MST-code)
           execute M/S/T code command
           return TRUE if skip other command
=========================================================*/
static BOOL MST_command()
{    int n,m,s,t;
     if (!fM && !fS && !fT) return(FALSE);
                                           /* MST output */
     PATH_calculation(4);
     lpCmd->ratio=0.; lpCmd->dlt=1.;
     PATH_append();
                                      /* file control ?? */
     if (!fM) return(TRUE);
     switch ((int)vM)
     {
     case 1 :               /* M01 : program option stop */
          if (!(PLC_status&bOptionalStop)) break;
     case 0 :                      /* M00 : program stop */
     case 2 : case 30 :         /* M02/M30 : program end */
          clear_CNC_file();
/*          CNC_reset_process();
*/
          break;
     }
     return(TRUE);
}

/*=========================================================
  special_command()                      (G-code group #00)
        special command
=========================================================*/
static BOOL special_command()
{    int n,old; double t;
     switch (gOther)
     {
     case 4 :                        /* G04 : time delay */
          if (!fP && !fX) t=0.;
          else    if (fP) t=get_value_input('P',3);
          else            t=get_value_input('X',3);
          PATH_calculation(4);
          lpCmd->ratio=0.;
          lpCmd->dlt=(t>0.008L)?(0.008L/t):(1.L);
          PATH_append();
          return(TRUE);
     case 9 :                        /* G09 : exact stop */
          PATH_calculation(4);
          lpCmd->ratio=0.; lpCmd->dlt=1.;
          PATH_append();
          return(TRUE);
     case 27 :                   /* G27 : referece check */
          get_axis_absolute((LPAXIS)&aGoal);
          absolute_to_local((LPAXIS)&aGoal,(LPAXIS)&aGoalX);
          lpCmd->goal=aGoalX;       PATH_calculation(0);
          lpCmd->stop|=bReferCheck; PATH_append();
          CNC_lastX=aGoalX; CNC_last=aGoal;
          return(TRUE);
     case 28 :               /* G28 : return to referece */
          get_axis_absolute((LPAXIS)&aGoal);
          absolute_to_local((LPAXIS)&aGoal,(LPAXIS)&aGoalX);
          lpCmd->goal=aGoalX; PATH_calculation(0); PATH_append();
          lpCmd->goal=CNC_refer[0]; gWork=0; PATH_calculation(0);
          lpCmd->stop|=bReferCheck;          PATH_append();
          CNC_lastX=aGoalX; CNC_last=aGoal;
          return(TRUE);
     case 29 :               /* G29 : move from referece */
          lpCmd->goal=CNC_lastX; PATH_calculation(0); PATH_append();
          get_axis_absolute((LPAXIS)&aGoal);
          absolute_to_local((LPAXIS)&aGoal,(LPAXIS)&aGoalX);
          lpCmd->goal=aGoalX;    PATH_calculation(0); PATH_append();
          CNC_lastX=aGoalX; CNC_last=aGoal;
          return(TRUE);
     case 30 :        /* G30 : return to second referece */
          n=(int)vP; if (n<2 || n>4) n=2;
          get_axis_absolute((LPAXIS)&aGoal);
          absolute_to_local((LPAXIS)&aGoal,(LPAXIS)&aGoalX);
          lpCmd->goal=aGoalX; PATH_calculation(0); PATH_append();
          lpCmd->goal=CNC_refer[n]; gWork=0; PATH_calculation(0);
          lpCmd->stop|=bReferCheck;          PATH_append();
          CNC_lastX=aGoalX; CNC_last=aGoal;
          return(TRUE);
     case 33 :                   /* G33 : thread cutting */
          if (!fF)   { CNC_error=eDecode; return(TRUE);                 }
          if (nUnit) { CNC_Fcode=get_value_input('F',4)*CNC_Scode*INCH; }
          else       { CNC_Fcode=get_value_input('F',2)*CNC_Scode;      }
          fF=0;
          get_axis_absolute((LPAXIS)&aGoal);
          absolute_to_local((LPAXIS)&aGoal,(LPAXIS)&aGoalX);
          lpCmd->goal=aGoalX;        PATH_calculation(1);
          lpCmd->start|=bIndexCome;  PATH_append();
          CNC_lastX=aGoalX; CNC_last=aGoal;
          return(TRUE);
     case 52 :   /* G52 : set special working coordinate */
          get_axis_input(&CNC_local);
          return(TRUE);
     case 53 :              /* G53 : machine positioning */
          aGoal=CNC_last;
          absolute_to_machine((LPAXIS)&aGoal,(LPAXIS)&aGoalX);
          CNC_last=aGoalX;          old=nInc; nInc=0;
          get_axis_absolute((LPAXIS)&aGoalX); nInc=old;
          machine_to_absolute((LPAXIS)&aGoalX,(LPAXIS)&aGoal);
          absolute_to_local((LPAXIS)&aGoal,(LPAXIS)&aGoalX);
          lpCmd->goal=aGoalX; gTool=0; gOffset=0; nCut=0;
          PATH_calculation(1); PATH_append();
          CNC_lastX=aGoalX; CNC_last=aGoal;
          return(TRUE);
     case 60 :         /* G60 : fixed-direct positioning */
          get_axis_absolute((LPAXIS)&aGoal);
          absolute_to_local((LPAXIS)&aGoal,(LPAXIS)&aGoalX);
          for (n=0; n<PLC_axis; n++)
               lpCmd->goal.v[n]=aGoalX.v[n]-CNC_G60size.v[n];
          PATH_calculation(0); PATH_append();
          lpCmd->goal=aGoalX;
          PATH_calculation(0); PATH_append();
          CNC_lastX=aGoalX; CNC_last=aGoal;
          return(TRUE);
     case 92 :     /* G92X_Y_Z_ : set working coordinate */
          if (is_any_axis_exist())
          {    aNow=PLC_command;
               get_axis_absolute((LPAXIS)&aGoal);
               absolute_to_local((LPAXIS)&aGoal,(LPAXIS)&aGoalX);
               for (n=0; n<PLC_axis; n++)
                    CNC_working[0].v[n]=PLC_command.v[n]-CNC_local.v[n]
                                   -CNC_working[nWork].v[n]-aGoalX.v[n];
               CNC_lastX=aGoalX; CNC_last=aGoal;
          } else       /* G92 : update current position */
          {    aNow=PLC_command;
               machine_to_local((LPAXIS)&aNow,(LPAXIS)&aGoalX);
               local_to_absolute((LPAXIS)&aGoalX,(LPAXIS)&aGoal);
               CNC_lastX=aGoalX; CNC_last=aGoal;
          }
          return(TRUE);
     default :
          break;
     }
     return(FALSE);
}

/*=========================================================
  motion_command()                       (G-code group #01)
         motion command

  command format :
    G00...;           fast positioning
    G01...;           linear iterpolation
    G02...;           circle iterpolation (CW)
    G03...;           circle iterpolation (CCW)
=========================================================*/
static BOOL motion_command()
{    double r; CNCaxis_t a; point_t p0,p1,p2;
                                 /* nop if no parameters */
     if (!is_any_axis_exist() && !is_any_center_exist())
          return(FALSE);
                             /* collect block parameters */
     if (gMove) { gMove--; nMove=gMove; }
     else       {          gMove=nMove; }
     lpCmd->code=gMove;
     preset_calculation();
     scale_calculation();
     get_axis_absolute((LPAXIS)&aGoal);
     absolute_to_local((LPAXIS)&aGoal,(LPAXIS)&aGoalX);
     lpCmd->goal=aGoalX;
                                   /* center calculation */
     if (lpCmd->code>1)
     {    if (fR)                                   /* R */
          {    r=get_value_input('R',nDot);
               p1.x=CNC_lastX.v[CNC_nx]; p1.y=CNC_lastX.v[CNC_ny];
               p2.x=aGoalX.v[CNC_nx];    p2.y=aGoalX.v[CNC_ny];
               if (find_circle_center(&p1,&p2,r,lpCmd->code-2,&p0))
               {    lpCmd->xc=p0.x; lpCmd->yc=p0.y;
               } else
               {    CNC_error=eCenter;
                    return(TRUE);
               }
          } else                                /* I/J/K */
          {    if (!is_any_center_exist())
               {    CNC_error=eCenter;
                    return(TRUE);
               }
               get_center_absolute((LPAXIS)&aCenter);
               absolute_to_local((LPAXIS)&aCenter,(LPAXIS)&aCenterX);
               lpCmd->xc=aCenterX.v[CNC_nx]; lpCmd->yc=aCenterX.v[CNC_ny];
          }
     }
     offset_calculation();
     stop_calculation();
     PATH_append();
     CNC_last=aGoal; CNC_lastX=aGoalX;
     return(TRUE);
}

/*=========================================================
  plane_command()                        (G-code group #02)
        working plane system

  command format :
    G17...;           select (X/Y) plane
    G18...;           select (Z/X) plane
    G19...;           select (Y/Z) plane
=========================================================*/
static BOOL plane_command()
{    int i; char x,y,z;
     if (gPlane)
     {    nPlane=gPlane-17;
          for (i=0,x=0; i<2; i++)        /* check X axis */
               if (is_input_exist(CNC_Xmap[i]))
                    x=get_axis_number(CNC_Xmap[i]);
          for (i=0,y=1; i<2; i++)        /* check Y axis */
               if (is_input_exist(CNC_Ymap[i]))
                    y=get_axis_number(CNC_Ymap[i]);
          for (i=0,z=2; i<2; i++)        /* check Z axis */
               if (is_input_exist(CNC_Zmap[i]))
                    z=get_axis_number(CNC_Zmap[i]);
                                        /* plane setting */
          switch (nPlane)
          {
          case 0 : CNC_nx=x; CNC_ny=y; CNC_nz=z; break;
          case 1 : CNC_nx=z; CNC_ny=x; CNC_nz=y; break;
          case 2 : CNC_nx=y; CNC_ny=z; CNC_nz=x; break;
          }
                                    /* coordinate update */
          CNC_polar.nx=CNC_nx; CNC_polar.ny=CNC_ny;
          local_to_absolute((LPAXIS)&CNC_lastX,(LPAXIS)&CNC_last);
     }
     gPlane=nPlane;
     return(FALSE);
}

/*=========================================================
  absolute_command()                     (G-code group #03)
           absolute/incremental coordinate system

  command format :
    G90...;           absolute coordination
    G91...;           incremental coordination
=========================================================*/
static BOOL absolute_command()
{    if (gInc) nInc=gInc-90;
     gInc=nInc;
     return(FALSE);
}

/*=========================================================
  limit_command()                        (G-code group #04)
        software limit boundary setting

  command format :
    G22...;           limit boundary setting
    G23...;           limit boundary cancel
=========================================================*/
static BOOL limit_command()
{    if (gLimit)
     {    nLimit=23-gLimit;
          if (nLimit)
          {    get_axis_input(&CNC_limit2H);
               absolute_to_machine(&CNC_limit2H,&CNC_limit2H);
               get_center_input(&CNC_limit2L);
               absolute_to_machine(&CNC_limit2L,&CNC_limit2L);
          }
          gLimit=nLimit;
          return(TRUE);
     }
     gLimit=nLimit;
     return(FALSE);
}

/*=========================================================
  feed_command()                         (G-code group #05)
       feedrate unit system

  command format :
    G94...;           feed per minute
    G95...;           feed per rotation
=========================================================*/
static BOOL feed_command()
{    if (gFeed) nFeed=gFeed-94;
     gFeed=nFeed;
     return(FALSE);

⌨️ 快捷键说明

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