找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 6004|回复: 3

[原创] APT刀轨数据生成NC程序C++源代码

[复制链接]

432

主题

5755

回帖

901万

积分

管理员

积分
9014144
发表于 2025-5-21 20:59:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区

您需要 登录 才可以下载或查看,没有账号?立即注册

×
APT刀轨数据生成NC程序C++源代码,本功能仅作为技术交流研究之用,代码,功能可能存在缺失。需自行编写刀轨数据的读取与处理。以下仅为部分代码以下为头文件部分源代码
  1. int  EQ_is_equal (double s, double t);
    6 N- E, ~6 P" V2 Z$ s+ e
  2. int  EQ_is_ge (double s, double t);, x; |- O' ~) F, F
  3. int  EQ_is_gt (double s, double t);
    0 o0 }4 b) q& z
  4. int  EQ_is_le (double s, double t);, E6 y: F! R+ k9 I; s! v5 v
  5. int  EQ_is_lt (double s, double t);
    7 Z* p. e& ?9 _" Z* C0 V
  6. int  EQ_is_zero (double s);
    ; {+ y. J2 U7 x1 c
  7. //=============================================================& T/ E+ s( O! j  @" r* B, X
  8. double ARCTAN1 (double y, double x );
    2 `  h, p: b. R4 S
  9. //#=============================================================& U" E4 x9 T* C5 m, _
  10. double ARCTAN2 (double y, double x );
      O* I% {) {7 i  u
  11. //#=============================================================7 `2 U& [! y+ L# R
  12. double CheckConst ( double angle, double constvar  );
    1 j% t4 p2 \& M4 z
  13. //#=============================================================' i2 G. N& E* T1 _3 M) f; R$ W
  14. double Check360 ( double angle );
    4 k' \. J  t: P, s
  15. //#=============================================================" T% v. }1 {/ |7 v  j3 ]! w1 d4 m4 ~
  16. double CheckLimit ( double angle, double kin_axis_min_limit, double kin_axis_max_limit );
    ! V' L. R) L; d: {
  17. //#=============================================================
复制代码
( |8 i6 I$ h, i0 ]% l; d# u  w
以下为部分源代码,用于判断,计算角度等
, E- D  a  a3 [+ Q/ J
  1. int  EQ_is_equal (double s, double t)
    3 d% p8 P' u  D# n3 s# M( X* w3 v$ O/ }

  2. 5 B: ~2 c$ P3 ]# ~& z
  3. {
    & @. I5 R7 e" X& U4 C

  4. 3 P( L  K$ z0 s# g- L
  5.   if (fabs(s-t)<= system_tolerance)  { return(1); } else { return(0) ; }
    & r+ |/ ^5 d- P$ H6 [9 D
  6. # }0 Q! Y" v8 d" j
  7. }  t5 Q% L- f" w1 ?+ g1 g$ k
  8. ! ^8 |. @4 ^8 E# G- e* ]
  9. /***********************************************************************/* Z. P( n% P/ X- s; ^4 Y+ A
  10. & \+ W. b6 D/ @- m+ u4 D) u
  11. int  EQ_is_ge (double s, double t)
    & W- N, E0 L  A0 N7 N$ f

  12. % l2 V2 m: G  N  c- w% M# ^* w2 W
  13. {
    $ C, W# ?% c6 [) a  U5 ~8 Q) N& K
  14. " N2 Q: T5 o7 m( F: f
  15.   if (s > (t - system_tolerance)) { return(1); } else { return(0) ; }
    . x+ C$ I2 u1 @( h( a3 ~

  16. ; R9 [$ k- Y+ e6 j0 Q
  17. }. B. F" J0 O, a
  18. % U& o2 A" [4 C# h, U; v9 ]
  19. /***********************************************************************/1 Z4 ^, p. `; V6 l  S2 I1 j  ]
  20. 0 o: `, \% b0 e' X- K
  21. int  EQ_is_gt (double s, double t)4 G- |% K. c, J* O
  22. $ d2 Y3 J3 `+ u& x0 L/ p& L: A
  23. {0 C  _0 Y! y; W! g1 \' e+ A
  24. - }. v9 b& H4 f8 ~6 i0 j/ n
  25.   if (s > (t + system_tolerance)) { return(1); } else { return(0) ; }
    3 v% G1 o6 }+ o: p* w3 i3 T

  26. ; E- T+ d" F+ _& K3 E) a7 O4 S( A
  27. }
    $ ?  M. L6 f7 `9 s1 g: z) `) _8 j
  28. ) k5 }& I' o: _- w; q- ~+ T
  29. /***********************************************************************/# |9 o6 b7 U  _) O, }7 @
  30. 6 E3 q* B5 z$ P& N1 P" K
  31. int  EQ_is_le (double s, double t)
    3 ?: [" R+ g# [: m7 x
  32. / ~4 I0 g" q8 a' `  ?* e* D8 L  Z/ U
  33. {% p/ \( Q& E( r! Z1 @
  34. ( a3 @8 U0 n; ^; h: p/ @( |& }
  35.   if (s < (t + system_tolerance)) { return(1); } else { return(0) ; }' l* |* a( o5 c
  36. % i* |, J, O6 a- G+ P
  37. }
    & t& R% E6 d: j+ P; |

  38. ) D) E* h' D7 J
  39. /***********************************************************************/. e8 ^# R0 O* V& K% f

  40. 3 r4 }1 Q& P2 h/ K
  41. int  EQ_is_lt (double s, double t)8 a* W8 ?+ q( L  l$ t! \3 J  }) x
  42. ' U0 K6 w, }* P9 f
  43. {1 O) \. {' l! l

  44. 0 Y; U% I# w! l' e
  45.   if (s < (t - system_tolerance)) { return(1); } else { return(0) ; }6 w  ?% u0 H3 Z" a$ {- _
  46. , U3 ^& b; \! _
  47. }: ~* p8 s6 X3 B" p* V" }% Z+ Z! i
  48. % R0 z# V2 G6 A) o! Q  I3 G! ?% i
  49. /***********************************************************************/' S' v" }6 f5 {' I: l5 O

  50. : m3 ^+ [1 X3 O: d/ _
  51. int  EQ_is_zero (double s)4 T0 v* L" ]7 V* F
  52. ( ~+ G! s2 M0 f6 V- r/ X
  53. {2 [8 a1 ]& {; h/ S  Q4 ?0 [8 ~

  54. 8 s( c+ i6 g3 a* |2 S
  55.   if (fabs(s)<= system_tolerance)  { return(1); } else { return(0) ; }* O* N" B; V6 m3 z/ e
  56. 4 J: U" |7 U; Q/ Y! p4 h8 d
  57. }
    % I7 K: ~! c1 {( j1 `% [
  58. 4 g# p7 ^% X5 v& M
  59. //=============================================================
    3 p! f' G4 g: D, W1 @& F) _; q

  60. 5 w" m! A9 d2 w# u- A
  61. double ARCTAN1 (double y, double x )3 Q+ C6 U" i& i: d1 |1 W- t' N& A; G7 L
  62. 3 z) g6 a5 r, o* p( W8 F0 x' t
  63. //#=============================================================& j' H/ q( T- n# X( s% S9 S5 m& t

  64. 1 Y! S* b  `& z) ~/ A
  65. {5 f2 @1 x& z! |7 @3 C' A: y. N  |

  66. / s" P* D2 \4 G/ C
  67.    double ang;
    4 V! o$ W. A7 I( r9 c3 H% e

  68. 6 y) U) I4 l1 j$ w0 K! c
  69.    if (EQ_is_zero(y)) { y=0; }; U8 l  C) h: p

  70. / W. x7 r2 ]8 J
  71.    if (EQ_is_zero(x)) { x=0; }! w- x4 x* U0 x  G! |9 I
  72. : U& ^" G" F6 a8 h1 Q+ i1 x& u
  73.    if (y == 0 && x == 0) { return(0); }
    0 c9 n/ t- U) s* m' a$ W" A6 i7 ~

  74. ' l( `) h( V. F  b/ d, |. w. _" I
  75.    ang=atan2(y,x);
    ' R' o' z7 U. B8 v* {& W
  76. 8 C. K1 S' I1 q0 I. R  C* q$ y( X# S
  77.    if (ang < 0 ) {: x; H3 V( U6 O0 I

  78. ' {; V3 z- S, k' M
  79.       return(ang + PI*2);
      J3 H1 p" P- g& w* n( @0 n5 G
  80. " J4 ?( C4 ~6 \
  81.    }# c6 X- W+ o9 U; K: A

  82. ( j7 c* b# b/ r
  83.    return(ang);6 ~) x2 l8 v- P( f8 v

  84. & x' w, i" A6 w
  85. }
    + V/ K( R- [; p) ^3 z

  86. 0 ]& _, D8 [8 W# M2 y
  87. //#=============================================================
    $ h; D2 ^, y, z$ I7 S
  88. : G" t! o3 Q$ |3 C7 |
  89. double ARCTAN2 (double y, double x )1 d" {. ]9 ]$ H; z: h% T% e

  90. 7 m) F: D/ ]' G
  91. //#=============================================================/ z# C5 O! P. u) f+ a
  92. 4 D3 M4 x5 r$ Y# v4 B
  93. {/ ?3 T' P% Y6 n9 \8 u0 z
  94. $ w$ G  ~# n, a7 H5 }& Z8 [
  95.    double ang;
    0 t) c. I: {! Q, |( h# \

  96. 2 @% G) y. Q% [
  97.    if (EQ_is_zero(y)) {
    , Z: Y9 R$ M9 [
  98.   E2 H  t" x% n' T
  99.       if (x < 0.0) { return (PI); }3 Y0 G* W' w2 o, x
  100. 1 O! B' @1 U9 ~
  101.       return (0.0);
    * U6 B" P( C: ]
  102. + {+ A2 {& S5 U" D+ n
  103.    }! ?! n7 s5 M: R$ }3 t

  104. 8 N- o5 I. V: O. U6 z
  105.    if (EQ_is_zero(x)) {
    8 I  O& b+ i2 Y2 f  b- x! N. u

  106. , h. b! m5 ^" {
  107.       if (y < 0.0) { return(PI*1.5); }
    ' N# a, D9 K1 W; q  ?
  108. 1 ]  [  n: `* L. w1 {  I( S
  109.       return(PI*.5);: {% G+ F7 B' m
  110. % G/ M, p, |+ U5 z* b8 A# N  k
  111.    }" `! C2 ?5 E2 s! X' U- l- h% o) E0 L
  112. 0 \) M* e4 ]- l* y
  113.    ang=atan(y/x);' ?( t* W1 f2 p$ I5 c& ~
  114. & O" Q" H3 P) N  g
  115.    if (x > 0.0 && y < 0.0) { return(ang+PI*2.0); }- N  d  |9 e5 l7 V$ h. B
  116. * S5 I' m5 q4 J
  117.    if (x < 0.0 && y < 0.0) { return(ang+PI); }8 y) w" r. i2 c; [+ f) c

  118. 5 g/ I0 H6 |5 i% D/ A
  119.    if (x < 0.0 && y > 0.0) { return(ang+PI); }
    7 H2 ]% l  z. h( _7 j+ `7 \- B

  120. . T5 k* l& _* l% I$ O2 d
  121.    return(ang);+ b1 w4 j: u& U8 U/ F8 z! y( O# E
  122. & _6 c( E* A- d! H
  123. }
    ! c  `$ l) k) z3 \, L" |

  124. , t4 o) ]7 h2 y7 P
  125. //#=============================================================
    0 e) b- f+ `, v6 W3 c7 D
  126. ( Y2 b' ]; I6 q$ R1 h8 `( u  j6 S- L
  127. double CheckConst ( double angle, double constvar  )5 J' R( V& ~+ R5 u

  128. 8 \+ @9 N9 D' t$ {7 h  [
  129. //#=============================================================
    ! P6 j; j  Q- r, z
  130. * p; R: X% G! X1 j
  131. {
    6 F: p) U3 z, r9 V4 F
  132. % q0 G) d: P. h+ |7 I$ [- @4 q3 ~
  133.    while (angle < -constvar) { angle+=constvar ; }
    4 @9 H8 _1 ]) `& W& T
  134. " }: |( o+ x. C# f1 w5 H. [8 l
  135.    while (angle >= constvar) { angle-=constvar ; }
    ! O& [, S, Z" u( }+ l4 Z
  136. # J  ^% N8 V2 n$ u" l$ V8 F9 Q
  137.    return (angle) ;1 h. v# \* B9 t4 A1 y/ m" v

  138. ; g* X0 Y8 d1 Q/ |7 L6 d
  139. }! i0 P4 f( X1 N  C- Q& n
  140. ' N# Z: E& q, l. l, |+ [
  141. //#=============================================================% Q$ J* [  i8 ^5 `- z7 x2 S
  142. / A, y' h8 X- ?% K
  143. double Check360 ( double angle )
    $ \; C) P( R* v  P

  144. $ q0 r# F4 r) y  F
  145. //#=============================================================; R+ X; R) j/ y) N
  146. - a- N) w  i0 P2 q6 V
  147. {; c8 |5 ]8 W8 P9 S4 u
  148. + ^" N3 C5 @2 g; _/ {
  149.    while (angle < -360.) { angle+=360. ; }. a" A+ S/ U  C  M# a  Y- f
  150. * V! S! k* V  ?: W
  151.    while (angle >= 360.) { angle-=360. ; }
    % g5 [, y& H- l. N

  152.   f5 F! G! _2 q2 u
  153.    return (angle) ;- F% M/ Z- X: |5 z: e

  154. . F. Y/ w  E9 f
  155. }
    2 \5 z7 C1 a2 G0 n+ d' I

  156. $ _7 Z$ J$ z0 x' }: P
  157. //#=============================================================/ z9 E% x2 z8 m, Q3 e; ~
  158. 5 u# |3 s. [; l& |4 C* A. H
  159. double CheckLimit ( double angle, double kin_axis_min_limit, double kin_axis_max_limit )/ |2 A) a1 ^) Q" M7 i! D
  160. 6 ~0 T/ L0 l# ?3 l3 f
  161. //#=============================================================8 S! [$ V- l; o% M

  162. 4 w0 Q; L! m9 p) W
  163. {
    8 g: x" I6 N2 j

  164. 3 a5 F6 A, y* g  L8 N2 d1 E2 L* N
  165.    while ((angle-kin_axis_min_limit) > 360.) { angle-=360. ; }
    - q% b6 G/ n" Y

  166. 6 Q. M* N, ^6 ?/ v: j( ~9 \
  167.    while ((kin_axis_max_limit-angle) <= -360.) { angle+=360. ; }
    0 \* i& m1 M1 _
  168. 3 i) D6 q2 p( `5 Q: f& p% q' M& S/ i; L
  169.    return (angle) ;
    ! D, _/ W4 N5 o6 h
  170. 8 V6 _; e* n+ ?1 {7 q
  171. }
复制代码

$ C" w4 X; B& u以下为摇篮5轴计算过程代码6 A7 w+ r: l: q$ [5 g2 W! R, w
  1. i=sin(ang_rad[1]);  j=0.0;  k=cos(ang_rad[1]);
    & A8 U- s# p& y, C- o6 \  s5 a- ]
  2. " E7 z" l' z- F  s1 n7 a) J
  3.          j=0.; B1=0.; B0=0.;0 u2 ^, f# M, D0 L: O2 G

  4. # K$ P: [  S  p; u
  5.           if (EQ_is_ge(i,0.)) {
    + Z, H; S, L) m0 S# J1 F8 ~" o

  6. 7 z( U" R: \, |5 r% J
  7.              if (EQ_is_gt(k,0.)) { B0=acos(k); B1=B0; } else { B0=acos(k); B1=B0; }, z, P1 W2 Y3 n" Z; Y% N  e, _2 `. a% @
  8. & H! t, S' B7 |+ u  a, E
  9.           }+ h' `( t7 Z8 _% _2 M9 @1 I) g& h

  10. ( D& O! _3 g- G# C! h# c; ?$ V- @
  11.           if (EQ_is_lt(i,0.)) {
    , P4 c0 t" L. ~
  12. 3 x! ~& ?' {1 n; k
  13.              if (EQ_is_lt(k,0.)) {
    ! d+ S: O. G8 d

  14. & j2 l7 G: J+ q; E, m- P- d/ ?% h* B
  15.                 B0=atan(i/k); B1=B0+PI ;
    & w! S7 u4 Q* ^  L9 h

  16. : Z9 J0 J  Y3 m
  17.              } else {# n0 [- `7 Z. [- ]  K3 q9 b2 i" l

  18. 3 q$ |  I) _* a% I# r4 h  [/ N
  19.               if (EQ_is_zero(k)) { B0=-PI/2. ; } else { B0=atan(i/k); }" u+ n# x. c7 G. E6 F
  20. 0 @0 f* G8 Y$ U/ o: }- u6 R
  21.               B1=2.*PI+B0 ;
    ' c: |5 c; D$ B. y' s* V

  22. ! y5 A: u4 s0 \' l
  23.              }! Q4 l1 x$ V6 {6 F6 G3 I3 D

  24. & b. H$ U& E$ s
  25.           }- @. s+ y: \5 J# A$ i/ b. c4 ~

  26. ' S- ^& I* h! e# Q1 p
  27.           if (EQ_is_ge(B1,0.)) B0=1.; else B0=-1. ;
    ' K# w: L/ `& y* \& {! C6 A) u# _4 z
  28.   G8 x' W/ ^" H. t- f# ]9 k; w
  29.           B2=(-1.)*B0*(2*PI-fabs(B1));! x& P8 i3 w0 ?- g' W& c

  30. / }. X! t4 z# U" R5 I6 C
  31.           ang_rad[0]=0.; ang_rad[1]=B1; ang_rad[2]=0.;
    $ l# \/ b- {4 m" a7 H9 }& P

  32. & p4 n( |* B* p. x4 j$ m( i
  33.           ang_rad[3]=0.; ang_rad[4]=B2; ang_rad[5]=0.;
复制代码

0 y. Z* s. ]9 q+ @通过输出的NC程序,反向输出的刀轨数据与原始刀轨文件对比,其数据结果一致。8 {% H" B- ^; E

6 y) I" N5 \% r 640.png 4 H7 l: t, `8 w; L
测试结果:
' V( L7 P$ C% O4 i; \7 E5 ^. y 6420.png
& {& n6 S! |, l6 {9 O
! Z/ v5 k1 q! ^% J' y反向测试结果 6410.png ! B$ d0 h5 A% L3 j- h% s/ D/ m

0

主题

25

回帖

17

积分

新手上路

积分
17
发表于 2025-6-3 18:53:03 | 显示全部楼层
谢谢分享
回复

使用道具 举报

0

主题

293

回帖

327

积分

中级会员

积分
327
发表于 2025-10-15 08:41:53 | 显示全部楼层
谢谢分享
回复

使用道具 举报

1

主题

136

回帖

173

积分

注册会员

积分
173
发表于 2025-10-15 12:52:53 | 显示全部楼层
感谢楼主的分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /2 下一条

QQ|Archiver|手机版|小黑屋|若枫后处理论坛 ( 苏ICP备11015087号-1|苏公网安备32059002001368号 )

GMT+8, 2025-12-20 07:26 , Processed in 0.727814 second(s), 24 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表