|
基于电子积木arduino的G代码解释器原代码,来源于http://arduino.cc/forum/搜CNC 5 D n. i! q/ y! ~我去年收集了许多程序,经过测试挑选出可以用,后来没时间继续研究学习,现在发 ; N! @2 f; H" r z6 O$ {上来给有用的朋友参考 , Z8 L9 w. R- G3 \8 N0 ~+ [4 K下面是其中的小段源码 " r6 ^. Y/ u; g$ b3 L//init our variables; j5 Z4 l+ N+ K; B0 U, I! v/ S long max_delta;1 `- T2 N& \& H. c/ Y long x_counter;1 P6 \5 C; { A( g: ^ p long y_counter; - \3 S& C2 A; u' ^% Mlong z_counter;3 ^; y, P5 ], T( Z @; e( o( [ bool x_can_step; # ]7 p6 m" R* C* e# }bool y_can_step; ' W; X( ]! u; \. P0 \/ g: A: h8 f& Y, {bool z_can_step;5 F1 Q4 k9 W/ W& [; N. r1 ? int milli_delay; - f; S/ @. @$ v- x/ vvoid init_steppers(); m" y" X8 r' d2 G { 3 {, v5 d( A/ x" l+ H/ v/ D" g//turn them off to start. " k4 U( ~# x0 w2 Bdisable_steppers(); # N; F( ]+ A/ m, l' j # u% \, b* E& D( k& o: }8 d# V0 b" N//init our points.- H: M% ~3 `! v6 q7 q+ }7 p current_units.x = 0.0; / f! u; ~9 m! L$ Z( {current_units.y = 0.0;0 Z, i+ t. W6 D: c; t current_units.z = 0.0;\7 e A8 g5 D target_units.x = 0.0;; b- o& H; q4 u8 |0 e- x% \0 [- R( L target_units.y = 0.0;8 W$ h: W6 ?: y5 _7 i1 L target_units.z = 0.0;) [2 V5 w6 t Z6 y % b! ~. a# q& D! C# f5 i pinMode(X_STEP_PIN, OUTPUT); ! N: f' @& ?# P! e) z+ Y$ f# GpinMode(X_DIR_PIN, OUTPUT);7 J! V4 o8 Q4 A+ Z& Q pinMode(X_ENABLE_PIN, OUTPUT);r- y+ m$ l- Y: V5 | pinMode(X_MIN_PIN, INPUT); & P" b8 ~) a3 a9 G0 CpinMode(X_MAX_PIN, INPUT); # N0 E2 a% w( z! R0 z" G; _ , x3 Y! w' k. I# `+ kpinMode(Y_STEP_PIN, OUTPUT); - R- P0 b/ \. o: ?9 Y% J% } FpinMode(Y_DIR_PIN, OUTPUT);$ k& l; A; l' N$ S7 [( {5 m- \ pinMode(Y_ENABLE_PIN, OUTPUT); - E9 b. U) }# X7 Y0 ipinMode(Y_MIN_PIN, INPUT); " Y8 | U5 B% UpinMode(Y_MAX_PIN, INPUT); 6 r: g# l Y! \8 `6 t- K. b 6 E) t# o9 C" qpinMode(Z_STEP_PIN, OUTPUT);# [, H f! {" L* O/ ]5 @! v pinMode(Z_DIR_PIN, OUTPUT); $ |9 i3 i6 y/ e+ M5 {5 \pinMode(Z_ENABLE_PIN, OUTPUT);1 t/ e5 y$ h# ~ pinMode(Z_MIN_PIN, INPUT); 0 E# H; u' R5 {+ [2 F; O: e, e* t. SpinMode(Z_MAX_PIN, INPUT); 3 _" l) o# \& N0 a% y; | 8 r# ]7 D) @5 M3 U: ]. R8 K X//figure our stuff. ( q# ?. z' n$ Z$ C" H* Vcalculate_deltas(); # u) M8 D/ j8 d}9 B3 o1 c0 ]8 W6 K5 Z; i void dda_move(long micro_delay)6 I! Q3 f1 m4 ?( s$ X4 V { 9 E% a5 { r2 ` `5 D//enable our steppers: x; L3 W: M0 N6 S* v# Y+ |0 X digitalWrite(X_ENABLE_PIN, HIGH); * b: Z+ _2 I- r( v* ?* G1 zdigitalWrite(Y_ENABLE_PIN, HIGH); 4 ~ n/ R/ u) L8 pdigitalWrite(Z_ENABLE_PIN, HIGH); ( `4 o9 O) l, m3 I- c2 k0 M- M& v. d; i' d //figure out our deltas3 s) h! J' Z7 S3 B/ n9 Q max_delta = max(delta_steps.x, delta_steps.y); 8 Y1 S$ r! |7 M( [9 smax_delta = max(delta_steps.z, max_delta); ) ~1 V& r$ l- q. H//init stuff.1 f( H/ M6 v+ X, s long x_counter = -max_delta/2; # v3 {' n; ~5 @# {. |* G, Ilong y_counter = -max_delta/2;6 I$ X I7 K- A# L9 |# ^% ^+ v: e long z_counter = -max_delta/2;; \9 `5 Q: ]. {; u # j& _8 E; `% m1 g- n //our step flags, y+ e7 q, O- j6 G bool x_can_step = 0;% o+ C4 u9 M, Y& g, G9 {" X bool y_can_step = 0;A: d$ L @6 l9 v* z( o/ q bool z_can_step = 0;+ G/ s3 E) R0 s1 K/ \* |9 Z! C' q * H; U2 Z+ t. @% z! E' t' h& M$ g if (micro_delay >= 16383) $ E6 c9 e9 Z6 E Jmilli_delay = micro_delay / 1000;" h* u3 a% c3 M& M8 ` else / k" F2 a5 Y+ |7 Kmilli_delay = 0; # m9 N+ \( O! X+ n; g, y % L/ f( @1 {, v g# c1 o; f |
本帖子中包含更多资源
您需要登录才可以下载或查看,没有帐号?注册会员
x
|