📄 tmac2.bak
字号:
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
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);
}
else{
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);
}
}
times = (int)((len - 2*ll)*xsteps/vmax);
for (i=0;i<times;i++){
strcpy(buf1,"P");
angle = vmax/(r*xsteps);
if (type == 2){
an -= angle;
if (an < 0)
an += 2*PI;
}
else{
an += angle;
if (an > 2*PI)
an -= 2*PI;
}
curx = cx + r*cos(an);
cury = cy + r*sin(an);
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
if (((oldxx > 0)&&(x < 0))||((oldxx < 0)&&(x > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
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);
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
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);
}
else{
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);
}
}
for (i=0;i<x_times;i++){
strcpy(buf1,"P");
if (s2 > 0){
if (s2 > 1){
angle = ((x_times - i)*x_once_max_a_pulses+2)/(r*xsteps);
s2 -= 2;
}
else{
angle = ((x_times - i)*x_once_max_a_pulses+1)/(r*xsteps);
s2 --;
}
}
else
angle = (x_times - i)*x_once_max_a_pulses/(r*xsteps);
if (type == 2){
an -= angle;
if (an < 0)
an += 2*PI;
}
else{
an += angle;
if (an > 2*PI)
an -= 2*PI;
}
if (i == x_times-1)
an = ea;
curx = cx + r*cos(an);
cury = cy + r*sin(an);
if (i == x_times-1){
an = ea;
curx = e_x;
cury = e_y;
}
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
if (((oldxx > 0)&&(x < 0))||((oldxx < 0)&&(x > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
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);
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
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);
}
else{
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);
}
}
}
else{
if (len < x_once_max_a_pulses/xsteps){
oldx = b_x;
oldy = b_y;
curx = e_x;
cury = e_y;
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
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);
}
else if (len < 2*x_once_max_a_pulses/xsteps){
oldx = b_x;
oldy = b_y;
an = count_angle(cx,cy,(b_x+e_x)/2,(b_y+e_y)/2);
curx = cx + r*cos(an);
cury = cy + r*sin(an);
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
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);
curx = e_x;
cury = e_y;
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
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);
}
else{
len /= 2;
times = 0;
ll = 0;
while (ll < len){
times ++;
ll += times*x_once_max_a_pulses/xsteps;
}
ll -= times*x_once_max_a_pulses/xsteps;
times --;
s1 = s2 = (len - ll)*xsteps;
for (i=0;i<times;i++){
strcpy(buf1,"P");
if (s1 > 0){
if (s1 > 1){
angle = ((i+1)*x_once_max_a_pulses+2)/(r*xsteps);
s1 -= 2;
}
else{
angle = ((i+1)*x_once_max_a_pulses+1)/(r*xsteps);
s1 --;
}
}
else
angle = (i+1)*x_once_max_a_pulses/(r*xsteps);
if (type == 2){
an -= angle;
if (an < 0)
an += 2*PI;
}
else{
an += angle;
if (an > 2*PI)
an -= 2*PI;
}
curx = cx + r*cos(an);
cury = cy + r*sin(an);
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
if (((oldxx > 0)&&(x < 0))||((oldxx < 0)&&(x > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
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);
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
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);
}
else{
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);
}
}
for (i=0;i<times;i++){
strcpy(buf1,"P");
if (s2 > 0){
if (s2 > 1){
angle = ((times - i)*x_once_max_a_pulses+2)/(r*xsteps);
s2 -= 2;
}
else{
angle = ((times - i)*x_once_max_a_pulses+1)/(r*xsteps);
s2 --;
}
}
else
angle = (times - i)*x_once_max_a_pulses/(r*xsteps);
if (type == 2){
an -= angle;
if (an < 0)
an += 2*PI;
}
else{
an += angle;
if (an > 2*PI)
an -= 2*PI;
}
if (i == times-1)
an = ea;
curx = cx + r*cos(an);
cury = cy + r*sin(an);
if (i == times-1){
an = ea;
curx = e_x;
cury = e_y;
}
xx = (curx - oldx)*xsteps;
yy = (cury - oldy)*ysteps;
oldx = curx;
oldy = cury;
if (xx > 0)
x = xx + x_adj + 0.5;
else
x = xx + x_adj - 0.5;
if (yy > 0)
y = yy + y_adj + 0.5;
else
y = yy + y_adj - 0.5;
x_adj += xx - x;
y_adj += yy - y;
if (((oldxx > 0)&&(x < 0))||((oldxx < 0)&&(x > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
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);
}
else if (((oldyy > 0)&&(y < 0))||((oldyy < 0)&&(y > 0))){
strcpy(buf1,"P");
itoa(0,buf2,10);
strcat(buf1,buf2);
itoa(0,buf2,10);
strcat(buf1," ");
strcat(buf1,buf2);
put_a_line(to_file,buf1);
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);
}
else{
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 = e_x;
oldy = e_y;
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 > 1)
x_once_max_v_pulses = x_once_max_a_pulses*x_times;
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 > 1)
y_once_max_v_pulses = y_once_max_a_pulses*y_times;
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 > 1)
x_once_max_v_pulses = x_once_max_a_pulses*x_times;
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 > 1)
y_once_max_v_pulses = y_once_max_a_pulses*y_times;
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 + -