Browse Source

Planner class parity with 1.1.x

Scott Lahteine 7 years ago
parent
commit
a52fec6ac4
2 changed files with 39 additions and 35 deletions
  1. 32
    28
      Marlin/src/module/planner.cpp
  2. 7
    7
      Marlin/src/module/planner.h

+ 32
- 28
Marlin/src/module/planner.cpp View File

105
 
105
 
106
 int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
106
 int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
107
 
107
 
108
-// Initialized by settings.load()
109
-float Planner::e_factor[EXTRUDERS],              // The flow percentage and volumetric multiplier combine to scale E movement
110
-      Planner::filament_size[EXTRUDERS],         // As a baseline for the multiplier, filament diameter
108
+float Planner::e_factor[EXTRUDERS],               // The flow percentage and volumetric multiplier combine to scale E movement
109
+      Planner::filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
111
       Planner::volumetric_area_nominal = CIRCLE_AREA((DEFAULT_NOMINAL_FILAMENT_DIA) * 0.5), // Nominal cross-sectional area
110
       Planner::volumetric_area_nominal = CIRCLE_AREA((DEFAULT_NOMINAL_FILAMENT_DIA) * 0.5), // Nominal cross-sectional area
112
-      Planner::volumetric_multiplier[EXTRUDERS]; // May be auto-adjusted by a filament width sensor
111
+      Planner::volumetric_multiplier[EXTRUDERS];  // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
113
 
112
 
114
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
113
 uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
115
          Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
114
          Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
129
   #if ABL_PLANAR
128
   #if ABL_PLANAR
130
     matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
129
     matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
131
   #endif
130
   #endif
132
-#endif
133
-
134
-#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
135
-  float Planner::z_fade_height, // Initialized by settings.load()
136
-        Planner::inverse_z_fade_height,
137
-        Planner::last_fade_z;
131
+  #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
132
+    float Planner::z_fade_height,      // Initialized by settings.load()
133
+          Planner::inverse_z_fade_height,
134
+          Planner::last_fade_z;
135
+  #endif
138
 #endif
136
 #endif
139
 
137
 
140
 #if ENABLED(AUTOTEMP)
138
 #if ENABLED(AUTOTEMP)
571
    */
569
    */
572
   void Planner::apply_leveling(float &rx, float &ry, float &rz) {
570
   void Planner::apply_leveling(float &rx, float &ry, float &rz) {
573
 
571
 
574
-    if (!planner.leveling_active) return;
572
+    if (!leveling_active) return;
575
 
573
 
576
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
574
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
577
       const float fade_scaling_factor = fade_scaling_factor_for_z(rz);
575
       const float fade_scaling_factor = fade_scaling_factor_for_z(rz);
614
 
612
 
615
   void Planner::unapply_leveling(float raw[XYZ]) {
613
   void Planner::unapply_leveling(float raw[XYZ]) {
616
 
614
 
617
-    if (!planner.leveling_active) return;
615
+    if (!leveling_active) return;
618
 
616
 
619
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
617
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
620
-      if (z_fade_height && raw[Z_AXIS] >= z_fade_height) return;
618
+      if (!leveling_active_at_z(raw[Z_AXIS])) return;
621
     #endif
619
     #endif
622
 
620
 
623
     #if ENABLED(AUTO_BED_LEVELING_UBL)
621
     #if ENABLED(AUTO_BED_LEVELING_UBL)
624
 
622
 
625
-      const float z_correct = ubl.get_z_correction(raw[X_AXIS], raw[Y_AXIS]);
626
-            float z_raw = raw[Z_AXIS] - z_correct;
623
+      const float z_physical = raw[Z_AXIS],
624
+                  z_correct = ubl.get_z_correction(raw[X_AXIS], raw[Y_AXIS]),
625
+                  z_virtual = z_physical - z_correct;
626
+            float z_raw = z_virtual;
627
 
627
 
628
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
628
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
629
 
629
 
630
-        // for P=physical_z, L=raw_z, M=mesh_z, H=fade_height,
630
+        // for P=physical_z, L=logical_z, M=mesh_z, H=fade_height,
631
         // Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
631
         // Given P=L+M(1-L/H) (faded mesh correction formula for L<H)
632
         //  then L=P-M(1-L/H)
632
         //  then L=P-M(1-L/H)
633
         //    so L=P-M+ML/H
633
         //    so L=P-M+ML/H
637
 
637
 
638
         if (planner.z_fade_height) {
638
         if (planner.z_fade_height) {
639
           if (z_raw >= planner.z_fade_height)
639
           if (z_raw >= planner.z_fade_height)
640
-            z_raw = raw[Z_AXIS];
640
+            z_raw = z_physical;
641
           else
641
           else
642
             z_raw /= 1.0 - z_correct * planner.inverse_z_fade_height;
642
             z_raw /= 1.0 - z_correct * planner.inverse_z_fade_height;
643
         }
643
         }
646
 
646
 
647
       raw[Z_AXIS] = z_raw;
647
       raw[Z_AXIS] = z_raw;
648
 
648
 
649
-    #elif ENABLED(MESH_BED_LEVELING)
649
+      return; // don't fall thru to other ENABLE_LEVELING_FADE_HEIGHT logic
650
 
650
 
651
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
652
-        const float c = mbl.get_z(raw[X_AXIS], raw[Y_AXIS], 1.0);
653
-        raw[Z_AXIS] = (z_fade_height * (raw[Z_AXIS] - c)) / (z_fade_height - c);
654
-      #else
655
-        raw[Z_AXIS] -= mbl.get_z(raw[X_AXIS], raw[Y_AXIS]);
656
-      #endif
651
+    #endif
652
+
653
+    #if ENABLED(MESH_BED_LEVELING)
654
+
655
+      if (leveling_active) {
656
+        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
657
+          const float c = mbl.get_z(raw[X_AXIS], raw[Y_AXIS], 1.0);
658
+          raw[Z_AXIS] = (z_fade_height * (raw[Z_AXIS]) - c) / (z_fade_height - c);
659
+        #else
660
+          raw[Z_AXIS] -= mbl.get_z(raw[X_AXIS], raw[Y_AXIS]);
661
+        #endif
662
+      }
657
 
663
 
658
     #elif ABL_PLANAR
664
     #elif ABL_PLANAR
659
 
665
 
660
       matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
666
       matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
661
 
667
 
662
       float dx = raw[X_AXIS] - (X_TILT_FULCRUM),
668
       float dx = raw[X_AXIS] - (X_TILT_FULCRUM),
663
-            dy = raw[Y_AXIS] - (Y_TILT_FULCRUM),
664
-            dz = raw[Z_AXIS];
669
+            dy = raw[Y_AXIS] - (Y_TILT_FULCRUM);
665
 
670
 
666
-      apply_rotation_xyz(inverse, dx, dy, dz);
671
+      apply_rotation_xyz(inverse, dx, dy, raw[Z_AXIS]);
667
 
672
 
668
       raw[X_AXIS] = dx + X_TILT_FULCRUM;
673
       raw[X_AXIS] = dx + X_TILT_FULCRUM;
669
       raw[Y_AXIS] = dy + Y_TILT_FULCRUM;
674
       raw[Y_AXIS] = dy + Y_TILT_FULCRUM;
670
-      raw[Z_AXIS] = dz;
671
 
675
 
672
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
676
     #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
673
 
677
 

+ 7
- 7
Marlin/src/module/planner.h View File

144
       static uint8_t last_extruder;             // Respond to extruder change
144
       static uint8_t last_extruder;             // Respond to extruder change
145
     #endif
145
     #endif
146
 
146
 
147
-    static int16_t flow_percentage[EXTRUDERS];  // Extrusion factor for each extruder
147
+    static int16_t flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder
148
 
148
 
149
     static float e_factor[EXTRUDERS],               // The flow percentage and volumetric multiplier combine to scale E movement
149
     static float e_factor[EXTRUDERS],               // The flow percentage and volumetric multiplier combine to scale E movement
150
                  filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
150
                  filament_size[EXTRUDERS],          // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
167
                  min_travel_feedrate_mm_s;
167
                  min_travel_feedrate_mm_s;
168
 
168
 
169
     #if HAS_LEVELING
169
     #if HAS_LEVELING
170
-      static bool leveling_active;              // Flag that bed leveling is enabled
170
+      static bool leveling_active;          // Flag that bed leveling is enabled
171
       #if ABL_PLANAR
171
       #if ABL_PLANAR
172
         static matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
172
         static matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
173
       #endif
173
       #endif
342
     /**
342
     /**
343
      * Planner::_buffer_line
343
      * Planner::_buffer_line
344
      *
344
      *
345
-     * Add a new direct linear movement to the buffer.
345
+     * Add a new linear movement to the buffer in axis units.
346
      *
346
      *
347
-     * Leveling and kinematics should be applied ahead of this.
347
+     * Leveling and kinematics should be applied ahead of calling this.
348
      *
348
      *
349
-     *  a,b,c,e   - target position in mm or degrees
350
-     *  fr_mm_s   - (target) speed of the move (mm/s)
349
+     *  a,b,c,e   - target positions in mm and/or degrees
350
+     *  fr_mm_s   - (target) speed of the move
351
      *  extruder  - target extruder
351
      *  extruder  - target extruder
352
      */
352
      */
353
     static void _buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder);
353
     static void _buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder);
444
       if (blocks_queued()) {
444
       if (blocks_queued()) {
445
         block_t* block = &block_buffer[block_buffer_tail];
445
         block_t* block = &block_buffer[block_buffer_tail];
446
         #if ENABLED(ULTRA_LCD)
446
         #if ENABLED(ULTRA_LCD)
447
-          block_buffer_runtime_us -= block->segment_time_us; //We can't be sure how long an active block will take, so don't count it.
447
+          block_buffer_runtime_us -= block->segment_time_us; // We can't be sure how long an active block will take, so don't count it.
448
         #endif
448
         #endif
449
         SBI(block->flag, BLOCK_BIT_BUSY);
449
         SBI(block->flag, BLOCK_BIT_BUSY);
450
         return block;
450
         return block;

Loading…
Cancel
Save