From 20b3af1cc2c4a5e8505d1aae3419ab9418ed88ab Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 16 Dec 2020 22:18:40 -0600 Subject: [PATCH] Use homing_feedrate function --- Marlin/src/core/types.h | 1 - Marlin/src/feature/encoder_i2c.cpp | 4 ++-- Marlin/src/feature/powerloss.cpp | 2 +- Marlin/src/gcode/calibrate/G34.cpp | 2 +- Marlin/src/gcode/feature/pause/G61.cpp | 11 +++++++---- Marlin/src/lcd/dwin/e3v2/dwin.cpp | 6 +++--- .../src/lcd/extui/lib/mks_ui/draw_filament_change.cpp | 2 -- Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp | 2 -- Marlin/src/lcd/menu/menu_probe_offset.cpp | 2 +- Marlin/src/module/motion.cpp | 2 +- Marlin/src/module/motion.h | 6 +++++- Marlin/src/module/planner.h | 2 +- Marlin/src/module/probe.cpp | 11 +++-------- 13 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h index a5b78caabb..20519e1888 100644 --- a/Marlin/src/core/types.h +++ b/Marlin/src/core/types.h @@ -75,7 +75,6 @@ typedef float feedRate_t; // Conversion macros #define MMM_TO_MMS(MM_M) feedRate_t(float(MM_M) / 60.0f) #define MMS_TO_MMM(MM_S) (float(MM_S) * 60.0f) -#define MMS_SCALED(V) ((V) * 0.01f * feedrate_percentage) // // Coordinates structures for XY, XYZ, XYZE... diff --git a/Marlin/src/feature/encoder_i2c.cpp b/Marlin/src/feature/encoder_i2c.cpp index 8a3e959e07..028e3abe54 100644 --- a/Marlin/src/feature/encoder_i2c.cpp +++ b/Marlin/src/feature/encoder_i2c.cpp @@ -332,7 +332,7 @@ bool I2CPositionEncoder::test_axis() { const float startPosition = soft_endstop.min[encoderAxis] + 10, endPosition = soft_endstop.max[encoderAxis] - 10; - const feedRate_t fr_mm_s = FLOOR(MMM_TO_MMS((encoderAxis == Z_AXIS) ? HOMING_FEEDRATE_Z : HOMING_FEEDRATE_XY)); + const feedRate_t fr_mm_s = FLOOR(homing_feedrate(encoderAxis)); ec = false; @@ -382,7 +382,7 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) { int32_t startCount, stopCount; - const feedRate_t fr_mm_s = MMM_TO_MMS((encoderAxis == Z_AXIS) ? HOMING_FEEDRATE_Z : HOMING_FEEDRATE_XY); + const feedRate_t fr_mm_s = homing_feedrate(encoderAxis); bool oldec = ec; ec = false; diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index c55b278a72..c679e6b68f 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -180,7 +180,7 @@ void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/ // Machine state info.current_position = current_position; - info.feedrate = uint16_t(feedrate_mm_s * 60.0f); + info.feedrate = uint16_t(MMS_TO_MMM(feedrate_mm_s)); info.zraise = zraise; TERN_(GCODE_REPEAT_MARKERS, info.stored_repeat = repeat); diff --git a/Marlin/src/gcode/calibrate/G34.cpp b/Marlin/src/gcode/calibrate/G34.cpp index 85e843c2c8..a96eac0a88 100644 --- a/Marlin/src/gcode/calibrate/G34.cpp +++ b/Marlin/src/gcode/calibrate/G34.cpp @@ -63,7 +63,7 @@ void GcodeSuite::G34() { // Move Z to pounce position if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Setting Z Pounce"); - do_blocking_move_to_z(zpounce, MMM_TO_MMS(HOMING_FEEDRATE_Z)); + do_blocking_move_to_z(zpounce, homing_feedrate(Z_AXIS)); // Store current motor settings, then apply reduced value diff --git a/Marlin/src/gcode/feature/pause/G61.cpp b/Marlin/src/gcode/feature/pause/G61.cpp index d8049f02bc..5d89af0ab8 100644 --- a/Marlin/src/gcode/feature/pause/G61.cpp +++ b/Marlin/src/gcode/feature/pause/G61.cpp @@ -49,10 +49,6 @@ void GcodeSuite::G61(void) { // No saved position? No axes being restored? if (!TEST(saved_slots[slot >> 3], slot & 0x07) || !parser.seen("XYZ")) return; - // Apply any given feedrate over 0.0 - const float fr = parser.linearval('F'); - if (fr > 0.0) feedrate_mm_s = MMM_TO_MMS(fr); - SERIAL_ECHOPAIR(STR_RESTORING_POS " S", int(slot)); LOOP_XYZ(i) { destination[i] = parser.seen(XYZ_CHAR(i)) @@ -63,8 +59,15 @@ void GcodeSuite::G61(void) { } SERIAL_EOL(); + // Apply any given feedrate over 0.0 + feedRate_t saved_feedrate = feedrate_mm_s; + const float fr = parser.linearval('F'); + if (fr > 0.0) feedrate_mm_s = MMM_TO_MMS(fr); + // Move to the saved position prepare_line_to_destination(); + + feedrate_mm_s = saved_feedrate; } #endif // SAVED_POSITIONS diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.cpp b/Marlin/src/lcd/dwin/e3v2/dwin.cpp index db44782fde..38e41ba11e 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.cpp +++ b/Marlin/src/lcd/dwin/e3v2/dwin.cpp @@ -1166,7 +1166,7 @@ void HMI_Move_X() { if (!planner.is_full()) { // Wait for planner moves to finish! planner.synchronize(); - planner.buffer_line(current_position, MMM_TO_MMS(HOMING_FEEDRATE_XY), active_extruder); + planner.buffer_line(current_position, homing_feedrate(X_AXIS), active_extruder); } DWIN_UpdateLCD(); return; @@ -1189,7 +1189,7 @@ void HMI_Move_Y() { if (!planner.is_full()) { // Wait for planner moves to finish! planner.synchronize(); - planner.buffer_line(current_position, MMM_TO_MMS(HOMING_FEEDRATE_XY), active_extruder); + planner.buffer_line(current_position, homing_feedrate(Y_AXIS), active_extruder); } DWIN_UpdateLCD(); return; @@ -1212,7 +1212,7 @@ void HMI_Move_Z() { if (!planner.is_full()) { // Wait for planner moves to finish! planner.synchronize(); - planner.buffer_line(current_position, MMM_TO_MMS(HOMING_FEEDRATE_Z), active_extruder); + planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); } DWIN_UpdateLCD(); return; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp index 1db11a20e6..4ab60321b6 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_filament_change.cpp @@ -45,8 +45,6 @@ enum { ID_FILAMNT_RETURN }; -extern feedRate_t feedrate_mm_s; - static void event_handler(lv_obj_t *obj, lv_event_t event) { if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp index 518ddbd251..ec68c27212 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_operation.cpp @@ -53,8 +53,6 @@ enum { static lv_obj_t *label_PowerOff; static lv_obj_t *buttonPowerOff; -extern feedRate_t feedrate_mm_s; - static void event_handler(lv_obj_t *obj, lv_event_t event) { if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { diff --git a/Marlin/src/lcd/menu/menu_probe_offset.cpp b/Marlin/src/lcd/menu/menu_probe_offset.cpp index 7804e732ec..5b88c8e805 100644 --- a/Marlin/src/lcd/menu/menu_probe_offset.cpp +++ b/Marlin/src/lcd/menu/menu_probe_offset.cpp @@ -146,7 +146,7 @@ void prepare_for_probe_offset_wizard() { // Move Nozzle to Probing/Homing Position ui.wait_for_move = true; current_position += probe.offset_xy; - line_to_current_position(MMM_TO_MMS(HOMING_FEEDRATE_XY)); + line_to_current_position(MMM_TO_MMS(XY_PROBE_SPEED)); ui.synchronize(GET_TEXT(MSG_PROBE_WIZARD_MOVING)); ui.wait_for_move = false; diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 7b4c89e759..28bf16a310 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -510,7 +510,7 @@ void do_z_clearance(const float &zclear, const bool z_trusted/*=true*/, const bo const bool rel = raise_on_untrusted && !z_trusted; float zdest = zclear + (rel ? current_position.z : 0.0f); if (!lower_allowed) NOLESS(zdest, current_position.z); - do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), MMM_TO_MMS(TERN(HAS_BED_PROBE, Z_PROBE_SPEED_FAST, HOMING_FEEDRATE_Z))); + do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), TERN(HAS_BED_PROBE, MMM_TO_MMS(Z_PROBE_SPEED_FAST), homing_feedrate(Z_AXIS))); } // diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index efbfd7de4d..2eb54f36fb 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -73,12 +73,16 @@ extern const feedRate_t homing_feedrate_mm_s[XYZ]; FORCE_INLINE feedRate_t homing_feedrate(const AxisEnum a) { return pgm_read_float(&homing_feedrate_mm_s[a]); } feedRate_t get_homing_bump_feedrate(const AxisEnum axis); +/** + * The default feedrate for many moves, set by the most recent move + */ extern feedRate_t feedrate_mm_s; /** - * Feedrate scaling + * Feedrate scaling is applied to all G0/G1, G2/G3, and G5 moves */ extern int16_t feedrate_percentage; +#define MMS_SCALED(V) ((V) * 0.01f * feedrate_percentage) // The active extruder (tool). Set with T command. #if HAS_MULTI_EXTRUDER diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index ac30938f2a..5050f060b0 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -978,6 +978,6 @@ class Planner { #endif // !CLASSIC_JERK }; -#define PLANNER_XY_FEEDRATE() (_MIN(planner.settings.max_feedrate_mm_s[X_AXIS], planner.settings.max_feedrate_mm_s[Y_AXIS])) +#define PLANNER_XY_FEEDRATE() _MIN(planner.settings.max_feedrate_mm_s[X_AXIS], planner.settings.max_feedrate_mm_s[Y_AXIS]) extern Planner planner; diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index 400206f83a..edf7ba3e20 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -152,8 +152,8 @@ xyz_pos_t Probe::offset; // Initialized by settings.load() inline void run_stow_moves_script() { const xyz_pos_t oldpos = current_position; endstops.enable_z_probe(false); - do_blocking_move_to_z(TOUCH_MI_RETRACT_Z, MMM_TO_MMS(HOMING_FEEDRATE_Z)); - do_blocking_move_to(oldpos, MMM_TO_MMS(HOMING_FEEDRATE_Z)); + do_blocking_move_to_z(TOUCH_MI_RETRACT_Z, homing_feedrate(Z_AXIS)); + do_blocking_move_to(oldpos, homing_feedrate(Z_AXIS)); } #elif ENABLED(Z_PROBE_ALLEN_KEY) @@ -664,11 +664,8 @@ float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise } else if (!position_is_reachable(npos)) return NAN; // The given position is in terms of the nozzle - const float old_feedrate_mm_s = feedrate_mm_s; - feedrate_mm_s = XY_PROBE_FEEDRATE_MM_S; - // Move the probe to the starting XYZ - do_blocking_move_to(npos); + do_blocking_move_to(npos, feedRate_t(XY_PROBE_FEEDRATE_MM_S)); float measured_z = NAN; if (!deploy()) measured_z = run_z_probe(sanity_check) + offset.z; @@ -683,8 +680,6 @@ float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise SERIAL_ECHOLNPAIR("Bed X: ", LOGICAL_X_POSITION(rx), " Y: ", LOGICAL_Y_POSITION(ry), " Z: ", measured_z); } - feedrate_mm_s = old_feedrate_mm_s; - if (isnan(measured_z)) { stow(); LCD_MESSAGEPGM(MSG_LCD_PROBING_FAILED);