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

📄 t.c

📁 激光加工控制系统 可以读入plt文件
💻 C
📖 第 1 页 / 共 2 页
字号:
	put_a_line(to_file,buf1);
	oldx += x/xsteps;
	oldy += y/ysteps;
	len5 = speed/xsteps+len4/i;
	len1 += len5;
	speed -= x_once_max_a_pulses;
      }
    }
  }
  else{
    len3 = len/2;
    len2 = 0;
    speed = 0;
    i = 0;
    while (len2 < len3){
      speed += x_once_max_a_pulses;
      len2 += speed/xsteps;
      i ++;
    }
    len2 -= speed/xsteps;
    len4 = len3 - len2;
    i --;
    len1 = 0;
    speed1 = speed-x_once_max_a_pulses;
    speed = 0;
    if (i == 0){
      curx = (b_x+e_x)/2;
      cury = (b_y+e_y)/2;
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
      strcpy(buf1,"P");
      itoa(x,buf2,10);
      strcat(buf1,buf2);
      itoa(y,buf2,10);
      strcat(buf1," ");
      strcat(buf1,buf2);
      put_a_line(to_file,buf1);
      oldx += x/xsteps;
      oldy += y/ysteps;
    }
    else{
      for (j=0;j<i;j++){
	speed += x_once_max_a_pulses;
	if (j == i-1){
	  curx = (b_x+e_x)/2;
	  cury = (b_y+e_y)/2;
	}
	else{
	  curx = b_x + (e_x-b_x)*(len1+speed/xsteps+len4/i)/len;
	  cury = b_y + (e_y-b_y)*(len1+speed/xsteps+len4/i)/len;
	}
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
	strcpy(buf1,"P");
	itoa(x,buf2,10);
	strcat(buf1,buf2);
	itoa(y,buf2,10);
	strcat(buf1," ");
	strcat(buf1,buf2);
	put_a_line(to_file,buf1);
	oldx += x/xsteps;
	oldy += y/ysteps;
	len5 = speed/xsteps+len4/i;
	len1 += len5;
      }
    }

    speed = speed1;
    if (i == 0){
      curx = e_x;
      cury = e_y;
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
      strcpy(buf1,"P");
      itoa(x,buf2,10);
      strcat(buf1,buf2);
      itoa(y,buf2,10);
      strcat(buf1," ");
      strcat(buf1,buf2);
      put_a_line(to_file,buf1);
      oldx += x/xsteps;
      oldy += y/ysteps;
    }
    else{
      for (j=0;j<i;j++){
	if (j == i-1){
	  curx = e_x;
	  cury = e_y;
	}
	else{
	  curx = b_x + (e_x-b_x)*(len1+speed/xsteps+len4/i)/len;
	  cury = b_y + (e_y-b_y)*(len1+speed/xsteps+len4/i)/len;
	}
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
	strcpy(buf1,"P");
	itoa(x,buf2,10);
	strcat(buf1,buf2);
	itoa(y,buf2,10);
	strcat(buf1," ");
	strcat(buf1,buf2);
	put_a_line(to_file,buf1);
	oldx += x/xsteps;
	oldy += y/ysteps;
	len5 = speed/xsteps+len4/i;
	len1 += len5;
	speed -= x_once_max_a_pulses;
      }
    }
  }
 oldx = e_x;
  oldy = e_y;
//  put_a_line(to_file,"P0 0");
}

proc_circ(int b_p,FILE *to_file,int type)
{
  float I,J,cx,cy,r,vmax,amax,curx,cury;
  float ba,ea,an,ll,len,angle,xx,yy;
  float len1,len2,len3,len4,len5,aa;
  float speed,speed1,dan,f;
  int x,y;
  unsigned char buf1[20],buf2[20];
  int s,s1,s2;
  int i,j,times;
  unsigned char chbak;

//  strcpy(buf1,"P0 0");
  put_a_line(to_file,buf1);
  b_x = oldx;
  b_y = oldy;
  I = oldi;
  J = oldj;
  if (buf[b_p] == 'X'){
    i = b_p + 1;
    while ((buf[i] != 'Y')&&(buf[i] != 'I')&&(buf[i] != 'J')&&(buf[i] != 0))
      i ++;
    if (buf[i] != 0){
      chbak = buf[i];
      buf[i] = 0;
    }
    e_x = atof(&(buf[b_p+1]));
    e_x -= o_x;
    buf[i] = chbak;
    i = b_p + 1;
    while ((buf[i] != 'Y')&&(buf[i] != 0))
      i ++;
    if (buf[i] == 'Y'){
      j = b_p + 1;
      while ((buf[j] != 'I')&&(buf[j] != 'J')&&(buf[i] != 0))
	j ++;
      if (buf[j] != 0){
	chbak = buf[j];
	buf[j] = 0;
      }
      e_y = atof(&(buf[i+1]));
      e_y -= o_y;
      buf[j] = chbak;
    }
    else{
      e_y = b_y;
    }
  }
  else{
    e_x = b_x;
    e_y = atof(&(buf[b_p+1]));
    e_y -= o_y;
  }

  i = b_p + 1;
  while ((buf[i] != 'I')&&(buf[i] != 0))
    i ++;
  if (buf[i] == 'I'){
    j = b_p + 1;
    while ((buf[j] != 'J')&&(buf[i] != 0))
      j ++;
    if (buf[j] != 0){
      chbak = buf[j];
      buf[j] = 0;
    }
    I = atof(&(buf[i+1]));
    buf[j] = chbak;
  }
  else
    I = oldi;

  i = b_p + 1;
  while ((buf[i] != 'J')&&(buf[i] != 0))
    i ++;
  if (buf[i] == 'J'){
    J = atof(&(buf[i+1]));
  }
  else
    J = oldj;

  cx = I + b_x;
  cy = J + b_y;

  r = sqrt((b_x-cx)*(b_x-cx)+(b_y-cy)*(b_y-cy));
  vmax = x_once_max_v_pulses;
  amax = x_once_max_a_pulses;
  oldx = curx = b_x;
  oldy = cury = b_y;
  ba = count_angle(cx,cy,b_x,b_y);
  ea = count_angle(cx,cy,e_x,e_y);
  if (type == 2){
    if (ba > ea)
      aa = (ba+ea)/2;
    else{
      aa = (ba + 2*PI - ea)/2;
      if (aa < 0)
	aa += 2*PI;
    }
  }
  else{
    if (ea > ba){
      aa = (ba+ea)/2;
    }
    else{
      aa = (ea + 2*PI - ba)/2;
      if (aa < 0)
	aa += 2*PI;
    }
  }
  an = ba;
  ll = x_len_to_acc/xsteps;
  if (ba > ea){
    len = r*(ba-ea);
  }
  else{
    len = r*(ba + 2*PI - ea);
  }
  if (type == 3)
    len = r*2*PI - len;
  if ((fabs(ba-ea) < 0.0001) || (fabs(fabs(ba-ea)-2*PI) < 0.0001))
    len = r*2*PI;

  if (len > 2*x_len_to_acc/xsteps){
    speed = 0;
    oldx = curx = b_x;
    oldy = cury = b_y;
    len1 = 0;
    while (len1 < len - x_len_to_acc/xsteps){
      if (speed < vmax)
	speed += x_once_max_a_pulses;
      else
	speed = vmax;
      len5 = speed/xsteps;
      dan = len5/r;

      an = count_angle(cx,cy,oldx,oldy);

      if (type == 2){
	an -= dan;
	if (an < 0)
	  an += 2*PI;
      }
      else{
	an += dan;
	if (an > 2*PI)
	  an -= 2*PI;
      }

      curx = cx + r*cos(an);
      cury = cy + r*sin(an);
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
      strcpy(buf1,"P");
      itoa(x,buf2,10);
      strcat(buf1,buf2);
      itoa(y,buf2,10);
      strcat(buf1," ");
      strcat(buf1,buf2);
      put_a_line(to_file,buf1);
      oldx += x/xsteps;
      oldy += y/ysteps;
      len1 += dan*r;
    }
    len3 = len - len1;
    i = 0;
    len2 = 0;
    speed = 0;
    while (len2 < len3){
      speed += x_once_max_a_pulses;
      len2 += speed/xsteps;
      i ++;
    }
    len2 -= speed/xsteps;
    len4 = len3 - len2;
    speed -= x_once_max_a_pulses;
    i --;
    if (i == 0){
      curx = e_x;
      cury = e_y;
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
      strcpy(buf1,"P");
      itoa(x,buf2,10);
      strcat(buf1,buf2);
      itoa(y,buf2,10);
      if (fabs(x+17) < 0.1)
	x = -17;
      strcat(buf1," ");
      strcat(buf1,buf2);
      put_a_line(to_file,buf1);
      oldx += x/xsteps;
      oldy += y/ysteps;
    }
    else{
      for (j=0;j<i;j++){
	if (j == i-1){
	  curx = e_x;
	  cury = e_y;
	}
	else{
	  len5 = speed/xsteps+len4/i;
	  dan = len5/r;

	  an = count_angle(cx,cy,oldx,oldy);

	  if (type == 2){
	    an -= dan;
	    if (an < 0)
	      an += 2*PI;
	  }
	  else{
	    an += dan;
	    if (an > 2*PI)
	      an -= 2*PI;
	  }

	  curx = cx + r*cos(an);
	  cury = cy + r*sin(an);
	}
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
	strcpy(buf1,"P");
	itoa(x,buf2,10);
	strcat(buf1,buf2);
	itoa(y,buf2,10);
	strcat(buf1," ");
	strcat(buf1,buf2);
	put_a_line(to_file,buf1);
	oldx += x/xsteps;
	oldy += y/ysteps;
	len1 += sqrt((float)x*x/(xsteps*xsteps)+(float)y*y/(ysteps*ysteps));
	speed -= x_once_max_a_pulses;
      }
    }
  }
  else{
    len3 = len/2;
    len2 = 0;
    speed = 0;
    i = 0;
    while (len2 < len3){
      speed += x_once_max_a_pulses;
      len2 += speed/xsteps;
      i ++;
    }
    len2 -= speed/xsteps;
    len4 = len3 - len2;
    i --;
    len1 = 0;
    speed1 = speed-x_once_max_a_pulses;
    speed = 0;
    if (i == 0){
      curx = cx + r*cos(aa);
      cury = cy + r*sin(aa);
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
      strcpy(buf1,"P");
      itoa(x,buf2,10);
      strcat(buf1,buf2);
      itoa(y,buf2,10);
      strcat(buf1," ");
      strcat(buf1,buf2);
      put_a_line(to_file,buf1);
      oldx += x/xsteps;
      oldy += y/ysteps;
    }
    else{
      for (j=0;j<i;j++){
	speed += x_once_max_a_pulses;
	if (j == i-1){
	  curx = cx + r*cos(aa);
	  cury = cy + r*sin(aa);
	}
	else{
	  len5 = speed/xsteps+len4/i;
	  dan = len5/r;

	  an = count_angle(cx,cy,oldx,oldy);

	  if (type == 2){
	    an -= dan;
	    if (an < 0)
	      an += 2*PI;
	  }
	  else{
	    an += dan;
	    if (an > 2*PI)
	      an -= 2*PI;
	  }

	  curx = cx + r*cos(an);
	  cury = cy + r*sin(an);
	}
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
	strcpy(buf1,"P");
	itoa(x,buf2,10);
	strcat(buf1,buf2);
	itoa(y,buf2,10);
	strcat(buf1," ");
	strcat(buf1,buf2);
	put_a_line(to_file,buf1);
	oldx += x/xsteps;
	oldy += y/ysteps;
	len1 += sqrt((float)x*x/(xsteps*xsteps)+(float)y*y/(ysteps*ysteps));
      }
    }

    speed = speed1;
    if (i == 0){
      curx = e_x;
      cury = e_y;
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
      strcpy(buf1,"P");
      itoa(x,buf2,10);
      strcat(buf1,buf2);
      itoa(y,buf2,10);
      strcat(buf1," ");
      strcat(buf1,buf2);
      put_a_line(to_file,buf1);
      oldx += x/xsteps;
      oldy += y/ysteps;
    }
    else{
      for (j=0;j<i;j++){
	if (j == i-1){
	  curx = e_x;
	  cury = e_y;
	}
	else{
	  len5 = speed/xsteps+len4/i;
	  dan = len5/r;

	  an = count_angle(cx,cy,oldx,oldy);

	  if (type == 2){
	    an -= dan;
	    if (an < 0)
	      an += 2*PI;
	  }
	  else{
	    an += dan;
	    if (an > 2*PI)
	      an -= 2*PI;
	  }

	  curx = cx + r*cos(an);
	  cury = cy + r*sin(an);
	}
      f = (curx - oldx)*xsteps;
      if (f > 0)
	x = f + 0.5;
      else
	x = f - 0.5;
      f = (cury - oldy)*ysteps;
      if (f > 0)
	y = f + 0.5;
      else
	y = f - 0.5;
	strcpy(buf1,"P");
	itoa(x,buf2,10);
	strcat(buf1,buf2);
	itoa(y,buf2,10);
	strcat(buf1," ");
	strcat(buf1,buf2);
	put_a_line(to_file,buf1);
	oldx += x/xsteps;
	oldy += y/ysteps;
	len1 += sqrt((float)x*x/(xsteps*xsteps)+(float)y*y/(ysteps*ysteps));
	speed -= x_once_max_a_pulses;
      }
    }
  }

  oldi = I;
  oldj = J;
//  strcpy(buf1,"P0 0");
//  put_a_line(to_file,buf1);
}

float count_angle(float x0, float y0, float x1, float y1)
{
  float a;

  if ((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0) < 1e-8)
    return 0;
  a = acos((x1-x0)/sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)));
  if (y1 < y0)
    a = 2*PI - a;
  return a;
}

recover_data()
{
  int i;

  xmaxv = xmaxv3;
  ymaxv = ymaxv3;
//  test_dog();
  zmaxv = zmaxv3;
  xmaxa = xmaxa3;
  ymaxa = ymaxa3;
  zmaxa = zmaxa3;
  xmaxv1 = xmaxv;               // Max Speed units(G CODE) per danwei
  ymaxv1 = ymaxv;
  x_once_max_v_pulses = xmaxv*xsteps*interval/(1000.0);
  y_once_max_v_pulses = ymaxv*ysteps*interval/(1000.0);
  if (danwei == MINUTES){
    x_once_max_v_pulses /= 60.0;
    y_once_max_v_pulses /= 60.0;
  }
  x_times = x_once_max_v_pulses/x_once_max_a_pulses;
  if (x_times <= 0)
    x_times = 1;
  x_len_to_acc = 0;
  for (i=0;i<x_times;i++){
    x_len_to_acc += (i+1)*x_once_max_a_pulses;
  }
  y_times = y_once_max_v_pulses/y_once_max_a_pulses;
  if (y_times <= 0)
    y_times = 1;
  y_len_to_acc = 0;
  for (i=0;i<y_times;i++){
    y_len_to_acc += (i+1)*y_once_max_a_pulses;
  }
}

set_data()
{
  int i;

  xmaxv3 = xmaxv;
  ymaxv3 = ymaxv;
  zmaxv3 = zmaxv;
  xmaxa3 = xmaxa;
  ymaxa3 = ymaxa;
  zmaxa3 = zmaxa;
  xmaxv = xmaxv2;
  ymaxv = ymaxv2;
  zmaxv = zmaxv2;
  xmaxa = xmaxa2;
  ymaxa = ymaxa2;
  zmaxa = zmaxa2;
  xmaxv1 = xmaxv;               // Max Speed units(G CODE) per danwei
  ymaxv1 = ymaxv;
  x_once_max_v_pulses = xmaxv*xsteps*interval/(1000.0);
  y_once_max_v_pulses = ymaxv*ysteps*interval/(1000.0);
  if (danwei == MINUTES){
    x_once_max_v_pulses /= 60.0;
    y_once_max_v_pulses /= 60.0;
  }
  x_times = x_once_max_v_pulses/x_once_max_a_pulses;
  if (x_times <= 0)
    x_times = 1;
  x_len_to_acc = 0;
  for (i=0;i<x_times;i++){
    x_len_to_acc += (i+1)*x_once_max_a_pulses;
  }
  y_times = y_once_max_v_pulses/y_once_max_a_pulses;
  if (y_times <= 0)
    y_times = 1;
  y_len_to_acc = 0;
  for (i=0;i<y_times;i++){
    y_len_to_acc += (i+1)*y_once_max_a_pulses;
  }
}

⌨️ 快捷键说明

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