|
基于电子积木arduino的G代码解释器原代码,来源于http://arduino.cc/forum/搜CNC
; E# U/ }: O% o& B$ _( a K: L我去年收集了许多程序,经过测试挑选出可以用,后来没时间继续研究学习,现在发
) V- {2 Z9 q% n2 z上来给有用的朋友参考) A) @' ?' _; B6 d$ V
下面是其中的小段源码
: H% H( q# @0 W//init our variables
2 r! [+ I+ z: @, e' V. `0 @long max_delta;
4 R6 u1 h# \, j! W5 L, n( T! |long x_counter;& I9 m3 l) D3 K& k p5 T! C
long y_counter;
, P7 D4 h6 n; Xlong z_counter;
8 i. W0 M4 Z/ z. ebool x_can_step;! V) v: O1 n: {/ T B( r6 x2 Z
bool y_can_step;/ T. I0 m9 E: {- R7 O4 x
bool z_can_step;6 [: h* [" U6 c& F! H, X
int milli_delay;
0 I9 z% P% ?5 F% |7 E) Gvoid init_steppers()! w9 u" N! ]2 V, |
{
' P( g# m( m. s0 B9 p //turn them off to start.
: j3 I/ I# Q: V* M% R, _ Y! v disable_steppers();
* \5 D6 _7 D" e( v + D/ T$ x6 h7 |+ a" ^' F
//init our points.- ~ D* ~, u! J' |- Y* _6 n7 |0 @
current_units.x = 0.0;
; g+ @1 n3 V# I3 t: D# g! m current_units.y = 0.0;6 H* _' M# v- _8 m( e h3 z
current_units.z = 0.0;
, J1 J4 {# u( F5 N+ F( e target_units.x = 0.0;
. _5 k& M+ r+ @: Y% \& q" { target_units.y = 0.0;% S( K9 }' H4 x+ E
target_units.z = 0.0;, ]! G b; H3 v; L% G& D( ~0 B* A
- T5 ^# y+ J8 Q
pinMode(X_STEP_PIN, OUTPUT);- @, K7 \4 C8 j. j% Z% c" W8 u
pinMode(X_DIR_PIN, OUTPUT);- [& N3 |( [) U9 q% D5 V+ Z
pinMode(X_ENABLE_PIN, OUTPUT);9 O/ x! M1 B7 s
pinMode(X_MIN_PIN, INPUT);3 c5 w. @3 {* H# n; j# B; [
pinMode(X_MAX_PIN, INPUT);3 F8 X3 E' S$ m8 Y
+ F1 D- T5 f: i6 H _ l pinMode(Y_STEP_PIN, OUTPUT);6 X+ u8 h: M" i- j) s/ X3 ^/ K1 c g
pinMode(Y_DIR_PIN, OUTPUT);
4 W8 h9 r: Z5 B' W7 L7 n# S pinMode(Y_ENABLE_PIN, OUTPUT);
! g$ M& V( { N! H& k pinMode(Y_MIN_PIN, INPUT);. I, [ u: v7 I8 d. G
pinMode(Y_MAX_PIN, INPUT); V; D- H9 O( F4 s
7 m) \9 B) E: y2 ], _" r
pinMode(Z_STEP_PIN, OUTPUT);
- Z4 H5 V8 A& r4 P pinMode(Z_DIR_PIN, OUTPUT);
' J' ^* O. G7 [ pinMode(Z_ENABLE_PIN, OUTPUT);3 Y6 e% A- ~/ g; L% Y/ {& c
pinMode(Z_MIN_PIN, INPUT);
# O) A/ @6 |) d. { X) {9 ] pinMode(Z_MAX_PIN, INPUT);
, k# E8 M1 h0 i; W
1 t8 K, `+ M/ N! T //figure our stuff.
: i; h( N% `. r8 |8 N5 \9 l calculate_deltas();
# A- D* k, Z% n3 s% H}
% P" M0 L3 {( U2 ^8 {void dda_move(long micro_delay)
+ Z! L7 v. U3 O{& A i) r1 F# S
//enable our steppers
) ?: O/ @' \7 D8 G4 M" w- z digitalWrite(X_ENABLE_PIN, HIGH);
z, ^ P/ q @4 W! o8 p" Q digitalWrite(Y_ENABLE_PIN, HIGH);. O# F' ~" V, l- z1 l, c
digitalWrite(Z_ENABLE_PIN, HIGH);
( m" Y$ P/ u1 {* @! G2 I ' D C+ V1 s$ _8 ^( _$ C! r5 {
//figure out our deltas! Q$ b3 \9 w6 p: v3 k* U; T% v
max_delta = max(delta_steps.x, delta_steps.y);
Q$ O; g; Q7 o h0 `- n max_delta = max(delta_steps.z, max_delta);+ N# m7 {2 X( X3 S# V
//init stuff.- n6 h7 b% u# R/ z; O' Q* v
long x_counter = -max_delta/2;& i/ ?- z( |, G8 K# m$ C5 S
long y_counter = -max_delta/2;
f$ n* H2 u# a% d! Z- z0 s long z_counter = -max_delta/2;
& B* M8 U7 u$ C& j. M/ E $ W$ x- T) C9 Y4 i& h) m- m
//our step flags! A; k( R* w4 y& T
bool x_can_step = 0;
5 m. s j# v9 S* | bool y_can_step = 0;
+ ^. {( r1 {; L2 g$ g" u bool z_can_step = 0;# G' E: z4 ? W k2 O
0 y9 J3 l+ m+ D( B' |9 s if (micro_delay >= 16383)4 j* ?0 Q6 j% d/ F! h1 Y
milli_delay = micro_delay / 1000;
8 D4 V3 _! h+ s& d/ @ else
+ G m$ z& S" }& t3 ^8 M3 v+ \# A milli_delay = 0;
8 [, |1 J$ s1 y; A/ t
: |. v$ k, \' A' N9 v |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
|