|
基于电子积木arduino的G代码解释器原代码,来源于http://arduino.cc/forum/搜CNC) z [1 ~ F7 N! n% ?" \ 我去年收集了许多程序,经过测试挑选出可以用,后来没时间继续研究学习,现在发* z; w- j7 C, Z2 b% y } 上来给有用的朋友参考$ s; P! V6 ]( b6 f- |! \5 s$ Z* X- p 下面是其中的小段源码 5 d5 G' x4 I5 l* t//init our variables * r: V. [3 Q4 i+ W# a$ Clong max_delta; 4 |0 m% A' \- l% `; P! z6 ilong x_counter;' Y) p$ b- t: O2 o long y_counter; ' M; s8 c$ s" D6 s) ]- z6 C2 wlong z_counter;" a5 s6 i7 {9 K( n. _/ p bool x_can_step; , p6 u1 [# W2 R W kbool y_can_step;$ p+ ~" Q' h/ C/ V6 _" p/ `$ j1 |/ j& t bool z_can_step; 1 c& D7 q1 m7 y& I* B& i ^3 A4 Cint milli_delay; 3 \) m. s/ A4 l6 D. zvoid init_steppers() ' k6 k3 |2 M/ P* M% a2 I{ 3 Q; a( `- K- {0 L; I) ?//turn them off to start.# `. m3 E# H. ^ disable_steppers(); 0 M ?2 {: `) x* e$ u% t) L + O$ L1 s" M3 D//init our points. 8 J" S* r# m3 o6 I4 l9 ^7 g. Fcurrent_units.x = 0.0;% m- b: ] r/ h! W h current_units.y = 0.0;& w, Q4 z& A' F1 W current_units.z = 0.0;2 }$ t' K4 P1 Z( S5 o- t) P2 j2 Z target_units.x = 0.0;, Z A! D2 g& m- [9 y target_units.y = 0.0; 5 e" ]9 ]6 T2 D) V$ o z( Ntarget_units.z = 0.0; & W& t( n+ ]& n. L1 `* O# i $ u3 K- k- c" W/ N$ GpinMode(X_STEP_PIN, OUTPUT); ! T6 j' U3 L# [3 d6 KpinMode(X_DIR_PIN, OUTPUT); 6 P( Q2 i( _) {/ @& g. U3 g/ }pinMode(X_ENABLE_PIN, OUTPUT); 9 u+ b- h* p; I8 k8 d2 kpinMode(X_MIN_PIN, INPUT);% v( y: M$ z% r' K6 i# _ pinMode(X_MAX_PIN, INPUT); % @3 S, ~9 u$ T o$ `5 R 6 a1 b* y D% DpinMode(Y_STEP_PIN, OUTPUT); ( t& g$ S6 h: ?8 F% C, c ApinMode(Y_DIR_PIN, OUTPUT);* W$ `2 j# ]! D. d, Q; T: L0 ~8 x) A pinMode(Y_ENABLE_PIN, OUTPUT); 5 n' ^1 p2 `% M5 q4 apinMode(Y_MIN_PIN, INPUT);2 |6 l" v, w( v2 K- o; V pinMode(Y_MAX_PIN, INPUT);/ i3 L+ P2 [- O4 c$ @' o . Z! H- C3 Z3 p pinMode(Z_STEP_PIN, OUTPUT);3 R$ V0 x6 g# b& _5 K( G; y pinMode(Z_DIR_PIN, OUTPUT);. Q5 Y& z. _- k- r' n pinMode(Z_ENABLE_PIN, OUTPUT);( d! k0 t) \3 ]+ q$ p pinMode(Z_MIN_PIN, INPUT); ' S9 L( s' w+ @! _) MpinMode(Z_MAX_PIN, INPUT);8 M& ?: J3 r& P' u; E6 _" e- j7 L
' V9 V3 P V- [! c//figure our stuff.: m' G; S" s6 B) l3 R2 J calculate_deltas();' m1 `" g0 y( [. R } 1 V2 K8 ~5 }3 h/ y& Jvoid dda_move(long micro_delay) ' ]- H0 z6 e7 x{ . n& S/ D! i. u9 q( u//enable our steppers( i# O! m' T8 Z digitalWrite(X_ENABLE_PIN, HIGH);4 D. z; C9 Z9 I digitalWrite(Y_ENABLE_PIN, HIGH);2 `0 ~+ a2 f+ z2 f( w4 Z digitalWrite(Z_ENABLE_PIN, HIGH); 8 @7 C4 d7 f( ~( ?* K7 K* X& a * G9 `& D5 r$ j) p//figure out our deltas " Q7 @- r+ l+ h0 {% Imax_delta = max(delta_steps.x, delta_steps.y);$ n/ A2 j: W& v2 P2 y/ V, u' ] max_delta = max(delta_steps.z, max_delta);! G: g# c( o% ] //init stuff.1 `: D5 _; P' o7 f- I long x_counter = -max_delta/2;" T3 }4 f+ _) N @+ u long y_counter = -max_delta/2; ( b0 p2 o) b: |. n3 g6 K' Clong z_counter = -max_delta/2; . E5 Z( y2 K& K# E' ~4 B ! F5 N6 P$ ?7 `; S! R9 J+ R6 \0 X( \6 C//our step flags , U( p: X* @' O# _bool x_can_step = 0; ' W M$ Q5 Q5 x, `; @2 Hbool y_can_step = 0; . c" L' ]$ q v1 w- ]1 Zbool z_can_step = 0; ; l1 y# Z G z; [8 Z( s" b $ c% s5 s" M2 G h6 D8 E& zif (micro_delay >= 16383) ! U5 i7 E8 E7 Q3 Hmilli_delay = micro_delay / 1000; - a) ?$ F j' M* q5 aelse4 L5 ?( A2 G& O6 C4 v# A K4 g milli_delay = 0; / y$ L- x3 V0 y. y4 ]* W 9 |. h+ Q5 C1 j8 C; x t. f |
本帖子中包含更多资源
您需要登录才可以下载或查看,没有帐号?注册会员
x
|