Browse Source

Improved Core-compatible jerk code

Scott Lahteine 7 years ago
parent
commit
3cd7659924
1 changed files with 11 additions and 28 deletions
  1. 11
    28
      Marlin/src/module/planner.cpp

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

@@ -1090,10 +1090,13 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1090 1090
     }
1091 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 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 1096
   LOOP_XYZE(i) {
1096 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 1100
     #if ENABLED(DISTINCT_E_FACTORS)
1098 1101
       if (i == E_AXIS) i += extruder;
1099 1102
     #endif
@@ -1138,6 +1141,9 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1138 1141
     }
1139 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 1147
   // Correct the speed
1142 1148
   if (speed_factor < 1.0) {
1143 1149
     LOOP_XYZE(i) current_speed[i] *= speed_factor;
@@ -1145,6 +1151,9 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1145 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 1157
   // Compute and limit the acceleration rate for the trapezoid generator.
1149 1158
   const float steps_per_mm = block->step_event_count * inverse_millimeters;
1150 1159
   uint32_t accel;
@@ -1246,32 +1255,6 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1246 1255
     }
1247 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 1258
   if (moves_queued && !UNEAR_ZERO(previous_nominal_speed)) {
1276 1259
     // Estimate a maximum velocity allowed at a joint of two successive segments.
1277 1260
     // If this maximum velocity allowed is lower than the minimum of the entry / exit safe velocities,
@@ -1283,7 +1266,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1283 1266
 
1284 1267
     // Factor to multiply the previous / current nominal velocities to get componentwise limited velocities.
1285 1268
     float v_factor = 1;
1286
-    limited = 0;
1269
+    uint8_t limited = 0;
1287 1270
 
1288 1271
     // Now limit the jerk in all axes.
1289 1272
     const float smaller_speed_factor = vmax_junction / previous_nominal_speed;

Loading…
Cancel
Save