Преглед на файлове

UltraLCD enhancements (lower fan resolution, backlash menu) (#13519)

Marcio Teixeira преди 6 години
родител
ревизия
5679fae11e

+ 1
- 0
Marlin/src/Marlin.cpp Целия файл

@@ -30,6 +30,7 @@
30 30
 
31 31
 #include "Marlin.h"
32 32
 
33
+#include "core/utility.h"
33 34
 #include "lcd/ultralcd.h"
34 35
 #include "module/motion.h"
35 36
 #include "module/planner.h"

+ 10
- 0
Marlin/src/core/utility.cpp Целия файл

@@ -57,6 +57,16 @@ void safe_delay(millis_t ms) {
57 57
   #define RJDIGIT(n, f) ((n) >= (f) ? DIGIMOD(n, f) : ' ')
58 58
   #define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-'))
59 59
 
60
+  // Convert a full-range unsigned 8bit int to a percentage
61
+  char* ui8tostr_percent(const uint8_t i) {
62
+    const uint16_t percent = 100 * i / 255;
63
+    conv[3] = RJDIGIT(percent, 100);
64
+    conv[4] = RJDIGIT(percent, 10);
65
+    conv[5] = DIGIMOD(percent, 1);
66
+    conv[6] = '%';
67
+    return &conv[3];
68
+  }
69
+
60 70
   // Convert unsigned 8bit int to string 123 format
61 71
   char* ui8tostr3(const uint8_t i) {
62 72
     conv[4] = RJDIGIT(i, 100);

+ 8
- 0
Marlin/src/core/utility.h Целия файл

@@ -55,6 +55,9 @@ inline void serial_delay(const millis_t ms) {
55 55
 
56 56
 #if ANY(ULTRA_LCD, DEBUG_LEVELING_FEATURE, EXTENSIBLE_UI)
57 57
 
58
+  // Convert a full-range unsigned 8bit int to a percentage
59
+  char* ui8tostr_percent(const uint8_t i);
60
+
58 61
   // Convert uint8_t to string with 123 format
59 62
   char* ui8tostr3(const uint8_t x);
60 63
 
@@ -135,3 +138,8 @@ public:
135 138
 
136 139
 #define REMEMBER(N,X, ...) restorer<typeof(X)> restorer_##N(X, ##__VA_ARGS__)
137 140
 #define RESTORE(N) restorer_##N.restore()
141
+
142
+// Converts from an uint8_t in the range of 0-255 to an uint8_t
143
+// in the range 0-100 while avoiding rounding artifacts
144
+constexpr uint8_t ui8_to_percent(const uint8_t i) { return (int(i) * 100 + 127) / 255; }
145
+constexpr uint8_t all_on = 0xFF, all_off = 0x00;

+ 7
- 6
Marlin/src/gcode/calibrate/G425.cpp Целия файл

@@ -56,7 +56,8 @@
56 56
 #define HAS_Y_CENTER BOTH(CALIBRATION_MEASURE_FRONT, CALIBRATION_MEASURE_BACK)
57 57
 
58 58
 #if ENABLED(BACKLASH_GCODE)
59
-  extern float backlash_distance_mm[], backlash_correction, backlash_smoothing_mm;
59
+  extern float backlash_distance_mm[], backlash_smoothing_mm;
60
+  extern uint8_t backlash_correction;
60 61
 #endif
61 62
 
62 63
 enum side_t : uint8_t { TOP, RIGHT, FRONT, LEFT, BACK, NUM_SIDES };
@@ -446,7 +447,7 @@ inline void calibrate_backlash(measurements_t &m, const float uncertainty) {
446 447
 
447 448
   {
448 449
     // New scope for TEMPORARY_BACKLASH_CORRECTION
449
-    TEMPORARY_BACKLASH_CORRECTION(0.0f);
450
+    TEMPORARY_BACKLASH_CORRECTION(all_off);
450 451
     TEMPORARY_BACKLASH_SMOOTHING(0.0f);
451 452
 
452 453
     probe_sides(m, uncertainty);
@@ -478,7 +479,7 @@ inline void calibrate_backlash(measurements_t &m, const float uncertainty) {
478 479
 
479 480
     {
480 481
       // New scope for TEMPORARY_BACKLASH_CORRECTION
481
-      TEMPORARY_BACKLASH_CORRECTION(1.0f);
482
+      TEMPORARY_BACKLASH_CORRECTION(all_on);
482 483
       TEMPORARY_BACKLASH_SMOOTHING(0.0f);
483 484
       move_to(
484 485
         X_AXIS, current_position[X_AXIS] + 3,
@@ -513,7 +514,7 @@ inline void update_measurements(measurements_t &m, const AxisEnum axis) {
513 514
  *    - Call calibrate_backlash() beforehand for best accuracy
514 515
  */
515 516
 inline void calibrate_toolhead(measurements_t &m, const float uncertainty, const uint8_t extruder) {
516
-  TEMPORARY_BACKLASH_CORRECTION(1.0f);
517
+  TEMPORARY_BACKLASH_CORRECTION(all_on);
517 518
   TEMPORARY_BACKLASH_SMOOTHING(0.0f);
518 519
 
519 520
   #if HOTENDS > 1
@@ -556,7 +557,7 @@ inline void calibrate_toolhead(measurements_t &m, const float uncertainty, const
556 557
  *   uncertainty    in     - How far away from the object to begin probing
557 558
  */
558 559
 inline void calibrate_all_toolheads(measurements_t &m, const float uncertainty) {
559
-  TEMPORARY_BACKLASH_CORRECTION(1.0f);
560
+  TEMPORARY_BACKLASH_CORRECTION(all_on);
560 561
   TEMPORARY_BACKLASH_SMOOTHING(0.0f);
561 562
 
562 563
   HOTEND_LOOP() calibrate_toolhead(m, uncertainty, e);
@@ -588,7 +589,7 @@ inline void calibrate_all() {
588 589
     reset_hotend_offsets();
589 590
   #endif
590 591
 
591
-  TEMPORARY_BACKLASH_CORRECTION(1.0f);
592
+  TEMPORARY_BACKLASH_CORRECTION(all_on);
592 593
   TEMPORARY_BACKLASH_SMOOTHING(0.0f);
593 594
 
594 595
   // Do a fast and rough calibration of the toolheads

+ 4
- 5
Marlin/src/gcode/calibrate/M425.cpp Целия файл

@@ -26,8 +26,8 @@
26 26
 
27 27
 #include "../../module/planner.h"
28 28
 
29
-float backlash_distance_mm[XYZ] = BACKLASH_DISTANCE_MM,
30
-      backlash_correction = BACKLASH_CORRECTION;
29
+float   backlash_distance_mm[XYZ] = BACKLASH_DISTANCE_MM;
30
+uint8_t backlash_correction = BACKLASH_CORRECTION * all_on;
31 31
 
32 32
 #ifdef BACKLASH_SMOOTHING_MM
33 33
   float backlash_smoothing_mm = BACKLASH_SMOOTHING_MM;
@@ -74,7 +74,7 @@ void GcodeSuite::M425() {
74 74
 
75 75
   if (parser.seen('F')) {
76 76
     planner.synchronize();
77
-    backlash_correction = MAX(0, MIN(1.0, parser.value_linear_units()));
77
+    backlash_correction = MAX(0, MIN(1.0, parser.value_float())) * all_on;
78 78
     noArgs = false;
79 79
   }
80 80
 
@@ -90,8 +90,7 @@ void GcodeSuite::M425() {
90 90
     SERIAL_ECHOPGM("Backlash correction is ");
91 91
     if (!backlash_correction) SERIAL_ECHOPGM("in");
92 92
     SERIAL_ECHOLNPGM("active:");
93
-    SERIAL_ECHOPAIR("  Correction Amount/Fade-out:     F", backlash_correction);
94
-    SERIAL_ECHOLNPGM("     (F1.0 = full, F0.0 = none)");
93
+    SERIAL_ECHOLNPAIR("  Correction Amount/Fade-out:     F", float(ui8_to_percent(backlash_correction)) / 100, "     (F1.0 = full, F0.0 = none)");
95 94
     SERIAL_ECHOPGM("  Backlash Distance (mm):        ");
96 95
     LOOP_XYZ(a) {
97 96
       SERIAL_CHAR(' ');

+ 4
- 3
Marlin/src/lcd/extensible_ui/ui_api.cpp Целия файл

@@ -82,7 +82,8 @@
82 82
 #include "ui_api.h"
83 83
 
84 84
 #if ENABLED(BACKLASH_GCODE)
85
-  extern float backlash_distance_mm[XYZ], backlash_correction;
85
+  extern float backlash_distance_mm[XYZ];
86
+  extern uint8_t backlash_correction;
86 87
   #ifdef BACKLASH_SMOOTHING_MM
87 88
     extern float backlash_smoothing_mm;
88 89
   #endif
@@ -686,8 +687,8 @@ namespace ExtUI {
686 687
     void setAxisBacklash_mm(const float value, const axis_t axis)
687 688
                                                       { backlash_distance_mm[axis] = clamp(value,0,5); }
688 689
 
689
-    float getBacklashCorrection_percent()             { return backlash_correction * 100; }
690
-    void setBacklashCorrection_percent(const float value) { backlash_correction = clamp(value, 0, 100) / 100.0f; }
690
+    float getBacklashCorrection_percent()             { return ui8_to_percent(backlash_correction); }
691
+    void setBacklashCorrection_percent(const float value) { backlash_correction = map(clamp(value, 0, 100), 0, 100, 0, 255); }
691 692
 
692 693
     #ifdef BACKLASH_SMOOTHING_MM
693 694
       float getBacklashSmoothing_mm()                 { return backlash_smoothing_mm; }

+ 10
- 0
Marlin/src/lcd/language/language_en.h Целия файл

@@ -1386,3 +1386,13 @@
1386 1386
 #ifndef MSG_SERVICE_IN
1387 1387
   #define MSG_SERVICE_IN                      _UxGT(" in:")
1388 1388
 #endif
1389
+
1390
+#ifndef MSG_BACKLASH
1391
+  #define MSG_BACKLASH                        _UxGT("Backlash")
1392
+#endif
1393
+#ifndef MSG_BACKLASH_CORRECTION
1394
+  #define MSG_BACKLASH_CORRECTION             _UxGT("Correction")
1395
+#endif
1396
+#ifndef MSG_BACKLASH_SMOOTHING
1397
+  #define MSG_BACKLASH_SMOOTHING              _UxGT("Smoothing")
1398
+#endif

+ 3
- 0
Marlin/src/lcd/menu/menu.h Целия файл

@@ -43,6 +43,7 @@ bool printer_busy();
43 43
     static inline char* strfunc(const float value) { return STRFUNC((TYPE) value); } \
44 44
   };
45 45
 
46
+DECLARE_MENU_EDIT_TYPE(uint8_t,  percent,     ui8tostr_percent,1     );   // 100%       right-justified
46 47
 DECLARE_MENU_EDIT_TYPE(int16_t,  int3,        i16tostr3,       1     );   // 123, -12   right-justified
47 48
 DECLARE_MENU_EDIT_TYPE(int16_t,  int4,        i16tostr4sign,   1     );   // 1234, -123 right-justified
48 49
 DECLARE_MENU_EDIT_TYPE(int8_t,   int8,        i8tostr3,        1     );   // 123, -12   right-justified
@@ -102,6 +103,7 @@ FORCE_INLINE void draw_menu_item_edit_P(const bool sel, const uint8_t row, PGM_P
102 103
   typedef void NAME##_void
103 104
 #define DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(NAME) _DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(MenuItemInfo_##NAME::type_t, NAME, MenuItemInfo_##NAME::strfunc)
104 105
 
106
+DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(percent);          // 100%       right-justified
105 107
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int3);             // 123, -12   right-justified
106 108
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int4);             // 1234, -123 right-justified
107 109
 DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int8);             // 123, -12   right-justified
@@ -174,6 +176,7 @@ class TMenuItem : MenuItemBase {
174 176
 
175 177
 #define DECLARE_MENU_EDIT_ITEM(NAME) typedef TMenuItem<MenuItemInfo_##NAME> MenuItem_##NAME;
176 178
 
179
+DECLARE_MENU_EDIT_ITEM(percent);
177 180
 DECLARE_MENU_EDIT_ITEM(int3);
178 181
 DECLARE_MENU_EDIT_ITEM(int4);
179 182
 DECLARE_MENU_EDIT_ITEM(int8);

+ 5
- 0
Marlin/src/lcd/menu/menu_advanced.cpp Целия файл

@@ -49,6 +49,7 @@
49 49
 #endif
50 50
 
51 51
 void menu_tmc();
52
+void menu_backlash();
52 53
 
53 54
 #if ENABLED(DAC_STEPPER_CURRENT)
54 55
 
@@ -647,6 +648,10 @@ void menu_advanced_settings() {
647 648
     }
648 649
   #endif // !SLIM_LCD_MENUS
649 650
 
651
+  #if ENABLED(BACKLASH_GCODE)
652
+    MENU_ITEM(submenu, MSG_BACKLASH, menu_backlash);
653
+  #endif
654
+
650 655
   #if ENABLED(DAC_STEPPER_CURRENT)
651 656
     MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, menu_dac);
652 657
   #endif

+ 58
- 0
Marlin/src/lcd/menu/menu_backlash.cpp Целия файл

@@ -0,0 +1,58 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+//
24
+// Backlash Menu
25
+//
26
+
27
+#include "../../inc/MarlinConfigPre.h"
28
+
29
+#if HAS_LCD_MENU && ENABLED(BACKLASH_GCODE)
30
+
31
+#include "menu.h"
32
+
33
+extern float backlash_distance_mm[XYZ];
34
+extern uint8_t backlash_correction;
35
+
36
+#ifdef BACKLASH_SMOOTHING_MM
37
+  extern float backlash_smoothing_mm;
38
+#endif
39
+
40
+void menu_backlash() {
41
+  START_MENU();
42
+  MENU_BACK(MSG_MAIN);
43
+
44
+  MENU_MULTIPLIER_ITEM_EDIT(percent, MSG_BACKLASH_CORRECTION, &backlash_correction, all_off, all_on);
45
+
46
+  #define EDIT_BACKLASH_DISTANCE(N) MENU_MULTIPLIER_ITEM_EDIT(float43, MSG_##N, &backlash_distance_mm[_AXIS(N)], 0.0f, 9.9f);
47
+  EDIT_BACKLASH_DISTANCE(A);
48
+  EDIT_BACKLASH_DISTANCE(B);
49
+  EDIT_BACKLASH_DISTANCE(C);
50
+
51
+  #ifdef BACKLASH_SMOOTHING_MM
52
+    MENU_MULTIPLIER_ITEM_EDIT(float43, MSG_BACKLASH_SMOOTHING, &backlash_smoothing_mm, 0.0f, 9.9f);
53
+  #endif
54
+
55
+  END_MENU();
56
+}
57
+
58
+#endif // HAS_LCD_MENU && BACKLASH_COMPENSATION

+ 6
- 6
Marlin/src/lcd/menu/menu_temperature.cpp Целия файл

@@ -395,21 +395,21 @@ void menu_temperature() {
395 395
   //
396 396
   #if FAN_COUNT > 0
397 397
     #if HAS_FAN0
398
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(uint8, MSG_FAN_SPEED FAN_SPEED_1_SUFFIX, &thermalManager.lcd_tmpfan_speed[0], 0, 255, thermalManager.lcd_setFanSpeed0);
398
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(percent, MSG_FAN_SPEED FAN_SPEED_1_SUFFIX, &thermalManager.lcd_tmpfan_speed[0], 0, 255, thermalManager.lcd_setFanSpeed0);
399 399
       #if ENABLED(EXTRA_FAN_SPEED)
400
-        MENU_MULTIPLIER_ITEM_EDIT(uint8, MSG_EXTRA_FAN_SPEED FAN_SPEED_1_SUFFIX, &thermalManager.new_fan_speed[0], 3, 255);
400
+        MENU_MULTIPLIER_ITEM_EDIT(percent, MSG_EXTRA_FAN_SPEED FAN_SPEED_1_SUFFIX, &thermalManager.new_fan_speed[0], 3, 255);
401 401
       #endif
402 402
     #endif
403 403
     #if HAS_FAN1 || (ENABLED(SINGLENOZZLE) && EXTRUDERS > 1)
404
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(uint8, MSG_FAN_SPEED " 2", &thermalManager.lcd_tmpfan_speed[1], 0, 255, thermalManager.lcd_setFanSpeed1);
404
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(percent, MSG_FAN_SPEED " 2", &thermalManager.lcd_tmpfan_speed[1], 0, 255, thermalManager.lcd_setFanSpeed1);
405 405
       #if ENABLED(EXTRA_FAN_SPEED)
406
-        MENU_MULTIPLIER_ITEM_EDIT(uint8, MSG_EXTRA_FAN_SPEED " 2", &thermalManager.new_fan_speed[1], 3, 255);
406
+        MENU_MULTIPLIER_ITEM_EDIT(percent, MSG_EXTRA_FAN_SPEED " 2", &thermalManager.new_fan_speed[1], 3, 255);
407 407
       #endif
408 408
     #endif
409 409
     #if HAS_FAN2 || (ENABLED(SINGLENOZZLE) && EXTRUDERS > 2)
410
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(uint8, MSG_FAN_SPEED " 3", &thermalManager.lcd_tmpfan_speed[2], 0, 255, thermalManager.lcd_setFanSpeed2);
410
+      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(percent, MSG_FAN_SPEED " 3", &thermalManager.lcd_tmpfan_speed[2], 0, 255, thermalManager.lcd_setFanSpeed2);
411 411
       #if ENABLED(EXTRA_FAN_SPEED)
412
-        MENU_MULTIPLIER_ITEM_EDIT(uint8, MSG_EXTRA_FAN_SPEED " 3", &thermalManager.new_fan_speed[2], 3, 255);
412
+        MENU_MULTIPLIER_ITEM_EDIT(percent, MSG_EXTRA_FAN_SPEED " 3", &thermalManager.new_fan_speed[2], 3, 255);
413 413
       #endif
414 414
     #endif
415 415
   #endif // FAN_COUNT > 0

+ 6
- 3
Marlin/src/module/planner.cpp Целия файл

@@ -1572,13 +1572,14 @@ void Planner::synchronize() {
1572 1572
  */
1573 1573
 #if ENABLED(BACKLASH_COMPENSATION)
1574 1574
   #if ENABLED(BACKLASH_GCODE)
1575
-    extern float backlash_distance_mm[], backlash_correction;
1575
+    extern float backlash_distance_mm[];
1576
+    extern uint8_t backlash_correction;
1576 1577
     #ifdef BACKLASH_SMOOTHING_MM
1577 1578
       extern float backlash_smoothing_mm;
1578 1579
     #endif
1579 1580
   #else
1580 1581
     constexpr float backlash_distance_mm[XYZ] = BACKLASH_DISTANCE_MM,
1581
-                    backlash_correction = BACKLASH_CORRECTION;
1582
+    constexpr uint8_t backlash_correction = BACKLASH_CORRECTION * 255;
1582 1583
     #ifdef BACKLASH_SMOOTHING_MM
1583 1584
       constexpr float backlash_smoothing_mm = BACKLASH_SMOOTHING_MM;
1584 1585
     #endif
@@ -1612,13 +1613,15 @@ void Planner::synchronize() {
1612 1613
       if (!changed_dir) return;
1613 1614
     #endif
1614 1615
 
1616
+    const float f_corr = float(backlash_correction) / 255.0f;
1617
+
1615 1618
     LOOP_XYZ(axis) {
1616 1619
       if (backlash_distance_mm[axis]) {
1617 1620
         const bool reversing = TEST(dm,axis);
1618 1621
 
1619 1622
         // When an axis changes direction, add axis backlash to the residual error
1620 1623
         if (TEST(changed_dir, axis))
1621
-          residual_error[axis] += backlash_correction * (reversing ? -1.0f : 1.0f) * backlash_distance_mm[axis] * planner.settings.axis_steps_per_mm[axis];
1624
+          residual_error[axis] += (reversing ? -f_corr : f_corr) * backlash_distance_mm[axis] * planner.settings.axis_steps_per_mm[axis];
1622 1625
 
1623 1626
         // Decide how much of the residual error to correct in this segment
1624 1627
         int32_t error_correction = residual_error[axis];

+ 1
- 1
Marlin/src/module/temperature.h Целия файл

@@ -420,7 +420,7 @@ class Temperature {
420 420
         static uint8_t paused_fan_speed[FAN_COUNT];
421 421
       #endif
422 422
 
423
-      static constexpr inline uint8_t fanPercent(const uint8_t speed) { return (int(speed) * 100 + 127) / 255; }
423
+      static constexpr inline uint8_t fanPercent(const uint8_t speed) { return ui8_to_percent(speed); }
424 424
 
425 425
       #if ENABLED(ADAPTIVE_FAN_SLOWING)
426 426
         static uint8_t fan_speed_scaler[FAN_COUNT];

Loading…
Отказ
Запис