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 8 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,7 +6988,7 @@ inline void gcode_M503() {
6988 6988
    */
6989 6989
   inline void gcode_M905() {
6990 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 6993
 #endif
6994 6994
 

+ 29
- 2
Marlin/planner.cpp View File

@@ -131,6 +131,11 @@ float Planner::previous_speed[NUM_AXIS],
131 131
   long Planner::axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
132 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 140
  * Class and Instance Methods
136 141
  */
@@ -140,6 +145,9 @@ Planner::Planner() { init(); }
140 145
 void Planner::init() {
141 146
   block_buffer_head = block_buffer_tail = 0;
142 147
   ZERO(position);
148
+  #if ENABLED(LIN_ADVANCE)
149
+    ZERO(position_float);
150
+  #endif
143 151
   ZERO(previous_speed);
144 152
   previous_nominal_speed = 0.0;
145 153
   #if ABL_PLANAR
@@ -604,6 +612,14 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
604 612
     lround(c * axis_steps_per_mm[Z_AXIS]),
605 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 624
   long da = target[X_AXIS] - position[X_AXIS],
609 625
        db = target[Y_AXIS] - position[Y_AXIS],
@@ -1232,12 +1248,12 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1232 1248
     // This leads to an enormous number of advance steps due to a huge e_acceleration.
1233 1249
     // The math is correct, but you don't want a retract move done with advance!
1234 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 1252
       block->use_advance_lead = false;
1237 1253
     }
1238 1254
     else {
1239 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 1259
   #elif ENABLED(ADVANCE)
@@ -1354,3 +1370,14 @@ void Planner::refresh_positioning() {
1354 1370
   }
1355 1371
 
1356 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,7 +95,7 @@ typedef struct {
95 95
   // Advance extrusion
96 96
   #if ENABLED(LIN_ADVANCE)
97 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 99
   #elif ENABLED(ADVANCE)
100 100
     int32_t advance_rate;
101 101
     volatile int32_t initial_advance;
@@ -196,6 +196,11 @@ class Planner {
196 196
       // Segment times (in µs). Used for speed calculations
197 197
       static long axis_segment_time[2][3];
198 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 205
   public:
201 206
 
@@ -245,6 +250,10 @@ class Planner {
245 250
       #define ARG_Z const float &lz
246 251
 
247 252
     #endif
253
+    
254
+    #if ENABLED(LIN_ADVANCE)
255
+      void advance_M905(const float &k);
256
+    #endif
248 257
 
249 258
     /**
250 259
      * Planner::_buffer_line

+ 6
- 18
Marlin/stepper.cpp View File

@@ -96,8 +96,7 @@ volatile uint32_t Stepper::step_events_completed = 0; // The number of step even
96 96
 
97 97
   #if ENABLED(LIN_ADVANCE)
98 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 100
         Stepper::current_estep_rate[E_STEPPERS],
102 101
         Stepper::current_adv_steps[E_STEPPERS];
103 102
   #else
@@ -534,7 +533,7 @@ void Stepper::isr() {
534 533
 
535 534
   #if ENABLED(LIN_ADVANCE)
536 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 537
       current_adv_steps[TOOL_E_INDEX] += delta_adv_steps;
539 538
       #if ENABLED(MIXING_EXTRUDER)
540 539
         // Mixing extruders apply advance lead proportionally
@@ -572,9 +571,9 @@ void Stepper::isr() {
572 571
       if (current_block->use_advance_lead) {
573 572
         #if ENABLED(MIXING_EXTRUDER)
574 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 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 577
         #endif
579 578
       }
580 579
 
@@ -624,9 +623,9 @@ void Stepper::isr() {
624 623
       if (current_block->use_advance_lead) {
625 624
         #if ENABLED(MIXING_EXTRUDER)
626 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 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 629
         #endif
631 630
       }
632 631
 
@@ -1350,14 +1349,3 @@ void Stepper::report_positions() {
1350 1349
   }
1351 1350
 
1352 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,7 +109,6 @@ class Stepper {
109 109
       static volatile unsigned char eISR_Rate;
110 110
       #if ENABLED(LIN_ADVANCE)
111 111
         static volatile int e_steps[E_STEPPERS];
112
-        static int extruder_advance_k;
113 112
         static int final_estep_rate;
114 113
         static int current_estep_rate[E_STEPPERS]; // Actual extruder speed [steps/s]
115 114
         static int current_adv_steps[E_STEPPERS];  // The amount of current added esteps due to advance.
@@ -277,11 +276,6 @@ class Stepper {
277 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 279
   private:
286 280
 
287 281
     static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
@@ -367,8 +361,8 @@ class Stepper {
367 361
       
368 362
       #if ENABLED(LIN_ADVANCE)
369 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 367
       #endif
374 368
 

Loading…
Cancel
Save