|
基于電子積木arduino的G代碼解釋器原代碼,來源于http://arduino.cc/forum/搜CNC
$ m% j( R1 Z* \. Y) T5 Q3 @- [ |9 D我去年收集了許多程序,,經(jīng)過測試挑選出可以用,后來沒時間繼續(xù)研究學(xué)習(xí),,現(xiàn)在發(fā)' ~% c) J( w6 ^$ M Q
上來給有用的朋友參考! x0 a1 F) X/ e/ \8 B9 j) d% a
下面是其中的小段源碼
0 d3 q; Q3 g" y, I//init our variables+ }4 k9 z' l9 g& x
long max_delta;5 o/ Y7 o) m: }4 E* i8 _
long x_counter;
B- Z6 h* K/ H. J- j( v: [long y_counter;
$ M9 P7 Q; y9 A( dlong z_counter;* e+ o2 U5 E: B3 H2 {* L2 U, f
bool x_can_step;+ V- U) a1 U$ J+ z4 ~+ B6 m
bool y_can_step;* x. M+ g0 N+ T" f1 H+ L @
bool z_can_step;
) [. {- d8 _! d, E& A( ]int milli_delay;
4 d( H1 Y$ h6 `" H+ [void init_steppers()8 q# |( D- A4 B2 Q0 K( }3 X6 Z
{
3 _% q C' A5 L+ L' C" v* e2 _ //turn them off to start.
" p0 x) e! b# ~8 D+ u disable_steppers();$ ?. U/ S" u, R% |% M/ o: x/ H
6 T: }7 I; K' ]" p
//init our points.
/ @' \# y- l) h: e# l current_units.x = 0.0;- E9 B+ ~7 p7 q# Z$ j @) n* T' Q+ f
current_units.y = 0.0;: K" h' j' G9 O4 t% D* f
current_units.z = 0.0;9 c `, S0 V% Y2 N
target_units.x = 0.0;
- s4 h0 }% w1 u- M target_units.y = 0.0;! P8 r/ g- \2 ]" J8 L+ w0 r
target_units.z = 0.0;
" L9 [9 [+ C+ \ y9 i6 O4 Z 4 e4 _4 Q: N1 d' S7 z! E% A
pinMode(X_STEP_PIN, OUTPUT);3 k0 w3 g W- \* c
pinMode(X_DIR_PIN, OUTPUT);5 ]% S. q2 F i# E2 E
pinMode(X_ENABLE_PIN, OUTPUT);
, a( j5 J/ b& Z% } pinMode(X_MIN_PIN, INPUT);
% K0 w( V: J1 h ~ pinMode(X_MAX_PIN, INPUT);
' k) h4 \! d9 f( F l
' z2 p( ]0 I+ {) K$ S pinMode(Y_STEP_PIN, OUTPUT);& J. g# S( J# ~" t
pinMode(Y_DIR_PIN, OUTPUT);
# Y# F) r2 s1 G( w) O3 _ pinMode(Y_ENABLE_PIN, OUTPUT);( j( z j6 }( ]$ G
pinMode(Y_MIN_PIN, INPUT);; l9 Z9 h/ K$ y% B! p! V/ R, L2 ]
pinMode(Y_MAX_PIN, INPUT);0 }% X' E$ z: e9 B1 Z L
8 q- n3 R! [+ n! ?, ^" h9 E& `
pinMode(Z_STEP_PIN, OUTPUT);
3 K! l- m) y& j1 G1 N- A* V8 r pinMode(Z_DIR_PIN, OUTPUT);: J( h! W; e1 S" n0 ?6 Y& D; ^
pinMode(Z_ENABLE_PIN, OUTPUT);
& }/ Y$ \) U. O) O pinMode(Z_MIN_PIN, INPUT);: u3 f0 i% u# z( F6 r" Y
pinMode(Z_MAX_PIN, INPUT);
- U% v/ H+ E" z6 W: Y6 X/ j ; ]. y9 u+ N5 Y* Q+ a
//figure our stuff.
, n+ n' D$ c9 M; t& z0 L calculate_deltas();
9 P v+ h2 I# b) L* A1 `}7 g" `$ y) q R! _ [; g9 n
void dda_move(long micro_delay)
( W2 U" L' W; V& ^" v0 T$ X7 q N{" @! s1 C; \6 q# y$ r+ F- p
//enable our steppers1 W- B O, {( R% K/ S: R
digitalWrite(X_ENABLE_PIN, HIGH);
, h. ~7 t: [; Q }# K, e# c" v digitalWrite(Y_ENABLE_PIN, HIGH);: o) W9 ^9 `/ R& r3 L2 I. m- s
digitalWrite(Z_ENABLE_PIN, HIGH);9 x3 I7 Q$ w; T+ I6 {; g
1 {) b5 `) W( d/ j" \ //figure out our deltas- r: b! c3 @3 R0 M0 S1 M
max_delta = max(delta_steps.x, delta_steps.y);
5 ?1 i9 X( i+ h" R6 X' A max_delta = max(delta_steps.z, max_delta);
0 n3 _. N. p& s w7 A //init stuff.0 [1 P2 X& |/ j2 ^! `2 R5 T- \6 E
long x_counter = -max_delta/2;
) j* a4 I0 d0 H! G long y_counter = -max_delta/2;
6 W+ U8 Z! N/ t: R long z_counter = -max_delta/2;
6 A8 @; J6 B& D, s1 \ $ q- K+ ^( Z0 _+ `' w7 v; T- D
//our step flags
" p$ H" Q; T1 }. z k2 C+ B bool x_can_step = 0;, ]* ~" `2 x- o9 R: k3 j) h
bool y_can_step = 0;
" w4 r1 T2 I1 T bool z_can_step = 0;/ s; Z! i6 W$ ^1 \6 w$ y [
. r) a1 p) x# b( x if (micro_delay >= 16383)/ L. F7 P9 n4 Z6 U+ j
milli_delay = micro_delay / 1000;
. R2 \# [! ?/ S* _0 G- V0 I4 Q' [# e else5 s' P/ J6 s6 b
milli_delay = 0;
) m, e/ S1 b: r9 L8 R$ V
' i" J" u4 T3 | |
本帖子中包含更多資源
您需要 登錄 才可以下載或查看,,沒有帳號?注冊會員
x
|