Pārlūkot izejas kodu

Fix long acceleration overflow

Scott Lahteine 4 gadus atpakaļ
vecāks
revīzija
d705a5b45e
2 mainītis faili ar 12 papildinājumiem un 13 dzēšanām
  1. 11
    12
      Marlin/src/module/planner.cpp
  2. 1
    1
      Marlin/src/module/planner.h

+ 11
- 12
Marlin/src/module/planner.cpp Parādīt failu

207
 
207
 
208
 xyze_long_t Planner::position{0};
208
 xyze_long_t Planner::position{0};
209
 
209
 
210
-uint32_t Planner::cutoff_long;
210
+uint32_t Planner::acceleration_long_cutoff;
211
 
211
 
212
 xyze_float_t Planner::previous_speed;
212
 xyze_float_t Planner::previous_speed;
213
 float Planner::previous_nominal_speed_sqr;
213
 float Planner::previous_nominal_speed_sqr;
2271
   // Compute and limit the acceleration rate for the trapezoid generator.
2271
   // Compute and limit the acceleration rate for the trapezoid generator.
2272
   const float steps_per_mm = block->step_event_count * inverse_millimeters;
2272
   const float steps_per_mm = block->step_event_count * inverse_millimeters;
2273
   uint32_t accel;
2273
   uint32_t accel;
2274
-  if (!block->steps.a && !block->steps.b && !block->steps.c) {
2275
-    // convert to: acceleration steps/sec^2
2276
-    accel = CEIL(settings.retract_acceleration * steps_per_mm);
2277
-    TERN_(LIN_ADVANCE, block->use_advance_lead = false);
2274
+  if (!block->steps.a && !block->steps.b && !block->steps.c) {    // Is this a retract / recover move?
2275
+    accel = CEIL(settings.retract_acceleration * steps_per_mm);   // Convert to: acceleration steps/sec^2
2276
+    TERN_(LIN_ADVANCE, block->use_advance_lead = false);          // No linear advance for simple retract/recover
2278
   }
2277
   }
2279
   else {
2278
   else {
2280
     #define LIMIT_ACCEL_LONG(AXIS,INDX) do{ \
2279
     #define LIMIT_ACCEL_LONG(AXIS,INDX) do{ \
2281
       if (block->steps[AXIS] && max_acceleration_steps_per_s2[AXIS+INDX] < accel) { \
2280
       if (block->steps[AXIS] && max_acceleration_steps_per_s2[AXIS+INDX] < accel) { \
2282
-        const uint32_t comp = max_acceleration_steps_per_s2[AXIS+INDX] * block->step_event_count; \
2283
-        if (accel * block->steps[AXIS] > comp) accel = comp / block->steps[AXIS]; \
2281
+        const uint32_t max_possible = max_acceleration_steps_per_s2[AXIS+INDX] * block->step_event_count / block->steps[AXIS]; \
2282
+        NOMORE(accel, max_possible); \
2284
       } \
2283
       } \
2285
     }while(0)
2284
     }while(0)
2286
 
2285
 
2287
     #define LIMIT_ACCEL_FLOAT(AXIS,INDX) do{ \
2286
     #define LIMIT_ACCEL_FLOAT(AXIS,INDX) do{ \
2288
       if (block->steps[AXIS] && max_acceleration_steps_per_s2[AXIS+INDX] < accel) { \
2287
       if (block->steps[AXIS] && max_acceleration_steps_per_s2[AXIS+INDX] < accel) { \
2289
-        const float comp = (float)max_acceleration_steps_per_s2[AXIS+INDX] * (float)block->step_event_count; \
2290
-        if ((float)accel * (float)block->steps[AXIS] > comp) accel = comp / (float)block->steps[AXIS]; \
2288
+        const float max_possible = float(max_acceleration_steps_per_s2[AXIS+INDX]) * float(block->step_event_count) / float(block->steps[AXIS]); \
2289
+        NOMORE(accel, max_possible); \
2291
       } \
2290
       } \
2292
     }while(0)
2291
     }while(0)
2293
 
2292
 
2336
     #endif
2335
     #endif
2337
 
2336
 
2338
     // Limit acceleration per axis
2337
     // Limit acceleration per axis
2339
-    if (block->step_event_count <= cutoff_long) {
2338
+    if (block->step_event_count <= acceleration_long_cutoff) {
2340
       LIMIT_ACCEL_LONG(A_AXIS, 0);
2339
       LIMIT_ACCEL_LONG(A_AXIS, 0);
2341
       LIMIT_ACCEL_LONG(B_AXIS, 0);
2340
       LIMIT_ACCEL_LONG(B_AXIS, 0);
2342
       LIMIT_ACCEL_LONG(C_AXIS, 0);
2341
       LIMIT_ACCEL_LONG(C_AXIS, 0);
2352
   block->acceleration_steps_per_s2 = accel;
2351
   block->acceleration_steps_per_s2 = accel;
2353
   block->acceleration = accel / steps_per_mm;
2352
   block->acceleration = accel / steps_per_mm;
2354
   #if DISABLED(S_CURVE_ACCELERATION)
2353
   #if DISABLED(S_CURVE_ACCELERATION)
2355
-    block->acceleration_rate = (uint32_t)(accel * (4096.0f * 4096.0f / (STEPPER_TIMER_RATE)));
2354
+    block->acceleration_rate = (uint32_t)(accel * (sq(4096.0f) / (STEPPER_TIMER_RATE)));
2356
   #endif
2355
   #endif
2357
   #if ENABLED(LIN_ADVANCE)
2356
   #if ENABLED(LIN_ADVANCE)
2358
     if (block->use_advance_lead) {
2357
     if (block->use_advance_lead) {
3020
     max_acceleration_steps_per_s2[i] = settings.max_acceleration_mm_per_s2[i] * settings.axis_steps_per_mm[i];
3019
     max_acceleration_steps_per_s2[i] = settings.max_acceleration_mm_per_s2[i] * settings.axis_steps_per_mm[i];
3021
     if (AXIS_CONDITION) NOLESS(highest_rate, max_acceleration_steps_per_s2[i]);
3020
     if (AXIS_CONDITION) NOLESS(highest_rate, max_acceleration_steps_per_s2[i]);
3022
   }
3021
   }
3023
-  cutoff_long = 4294967295UL / highest_rate; // 0xFFFFFFFFUL
3022
+  acceleration_long_cutoff = 4294967295UL / highest_rate; // 0xFFFFFFFFUL
3024
   TERN_(HAS_LINEAR_E_JERK, recalculate_max_e_jerk());
3023
   TERN_(HAS_LINEAR_E_JERK, recalculate_max_e_jerk());
3025
 }
3024
 }
3026
 
3025
 

+ 1
- 1
Marlin/src/module/planner.h Parādīt failu

443
     /**
443
     /**
444
      * Limit where 64bit math is necessary for acceleration calculation
444
      * Limit where 64bit math is necessary for acceleration calculation
445
      */
445
      */
446
-    static uint32_t cutoff_long;
446
+    static uint32_t acceleration_long_cutoff;
447
 
447
 
448
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
448
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
449
       static float last_fade_z;
449
       static float last_fade_z;

Notiek ielāde…
Atcelt
Saglabāt