From a3e25a0fcad09cc042718407bb2ffad2b6b78f65 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 7 Mar 2016 20:11:56 -0800 Subject: [PATCH 1/2] Instead of trying to move now, set a flag to move asap --- Marlin/Marlin.h | 2 +- Marlin/ultralcd.cpp | 46 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index ab85ab5926..1268308f1b 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -213,7 +213,7 @@ void manage_inactivity(bool ignore_stepper_queue = false); * A_AXIS and B_AXIS are used by COREXY printers * X_HEAD and Y_HEAD is used for systems that don't have a 1:1 relationship between X_AXIS and X Head movement, like CoreXY bots. */ -enum AxisEnum {X_AXIS = 0, A_AXIS = 0, Y_AXIS = 1, B_AXIS = 1, Z_AXIS = 2, C_AXIS = 2, E_AXIS = 3, X_HEAD = 4, Y_HEAD = 5, Z_HEAD = 5}; +enum AxisEnum {NO_AXIS = -1, X_AXIS = 0, A_AXIS = 0, Y_AXIS = 1, B_AXIS = 1, Z_AXIS = 2, C_AXIS = 2, E_AXIS = 3, X_HEAD = 4, Y_HEAD = 5, Z_HEAD = 5}; #define _AXIS(AXIS) AXIS ##_AXIS diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 63fe56b66c..815d4cee22 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -50,6 +50,8 @@ int8_t encoderDiff; // updated from interrupt context and added to encoderPosition every LCD update +int8_t manual_move_axis = (int8_t)NO_AXIS; + bool encoderRateMultiplierEnabled; int32_t lastEncoderMovementMillis; @@ -938,7 +940,7 @@ void lcd_cooldown() { ENCODER_DIRECTION_NORMAL(); // Encoder wheel adjusts the Z position - if (encoderPosition && planner.movesplanned() <= 3) { + if (encoderPosition) { refresh_cmd_timeout(); current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP); NOLESS(current_position[Z_AXIS], 0); @@ -951,8 +953,8 @@ void lcd_cooldown() { LCDVIEW_REDRAW_NOW #endif ; + encoderPosition = 0; } - encoderPosition = 0; static bool debounce_click = false; if (LCD_CLICKED) { @@ -1190,6 +1192,32 @@ static void lcd_prepare_menu() { #endif // DELTA_CALIBRATION_MENU +/** + * If the manual move hasn't been fed to the planner yet, + * and the planner can accept one, send immediately + */ +inline void manage_manual_move() { + if (manual_move_axis != (int8_t)NO_AXIS && !planner.planner_is_full()) { + #if ENABLED(DELTA) + calculate_delta(current_position); + planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[manual_move_axis]/60, active_extruder); + #else + planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[manual_move_axis]/60, active_extruder); + #endif + manual_move_axis = (int8_t)NO_AXIS; + } +} + +/** + * Set a flag that lcd_update() should send a move + * to "current_position" at the next opportunity, + * and try to send one now. + */ +inline void manual_move_to_current(AxisEnum axis) { + manual_move_axis = (int8_t)axis; + manage_manual_move(); +} + /** * * "Prepare" > "Move Axis" submenu @@ -1200,15 +1228,15 @@ float move_menu_scale; static void _lcd_move(const char* name, AxisEnum axis, float min, float max) { ENCODER_DIRECTION_NORMAL(); - if (encoderPosition && planner.movesplanned() <= 3) { + if (encoderPosition) { refresh_cmd_timeout(); current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale; if (min_software_endstops) NOLESS(current_position[axis], min); if (max_software_endstops) NOMORE(current_position[axis], max); - line_to_current(axis); + encoderPosition = 0; + manual_move_to_current(axis); lcdDrawUpdate = LCDVIEW_REDRAW_NOW; } - encoderPosition = 0; if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis])); if (LCD_CLICKED) lcd_goto_previous_menu(true); } @@ -1232,12 +1260,12 @@ static void lcd_move_e( unsigned short original_active_extruder = active_extruder; active_extruder = e; #endif - if (encoderPosition && planner.movesplanned() <= 3) { + if (encoderPosition) { current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale; - line_to_current(E_AXIS); + encoderPosition = 0; + manual_move_to_current(E_AXIS); lcdDrawUpdate = LCDVIEW_REDRAW_NOW; } - encoderPosition = 0; if (lcdDrawUpdate) { PGM_P pos_label; #if EXTRUDERS == 1 @@ -2149,6 +2177,8 @@ void lcd_update() { static millis_t return_to_status_ms = 0; #endif + manage_manual_move(); + lcd_buttons_update(); #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT) From 47b5c55c292d95e03455b54591bef500e9bcd625 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 3 Apr 2016 18:06:17 -0700 Subject: [PATCH 2/2] Implement the delayed-move technique --- Marlin/planner.h | 2 ++ Marlin/ultralcd.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Marlin/planner.h b/Marlin/planner.h index 96e580db96..7a9f96e66c 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -189,6 +189,8 @@ class Planner { */ static uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); } + static bool is_full() { return (block_buffer_tail == BLOCK_MOD(block_buffer_head + 1)); } + #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING) #if ENABLED(AUTO_BED_LEVELING_FEATURE) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 815d4cee22..cf9c9ac4cc 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -51,6 +51,7 @@ int8_t encoderDiff; // updated from interrupt context and added to encoderPosition every LCD update int8_t manual_move_axis = (int8_t)NO_AXIS; +millis_t manual_move_start_time = 0; bool encoderRateMultiplierEnabled; int32_t lastEncoderMovementMillis; @@ -1193,11 +1194,11 @@ static void lcd_prepare_menu() { #endif // DELTA_CALIBRATION_MENU /** - * If the manual move hasn't been fed to the planner yet, + * If the most recent manual move hasn't been fed to the planner yet, * and the planner can accept one, send immediately */ inline void manage_manual_move() { - if (manual_move_axis != (int8_t)NO_AXIS && !planner.planner_is_full()) { + if (manual_move_axis != (int8_t)NO_AXIS && millis() >= manual_move_start_time && !planner.is_full()) { #if ENABLED(DELTA) calculate_delta(current_position); planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[manual_move_axis]/60, active_extruder); @@ -1209,13 +1210,12 @@ inline void manage_manual_move() { } /** - * Set a flag that lcd_update() should send a move - * to "current_position" at the next opportunity, - * and try to send one now. + * Set a flag that lcd_update() should start a move + * to "current_position" after a short delay. */ inline void manual_move_to_current(AxisEnum axis) { + manual_move_start_time = millis() + 500UL; // 1/2 second delay manual_move_axis = (int8_t)axis; - manage_manual_move(); } /**