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

📄 maindlg.cpp

📁 激光加工控制系统 可以读入plt文件
💻 CPP
📖 第 1 页 / 共 4 页
字号:

  flag = 0;
  i = 0;
  while ((nbuf[i] != 'G')&&(nbuf[i] != 0))
    i ++;
  if (nbuf[i] == 0)
    flag = 1;
  else{
    type = atoi(&(nbuf[i+1]));
    if (type == 1){
      i = 0;
      while ((nbuf[i] != 'X')&&(nbuf[i] != 0))
	i ++;
      if (nbuf[i] == 0){
	n_x = e[0];
      }
      else{
	n_x = atof(&(nbuf[i+1]));
	n_x -= o_x;
      }
      i = 0;
      while ((nbuf[i] != 'Y')&&(nbuf[i] != 0))
	i ++;
      if (nbuf[i] == 0){
	n_y = e[1];
      }
      else{
	n_y = atof(&(nbuf[i+1]));
	n_y -= o_y;
      }

      df = ((e_x-b_x)*(e_x-b_x));
      df += ((e_y-b_y)*(e_y-b_y));
      l1 = sqrt(df);
      df = (n_x-e_x)*(n_x-e_x);
      df += (n_y-e_y)*(n_y-e_y);
      l2 = sqrt(df);
      df = (n_x-b_x)*(n_x-b_x);
      df += (n_y-b_y)*(n_y-b_y);
      l3 = sqrt(df);

      if (fabs(l3-l1-l2) < 0.001){
	an = PI;
      }
      else
	an = acos((l1*l1+l2*l2-l3*l3)/(2*l1*l2));

      if (an < 5*PI/8)
	flag = 1;
    }
    else
     flag = 1;
  }
/*
  if (sub_flag == 1)
    add_flag = 1;
  else
    add_flag = 0;
  if (flag == 1)
    sub_flag = 1;
  else
    sub_flag = 0;
*/
  if (fabs(e_x)+fabs(e_y) < 0.001)
    i = 0;
  times[0] = times[1] = 0;

  for (i=0;i<2;i++){
    all_ps = (long)(fabs(e[i] - b[i])*pulses_per_unit[i]+0.5);
    ps[i] = all_ps;
  }
/*
  fprintf(tar_fpe,"P%f %f\n",ps[0],ps[1]);
  x_ps += ps[0];
  y_ps += ps[1];
  return 1;
*/
  ll = 0;
  p = 0;
  if (ps[0]*pulses_per_unit[1] > ps[1]*pulses_per_unit[0]){
	  ll = ps[0];
	  p = 0;
  }
  else{
	  ll = ps[1];
	  p = 1;
  }
/*
  for (i=0;i<2;i++){
    if (ll < ps[i]){
      ll = ps[i];
      p = i;
    }
  }
*/

  i = p;
  flag = 0;
  df = (e[0]-b[0])*(e[0]-b[0]);
  df += (e[1]-b[1])*(e[1]-b[1]);
  df = sqrt(df);
  r_p = vmax*fabs(e[i]-b[i])/df;
  all_ps = ps[i];

//  if (all_ps == 0)
//	  i = 0;
  s = 0;
  v = 0;
  a = acc[i];
  a_times = 0;
  while (flag == 0){
    if (v+a > r_p)
      flag = 1;
    else{
      v += a;
      s += v;
      a_buf[a_times] = v;
      a_times ++;
    }
  }

  a_s_ps = 0;
  if (add_flag == 1)
    a_s_ps += s;
  if (sub_flag == 1)
    a_s_ps += s;
  if ((add_flag == 0)&&(sub_flag == 0)&&
	  (fabs(e[1] - b[1]) < 0.005)&&(dk_flag)){
    if (e[0] > b[0])
      x = ps[0];
	else
	  x = -ps[0];
    y = 0;
	spds = r_p;
    put2();
  }
  else{
  old_x_ps = x_ps;
  old_y_ps = y_ps;
  
  if (all_ps > a_s_ps + 4*r_p){
    a_s_ps = 0;
    if (add_flag == 1){
      for (j=0;j<a_times;j++){
	putxy(i,a_buf[j]);
      }
      a_s_ps += s;
    }
    if (sub_flag == 1){
      a_s_ps += s;
    }

    run_ps = all_ps - a_s_ps;
    if ((r_p == 0)&&(abs(all_ps) > 0))
		r_p = 1;
    if (r_p == 0){
      putxy(i,all_ps);
    }
    else{
      num = run_ps / r_p;
      left = run_ps % r_p;
      aver_add = left / num;
      left_add = left % num;
      for (j=0;j<num;j++){
	if (j < left_add)
	  putxy(i,r_p + aver_add + 1);
	else
	  putxy(i,r_p + aver_add);
      }

      if (sub_flag == 1){
	for (j=a_times-1;j>=0;j--){
	  putxy(i,a_buf[j]);
	}
      }
    }
  }
  else if ((add_flag == 1)||(sub_flag == 1)){
    if ((add_flag == 1)&&(sub_flag == 1)){
      half_ps = all_ps / 2;
      if (half_ps > s){
	left = half_ps - s;
	num = left / r_p;
	left_add = left % r_p;
	k = 0;
	for (j=0;j<a_times;j++){
	  if (j == 0){
	    if (left_add < a_buf[0]){
	      putxy(i,left_add);
	      b_buf[k++] = left_add;
	    }
	    putxy(i,a_buf[j]);
	    b_buf[k++] = a_buf[j];
	  }
	  else if (j == a_times-1){
		if ((left_add >= a_buf[j-1]) && (left_add <= a_buf[j])){
	      putxy(i,left_add);
	      b_buf[k++] = left_add;
	      putxy(i,a_buf[j]);
	      b_buf[k++] = a_buf[j];
        }
		else if (left_add >= a_buf[j]){
	      putxy(i,a_buf[j]);
	      b_buf[k++] = a_buf[j];
	      putxy(i,left_add);
	      b_buf[k++] = left_add;
	    }
		else{
	      putxy(i,a_buf[j]);
	      b_buf[k++] = a_buf[j];
        }
	  }
	  else if ((left_add >= a_buf[j-1]) && (left_add <= a_buf[j])){
	    putxy(i,left_add);
	    b_buf[k++] = left_add;
	    putxy(i,a_buf[j]);
	    b_buf[k++] = a_buf[j];
	  }
	  else{
	    putxy(i,a_buf[j]);
	    b_buf[k++] = a_buf[j];
	  }
	}

    for (j=0;j<2*num;j++)
	  putxy1(i,r_p);

	for (m=k-1;m>=0;m--){
	  if (m == 0){
	    if (all_ps % 2 == 1)
	      putxy(i,b_buf[m]+1);
	    else
	      putxy(i,b_buf[m]);
	  }
	  else
	    putxy(i,b_buf[m]);
	}
      }
      else{
	m = 0;
	k = 0;
	flag = 0;
	while (flag == 0){
	  if (m + a_buf[k] > half_ps){
	    flag = 1;
	  }
	  else{
	    m += a_buf[k];
	    k ++;
	  }
	}
	left = half_ps - m;
	if (k == 0){
	  putxy(i,all_ps);
	}
	else{
	  aver_add = left / k;
	  left_add = left % k;
	  m = 0;
	  for (j=0;j<k;j++){
	    if (j < left_add){
	      putxy(i,a_buf[j]+aver_add+1);
	      b_buf[m++] = a_buf[j]+aver_add+1;
	    }
	    else{
	      putxy(i,a_buf[j]+aver_add);
	      b_buf[m++] = a_buf[j]+aver_add;
	    }
	  }

	  for (k=m-1;k>=0;k--){
	    if (k == 0){
	      if (all_ps % 2 == 1)
		putxy(i,b_buf[k]+1);
	      else
		putxy(i,b_buf[k]);
	    }
	    else
	      putxy(i,b_buf[k]);
	  }
	}
      }
    }
    else if ((add_flag == 1)&&(sub_flag == 0)){
      if (all_ps > s){
	left = all_ps - s;
	num = left / r_p;
	left = left % r_p;
	if (a_times == 0){
	  putxy(i,left);
	  for (j=0;j<num;j++)
	    putxy1(i,r_p);
	}
	else{
	  aver_add = left / a_times;
	  left_add = left % a_times;
	  for (j=0;j<a_times;j++){
	    if (j < left_add)
	      putxy(i,a_buf[j]+aver_add+1);
	    else
	      putxy(i,a_buf[j]+aver_add);
	  }
	  for (j=0;j<num;j++)
	    putxy1(i,r_p);
	}
      }
      else{
	m = 0;
	k = 0;
	flag = 0;
	while (flag == 0){
	  if (m + a_buf[k] > all_ps){
	    flag = 1;
	  }
	  else{
	    m += a_buf[k];
	    k ++;
	  }
	}
	left = all_ps - m;
	if (k == 0){
	  putxy(i,all_ps);
	}
	else{
	  if (left > a_buf[k-1]){
		  a_buf[k] = left;
		  left = 0;
		  k ++;
	  }
	  aver_add = left / k;
	  left_add = left % k;
	  m = 0;
	  for (j=0;j<k;j++){
	    if (j < left_add)
	      putxy(i,a_buf[j]+aver_add+1);
	    else
	      putxy(i,a_buf[j]+aver_add);
	  }
	}
      }
    }
    else if ((add_flag == 0)&&(sub_flag == 1)){
      if (all_ps > s){
	left = all_ps - s;
	num = left / r_p;
	left = left % r_p;
	if (a_times == 0){
	  for (j=0;j<num;j++)
	    putxy1(i,r_p);
	  putxy(i,left);
	}
	else{
	  aver_add = left / a_times;
	  left_add = left % a_times;
	  for (j=0;j<num;j++)
	    putxy1(i,r_p);
	  for (j=a_times-1;j>=0;j--){
	    if (j < left_add)
	      putxy(i,a_buf[j]+aver_add+1);
	    else
	      putxy(i,a_buf[j]+aver_add);
	  }
	}
      }
      else{
	m = 0;
	k = 0;
	flag = 0;
	while (flag == 0){
	  if (m + a_buf[k] > all_ps){
	    flag = 1;
	  }
	  else{
	    m += a_buf[k];
	    k ++;
	  }
	}
	left = all_ps - m;
	if (k == 0){
	  putxy(i,all_ps);
	}
	else{
	  aver_add = left / k;
	  left_add = left % k;
	  m = 0;
	  for (j=k-1;j>=0;j--){
	    if (j < left_add)
	      putxy(i,a_buf[j]+aver_add+1);
	    else
	      putxy(i,a_buf[j]+aver_add);
	  }
	}
      }

    }
  }
  else{
    if ((r_p == 0)&&(abs(all_ps) > 0))
		r_p = 1;
    if (r_p == 0){
      putxy(i,all_ps);
    }
    else{
      num = all_ps / r_p;
      left = all_ps % r_p;
      if (num == 0){
	putxy(i,all_ps);
      }
      else{
	aver_add = left / num;
	left_add = left % num;
	for (j=0;j<num;j++){
	  if (j < left_add)
	    putxy1(i,r_p + aver_add + 1);
	  else
	    putxy1(i,r_p + aver_add);
	}
      }
    }
  }
  if (sub_flag == 1){
    putxy(i,0);
  }

  if (fabs(fabs(x_ps - old_x_ps) + fabs(y_ps - old_y_ps) - ps[0] - ps[1]) > 0.5){
    if (e[0] - b[0] < 0)
		ps[0] = -ps[0];
    if (e[1] - b[1] < 0)
		ps[1] = -ps[1];
	int t1,t2;
    t1 = ps[0] - (x_ps - old_x_ps);
    t2 = ps[1] - (y_ps - old_y_ps);
    fprintf(tar_fpe,"P%d %d\n",t1,t2);
	x_ps += t1;
	y_ps += t2;
  }  
  }
  return 1;

}



put1()
{
  int i;

  strcpy(buf1,"P");
  itoa(x,buf2,10);
  strcat(buf1,buf2);
  itoa(y,buf2,10);
  strcat(buf1," ");
  strcat(buf1,buf2);
  put_a_line_to_tar_fpe(buf1);
  x_ps += x;
  y_ps += y;
  return 1;
}

put2()
{
  int i;

  if ((y == 0)&&(dk_flag == 1)){
    strcpy(buf1,"B");
    itoa(x,buf2,10);
    strcat(buf1,buf2);
    itoa(y,buf2,10);
    strcat(buf1," ");
    strcat(buf1,buf2);
    itoa(spds,buf2,10);
    strcat(buf1," ");
    strcat(buf1,buf2);
    put_a_line_to_tar_fpe(buf1);
    x_ps += x;
    y_ps += y;
  }
  else{
    strcpy(buf1,"P");
    itoa(x,buf2,10);
    strcat(buf1,buf2);
    itoa(y,buf2,10);
    strcat(buf1," ");
    strcat(buf1,buf2);
    put_a_line_to_tar_fpe(buf1);
    x_ps += x;
    y_ps += y;
  }
  return 1;
}

putxy(int i,int num)
{
/*
  if (i == 0){
    x = num;
    if (e[0] < b[0])
      x = -x;
	if (bb_y/xyrate+(x_ps+x-bb_x)*(e[1]-b[1])/((e[0]-b[0])/xyrate)-y_ps > 0)
      y = bb_y/xyrate+(x_ps+x-bb_x)*(e[1]-b[1])/((e[0]-b[0])*xyrate)-y_ps + 0.5;
	else
      y = bb_y/xyrate+(x_ps+x-bb_x)*(e[1]-b[1])/((e[0]-b[0])*xyrate)-y_ps - 0.5;
  }
  if (i == 1){
    y = num;
    if (e[1] < b[1])
      y = -y;
	if (xyrate*bb_x+xyrate*(y_ps+y-bb_y)*(e[0]-b[0])/(e[1]-b[1])-x_ps > 0)
      x = xyrate*bb_x+xyrate*(y_ps+y-bb_y)*(e[0]-b[0])/(e[1]-b[1])-x_ps+0.5;
	else
      x = xyrate*bb_x+xyrate*(y_ps+y-bb_y)*(e[0]-b[0])/(e[1]-b[1])-x_ps-0.5;
  }
  put1();
*/
  if (i == 0){
    x = num;
    if (e[0] < b[0])
      x = -x;
	if (bb_y+(x_ps+x-bb_x)*(e[1]-b[1])/((e[0]-b[0]))-y_ps > 0)
      y = (bb_y+(x_ps+x-bb_x)*(e[1]-b[1])/((e[0]-b[0]))-y_ps)/xyrate + 0.5;
	else
      y = (bb_y+(x_ps+x-bb_x)*(e[1]-b[1])/((e[0]-b[0]))-y_ps)/xyrate - 0.5;
  }
  if (i == 1){
    y = num;
    if (e[1] < b[1])
      y = -y;
	if (bb_x+(y_ps+y-bb_y)*(e[0]-b[0])/(e[1]-b[1])-x_ps > 0)
      x = (bb_x+(y_ps+y-bb_y)*(e[0]-b[0])/(e[1]-b[1])-x_ps)*xyrate+0.5;
	else
      x = (bb_x+(y_ps+y-bb_y)*(e[0]-b[0])/(e[1]-b[1])-x_ps)*xyrate-0.5;
  }
  put1();
}

putxy1(int i,int num)
{
  if (i == 0){
    x = num;
    if (e[0] < b[0])
      x = -x;
    y = (bb_y+(x_ps+x-bb_x)*(e[1]-b[1])/(e[0]-b[0])-y_ps)/xyrate;
  }
  if (i == 1){
    y = num;
    if (e[1] < b[1])
      y = -y;
    x = (bb_x+(y_ps+y-bb_y)*(e[0]-b[0])/(e[1]-b[1])-x_ps)*xyrate;
  }
  if (y != 0)
    put1();
  else{
    spds = r_p;
    put2();
  }
}

BOOL maindlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class

	return CDialog::DestroyWindow();
}

test_dog()
{
	if (quit_flag == 1){
      exit(-1);
	}
}

⌨️ 快捷键说明

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