浏览代码

Merge pull request #4387 from thinkyhead/rc_anhardt_more_4370

Update Z in a unified way in run_z_probe
Scott Lahteine 9 年前
父节点
当前提交
c287846f46
共有 4 个文件被更改,包括 42 次插入65 次删除
  1. 30
    56
      Marlin/Marlin_main.cpp
  2. 1
    1
      Marlin/configuration_store.cpp
  3. 3
    0
      Marlin/enum.h
  4. 8
    8
      Marlin/planner.cpp

+ 30
- 56
Marlin/Marlin_main.cpp 查看文件

564
 void get_available_commands();
564
 void get_available_commands();
565
 void process_next_command();
565
 void process_next_command();
566
 void prepare_move_to_destination();
566
 void prepare_move_to_destination();
567
-void set_current_from_steppers();
567
+void set_current_from_steppers_for_axis(AxisEnum axis);
568
 
568
 
569
 #if ENABLED(ARC_SUPPORT)
569
 #if ENABLED(ARC_SUPPORT)
570
   void plan_arc(float target[NUM_AXIS], float* offset, uint8_t clockwise);
570
   void plan_arc(float target[NUM_AXIS], float* offset, uint8_t clockwise);
1524
     if (axis == X_AXIS || axis == Y_AXIS) {
1524
     if (axis == X_AXIS || axis == Y_AXIS) {
1525
 
1525
 
1526
       float homeposition[3];
1526
       float homeposition[3];
1527
-      for (uint8_t i = X_AXIS; i <= Z_AXIS; i++)
1528
-        homeposition[i] = LOGICAL_POSITION(base_home_pos(i), i);
1527
+      LOOP_XYZ(i) homeposition[i] = LOGICAL_POSITION(base_home_pos(i), i);
1529
 
1528
 
1530
       // SERIAL_ECHOPGM("homeposition[x]= "); SERIAL_ECHO(homeposition[0]);
1529
       // SERIAL_ECHOPGM("homeposition[x]= "); SERIAL_ECHO(homeposition[0]);
1531
       // SERIAL_ECHOPGM("homeposition[y]= "); SERIAL_ECHOLN(homeposition[1]);
1530
       // SERIAL_ECHOPGM("homeposition[y]= "); SERIAL_ECHOLN(homeposition[1]);
2104
     return false;
2103
     return false;
2105
   }
2104
   }
2106
 
2105
 
2107
-  #if ENABLED(DELTA)
2108
-    #define SET_Z_FROM_STEPPERS() set_current_from_steppers()
2109
-  #else
2110
-    #define SET_Z_FROM_STEPPERS() current_position[Z_AXIS] = LOGICAL_POSITION(stepper.get_axis_position_mm(Z_AXIS), Z_AXIS)
2111
-  #endif
2112
-
2113
   // Do a single Z probe and return with current_position[Z_AXIS]
2106
   // Do a single Z probe and return with current_position[Z_AXIS]
2114
   // at the height where the probe triggered.
2107
   // at the height where the probe triggered.
2115
   static float run_z_probe() {
2108
   static float run_z_probe() {
2121
       planner.bed_level_matrix.set_to_identity();
2114
       planner.bed_level_matrix.set_to_identity();
2122
     #endif
2115
     #endif
2123
 
2116
 
2124
-    #if ENABLED(DELTA)
2125
-      float z_before = current_position[Z_AXIS],         // Current Z
2126
-            z_mm = stepper.get_axis_position_mm(Z_AXIS); // Some tower's current position
2127
-    #endif
2128
-
2129
     do_blocking_move_to_z(-(Z_MAX_LENGTH + 10), Z_PROBE_SPEED_FAST);
2117
     do_blocking_move_to_z(-(Z_MAX_LENGTH + 10), Z_PROBE_SPEED_FAST);
2130
     endstops.hit_on_purpose();
2118
     endstops.hit_on_purpose();
2131
-    SET_Z_FROM_STEPPERS();
2119
+    set_current_from_steppers_for_axis(Z_AXIS);
2132
     SYNC_PLAN_POSITION_KINEMATIC();
2120
     SYNC_PLAN_POSITION_KINEMATIC();
2133
 
2121
 
2134
     // move up the retract distance
2122
     // move up the retract distance
2135
     do_blocking_move_to_z(current_position[Z_AXIS] + home_bump_mm(Z_AXIS), Z_PROBE_SPEED_FAST);
2123
     do_blocking_move_to_z(current_position[Z_AXIS] + home_bump_mm(Z_AXIS), Z_PROBE_SPEED_FAST);
2136
 
2124
 
2137
-    #if ENABLED(DELTA)
2138
-      z_before = current_position[Z_AXIS];
2139
-      z_mm = stepper.get_axis_position_mm(Z_AXIS);
2140
-    #endif
2141
-
2142
     // move back down slowly to find bed
2125
     // move back down slowly to find bed
2143
     do_blocking_move_to_z(current_position[Z_AXIS] - home_bump_mm(Z_AXIS) * 2, Z_PROBE_SPEED_SLOW);
2126
     do_blocking_move_to_z(current_position[Z_AXIS] - home_bump_mm(Z_AXIS) * 2, Z_PROBE_SPEED_SLOW);
2144
     endstops.hit_on_purpose();
2127
     endstops.hit_on_purpose();
2145
-    SET_Z_FROM_STEPPERS();
2128
+    set_current_from_steppers_for_axis(Z_AXIS);
2146
     SYNC_PLAN_POSITION_KINEMATIC();
2129
     SYNC_PLAN_POSITION_KINEMATIC();
2147
 
2130
 
2148
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2131
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2597
  *  - Set the feedrate, if included
2580
  *  - Set the feedrate, if included
2598
  */
2581
  */
2599
 void gcode_get_destination() {
2582
 void gcode_get_destination() {
2600
-  for (int i = 0; i < NUM_AXIS; i++) {
2583
+  LOOP_XYZE(i) {
2601
     if (code_seen(axis_codes[i]))
2584
     if (code_seen(axis_codes[i]))
2602
       destination[i] = code_value_axis_units(i) + (axis_relative_modes[i] || relative_mode ? current_position[i] : 0);
2585
       destination[i] = code_value_axis_units(i) + (axis_relative_modes[i] || relative_mode ? current_position[i] : 0);
2603
     else
2586
     else
3900
   if (!didE) stepper.synchronize();
3883
   if (!didE) stepper.synchronize();
3901
 
3884
 
3902
   bool didXYZ = false;
3885
   bool didXYZ = false;
3903
-  for (int i = 0; i < NUM_AXIS; i++) {
3886
+  LOOP_XYZE(i) {
3904
     if (code_seen(axis_codes[i])) {
3887
     if (code_seen(axis_codes[i])) {
3905
       float p = current_position[i],
3888
       float p = current_position[i],
3906
             v = code_value_axis_units(i);
3889
             v = code_value_axis_units(i);
5147
  *      (Follows the same syntax as G92)
5130
  *      (Follows the same syntax as G92)
5148
  */
5131
  */
5149
 inline void gcode_M92() {
5132
 inline void gcode_M92() {
5150
-  for (int8_t i = 0; i < NUM_AXIS; i++) {
5133
+  LOOP_XYZE(i) {
5151
     if (code_seen(axis_codes[i])) {
5134
     if (code_seen(axis_codes[i])) {
5152
       if (i == E_AXIS) {
5135
       if (i == E_AXIS) {
5153
         float value = code_value_per_axis_unit(i);
5136
         float value = code_value_per_axis_unit(i);
5339
  * M201: Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
5322
  * M201: Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
5340
  */
5323
  */
5341
 inline void gcode_M201() {
5324
 inline void gcode_M201() {
5342
-  for (int8_t i = 0; i < NUM_AXIS; i++) {
5325
+  LOOP_XYZE(i) {
5343
     if (code_seen(axis_codes[i])) {
5326
     if (code_seen(axis_codes[i])) {
5344
       planner.max_acceleration_mm_per_s2[i] = code_value_axis_units(i);
5327
       planner.max_acceleration_mm_per_s2[i] = code_value_axis_units(i);
5345
     }
5328
     }
5350
 
5333
 
5351
 #if 0 // Not used for Sprinter/grbl gen6
5334
 #if 0 // Not used for Sprinter/grbl gen6
5352
   inline void gcode_M202() {
5335
   inline void gcode_M202() {
5353
-    for (int8_t i = 0; i < NUM_AXIS; i++) {
5336
+    LOOP_XYZE(i) {
5354
       if (code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value_axis_units(i) * planner.axis_steps_per_mm[i];
5337
       if (code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value_axis_units(i) * planner.axis_steps_per_mm[i];
5355
     }
5338
     }
5356
   }
5339
   }
5361
  * M203: Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in units/sec
5344
  * M203: Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in units/sec
5362
  */
5345
  */
5363
 inline void gcode_M203() {
5346
 inline void gcode_M203() {
5364
-  for (int8_t i = 0; i < NUM_AXIS; i++)
5347
+  LOOP_XYZE(i)
5365
     if (code_seen(axis_codes[i]))
5348
     if (code_seen(axis_codes[i]))
5366
       planner.max_feedrate_mm_s[i] = code_value_axis_units(i);
5349
       planner.max_feedrate_mm_s[i] = code_value_axis_units(i);
5367
 }
5350
 }
5421
  * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
5404
  * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
5422
  */
5405
  */
5423
 inline void gcode_M206() {
5406
 inline void gcode_M206() {
5424
-  for (int8_t i = X_AXIS; i <= Z_AXIS; i++)
5407
+  LOOP_XYZ(i)
5425
     if (code_seen(axis_codes[i]))
5408
     if (code_seen(axis_codes[i]))
5426
       set_home_offset((AxisEnum)i, code_value_axis_units(i));
5409
       set_home_offset((AxisEnum)i, code_value_axis_units(i));
5427
 
5410
 
5463
         SERIAL_ECHOLNPGM(">>> gcode_M666");
5446
         SERIAL_ECHOLNPGM(">>> gcode_M666");
5464
       }
5447
       }
5465
     #endif
5448
     #endif
5466
-    for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
5449
+    LOOP_XYZ(i) {
5467
       if (code_seen(axis_codes[i])) {
5450
       if (code_seen(axis_codes[i])) {
5468
         endstop_adj[i] = code_value_axis_units(i);
5451
         endstop_adj[i] = code_value_axis_units(i);
5469
         #if ENABLED(DEBUG_LEVELING_FEATURE)
5452
         #if ENABLED(DEBUG_LEVELING_FEATURE)
5955
    * M365: SCARA calibration: Scaling factor, X, Y, Z axis
5938
    * M365: SCARA calibration: Scaling factor, X, Y, Z axis
5956
    */
5939
    */
5957
   inline void gcode_M365() {
5940
   inline void gcode_M365() {
5958
-    for (int8_t i = X_AXIS; i <= Z_AXIS; i++)
5941
+    LOOP_XYZ(i)
5959
       if (code_seen(axis_codes[i]))
5942
       if (code_seen(axis_codes[i]))
5960
         axis_scaling[i] = code_value_float();
5943
         axis_scaling[i] = code_value_float();
5961
   }
5944
   }
6091
   stepper.quick_stop();
6074
   stepper.quick_stop();
6092
   #if DISABLED(SCARA)
6075
   #if DISABLED(SCARA)
6093
     stepper.synchronize();
6076
     stepper.synchronize();
6094
-    set_current_from_steppers();
6095
-    sync_plan_position();                       // ...re-apply to planner position
6077
+    LOOP_XYZ(i) set_current_from_steppers_for_axis((AxisEnum)i);
6078
+    SYNC_PLAN_POSITION_KINEMATIC();
6096
   #endif
6079
   #endif
6097
 }
6080
 }
6098
 
6081
 
6155
  */
6138
  */
6156
 inline void gcode_M428() {
6139
 inline void gcode_M428() {
6157
   bool err = false;
6140
   bool err = false;
6158
-  for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
6141
+  LOOP_XYZ(i) {
6159
     if (axis_homed[i]) {
6142
     if (axis_homed[i]) {
6160
       float base = (current_position[i] > (sw_endstop_min[i] + sw_endstop_max[i]) / 2) ? base_home_pos(i) : 0,
6143
       float base = (current_position[i] > (sw_endstop_min[i] + sw_endstop_max[i]) / 2) ? base_home_pos(i) : 0,
6161
             diff = current_position[i] - LOGICAL_POSITION(base, i);
6144
             diff = current_position[i] - LOGICAL_POSITION(base, i);
6285
     float lastpos[NUM_AXIS];
6268
     float lastpos[NUM_AXIS];
6286
 
6269
 
6287
     // Save current position of all axes
6270
     // Save current position of all axes
6288
-    for (uint8_t i = 0; i < NUM_AXIS; i++)
6271
+    LOOP_XYZE(i)
6289
       lastpos[i] = destination[i] = current_position[i];
6272
       lastpos[i] = destination[i] = current_position[i];
6290
 
6273
 
6291
     // Define runplan for move axes
6274
     // Define runplan for move axes
6506
  */
6489
  */
6507
 inline void gcode_M907() {
6490
 inline void gcode_M907() {
6508
   #if HAS_DIGIPOTSS
6491
   #if HAS_DIGIPOTSS
6509
-    for (int i = 0; i < NUM_AXIS; i++)
6492
+    LOOP_XYZE(i)
6510
       if (code_seen(axis_codes[i])) stepper.digipot_current(i, code_value_int());
6493
       if (code_seen(axis_codes[i])) stepper.digipot_current(i, code_value_int());
6511
     if (code_seen('B')) stepper.digipot_current(4, code_value_int());
6494
     if (code_seen('B')) stepper.digipot_current(4, code_value_int());
6512
     if (code_seen('S')) for (int i = 0; i <= 4; i++) stepper.digipot_current(i, code_value_int());
6495
     if (code_seen('S')) for (int i = 0; i <= 4; i++) stepper.digipot_current(i, code_value_int());
6522
   #endif
6505
   #endif
6523
   #if ENABLED(DIGIPOT_I2C)
6506
   #if ENABLED(DIGIPOT_I2C)
6524
     // this one uses actual amps in floating point
6507
     // this one uses actual amps in floating point
6525
-    for (int i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) digipot_i2c_set_current(i, code_value_float());
6508
+    LOOP_XYZE(i) if (code_seen(axis_codes[i])) digipot_i2c_set_current(i, code_value_float());
6526
     // for each additional extruder (named B,C,D,E..., channels 4,5,6,7...)
6509
     // for each additional extruder (named B,C,D,E..., channels 4,5,6,7...)
6527
     for (int i = NUM_AXIS; i < DIGIPOT_I2C_NUM_CHANNELS; i++) if (code_seen('B' + i - (NUM_AXIS))) digipot_i2c_set_current(i, code_value_float());
6510
     for (int i = NUM_AXIS; i < DIGIPOT_I2C_NUM_CHANNELS; i++) if (code_seen('B' + i - (NUM_AXIS))) digipot_i2c_set_current(i, code_value_float());
6528
   #endif
6511
   #endif
6531
       float dac_percent = code_value_float();
6514
       float dac_percent = code_value_float();
6532
       for (uint8_t i = 0; i <= 4; i++) dac_current_percent(i, dac_percent);
6515
       for (uint8_t i = 0; i <= 4; i++) dac_current_percent(i, dac_percent);
6533
     }
6516
     }
6534
-    for (uint8_t i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) dac_current_percent(i, code_value_float());
6517
+    LOOP_XYZE(i) if (code_seen(axis_codes[i])) dac_current_percent(i, code_value_float());
6535
   #endif
6518
   #endif
6536
 }
6519
 }
6537
 
6520
 
6570
   // M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
6553
   // M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
6571
   inline void gcode_M350() {
6554
   inline void gcode_M350() {
6572
     if (code_seen('S')) for (int i = 0; i <= 4; i++) stepper.microstep_mode(i, code_value_byte());
6555
     if (code_seen('S')) for (int i = 0; i <= 4; i++) stepper.microstep_mode(i, code_value_byte());
6573
-    for (int i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) stepper.microstep_mode(i, code_value_byte());
6556
+    LOOP_XYZE(i) if (code_seen(axis_codes[i])) stepper.microstep_mode(i, code_value_byte());
6574
     if (code_seen('B')) stepper.microstep_mode(4, code_value_byte());
6557
     if (code_seen('B')) stepper.microstep_mode(4, code_value_byte());
6575
     stepper.microstep_readings();
6558
     stepper.microstep_readings();
6576
   }
6559
   }
6582
   inline void gcode_M351() {
6565
   inline void gcode_M351() {
6583
     if (code_seen('S')) switch (code_value_byte()) {
6566
     if (code_seen('S')) switch (code_value_byte()) {
6584
       case 1:
6567
       case 1:
6585
-        for (int i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) stepper.microstep_ms(i, code_value_byte(), -1);
6568
+        LOOP_XYZE(i) if (code_seen(axis_codes[i])) stepper.microstep_ms(i, code_value_byte(), -1);
6586
         if (code_seen('B')) stepper.microstep_ms(4, code_value_byte(), -1);
6569
         if (code_seen('B')) stepper.microstep_ms(4, code_value_byte(), -1);
6587
         break;
6570
         break;
6588
       case 2:
6571
       case 2:
6589
-        for (int i = 0; i < NUM_AXIS; i++) if (code_seen(axis_codes[i])) stepper.microstep_ms(i, -1, code_value_byte());
6572
+        LOOP_XYZE(i) if (code_seen(axis_codes[i])) stepper.microstep_ms(i, -1, code_value_byte());
6590
         if (code_seen('B')) stepper.microstep_ms(4, -1, code_value_byte());
6573
         if (code_seen('B')) stepper.microstep_ms(4, -1, code_value_byte());
6591
         break;
6574
         break;
6592
     }
6575
     }
7929
 
7912
 
7930
 #endif // DELTA
7913
 #endif // DELTA
7931
 
7914
 
7932
-void set_current_from_steppers() {
7915
+void set_current_from_steppers_for_axis(AxisEnum axis) {
7933
   #if ENABLED(DELTA)
7916
   #if ENABLED(DELTA)
7934
     set_cartesian_from_steppers();
7917
     set_cartesian_from_steppers();
7935
-    current_position[X_AXIS] = cartesian_position[X_AXIS];
7936
-    current_position[Y_AXIS] = cartesian_position[Y_AXIS];
7937
-    current_position[Z_AXIS] = cartesian_position[Z_AXIS];
7918
+    current_position[axis] = LOGICAL_POSITION(cartesian_position[axis], axis);
7938
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
7919
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
7939
-    vector_3 pos = planner.adjusted_position(); // values directly from steppers...
7940
-    current_position[X_AXIS] = pos.x;
7941
-    current_position[Y_AXIS] = pos.y;
7942
-    current_position[Z_AXIS] = pos.z;
7920
+    vector_3 pos = planner.adjusted_position();
7921
+    current_position[axis] = LOGICAL_POSITION(axis == X_AXIS ? pos.x : axis == Y_AXIS ? pos.y : pos.z, axis);
7943
   #else
7922
   #else
7944
-    current_position[X_AXIS] = stepper.get_axis_position_mm(X_AXIS); // CORE handled transparently
7945
-    current_position[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
7946
-    current_position[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
7923
+    current_position[axis] = LOGICAL_POSITION(stepper.get_axis_position_mm(axis), axis); // CORE handled transparently
7947
   #endif
7924
   #endif
7948
-
7949
-  for (uint8_t i = X_AXIS; i <= Z_AXIS; i++)
7950
-    current_position[i] += LOGICAL_POSITION(0, i);
7951
 }
7925
 }
7952
 
7926
 
7953
 #if ENABLED(MESH_BED_LEVELING)
7927
 #if ENABLED(MESH_BED_LEVELING)
8013
 
7987
 
8014
   inline bool prepare_kinematic_move_to(float target[NUM_AXIS]) {
7988
   inline bool prepare_kinematic_move_to(float target[NUM_AXIS]) {
8015
     float difference[NUM_AXIS];
7989
     float difference[NUM_AXIS];
8016
-    for (int8_t i = 0; i < NUM_AXIS; i++) difference[i] = target[i] - current_position[i];
7990
+    LOOP_XYZE(i) difference[i] = target[i] - current_position[i];
8017
 
7991
 
8018
     float cartesian_mm = sqrt(sq(difference[X_AXIS]) + sq(difference[Y_AXIS]) + sq(difference[Z_AXIS]));
7992
     float cartesian_mm = sqrt(sq(difference[X_AXIS]) + sq(difference[Y_AXIS]) + sq(difference[Z_AXIS]));
8019
     if (cartesian_mm < 0.000001) cartesian_mm = abs(difference[E_AXIS]);
7993
     if (cartesian_mm < 0.000001) cartesian_mm = abs(difference[E_AXIS]);
8031
 
8005
 
8032
       float fraction = float(s) * inv_steps;
8006
       float fraction = float(s) * inv_steps;
8033
 
8007
 
8034
-      for (int8_t i = 0; i < NUM_AXIS; i++)
8008
+      LOOP_XYZE(i)
8035
         target[i] = current_position[i] + difference[i] * fraction;
8009
         target[i] = current_position[i] + difference[i] * fraction;
8036
 
8010
 
8037
       inverse_kinematics(target);
8011
       inverse_kinematics(target);

+ 1
- 1
Marlin/configuration_store.cpp 查看文件

563
   float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
563
   float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
564
   float tmp2[] = DEFAULT_MAX_FEEDRATE;
564
   float tmp2[] = DEFAULT_MAX_FEEDRATE;
565
   long tmp3[] = DEFAULT_MAX_ACCELERATION;
565
   long tmp3[] = DEFAULT_MAX_ACCELERATION;
566
-  for (uint8_t i = 0; i < NUM_AXIS; i++) {
566
+  LOOP_XYZE(i) {
567
     planner.axis_steps_per_mm[i] = tmp1[i];
567
     planner.axis_steps_per_mm[i] = tmp1[i];
568
     planner.max_feedrate_mm_s[i] = tmp2[i];
568
     planner.max_feedrate_mm_s[i] = tmp2[i];
569
     planner.max_acceleration_mm_per_s2[i] = tmp3[i];
569
     planner.max_acceleration_mm_per_s2[i] = tmp3[i];

+ 3
- 0
Marlin/enum.h 查看文件

45
   Z_HEAD  = 5
45
   Z_HEAD  = 5
46
 };
46
 };
47
 
47
 
48
+#define LOOP_XYZ(VAR)  for (uint8_t VAR=X_AXIS; VAR<=Z_AXIS; VAR++)
49
+#define LOOP_XYZE(VAR) for (uint8_t VAR=X_AXIS; VAR<=E_AXIS; VAR++)
50
+
48
 typedef enum {
51
 typedef enum {
49
   LINEARUNIT_MM,
52
   LINEARUNIT_MM,
50
   LINEARUNIT_INCH
53
   LINEARUNIT_INCH

+ 8
- 8
Marlin/planner.cpp 查看文件

134
 void Planner::init() {
134
 void Planner::init() {
135
   block_buffer_head = block_buffer_tail = 0;
135
   block_buffer_head = block_buffer_tail = 0;
136
   memset(position, 0, sizeof(position)); // clear position
136
   memset(position, 0, sizeof(position)); // clear position
137
-  for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = 0.0;
137
+  LOOP_XYZE(i) previous_speed[i] = 0.0;
138
   previous_nominal_speed = 0.0;
138
   previous_nominal_speed = 0.0;
139
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
139
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
140
     bed_level_matrix.set_to_identity();
140
     bed_level_matrix.set_to_identity();
423
 
423
 
424
     for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
424
     for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
425
       block = &block_buffer[b];
425
       block = &block_buffer[b];
426
-      for (int i = 0; i < NUM_AXIS; i++) if (block->steps[i]) axis_active[i]++;
426
+      LOOP_XYZE(i) if (block->steps[i]) axis_active[i]++;
427
     }
427
     }
428
   }
428
   }
429
   #if ENABLED(DISABLE_X)
429
   #if ENABLED(DISABLE_X)
893
   // Calculate and limit speed in mm/sec for each axis
893
   // Calculate and limit speed in mm/sec for each axis
894
   float current_speed[NUM_AXIS];
894
   float current_speed[NUM_AXIS];
895
   float speed_factor = 1.0; //factor <=1 do decrease speed
895
   float speed_factor = 1.0; //factor <=1 do decrease speed
896
-  for (int i = 0; i < NUM_AXIS; i++) {
896
+  LOOP_XYZE(i) {
897
     current_speed[i] = delta_mm[i] * inverse_second;
897
     current_speed[i] = delta_mm[i] * inverse_second;
898
     float cs = fabs(current_speed[i]), mf = max_feedrate_mm_s[i];
898
     float cs = fabs(current_speed[i]), mf = max_feedrate_mm_s[i];
899
     if (cs > mf) speed_factor = min(speed_factor, mf / cs);
899
     if (cs > mf) speed_factor = min(speed_factor, mf / cs);
939
 
939
 
940
   // Correct the speed
940
   // Correct the speed
941
   if (speed_factor < 1.0) {
941
   if (speed_factor < 1.0) {
942
-    for (unsigned char i = 0; i < NUM_AXIS; i++) current_speed[i] *= speed_factor;
942
+    LOOP_XYZE(i) current_speed[i] *= speed_factor;
943
     block->nominal_speed *= speed_factor;
943
     block->nominal_speed *= speed_factor;
944
     block->nominal_rate *= speed_factor;
944
     block->nominal_rate *= speed_factor;
945
   }
945
   }
1051
   block->recalculate_flag = true; // Always calculate trapezoid for new block
1051
   block->recalculate_flag = true; // Always calculate trapezoid for new block
1052
 
1052
 
1053
   // Update previous path unit_vector and nominal speed
1053
   // Update previous path unit_vector and nominal speed
1054
-  for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = current_speed[i];
1054
+  LOOP_XYZE(i) previous_speed[i] = current_speed[i];
1055
   previous_nominal_speed = block->nominal_speed;
1055
   previous_nominal_speed = block->nominal_speed;
1056
 
1056
 
1057
   #if ENABLED(LIN_ADVANCE)
1057
   #if ENABLED(LIN_ADVANCE)
1098
   block_buffer_head = next_buffer_head;
1098
   block_buffer_head = next_buffer_head;
1099
 
1099
 
1100
   // Update position
1100
   // Update position
1101
-  for (int i = 0; i < NUM_AXIS; i++) position[i] = target[i];
1101
+  LOOP_XYZE(i) position[i] = target[i];
1102
 
1102
 
1103
   recalculate();
1103
   recalculate();
1104
 
1104
 
1155
     stepper.set_position(nx, ny, nz, ne);
1155
     stepper.set_position(nx, ny, nz, ne);
1156
     previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1156
     previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1157
 
1157
 
1158
-    for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = 0.0;
1158
+    LOOP_XYZE(i) previous_speed[i] = 0.0;
1159
   }
1159
   }
1160
 
1160
 
1161
 /**
1161
 /**
1168
 
1168
 
1169
 // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
1169
 // Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
1170
 void Planner::reset_acceleration_rates() {
1170
 void Planner::reset_acceleration_rates() {
1171
-  for (int i = 0; i < NUM_AXIS; i++)
1171
+  LOOP_XYZE(i)
1172
     max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
1172
     max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
1173
 }
1173
 }
1174
 
1174
 

正在加载...
取消
保存