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

This commit is contained in:
Marcio Teixeira 2019-03-29 13:07:43 -06:00 committed by Scott Lahteine
parent de0f35f2d9
commit 5679fae11e
13 changed files with 123 additions and 24 deletions

View file

@ -30,6 +30,7 @@
#include "Marlin.h" #include "Marlin.h"
#include "core/utility.h"
#include "lcd/ultralcd.h" #include "lcd/ultralcd.h"
#include "module/motion.h" #include "module/motion.h"
#include "module/planner.h" #include "module/planner.h"

View file

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

View file

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

View file

@ -56,7 +56,8 @@
#define HAS_Y_CENTER BOTH(CALIBRATION_MEASURE_FRONT, CALIBRATION_MEASURE_BACK) #define HAS_Y_CENTER BOTH(CALIBRATION_MEASURE_FRONT, CALIBRATION_MEASURE_BACK)
#if ENABLED(BACKLASH_GCODE) #if ENABLED(BACKLASH_GCODE)
extern float backlash_distance_mm[], backlash_correction, backlash_smoothing_mm; extern float backlash_distance_mm[], backlash_smoothing_mm;
extern uint8_t backlash_correction;
#endif #endif
enum side_t : uint8_t { TOP, RIGHT, FRONT, LEFT, BACK, NUM_SIDES }; 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) {
{ {
// New scope for TEMPORARY_BACKLASH_CORRECTION // New scope for TEMPORARY_BACKLASH_CORRECTION
TEMPORARY_BACKLASH_CORRECTION(0.0f); TEMPORARY_BACKLASH_CORRECTION(all_off);
TEMPORARY_BACKLASH_SMOOTHING(0.0f); TEMPORARY_BACKLASH_SMOOTHING(0.0f);
probe_sides(m, uncertainty); probe_sides(m, uncertainty);
@ -478,7 +479,7 @@ inline void calibrate_backlash(measurements_t &m, const float uncertainty) {
{ {
// New scope for TEMPORARY_BACKLASH_CORRECTION // New scope for TEMPORARY_BACKLASH_CORRECTION
TEMPORARY_BACKLASH_CORRECTION(1.0f); TEMPORARY_BACKLASH_CORRECTION(all_on);
TEMPORARY_BACKLASH_SMOOTHING(0.0f); TEMPORARY_BACKLASH_SMOOTHING(0.0f);
move_to( move_to(
X_AXIS, current_position[X_AXIS] + 3, X_AXIS, current_position[X_AXIS] + 3,
@ -513,7 +514,7 @@ inline void update_measurements(measurements_t &m, const AxisEnum axis) {
* - Call calibrate_backlash() beforehand for best accuracy * - Call calibrate_backlash() beforehand for best accuracy
*/ */
inline void calibrate_toolhead(measurements_t &m, const float uncertainty, const uint8_t extruder) { inline void calibrate_toolhead(measurements_t &m, const float uncertainty, const uint8_t extruder) {
TEMPORARY_BACKLASH_CORRECTION(1.0f); TEMPORARY_BACKLASH_CORRECTION(all_on);
TEMPORARY_BACKLASH_SMOOTHING(0.0f); TEMPORARY_BACKLASH_SMOOTHING(0.0f);
#if HOTENDS > 1 #if HOTENDS > 1
@ -556,7 +557,7 @@ inline void calibrate_toolhead(measurements_t &m, const float uncertainty, const
* uncertainty in - How far away from the object to begin probing * uncertainty in - How far away from the object to begin probing
*/ */
inline void calibrate_all_toolheads(measurements_t &m, const float uncertainty) { inline void calibrate_all_toolheads(measurements_t &m, const float uncertainty) {
TEMPORARY_BACKLASH_CORRECTION(1.0f); TEMPORARY_BACKLASH_CORRECTION(all_on);
TEMPORARY_BACKLASH_SMOOTHING(0.0f); TEMPORARY_BACKLASH_SMOOTHING(0.0f);
HOTEND_LOOP() calibrate_toolhead(m, uncertainty, e); HOTEND_LOOP() calibrate_toolhead(m, uncertainty, e);
@ -588,7 +589,7 @@ inline void calibrate_all() {
reset_hotend_offsets(); reset_hotend_offsets();
#endif #endif
TEMPORARY_BACKLASH_CORRECTION(1.0f); TEMPORARY_BACKLASH_CORRECTION(all_on);
TEMPORARY_BACKLASH_SMOOTHING(0.0f); TEMPORARY_BACKLASH_SMOOTHING(0.0f);
// Do a fast and rough calibration of the toolheads // Do a fast and rough calibration of the toolheads

View file

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

View file

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

View file

@ -1386,3 +1386,13 @@
#ifndef MSG_SERVICE_IN #ifndef MSG_SERVICE_IN
#define MSG_SERVICE_IN _UxGT(" in:") #define MSG_SERVICE_IN _UxGT(" in:")
#endif #endif
#ifndef MSG_BACKLASH
#define MSG_BACKLASH _UxGT("Backlash")
#endif
#ifndef MSG_BACKLASH_CORRECTION
#define MSG_BACKLASH_CORRECTION _UxGT("Correction")
#endif
#ifndef MSG_BACKLASH_SMOOTHING
#define MSG_BACKLASH_SMOOTHING _UxGT("Smoothing")
#endif

View file

@ -43,6 +43,7 @@ bool printer_busy();
static inline char* strfunc(const float value) { return STRFUNC((TYPE) value); } \ static inline char* strfunc(const float value) { return STRFUNC((TYPE) value); } \
}; };
DECLARE_MENU_EDIT_TYPE(uint8_t, percent, ui8tostr_percent,1 ); // 100% right-justified
DECLARE_MENU_EDIT_TYPE(int16_t, int3, i16tostr3, 1 ); // 123, -12 right-justified DECLARE_MENU_EDIT_TYPE(int16_t, int3, i16tostr3, 1 ); // 123, -12 right-justified
DECLARE_MENU_EDIT_TYPE(int16_t, int4, i16tostr4sign, 1 ); // 1234, -123 right-justified DECLARE_MENU_EDIT_TYPE(int16_t, int4, i16tostr4sign, 1 ); // 1234, -123 right-justified
DECLARE_MENU_EDIT_TYPE(int8_t, int8, i8tostr3, 1 ); // 123, -12 right-justified 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
typedef void NAME##_void typedef void NAME##_void
#define DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(NAME) _DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(MenuItemInfo_##NAME::type_t, NAME, MenuItemInfo_##NAME::strfunc) #define DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(NAME) _DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(MenuItemInfo_##NAME::type_t, NAME, MenuItemInfo_##NAME::strfunc)
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(percent); // 100% right-justified
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int3); // 123, -12 right-justified DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int3); // 123, -12 right-justified
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int4); // 1234, -123 right-justified DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int4); // 1234, -123 right-justified
DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int8); // 123, -12 right-justified DEFINE_DRAW_MENU_ITEM_SETTING_EDIT(int8); // 123, -12 right-justified
@ -174,6 +176,7 @@ class TMenuItem : MenuItemBase {
#define DECLARE_MENU_EDIT_ITEM(NAME) typedef TMenuItem<MenuItemInfo_##NAME> MenuItem_##NAME; #define DECLARE_MENU_EDIT_ITEM(NAME) typedef TMenuItem<MenuItemInfo_##NAME> MenuItem_##NAME;
DECLARE_MENU_EDIT_ITEM(percent);
DECLARE_MENU_EDIT_ITEM(int3); DECLARE_MENU_EDIT_ITEM(int3);
DECLARE_MENU_EDIT_ITEM(int4); DECLARE_MENU_EDIT_ITEM(int4);
DECLARE_MENU_EDIT_ITEM(int8); DECLARE_MENU_EDIT_ITEM(int8);

View file

@ -49,6 +49,7 @@
#endif #endif
void menu_tmc(); void menu_tmc();
void menu_backlash();
#if ENABLED(DAC_STEPPER_CURRENT) #if ENABLED(DAC_STEPPER_CURRENT)
@ -647,6 +648,10 @@ void menu_advanced_settings() {
} }
#endif // !SLIM_LCD_MENUS #endif // !SLIM_LCD_MENUS
#if ENABLED(BACKLASH_GCODE)
MENU_ITEM(submenu, MSG_BACKLASH, menu_backlash);
#endif
#if ENABLED(DAC_STEPPER_CURRENT) #if ENABLED(DAC_STEPPER_CURRENT)
MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, menu_dac); MENU_ITEM(submenu, MSG_DRIVE_STRENGTH, menu_dac);
#endif #endif

View file

@ -0,0 +1,58 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
//
// Backlash Menu
//
#include "../../inc/MarlinConfigPre.h"
#if HAS_LCD_MENU && ENABLED(BACKLASH_GCODE)
#include "menu.h"
extern float backlash_distance_mm[XYZ];
extern uint8_t backlash_correction;
#ifdef BACKLASH_SMOOTHING_MM
extern float backlash_smoothing_mm;
#endif
void menu_backlash() {
START_MENU();
MENU_BACK(MSG_MAIN);
MENU_MULTIPLIER_ITEM_EDIT(percent, MSG_BACKLASH_CORRECTION, &backlash_correction, all_off, all_on);
#define EDIT_BACKLASH_DISTANCE(N) MENU_MULTIPLIER_ITEM_EDIT(float43, MSG_##N, &backlash_distance_mm[_AXIS(N)], 0.0f, 9.9f);
EDIT_BACKLASH_DISTANCE(A);
EDIT_BACKLASH_DISTANCE(B);
EDIT_BACKLASH_DISTANCE(C);
#ifdef BACKLASH_SMOOTHING_MM
MENU_MULTIPLIER_ITEM_EDIT(float43, MSG_BACKLASH_SMOOTHING, &backlash_smoothing_mm, 0.0f, 9.9f);
#endif
END_MENU();
}
#endif // HAS_LCD_MENU && BACKLASH_COMPENSATION

View file

@ -395,21 +395,21 @@ void menu_temperature() {
// //
#if FAN_COUNT > 0 #if FAN_COUNT > 0
#if HAS_FAN0 #if HAS_FAN0
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(uint8, MSG_FAN_SPEED FAN_SPEED_1_SUFFIX, &thermalManager.lcd_tmpfan_speed[0], 0, 255, thermalManager.lcd_setFanSpeed0); MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(percent, MSG_FAN_SPEED FAN_SPEED_1_SUFFIX, &thermalManager.lcd_tmpfan_speed[0], 0, 255, thermalManager.lcd_setFanSpeed0);
#if ENABLED(EXTRA_FAN_SPEED) #if ENABLED(EXTRA_FAN_SPEED)
MENU_MULTIPLIER_ITEM_EDIT(uint8, MSG_EXTRA_FAN_SPEED FAN_SPEED_1_SUFFIX, &thermalManager.new_fan_speed[0], 3, 255); MENU_MULTIPLIER_ITEM_EDIT(percent, MSG_EXTRA_FAN_SPEED FAN_SPEED_1_SUFFIX, &thermalManager.new_fan_speed[0], 3, 255);
#endif #endif
#endif #endif
#if HAS_FAN1 || (ENABLED(SINGLENOZZLE) && EXTRUDERS > 1) #if HAS_FAN1 || (ENABLED(SINGLENOZZLE) && EXTRUDERS > 1)
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(uint8, MSG_FAN_SPEED " 2", &thermalManager.lcd_tmpfan_speed[1], 0, 255, thermalManager.lcd_setFanSpeed1); MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(percent, MSG_FAN_SPEED " 2", &thermalManager.lcd_tmpfan_speed[1], 0, 255, thermalManager.lcd_setFanSpeed1);
#if ENABLED(EXTRA_FAN_SPEED) #if ENABLED(EXTRA_FAN_SPEED)
MENU_MULTIPLIER_ITEM_EDIT(uint8, MSG_EXTRA_FAN_SPEED " 2", &thermalManager.new_fan_speed[1], 3, 255); MENU_MULTIPLIER_ITEM_EDIT(percent, MSG_EXTRA_FAN_SPEED " 2", &thermalManager.new_fan_speed[1], 3, 255);
#endif #endif
#endif #endif
#if HAS_FAN2 || (ENABLED(SINGLENOZZLE) && EXTRUDERS > 2) #if HAS_FAN2 || (ENABLED(SINGLENOZZLE) && EXTRUDERS > 2)
MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(uint8, MSG_FAN_SPEED " 3", &thermalManager.lcd_tmpfan_speed[2], 0, 255, thermalManager.lcd_setFanSpeed2); MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(percent, MSG_FAN_SPEED " 3", &thermalManager.lcd_tmpfan_speed[2], 0, 255, thermalManager.lcd_setFanSpeed2);
#if ENABLED(EXTRA_FAN_SPEED) #if ENABLED(EXTRA_FAN_SPEED)
MENU_MULTIPLIER_ITEM_EDIT(uint8, MSG_EXTRA_FAN_SPEED " 3", &thermalManager.new_fan_speed[2], 3, 255); MENU_MULTIPLIER_ITEM_EDIT(percent, MSG_EXTRA_FAN_SPEED " 3", &thermalManager.new_fan_speed[2], 3, 255);
#endif #endif
#endif #endif
#endif // FAN_COUNT > 0 #endif // FAN_COUNT > 0

View file

@ -1572,13 +1572,14 @@ void Planner::synchronize() {
*/ */
#if ENABLED(BACKLASH_COMPENSATION) #if ENABLED(BACKLASH_COMPENSATION)
#if ENABLED(BACKLASH_GCODE) #if ENABLED(BACKLASH_GCODE)
extern float backlash_distance_mm[], backlash_correction; extern float backlash_distance_mm[];
extern uint8_t backlash_correction;
#ifdef BACKLASH_SMOOTHING_MM #ifdef BACKLASH_SMOOTHING_MM
extern float backlash_smoothing_mm; extern float backlash_smoothing_mm;
#endif #endif
#else #else
constexpr float backlash_distance_mm[XYZ] = BACKLASH_DISTANCE_MM, constexpr float backlash_distance_mm[XYZ] = BACKLASH_DISTANCE_MM,
backlash_correction = BACKLASH_CORRECTION; constexpr uint8_t backlash_correction = BACKLASH_CORRECTION * 255;
#ifdef BACKLASH_SMOOTHING_MM #ifdef BACKLASH_SMOOTHING_MM
constexpr float backlash_smoothing_mm = BACKLASH_SMOOTHING_MM; constexpr float backlash_smoothing_mm = BACKLASH_SMOOTHING_MM;
#endif #endif
@ -1612,13 +1613,15 @@ void Planner::synchronize() {
if (!changed_dir) return; if (!changed_dir) return;
#endif #endif
const float f_corr = float(backlash_correction) / 255.0f;
LOOP_XYZ(axis) { LOOP_XYZ(axis) {
if (backlash_distance_mm[axis]) { if (backlash_distance_mm[axis]) {
const bool reversing = TEST(dm,axis); const bool reversing = TEST(dm,axis);
// When an axis changes direction, add axis backlash to the residual error // When an axis changes direction, add axis backlash to the residual error
if (TEST(changed_dir, axis)) if (TEST(changed_dir, axis))
residual_error[axis] += backlash_correction * (reversing ? -1.0f : 1.0f) * backlash_distance_mm[axis] * planner.settings.axis_steps_per_mm[axis]; residual_error[axis] += (reversing ? -f_corr : f_corr) * backlash_distance_mm[axis] * planner.settings.axis_steps_per_mm[axis];
// Decide how much of the residual error to correct in this segment // Decide how much of the residual error to correct in this segment
int32_t error_correction = residual_error[axis]; int32_t error_correction = residual_error[axis];

View file

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