Pārlūkot izejas kodu

Planner singleton class

Scott Lahteine 8 gadus atpakaļ
vecāks
revīzija
96f51f400f

+ 6
- 0
Marlin/Marlin.h Parādīt failu

@@ -283,6 +283,12 @@ extern float sw_endstop_max[3]; // axis[n].sw_endstop_max
283 283
 extern bool axis_known_position[3]; // axis[n].is_known
284 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 292
 #if ENABLED(DELTA)
287 293
   #ifndef DELTA_RADIUS_TRIM_TOWER_1
288 294
     #define DELTA_RADIUS_TRIM_TOWER_1 0.0

+ 94
- 98
Marlin/Marlin_main.cpp Parādīt failu

@@ -149,7 +149,7 @@
149 149
  * M84  - Disable steppers until next move,
150 150
  *        or use S<seconds> to specify an inactivity timeout, after which the steppers will be disabled.  S0 to disable the timeout.
151 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 153
  * M104 - Set extruder target temp
154 154
  * M105 - Read current temp
155 155
  * M106 - Fan on
@@ -540,7 +540,7 @@ static void report_current_position();
540 540
       if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position_delta", current_position);
541 541
     #endif
542 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 545
 #endif
546 546
 
@@ -817,7 +817,6 @@ void setup() {
817 817
   lcd_init();
818 818
 
819 819
   tp_init();    // Initialize temperature loop
820
-  plan_init();  // Initialize planner;
821 820
 
822 821
   #if ENABLED(DELTA) || ENABLED(SCARA)
823 822
     // Vital to init kinematic equivalent for X0 Y0 Z0
@@ -1405,17 +1404,17 @@ inline void set_homing_bump_feedrate(AxisEnum axis) {
1405 1404
 // (or from wherever it has been told it is located).
1406 1405
 //
1407 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 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 1413
 // line_to_destination
1415 1414
 // Move the planner, not necessarily synced with current_position
1416 1415
 //
1417 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 1419
 inline void line_to_destination() {
1421 1420
   line_to_destination(feedrate);
@@ -1430,9 +1429,9 @@ inline void sync_plan_position() {
1430 1429
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1431 1430
     if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position", current_position);
1432 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 1435
 inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); }
1437 1436
 inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); }
1438 1437
 
@@ -1459,7 +1458,7 @@ static void setup_for_endstop_move() {
1459 1458
       #endif
1460 1459
       refresh_cmd_timeout();
1461 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 1462
       set_current_to_destination();
1464 1463
     }
1465 1464
   #endif
@@ -1470,21 +1469,21 @@ static void setup_for_endstop_move() {
1470 1469
 
1471 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 1474
         #if ENABLED(DEBUG_LEVELING_FEATURE)
1476
-          plan_bed_level_matrix.set_to_identity();
1475
+          planner.bed_level_matrix.set_to_identity();
1477 1476
           if (DEBUGGING(LEVELING)) {
1478
-            vector_3 uncorrected_position = plan_get_position();
1477
+            vector_3 uncorrected_position = planner.adjusted_position();
1479 1478
             DEBUG_POS(">>> set_bed_level_equation_lsq", uncorrected_position);
1480 1479
             DEBUG_POS(">>> set_bed_level_equation_lsq", current_position);
1481 1480
           }
1482 1481
         #endif
1483 1482
 
1484 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 1487
         current_position[X_AXIS] = corrected_position.x;
1489 1488
         current_position[Y_AXIS] = corrected_position.y;
1490 1489
         current_position[Z_AXIS] = corrected_position.z;
@@ -1502,7 +1501,7 @@ static void setup_for_endstop_move() {
1502 1501
 
1503 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 1506
       vector_3 pt1 = vector_3(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, z_at_pt_1);
1508 1507
       vector_3 pt2 = vector_3(ABL_PROBE_PT_2_X, ABL_PROBE_PT_2_Y, z_at_pt_2);
@@ -1515,9 +1514,9 @@ static void setup_for_endstop_move() {
1515 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 1521
       #if ENABLED(DEBUG_LEVELING_FEATURE)
1523 1522
         if (DEBUGGING(LEVELING)) {
@@ -1568,7 +1567,7 @@ static void setup_for_endstop_move() {
1568 1567
        * is not where we said to go.
1569 1568
        */
1570 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 1571
       current_position[Z_AXIS] = mm;
1573 1572
 
1574 1573
       #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -1579,7 +1578,7 @@ static void setup_for_endstop_move() {
1579 1578
 
1580 1579
     #else // !DELTA
1581 1580
 
1582
-      plan_bed_level_matrix.set_to_identity();
1581
+      planner.bed_level_matrix.set_to_identity();
1583 1582
       feedrate = homing_feedrate[Z_AXIS];
1584 1583
 
1585 1584
       // Move down until the Z probe (or endstop?) is triggered
@@ -1589,7 +1588,7 @@ static void setup_for_endstop_move() {
1589 1588
 
1590 1589
       // Tell the planner where we ended up - Get this from the stepper handler
1591 1590
       zPosition = stepper.get_axis_position_mm(Z_AXIS);
1592
-      plan_set_position(
1591
+      planner.set_position(
1593 1592
         current_position[X_AXIS], current_position[Y_AXIS], zPosition,
1594 1593
         current_position[E_AXIS]
1595 1594
       );
@@ -2552,7 +2551,7 @@ inline void gcode_G28() {
2552 2551
 
2553 2552
   // For auto bed leveling, clear the level matrix
2554 2553
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
2555
-    plan_bed_level_matrix.set_to_identity();
2554
+    planner.bed_level_matrix.set_to_identity();
2556 2555
     #if ENABLED(DELTA)
2557 2556
       reset_bed_level();
2558 2557
     #endif
@@ -2630,7 +2629,7 @@ inline void gcode_G28() {
2630 2629
       // Raise Z before homing any other axes and z is not already high enough (never lower z)
2631 2630
       if (current_position[Z_AXIS] <= MIN_Z_HEIGHT_FOR_HOMING) {
2632 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 2633
         #if ENABLED(DEBUG_LEVELING_FEATURE)
2635 2634
           if (DEBUGGING(LEVELING)) {
2636 2635
             SERIAL_ECHOPAIR("Raise Z (before homing) to ", (MIN_Z_HEIGHT_FOR_HOMING));
@@ -3201,22 +3200,22 @@ inline void gcode_G28() {
3201 3200
 
3202 3201
       #if ENABLED(DEBUG_LEVELING_FEATURE) && DISABLED(DELTA)
3203 3202
         if (DEBUGGING(LEVELING)) {
3204
-          vector_3 corrected_position = plan_get_position();
3203
+          vector_3 corrected_position = planner.adjusted_position();
3205 3204
           DEBUG_POS("BEFORE matrix.set_to_identity", corrected_position);
3206 3205
           DEBUG_POS("BEFORE matrix.set_to_identity", current_position);
3207 3206
         }
3208 3207
       #endif
3209 3208
 
3210 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 3212
       #if ENABLED(DELTA)
3214 3213
         reset_bed_level();
3215 3214
       #else //!DELTA
3216 3215
 
3217
-        //vector_3 corrected_position = plan_get_position();
3216
+        //vector_3 corrected_position = planner.adjusted_position();
3218 3217
         //corrected_position.debug("position before G29");
3219
-        vector_3 uncorrected_position = plan_get_position();
3218
+        vector_3 uncorrected_position = planner.adjusted_position();
3220 3219
         //uncorrected_position.debug("position during G29");
3221 3220
         current_position[X_AXIS] = uncorrected_position.x;
3222 3221
         current_position[Y_AXIS] = uncorrected_position.y;
@@ -3415,7 +3414,7 @@ inline void gcode_G28() {
3415 3414
                     y_tmp = eqnAMatrix[ind + 1 * abl2],
3416 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 3419
               NOMORE(min_diff, eqnBVector[ind] - z_tmp);
3421 3420
 
@@ -3438,7 +3437,7 @@ inline void gcode_G28() {
3438 3437
                       y_tmp = eqnAMatrix[ind + 1 * abl2],
3439 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 3442
                 float diff = eqnBVector[ind] - z_tmp - min_diff;
3444 3443
                 if (diff >= 0.0)
@@ -3497,7 +3496,7 @@ inline void gcode_G28() {
3497 3496
       #endif
3498 3497
     #else // !DELTA
3499 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 3501
       if (!dryrun) {
3503 3502
         /**
@@ -3508,7 +3507,7 @@ inline void gcode_G28() {
3508 3507
         float x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
3509 3508
               y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
3510 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 3512
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3514 3513
           if (DEBUGGING(LEVELING)) {
@@ -3520,13 +3519,13 @@ inline void gcode_G28() {
3520 3519
         #endif
3521 3520
 
3522 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 3525
          * Get the current Z position and send it to the planner.
3527 3526
          *
3528 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 3530
          * >> zprobe_zoffset : Z distance from nozzle to Z probe
3532 3531
          * (set by default, M851, EEPROM, or Menu)
@@ -4065,7 +4064,7 @@ inline void gcode_M42() {
4065 4064
       reset_bed_level();
4066 4065
     #else
4067 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 4068
     #endif
4070 4069
 
4071 4070
     if (Z_start_location < Z_RAISE_BEFORE_PROBING * 2.0)
@@ -4454,10 +4453,7 @@ inline void gcode_M109() {
4454 4453
   }
4455 4454
 
4456 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 4457
   #endif
4462 4458
 
4463 4459
   #if TEMP_RESIDENCY_TIME > 0
@@ -4897,15 +4893,15 @@ inline void gcode_M92() {
4897 4893
       if (i == E_AXIS) {
4898 4894
         float value = code_value();
4899 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 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,9 +4936,9 @@ static void report_current_position() {
4940 4936
     SERIAL_EOL;
4941 4937
 
4942 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 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 4942
     SERIAL_EOL; SERIAL_EOL;
4947 4943
   #endif
4948 4944
 }
@@ -5083,17 +5079,17 @@ inline void gcode_M200() {
5083 5079
 inline void gcode_M201() {
5084 5080
   for (int8_t i = 0; i < NUM_AXIS; i++) {
5085 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 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 5089
 #if 0 // Not used for Sprinter/grbl gen6
5094 5090
   inline void gcode_M202() {
5095 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 5095
 #endif
@@ -5105,7 +5101,7 @@ inline void gcode_M201() {
5105 5101
 inline void gcode_M203() {
5106 5102
   for (int8_t i = 0; i < NUM_AXIS; i++) {
5107 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,23 +5117,23 @@ inline void gcode_M203() {
5121 5117
  */
5122 5118
 inline void gcode_M204() {
5123 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 5122
     SERIAL_EOL;
5127 5123
   }
5128 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 5127
     SERIAL_EOL;
5132 5128
   }
5133 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 5132
     SERIAL_EOL;
5137 5133
   }
5138 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 5137
     SERIAL_EOL;
5142 5138
   }
5143 5139
 }
@@ -5153,12 +5149,12 @@ inline void gcode_M204() {
5153 5149
  *    E = Max E Jerk (mm/s/s)
5154 5150
  */
5155 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,7 +6000,7 @@ inline void gcode_M503() {
6004 6000
 
6005 6001
     #if ENABLED(DELTA)
6006 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 6004
     #else
6009 6005
       #define RUNPLAN line_to_destination();
6010 6006
     #endif
@@ -6097,8 +6093,8 @@ inline void gcode_M503() {
6097 6093
     #if ENABLED(DELTA)
6098 6094
       // Move XYZ to starting position, then E
6099 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 6098
     #else
6103 6099
       // Move XY to starting position, then Z, then E
6104 6100
       destination[X_AXIS] = lastpos[X_AXIS];
@@ -6292,7 +6288,7 @@ inline void gcode_T(uint8_t tmp_extruder) {
6292 6288
     #ifdef XY_TRAVEL_SPEED
6293 6289
       feedrate = XY_TRAVEL_SPEED;
6294 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 6292
     #endif
6297 6293
   }
6298 6294
 
@@ -6304,12 +6300,12 @@ inline void gcode_T(uint8_t tmp_extruder) {
6304 6300
         if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE && IsRunning() &&
6305 6301
             (delayed_move_time || current_position[X_AXIS] != x_home_pos(active_extruder))) {
6306 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 6309
           stepper.synchronize();
6314 6310
         }
6315 6311
 
@@ -7186,9 +7182,9 @@ void clamp_to_software_endstops(float target[3]) {
7186 7182
 #if ENABLED(MESH_BED_LEVELING)
7187 7183
 
7188 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 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 7188
     set_current_to_destination();
7193 7189
     return;
7194 7190
   }
@@ -7202,7 +7198,7 @@ void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_
7202 7198
   iy = min(iy, MESH_NUM_Y_POINTS - 2);
7203 7199
   if (pix == ix && piy == iy) {
7204 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 7202
     set_current_to_destination();
7207 7203
     return;
7208 7204
   }
@@ -7241,7 +7237,7 @@ void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_
7241 7237
   }
7242 7238
   else {
7243 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 7241
     set_current_to_destination();
7246 7242
     return;
7247 7243
   }
@@ -7250,12 +7246,12 @@ void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_
7250 7246
   destination[Y_AXIS] = ny;
7251 7247
   destination[Z_AXIS] = nz;
7252 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 7250
   destination[X_AXIS] = x;
7255 7251
   destination[Y_AXIS] = y;
7256 7252
   destination[Z_AXIS] = z;
7257 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 7256
 #endif  // MESH_BED_LEVELING
7261 7257
 
@@ -7314,7 +7310,7 @@ void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_
7314 7310
       //DEBUG_POS("prepare_move_delta", target);
7315 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 7315
     return true;
7320 7316
   }
@@ -7331,9 +7327,9 @@ void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_
7331 7327
     if (active_extruder_parked) {
7332 7328
       if (dual_x_carriage_mode == DXC_DUPLICATION_MODE && active_extruder == 0) {
7333 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 7333
         sync_plan_position();
7338 7334
         stepper.synchronize();
7339 7335
         extruder_duplication_enabled = true;
@@ -7353,9 +7349,9 @@ void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_
7353 7349
         }
7354 7350
         delayed_move_time = 0;
7355 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 7355
         active_extruder_parked = false;
7360 7356
       }
7361 7357
     }
@@ -7373,7 +7369,7 @@ void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_
7373 7369
     }
7374 7370
     else {
7375 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 7373
         return false;
7378 7374
       #else
7379 7375
         line_to_destination(feedrate * feedrate_multiplier / 100.0);
@@ -7387,7 +7383,7 @@ void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_
7387 7383
 /**
7388 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 7387
  *  smaller moves into the planner for DELTA or SCARA.)
7392 7388
  */
7393 7389
 void prepare_move() {
@@ -7531,9 +7527,9 @@ void plan_arc(
7531 7527
       #if ENABLED(AUTO_BED_LEVELING_FEATURE)
7532 7528
         adjust_delta(arc_target);
7533 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 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 7533
     #endif
7538 7534
   }
7539 7535
 
@@ -7543,9 +7539,9 @@ void plan_arc(
7543 7539
     #if ENABLED(AUTO_BED_LEVELING_FEATURE)
7544 7540
       adjust_delta(target);
7545 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 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 7545
   #endif
7550 7546
 
7551 7547
   // As far as the parser is concerned, the position is now == target. In reality the
@@ -7762,7 +7758,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
7762 7758
   if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) kill(PSTR(MSG_KILLED));
7763 7759
 
7764 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 7762
     #if ENABLED(DISABLE_INACTIVE_X)
7767 7763
       disable_x();
7768 7764
     #endif
@@ -7855,12 +7851,12 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
7855 7851
           #endif
7856 7852
         }
7857 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 7857
       current_position[E_AXIS] = oldepos;
7862 7858
       destination[E_AXIS] = oldedes;
7863
-      plan_set_e_position(oldepos);
7859
+      planner.set_e_position(oldepos);
7864 7860
       previous_cmd_ms = ms; // refresh_cmd_timeout()
7865 7861
       stepper.synchronize();
7866 7862
       switch (active_extruder) {
@@ -7900,7 +7896,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
7900 7896
     handle_status_leds();
7901 7897
   #endif
7902 7898
 
7903
-  check_axes_activity();
7899
+  planner.check_axes_activity();
7904 7900
 }
7905 7901
 
7906 7902
 void kill(const char* lcd_msg) {

+ 73
- 73
Marlin/configuration_store.cpp Parādīt failu

@@ -43,18 +43,18 @@
43 43
  *
44 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 58
  *  188  M206 XYZ  home_offset (float x3)
59 59
  *
60 60
  * Mesh bed leveling:
@@ -173,18 +173,18 @@ void Config_StoreSettings()  {
173 173
   char ver[4] = "000";
174 174
   int i = EEPROM_OFFSET;
175 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 188
   EEPROM_WRITE_VAR(i, home_offset);
189 189
 
190 190
   uint8_t mesh_num_x = 3;
@@ -351,22 +351,22 @@ void Config_RetrieveSettings() {
351 351
     float dummy = 0;
352 352
 
353 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 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 370
     EEPROM_READ_VAR(i, home_offset);
371 371
 
372 372
     uint8_t dummy_uint8 = 0, mesh_num_x = 0, mesh_num_y = 0;
@@ -528,9 +528,9 @@ void Config_ResetDefault() {
528 528
   float tmp2[] = DEFAULT_MAX_FEEDRATE;
529 529
   long tmp3[] = DEFAULT_MAX_ACCELERATION;
530 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 534
     #if ENABLED(SCARA)
535 535
       if (i < COUNT(axis_scaling))
536 536
         axis_scaling[i] = 1;
@@ -538,17 +538,17 @@ void Config_ResetDefault() {
538 538
   }
539 539
 
540 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 552
   home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
553 553
 
554 554
   #if ENABLED(MESH_BED_LEVELING)
@@ -653,10 +653,10 @@ void Config_PrintSettings(bool forReplay) {
653 653
     SERIAL_ECHOLNPGM("Steps per unit:");
654 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 660
   SERIAL_EOL;
661 661
 
662 662
   CONFIG_ECHO_START;
@@ -677,10 +677,10 @@ void Config_PrintSettings(bool forReplay) {
677 677
     SERIAL_ECHOLNPGM("Maximum feedrates (mm/s):");
678 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 684
   SERIAL_EOL;
685 685
 
686 686
   CONFIG_ECHO_START;
@@ -688,19 +688,19 @@ void Config_PrintSettings(bool forReplay) {
688 688
     SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):");
689 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 695
   SERIAL_EOL;
696 696
   CONFIG_ECHO_START;
697 697
   if (!forReplay) {
698 698
     SERIAL_ECHOLNPGM("Accelerations: P=printing, R=retract and T=travel");
699 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 704
   SERIAL_EOL;
705 705
 
706 706
   CONFIG_ECHO_START;
@@ -708,12 +708,12 @@ void Config_PrintSettings(bool forReplay) {
708 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 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 717
   SERIAL_EOL;
718 718
 
719 719
   CONFIG_ECHO_START;

+ 147
- 203
Marlin/planner.cpp Parādīt failu

@@ -81,105 +81,27 @@
81 81
   #include "mesh_bed_leveling.h"
82 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 105
   unsigned long initial_rate = ceil(block->nominal_rate * entry_factor),
184 106
                 final_rate = ceil(block->nominal_rate * exit_factor); // (steps per second)
185 107
 
@@ -225,12 +147,6 @@ void calculate_trapezoid_for_block(block_t* block, float entry_factor, float exi
225 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 150
 // "Junction jerk" in this context is the immediate change in speed at the junction of two blocks.
235 151
 // This method will calculate the junction jerk as the euclidean distance between the nominal
236 152
 // velocities of the respective blocks.
@@ -240,8 +156,8 @@ FORCE_INLINE float max_allowable_speed(float acceleration, float target_velocity
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 161
   if (!current) return;
246 162
   UNUSED(previous);
247 163
 
@@ -267,31 +183,34 @@ void planner_reverse_pass_kernel(block_t* previous, block_t* current, block_t* n
267 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 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 204
       block[2] = block[1];
286 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 214
   if (!previous) return;
296 215
   UNUSED(next);
297 216
 
@@ -312,26 +231,28 @@ void planner_forward_pass_kernel(block_t* previous, block_t* current, block_t* n
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 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 242
     block[0] = block[1];
323 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 256
   int8_t block_index = block_buffer_tail;
336 257
   block_t* current;
337 258
   block_t* next = NULL;
@@ -358,54 +279,52 @@ void planner_recalculate_trapezoids() {
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 313
 #if ENABLED(AUTOTEMP)
393
-  void getHighESpeed() {
314
+
315
+  void Planner::getHighESpeed() {
394 316
     static float oldt = 0;
395 317
 
396 318
     if (!autotemp_enabled) return;
397 319
     if (degTargetHotend0() + 2 < autotemp_min) return; // probably temperature set to zero.
398 320
 
399 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 324
       if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS]) {
405 325
         float se = (float)block->steps[E_AXIS] / block->step_event_count * block->nominal_speed; // mm/sec;
406 326
         NOLESS(high, se);
407 327
       }
408
-      block_index = next_block_index(block_index);
409 328
     }
410 329
 
411 330
     float t = autotemp_min + high * autotemp_factor;
@@ -417,9 +336,13 @@ void plan_init() {
417 336
     oldt = t;
418 337
     setTargetHotend0(t);
419 338
   }
339
+
420 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 346
   unsigned char axis_active[NUM_AXIS] = { 0 },
424 347
                 tail_fan_speed[FAN_COUNT];
425 348
 
@@ -432,26 +355,23 @@ void check_axes_activity() {
432 355
                   tail_e_to_p_pressure = baricuda_e_to_p_pressure;
433 356
   #endif
434 357
 
435
-  block_t* block;
436
-
437 358
   if (blocks_queued()) {
438 359
 
439
-    uint8_t block_index = block_buffer_tail;
440
-
441 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 362
     #endif
444 363
 
364
+    block_t* block;
365
+
445 366
     #if ENABLED(BARICUDA)
446
-      block = &block_buffer[block_index];
367
+      block = &block_buffer[block_buffer_tail];
447 368
       tail_valve_pressure = block->valve_pressure;
448 369
       tail_e_to_p_pressure = block->e_to_p_pressure;
449 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 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 377
   #if ENABLED(DISABLE_X)
@@ -549,15 +469,20 @@ void check_axes_activity() {
549 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 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 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 486
 #endif  // AUTO_BED_LEVELING_FEATURE
562 487
 {
563 488
   // Calculate the buffer head after we push this byte
@@ -570,7 +495,7 @@ float junction_deviation = 0.1;
570 495
   #if ENABLED(MESH_BED_LEVELING)
571 496
     if (mbl.active) z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
572 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 499
   #endif
575 500
 
576 501
   // The target position of the tool in absolute steps
@@ -703,7 +628,8 @@ float junction_deviation = 0.1;
703 628
 
704 629
   // Enable extruder(s)
705 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 634
       for (int i = 0; i < EXTRUDERS; i++)
709 635
         if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
@@ -762,19 +688,18 @@ float junction_deviation = 0.1;
762 688
           #endif // EXTRUDERS > 2
763 689
         #endif // EXTRUDERS > 1
764 690
       }
765
-    }
766
-    else { // enable all
691
+    #else
767 692
       enable_e0();
768 693
       enable_e1();
769 694
       enable_e2();
770 695
       enable_e3();
771
-    }
696
+    #endif
772 697
   }
773 698
 
774 699
   if (block->steps[E_AXIS])
775
-    NOLESS(feed_rate, minimumfeedrate);
700
+    NOLESS(feed_rate, min_feedrate);
776 701
   else
777
-    NOLESS(feed_rate, mintravelfeedrate);
702
+    NOLESS(feed_rate, min_travel_feedrate);
778 703
 
779 704
   /**
780 705
    * This part of the code calculates the total length of the movement.
@@ -837,9 +762,9 @@ float junction_deviation = 0.1;
837 762
       //  segment time im micro seconds
838 763
       unsigned long segment_time = lround(1000000.0/inverse_second);
839 764
       if (mq) {
840
-        if (segment_time < minsegmenttime) {
765
+        if (segment_time < min_segment_time) {
841 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 768
           #ifdef XY_FREQUENCY_LIMIT
844 769
             segment_time = lround(1000000.0 / inverse_second);
845 770
           #endif
@@ -968,6 +893,9 @@ float junction_deviation = 0.1;
968 893
   block->acceleration_rate = (long)(acc_st * 16777216.0 / (F_CPU / 8.0));
969 894
 
970 895
   #if 0  // Use old jerk for now
896
+
897
+    float junction_deviation = 0.1;
898
+
971 899
     // Compute path unit vector
972 900
     double unit_vec[3];
973 901
 
@@ -1083,11 +1011,11 @@ float junction_deviation = 0.1;
1083 1011
   // Update position
1084 1012
   for (int i = 0; i < NUM_AXIS; i++) position[i] = target[i];
1085 1013
 
1086
-  planner_recalculate();
1014
+  recalculate();
1087 1015
 
1088 1016
   stepper.wake_up();
1089 1017
 
1090
-} // plan_buffer_line()
1018
+} // buffer_line()
1091 1019
 
1092 1020
 #if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA)
1093 1021
 
@@ -1096,13 +1024,15 @@ float junction_deviation = 0.1;
1096 1024
    *
1097 1025
    * On CORE machines XYZ is derived from ABC.
1098 1026
    */
1099
-  vector_3 plan_get_position() {
1027
+  vector_3 Planner::adjusted_position() {
1100 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 1036
     position.apply_rotation(inverse);
1107 1037
     //position.debug("after rotation");
1108 1038
 
@@ -1117,15 +1047,15 @@ float junction_deviation = 0.1;
1117 1047
  * On CORE machines stepper ABC will be translated from the given XYZ.
1118 1048
  */
1119 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 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 1053
 #endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
1124 1054
   {
1125 1055
     #if ENABLED(MESH_BED_LEVELING)
1126 1056
       if (mbl.active) z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
1127 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 1059
     #endif
1130 1060
 
1131 1061
     long nx = position[X_AXIS] = lround(x * axis_steps_per_unit[X_AXIS]),
@@ -1138,13 +1068,27 @@ float junction_deviation = 0.1;
1138 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 1075
   position[E_AXIS] = lround(e * axis_steps_per_unit[E_AXIS]);
1143 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 1081
   for (int i = 0; i < NUM_AXIS; i++)
1149 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 Parādīt failu

@@ -48,17 +48,36 @@
48 48
 
49 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 67
 typedef struct {
68
+
69
+  unsigned char active_extruder;            // The extruder to move (if E move)
70
+
54 71
   // Fields used by the bresenham algorithm for tracing the line
55 72
   long steps[NUM_AXIS];                     // Step count along each axis
56 73
   unsigned long step_event_count;           // The number of step events required to complete this block
74
+
57 75
   long accelerate_until;                    // The index of the step event on which to stop acceleration
58 76
   long decelerate_after;                    // The index of the step event on which to start decelerating
59 77
   long acceleration_rate;                   // The acceleration rate used for acceleration calculation
78
+
60 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 81
   #if ENABLED(ADVANCE)
63 82
     long advance_rate;
64 83
     volatile long initial_advance;
@@ -67,7 +86,6 @@ typedef struct {
67 86
   #endif
68 87
 
69 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 89
   float nominal_speed;                               // The nominal speed for this block in mm/sec
72 90
   float entry_speed;                                 // Entry speed at previous-current junction in mm/sec
73 91
   float max_entry_speed;                             // Maximum allowable junction entry speed in mm/sec
@@ -97,102 +115,220 @@ typedef struct {
97 115
 
98 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 334
 #endif // PLANNER_H

+ 6
- 6
Marlin/stepper.cpp Parādīt failu

@@ -242,7 +242,7 @@ ISR(TIMER1_COMPA_vect) { stepper.isr(); }
242 242
 void Stepper::isr() {
243 243
   if (cleaning_buffer_counter) {
244 244
     current_block = NULL;
245
-    plan_discard_current_block();
245
+    planner.discard_current_block();
246 246
     #ifdef SD_FINISHED_RELEASECOMMAND
247 247
       if ((cleaning_buffer_counter == 1) && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
248 248
     #endif
@@ -254,7 +254,7 @@ void Stepper::isr() {
254 254
   // If there is no current block, attempt to pop one from the buffer
255 255
   if (!current_block) {
256 256
     // Anything in the buffer?
257
-    current_block = plan_get_current_block();
257
+    current_block = planner.get_current_block();
258 258
     if (current_block) {
259 259
       current_block->busy = true;
260 260
       trapezoid_generator_reset();
@@ -396,7 +396,7 @@ void Stepper::isr() {
396 396
     // If current block is finished, reset pointer
397 397
     if (step_events_completed >= current_block->step_event_count) {
398 398
       current_block = NULL;
399
-      plan_discard_current_block();
399
+      planner.discard_current_block();
400 400
     }
401 401
   }
402 402
 }
@@ -620,7 +620,7 @@ void Stepper::init() {
620 620
 /**
621 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 626
  * Set the stepper positions directly in steps
@@ -693,7 +693,7 @@ float Stepper::get_axis_position_mm(AxisEnum axis) {
693 693
   #else
694 694
     axis_steps = position(axis);
695 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 699
 void Stepper::finish_and_disable() {
@@ -704,7 +704,7 @@ void Stepper::finish_and_disable() {
704 704
 void Stepper::quick_stop() {
705 705
   cleaning_buffer_counter = 5000;
706 706
   DISABLE_STEPPER_DRIVER_INTERRUPT();
707
-  while (blocks_queued()) plan_discard_current_block();
707
+  while (planner.blocks_queued()) planner.discard_current_block();
708 708
   current_block = NULL;
709 709
   ENABLE_STEPPER_DRIVER_INTERRUPT();
710 710
 }

+ 1
- 1
Marlin/stepper.h Parādīt failu

@@ -245,7 +245,7 @@ class Stepper {
245 245
     // Triggered position of an axis in mm (not core-savvy)
246 246
     //
247 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 251
     FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {

+ 1
- 1
Marlin/temperature.cpp Parādīt failu

@@ -613,7 +613,7 @@ float get_pid_output(int e) {
613 613
               lpq[lpq_ptr++] = 0;
614 614
             }
615 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 617
             pid_output += cTerm[e];
618 618
           }
619 619
         #endif //PID_ADD_EXTRUSION_RATE

+ 7
- 3
Marlin/temperature.h Parādīt failu

@@ -79,6 +79,10 @@ extern float current_temperature_bed;
79 79
   extern unsigned char soft_pwm_bed;
80 80
 #endif
81 81
 
82
+#if ENABLED(FAN_SOFT_PWM)
83
+  extern unsigned char fanSpeedSoftPwm[FAN_COUNT];
84
+#endif
85
+
82 86
 #if ENABLED(PIDTEMP)
83 87
 
84 88
   #if ENABLED(PID_PARAMS_PER_EXTRUDER)
@@ -178,9 +182,9 @@ void checkExtruderAutoFans();
178 182
 
179 183
 FORCE_INLINE void autotempShutdown() {
180 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 188
         setTargetHotend(0, active_extruder);
185 189
     }
186 190
   #endif

+ 35
- 33
Marlin/ultralcd.cpp Parādīt failu

@@ -463,9 +463,9 @@ static void lcd_status_screen() {
463 463
 inline void line_to_current(AxisEnum axis) {
464 464
   #if ENABLED(DELTA)
465 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 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 469
   #endif
470 470
 }
471 471
 
@@ -495,7 +495,7 @@ inline void line_to_current(AxisEnum axis) {
495 495
 static void lcd_main_menu() {
496 496
   START_MENU();
497 497
   MENU_ITEM(back, MSG_WATCH);
498
-  if (movesplanned() || IS_SD_PRINTING) {
498
+  if (planner.movesplanned() || IS_SD_PRINTING) {
499 499
     MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
500 500
   }
501 501
   else {
@@ -934,7 +934,7 @@ void lcd_cooldown() {
934 934
     ENCODER_DIRECTION_NORMAL();
935 935
 
936 936
     // Encoder wheel adjusts the Z position
937
-    if (encoderPosition && movesplanned() <= 3) {
937
+    if (encoderPosition && planner.movesplanned() <= 3) {
938 938
       refresh_cmd_timeout();
939 939
       current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
940 940
       NOLESS(current_position[Z_AXIS], 0);
@@ -1037,7 +1037,7 @@ void lcd_cooldown() {
1037 1037
     if (LCD_CLICKED) {
1038 1038
       _lcd_level_bed_position = 0;
1039 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 1041
       lcd_goto_menu(_lcd_level_goto_next_point, true);
1042 1042
     }
1043 1043
   }
@@ -1191,7 +1191,7 @@ float move_menu_scale;
1191 1191
 
1192 1192
 static void _lcd_move(const char* name, AxisEnum axis, float min, float max) {
1193 1193
   ENCODER_DIRECTION_NORMAL();
1194
-  if (encoderPosition && movesplanned() <= 3) {
1194
+  if (encoderPosition && planner.movesplanned() <= 3) {
1195 1195
     refresh_cmd_timeout();
1196 1196
     current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
1197 1197
     if (min_software_endstops) NOLESS(current_position[axis], min);
@@ -1223,7 +1223,7 @@ static void lcd_move_e(
1223 1223
     unsigned short original_active_extruder = active_extruder;
1224 1224
     active_extruder = e;
1225 1225
   #endif
1226
-  if (encoderPosition && movesplanned() <= 3) {
1226
+  if (encoderPosition && planner.movesplanned() <= 3) {
1227 1227
     current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
1228 1228
     line_to_current(E_AXIS);
1229 1229
     lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
@@ -1511,10 +1511,10 @@ static void lcd_control_temperature_menu() {
1511 1511
   // Autotemp, Min, Max, Fact
1512 1512
   //
1513 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 1518
   #endif
1519 1519
 
1520 1520
   //
@@ -1618,6 +1618,8 @@ static void lcd_control_temperature_preheat_abs_settings_menu() {
1618 1618
   END_MENU();
1619 1619
 }
1620 1620
 
1621
+static void _reset_acceleration_rates() { planner.reset_acceleration_rates(); }
1622
+
1621 1623
 /**
1622 1624
  *
1623 1625
  * "Control" > "Motion" submenu
@@ -1633,34 +1635,34 @@ static void lcd_control_motion_menu() {
1633 1635
   #if ENABLED(MANUAL_BED_LEVELING)
1634 1636
     MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
1635 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 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 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 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 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 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 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 1666
   #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
1665 1667
     MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &abort_on_endstop_hit);
1666 1668
   #endif

Notiek ielāde…
Atcelt
Saglabāt