|
基于电子积木arduino的G代码解释器原代码,来源于http://arduino.cc/forum/搜CNC
; }( @7 [; b0 s% m7 h& _我去年收集了许多程序,经过测试挑选出可以用,后来没时间继续研究学习,现在发
7 K2 v+ t* W3 ]$ G& D上来给有用的朋友参考/ f+ d" x* \( L; ~, e
下面是其中的小段源码8 K9 |* T& U1 N0 n! C V
//init our variables
0 B/ A! d0 I$ ylong max_delta; N( u: o- A. S' V2 R8 m |+ z
long x_counter;
8 X( t! |" x8 g3 a7 W. G' Vlong y_counter;/ Q; ?" t5 c, u5 d$ R; E
long z_counter;, k' b2 \4 l1 h) N
bool x_can_step;- C) [1 B2 O6 z- i( E+ [
bool y_can_step;
$ Z4 b9 a* C: ^# k' P" obool z_can_step;
: h0 ?; O2 G; A5 A3 @! ~int milli_delay;" E, W2 N" A! \
void init_steppers()
/ p+ W3 n$ k1 J' c2 i6 M! P{0 a8 K, f' x: {( Z
//turn them off to start.
* N! Z' l; k& H! G/ j" B disable_steppers();
9 i7 c' K. Y3 F) W+ X; w9 i6 l0 Z + ~( l$ B; H* r1 @
//init our points.
1 M9 W4 u* o4 A8 C5 x. ^1 V current_units.x = 0.0;
5 i+ b; r8 h3 { current_units.y = 0.0;
2 I5 ^/ ?6 V) U: c" u current_units.z = 0.0;' ^" F, S6 M1 V. o' p
target_units.x = 0.0;: I7 [# a5 v* ]
target_units.y = 0.0;
2 n! `+ P1 \' e/ {0 T9 ^4 P target_units.z = 0.0;7 K0 _# e( n1 a7 @0 J3 B5 Z& R( o
" S5 x d6 U6 Y# i
pinMode(X_STEP_PIN, OUTPUT);
% H1 j, T* C6 q8 F: k pinMode(X_DIR_PIN, OUTPUT);- M0 l& t$ o) `3 C' v2 p
pinMode(X_ENABLE_PIN, OUTPUT);- y1 B Z- \+ `/ P& X
pinMode(X_MIN_PIN, INPUT);
. R% p+ ?) {+ U n/ P8 X+ I k" v pinMode(X_MAX_PIN, INPUT);8 A, n6 [" Q6 S: W+ W& @' P
; \* A4 L4 d7 M
pinMode(Y_STEP_PIN, OUTPUT);
" G8 p+ W. z0 j+ C4 [3 n b* Z pinMode(Y_DIR_PIN, OUTPUT);
$ q* g& g9 N) T/ i, X4 ~2 D: H pinMode(Y_ENABLE_PIN, OUTPUT);
5 d2 l/ |$ ^2 ^; V0 {* d: X# @/ E% ^ pinMode(Y_MIN_PIN, INPUT);8 n) n2 N& d8 I& i
pinMode(Y_MAX_PIN, INPUT);% [6 e/ q6 S) n$ d1 U3 r' V3 K* D
2 @9 h4 R& t" s& j6 M: Y; _ pinMode(Z_STEP_PIN, OUTPUT);
8 c; l4 j. U8 c% g pinMode(Z_DIR_PIN, OUTPUT);
3 S) @2 k! \# }2 K# p3 b. ]" D pinMode(Z_ENABLE_PIN, OUTPUT);$ F" @+ p' R3 d' b& A% C+ p
pinMode(Z_MIN_PIN, INPUT);
7 C# D; O) u+ f3 r pinMode(Z_MAX_PIN, INPUT);
. U" r1 W" |) ^6 `% C2 \% u9 E9 g5 C2 x % G% [0 [! h: y5 _: O" u: r
//figure our stuff.
3 N" J J( E2 n7 I1 U0 k calculate_deltas();3 S& B) j9 u$ x3 ]
}
+ H4 Q2 D$ k0 H0 y* n# \3 bvoid dda_move(long micro_delay)
* _: T; K J7 r7 }; g n! o{
; R. K$ ~$ b0 C1 w- k S //enable our steppers2 C j6 z8 P1 o. o! ^8 v
digitalWrite(X_ENABLE_PIN, HIGH);
- {+ Y: M% S1 Y4 v- Y digitalWrite(Y_ENABLE_PIN, HIGH);
: m0 Q" v% v1 o8 D0 T digitalWrite(Z_ENABLE_PIN, HIGH);. I; W$ G$ r, c' T p$ V
% G' l' G. t6 ]& U! x& |2 v, g
//figure out our deltas. N% P9 }8 O2 R- W% Y! J0 V! z
max_delta = max(delta_steps.x, delta_steps.y);1 @" R$ |( o6 @8 b
max_delta = max(delta_steps.z, max_delta);$ D6 U, N w' E0 @' `' y) l2 O
//init stuff.
' X, L9 i( o* R" w# v: a long x_counter = -max_delta/2;" k: r6 Q' e( q5 {7 g; U3 k
long y_counter = -max_delta/2;
: h" J, M- R/ u9 B0 L) C4 x( l long z_counter = -max_delta/2;
# p, S, e4 `0 j* G! b! |
6 x$ O7 E6 p6 A9 P% o* M //our step flags' ^. X* R0 M) u& y# T/ z% ^
bool x_can_step = 0;7 b4 e6 [# r3 m* x1 U L4 d
bool y_can_step = 0;
% b$ A; a; w9 J2 d# K; Z, y bool z_can_step = 0;
/ J: ?) ~( p+ t% A4 ~4 y; Z, o + ]# x% E" X# B* y$ S" _7 t
if (micro_delay >= 16383)
' S" G0 ~2 q: n7 Z- j+ V1 N milli_delay = micro_delay / 1000;
% x6 a7 z: C. n* } else N' G% B6 U. |" c
milli_delay = 0;
0 r2 }% e" m4 J6 F% d. C
1 v c3 O F8 B/ M% X. n |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
|