ソースを参照

Merge pull request #8698 from thinkyhead/bf2_replace_jerk_code

[2.0.x] Improved Core-compatible jerk code
Scott Lahteine 7年前
コミット
542efda7db
コミッターのメールアドレスに関連付けられたアカウントが存在しません
1個のファイルの変更11行の追加28行の削除
  1. 11
    28
      Marlin/src/module/planner.cpp

+ 11
- 28
Marlin/src/module/planner.cpp ファイルの表示

1090
     }
1090
     }
1091
   #endif
1091
   #endif
1092
 
1092
 
1093
-  // Calculate and limit speed in mm/sec for each axis
1093
+  // Calculate and limit speed in mm/sec for each axis, calculate minimum acceleration ratio
1094
   float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
1094
   float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
1095
+  float max_stepper_speed = 0, min_axis_accel_ratio = 1; // ratio < 1 means acceleration ramp needed
1095
   LOOP_XYZE(i) {
1096
   LOOP_XYZE(i) {
1096
     const float cs = FABS((current_speed[i] = delta_mm[i] * inverse_secs));
1097
     const float cs = FABS((current_speed[i] = delta_mm[i] * inverse_secs));
1098
+    NOMORE(min_axis_accel_ratio, max_jerk[i] / cs);
1099
+    NOLESS(max_stepper_speed, cs);
1097
     #if ENABLED(DISTINCT_E_FACTORS)
1100
     #if ENABLED(DISTINCT_E_FACTORS)
1098
       if (i == E_AXIS) i += extruder;
1101
       if (i == E_AXIS) i += extruder;
1099
     #endif
1102
     #endif
1138
     }
1141
     }
1139
   #endif // XY_FREQUENCY_LIMIT
1142
   #endif // XY_FREQUENCY_LIMIT
1140
 
1143
 
1144
+  block->nominal_speed = max_stepper_speed; // (mm/sec) Always > 0
1145
+  block->nominal_rate = CEIL(block->step_event_count * inverse_secs); // (step/sec) Always > 0
1146
+
1141
   // Correct the speed
1147
   // Correct the speed
1142
   if (speed_factor < 1.0) {
1148
   if (speed_factor < 1.0) {
1143
     LOOP_XYZE(i) current_speed[i] *= speed_factor;
1149
     LOOP_XYZE(i) current_speed[i] *= speed_factor;
1145
     block->nominal_rate *= speed_factor;
1151
     block->nominal_rate *= speed_factor;
1146
   }
1152
   }
1147
 
1153
 
1154
+  float safe_speed = block->nominal_speed * min_axis_accel_ratio;
1155
+  static float previous_safe_speed;
1156
+
1148
   // Compute and limit the acceleration rate for the trapezoid generator.
1157
   // Compute and limit the acceleration rate for the trapezoid generator.
1149
   const float steps_per_mm = block->step_event_count * inverse_millimeters;
1158
   const float steps_per_mm = block->step_event_count * inverse_millimeters;
1150
   uint32_t accel;
1159
   uint32_t accel;
1246
     }
1255
     }
1247
   #endif
1256
   #endif
1248
 
1257
 
1249
-  /**
1250
-   * Adapted from Průša MKS firmware
1251
-   * https://github.com/prusa3d/Prusa-Firmware
1252
-   *
1253
-   * Start with a safe speed (from which the machine may halt to stop immediately).
1254
-   */
1255
-
1256
-  // Exit speed limited by a jerk to full halt of a previous last segment
1257
-  static float previous_safe_speed;
1258
-
1259
-  float safe_speed = block->nominal_speed;
1260
-  uint8_t limited = 0;
1261
-  LOOP_XYZE(i) {
1262
-    const float jerk = FABS(current_speed[i]), maxj = max_jerk[i];
1263
-    if (jerk > maxj) {
1264
-      if (limited) {
1265
-        const float mjerk = maxj * block->nominal_speed;
1266
-        if (jerk * safe_speed > mjerk) safe_speed = mjerk / jerk;
1267
-      }
1268
-      else {
1269
-        ++limited;
1270
-        safe_speed = maxj;
1271
-      }
1272
-    }
1273
-  }
1274
-
1275
   if (moves_queued && !UNEAR_ZERO(previous_nominal_speed)) {
1258
   if (moves_queued && !UNEAR_ZERO(previous_nominal_speed)) {
1276
     // Estimate a maximum velocity allowed at a joint of two successive segments.
1259
     // Estimate a maximum velocity allowed at a joint of two successive segments.
1277
     // If this maximum velocity allowed is lower than the minimum of the entry / exit safe velocities,
1260
     // If this maximum velocity allowed is lower than the minimum of the entry / exit safe velocities,
1283
 
1266
 
1284
     // Factor to multiply the previous / current nominal velocities to get componentwise limited velocities.
1267
     // Factor to multiply the previous / current nominal velocities to get componentwise limited velocities.
1285
     float v_factor = 1;
1268
     float v_factor = 1;
1286
-    limited = 0;
1269
+    uint8_t limited = 0;
1287
 
1270
 
1288
     // Now limit the jerk in all axes.
1271
     // Now limit the jerk in all axes.
1289
     const float smaller_speed_factor = vmax_junction / previous_nominal_speed;
1272
     const float smaller_speed_factor = vmax_junction / previous_nominal_speed;

読み込み中…
キャンセル
保存