|
基于电子积木arduino的G代码解释器原代码,来源于http://arduino.cc/forum/搜CNC
( U3 X; ?* x P* @ r9 N5 T我去年收集了许多程序,经过测试挑选出可以用,后来没时间继续研究学习,现在发
3 v$ ^! Q: N1 o; _3 J& U上来给有用的朋友参考( P# {! |: K0 ]( Y7 _' w% o
下面是其中的小段源码% i+ E& |, \3 `) g% {1 @' e6 X& S9 o
//init our variables
; q# v9 U5 X5 U, f" e) }long max_delta;6 g+ k* ^; y- O1 G3 w6 B/ f6 D
long x_counter;
2 P3 s! [$ |% m4 g, o' f( p, _- wlong y_counter;
y2 y$ M2 Q+ ~, m2 Q! X# X0 d8 [long z_counter;
! k5 n1 n$ g! sbool x_can_step;; _. J H; h. K
bool y_can_step;
+ p0 a* Z9 E% [8 B* fbool z_can_step;
( q- N$ t6 y( ?/ M- n4 @; \) v1 X: Nint milli_delay;
, X) \# W+ J) B# I7 _# s1 g6 F evoid init_steppers()
6 K% ]( x+ [, A+ Y4 g. }{# ^1 x( ^* j. S9 u
//turn them off to start.) v" A ]' W' Y3 s- l2 S
disable_steppers();
6 K1 O- V: A& P5 `9 N( R) }' g' S
0 Q! }' Y; [9 U" i- O$ g6 M //init our points.
- @& h* _: y3 j5 ?; n7 Y! w current_units.x = 0.0;
" ~. w% S8 F9 l current_units.y = 0.0;
3 p/ R% b9 E) x" X4 l current_units.z = 0.0;5 e! m: S. s3 j$ _
target_units.x = 0.0;
3 W6 i: U+ z0 }1 a6 E) i4 P target_units.y = 0.0;
8 F# X: k4 i" U! q0 Z/ b target_units.z = 0.0;
( q3 l0 p8 g( u9 O3 ~! b& E - v7 z# ^% j1 X+ t
pinMode(X_STEP_PIN, OUTPUT);
" o0 O9 _! F4 h% V! @( C pinMode(X_DIR_PIN, OUTPUT);
% g! [" ?' Y9 {- c4 ~ pinMode(X_ENABLE_PIN, OUTPUT);
. Z! B/ P& D' V2 f pinMode(X_MIN_PIN, INPUT);( D# t$ U: Y2 |* |4 ?, t
pinMode(X_MAX_PIN, INPUT);
# F" }, a3 g1 f
: ^) z) N5 `: T7 i pinMode(Y_STEP_PIN, OUTPUT);
( I2 u* C& I' f! d( ?0 g pinMode(Y_DIR_PIN, OUTPUT);
9 U( B& p4 v" a, z$ j pinMode(Y_ENABLE_PIN, OUTPUT);
% H* q" y8 O/ S pinMode(Y_MIN_PIN, INPUT);; n7 f% J1 B$ C$ I% L9 G2 s
pinMode(Y_MAX_PIN, INPUT);
6 l" l+ o1 G* h$ a& z7 [* \ d 4 G+ v' ?6 l0 @! D+ N
pinMode(Z_STEP_PIN, OUTPUT);- a4 j$ j4 p- e5 S3 \6 c
pinMode(Z_DIR_PIN, OUTPUT);
6 W; X. _) i1 ?0 p6 V pinMode(Z_ENABLE_PIN, OUTPUT);* V6 V9 I! n7 c. D$ h7 }
pinMode(Z_MIN_PIN, INPUT);% K$ k3 ?9 ] m! Z$ o7 y0 j
pinMode(Z_MAX_PIN, INPUT);
, Z1 p" m. U# O) E7 ` 8 h8 S# U/ d1 [) x
//figure our stuff.
/ r1 T1 B) e' V- f calculate_deltas();6 ]; J5 W/ x; X6 L% S
}
) J5 {+ ?. `4 c+ f7 Bvoid dda_move(long micro_delay)
# V2 c0 J, Y1 M2 x! Z! }{/ a* b+ R3 S3 E
//enable our steppers6 o$ P9 q u7 Y# z. [
digitalWrite(X_ENABLE_PIN, HIGH);
2 @5 X& v/ b4 h/ g9 A3 B" ?% J E" L digitalWrite(Y_ENABLE_PIN, HIGH);1 P# s6 J# W: U0 C/ U6 b; C
digitalWrite(Z_ENABLE_PIN, HIGH);, G% Q% z0 a7 D6 L7 @" g
0 Y4 S" K: W+ [
//figure out our deltas
, S% Z4 c, U3 g) L. V- o/ K max_delta = max(delta_steps.x, delta_steps.y);( {+ P( R4 K, w0 u
max_delta = max(delta_steps.z, max_delta);
' v U- X& b: q/ R //init stuff.
) L9 S ~4 A4 z6 p long x_counter = -max_delta/2;
/ |" ~1 H* h4 ~8 L; Z% N long y_counter = -max_delta/2;
1 [& T4 L* \, t/ S/ z! |! T% ] long z_counter = -max_delta/2;
7 `. I3 I( G" ^( l i' p) V
. f/ C, `4 q5 u8 D6 R2 }5 k% l //our step flags
7 R2 u, r$ D1 Z+ g3 i bool x_can_step = 0;5 |, w6 U! C8 D# m2 N
bool y_can_step = 0;6 w- F. e- U! Y: }
bool z_can_step = 0;
2 p! z' u. o/ i0 N
7 \8 j! x, U! F# n if (micro_delay >= 16383)
( S+ }: W; b" H& C& q milli_delay = micro_delay / 1000;
4 I3 f+ g* X7 g, D ?+ O else
0 a. e+ W) f+ d- ]( J; U milli_delay = 0;
* q m: t. f4 A
1 U3 o$ e: k" K |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
|