Browse Source

Use a, b, c instead of lx, ly, lz

Scott Lahteine 8 years ago
parent
commit
c5cac486f5
5 changed files with 116 additions and 111 deletions
  1. 1
    2
      Marlin/Marlin_main.cpp
  2. 80
    79
      Marlin/planner.cpp
  3. 17
    12
      Marlin/planner.h
  4. 15
    15
      Marlin/stepper.cpp
  5. 3
    3
      Marlin/stepper.h

+ 1
- 2
Marlin/Marlin_main.cpp View File

@@ -6892,8 +6892,7 @@ inline void gcode_M503() {
6892 6892
     KEEPALIVE_STATE(IN_HANDLER);
6893 6893
 
6894 6894
     // Set extruder to saved position
6895
-    current_position[E_AXIS] = lastpos[E_AXIS];
6896
-    destination[E_AXIS] = lastpos[E_AXIS];
6895
+    destination[E_AXIS] = current_position[E_AXIS] = lastpos[E_AXIS];
6897 6896
     planner.set_e_position_mm(current_position[E_AXIS]);
6898 6897
 
6899 6898
     #if IS_KINEMATIC

+ 80
- 79
Marlin/planner.cpp View File

@@ -594,13 +594,14 @@ void Planner::check_axes_activity() {
594 594
  * Planner::_buffer_line
595 595
  *
596 596
  * Add a new linear movement to the buffer.
597
- * Not apply the leveling.
598 597
  *
599
- *  x,y,z,e   - target position in mm
600
- *  fr_mm_s   - (target) speed of the move
601
- *  extruder  - target extruder
598
+ * Leveling and kinematics should be applied ahead of calling this.
599
+ *
600
+ *  a,b,c,e     - target positions in mm or degrees
601
+ *  fr_mm_s     - (target) speed of the move
602
+ *  extruder    - target extruder
602 603
  */
603
-void Planner::_buffer_line(const float &lx, const float &ly, const float &lz, const float &e, float fr_mm_s, const uint8_t extruder) {
604
+void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder) {
604 605
   // Calculate the buffer head after we push this byte
605 606
   int next_buffer_head = next_block_index(block_buffer_head);
606 607
 
@@ -611,36 +612,36 @@ void Planner::_buffer_line(const float &lx, const float &ly, const float &lz, co
611 612
   // The target position of the tool in absolute steps
612 613
   // Calculate target position in absolute steps
613 614
   //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
614
-  long target[NUM_AXIS] = {
615
-    lround(lx * axis_steps_per_mm[X_AXIS]),
616
-    lround(ly * axis_steps_per_mm[Y_AXIS]),
617
-    lround(lz * axis_steps_per_mm[Z_AXIS]),
615
+  long target[XYZE] = {
616
+    lround(a * axis_steps_per_mm[X_AXIS]),
617
+    lround(b * axis_steps_per_mm[Y_AXIS]),
618
+    lround(c * axis_steps_per_mm[Z_AXIS]),
618 619
     lround(e * axis_steps_per_mm[E_AXIS])
619 620
   };
620 621
 
621
-  long dx = target[X_AXIS] - position[X_AXIS],
622
-       dy = target[Y_AXIS] - position[Y_AXIS],
623
-       dz = target[Z_AXIS] - position[Z_AXIS];
622
+  long da = target[X_AXIS] - position[X_AXIS],
623
+       db = target[Y_AXIS] - position[Y_AXIS],
624
+       dc = target[Z_AXIS] - position[Z_AXIS];
624 625
 
625 626
   /*
626 627
   SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
627 628
   SERIAL_CHAR(' ');
628 629
   #if IS_KINEMATIC
629
-    SERIAL_ECHOPAIR("A:", lx);
630
-    SERIAL_ECHOPAIR(" (", dx);
631
-    SERIAL_ECHOPAIR(") B:", ly);
630
+    SERIAL_ECHOPAIR("A:", a);
631
+    SERIAL_ECHOPAIR(" (", da);
632
+    SERIAL_ECHOPAIR(") B:", b);
632 633
   #else
633
-    SERIAL_ECHOPAIR("X:", lx);
634
-    SERIAL_ECHOPAIR(" (", dx);
635
-    SERIAL_ECHOPAIR(") Y:", ly);
634
+    SERIAL_ECHOPAIR("X:", a);
635
+    SERIAL_ECHOPAIR(" (", da);
636
+    SERIAL_ECHOPAIR(") Y:", b);
636 637
   #endif
637
-  SERIAL_ECHOPAIR(" (", dy);
638
+  SERIAL_ECHOPAIR(" (", db);
638 639
   #if ENABLED(DELTA)
639
-    SERIAL_ECHOPAIR(") C:", lz);
640
+    SERIAL_ECHOPAIR(") C:", c);
640 641
   #else
641
-    SERIAL_ECHOPAIR(") Z:", lz);
642
+    SERIAL_ECHOPAIR(") Z:", c);
642 643
   #endif
643
-  SERIAL_ECHOPAIR(" (", dz);
644
+  SERIAL_ECHOPAIR(" (", dc);
644 645
   SERIAL_CHAR(')');
645 646
   SERIAL_EOL;
646 647
   //*/
@@ -679,24 +680,24 @@ void Planner::_buffer_line(const float &lx, const float &ly, const float &lz, co
679 680
   #if ENABLED(COREXY)
680 681
     // corexy planning
681 682
     // these equations follow the form of the dA and dB equations on http://www.corexy.com/theory.html
682
-    block->steps[A_AXIS] = labs(dx + dy);
683
-    block->steps[B_AXIS] = labs(dx - dy);
684
-    block->steps[Z_AXIS] = labs(dz);
683
+    block->steps[A_AXIS] = labs(da + db);
684
+    block->steps[B_AXIS] = labs(da - db);
685
+    block->steps[Z_AXIS] = labs(dc);
685 686
   #elif ENABLED(COREXZ)
686 687
     // corexz planning
687
-    block->steps[A_AXIS] = labs(dx + dz);
688
-    block->steps[Y_AXIS] = labs(dy);
689
-    block->steps[C_AXIS] = labs(dx - dz);
688
+    block->steps[A_AXIS] = labs(da + dc);
689
+    block->steps[Y_AXIS] = labs(db);
690
+    block->steps[C_AXIS] = labs(da - dc);
690 691
   #elif ENABLED(COREYZ)
691 692
     // coreyz planning
692
-    block->steps[X_AXIS] = labs(dx);
693
-    block->steps[B_AXIS] = labs(dy + dz);
694
-    block->steps[C_AXIS] = labs(dy - dz);
693
+    block->steps[X_AXIS] = labs(da);
694
+    block->steps[B_AXIS] = labs(db + dc);
695
+    block->steps[C_AXIS] = labs(db - dc);
695 696
   #else
696 697
     // default non-h-bot planning
697
-    block->steps[X_AXIS] = labs(dx);
698
-    block->steps[Y_AXIS] = labs(dy);
699
-    block->steps[Z_AXIS] = labs(dz);
698
+    block->steps[X_AXIS] = labs(da);
699
+    block->steps[Y_AXIS] = labs(db);
700
+    block->steps[Z_AXIS] = labs(dc);
700 701
   #endif
701 702
 
702 703
   block->steps[E_AXIS] = labs(de) * volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01 + 0.5;
@@ -720,33 +721,33 @@ void Planner::_buffer_line(const float &lx, const float &ly, const float &lz, co
720 721
     block->e_to_p_pressure = baricuda_e_to_p_pressure;
721 722
   #endif
722 723
 
723
-  // Compute direction bits for this block
724
-  uint8_t db = 0;
724
+  // Compute direction bit-mask for this block
725
+  uint8_t dm = 0;
725 726
   #if ENABLED(COREXY)
726
-    if (dx < 0) SBI(db, X_HEAD); // Save the real Extruder (head) direction in X Axis
727
-    if (dy < 0) SBI(db, Y_HEAD); // ...and Y
728
-    if (dz < 0) SBI(db, Z_AXIS);
729
-    if (dx + dy < 0) SBI(db, A_AXIS); // Motor A direction
730
-    if (dx - dy < 0) SBI(db, B_AXIS); // Motor B direction
727
+    if (da < 0) SBI(dm, X_HEAD); // Save the real Extruder (head) direction in X Axis
728
+    if (db < 0) SBI(dm, Y_HEAD); // ...and Y
729
+    if (dc < 0) SBI(dm, Z_AXIS);
730
+    if (da + db < 0) SBI(dm, A_AXIS); // Motor A direction
731
+    if (da - db < 0) SBI(dm, B_AXIS); // Motor B direction
731 732
   #elif ENABLED(COREXZ)
732
-    if (dx < 0) SBI(db, X_HEAD); // Save the real Extruder (head) direction in X Axis
733
-    if (dy < 0) SBI(db, Y_AXIS);
734
-    if (dz < 0) SBI(db, Z_HEAD); // ...and Z
735
-    if (dx + dz < 0) SBI(db, A_AXIS); // Motor A direction
736
-    if (dx - dz < 0) SBI(db, C_AXIS); // Motor C direction
733
+    if (da < 0) SBI(dm, X_HEAD); // Save the real Extruder (head) direction in X Axis
734
+    if (db < 0) SBI(dm, Y_AXIS);
735
+    if (dc < 0) SBI(dm, Z_HEAD); // ...and Z
736
+    if (da + dc < 0) SBI(dm, A_AXIS); // Motor A direction
737
+    if (da - dc < 0) SBI(dm, C_AXIS); // Motor C direction
737 738
   #elif ENABLED(COREYZ)
738
-    if (dx < 0) SBI(db, X_AXIS);
739
-    if (dy < 0) SBI(db, Y_HEAD); // Save the real Extruder (head) direction in Y Axis
740
-    if (dz < 0) SBI(db, Z_HEAD); // ...and Z
741
-    if (dy + dz < 0) SBI(db, B_AXIS); // Motor B direction
742
-    if (dy - dz < 0) SBI(db, C_AXIS); // Motor C direction
739
+    if (da < 0) SBI(dm, X_AXIS);
740
+    if (db < 0) SBI(dm, Y_HEAD); // Save the real Extruder (head) direction in Y Axis
741
+    if (dc < 0) SBI(dm, Z_HEAD); // ...and Z
742
+    if (db + dc < 0) SBI(dm, B_AXIS); // Motor B direction
743
+    if (db - dc < 0) SBI(dm, C_AXIS); // Motor C direction
743 744
   #else
744
-    if (dx < 0) SBI(db, X_AXIS);
745
-    if (dy < 0) SBI(db, Y_AXIS);
746
-    if (dz < 0) SBI(db, Z_AXIS);
745
+    if (da < 0) SBI(dm, X_AXIS);
746
+    if (db < 0) SBI(dm, Y_AXIS);
747
+    if (dc < 0) SBI(dm, Z_AXIS);
747 748
   #endif
748
-  if (de < 0) SBI(db, E_AXIS);
749
-  block->direction_bits = db;
749
+  if (de < 0) SBI(dm, E_AXIS);
750
+  block->direction_bits = dm;
750 751
 
751 752
   block->active_extruder = extruder;
752 753
 
@@ -859,29 +860,29 @@ void Planner::_buffer_line(const float &lx, const float &ly, const float &lz, co
859 860
   #if ENABLED(COREXY) || ENABLED(COREXZ) || ENABLED(COREYZ)
860 861
     float delta_mm[7];
861 862
     #if ENABLED(COREXY)
862
-      delta_mm[X_HEAD] = dx * steps_to_mm[A_AXIS];
863
-      delta_mm[Y_HEAD] = dy * steps_to_mm[B_AXIS];
864
-      delta_mm[Z_AXIS] = dz * steps_to_mm[Z_AXIS];
865
-      delta_mm[A_AXIS] = (dx + dy) * steps_to_mm[A_AXIS];
866
-      delta_mm[B_AXIS] = (dx - dy) * steps_to_mm[B_AXIS];
863
+      delta_mm[X_HEAD] = da * steps_to_mm[A_AXIS];
864
+      delta_mm[Y_HEAD] = db * steps_to_mm[B_AXIS];
865
+      delta_mm[Z_AXIS] = dc * steps_to_mm[Z_AXIS];
866
+      delta_mm[A_AXIS] = (da + db) * steps_to_mm[A_AXIS];
867
+      delta_mm[B_AXIS] = (da - db) * steps_to_mm[B_AXIS];
867 868
     #elif ENABLED(COREXZ)
868
-      delta_mm[X_HEAD] = dx * steps_to_mm[A_AXIS];
869
-      delta_mm[Y_AXIS] = dy * steps_to_mm[Y_AXIS];
870
-      delta_mm[Z_HEAD] = dz * steps_to_mm[C_AXIS];
871
-      delta_mm[A_AXIS] = (dx + dz) * steps_to_mm[A_AXIS];
872
-      delta_mm[C_AXIS] = (dx - dz) * steps_to_mm[C_AXIS];
869
+      delta_mm[X_HEAD] = da * steps_to_mm[A_AXIS];
870
+      delta_mm[Y_AXIS] = db * steps_to_mm[Y_AXIS];
871
+      delta_mm[Z_HEAD] = dc * steps_to_mm[C_AXIS];
872
+      delta_mm[A_AXIS] = (da + dc) * steps_to_mm[A_AXIS];
873
+      delta_mm[C_AXIS] = (da - dc) * steps_to_mm[C_AXIS];
873 874
     #elif ENABLED(COREYZ)
874
-      delta_mm[X_AXIS] = dx * steps_to_mm[X_AXIS];
875
-      delta_mm[Y_HEAD] = dy * steps_to_mm[B_AXIS];
876
-      delta_mm[Z_HEAD] = dz * steps_to_mm[C_AXIS];
877
-      delta_mm[B_AXIS] = (dy + dz) * steps_to_mm[B_AXIS];
878
-      delta_mm[C_AXIS] = (dy - dz) * steps_to_mm[C_AXIS];
875
+      delta_mm[X_AXIS] = da * steps_to_mm[X_AXIS];
876
+      delta_mm[Y_HEAD] = db * steps_to_mm[B_AXIS];
877
+      delta_mm[Z_HEAD] = dc * steps_to_mm[C_AXIS];
878
+      delta_mm[B_AXIS] = (db + dc) * steps_to_mm[B_AXIS];
879
+      delta_mm[C_AXIS] = (db - dc) * steps_to_mm[C_AXIS];
879 880
     #endif
880 881
   #else
881 882
     float delta_mm[4];
882
-    delta_mm[X_AXIS] = dx * steps_to_mm[X_AXIS];
883
-    delta_mm[Y_AXIS] = dy * steps_to_mm[Y_AXIS];
884
-    delta_mm[Z_AXIS] = dz * steps_to_mm[Z_AXIS];
883
+    delta_mm[X_AXIS] = da * steps_to_mm[X_AXIS];
884
+    delta_mm[Y_AXIS] = db * steps_to_mm[Y_AXIS];
885
+    delta_mm[Z_AXIS] = dc * steps_to_mm[Z_AXIS];
885 886
   #endif
886 887
   delta_mm[E_AXIS] = 0.01 * (de * steps_to_mm[E_AXIS]) * volumetric_multiplier[extruder] * flow_percentage[extruder];
887 888
 
@@ -1184,12 +1185,12 @@ void Planner::_buffer_line(const float &lx, const float &ly, const float &lz, co
1184 1185
  * On CORE machines stepper ABC will be translated from the given XYZ.
1185 1186
  */
1186 1187
 
1187
-void Planner::_set_position_mm(const float &lx, const float &ly, const float &lz, const float &e) {
1188
-  long nx = position[X_AXIS] = lround(lx * axis_steps_per_mm[X_AXIS]),
1189
-       ny = position[Y_AXIS] = lround(ly * axis_steps_per_mm[Y_AXIS]),
1190
-       nz = position[Z_AXIS] = lround(lz * axis_steps_per_mm[Z_AXIS]),
1188
+void Planner::_set_position_mm(const float &a, const float &b, const float &c, const float &e) {
1189
+  long na = position[X_AXIS] = lround(a * axis_steps_per_mm[X_AXIS]),
1190
+       nb = position[Y_AXIS] = lround(b * axis_steps_per_mm[Y_AXIS]),
1191
+       nc = position[Z_AXIS] = lround(c * axis_steps_per_mm[Z_AXIS]),
1191 1192
        ne = position[E_AXIS] = lround(e * axis_steps_per_mm[E_AXIS]);
1192
-  stepper.set_position(nx, ny, nz, ne);
1193
+  stepper.set_position(na, nb, nc, ne);
1193 1194
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1194 1195
 
1195 1196
   memset(previous_speed, 0, sizeof(previous_speed));

+ 17
- 12
Marlin/planner.h View File

@@ -232,27 +232,32 @@ class Planner {
232 232
     /**
233 233
      * Planner::_buffer_line
234 234
      *
235
-     * Add a new linear movement to the buffer.
236
-     * Doesn't apply the leveling.
235
+     * Add a new direct linear movement to the buffer.
236
+     *
237
+     * Leveling and kinematics should be applied ahead of this.
237 238
      *
238
-     *  x,y,z,e   - target position in mm
239
-     *  fr_mm_s   - (target) speed of the move
239
+     *  a,b,c,e   - target position in mm or degrees
240
+     *  fr_mm_s   - (target) speed of the move (mm/s)
240 241
      *  extruder  - target extruder
241 242
      */
242
-    static void _buffer_line(const float &lx, const float &ly, const float &lz, const float &e, float fr_mm_s, const uint8_t extruder);
243
+    static void _buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder);
243 244
 
244
-    static void _set_position_mm(const float &lx, const float &ly, const float &lz, const float &e);
245
+    static void _set_position_mm(const float &a, const float &b, const float &c, const float &e);
245 246
 
246 247
     /**
247 248
      * Add a new linear movement to the buffer.
248 249
      * The target is NOT translated to delta/scara
249 250
      *
250
-     *  x,y,z,e   - target position in mm
251
-     *  fr_mm_s   - (target) speed of the move (mm/s)
252
-     *  extruder  - target extruder
251
+     * Leveling will be applied to input on cartesians.
252
+     * Kinematic machines should call buffer_line_kinematic (for leveled moves).
253
+     * (Cartesians may also call buffer_line_kinematic.)
254
+     *
255
+     *  lx,ly,lz,e   - target position in mm or degrees
256
+     *  fr_mm_s      - (target) speed of the move (mm/s)
257
+     *  extruder     - target extruder
253 258
      */
254 259
     static FORCE_INLINE void buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, float fr_mm_s, const uint8_t extruder) {
255
-      #if PLANNER_LEVELING && ! IS_KINEMATIC
260
+      #if PLANNER_LEVELING && IS_CARTESIAN
256 261
         apply_leveling(lx, ly, lz);
257 262
       #endif
258 263
       _buffer_line(lx, ly, lz, e, fr_mm_s, extruder);
@@ -267,7 +272,7 @@ class Planner {
267 272
      *  fr_mm_s  - (target) speed of the move (mm/s)
268 273
      *  extruder - target extruder
269 274
      */
270
-     static FORCE_INLINE void buffer_line_kinematic(const float target[NUM_AXIS], float fr_mm_s, const uint8_t extruder) {
275
+    static FORCE_INLINE void buffer_line_kinematic(const float target[XYZE], float fr_mm_s, const uint8_t extruder) {
271 276
       #if PLANNER_LEVELING
272 277
         float pos[XYZ] = { target[X_AXIS], target[Y_AXIS], target[Z_AXIS] };
273 278
         apply_leveling(pos);
@@ -292,7 +297,7 @@ class Planner {
292 297
      * Clears previous speed values.
293 298
      */
294 299
     static FORCE_INLINE void set_position_mm(ARG_X, ARG_Y, ARG_Z, const float &e) {
295
-      #if PLANNER_LEVELING && ! IS_KINEMATIC
300
+      #if PLANNER_LEVELING && IS_CARTESIAN
296 301
         apply_leveling(lx, ly, lz);
297 302
       #endif
298 303
       _set_position_mm(lx, ly, lz, e);

+ 15
- 15
Marlin/stepper.cpp View File

@@ -953,7 +953,7 @@ void Stepper::synchronize() { while (planner.blocks_queued()) idle(); }
953 953
  * This allows get_axis_position_mm to correctly
954 954
  * derive the current XYZ position later on.
955 955
  */
956
-void Stepper::set_position(const long& x, const long& y, const long& z, const long& e) {
956
+void Stepper::set_position(const long &a, const long &b, const long &c, const long &e) {
957 957
 
958 958
   synchronize(); // Bad to set stepper counts in the middle of a move
959 959
 
@@ -962,37 +962,37 @@ void Stepper::set_position(const long& x, const long& y, const long& z, const lo
962 962
   #if ENABLED(COREXY)
963 963
     // corexy positioning
964 964
     // these equations follow the form of the dA and dB equations on http://www.corexy.com/theory.html
965
-    count_position[A_AXIS] = x + y;
966
-    count_position[B_AXIS] = x - y;
967
-    count_position[Z_AXIS] = z;
965
+    count_position[A_AXIS] = a + b;
966
+    count_position[B_AXIS] = a - b;
967
+    count_position[Z_AXIS] = c;
968 968
   #elif ENABLED(COREXZ)
969 969
     // corexz planning
970
-    count_position[A_AXIS] = x + z;
971
-    count_position[Y_AXIS] = y;
972
-    count_position[C_AXIS] = x - z;
970
+    count_position[A_AXIS] = a + c;
971
+    count_position[Y_AXIS] = b;
972
+    count_position[C_AXIS] = a - c;
973 973
   #elif ENABLED(COREYZ)
974 974
     // coreyz planning
975
-    count_position[X_AXIS] = x;
976
-    count_position[B_AXIS] = y + z;
977
-    count_position[C_AXIS] = y - z;
975
+    count_position[X_AXIS] = a;
976
+    count_position[B_AXIS] = y + c;
977
+    count_position[C_AXIS] = y - c;
978 978
   #else
979 979
     // default non-h-bot planning
980
-    count_position[X_AXIS] = x;
981
-    count_position[Y_AXIS] = y;
982
-    count_position[Z_AXIS] = z;
980
+    count_position[X_AXIS] = a;
981
+    count_position[Y_AXIS] = b;
982
+    count_position[Z_AXIS] = c;
983 983
   #endif
984 984
 
985 985
   count_position[E_AXIS] = e;
986 986
   CRITICAL_SECTION_END;
987 987
 }
988 988
 
989
-void Stepper::set_position(const AxisEnum &axis, const long& v) {
989
+void Stepper::set_position(const AxisEnum &axis, const long &v) {
990 990
   CRITICAL_SECTION_START;
991 991
   count_position[axis] = v;
992 992
   CRITICAL_SECTION_END;
993 993
 }
994 994
 
995
-void Stepper::set_e_position(const long& e) {
995
+void Stepper::set_e_position(const long &e) {
996 996
   CRITICAL_SECTION_START;
997 997
   count_position[E_AXIS] = e;
998 998
   CRITICAL_SECTION_END;

+ 3
- 3
Marlin/stepper.h View File

@@ -188,9 +188,9 @@ class Stepper {
188 188
     //
189 189
     // Set the current position in steps
190 190
     //
191
-    static void set_position(const long& x, const long& y, const long& z, const long& e);
192
-    static void set_position(const AxisEnum& a, const long& v);
193
-    static void set_e_position(const long& e);
191
+    static void set_position(const long &a, const long &b, const long &c, const long &e);
192
+    static void set_position(const AxisEnum &a, const long &v);
193
+    static void set_e_position(const long &e);
194 194
 
195 195
     //
196 196
     // Set direction bits for all steppers

Loading…
Cancel
Save