Browse Source

BugFix for incorrect E-speed calculation

The extrusion speed was wrong due to a not high enough precision of
esteps to XY steps, therefore now the target float values are used to
calculate the ratio between XY movement and extrusion speed.
The e_speed_multiplier8 was replaced by an absolute multiplier called
abs_adv_steps_multiplier8, therefore one multiplication and bitshift can
be saved inside the stepper ISR. Due to this, also extruder_advance_k is
better suited inside the planner and not the stepper files any more.
Sebastianv650 7 years ago
parent
commit
f9bea7968f
5 changed files with 48 additions and 30 deletions
  1. 1
    1
      Marlin/Marlin_main.cpp
  2. 29
    2
      Marlin/planner.cpp
  3. 10
    1
      Marlin/planner.h
  4. 6
    18
      Marlin/stepper.cpp
  5. 2
    8
      Marlin/stepper.h

+ 1
- 1
Marlin/Marlin_main.cpp View File

6988
    */
6988
    */
6989
   inline void gcode_M905() {
6989
   inline void gcode_M905() {
6990
     stepper.synchronize();
6990
     stepper.synchronize();
6991
-    stepper.advance_M905(code_seen('K') ? code_value_float() : -1.0);
6991
+    planner.advance_M905(code_seen('K') ? code_value_float() : -1.0);
6992
   }
6992
   }
6993
 #endif
6993
 #endif
6994
 
6994
 

+ 29
- 2
Marlin/planner.cpp View File

131
   long Planner::axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
131
   long Planner::axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
132
 #endif
132
 #endif
133
 
133
 
134
+#if ENABLED(LIN_ADVANCE)
135
+  float Planner::extruder_advance_k = LIN_ADVANCE_K;
136
+  float Planner::position_float[NUM_AXIS] = { 0 };
137
+#endif
138
+
134
 /**
139
 /**
135
  * Class and Instance Methods
140
  * Class and Instance Methods
136
  */
141
  */
140
 void Planner::init() {
145
 void Planner::init() {
141
   block_buffer_head = block_buffer_tail = 0;
146
   block_buffer_head = block_buffer_tail = 0;
142
   ZERO(position);
147
   ZERO(position);
148
+  #if ENABLED(LIN_ADVANCE)
149
+    ZERO(position_float);
150
+  #endif
143
   ZERO(previous_speed);
151
   ZERO(previous_speed);
144
   previous_nominal_speed = 0.0;
152
   previous_nominal_speed = 0.0;
145
   #if ABL_PLANAR
153
   #if ABL_PLANAR
604
     lround(c * axis_steps_per_mm[Z_AXIS]),
612
     lround(c * axis_steps_per_mm[Z_AXIS]),
605
     lround(e * axis_steps_per_mm[E_AXIS])
613
     lround(e * axis_steps_per_mm[E_AXIS])
606
   };
614
   };
615
+  
616
+  #if ENABLED(LIN_ADVANCE)
617
+    float target_float[XYZE] = {a, b, c, e};
618
+    float de_float = target_float[E_AXIS] - position_float[E_AXIS];
619
+    float mm_D_float = sqrt(sq(target_float[X_AXIS] - position_float[X_AXIS]) + sq(target_float[Y_AXIS] - position_float[Y_AXIS]));
620
+    
621
+    memcpy(position_float, target_float, sizeof(position_float));
622
+  #endif
607
 
623
 
608
   long da = target[X_AXIS] - position[X_AXIS],
624
   long da = target[X_AXIS] - position[X_AXIS],
609
        db = target[Y_AXIS] - position[Y_AXIS],
625
        db = target[Y_AXIS] - position[Y_AXIS],
1232
     // This leads to an enormous number of advance steps due to a huge e_acceleration.
1248
     // This leads to an enormous number of advance steps due to a huge e_acceleration.
1233
     // The math is correct, but you don't want a retract move done with advance!
1249
     // The math is correct, but you don't want a retract move done with advance!
1234
     // So this situation is filtered out here.
1250
     // So this situation is filtered out here.
1235
-    if (!esteps || (!block->steps[X_AXIS] && !block->steps[Y_AXIS]) || stepper.get_advance_k() == 0 || (uint32_t)esteps == block->step_event_count) {
1251
+    if (!esteps || (!block->steps[X_AXIS] && !block->steps[Y_AXIS]) || extruder_advance_k == 0.0 || (uint32_t)esteps == block->step_event_count) {
1236
       block->use_advance_lead = false;
1252
       block->use_advance_lead = false;
1237
     }
1253
     }
1238
     else {
1254
     else {
1239
       block->use_advance_lead = true;
1255
       block->use_advance_lead = true;
1240
-      block->e_speed_multiplier8 = (esteps << 8) / block->step_event_count;
1256
+      block->abs_adv_steps_multiplier8 = lround(extruder_advance_k * (de_float / mm_D_float) * block->nominal_speed / (float)block->nominal_rate * axis_steps_per_mm[Z_AXIS] * 256.0);
1241
     }
1257
     }
1242
 
1258
 
1243
   #elif ENABLED(ADVANCE)
1259
   #elif ENABLED(ADVANCE)
1354
   }
1370
   }
1355
 
1371
 
1356
 #endif
1372
 #endif
1373
+
1374
+#if ENABLED(LIN_ADVANCE)
1375
+
1376
+  void Planner::advance_M905(const float &k) {
1377
+    if (k >= 0.0) extruder_advance_k = k;
1378
+    SERIAL_ECHO_START;
1379
+    SERIAL_ECHOPAIR("Advance factor: ", extruder_advance_k);
1380
+    SERIAL_EOL;
1381
+  }
1382
+
1383
+#endif

+ 10
- 1
Marlin/planner.h View File

95
   // Advance extrusion
95
   // Advance extrusion
96
   #if ENABLED(LIN_ADVANCE)
96
   #if ENABLED(LIN_ADVANCE)
97
     bool use_advance_lead;
97
     bool use_advance_lead;
98
-    int16_t e_speed_multiplier8; // Factorised by 2^8 to avoid float
98
+    uint32_t abs_adv_steps_multiplier8; // Factorised by 2^8 to avoid float
99
   #elif ENABLED(ADVANCE)
99
   #elif ENABLED(ADVANCE)
100
     int32_t advance_rate;
100
     int32_t advance_rate;
101
     volatile int32_t initial_advance;
101
     volatile int32_t initial_advance;
196
       // Segment times (in µs). Used for speed calculations
196
       // Segment times (in µs). Used for speed calculations
197
       static long axis_segment_time[2][3];
197
       static long axis_segment_time[2][3];
198
     #endif
198
     #endif
199
+    
200
+    #if ENABLED(LIN_ADVANCE)
201
+      static float position_float[NUM_AXIS];
202
+      static float extruder_advance_k;
203
+    #endif
199
 
204
 
200
   public:
205
   public:
201
 
206
 
245
       #define ARG_Z const float &lz
250
       #define ARG_Z const float &lz
246
 
251
 
247
     #endif
252
     #endif
253
+    
254
+    #if ENABLED(LIN_ADVANCE)
255
+      void advance_M905(const float &k);
256
+    #endif
248
 
257
 
249
     /**
258
     /**
250
      * Planner::_buffer_line
259
      * Planner::_buffer_line

+ 6
- 18
Marlin/stepper.cpp View File

96
 
96
 
97
   #if ENABLED(LIN_ADVANCE)
97
   #if ENABLED(LIN_ADVANCE)
98
     volatile int Stepper::e_steps[E_STEPPERS];
98
     volatile int Stepper::e_steps[E_STEPPERS];
99
-    int Stepper::extruder_advance_k = LIN_ADVANCE_K,
100
-        Stepper::final_estep_rate,
99
+    int Stepper::final_estep_rate,
101
         Stepper::current_estep_rate[E_STEPPERS],
100
         Stepper::current_estep_rate[E_STEPPERS],
102
         Stepper::current_adv_steps[E_STEPPERS];
101
         Stepper::current_adv_steps[E_STEPPERS];
103
   #else
102
   #else
534
 
533
 
535
   #if ENABLED(LIN_ADVANCE)
534
   #if ENABLED(LIN_ADVANCE)
536
     if (current_block->use_advance_lead) {
535
     if (current_block->use_advance_lead) {
537
-      int delta_adv_steps = (((long)extruder_advance_k * current_estep_rate[TOOL_E_INDEX]) >> 9) - current_adv_steps[TOOL_E_INDEX];
536
+      int delta_adv_steps = current_estep_rate[TOOL_E_INDEX] - current_adv_steps[TOOL_E_INDEX];
538
       current_adv_steps[TOOL_E_INDEX] += delta_adv_steps;
537
       current_adv_steps[TOOL_E_INDEX] += delta_adv_steps;
539
       #if ENABLED(MIXING_EXTRUDER)
538
       #if ENABLED(MIXING_EXTRUDER)
540
         // Mixing extruders apply advance lead proportionally
539
         // Mixing extruders apply advance lead proportionally
572
       if (current_block->use_advance_lead) {
571
       if (current_block->use_advance_lead) {
573
         #if ENABLED(MIXING_EXTRUDER)
572
         #if ENABLED(MIXING_EXTRUDER)
574
           MIXING_STEPPERS_LOOP(j)
573
           MIXING_STEPPERS_LOOP(j)
575
-            current_estep_rate[j] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
574
+            current_estep_rate[j] = ((uint32_t)acc_step_rate * current_block->abs_adv_steps_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 17;
576
         #else
575
         #else
577
-          current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
576
+          current_estep_rate[TOOL_E_INDEX] = ((uint32_t)acc_step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
578
         #endif
577
         #endif
579
       }
578
       }
580
 
579
 
624
       if (current_block->use_advance_lead) {
623
       if (current_block->use_advance_lead) {
625
         #if ENABLED(MIXING_EXTRUDER)
624
         #if ENABLED(MIXING_EXTRUDER)
626
           MIXING_STEPPERS_LOOP(j)
625
           MIXING_STEPPERS_LOOP(j)
627
-            current_estep_rate[j] = ((uint32_t)step_rate * current_block->e_speed_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 8;
626
+            current_estep_rate[j] = ((uint32_t)step_rate * current_block->abs_adv_steps_multiplier8 * current_block->step_event_count / current_block->mix_event_count[j]) >> 17;
628
         #else
627
         #else
629
-          current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->e_speed_multiplier8) >> 8;
628
+          current_estep_rate[TOOL_E_INDEX] = ((uint32_t)step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
630
         #endif
629
         #endif
631
       }
630
       }
632
 
631
 
1350
   }
1349
   }
1351
 
1350
 
1352
 #endif // HAS_MICROSTEPS
1351
 #endif // HAS_MICROSTEPS
1353
-
1354
-#if ENABLED(LIN_ADVANCE)
1355
-
1356
-  void Stepper::advance_M905(const float &k) {
1357
-    if (k >= 0) extruder_advance_k = k;
1358
-    SERIAL_ECHO_START;
1359
-    SERIAL_ECHOPAIR("Advance factor: ", extruder_advance_k);
1360
-    SERIAL_EOL;
1361
-  }
1362
-
1363
-#endif // LIN_ADVANCE

+ 2
- 8
Marlin/stepper.h View File

109
       static volatile unsigned char eISR_Rate;
109
       static volatile unsigned char eISR_Rate;
110
       #if ENABLED(LIN_ADVANCE)
110
       #if ENABLED(LIN_ADVANCE)
111
         static volatile int e_steps[E_STEPPERS];
111
         static volatile int e_steps[E_STEPPERS];
112
-        static int extruder_advance_k;
113
         static int final_estep_rate;
112
         static int final_estep_rate;
114
         static int current_estep_rate[E_STEPPERS]; // Actual extruder speed [steps/s]
113
         static int current_estep_rate[E_STEPPERS]; // Actual extruder speed [steps/s]
115
         static int current_adv_steps[E_STEPPERS];  // The amount of current added esteps due to advance.
114
         static int current_adv_steps[E_STEPPERS];  // The amount of current added esteps due to advance.
277
       return endstops_trigsteps[axis] * planner.steps_to_mm[axis];
276
       return endstops_trigsteps[axis] * planner.steps_to_mm[axis];
278
     }
277
     }
279
 
278
 
280
-    #if ENABLED(LIN_ADVANCE)
281
-      void advance_M905(const float &k);
282
-      FORCE_INLINE int get_advance_k() { return extruder_advance_k; }
283
-    #endif
284
-
285
   private:
279
   private:
286
 
280
 
287
     static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
281
     static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
367
       
361
       
368
       #if ENABLED(LIN_ADVANCE)
362
       #if ENABLED(LIN_ADVANCE)
369
         if (current_block->use_advance_lead) {
363
         if (current_block->use_advance_lead) {
370
-          current_estep_rate[current_block->active_extruder] = ((unsigned long)acc_step_rate * current_block->e_speed_multiplier8) >> 8;
371
-          final_estep_rate = (current_block->nominal_rate * current_block->e_speed_multiplier8) >> 8;
364
+          current_estep_rate[current_block->active_extruder] = ((unsigned long)acc_step_rate * current_block->abs_adv_steps_multiplier8) >> 17;
365
+          final_estep_rate = (current_block->nominal_rate * current_block->abs_adv_steps_multiplier8) >> 17;
372
         }
366
         }
373
       #endif
367
       #endif
374
 
368
 

Loading…
Cancel
Save