Browse Source

Planner singleton class

Scott Lahteine 8 years ago
parent
commit
96f51f400f
10 changed files with 598 additions and 510 deletions
  1. 6
    0
      Marlin/Marlin.h
  2. 94
    98
      Marlin/Marlin_main.cpp
  3. 73
    73
      Marlin/configuration_store.cpp
  4. 147
    203
      Marlin/planner.cpp
  5. 228
    92
      Marlin/planner.h
  6. 6
    6
      Marlin/stepper.cpp
  7. 1
    1
      Marlin/stepper.h
  8. 1
    1
      Marlin/temperature.cpp
  9. 7
    3
      Marlin/temperature.h
  10. 35
    33
      Marlin/ultralcd.cpp

+ 6
- 0
Marlin/Marlin.h View File

283
 extern bool axis_known_position[3]; // axis[n].is_known
283
 extern bool axis_known_position[3]; // axis[n].is_known
284
 extern bool axis_homed[3]; // axis[n].is_homed
284
 extern bool axis_homed[3]; // axis[n].is_homed
285
 
285
 
286
+// GCode support for external objects
287
+extern bool code_seen(char);
288
+extern float code_value();
289
+extern long code_value_long();
290
+extern int16_t code_value_short();
291
+
286
 #if ENABLED(DELTA)
292
 #if ENABLED(DELTA)
287
   #ifndef DELTA_RADIUS_TRIM_TOWER_1
293
   #ifndef DELTA_RADIUS_TRIM_TOWER_1
288
     #define DELTA_RADIUS_TRIM_TOWER_1 0.0
294
     #define DELTA_RADIUS_TRIM_TOWER_1 0.0

+ 94
- 98
Marlin/Marlin_main.cpp View File

149
  * M84  - Disable steppers until next move,
149
  * M84  - Disable steppers until next move,
150
  *        or use S<seconds> to specify an inactivity timeout, after which the steppers will be disabled.  S0 to disable the timeout.
150
  *        or use S<seconds> to specify an inactivity timeout, after which the steppers will be disabled.  S0 to disable the timeout.
151
  * M85  - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
151
  * M85  - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
152
- * M92  - Set axis_steps_per_unit - same syntax as G92
152
+ * M92  - Set planner.axis_steps_per_unit - same syntax as G92
153
  * M104 - Set extruder target temp
153
  * M104 - Set extruder target temp
154
  * M105 - Read current temp
154
  * M105 - Read current temp
155
  * M106 - Fan on
155
  * M106 - Fan on
540
       if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position_delta", current_position);
540
       if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position_delta", current_position);
541
     #endif
541
     #endif
542
     calculate_delta(current_position);
542
     calculate_delta(current_position);
543
-    plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
543
+    planner.set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
544
   }
544
   }
545
 #endif
545
 #endif
546
 
546
 
817
   lcd_init();
817
   lcd_init();
818
 
818
 
819
   tp_init();    // Initialize temperature loop
819
   tp_init();    // Initialize temperature loop
820
-  plan_init();  // Initialize planner;
821
 
820
 
822
   #if ENABLED(DELTA) || ENABLED(SCARA)
821
   #if ENABLED(DELTA) || ENABLED(SCARA)
823
     // Vital to init kinematic equivalent for X0 Y0 Z0
822
     // Vital to init kinematic equivalent for X0 Y0 Z0
1405
 // (or from wherever it has been told it is located).
1404
 // (or from wherever it has been told it is located).
1406
 //
1405
 //
1407
 inline void line_to_current_position() {
1406
 inline void line_to_current_position() {
1408
-  plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder);
1407
+  planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate / 60, active_extruder);
1409
 }
1408
 }
1410
 inline void line_to_z(float zPosition) {
1409
 inline void line_to_z(float zPosition) {
1411
-  plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate / 60, active_extruder);
1410
+  planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], zPosition, current_position[E_AXIS], feedrate / 60, active_extruder);
1412
 }
1411
 }
1413
 //
1412
 //
1414
 // line_to_destination
1413
 // line_to_destination
1415
 // Move the planner, not necessarily synced with current_position
1414
 // Move the planner, not necessarily synced with current_position
1416
 //
1415
 //
1417
 inline void line_to_destination(float mm_m) {
1416
 inline void line_to_destination(float mm_m) {
1418
-  plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], mm_m / 60, active_extruder);
1417
+  planner.buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], mm_m / 60, active_extruder);
1419
 }
1418
 }
1420
 inline void line_to_destination() {
1419
 inline void line_to_destination() {
1421
   line_to_destination(feedrate);
1420
   line_to_destination(feedrate);
1430
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1429
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1431
     if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position);
1430
     if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position);
1432
   #endif
1431
   #endif
1433
-  plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1432
+  planner.set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1434
 }
1433
 }
1435
-inline void sync_plan_position_e() { plan_set_e_position(current_position[E_AXIS]); }
1434
+inline void sync_plan_position_e() { planner.set_e_position(current_position[E_AXIS]); }
1436
 inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); }
1435
 inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); }
1437
 inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); }
1436
 inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); }
1438
 
1437
 
1459
       #endif
1458
       #endif
1460
       refresh_cmd_timeout();
1459
       refresh_cmd_timeout();
1461
       calculate_delta(destination);
1460
       calculate_delta(destination);
1462
-      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], (feedrate / 60) * (feedrate_multiplier / 100.0), active_extruder);
1461
+      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], (feedrate / 60) * (feedrate_multiplier / 100.0), active_extruder);
1463
       set_current_to_destination();
1462
       set_current_to_destination();
1464
     }
1463
     }
1465
   #endif
1464
   #endif
1470
 
1469
 
1471
       static void set_bed_level_equation_lsq(double* plane_equation_coefficients) {
1470
       static void set_bed_level_equation_lsq(double* plane_equation_coefficients) {
1472
 
1471
 
1473
-        //plan_bed_level_matrix.debug("bed level before");
1472
+        //planner.bed_level_matrix.debug("bed level before");
1474
 
1473
 
1475
         #if ENABLED(DEBUG_LEVELING_FEATURE)
1474
         #if ENABLED(DEBUG_LEVELING_FEATURE)
1476
-          plan_bed_level_matrix.set_to_identity();
1475
+          planner.bed_level_matrix.set_to_identity();
1477
           if (DEBUGGING(LEVELING)) {
1476
           if (DEBUGGING(LEVELING)) {
1478
-            vector_3 uncorrected_position = plan_get_position();
1477
+            vector_3 uncorrected_position = planner.adjusted_position();
1479
             DEBUG_POS(">>> set_bed_level_equation_lsq", uncorrected_position);
1478
             DEBUG_POS(">>> set_bed_level_equation_lsq", uncorrected_position);
1480
             DEBUG_POS(">>> set_bed_level_equation_lsq", current_position);
1479
             DEBUG_POS(">>> set_bed_level_equation_lsq", current_position);
1481
           }
1480
           }
1482
         #endif
1481
         #endif
1483
 
1482
 
1484
         vector_3 planeNormal = vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1);
1483
         vector_3 planeNormal = vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1);
1485
-        plan_bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
1484
+        planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
1486
 
1485
 
1487
-        vector_3 corrected_position = plan_get_position();
1486
+        vector_3 corrected_position = planner.adjusted_position();
1488
         current_position[X_AXIS] = corrected_position.x;
1487
         current_position[X_AXIS] = corrected_position.x;
1489
         current_position[Y_AXIS] = corrected_position.y;
1488
         current_position[Y_AXIS] = corrected_position.y;
1490
         current_position[Z_AXIS] = corrected_position.z;
1489
         current_position[Z_AXIS] = corrected_position.z;
1502
 
1501
 
1503
     static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float z_at_pt_3) {
1502
     static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float z_at_pt_3) {
1504
 
1503
 
1505
-      plan_bed_level_matrix.set_to_identity();
1504
+      planner.bed_level_matrix.set_to_identity();
1506
 
1505
 
1507
       vector_3 pt1 = vector_3(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, z_at_pt_1);
1506
       vector_3 pt1 = vector_3(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, z_at_pt_1);
1508
       vector_3 pt2 = vector_3(ABL_PROBE_PT_2_X, ABL_PROBE_PT_2_Y, z_at_pt_2);
1507
       vector_3 pt2 = vector_3(ABL_PROBE_PT_2_X, ABL_PROBE_PT_2_Y, z_at_pt_2);
1515
         planeNormal.z = -planeNormal.z;
1514
         planeNormal.z = -planeNormal.z;
1516
       }
1515
       }
1517
 
1516
 
1518
-      plan_bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
1517
+      planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
1519
 
1518
 
1520
-      vector_3 corrected_position = plan_get_position();
1519
+      vector_3 corrected_position = planner.adjusted_position();
1521
 
1520
 
1522
       #if ENABLED(DEBUG_LEVELING_FEATURE)
1521
       #if ENABLED(DEBUG_LEVELING_FEATURE)
1523
         if (DEBUGGING(LEVELING)) {
1522
         if (DEBUGGING(LEVELING)) {
1568
        * is not where we said to go.
1567
        * is not where we said to go.
1569
        */
1568
        */
1570
       long stop_steps = stepper.position(Z_AXIS);
1569
       long stop_steps = stepper.position(Z_AXIS);
1571
-      float mm = start_z - float(start_steps - stop_steps) / axis_steps_per_unit[Z_AXIS];
1570
+      float mm = start_z - float(start_steps - stop_steps) / planner.axis_steps_per_unit[Z_AXIS];
1572
       current_position[Z_AXIS] = mm;
1571
       current_position[Z_AXIS] = mm;
1573
 
1572
 
1574
       #if ENABLED(DEBUG_LEVELING_FEATURE)
1573
       #if ENABLED(DEBUG_LEVELING_FEATURE)
1579
 
1578
 
1580
     #else // !DELTA
1579
     #else // !DELTA
1581
 
1580
 
1582
-      plan_bed_level_matrix.set_to_identity();
1581
+      planner.bed_level_matrix.set_to_identity();
1583
       feedrate = homing_feedrate[Z_AXIS];
1582
       feedrate = homing_feedrate[Z_AXIS];
1584
 
1583
 
1585
       // Move down until the Z probe (or endstop?) is triggered
1584
       // Move down until the Z probe (or endstop?) is triggered
1589
 
1588
 
1590
       // Tell the planner where we ended up - Get this from the stepper handler
1589
       // Tell the planner where we ended up - Get this from the stepper handler
1591
       zPosition = stepper.get_axis_position_mm(Z_AXIS);
1590
       zPosition = stepper.get_axis_position_mm(Z_AXIS);
1592
-      plan_set_position(
1591
+      planner.set_position(
1593
         current_position[X_AXIS], current_position[Y_AXIS], zPosition,
1592
         current_position[X_AXIS], current_position[Y_AXIS], zPosition,
1594
         current_position[E_AXIS]
1593
         current_position[E_AXIS]
1595
       );
1594
       );
2552
 
2551
 
2553
   // For auto bed leveling, clear the level matrix
2552
   // For auto bed leveling, clear the level matrix
2554
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
2553
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
2555
-    plan_bed_level_matrix.set_to_identity();
2554
+    planner.bed_level_matrix.set_to_identity();
2556
     #if ENABLED(DELTA)
2555
     #if ENABLED(DELTA)
2557
       reset_bed_level();
2556
       reset_bed_level();
2558
     #endif
2557
     #endif
2630
       // Raise Z before homing any other axes and z is not already high enough (never lower z)
2629
       // Raise Z before homing any other axes and z is not already high enough (never lower z)
2631
       if (current_position[Z_AXIS] <= MIN_Z_HEIGHT_FOR_HOMING) {
2630
       if (current_position[Z_AXIS] <= MIN_Z_HEIGHT_FOR_HOMING) {
2632
         destination[Z_AXIS] = MIN_Z_HEIGHT_FOR_HOMING;
2631
         destination[Z_AXIS] = MIN_Z_HEIGHT_FOR_HOMING;
2633
-        feedrate = max_feedrate[Z_AXIS] * 60;  // feedrate (mm/m) = max_feedrate (mm/s)
2632
+        feedrate = planner.max_feedrate[Z_AXIS] * 60;  // feedrate (mm/m) = max_feedrate (mm/s)
2634
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2633
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2635
           if (DEBUGGING(LEVELING)) {
2634
           if (DEBUGGING(LEVELING)) {
2636
             SERIAL_ECHOPAIR("Raise Z (before homing) to ", (MIN_Z_HEIGHT_FOR_HOMING));
2635
             SERIAL_ECHOPAIR("Raise Z (before homing) to ", (MIN_Z_HEIGHT_FOR_HOMING));
3201
 
3200
 
3202
       #if ENABLED(DEBUG_LEVELING_FEATURE) && DISABLED(DELTA)
3201
       #if ENABLED(DEBUG_LEVELING_FEATURE) && DISABLED(DELTA)
3203
         if (DEBUGGING(LEVELING)) {
3202
         if (DEBUGGING(LEVELING)) {
3204
-          vector_3 corrected_position = plan_get_position();
3203
+          vector_3 corrected_position = planner.adjusted_position();
3205
           DEBUG_POS("BEFORE matrix.set_to_identity", corrected_position);
3204
           DEBUG_POS("BEFORE matrix.set_to_identity", corrected_position);
3206
           DEBUG_POS("BEFORE matrix.set_to_identity", current_position);
3205
           DEBUG_POS("BEFORE matrix.set_to_identity", current_position);
3207
         }
3206
         }
3208
       #endif
3207
       #endif
3209
 
3208
 
3210
       // make sure the bed_level_rotation_matrix is identity or the planner will get it wrong
3209
       // make sure the bed_level_rotation_matrix is identity or the planner will get it wrong
3211
-      plan_bed_level_matrix.set_to_identity();
3210
+      planner.bed_level_matrix.set_to_identity();
3212
 
3211
 
3213
       #if ENABLED(DELTA)
3212
       #if ENABLED(DELTA)
3214
         reset_bed_level();
3213
         reset_bed_level();
3215
       #else //!DELTA
3214
       #else //!DELTA
3216
 
3215
 
3217
-        //vector_3 corrected_position = plan_get_position();
3216
+        //vector_3 corrected_position = planner.adjusted_position();
3218
         //corrected_position.debug("position before G29");
3217
         //corrected_position.debug("position before G29");
3219
-        vector_3 uncorrected_position = plan_get_position();
3218
+        vector_3 uncorrected_position = planner.adjusted_position();
3220
         //uncorrected_position.debug("position during G29");
3219
         //uncorrected_position.debug("position during G29");
3221
         current_position[X_AXIS] = uncorrected_position.x;
3220
         current_position[X_AXIS] = uncorrected_position.x;
3222
         current_position[Y_AXIS] = uncorrected_position.y;
3221
         current_position[Y_AXIS] = uncorrected_position.y;
3415
                     y_tmp = eqnAMatrix[ind + 1 * abl2],
3414
                     y_tmp = eqnAMatrix[ind + 1 * abl2],
3416
                     z_tmp = 0;
3415
                     z_tmp = 0;
3417
 
3416
 
3418
-              apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp);
3417
+              apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
3419
 
3418
 
3420
               NOMORE(min_diff, eqnBVector[ind] - z_tmp);
3419
               NOMORE(min_diff, eqnBVector[ind] - z_tmp);
3421
 
3420
 
3438
                       y_tmp = eqnAMatrix[ind + 1 * abl2],
3437
                       y_tmp = eqnAMatrix[ind + 1 * abl2],
3439
                       z_tmp = 0;
3438
                       z_tmp = 0;
3440
 
3439
 
3441
-                apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp);
3440
+                apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
3442
 
3441
 
3443
                 float diff = eqnBVector[ind] - z_tmp - min_diff;
3442
                 float diff = eqnBVector[ind] - z_tmp - min_diff;
3444
                 if (diff >= 0.0)
3443
                 if (diff >= 0.0)
3497
       #endif
3496
       #endif
3498
     #else // !DELTA
3497
     #else // !DELTA
3499
       if (verbose_level > 0)
3498
       if (verbose_level > 0)
3500
-        plan_bed_level_matrix.debug(" \n\nBed Level Correction Matrix:");
3499
+        planner.bed_level_matrix.debug(" \n\nBed Level Correction Matrix:");
3501
 
3500
 
3502
       if (!dryrun) {
3501
       if (!dryrun) {
3503
         /**
3502
         /**
3508
         float x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
3507
         float x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
3509
               y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
3508
               y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
3510
               z_tmp = current_position[Z_AXIS],
3509
               z_tmp = current_position[Z_AXIS],
3511
-              real_z = stepper.get_axis_position_mm(Z_AXIS);  //get the real Z (since plan_get_position is now correcting the plane)
3510
+              real_z = stepper.get_axis_position_mm(Z_AXIS);  //get the real Z (since planner.adjusted_position is now correcting the plane)
3512
 
3511
 
3513
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3512
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3514
           if (DEBUGGING(LEVELING)) {
3513
           if (DEBUGGING(LEVELING)) {
3520
         #endif
3519
         #endif
3521
 
3520
 
3522
         // Apply the correction sending the Z probe offset
3521
         // Apply the correction sending the Z probe offset
3523
-        apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp);
3522
+        apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
3524
 
3523
 
3525
         /*
3524
         /*
3526
          * Get the current Z position and send it to the planner.
3525
          * Get the current Z position and send it to the planner.
3527
          *
3526
          *
3528
          * >> (z_tmp - real_z) : The rotated current Z minus the uncorrected Z
3527
          * >> (z_tmp - real_z) : The rotated current Z minus the uncorrected Z
3529
-         * (most recent plan_set_position/sync_plan_position)
3528
+         * (most recent planner.set_position/sync_plan_position)
3530
          *
3529
          *
3531
          * >> zprobe_zoffset : Z distance from nozzle to Z probe
3530
          * >> zprobe_zoffset : Z distance from nozzle to Z probe
3532
          * (set by default, M851, EEPROM, or Menu)
3531
          * (set by default, M851, EEPROM, or Menu)
4065
       reset_bed_level();
4064
       reset_bed_level();
4066
     #else
4065
     #else
4067
       // we don't do bed level correction in M48 because we want the raw data when we probe
4066
       // we don't do bed level correction in M48 because we want the raw data when we probe
4068
-      plan_bed_level_matrix.set_to_identity();
4067
+      planner.bed_level_matrix.set_to_identity();
4069
     #endif
4068
     #endif
4070
 
4069
 
4071
     if (Z_start_location < Z_RAISE_BEFORE_PROBING * 2.0)
4070
     if (Z_start_location < Z_RAISE_BEFORE_PROBING * 2.0)
4454
   }
4453
   }
4455
 
4454
 
4456
   #if ENABLED(AUTOTEMP)
4455
   #if ENABLED(AUTOTEMP)
4457
-    autotemp_enabled = code_seen('F');
4458
-    if (autotemp_enabled) autotemp_factor = code_value();
4459
-    if (code_seen('S')) autotemp_min = code_value();
4460
-    if (code_seen('B')) autotemp_max = code_value();
4456
+    planner.autotemp_M109();
4461
   #endif
4457
   #endif
4462
 
4458
 
4463
   #if TEMP_RESIDENCY_TIME > 0
4459
   #if TEMP_RESIDENCY_TIME > 0
4897
       if (i == E_AXIS) {
4893
       if (i == E_AXIS) {
4898
         float value = code_value();
4894
         float value = code_value();
4899
         if (value < 20.0) {
4895
         if (value < 20.0) {
4900
-          float factor = axis_steps_per_unit[i] / value; // increase e constants if M92 E14 is given for netfab.
4901
-          max_e_jerk *= factor;
4902
-          max_feedrate[i] *= factor;
4903
-          axis_steps_per_sqr_second[i] *= factor;
4896
+          float factor = planner.axis_steps_per_unit[i] / value; // increase e constants if M92 E14 is given for netfab.
4897
+          planner.max_e_jerk *= factor;
4898
+          planner.max_feedrate[i] *= factor;
4899
+          planner.axis_steps_per_sqr_second[i] *= factor;
4904
         }
4900
         }
4905
-        axis_steps_per_unit[i] = value;
4901
+        planner.axis_steps_per_unit[i] = value;
4906
       }
4902
       }
4907
       else {
4903
       else {
4908
-        axis_steps_per_unit[i] = code_value();
4904
+        planner.axis_steps_per_unit[i] = code_value();
4909
       }
4905
       }
4910
     }
4906
     }
4911
   }
4907
   }
4940
     SERIAL_EOL;
4936
     SERIAL_EOL;
4941
 
4937
 
4942
     SERIAL_PROTOCOLPGM("SCARA step Cal - Theta:");
4938
     SERIAL_PROTOCOLPGM("SCARA step Cal - Theta:");
4943
-    SERIAL_PROTOCOL(delta[X_AXIS] / 90 * axis_steps_per_unit[X_AXIS]);
4939
+    SERIAL_PROTOCOL(delta[X_AXIS] / 90 * planner.axis_steps_per_unit[X_AXIS]);
4944
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
4940
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
4945
-    SERIAL_PROTOCOL((delta[Y_AXIS] - delta[X_AXIS]) / 90 * axis_steps_per_unit[Y_AXIS]);
4941
+    SERIAL_PROTOCOL((delta[Y_AXIS] - delta[X_AXIS]) / 90 * planner.axis_steps_per_unit[Y_AXIS]);
4946
     SERIAL_EOL; SERIAL_EOL;
4942
     SERIAL_EOL; SERIAL_EOL;
4947
   #endif
4943
   #endif
4948
 }
4944
 }
5083
 inline void gcode_M201() {
5079
 inline void gcode_M201() {
5084
   for (int8_t i = 0; i < NUM_AXIS; i++) {
5080
   for (int8_t i = 0; i < NUM_AXIS; i++) {
5085
     if (code_seen(axis_codes[i])) {
5081
     if (code_seen(axis_codes[i])) {
5086
-      max_acceleration_units_per_sq_second[i] = code_value();
5082
+      planner.max_acceleration_units_per_sq_second[i] = code_value();
5087
     }
5083
     }
5088
   }
5084
   }
5089
   // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
5085
   // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
5090
-  reset_acceleration_rates();
5086
+  planner.reset_acceleration_rates();
5091
 }
5087
 }
5092
 
5088
 
5093
 #if 0 // Not used for Sprinter/grbl gen6
5089
 #if 0 // Not used for Sprinter/grbl gen6
5094
   inline void gcode_M202() {
5090
   inline void gcode_M202() {
5095
     for (int8_t i = 0; i < NUM_AXIS; i++) {
5091
     for (int8_t i = 0; i < NUM_AXIS; i++) {
5096
-      if (code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
5092
+      if (code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * planner.axis_steps_per_unit[i];
5097
     }
5093
     }
5098
   }
5094
   }
5099
 #endif
5095
 #endif
5105
 inline void gcode_M203() {
5101
 inline void gcode_M203() {
5106
   for (int8_t i = 0; i < NUM_AXIS; i++) {
5102
   for (int8_t i = 0; i < NUM_AXIS; i++) {
5107
     if (code_seen(axis_codes[i])) {
5103
     if (code_seen(axis_codes[i])) {
5108
-      max_feedrate[i] = code_value();
5104
+      planner.max_feedrate[i] = code_value();
5109
     }
5105
     }
5110
   }
5106
   }
5111
 }
5107
 }
5121
  */
5117
  */
5122
 inline void gcode_M204() {
5118
 inline void gcode_M204() {
5123
   if (code_seen('S')) {  // Kept for legacy compatibility. Should NOT BE USED for new developments.
5119
   if (code_seen('S')) {  // Kept for legacy compatibility. Should NOT BE USED for new developments.
5124
-    travel_acceleration = acceleration = code_value();
5125
-    SERIAL_ECHOPAIR("Setting Print and Travel Acceleration: ", acceleration);
5120
+    planner.travel_acceleration = planner.acceleration = code_value();
5121
+    SERIAL_ECHOPAIR("Setting Print and Travel Acceleration: ", planner.acceleration);
5126
     SERIAL_EOL;
5122
     SERIAL_EOL;
5127
   }
5123
   }
5128
   if (code_seen('P')) {
5124
   if (code_seen('P')) {
5129
-    acceleration = code_value();
5130
-    SERIAL_ECHOPAIR("Setting Print Acceleration: ", acceleration);
5125
+    planner.acceleration = code_value();
5126
+    SERIAL_ECHOPAIR("Setting Print Acceleration: ", planner.acceleration);
5131
     SERIAL_EOL;
5127
     SERIAL_EOL;
5132
   }
5128
   }
5133
   if (code_seen('R')) {
5129
   if (code_seen('R')) {
5134
-    retract_acceleration = code_value();
5135
-    SERIAL_ECHOPAIR("Setting Retract Acceleration: ", retract_acceleration);
5130
+    planner.retract_acceleration = code_value();
5131
+    SERIAL_ECHOPAIR("Setting Retract Acceleration: ", planner.retract_acceleration);
5136
     SERIAL_EOL;
5132
     SERIAL_EOL;
5137
   }
5133
   }
5138
   if (code_seen('T')) {
5134
   if (code_seen('T')) {
5139
-    travel_acceleration = code_value();
5140
-    SERIAL_ECHOPAIR("Setting Travel Acceleration: ", travel_acceleration);
5135
+    planner.travel_acceleration = code_value();
5136
+    SERIAL_ECHOPAIR("Setting Travel Acceleration: ", planner.travel_acceleration);
5141
     SERIAL_EOL;
5137
     SERIAL_EOL;
5142
   }
5138
   }
5143
 }
5139
 }
5153
  *    E = Max E Jerk (mm/s/s)
5149
  *    E = Max E Jerk (mm/s/s)
5154
  */
5150
  */
5155
 inline void gcode_M205() {
5151
 inline void gcode_M205() {
5156
-  if (code_seen('S')) minimumfeedrate = code_value();
5157
-  if (code_seen('T')) mintravelfeedrate = code_value();
5158
-  if (code_seen('B')) minsegmenttime = code_value();
5159
-  if (code_seen('X')) max_xy_jerk = code_value();
5160
-  if (code_seen('Z')) max_z_jerk = code_value();
5161
-  if (code_seen('E')) max_e_jerk = code_value();
5152
+  if (code_seen('S')) planner.min_feedrate = code_value();
5153
+  if (code_seen('T')) planner.min_travel_feedrate = code_value();
5154
+  if (code_seen('B')) planner.min_segment_time = code_value();
5155
+  if (code_seen('X')) planner.max_xy_jerk = code_value();
5156
+  if (code_seen('Z')) planner.max_z_jerk = code_value();
5157
+  if (code_seen('E')) planner.max_e_jerk = code_value();
5162
 }
5158
 }
5163
 
5159
 
5164
 /**
5160
 /**
6004
 
6000
 
6005
     #if ENABLED(DELTA)
6001
     #if ENABLED(DELTA)
6006
       #define RUNPLAN calculate_delta(destination); \
6002
       #define RUNPLAN calculate_delta(destination); \
6007
-                      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], fr60, active_extruder);
6003
+                      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], fr60, active_extruder);
6008
     #else
6004
     #else
6009
       #define RUNPLAN line_to_destination();
6005
       #define RUNPLAN line_to_destination();
6010
     #endif
6006
     #endif
6097
     #if ENABLED(DELTA)
6093
     #if ENABLED(DELTA)
6098
       // Move XYZ to starting position, then E
6094
       // Move XYZ to starting position, then E
6099
       calculate_delta(lastpos);
6095
       calculate_delta(lastpos);
6100
-      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], fr60, active_extruder);
6101
-      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], lastpos[E_AXIS], fr60, active_extruder);
6096
+      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], fr60, active_extruder);
6097
+      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], lastpos[E_AXIS], fr60, active_extruder);
6102
     #else
6098
     #else
6103
       // Move XY to starting position, then Z, then E
6099
       // Move XY to starting position, then Z, then E
6104
       destination[X_AXIS] = lastpos[X_AXIS];
6100
       destination[X_AXIS] = lastpos[X_AXIS];
6292
     #ifdef XY_TRAVEL_SPEED
6288
     #ifdef XY_TRAVEL_SPEED
6293
       feedrate = XY_TRAVEL_SPEED;
6289
       feedrate = XY_TRAVEL_SPEED;
6294
     #else
6290
     #else
6295
-      feedrate = min(max_feedrate[X_AXIS], max_feedrate[Y_AXIS]);
6291
+      feedrate = min(planner.max_feedrate[X_AXIS], planner.max_feedrate[Y_AXIS]);
6296
     #endif
6292
     #endif
6297
   }
6293
   }
6298
 
6294
 
6304
         if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE && IsRunning() &&
6300
         if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE && IsRunning() &&
6305
             (delayed_move_time || current_position[X_AXIS] != x_home_pos(active_extruder))) {
6301
             (delayed_move_time || current_position[X_AXIS] != x_home_pos(active_extruder))) {
6306
           // Park old head: 1) raise 2) move to park position 3) lower
6302
           // Park old head: 1) raise 2) move to park position 3) lower
6307
-          plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
6308
-                           current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
6309
-          plan_buffer_line(x_home_pos(active_extruder), current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
6310
-                           current_position[E_AXIS], max_feedrate[X_AXIS], active_extruder);
6311
-          plan_buffer_line(x_home_pos(active_extruder), current_position[Y_AXIS], current_position[Z_AXIS],
6312
-                           current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
6303
+          planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
6304
+                           current_position[E_AXIS], planner.max_feedrate[Z_AXIS], active_extruder);
6305
+          planner.buffer_line(x_home_pos(active_extruder), current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
6306
+                           current_position[E_AXIS], planner.max_feedrate[X_AXIS], active_extruder);
6307
+          planner.buffer_line(x_home_pos(active_extruder), current_position[Y_AXIS], current_position[Z_AXIS],
6308
+                           current_position[E_AXIS], planner.max_feedrate[Z_AXIS], active_extruder);
6313
           stepper.synchronize();
6309
           stepper.synchronize();
6314
         }
6310
         }
6315
 
6311
 
7186
 #if ENABLED(MESH_BED_LEVELING)
7182
 #if ENABLED(MESH_BED_LEVELING)
7187
 
7183
 
7188
 // This function is used to split lines on mesh borders so each segment is only part of one mesh area
7184
 // This function is used to split lines on mesh borders so each segment is only part of one mesh area
7189
-void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_rate, const uint8_t& extruder, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7185
+void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate, const uint8_t& extruder, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
7190
   if (!mbl.active) {
7186
   if (!mbl.active) {
7191
-    plan_buffer_line(x, y, z, e, feed_rate, extruder);
7187
+    planner.buffer_line(x, y, z, e, feed_rate, extruder);
7192
     set_current_to_destination();
7188
     set_current_to_destination();
7193
     return;
7189
     return;
7194
   }
7190
   }
7202
   iy = min(iy, MESH_NUM_Y_POINTS - 2);
7198
   iy = min(iy, MESH_NUM_Y_POINTS - 2);
7203
   if (pix == ix && piy == iy) {
7199
   if (pix == ix && piy == iy) {
7204
     // Start and end on same mesh square
7200
     // Start and end on same mesh square
7205
-    plan_buffer_line(x, y, z, e, feed_rate, extruder);
7201
+    planner.buffer_line(x, y, z, e, feed_rate, extruder);
7206
     set_current_to_destination();
7202
     set_current_to_destination();
7207
     return;
7203
     return;
7208
   }
7204
   }
7241
   }
7237
   }
7242
   else {
7238
   else {
7243
     // Already split on a border
7239
     // Already split on a border
7244
-    plan_buffer_line(x, y, z, e, feed_rate, extruder);
7240
+    planner.buffer_line(x, y, z, e, feed_rate, extruder);
7245
     set_current_to_destination();
7241
     set_current_to_destination();
7246
     return;
7242
     return;
7247
   }
7243
   }
7250
   destination[Y_AXIS] = ny;
7246
   destination[Y_AXIS] = ny;
7251
   destination[Z_AXIS] = nz;
7247
   destination[Z_AXIS] = nz;
7252
   destination[E_AXIS] = ne;
7248
   destination[E_AXIS] = ne;
7253
-  mesh_plan_buffer_line(nx, ny, nz, ne, feed_rate, extruder, x_splits, y_splits);
7249
+  mesh_buffer_line(nx, ny, nz, ne, feed_rate, extruder, x_splits, y_splits);
7254
   destination[X_AXIS] = x;
7250
   destination[X_AXIS] = x;
7255
   destination[Y_AXIS] = y;
7251
   destination[Y_AXIS] = y;
7256
   destination[Z_AXIS] = z;
7252
   destination[Z_AXIS] = z;
7257
   destination[E_AXIS] = e;
7253
   destination[E_AXIS] = e;
7258
-  mesh_plan_buffer_line(x, y, z, e, feed_rate, extruder, x_splits, y_splits);
7254
+  mesh_buffer_line(x, y, z, e, feed_rate, extruder, x_splits, y_splits);
7259
 }
7255
 }
7260
 #endif  // MESH_BED_LEVELING
7256
 #endif  // MESH_BED_LEVELING
7261
 
7257
 
7314
       //DEBUG_POS("prepare_move_delta", target);
7310
       //DEBUG_POS("prepare_move_delta", target);
7315
       //DEBUG_POS("prepare_move_delta", delta);
7311
       //DEBUG_POS("prepare_move_delta", delta);
7316
 
7312
 
7317
-      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], target[E_AXIS], feedrate / 60 * feedrate_multiplier / 100.0, active_extruder);
7313
+      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], target[E_AXIS], feedrate / 60 * feedrate_multiplier / 100.0, active_extruder);
7318
     }
7314
     }
7319
     return true;
7315
     return true;
7320
   }
7316
   }
7331
     if (active_extruder_parked) {
7327
     if (active_extruder_parked) {
7332
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && active_extruder == 0) {
7328
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && active_extruder == 0) {
7333
         // move duplicate extruder into correct duplication position.
7329
         // move duplicate extruder into correct duplication position.
7334
-        plan_set_position(inactive_extruder_x_pos, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
7335
-        plan_buffer_line(current_position[X_AXIS] + duplicate_extruder_x_offset,
7336
-                         current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], max_feedrate[X_AXIS], 1);
7330
+        planner.set_position(inactive_extruder_x_pos, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
7331
+        planner.buffer_line(current_position[X_AXIS] + duplicate_extruder_x_offset,
7332
+                         current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], planner.max_feedrate[X_AXIS], 1);
7337
         sync_plan_position();
7333
         sync_plan_position();
7338
         stepper.synchronize();
7334
         stepper.synchronize();
7339
         extruder_duplication_enabled = true;
7335
         extruder_duplication_enabled = true;
7353
         }
7349
         }
7354
         delayed_move_time = 0;
7350
         delayed_move_time = 0;
7355
         // unpark extruder: 1) raise, 2) move into starting XY position, 3) lower
7351
         // unpark extruder: 1) raise, 2) move into starting XY position, 3) lower
7356
-        plan_buffer_line(raised_parked_position[X_AXIS], raised_parked_position[Y_AXIS], raised_parked_position[Z_AXIS], current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
7357
-        plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], raised_parked_position[Z_AXIS], current_position[E_AXIS], min(max_feedrate[X_AXIS], max_feedrate[Y_AXIS]), active_extruder);
7358
-        plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
7352
+        planner.buffer_line(raised_parked_position[X_AXIS], raised_parked_position[Y_AXIS], raised_parked_position[Z_AXIS], current_position[E_AXIS], planner.max_feedrate[Z_AXIS], active_extruder);
7353
+        planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], raised_parked_position[Z_AXIS], current_position[E_AXIS], min(planner.max_feedrate[X_AXIS], planner.max_feedrate[Y_AXIS]), active_extruder);
7354
+        planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], planner.max_feedrate[Z_AXIS], active_extruder);
7359
         active_extruder_parked = false;
7355
         active_extruder_parked = false;
7360
       }
7356
       }
7361
     }
7357
     }
7373
     }
7369
     }
7374
     else {
7370
     else {
7375
       #if ENABLED(MESH_BED_LEVELING)
7371
       #if ENABLED(MESH_BED_LEVELING)
7376
-        mesh_plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], (feedrate / 60) * (feedrate_multiplier / 100.0), active_extruder);
7372
+        mesh_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], (feedrate / 60) * (feedrate_multiplier / 100.0), active_extruder);
7377
         return false;
7373
         return false;
7378
       #else
7374
       #else
7379
         line_to_destination(feedrate * feedrate_multiplier / 100.0);
7375
         line_to_destination(feedrate * feedrate_multiplier / 100.0);
7387
 /**
7383
 /**
7388
  * Prepare a single move and get ready for the next one
7384
  * Prepare a single move and get ready for the next one
7389
  *
7385
  *
7390
- * (This may call plan_buffer_line several times to put
7386
+ * (This may call planner.buffer_line several times to put
7391
  *  smaller moves into the planner for DELTA or SCARA.)
7387
  *  smaller moves into the planner for DELTA or SCARA.)
7392
  */
7388
  */
7393
 void prepare_move() {
7389
 void prepare_move() {
7531
       #if ENABLED(AUTO_BED_LEVELING_FEATURE)
7527
       #if ENABLED(AUTO_BED_LEVELING_FEATURE)
7532
         adjust_delta(arc_target);
7528
         adjust_delta(arc_target);
7533
       #endif
7529
       #endif
7534
-      plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], arc_target[E_AXIS], feed_rate, active_extruder);
7530
+      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], arc_target[E_AXIS], feed_rate, active_extruder);
7535
     #else
7531
     #else
7536
-      plan_buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], arc_target[E_AXIS], feed_rate, active_extruder);
7532
+      planner.buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], arc_target[E_AXIS], feed_rate, active_extruder);
7537
     #endif
7533
     #endif
7538
   }
7534
   }
7539
 
7535
 
7543
     #if ENABLED(AUTO_BED_LEVELING_FEATURE)
7539
     #if ENABLED(AUTO_BED_LEVELING_FEATURE)
7544
       adjust_delta(target);
7540
       adjust_delta(target);
7545
     #endif
7541
     #endif
7546
-    plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], target[E_AXIS], feed_rate, active_extruder);
7542
+    planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], target[E_AXIS], feed_rate, active_extruder);
7547
   #else
7543
   #else
7548
-    plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feed_rate, active_extruder);
7544
+    planner.buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feed_rate, active_extruder);
7549
   #endif
7545
   #endif
7550
 
7546
 
7551
   // As far as the parser is concerned, the position is now == target. In reality the
7547
   // As far as the parser is concerned, the position is now == target. In reality the
7762
   if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) kill(PSTR(MSG_KILLED));
7758
   if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) kill(PSTR(MSG_KILLED));
7763
 
7759
 
7764
   if (stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time)
7760
   if (stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time)
7765
-      && !ignore_stepper_queue && !blocks_queued()) {
7761
+      && !ignore_stepper_queue && !planner.blocks_queued()) {
7766
     #if ENABLED(DISABLE_INACTIVE_X)
7762
     #if ENABLED(DISABLE_INACTIVE_X)
7767
       disable_x();
7763
       disable_x();
7768
     #endif
7764
     #endif
7855
           #endif
7851
           #endif
7856
         }
7852
         }
7857
         float oldepos = current_position[E_AXIS], oldedes = destination[E_AXIS];
7853
         float oldepos = current_position[E_AXIS], oldedes = destination[E_AXIS];
7858
-        plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS],
7859
-                         destination[E_AXIS] + (EXTRUDER_RUNOUT_EXTRUDE) * (EXTRUDER_RUNOUT_ESTEPS) / axis_steps_per_unit[E_AXIS],
7860
-                         (EXTRUDER_RUNOUT_SPEED) / 60. * (EXTRUDER_RUNOUT_ESTEPS) / axis_steps_per_unit[E_AXIS], active_extruder);
7854
+        planner.buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS],
7855
+                         destination[E_AXIS] + (EXTRUDER_RUNOUT_EXTRUDE) * (EXTRUDER_RUNOUT_ESTEPS) / planner.axis_steps_per_unit[E_AXIS],
7856
+                         (EXTRUDER_RUNOUT_SPEED) / 60. * (EXTRUDER_RUNOUT_ESTEPS) / planner.axis_steps_per_unit[E_AXIS], active_extruder);
7861
       current_position[E_AXIS] = oldepos;
7857
       current_position[E_AXIS] = oldepos;
7862
       destination[E_AXIS] = oldedes;
7858
       destination[E_AXIS] = oldedes;
7863
-      plan_set_e_position(oldepos);
7859
+      planner.set_e_position(oldepos);
7864
       previous_cmd_ms = ms; // refresh_cmd_timeout()
7860
       previous_cmd_ms = ms; // refresh_cmd_timeout()
7865
       stepper.synchronize();
7861
       stepper.synchronize();
7866
       switch (active_extruder) {
7862
       switch (active_extruder) {
7900
     handle_status_leds();
7896
     handle_status_leds();
7901
   #endif
7897
   #endif
7902
 
7898
 
7903
-  check_axes_activity();
7899
+  planner.check_axes_activity();
7904
 }
7900
 }
7905
 
7901
 
7906
 void kill(const char* lcd_msg) {
7902
 void kill(const char* lcd_msg) {

+ 73
- 73
Marlin/configuration_store.cpp View File

43
  *
43
  *
44
  *  100  Version (char x4)
44
  *  100  Version (char x4)
45
  *
45
  *
46
- *  104  M92 XYZE  axis_steps_per_unit (float x4)
47
- *  120  M203 XYZE max_feedrate (float x4)
48
- *  136  M201 XYZE max_acceleration_units_per_sq_second (uint32_t x4)
49
- *  152  M204 P    acceleration (float)
50
- *  156  M204 R    retract_acceleration (float)
51
- *  160  M204 T    travel_acceleration (float)
52
- *  164  M205 S    minimumfeedrate (float)
53
- *  168  M205 T    mintravelfeedrate (float)
54
- *  172  M205 B    minsegmenttime (ulong)
55
- *  176  M205 X    max_xy_jerk (float)
56
- *  180  M205 Z    max_z_jerk (float)
57
- *  184  M205 E    max_e_jerk (float)
46
+ *  104  M92 XYZE  planner.axis_steps_per_unit (float x4)
47
+ *  120  M203 XYZE planner.max_feedrate (float x4)
48
+ *  136  M201 XYZE planner.max_acceleration_units_per_sq_second (uint32_t x4)
49
+ *  152  M204 P    planner.acceleration (float)
50
+ *  156  M204 R    planner.retract_acceleration (float)
51
+ *  160  M204 T    planner.travel_acceleration (float)
52
+ *  164  M205 S    planner.min_feedrate (float)
53
+ *  168  M205 T    planner.min_travel_feedrate (float)
54
+ *  172  M205 B    planner.min_segment_time (ulong)
55
+ *  176  M205 X    planner.max_xy_jerk (float)
56
+ *  180  M205 Z    planner.max_z_jerk (float)
57
+ *  184  M205 E    planner.max_e_jerk (float)
58
  *  188  M206 XYZ  home_offset (float x3)
58
  *  188  M206 XYZ  home_offset (float x3)
59
  *
59
  *
60
  * Mesh bed leveling:
60
  * Mesh bed leveling:
173
   char ver[4] = "000";
173
   char ver[4] = "000";
174
   int i = EEPROM_OFFSET;
174
   int i = EEPROM_OFFSET;
175
   EEPROM_WRITE_VAR(i, ver); // invalidate data first
175
   EEPROM_WRITE_VAR(i, ver); // invalidate data first
176
-  EEPROM_WRITE_VAR(i, axis_steps_per_unit);
177
-  EEPROM_WRITE_VAR(i, max_feedrate);
178
-  EEPROM_WRITE_VAR(i, max_acceleration_units_per_sq_second);
179
-  EEPROM_WRITE_VAR(i, acceleration);
180
-  EEPROM_WRITE_VAR(i, retract_acceleration);
181
-  EEPROM_WRITE_VAR(i, travel_acceleration);
182
-  EEPROM_WRITE_VAR(i, minimumfeedrate);
183
-  EEPROM_WRITE_VAR(i, mintravelfeedrate);
184
-  EEPROM_WRITE_VAR(i, minsegmenttime);
185
-  EEPROM_WRITE_VAR(i, max_xy_jerk);
186
-  EEPROM_WRITE_VAR(i, max_z_jerk);
187
-  EEPROM_WRITE_VAR(i, max_e_jerk);
176
+  EEPROM_WRITE_VAR(i, planner.axis_steps_per_unit);
177
+  EEPROM_WRITE_VAR(i, planner.max_feedrate);
178
+  EEPROM_WRITE_VAR(i, planner.max_acceleration_units_per_sq_second);
179
+  EEPROM_WRITE_VAR(i, planner.acceleration);
180
+  EEPROM_WRITE_VAR(i, planner.retract_acceleration);
181
+  EEPROM_WRITE_VAR(i, planner.travel_acceleration);
182
+  EEPROM_WRITE_VAR(i, planner.min_feedrate);
183
+  EEPROM_WRITE_VAR(i, planner.min_travel_feedrate);
184
+  EEPROM_WRITE_VAR(i, planner.min_segment_time);
185
+  EEPROM_WRITE_VAR(i, planner.max_xy_jerk);
186
+  EEPROM_WRITE_VAR(i, planner.max_z_jerk);
187
+  EEPROM_WRITE_VAR(i, planner.max_e_jerk);
188
   EEPROM_WRITE_VAR(i, home_offset);
188
   EEPROM_WRITE_VAR(i, home_offset);
189
 
189
 
190
   uint8_t mesh_num_x = 3;
190
   uint8_t mesh_num_x = 3;
351
     float dummy = 0;
351
     float dummy = 0;
352
 
352
 
353
     // version number match
353
     // version number match
354
-    EEPROM_READ_VAR(i, axis_steps_per_unit);
355
-    EEPROM_READ_VAR(i, max_feedrate);
356
-    EEPROM_READ_VAR(i, max_acceleration_units_per_sq_second);
354
+    EEPROM_READ_VAR(i, planner.axis_steps_per_unit);
355
+    EEPROM_READ_VAR(i, planner.max_feedrate);
356
+    EEPROM_READ_VAR(i, planner.max_acceleration_units_per_sq_second);
357
 
357
 
358
     // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
358
     // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
359
-    reset_acceleration_rates();
360
-
361
-    EEPROM_READ_VAR(i, acceleration);
362
-    EEPROM_READ_VAR(i, retract_acceleration);
363
-    EEPROM_READ_VAR(i, travel_acceleration);
364
-    EEPROM_READ_VAR(i, minimumfeedrate);
365
-    EEPROM_READ_VAR(i, mintravelfeedrate);
366
-    EEPROM_READ_VAR(i, minsegmenttime);
367
-    EEPROM_READ_VAR(i, max_xy_jerk);
368
-    EEPROM_READ_VAR(i, max_z_jerk);
369
-    EEPROM_READ_VAR(i, max_e_jerk);
359
+    planner.reset_acceleration_rates();
360
+
361
+    EEPROM_READ_VAR(i, planner.acceleration);
362
+    EEPROM_READ_VAR(i, planner.retract_acceleration);
363
+    EEPROM_READ_VAR(i, planner.travel_acceleration);
364
+    EEPROM_READ_VAR(i, planner.min_feedrate);
365
+    EEPROM_READ_VAR(i, planner.min_travel_feedrate);
366
+    EEPROM_READ_VAR(i, planner.min_segment_time);
367
+    EEPROM_READ_VAR(i, planner.max_xy_jerk);
368
+    EEPROM_READ_VAR(i, planner.max_z_jerk);
369
+    EEPROM_READ_VAR(i, planner.max_e_jerk);
370
     EEPROM_READ_VAR(i, home_offset);
370
     EEPROM_READ_VAR(i, home_offset);
371
 
371
 
372
     uint8_t dummy_uint8 = 0, mesh_num_x = 0, mesh_num_y = 0;
372
     uint8_t dummy_uint8 = 0, mesh_num_x = 0, mesh_num_y = 0;
528
   float tmp2[] = DEFAULT_MAX_FEEDRATE;
528
   float tmp2[] = DEFAULT_MAX_FEEDRATE;
529
   long tmp3[] = DEFAULT_MAX_ACCELERATION;
529
   long tmp3[] = DEFAULT_MAX_ACCELERATION;
530
   for (uint8_t i = 0; i < NUM_AXIS; i++) {
530
   for (uint8_t i = 0; i < NUM_AXIS; i++) {
531
-    axis_steps_per_unit[i] = tmp1[i];
532
-    max_feedrate[i] = tmp2[i];
533
-    max_acceleration_units_per_sq_second[i] = tmp3[i];
531
+    planner.axis_steps_per_unit[i] = tmp1[i];
532
+    planner.max_feedrate[i] = tmp2[i];
533
+    planner.max_acceleration_units_per_sq_second[i] = tmp3[i];
534
     #if ENABLED(SCARA)
534
     #if ENABLED(SCARA)
535
       if (i < COUNT(axis_scaling))
535
       if (i < COUNT(axis_scaling))
536
         axis_scaling[i] = 1;
536
         axis_scaling[i] = 1;
538
   }
538
   }
539
 
539
 
540
   // steps per sq second need to be updated to agree with the units per sq second
540
   // steps per sq second need to be updated to agree with the units per sq second
541
-  reset_acceleration_rates();
542
-
543
-  acceleration = DEFAULT_ACCELERATION;
544
-  retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
545
-  travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
546
-  minimumfeedrate = DEFAULT_MINIMUMFEEDRATE;
547
-  minsegmenttime = DEFAULT_MINSEGMENTTIME;
548
-  mintravelfeedrate = DEFAULT_MINTRAVELFEEDRATE;
549
-  max_xy_jerk = DEFAULT_XYJERK;
550
-  max_z_jerk = DEFAULT_ZJERK;
551
-  max_e_jerk = DEFAULT_EJERK;
541
+  planner.reset_acceleration_rates();
542
+
543
+  planner.acceleration = DEFAULT_ACCELERATION;
544
+  planner.retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
545
+  planner.travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
546
+  planner.min_feedrate = DEFAULT_MINIMUMFEEDRATE;
547
+  planner.min_segment_time = DEFAULT_MINSEGMENTTIME;
548
+  planner.min_travel_feedrate = DEFAULT_MINTRAVELFEEDRATE;
549
+  planner.max_xy_jerk = DEFAULT_XYJERK;
550
+  planner.max_z_jerk = DEFAULT_ZJERK;
551
+  planner.max_e_jerk = DEFAULT_EJERK;
552
   home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
552
   home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
553
 
553
 
554
   #if ENABLED(MESH_BED_LEVELING)
554
   #if ENABLED(MESH_BED_LEVELING)
653
     SERIAL_ECHOLNPGM("Steps per unit:");
653
     SERIAL_ECHOLNPGM("Steps per unit:");
654
     CONFIG_ECHO_START;
654
     CONFIG_ECHO_START;
655
   }
655
   }
656
-  SERIAL_ECHOPAIR("  M92 X", axis_steps_per_unit[X_AXIS]);
657
-  SERIAL_ECHOPAIR(" Y", axis_steps_per_unit[Y_AXIS]);
658
-  SERIAL_ECHOPAIR(" Z", axis_steps_per_unit[Z_AXIS]);
659
-  SERIAL_ECHOPAIR(" E", axis_steps_per_unit[E_AXIS]);
656
+  SERIAL_ECHOPAIR("  M92 X", planner.axis_steps_per_unit[X_AXIS]);
657
+  SERIAL_ECHOPAIR(" Y", planner.axis_steps_per_unit[Y_AXIS]);
658
+  SERIAL_ECHOPAIR(" Z", planner.axis_steps_per_unit[Z_AXIS]);
659
+  SERIAL_ECHOPAIR(" E", planner.axis_steps_per_unit[E_AXIS]);
660
   SERIAL_EOL;
660
   SERIAL_EOL;
661
 
661
 
662
   CONFIG_ECHO_START;
662
   CONFIG_ECHO_START;
677
     SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
677
     SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
678
     CONFIG_ECHO_START;
678
     CONFIG_ECHO_START;
679
   }
679
   }
680
-  SERIAL_ECHOPAIR("  M203 X", max_feedrate[X_AXIS]);
681
-  SERIAL_ECHOPAIR(" Y", max_feedrate[Y_AXIS]);
682
-  SERIAL_ECHOPAIR(" Z", max_feedrate[Z_AXIS]);
683
-  SERIAL_ECHOPAIR(" E", max_feedrate[E_AXIS]);
680
+  SERIAL_ECHOPAIR("  M203 X", planner.max_feedrate[X_AXIS]);
681
+  SERIAL_ECHOPAIR(" Y", planner.max_feedrate[Y_AXIS]);
682
+  SERIAL_ECHOPAIR(" Z", planner.max_feedrate[Z_AXIS]);
683
+  SERIAL_ECHOPAIR(" E", planner.max_feedrate[E_AXIS]);
684
   SERIAL_EOL;
684
   SERIAL_EOL;
685
 
685
 
686
   CONFIG_ECHO_START;
686
   CONFIG_ECHO_START;
688
     SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
688
     SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
689
     CONFIG_ECHO_START;
689
     CONFIG_ECHO_START;
690
   }
690
   }
691
-  SERIAL_ECHOPAIR("  M201 X", max_acceleration_units_per_sq_second[X_AXIS]);
692
-  SERIAL_ECHOPAIR(" Y", max_acceleration_units_per_sq_second[Y_AXIS]);
693
-  SERIAL_ECHOPAIR(" Z", max_acceleration_units_per_sq_second[Z_AXIS]);
694
-  SERIAL_ECHOPAIR(" E", max_acceleration_units_per_sq_second[E_AXIS]);
691
+  SERIAL_ECHOPAIR("  M201 X", planner.max_acceleration_units_per_sq_second[X_AXIS]);
692
+  SERIAL_ECHOPAIR(" Y", planner.max_acceleration_units_per_sq_second[Y_AXIS]);
693
+  SERIAL_ECHOPAIR(" Z", planner.max_acceleration_units_per_sq_second[Z_AXIS]);
694
+  SERIAL_ECHOPAIR(" E", planner.max_acceleration_units_per_sq_second[E_AXIS]);
695
   SERIAL_EOL;
695
   SERIAL_EOL;
696
   CONFIG_ECHO_START;
696
   CONFIG_ECHO_START;
697
   if (!forReplay) {
697
   if (!forReplay) {
698
     SERIAL_ECHOLNPGM("Accelerations: P=printing, R=retract and T=travel");
698
     SERIAL_ECHOLNPGM("Accelerations: P=printing, R=retract and T=travel");
699
     CONFIG_ECHO_START;
699
     CONFIG_ECHO_START;
700
   }
700
   }
701
-  SERIAL_ECHOPAIR("  M204 P", acceleration);
702
-  SERIAL_ECHOPAIR(" R", retract_acceleration);
703
-  SERIAL_ECHOPAIR(" T", travel_acceleration);
701
+  SERIAL_ECHOPAIR("  M204 P", planner.acceleration);
702
+  SERIAL_ECHOPAIR(" R", planner.retract_acceleration);
703
+  SERIAL_ECHOPAIR(" T", planner.travel_acceleration);
704
   SERIAL_EOL;
704
   SERIAL_EOL;
705
 
705
 
706
   CONFIG_ECHO_START;
706
   CONFIG_ECHO_START;
708
     SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s),  Z=maximum Z jerk (mm/s),  E=maximum E jerk (mm/s)");
708
     SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s),  Z=maximum Z jerk (mm/s),  E=maximum E jerk (mm/s)");
709
     CONFIG_ECHO_START;
709
     CONFIG_ECHO_START;
710
   }
710
   }
711
-  SERIAL_ECHOPAIR("  M205 S", minimumfeedrate);
712
-  SERIAL_ECHOPAIR(" T", mintravelfeedrate);
713
-  SERIAL_ECHOPAIR(" B", minsegmenttime);
714
-  SERIAL_ECHOPAIR(" X", max_xy_jerk);
715
-  SERIAL_ECHOPAIR(" Z", max_z_jerk);
716
-  SERIAL_ECHOPAIR(" E", max_e_jerk);
711
+  SERIAL_ECHOPAIR("  M205 S", planner.min_feedrate);
712
+  SERIAL_ECHOPAIR(" T", planner.min_travel_feedrate);
713
+  SERIAL_ECHOPAIR(" B", planner.min_segment_time);
714
+  SERIAL_ECHOPAIR(" X", planner.max_xy_jerk);
715
+  SERIAL_ECHOPAIR(" Z", planner.max_z_jerk);
716
+  SERIAL_ECHOPAIR(" E", planner.max_e_jerk);
717
   SERIAL_EOL;
717
   SERIAL_EOL;
718
 
718
 
719
   CONFIG_ECHO_START;
719
   CONFIG_ECHO_START;

+ 147
- 203
Marlin/planner.cpp View File

81
   #include "mesh_bed_leveling.h"
81
   #include "mesh_bed_leveling.h"
82
 #endif
82
 #endif
83
 
83
 
84
-//===========================================================================
85
-//============================= public variables ============================
86
-//===========================================================================
87
-
88
-millis_t minsegmenttime;
89
-float max_feedrate[NUM_AXIS]; // Max speeds in mm per minute
90
-float axis_steps_per_unit[NUM_AXIS];
91
-unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
92
-float minimumfeedrate;
93
-float acceleration;         // Normal acceleration mm/s^2  DEFAULT ACCELERATION for all printing moves. M204 SXXXX
94
-float retract_acceleration; // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
95
-float travel_acceleration;  // Travel acceleration mm/s^2  DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
96
-float max_xy_jerk;          // The largest speed change requiring no acceleration
97
-float max_z_jerk;
98
-float max_e_jerk;
99
-float mintravelfeedrate;
100
-unsigned long axis_steps_per_sqr_second[NUM_AXIS];
101
-
102
-#if ENABLED(AUTO_BED_LEVELING_FEATURE)
103
-  // Transform required to compensate for bed level
104
-  matrix_3x3 plan_bed_level_matrix = {
105
-    1.0, 0.0, 0.0,
106
-    0.0, 1.0, 0.0,
107
-    0.0, 0.0, 1.0
108
-  };
109
-#endif // AUTO_BED_LEVELING_FEATURE
84
+Planner planner;
110
 
85
 
111
-#if ENABLED(AUTOTEMP)
112
-  float autotemp_max = 250;
113
-  float autotemp_min = 210;
114
-  float autotemp_factor = 0.1;
115
-  bool autotemp_enabled = false;
116
-#endif
117
-
118
-#if ENABLED(FAN_SOFT_PWM)
119
-  extern unsigned char fanSpeedSoftPwm[FAN_COUNT];
120
-#endif
121
-
122
-//===========================================================================
123
-//============ semi-private variables, used in inline functions =============
124
-//===========================================================================
125
-
126
-block_t block_buffer[BLOCK_BUFFER_SIZE];            // A ring buffer for motion instfructions
127
-volatile unsigned char block_buffer_head;           // Index of the next block to be pushed
128
-volatile unsigned char block_buffer_tail;           // Index of the block to process now
129
-
130
-//===========================================================================
131
-//============================ private variables ============================
132
-//===========================================================================
133
-
134
-// The current position of the tool in absolute steps
135
-long position[NUM_AXIS];               // Rescaled from extern when axis_steps_per_unit are changed by gcode
136
-static float previous_speed[NUM_AXIS]; // Speed of previous path line segment
137
-static float previous_nominal_speed;   // Nominal speed of previous path line segment
138
-
139
-uint8_t g_uc_extruder_last_move[EXTRUDERS] = { 0 };
140
-
141
-#ifdef XY_FREQUENCY_LIMIT
142
-  // Used for the frequency limit
143
-  #define MAX_FREQ_TIME (1000000.0/XY_FREQUENCY_LIMIT)
144
-  // Old direction bits. Used for speed calculations
145
-  static unsigned char old_direction_bits = 0;
146
-  // Segment times (in µs). Used for speed calculations
147
-  static long axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
148
-#endif
149
-
150
-#if ENABLED(DUAL_X_CARRIAGE)
151
-  extern bool extruder_duplication_enabled;
152
-#endif
153
-
154
-//===========================================================================
155
-//================================ functions ================================
156
-//===========================================================================
157
-
158
-// Get the next / previous index of the next block in the ring buffer
159
-// NOTE: Using & here (not %) because BLOCK_BUFFER_SIZE is always a power of 2
160
-FORCE_INLINE int8_t next_block_index(int8_t block_index) { return BLOCK_MOD(block_index + 1); }
161
-FORCE_INLINE int8_t prev_block_index(int8_t block_index) { return BLOCK_MOD(block_index - 1); }
162
-
163
-// Calculates the distance (not time) it takes to accelerate from initial_rate to target_rate using the
164
-// given acceleration:
165
-FORCE_INLINE float estimate_acceleration_distance(float initial_rate, float target_rate, float acceleration) {
166
-  if (acceleration == 0) return 0; // acceleration was 0, set acceleration distance to 0
167
-  return (target_rate * target_rate - initial_rate * initial_rate) / (acceleration * 2);
86
+Planner::Planner() {
87
+  #if ENABLED(AUTO_BED_LEVELING_FEATURE)
88
+    bed_level_matrix.set_to_identity();
89
+  #endif
90
+  init();
168
 }
91
 }
169
 
92
 
170
-// This function gives you the point at which you must start braking (at the rate of -acceleration) if
171
-// you started at speed initial_rate and accelerated until this point and want to end at the final_rate after
172
-// a total travel of distance. This can be used to compute the intersection point between acceleration and
173
-// deceleration in the cases where the trapezoid has no plateau (i.e. never reaches maximum speed)
174
-
175
-FORCE_INLINE float intersection_distance(float initial_rate, float final_rate, float acceleration, float distance) {
176
-  if (acceleration == 0) return 0; // acceleration was 0, set intersection distance to 0
177
-  return (acceleration * 2 * distance - initial_rate * initial_rate + final_rate * final_rate) / (acceleration * 4);
93
+void Planner::init() {
94
+  block_buffer_head = block_buffer_tail = 0;
95
+  memset(position, 0, sizeof(position)); // clear position
96
+  for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = 0.0;
97
+  previous_nominal_speed = 0.0;
178
 }
98
 }
179
 
99
 
180
-// Calculates trapezoid parameters so that the entry- and exit-speed is compensated by the provided factors.
181
-
182
-void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor) {
100
+/**
101
+ * Calculate trapezoid parameters, multiplying the entry- and exit-speeds
102
+ * by the provided factors.
103
+ */
104
+void Planner::calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor) {
183
   unsigned long initial_rate = ceil(block->nominal_rate * entry_factor),
105
   unsigned long initial_rate = ceil(block->nominal_rate * entry_factor),
184
                 final_rate = ceil(block->nominal_rate * exit_factor); // (steps per second)
106
                 final_rate = ceil(block->nominal_rate * exit_factor); // (steps per second)
185
 
107
 
225
   CRITICAL_SECTION_END;
147
   CRITICAL_SECTION_END;
226
 }
148
 }
227
 
149
 
228
-// Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the
229
-// acceleration within the allotted distance.
230
-FORCE_INLINE float max_allowable_speed(float acceleration, float target_velocity, float distance) {
231
-  return sqrt(target_velocity * target_velocity - 2 * acceleration * distance);
232
-}
233
-
234
 // "Junction jerk" in this context is the immediate change in speed at the junction of two blocks.
150
 // "Junction jerk" in this context is the immediate change in speed at the junction of two blocks.
235
 // This method will calculate the junction jerk as the euclidean distance between the nominal
151
 // This method will calculate the junction jerk as the euclidean distance between the nominal
236
 // velocities of the respective blocks.
152
 // velocities of the respective blocks.
240
 //}
156
 //}
241
 
157
 
242
 
158
 
243
-// The kernel called by planner_recalculate() when scanning the plan from last to first entry.
244
-void planner_reverse_pass_kernel(block_t* previous, block_t* current, block_t* next) {
159
+// The kernel called by recalculate() when scanning the plan from last to first entry.
160
+void Planner::reverse_pass_kernel(block_t* previous, block_t* current, block_t* next) {
245
   if (!current) return;
161
   if (!current) return;
246
   UNUSED(previous);
162
   UNUSED(previous);
247
 
163
 
267
   } // Skip last block. Already initialized and set for recalculation.
183
   } // Skip last block. Already initialized and set for recalculation.
268
 }
184
 }
269
 
185
 
270
-// planner_recalculate() needs to go over the current plan twice. Once in reverse and once forward. This
271
-// implements the reverse pass.
272
-void planner_reverse_pass() {
273
-  uint8_t block_index = block_buffer_head;
186
+/**
187
+ * recalculate() needs to go over the current plan twice.
188
+ * Once in reverse and once forward. This implements the reverse pass.
189
+ */
190
+void Planner::reverse_pass() {
274
 
191
 
275
-  //Make a local copy of block_buffer_tail, because the interrupt can alter it
276
-  CRITICAL_SECTION_START;
277
-    unsigned char tail = block_buffer_tail;
278
-  CRITICAL_SECTION_END
192
+  if (movesplanned() > 3) {
279
 
193
 
280
-  if (BLOCK_MOD(block_buffer_head - tail + BLOCK_BUFFER_SIZE) > 3) { // moves queued
281
-    block_index = BLOCK_MOD(block_buffer_head - 3);
282
     block_t* block[3] = { NULL, NULL, NULL };
194
     block_t* block[3] = { NULL, NULL, NULL };
283
-    while (block_index != tail) {
284
-      block_index = prev_block_index(block_index);
195
+
196
+    // Make a local copy of block_buffer_tail, because the interrupt can alter it
197
+    CRITICAL_SECTION_START;
198
+      uint8_t tail = block_buffer_tail;
199
+    CRITICAL_SECTION_END
200
+
201
+    uint8_t b = BLOCK_MOD(block_buffer_head - 3);
202
+    while (b != tail) {
203
+      b = prev_block_index(b);
285
       block[2] = block[1];
204
       block[2] = block[1];
286
       block[1] = block[0];
205
       block[1] = block[0];
287
-      block[0] = &block_buffer[block_index];
288
-      planner_reverse_pass_kernel(block[0], block[1], block[2]);
206
+      block[0] = &block_buffer[b];
207
+      reverse_pass_kernel(block[0], block[1], block[2]);
289
     }
208
     }
290
   }
209
   }
291
 }
210
 }
292
 
211
 
293
-// The kernel called by planner_recalculate() when scanning the plan from first to last entry.
294
-void planner_forward_pass_kernel(block_t* previous, block_t* current, block_t* next) {
212
+// The kernel called by recalculate() when scanning the plan from first to last entry.
213
+void Planner::forward_pass_kernel(block_t* previous, block_t* current, block_t* next) {
295
   if (!previous) return;
214
   if (!previous) return;
296
   UNUSED(next);
215
   UNUSED(next);
297
 
216
 
312
   }
231
   }
313
 }
232
 }
314
 
233
 
315
-// planner_recalculate() needs to go over the current plan twice. Once in reverse and once forward. This
316
-// implements the forward pass.
317
-void planner_forward_pass() {
318
-  uint8_t block_index = block_buffer_tail;
234
+/**
235
+ * recalculate() needs to go over the current plan twice.
236
+ * Once in reverse and once forward. This implements the forward pass.
237
+ */
238
+void Planner::forward_pass() {
319
   block_t* block[3] = { NULL, NULL, NULL };
239
   block_t* block[3] = { NULL, NULL, NULL };
320
 
240
 
321
-  while (block_index != block_buffer_head) {
241
+  for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
322
     block[0] = block[1];
242
     block[0] = block[1];
323
     block[1] = block[2];
243
     block[1] = block[2];
324
-    block[2] = &block_buffer[block_index];
325
-    planner_forward_pass_kernel(block[0], block[1], block[2]);
326
-    block_index = next_block_index(block_index);
244
+    block[2] = &block_buffer[b];
245
+    forward_pass_kernel(block[0], block[1], block[2]);
327
   }
246
   }
328
-  planner_forward_pass_kernel(block[1], block[2], NULL);
247
+  forward_pass_kernel(block[1], block[2], NULL);
329
 }
248
 }
330
 
249
 
331
-// Recalculates the trapezoid speed profiles for all blocks in the plan according to the
332
-// entry_factor for each junction. Must be called by planner_recalculate() after
333
-// updating the blocks.
334
-void planner_recalculate_trapezoids() {
250
+/**
251
+ * Recalculate the trapezoid speed profiles for all blocks in the plan
252
+ * according to the entry_factor for each junction. Must be called by
253
+ * recalculate() after updating the blocks.
254
+ */
255
+void Planner::recalculate_trapezoids() {
335
   int8_t block_index = block_buffer_tail;
256
   int8_t block_index = block_buffer_tail;
336
   block_t* current;
257
   block_t* current;
337
   block_t* next = NULL;
258
   block_t* next = NULL;
358
   }
279
   }
359
 }
280
 }
360
 
281
 
361
-// Recalculates the motion plan according to the following algorithm:
362
-//
363
-//   1. Go over every block in reverse order and calculate a junction speed reduction (i.e. block_t.entry_factor)
364
-//      so that:
365
-//     a. The junction jerk is within the set limit
366
-//     b. No speed reduction within one block requires faster deceleration than the one, true constant
367
-//        acceleration.
368
-//   2. Go over every block in chronological order and dial down junction speed reduction values if
369
-//     a. The speed increase within one block would require faster acceleration than the one, true
370
-//        constant acceleration.
371
-//
372
-// When these stages are complete all blocks have an entry_factor that will allow all speed changes to
373
-// be performed using only the one, true constant acceleration, and where no junction jerk is jerkier than
374
-// the set limit. Finally it will:
375
-//
376
-//   3. Recalculate trapezoids for all blocks.
377
-
378
-void planner_recalculate() {
379
-  planner_reverse_pass();
380
-  planner_forward_pass();
381
-  planner_recalculate_trapezoids();
382
-}
383
-
384
-void plan_init() {
385
-  block_buffer_head = block_buffer_tail = 0;
386
-  memset(position, 0, sizeof(position)); // clear position
387
-  for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = 0.0;
388
-  previous_nominal_speed = 0.0;
282
+/*
283
+ * Recalculate the motion plan according to the following algorithm:
284
+ *
285
+ *   1. Go over every block in reverse order...
286
+ *
287
+ *      Calculate a junction speed reduction (block_t.entry_factor) so:
288
+ *
289
+ *      a. The junction jerk is within the set limit, and
290
+ *
291
+ *      b. No speed reduction within one block requires faster
292
+ *         deceleration than the one, true constant acceleration.
293
+ *
294
+ *   2. Go over every block in chronological order...
295
+ *
296
+ *      Dial down junction speed reduction values if:
297
+ *      a. The speed increase within one block would require faster
298
+ *         acceleration than the one, true constant acceleration.
299
+ *
300
+ * After that, all blocks will have an entry_factor allowing all speed changes to
301
+ * be performed using only the one, true constant acceleration, and where no junction
302
+ * jerk is jerkier than the set limit, Jerky. Finally it will:
303
+ *
304
+ *   3. Recalculate "trapezoids" for all blocks.
305
+ */
306
+void Planner::recalculate() {
307
+  reverse_pass();
308
+  forward_pass();
309
+  recalculate_trapezoids();
389
 }
310
 }
390
 
311
 
391
 
312
 
392
 #if ENABLED(AUTOTEMP)
313
 #if ENABLED(AUTOTEMP)
393
-  void getHighESpeed() {
314
+
315
+  void Planner::getHighESpeed() {
394
     static float oldt = 0;
316
     static float oldt = 0;
395
 
317
 
396
     if (!autotemp_enabled) return;
318
     if (!autotemp_enabled) return;
397
     if (degTargetHotend0() + 2 < autotemp_min) return; // probably temperature set to zero.
319
     if (degTargetHotend0() + 2 < autotemp_min) return; // probably temperature set to zero.
398
 
320
 
399
     float high = 0.0;
321
     float high = 0.0;
400
-    uint8_t block_index = block_buffer_tail;
401
-
402
-    while (block_index != block_buffer_head) {
403
-      block_t* block = &block_buffer[block_index];
322
+    for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
323
+      block_t* block = &block_buffer[b];
404
       if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS]) {
324
       if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS]) {
405
         float se = (float)block->steps[E_AXIS] / block->step_event_count * block->nominal_speed; // mm/sec;
325
         float se = (float)block->steps[E_AXIS] / block->step_event_count * block->nominal_speed; // mm/sec;
406
         NOLESS(high, se);
326
         NOLESS(high, se);
407
       }
327
       }
408
-      block_index = next_block_index(block_index);
409
     }
328
     }
410
 
329
 
411
     float t = autotemp_min + high * autotemp_factor;
330
     float t = autotemp_min + high * autotemp_factor;
417
     oldt = t;
336
     oldt = t;
418
     setTargetHotend0(t);
337
     setTargetHotend0(t);
419
   }
338
   }
339
+
420
 #endif //AUTOTEMP
340
 #endif //AUTOTEMP
421
 
341
 
422
-void check_axes_activity() {
342
+/**
343
+ * Maintain fans, paste extruder pressure, 
344
+ */
345
+void Planner::check_axes_activity() {
423
   unsigned char axis_active[NUM_AXIS] = { 0 },
346
   unsigned char axis_active[NUM_AXIS] = { 0 },
424
                 tail_fan_speed[FAN_COUNT];
347
                 tail_fan_speed[FAN_COUNT];
425
 
348
 
432
                   tail_e_to_p_pressure = baricuda_e_to_p_pressure;
355
                   tail_e_to_p_pressure = baricuda_e_to_p_pressure;
433
   #endif
356
   #endif
434
 
357
 
435
-  block_t* block;
436
-
437
   if (blocks_queued()) {
358
   if (blocks_queued()) {
438
 
359
 
439
-    uint8_t block_index = block_buffer_tail;
440
-
441
     #if FAN_COUNT > 0
360
     #if FAN_COUNT > 0
442
-      for (uint8_t i = 0; i < FAN_COUNT; i++) tail_fan_speed[i] = block_buffer[block_index].fan_speed[i];
361
+      for (uint8_t i = 0; i < FAN_COUNT; i++) tail_fan_speed[i] = block_buffer[block_buffer_tail].fan_speed[i];
443
     #endif
362
     #endif
444
 
363
 
364
+    block_t* block;
365
+
445
     #if ENABLED(BARICUDA)
366
     #if ENABLED(BARICUDA)
446
-      block = &block_buffer[block_index];
367
+      block = &block_buffer[block_buffer_tail];
447
       tail_valve_pressure = block->valve_pressure;
368
       tail_valve_pressure = block->valve_pressure;
448
       tail_e_to_p_pressure = block->e_to_p_pressure;
369
       tail_e_to_p_pressure = block->e_to_p_pressure;
449
     #endif
370
     #endif
450
 
371
 
451
-    while (block_index != block_buffer_head) {
452
-      block = &block_buffer[block_index];
372
+    for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
373
+      block = &block_buffer[b];
453
       for (int i = 0; i < NUM_AXIS; i++) if (block->steps[i]) axis_active[i]++;
374
       for (int i = 0; i < NUM_AXIS; i++) if (block->steps[i]) axis_active[i]++;
454
-      block_index = next_block_index(block_index);
455
     }
375
     }
456
   }
376
   }
457
   #if ENABLED(DISABLE_X)
377
   #if ENABLED(DISABLE_X)
549
   #endif
469
   #endif
550
 }
470
 }
551
 
471
 
472
+/**
473
+ * Planner::buffer_line
474
+ *
475
+ * Add a new linear movement to the buffer.
476
+ *
477
+ *  x,y,z,e   - target position in mm
478
+ *  feed_rate - (target) speed of the move
479
+ *  extruder  - target extruder
480
+ */
552
 
481
 
553
-float junction_deviation = 0.1;
554
-// Add a new linear movement to the buffer. steps[X_AXIS], _y and _z is the absolute position in
555
-// mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
556
-// calculation the caller must also provide the physical length of the line in millimeters.
557
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
482
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
558
-  void plan_buffer_line(float x, float y, float z, const float& e, float feed_rate, const uint8_t extruder)
483
+  void Planner::buffer_line(float x, float y, float z, const float& e, float feed_rate, const uint8_t extruder)
559
 #else
484
 #else
560
-  void plan_buffer_line(const float& x, const float& y, const float& z, const float& e, float feed_rate, const uint8_t extruder)
485
+  void Planner::buffer_line(const float& x, const float& y, const float& z, const float& e, float feed_rate, const uint8_t extruder)
561
 #endif  // AUTO_BED_LEVELING_FEATURE
486
 #endif  // AUTO_BED_LEVELING_FEATURE
562
 {
487
 {
563
   // Calculate the buffer head after we push this byte
488
   // Calculate the buffer head after we push this byte
570
   #if ENABLED(MESH_BED_LEVELING)
495
   #if ENABLED(MESH_BED_LEVELING)
571
     if (mbl.active) z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
496
     if (mbl.active) z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
572
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
497
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
573
-    apply_rotation_xyz(plan_bed_level_matrix, x, y, z);
498
+    apply_rotation_xyz(bed_level_matrix, x, y, z);
574
   #endif
499
   #endif
575
 
500
 
576
   // The target position of the tool in absolute steps
501
   // The target position of the tool in absolute steps
703
 
628
 
704
   // Enable extruder(s)
629
   // Enable extruder(s)
705
   if (block->steps[E_AXIS]) {
630
   if (block->steps[E_AXIS]) {
706
-    if (DISABLE_INACTIVE_EXTRUDER) { //enable only selected extruder
631
+
632
+    #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder
707
 
633
 
708
       for (int i = 0; i < EXTRUDERS; i++)
634
       for (int i = 0; i < EXTRUDERS; i++)
709
         if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
635
         if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
762
           #endif // EXTRUDERS > 2
688
           #endif // EXTRUDERS > 2
763
         #endif // EXTRUDERS > 1
689
         #endif // EXTRUDERS > 1
764
       }
690
       }
765
-    }
766
-    else { // enable all
691
+    #else
767
       enable_e0();
692
       enable_e0();
768
       enable_e1();
693
       enable_e1();
769
       enable_e2();
694
       enable_e2();
770
       enable_e3();
695
       enable_e3();
771
-    }
696
+    #endif
772
   }
697
   }
773
 
698
 
774
   if (block->steps[E_AXIS])
699
   if (block->steps[E_AXIS])
775
-    NOLESS(feed_rate, minimumfeedrate);
700
+    NOLESS(feed_rate, min_feedrate);
776
   else
701
   else
777
-    NOLESS(feed_rate, mintravelfeedrate);
702
+    NOLESS(feed_rate, min_travel_feedrate);
778
 
703
 
779
   /**
704
   /**
780
    * This part of the code calculates the total length of the movement.
705
    * This part of the code calculates the total length of the movement.
837
       //  segment time im micro seconds
762
       //  segment time im micro seconds
838
       unsigned long segment_time = lround(1000000.0/inverse_second);
763
       unsigned long segment_time = lround(1000000.0/inverse_second);
839
       if (mq) {
764
       if (mq) {
840
-        if (segment_time < minsegmenttime) {
765
+        if (segment_time < min_segment_time) {
841
           // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
766
           // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
842
-          inverse_second = 1000000.0 / (segment_time + lround(2 * (minsegmenttime - segment_time) / moves_queued));
767
+          inverse_second = 1000000.0 / (segment_time + lround(2 * (min_segment_time - segment_time) / moves_queued));
843
           #ifdef XY_FREQUENCY_LIMIT
768
           #ifdef XY_FREQUENCY_LIMIT
844
             segment_time = lround(1000000.0 / inverse_second);
769
             segment_time = lround(1000000.0 / inverse_second);
845
           #endif
770
           #endif
968
   block->acceleration_rate = (long)(acc_st * 16777216.0 / (F_CPU / 8.0));
893
   block->acceleration_rate = (long)(acc_st * 16777216.0 / (F_CPU / 8.0));
969
 
894
 
970
   #if 0  // Use old jerk for now
895
   #if 0  // Use old jerk for now
896
+
897
+    float junction_deviation = 0.1;
898
+
971
     // Compute path unit vector
899
     // Compute path unit vector
972
     double unit_vec[3];
900
     double unit_vec[3];
973
 
901
 
1083
   // Update position
1011
   // Update position
1084
   for (int i = 0; i < NUM_AXIS; i++) position[i] = target[i];
1012
   for (int i = 0; i < NUM_AXIS; i++) position[i] = target[i];
1085
 
1013
 
1086
-  planner_recalculate();
1014
+  recalculate();
1087
 
1015
 
1088
   stepper.wake_up();
1016
   stepper.wake_up();
1089
 
1017
 
1090
-} // plan_buffer_line()
1018
+} // buffer_line()
1091
 
1019
 
1092
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA)
1020
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA)
1093
 
1021
 
1096
    *
1024
    *
1097
    * On CORE machines XYZ is derived from ABC.
1025
    * On CORE machines XYZ is derived from ABC.
1098
    */
1026
    */
1099
-  vector_3 plan_get_position() {
1027
+  vector_3 Planner::adjusted_position() {
1100
     vector_3 position = vector_3(stepper.get_axis_position_mm(X_AXIS), stepper.get_axis_position_mm(Y_AXIS), stepper.get_axis_position_mm(Z_AXIS));
1028
     vector_3 position = vector_3(stepper.get_axis_position_mm(X_AXIS), stepper.get_axis_position_mm(Y_AXIS), stepper.get_axis_position_mm(Z_AXIS));
1101
 
1029
 
1102
-    //position.debug("in plan_get position");
1103
-    //plan_bed_level_matrix.debug("in plan_get_position");
1104
-    matrix_3x3 inverse = matrix_3x3::transpose(plan_bed_level_matrix);
1105
-    //inverse.debug("in plan_get inverse");
1030
+    //position.debug("in Planner::position");
1031
+    //bed_level_matrix.debug("in Planner::position");
1032
+
1033
+    matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
1034
+    //inverse.debug("in Planner::inverse");
1035
+
1106
     position.apply_rotation(inverse);
1036
     position.apply_rotation(inverse);
1107
     //position.debug("after rotation");
1037
     //position.debug("after rotation");
1108
 
1038
 
1117
  * On CORE machines stepper ABC will be translated from the given XYZ.
1047
  * On CORE machines stepper ABC will be translated from the given XYZ.
1118
  */
1048
  */
1119
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
1049
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
1120
-  void plan_set_position(float x, float y, float z, const float& e)
1050
+  void Planner::set_position(float x, float y, float z, const float& e)
1121
 #else
1051
 #else
1122
-  void plan_set_position(const float& x, const float& y, const float& z, const float& e)
1052
+  void Planner::set_position(const float& x, const float& y, const float& z, const float& e)
1123
 #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
1053
 #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
1124
   {
1054
   {
1125
     #if ENABLED(MESH_BED_LEVELING)
1055
     #if ENABLED(MESH_BED_LEVELING)
1126
       if (mbl.active) z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
1056
       if (mbl.active) z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
1127
     #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
1057
     #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
1128
-      apply_rotation_xyz(plan_bed_level_matrix, x, y, z);
1058
+      apply_rotation_xyz(bed_level_matrix, x, y, z);
1129
     #endif
1059
     #endif
1130
 
1060
 
1131
     long nx = position[X_AXIS] = lround(x * axis_steps_per_unit[X_AXIS]),
1061
     long nx = position[X_AXIS] = lround(x * axis_steps_per_unit[X_AXIS]),
1138
     for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = 0.0;
1068
     for (int i = 0; i < NUM_AXIS; i++) previous_speed[i] = 0.0;
1139
   }
1069
   }
1140
 
1070
 
1141
-void plan_set_e_position(const float& e) {
1071
+/**
1072
+ * Directly set the planner E position (hence the stepper E position).
1073
+ */
1074
+void Planner::set_e_position(const float& e) {
1142
   position[E_AXIS] = lround(e * axis_steps_per_unit[E_AXIS]);
1075
   position[E_AXIS] = lround(e * axis_steps_per_unit[E_AXIS]);
1143
   stepper.set_e_position(position[E_AXIS]);
1076
   stepper.set_e_position(position[E_AXIS]);
1144
 }
1077
 }
1145
 
1078
 
1146
-// Calculate the steps/s^2 acceleration rates, based on the mm/s^s
1147
-void reset_acceleration_rates() {
1079
+// Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
1080
+void Planner::reset_acceleration_rates() {
1148
   for (int i = 0; i < NUM_AXIS; i++)
1081
   for (int i = 0; i < NUM_AXIS; i++)
1149
     axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
1082
     axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
1150
 }
1083
 }
1084
+
1085
+#if ENABLED(AUTOTEMP)
1086
+
1087
+  void Planner::autotemp_M109() {
1088
+    autotemp_enabled = code_seen('F');
1089
+    if (autotemp_enabled) autotemp_factor = code_value();
1090
+    if (code_seen('S')) autotemp_min = code_value();
1091
+    if (code_seen('B')) autotemp_max = code_value();
1092
+  }
1093
+
1094
+#endif

+ 228
- 92
Marlin/planner.h View File

48
 
48
 
49
 #include "Marlin.h"
49
 #include "Marlin.h"
50
 
50
 
51
-// This struct is used when buffering the setup for each linear movement "nominal" values are as specified in
52
-// the source g-code and may never actually be reached if acceleration management is active.
51
+#if ENABLED(AUTO_BED_LEVELING_FEATURE)
52
+  #include "vector_3.h"
53
+#endif
54
+
55
+class Planner;
56
+extern Planner planner;
57
+
58
+/**
59
+ * struct block_t
60
+ *
61
+ * A single entry in the planner buffer.
62
+ * Tracks linear movement over multiple axes.
63
+ *
64
+ * The "nominal" values are as-specified by gcode, and
65
+ * may never actually be reached due to acceleration limits.
66
+ */
53
 typedef struct {
67
 typedef struct {
68
+
69
+  unsigned char active_extruder;            // The extruder to move (if E move)
70
+
54
   // Fields used by the bresenham algorithm for tracing the line
71
   // Fields used by the bresenham algorithm for tracing the line
55
   long steps[NUM_AXIS];                     // Step count along each axis
72
   long steps[NUM_AXIS];                     // Step count along each axis
56
   unsigned long step_event_count;           // The number of step events required to complete this block
73
   unsigned long step_event_count;           // The number of step events required to complete this block
74
+
57
   long accelerate_until;                    // The index of the step event on which to stop acceleration
75
   long accelerate_until;                    // The index of the step event on which to stop acceleration
58
   long decelerate_after;                    // The index of the step event on which to start decelerating
76
   long decelerate_after;                    // The index of the step event on which to start decelerating
59
   long acceleration_rate;                   // The acceleration rate used for acceleration calculation
77
   long acceleration_rate;                   // The acceleration rate used for acceleration calculation
78
+
60
   unsigned char direction_bits;             // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
79
   unsigned char direction_bits;             // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
61
-  unsigned char active_extruder;            // Selects the active extruder
80
+
62
   #if ENABLED(ADVANCE)
81
   #if ENABLED(ADVANCE)
63
     long advance_rate;
82
     long advance_rate;
64
     volatile long initial_advance;
83
     volatile long initial_advance;
67
   #endif
86
   #endif
68
 
87
 
69
   // Fields used by the motion planner to manage acceleration
88
   // Fields used by the motion planner to manage acceleration
70
-  // float speed_x, speed_y, speed_z, speed_e;          // Nominal mm/sec for each axis
71
   float nominal_speed;                               // The nominal speed for this block in mm/sec
89
   float nominal_speed;                               // The nominal speed for this block in mm/sec
72
   float entry_speed;                                 // Entry speed at previous-current junction in mm/sec
90
   float entry_speed;                                 // Entry speed at previous-current junction in mm/sec
73
   float max_entry_speed;                             // Maximum allowable junction entry speed in mm/sec
91
   float max_entry_speed;                             // Maximum allowable junction entry speed in mm/sec
97
 
115
 
98
 #define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
116
 #define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
99
 
117
 
100
-// Initialize the motion plan subsystem
101
-void plan_init();
118
+class Planner {
102
 
119
 
103
-void check_axes_activity();
120
+  public:
104
 
121
 
105
-// Get the number of buffered moves
106
-extern volatile unsigned char block_buffer_head;
107
-extern volatile unsigned char block_buffer_tail;
108
-FORCE_INLINE uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); }
122
+    /**
123
+     * A ring buffer of moves described in steps
124
+     */
125
+    block_t block_buffer[BLOCK_BUFFER_SIZE];
126
+    volatile uint8_t block_buffer_head = 0;           // Index of the next block to be pushed
127
+    volatile uint8_t block_buffer_tail = 0;
128
+
129
+    float max_feedrate[NUM_AXIS]; // Max speeds in mm per minute
130
+    float axis_steps_per_unit[NUM_AXIS];
131
+    unsigned long axis_steps_per_sqr_second[NUM_AXIS];
132
+    unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
133
+
134
+    millis_t min_segment_time;
135
+    float min_feedrate;
136
+    float acceleration;         // Normal acceleration mm/s^2  DEFAULT ACCELERATION for all printing moves. M204 SXXXX
137
+    float retract_acceleration; // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
138
+    float travel_acceleration;  // Travel acceleration mm/s^2  DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
139
+    float max_xy_jerk;          // The largest speed change requiring no acceleration
140
+    float max_z_jerk;
141
+    float max_e_jerk;
142
+    float min_travel_feedrate;
143
+
144
+    #if ENABLED(AUTO_BED_LEVELING_FEATURE)
145
+      matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
146
+    #endif
147
+
148
+  private:
109
 
149
 
110
-#if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
150
+    /**
151
+     * The current position of the tool in absolute steps
152
+     * Reclculated if any axis_steps_per_unit are changed by gcode
153
+     */
154
+    long position[NUM_AXIS] = { 0 };
111
 
155
 
112
-  #if ENABLED(AUTO_BED_LEVELING_FEATURE)
113
-    #include "vector_3.h"
156
+    /**
157
+     * Speed of previous path line segment
158
+     */
159
+    float previous_speed[NUM_AXIS];
160
+
161
+    /**
162
+     * Nominal speed of previous path line segment
163
+     */
164
+    float previous_nominal_speed;
165
+
166
+    #if ENABLED(DISABLE_INACTIVE_EXTRUDER)
167
+      /**
168
+       * Counters to manage disabling inactive extruders
169
+       */
170
+      uint8_t g_uc_extruder_last_move[EXTRUDERS] = { 0 };
171
+    #endif // DISABLE_INACTIVE_EXTRUDER
172
+
173
+    #ifdef XY_FREQUENCY_LIMIT
174
+      // Used for the frequency limit
175
+      #define MAX_FREQ_TIME (1000000.0/XY_FREQUENCY_LIMIT)
176
+      // Old direction bits. Used for speed calculations
177
+      static unsigned char old_direction_bits = 0;
178
+      // Segment times (in µs). Used for speed calculations
179
+      static long axis_segment_time[2][3] = { {MAX_FREQ_TIME + 1, 0, 0}, {MAX_FREQ_TIME + 1, 0, 0} };
180
+    #endif
181
+
182
+    #if ENABLED(DUAL_X_CARRIAGE)
183
+      extern bool extruder_duplication_enabled;
184
+    #endif
114
 
185
 
115
-    // Transform required to compensate for bed level
116
-    extern matrix_3x3 plan_bed_level_matrix;
186
+  public:
187
+
188
+    Planner();
189
+
190
+    void init();
191
+
192
+    void reset_acceleration_rates();
193
+
194
+    // Manage fans, paste pressure, etc.
195
+    void check_axes_activity();
117
 
196
 
118
     /**
197
     /**
119
-     * Get the position applying the bed level matrix
198
+     * Number of moves currently in the planner
120
      */
199
      */
121
-    vector_3 plan_get_position();
122
-  #endif  // AUTO_BED_LEVELING_FEATURE
123
-
124
-  /**
125
-   * Add a new linear movement to the buffer. x, y, z are the signed, absolute target position in
126
-   * millimeters. Feed rate specifies the (target) speed of the motion.
127
-   */
128
-  void plan_buffer_line(float x, float y, float z, const float& e, float feed_rate, const uint8_t extruder);
129
-
130
-  /**
131
-   * Set the planner positions. Used for G92 instructions.
132
-   * Multiplies by axis_steps_per_unit[] to set stepper positions.
133
-   * Clears previous speed values.
134
-   */
135
-  void plan_set_position(float x, float y, float z, const float& e);
136
-
137
-#else
138
-
139
-  void plan_buffer_line(const float& x, const float& y, const float& z, const float& e, float feed_rate, const uint8_t extruder);
140
-  void plan_set_position(const float& x, const float& y, const float& z, const float& e);
141
-
142
-#endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
143
-
144
-void plan_set_e_position(const float& e);
145
-
146
-//===========================================================================
147
-//============================= public variables ============================
148
-//===========================================================================
149
-
150
-extern millis_t minsegmenttime;
151
-extern float max_feedrate[NUM_AXIS]; // Max speeds in mm per minute
152
-extern float axis_steps_per_unit[NUM_AXIS];
153
-extern unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
154
-extern float minimumfeedrate;
155
-extern float acceleration;         // Normal acceleration mm/s^2  DEFAULT ACCELERATION for all printing moves. M204 SXXXX
156
-extern float retract_acceleration; // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
157
-extern float travel_acceleration;  // Travel acceleration mm/s^2  DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
158
-extern float max_xy_jerk;          // The largest speed change requiring no acceleration
159
-extern float max_z_jerk;
160
-extern float max_e_jerk;
161
-extern float mintravelfeedrate;
162
-extern unsigned long axis_steps_per_sqr_second[NUM_AXIS];
163
-
164
-#if ENABLED(AUTOTEMP)
165
-  extern bool autotemp_enabled;
166
-  extern float autotemp_max;
167
-  extern float autotemp_min;
168
-  extern float autotemp_factor;
169
-#endif
200
+    FORCE_INLINE uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); }
201
+
202
+    #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
203
+
204
+      #if ENABLED(AUTO_BED_LEVELING_FEATURE)
205
+        /**
206
+         * The corrected position, applying the bed level matrix
207
+         */
208
+        vector_3 adjusted_position();
209
+      #endif
210
+
211
+      /**
212
+       * Add a new linear movement to the buffer.
213
+       *
214
+       *  x,y,z,e   - target position in mm
215
+       *  feed_rate - (target) speed of the move
216
+       *  extruder  - target extruder
217
+       */
218
+      void buffer_line(float x, float y, float z, const float& e, float feed_rate, const uint8_t extruder);
219
+
220
+      /**
221
+       * Set the planner.position and individual stepper positions.
222
+       * Used by G92, G28, G29, and other procedures.
223
+       *
224
+       * Multiplies by axis_steps_per_unit[] and does necessary conversion
225
+       * for COREXY / COREXZ to set the corresponding stepper positions.
226
+       *
227
+       * Clears previous speed values.
228
+       */
229
+      void set_position(float x, float y, float z, const float& e);
230
+
231
+    #else
232
+
233
+      void buffer_line(const float& x, const float& y, const float& z, const float& e, float feed_rate, const uint8_t extruder);
234
+      void set_position(const float& x, const float& y, const float& z, const float& e);
235
+
236
+    #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
237
+
238
+    /**
239
+     * Set the E position (mm) of the planner (and the E stepper)
240
+     */
241
+    void set_e_position(const float& e);
242
+
243
+    /**
244
+     * Does the buffer have any blocks queued?
245
+     */
246
+    FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
247
+
248
+    /**
249
+     * "Discards" the block and "releases" the memory.
250
+     * Called when the current block is no longer needed.
251
+     */
252
+    FORCE_INLINE void discard_current_block() {
253
+      if (blocks_queued())
254
+        block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
255
+    }
256
+
257
+    /**
258
+     * The current block. NULL if the buffer is empty.
259
+     * This also marks the block as busy.
260
+     */
261
+    FORCE_INLINE block_t* get_current_block() {
262
+      if (blocks_queued()) {
263
+        block_t* block = &block_buffer[block_buffer_tail];
264
+        block->busy = true;
265
+        return block;
266
+      }
267
+      else
268
+        return NULL;
269
+    }
270
+
271
+    /**
272
+     * Get the index of the next / previous block in the ring buffer
273
+     */
274
+    FORCE_INLINE int8_t next_block_index(int8_t block_index) { return BLOCK_MOD(block_index + 1); }
275
+    FORCE_INLINE int8_t prev_block_index(int8_t block_index) { return BLOCK_MOD(block_index - 1); }
276
+
277
+    /**
278
+     * Calculate the distance (not time) it takes to accelerate
279
+     * from initial_rate to target_rate using the given acceleration:
280
+     */
281
+    FORCE_INLINE float estimate_acceleration_distance(float initial_rate, float target_rate, float acceleration) {
282
+      if (acceleration == 0) return 0; // acceleration was 0, set acceleration distance to 0
283
+      return (target_rate * target_rate - initial_rate * initial_rate) / (acceleration * 2);
284
+    }
285
+
286
+    /**
287
+     * Return the point at which you must start braking (at the rate of -'acceleration') if
288
+     * you start at 'initial_rate', accelerate (until reaching the point), and want to end at
289
+     * 'final_rate' after traveling 'distance'.
290
+     *
291
+     * This is used to compute the intersection point between acceleration and deceleration
292
+     * in cases where the "trapezoid" has no plateau (i.e., never reaches maximum speed)
293
+     */
294
+    FORCE_INLINE float intersection_distance(float initial_rate, float final_rate, float acceleration, float distance) {
295
+      if (acceleration == 0) return 0; // acceleration was 0, set intersection distance to 0
296
+      return (acceleration * 2 * distance - initial_rate * initial_rate + final_rate * final_rate) / (acceleration * 4);
297
+    }
298
+
299
+    /**
300
+     * Calculate the maximum allowable speed at this point, in order
301
+     * to reach 'target_velocity' using 'acceleration' within a given
302
+     * 'distance'.
303
+     */
304
+    FORCE_INLINE float max_allowable_speed(float acceleration, float target_velocity, float distance) {
305
+      return sqrt(target_velocity * target_velocity - 2 * acceleration * distance);
306
+    }
307
+
308
+
309
+    #if ENABLED(AUTOTEMP)
310
+      float autotemp_max = 250;
311
+      float autotemp_min = 210;
312
+      float autotemp_factor = 0.1;
313
+      bool autotemp_enabled = false;
314
+      void getHighESpeed();
315
+      void autotemp_M109();
316
+    #endif
317
+
318
+  private:
319
+
320
+    void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exit_factor);
321
+
322
+    void reverse_pass_kernel(block_t* previous, block_t* current, block_t* next);
323
+    void forward_pass_kernel(block_t* previous, block_t* current, block_t* next);
324
+
325
+    void reverse_pass();
326
+    void forward_pass();
327
+
328
+    void recalculate_trapezoids();
329
+
330
+    void recalculate();
170
 
331
 
171
-extern block_t block_buffer[BLOCK_BUFFER_SIZE];            // A ring buffer for motion instructions
172
-extern volatile unsigned char block_buffer_head;           // Index of the next block to be pushed
173
-extern volatile unsigned char block_buffer_tail;
174
-
175
-// Returns true if the buffer has a queued block, false otherwise
176
-FORCE_INLINE bool blocks_queued() { return (block_buffer_head != block_buffer_tail); }
177
-
178
-// Called when the current block is no longer needed. Discards
179
-// the block and makes the memory available for new blocks.
180
-FORCE_INLINE void plan_discard_current_block() {
181
-  if (blocks_queued())
182
-    block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
183
-}
184
-
185
-// Gets the current block. Returns NULL if buffer empty
186
-FORCE_INLINE block_t* plan_get_current_block() {
187
-  if (blocks_queued()) {
188
-    block_t* block = &block_buffer[block_buffer_tail];
189
-    block->busy = true;
190
-    return block;
191
-  }
192
-  else
193
-    return NULL;
194
-}
195
-
196
-void reset_acceleration_rates();
332
+};
197
 
333
 
198
 #endif // PLANNER_H
334
 #endif // PLANNER_H

+ 6
- 6
Marlin/stepper.cpp View File

242
 void Stepper::isr() {
242
 void Stepper::isr() {
243
   if (cleaning_buffer_counter) {
243
   if (cleaning_buffer_counter) {
244
     current_block = NULL;
244
     current_block = NULL;
245
-    plan_discard_current_block();
245
+    planner.discard_current_block();
246
     #ifdef SD_FINISHED_RELEASECOMMAND
246
     #ifdef SD_FINISHED_RELEASECOMMAND
247
       if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
247
       if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
248
     #endif
248
     #endif
254
   // If there is no current block, attempt to pop one from the buffer
254
   // If there is no current block, attempt to pop one from the buffer
255
   if (!current_block) {
255
   if (!current_block) {
256
     // Anything in the buffer?
256
     // Anything in the buffer?
257
-    current_block = plan_get_current_block();
257
+    current_block = planner.get_current_block();
258
     if (current_block) {
258
     if (current_block) {
259
       current_block->busy = true;
259
       current_block->busy = true;
260
       trapezoid_generator_reset();
260
       trapezoid_generator_reset();
396
     // If current block is finished, reset pointer
396
     // If current block is finished, reset pointer
397
     if (step_events_completed >= current_block->step_event_count) {
397
     if (step_events_completed >= current_block->step_event_count) {
398
       current_block = NULL;
398
       current_block = NULL;
399
-      plan_discard_current_block();
399
+      planner.discard_current_block();
400
     }
400
     }
401
   }
401
   }
402
 }
402
 }
620
 /**
620
 /**
621
  * Block until all buffered steps are executed
621
  * Block until all buffered steps are executed
622
  */
622
  */
623
-void Stepper::synchronize() { while (blocks_queued()) idle(); }
623
+void Stepper::synchronize() { while (planner.blocks_queued()) idle(); }
624
 
624
 
625
 /**
625
 /**
626
  * Set the stepper positions directly in steps
626
  * Set the stepper positions directly in steps
693
   #else
693
   #else
694
     axis_steps = position(axis);
694
     axis_steps = position(axis);
695
   #endif
695
   #endif
696
-  return axis_steps / axis_steps_per_unit[axis];
696
+  return axis_steps / planner.axis_steps_per_unit[axis];
697
 }
697
 }
698
 
698
 
699
 void Stepper::finish_and_disable() {
699
 void Stepper::finish_and_disable() {
704
 void Stepper::quick_stop() {
704
 void Stepper::quick_stop() {
705
   cleaning_buffer_counter = 5000;
705
   cleaning_buffer_counter = 5000;
706
   DISABLE_STEPPER_DRIVER_INTERRUPT();
706
   DISABLE_STEPPER_DRIVER_INTERRUPT();
707
-  while (blocks_queued()) plan_discard_current_block();
707
+  while (planner.blocks_queued()) planner.discard_current_block();
708
   current_block = NULL;
708
   current_block = NULL;
709
   ENABLE_STEPPER_DRIVER_INTERRUPT();
709
   ENABLE_STEPPER_DRIVER_INTERRUPT();
710
 }
710
 }

+ 1
- 1
Marlin/stepper.h View File

245
     // Triggered position of an axis in mm (not core-savvy)
245
     // Triggered position of an axis in mm (not core-savvy)
246
     //
246
     //
247
     FORCE_INLINE float triggered_position_mm(AxisEnum axis) {
247
     FORCE_INLINE float triggered_position_mm(AxisEnum axis) {
248
-      return endstops_trigsteps[axis] / axis_steps_per_unit[axis];
248
+      return endstops_trigsteps[axis] / planner.axis_steps_per_unit[axis];
249
     }
249
     }
250
 
250
 
251
     FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
251
     FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {

+ 1
- 1
Marlin/temperature.cpp View File

613
               lpq[lpq_ptr++] = 0;
613
               lpq[lpq_ptr++] = 0;
614
             }
614
             }
615
             if (lpq_ptr >= lpq_len) lpq_ptr = 0;
615
             if (lpq_ptr >= lpq_len) lpq_ptr = 0;
616
-            cTerm[e] = (lpq[lpq_ptr] / axis_steps_per_unit[E_AXIS]) * PID_PARAM(Kc, e);
616
+            cTerm[e] = (lpq[lpq_ptr] / planner.axis_steps_per_unit[E_AXIS]) * PID_PARAM(Kc, e);
617
             pid_output += cTerm[e];
617
             pid_output += cTerm[e];
618
           }
618
           }
619
         #endif //PID_ADD_EXTRUSION_RATE
619
         #endif //PID_ADD_EXTRUSION_RATE

+ 7
- 3
Marlin/temperature.h View File

79
   extern unsigned char soft_pwm_bed;
79
   extern unsigned char soft_pwm_bed;
80
 #endif
80
 #endif
81
 
81
 
82
+#if ENABLED(FAN_SOFT_PWM)
83
+  extern unsigned char fanSpeedSoftPwm[FAN_COUNT];
84
+#endif
85
+
82
 #if ENABLED(PIDTEMP)
86
 #if ENABLED(PIDTEMP)
83
 
87
 
84
   #if ENABLED(PID_PARAMS_PER_EXTRUDER)
88
   #if ENABLED(PID_PARAMS_PER_EXTRUDER)
178
 
182
 
179
 FORCE_INLINE void autotempShutdown() {
183
 FORCE_INLINE void autotempShutdown() {
180
   #if ENABLED(AUTOTEMP)
184
   #if ENABLED(AUTOTEMP)
181
-    if (autotemp_enabled) {
182
-      autotemp_enabled = false;
183
-      if (degTargetHotend(active_extruder) > autotemp_min)
185
+    if (planner.autotemp_enabled) {
186
+      planner.autotemp_enabled = false;
187
+      if (degTargetHotend(active_extruder) > planner.autotemp_min)
184
         setTargetHotend(0, active_extruder);
188
         setTargetHotend(0, active_extruder);
185
     }
189
     }
186
   #endif
190
   #endif

+ 35
- 33
Marlin/ultralcd.cpp View File

463
 inline void line_to_current(AxisEnum axis) {
463
 inline void line_to_current(AxisEnum axis) {
464
   #if ENABLED(DELTA)
464
   #if ENABLED(DELTA)
465
     calculate_delta(current_position);
465
     calculate_delta(current_position);
466
-    plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
466
+    planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
467
   #else
467
   #else
468
-    plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
468
+    planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis]/60, active_extruder);
469
   #endif
469
   #endif
470
 }
470
 }
471
 
471
 
495
 static void lcd_main_menu() {
495
 static void lcd_main_menu() {
496
   START_MENU();
496
   START_MENU();
497
   MENU_ITEM(back, MSG_WATCH);
497
   MENU_ITEM(back, MSG_WATCH);
498
-  if (movesplanned() || IS_SD_PRINTING) {
498
+  if (planner.movesplanned() || IS_SD_PRINTING) {
499
     MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
499
     MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
500
   }
500
   }
501
   else {
501
   else {
934
     ENCODER_DIRECTION_NORMAL();
934
     ENCODER_DIRECTION_NORMAL();
935
 
935
 
936
     // Encoder wheel adjusts the Z position
936
     // Encoder wheel adjusts the Z position
937
-    if (encoderPosition && movesplanned() <= 3) {
937
+    if (encoderPosition && planner.movesplanned() <= 3) {
938
       refresh_cmd_timeout();
938
       refresh_cmd_timeout();
939
       current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
939
       current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
940
       NOLESS(current_position[Z_AXIS], 0);
940
       NOLESS(current_position[Z_AXIS], 0);
1037
     if (LCD_CLICKED) {
1037
     if (LCD_CLICKED) {
1038
       _lcd_level_bed_position = 0;
1038
       _lcd_level_bed_position = 0;
1039
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1039
       current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
1040
-      plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1040
+      planner.set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1041
       lcd_goto_menu(_lcd_level_goto_next_point, true);
1041
       lcd_goto_menu(_lcd_level_goto_next_point, true);
1042
     }
1042
     }
1043
   }
1043
   }
1191
 
1191
 
1192
 static void _lcd_move(const char* name, AxisEnum axis, float min, float max) {
1192
 static void _lcd_move(const char* name, AxisEnum axis, float min, float max) {
1193
   ENCODER_DIRECTION_NORMAL();
1193
   ENCODER_DIRECTION_NORMAL();
1194
-  if (encoderPosition && movesplanned() <= 3) {
1194
+  if (encoderPosition && planner.movesplanned() <= 3) {
1195
     refresh_cmd_timeout();
1195
     refresh_cmd_timeout();
1196
     current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
1196
     current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
1197
     if (min_software_endstops) NOLESS(current_position[axis], min);
1197
     if (min_software_endstops) NOLESS(current_position[axis], min);
1223
     unsigned short original_active_extruder = active_extruder;
1223
     unsigned short original_active_extruder = active_extruder;
1224
     active_extruder = e;
1224
     active_extruder = e;
1225
   #endif
1225
   #endif
1226
-  if (encoderPosition && movesplanned() <= 3) {
1226
+  if (encoderPosition && planner.movesplanned() <= 3) {
1227
     current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
1227
     current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
1228
     line_to_current(E_AXIS);
1228
     line_to_current(E_AXIS);
1229
     lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1229
     lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1511
   // Autotemp, Min, Max, Fact
1511
   // Autotemp, Min, Max, Fact
1512
   //
1512
   //
1513
   #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
1513
   #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
1514
-    MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
1515
-    MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 15);
1516
-    MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 15);
1517
-    MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
1514
+    MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
1515
+    MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
1516
+    MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
1517
+    MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
1518
   #endif
1518
   #endif
1519
 
1519
 
1520
   //
1520
   //
1618
   END_MENU();
1618
   END_MENU();
1619
 }
1619
 }
1620
 
1620
 
1621
+static void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
1622
+
1621
 /**
1623
 /**
1622
  *
1624
  *
1623
  * "Control" > "Motion" submenu
1625
  * "Control" > "Motion" submenu
1633
   #if ENABLED(MANUAL_BED_LEVELING)
1635
   #if ENABLED(MANUAL_BED_LEVELING)
1634
     MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
1636
     MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
1635
   #endif
1637
   #endif
1636
-  MENU_ITEM_EDIT(float5, MSG_ACC, &acceleration, 10, 99000);
1637
-  MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &max_xy_jerk, 1, 990);
1638
+  MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
1639
+  MENU_ITEM_EDIT(float3, MSG_VXY_JERK, &planner.max_xy_jerk, 1, 990);
1638
   #if ENABLED(DELTA)
1640
   #if ENABLED(DELTA)
1639
-    MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &max_z_jerk, 1, 990);
1641
+    MENU_ITEM_EDIT(float3, MSG_VZ_JERK, &planner.max_z_jerk, 1, 990);
1640
   #else
1642
   #else
1641
-    MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &max_z_jerk, 0.1, 990);
1643
+    MENU_ITEM_EDIT(float52, MSG_VZ_JERK, &planner.max_z_jerk, 0.1, 990);
1642
   #endif
1644
   #endif
1643
-  MENU_ITEM_EDIT(float3, MSG_VE_JERK, &max_e_jerk, 1, 990);
1644
-  MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &max_feedrate[X_AXIS], 1, 999);
1645
-  MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &max_feedrate[Y_AXIS], 1, 999);
1646
-  MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &max_feedrate[Z_AXIS], 1, 999);
1647
-  MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &max_feedrate[E_AXIS], 1, 999);
1648
-  MENU_ITEM_EDIT(float3, MSG_VMIN, &minimumfeedrate, 0, 999);
1649
-  MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &mintravelfeedrate, 0, 999);
1650
-  MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, reset_acceleration_rates);
1651
-  MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, reset_acceleration_rates);
1652
-  MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &max_acceleration_units_per_sq_second[Z_AXIS], 10, 99000, reset_acceleration_rates);
1653
-  MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, reset_acceleration_rates);
1654
-  MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &retract_acceleration, 100, 99000);
1655
-  MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &travel_acceleration, 100, 99000);
1656
-  MENU_ITEM_EDIT(float52, MSG_XSTEPS, &axis_steps_per_unit[X_AXIS], 5, 9999);
1657
-  MENU_ITEM_EDIT(float52, MSG_YSTEPS, &axis_steps_per_unit[Y_AXIS], 5, 9999);
1645
+  MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_e_jerk, 1, 990);
1646
+  MENU_ITEM_EDIT(float3, MSG_VMAX MSG_X, &planner.max_feedrate[X_AXIS], 1, 999);
1647
+  MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Y, &planner.max_feedrate[Y_AXIS], 1, 999);
1648
+  MENU_ITEM_EDIT(float3, MSG_VMAX MSG_Z, &planner.max_feedrate[Z_AXIS], 1, 999);
1649
+  MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate[E_AXIS], 1, 999);
1650
+  MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate, 0, 999);
1651
+  MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate, 0, 999);
1652
+  MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_X, &planner.max_acceleration_units_per_sq_second[X_AXIS], 100, 99000, _reset_acceleration_rates);
1653
+  MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Y, &planner.max_acceleration_units_per_sq_second[Y_AXIS], 100, 99000, _reset_acceleration_rates);
1654
+  MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_Z, &planner.max_acceleration_units_per_sq_second[Z_AXIS], 10, 99000, _reset_acceleration_rates);
1655
+  MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_units_per_sq_second[E_AXIS], 100, 99000, _reset_acceleration_rates);
1656
+  MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
1657
+  MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
1658
+  MENU_ITEM_EDIT(float52, MSG_XSTEPS, &planner.axis_steps_per_unit[X_AXIS], 5, 9999);
1659
+  MENU_ITEM_EDIT(float52, MSG_YSTEPS, &planner.axis_steps_per_unit[Y_AXIS], 5, 9999);
1658
   #if ENABLED(DELTA)
1660
   #if ENABLED(DELTA)
1659
-    MENU_ITEM_EDIT(float52, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
1661
+    MENU_ITEM_EDIT(float52, MSG_ZSTEPS, &planner.axis_steps_per_unit[Z_AXIS], 5, 9999);
1660
   #else
1662
   #else
1661
-    MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &axis_steps_per_unit[Z_AXIS], 5, 9999);
1663
+    MENU_ITEM_EDIT(float51, MSG_ZSTEPS, &planner.axis_steps_per_unit[Z_AXIS], 5, 9999);
1662
   #endif
1664
   #endif
1663
-  MENU_ITEM_EDIT(float51, MSG_ESTEPS, &axis_steps_per_unit[E_AXIS], 5, 9999);
1665
+  MENU_ITEM_EDIT(float51, MSG_ESTEPS, &planner.axis_steps_per_unit[E_AXIS], 5, 9999);
1664
   #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
1666
   #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
1665
     MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &abort_on_endstop_hit);
1667
     MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &abort_on_endstop_hit);
1666
   #endif
1668
   #endif

Loading…
Cancel
Save