|
基于电子积木arduino的G代码解释器原代码,来源于http://arduino.cc/forum/搜CNC
) s% U9 J i4 o+ H, v H* R我去年收集了许多程序,经过测试挑选出可以用,后来没时间继续研究学习,现在发! \3 M4 T, b4 W. \: u! I& [
上来给有用的朋友参考
; }8 U {' H% R$ S. ~2 f) c( ^下面是其中的小段源码
: v! O r6 [8 W6 h' V% M//init our variables
. O+ p" f H& ]1 ]long max_delta;
) y9 N2 H* ]- k, along x_counter;
9 O. ?$ Z7 V) Y8 B. b" @long y_counter;
8 w4 m! ^* X, llong z_counter;% H) p$ s, j! C
bool x_can_step;/ V6 `6 y; b; e/ I1 K
bool y_can_step;- b1 [, J( F ]8 R' }1 z# Z, y! \
bool z_can_step;! G6 Q5 t$ V6 e
int milli_delay;$ e- c) v+ J8 }; q; f+ q# B8 n
void init_steppers()1 j6 p H) o. Y
{! Y" r& t* r0 e1 {, d
//turn them off to start./ D2 r: U2 @0 ]; G! y9 F$ {) R
disable_steppers();
/ Y o+ _# ~0 Z: w' W 1 e( z- h8 `! p1 T; Y
//init our points.
* r$ z5 V+ _ d/ {2 U" w, i5 s7 } current_units.x = 0.0;. K5 j* _7 |) j3 j n
current_units.y = 0.0;
! i' o1 A6 W/ \) z current_units.z = 0.0;
) X) a% v* Q' }# W; p target_units.x = 0.0;# I/ |6 g. K. u* P" w" }1 j
target_units.y = 0.0;0 r& o2 m! {. p% F
target_units.z = 0.0;, `: Y+ J. N. s5 O
% [4 }$ V1 i, [& p, D ? pinMode(X_STEP_PIN, OUTPUT);
( S* U+ u9 [1 p4 _4 b% D pinMode(X_DIR_PIN, OUTPUT);& d/ E* C* e( V3 z; P/ Y8 l- }+ z
pinMode(X_ENABLE_PIN, OUTPUT);# j" a) s( G' O C0 v F
pinMode(X_MIN_PIN, INPUT);5 m) \% P. Q# v
pinMode(X_MAX_PIN, INPUT);& x9 i# W4 ~9 z% a6 H1 z
7 E( C* J8 b: G) s$ P* F pinMode(Y_STEP_PIN, OUTPUT);
6 r+ M- T% u: O; [! D7 U pinMode(Y_DIR_PIN, OUTPUT);
$ p( ^9 m4 C( A: z pinMode(Y_ENABLE_PIN, OUTPUT);
3 E9 O7 J: ]3 R( I p& k/ a: N pinMode(Y_MIN_PIN, INPUT);4 u' _& F9 m u0 ]3 ?
pinMode(Y_MAX_PIN, INPUT);
- |" c- ]6 @+ g7 T( U$ a* Z% O . B. K9 k1 u0 V8 V; C
pinMode(Z_STEP_PIN, OUTPUT);
4 s8 D3 [) n; b1 H pinMode(Z_DIR_PIN, OUTPUT);
/ A9 L! l; x$ f. ?) i+ Y% Y9 ?3 c pinMode(Z_ENABLE_PIN, OUTPUT);
$ ]" |" P5 Q2 p4 \5 \3 ~( J pinMode(Z_MIN_PIN, INPUT);% f6 x1 m; A" f1 U; p! M
pinMode(Z_MAX_PIN, INPUT);
/ j$ x' f5 ?# E8 B/ P/ y
1 F9 b9 x# | M! D: G9 m //figure our stuff.4 M/ l& }, ^7 H' k m3 z: l
calculate_deltas();# e6 b# M0 I+ k
}) v, ~( u* A8 x0 G$ u
void dda_move(long micro_delay)
: {! @# z3 H' n: ~% U{
( z) p' Y6 |* @" ] //enable our steppers& g; |. d& F, M! H) P |
digitalWrite(X_ENABLE_PIN, HIGH);
q; r; `+ X8 k+ X. A digitalWrite(Y_ENABLE_PIN, HIGH);7 W8 s3 o0 h& a6 n
digitalWrite(Z_ENABLE_PIN, HIGH);
1 A E$ N( R' Y$ s( g8 d: |' t 8 D% C; b! C0 }$ _3 I
//figure out our deltas
2 ^) J ?5 t: o( L# u* F max_delta = max(delta_steps.x, delta_steps.y);' h8 t$ q- ?0 H8 q8 y+ y
max_delta = max(delta_steps.z, max_delta);( e' b6 L. P6 K# ?% |1 M7 |& B; g, @
//init stuff.
$ ~4 f/ H. T& x: F long x_counter = -max_delta/2;
8 B3 a4 u4 g1 e+ n1 r long y_counter = -max_delta/2;, M E- M/ ?4 x' i8 `7 M
long z_counter = -max_delta/2;
6 K2 {# i9 [3 l8 [5 S4 K 3 f$ W& ^; ^. O p3 f7 u2 C" ^( L! s
//our step flags" X7 R; [! l" ^. p; q% ]7 o
bool x_can_step = 0;8 a9 Y: n; r/ i+ ?; W2 s$ p0 F1 m
bool y_can_step = 0;3 |3 \6 m) V r, d4 v
bool z_can_step = 0;* q& v7 p0 @; q3 G
+ N. F% t# f- u; K6 x2 G. C if (micro_delay >= 16383)
' }0 I! ~. K; V* F0 F9 u) j milli_delay = micro_delay / 1000;
! T/ } p$ g" c9 {; e. H) n; M, V! x else
$ N+ f' j- U7 W5 Z" ?. P0 ^! V milli_delay = 0;
0 B9 ~# \" C% \% I# U; X! L. a$ X3 y4 A
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
|