Skip to content

Commit

Permalink
✨ EP_BABYSTEPPING (MarlinFirmware#25869)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and Tracy Spiva committed May 25, 2023
1 parent f5636c9 commit a63000f
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 179 deletions.
4 changes: 2 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@
*/
#define SHOW_BOOTSCREEN // Show the Marlin bootscreen on startup. ** ENABLE FOR PRODUCTION **
#if ENABLED(SHOW_BOOTSCREEN)
#define BOOTSCREEN_TIMEOUT 4000 // (ms) Total Duration to display the boot screen(s)
#define BOOTSCREEN_TIMEOUT 3000 // (ms) Total Duration to display the boot screen(s)
#if EITHER(HAS_MARLINUI_U8GLIB, TFT_COLOR_UI)
#define BOOT_MARLIN_LOGO_SMALL // Show a smaller Marlin logo on the Boot Screen (saving lots of flash)
#endif
Expand Down Expand Up @@ -2210,7 +2210,7 @@
#if ENABLED(BABYSTEPPING)
#define INTEGRATED_BABYSTEPPING // EXPERIMENTAL integration of babystepping into the Stepper ISR
//#define BABYSTEP_WITHOUT_HOMING
//#define BABYSTEP_ALWAYS_AVAILABLE // Allow babystepping at all times (not just during movement).
//#define BABYSTEP_ALWAYS_AVAILABLE // Allow babystepping at all times (not just during movement)
//#define BABYSTEP_XY // Also enable X/Y Babystepping. Not supported on DELTA!
//#define BABYSTEP_INVERT_Z // Enable if Z babysteps should go the other way
//#define BABYSTEP_MILLIMETER_UNITS // Specify BABYSTEP_MULTIPLICATOR_(XY|Z) in mm instead of micro-steps
Expand Down
9 changes: 9 additions & 0 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,10 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
#endif
}

#if BOTH(EP_BABYSTEPPING, EMERGENCY_PARSER)
#include "feature/babystep.h"
#endif

/**
* Standard idle routine keeps the machine alive:
* - Core Marlin activities
Expand Down Expand Up @@ -848,6 +852,11 @@ void idle(const bool no_stepper_sleep/*=false*/) {
// Handle Joystick jogging
TERN_(POLL_JOG, joystick.inject_jog_moves());

// Async Babystepping via the Emergency Parser
#if BOTH(EP_BABYSTEPPING, EMERGENCY_PARSER)
babystep.do_ep_steps();
#endif

// Direct Stepping
TERN_(DIRECT_STEPPING, page_manager.write_responses());

Expand Down
12 changes: 11 additions & 1 deletion Marlin/src/feature/babystep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "babystep.h"
#include "../MarlinCore.h"
#include "../module/motion.h" // for axes_should_home()
#include "../module/motion.h" // for axes_should_home(), BABYSTEP_ALLOWED
#include "../module/planner.h" // for axis_steps_per_mm[]
#include "../module/stepper.h"

Expand All @@ -42,6 +42,10 @@ volatile int16_t Babystep::steps[BS_AXIS_IND(Z_AXIS) + 1];
#endif
int16_t Babystep::accum;

#if BOTH(EP_BABYSTEPPING, EMERGENCY_PARSER)
int16_t Babystep::ep_babysteps;
#endif

void Babystep::step_axis(const AxisEnum axis) {
const int16_t curTodo = steps[BS_AXIS_IND(axis)]; // get rid of volatile for performance
if (curTodo) {
Expand Down Expand Up @@ -76,4 +80,10 @@ void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
TERN_(INTEGRATED_BABYSTEPPING, if (has_steps()) stepper.initiateBabystepping());
}

#if ENABLED(EP_BABYSTEPPING)
// Step Z for M293 / M294
void Babystep::z_up() { if (BABYSTEP_ALLOWED()) add_steps(Z_AXIS, +BABYSTEP_SIZE_Z); }
void Babystep::z_down() { if (BABYSTEP_ALLOWED()) add_steps(Z_AXIS, -BABYSTEP_SIZE_Z); }
#endif

#endif // BABYSTEPPING
19 changes: 19 additions & 0 deletions Marlin/src/feature/babystep.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Babystep {
static volatile int16_t steps[BS_AXIS_IND(Z_AXIS) + 1];
static int16_t accum; // Total babysteps in current edit

#if BOTH(EP_BABYSTEPPING, EMERGENCY_PARSER)
static int16_t ep_babysteps;
#endif

#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
static int16_t axis_total[BS_TOTAL_IND(Z_AXIS) + 1]; // Total babysteps since G28
static void reset_total(const AxisEnum axis) {
Expand All @@ -63,6 +67,21 @@ class Babystep {
static void add_steps(const AxisEnum axis, const int16_t distance);
static void add_mm(const AxisEnum axis, const_float_t mm);

#if ENABLED(EP_BABYSTEPPING)
// Step Z for M293 / M294
static void z_up();
static void z_down();
#if ENABLED(EMERGENCY_PARSER)
// Step Z according to steps accumulated by the EP
FORCE_INLINE static void do_ep_steps() {
if (ep_babysteps) {
if (ep_babysteps > 0) { z_up(); ep_babysteps--; }
else { z_down(); ep_babysteps++; }
}
}
#endif
#endif // EP_BABYSTEPPING

#if ENABLED(BD_SENSOR)
static void set_mm(const AxisEnum axis, const_float_t mm);
#endif
Expand Down
185 changes: 184 additions & 1 deletion Marlin/src/feature/e_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* e_parser.cpp - Intercept special commands directly in the serial stream
*/

#include "../inc/MarlinConfigPre.h"
#include "../inc/MarlinConfig.h"

#if ENABLED(EMERGENCY_PARSER)

Expand All @@ -39,10 +39,193 @@ bool EmergencyParser::killed_by_M112, // = false
EmergencyParser::enabled;

#if ENABLED(HOST_PROMPT_SUPPORT)
#include "host_actions.h"
uint8_t EmergencyParser::M876_reason; // = 0
#endif

// Global instance
EmergencyParser emergency_parser;

// External references
extern bool wait_for_user, wait_for_heatup;

#if ENABLED(EP_BABYSTEPPING)
#include "babystep.h"
#endif

#if ENABLED(REALTIME_REPORTING_COMMANDS)
// From motion.h, which cannot be included here
void report_current_position_moving();
void quickpause_stepper();
void quickresume_stepper();
#endif

void EmergencyParser::update(EmergencyParser::State &state, const uint8_t c) {
switch (state) {
case EP_RESET:
switch (c) {
case ' ': case '\n': case '\r': break;
case 'N': state = EP_N; break;
case 'M': state = EP_M; break;
#if ENABLED(REALTIME_REPORTING_COMMANDS)
case 'S': state = EP_S; break;
case 'P': state = EP_P; break;
case 'R': state = EP_R; break;
#endif
#if ENABLED(SOFT_RESET_VIA_SERIAL)
case '^': state = EP_ctrl; break;
case 'K': state = EP_K; break;
#endif
default: state = EP_IGNORE;
}
break;

case EP_N:
switch (c) {
case '0' ... '9':
case '-': case ' ': break;
case 'M': state = EP_M; break;
#if ENABLED(REALTIME_REPORTING_COMMANDS)
case 'S': state = EP_S; break;
case 'P': state = EP_P; break;
case 'R': state = EP_R; break;
#endif
default: state = EP_IGNORE;
}
break;

#if ENABLED(REALTIME_REPORTING_COMMANDS)
case EP_S: state = (c == '0') ? EP_S0 : EP_IGNORE; break;
case EP_S0: state = (c == '0') ? EP_S00 : EP_IGNORE; break;
case EP_S00: state = (c == '0') ? EP_GRBL_STATUS : EP_IGNORE; break;

case EP_R: state = (c == '0') ? EP_R0 : EP_IGNORE; break;
case EP_R0: state = (c == '0') ? EP_R00 : EP_IGNORE; break;
case EP_R00: state = (c == '0') ? EP_GRBL_RESUME : EP_IGNORE; break;

case EP_P: state = (c == '0') ? EP_P0 : EP_IGNORE; break;
case EP_P0: state = (c == '0') ? EP_P00 : EP_IGNORE; break;
case EP_P00: state = (c == '0') ? EP_GRBL_PAUSE : EP_IGNORE; break;
#endif

#if ENABLED(SOFT_RESET_VIA_SERIAL)
case EP_ctrl: state = (c == 'X') ? EP_KILL : EP_IGNORE; break;
case EP_K: state = (c == 'I') ? EP_KI : EP_IGNORE; break;
case EP_KI: state = (c == 'L') ? EP_KIL : EP_IGNORE; break;
case EP_KIL: state = (c == 'L') ? EP_KILL : EP_IGNORE; break;
#endif

case EP_M:
switch (c) {
case ' ': break;
case '1': state = EP_M1; break;
#if ENABLED(EP_BABYSTEPPING)
case '2': state = EP_M2; break;
#endif
case '4': state = EP_M4; break;
#if HAS_MEDIA
case '5': state = EP_M5; break;
#endif
#if ENABLED(HOST_PROMPT_SUPPORT)
case '8': state = EP_M8; break;
#endif
default: state = EP_IGNORE;
}
break;

case EP_M1:
switch (c) {
case '0': state = EP_M10; break;
case '1': state = EP_M11; break;
default: state = EP_IGNORE;
}
break;

case EP_M10: state = (c == '8') ? EP_M108 : EP_IGNORE; break;
case EP_M11: state = (c == '2') ? EP_M112 : EP_IGNORE; break;
case EP_M4: state = (c == '1') ? EP_M41 : EP_IGNORE; break;
case EP_M41: state = (c == '0') ? EP_M410 : EP_IGNORE; break;

#if HAS_MEDIA
case EP_M5: state = (c == '2') ? EP_M52 : EP_IGNORE; break;
case EP_M52: state = (c == '4') ? EP_M524 : EP_IGNORE; break;
#endif

#if ENABLED(EP_BABYSTEPPING)
case EP_M2:
switch (c) {
case '9': state = EP_M29; break;
default: state = EP_IGNORE;
}
break;

case EP_M29:
switch (c) {
case '3': state = EP_M293; break;
case '4': state = EP_M294; break;
default: state = EP_IGNORE;
}
break;
#endif

#if ENABLED(HOST_PROMPT_SUPPORT)

case EP_M8: state = (c == '7') ? EP_M87 : EP_IGNORE; break;
case EP_M87: state = (c == '6') ? EP_M876 : EP_IGNORE; break;

case EP_M876:
switch (c) {
case ' ': break;
case 'S': state = EP_M876S; break;
default: state = EP_IGNORE; break;
}
break;

case EP_M876S:
switch (c) {
case ' ': break;
case '0' ... '9':
state = EP_M876SN;
M876_reason = uint8_t(c - '0');
break;
}
break;

#endif

case EP_IGNORE:
if (ISEOL(c)) state = EP_RESET;
break;

default:
if (ISEOL(c)) {
if (enabled) switch (state) {
case EP_M108: wait_for_user = wait_for_heatup = false; break;
case EP_M112: killed_by_M112 = true; break;
case EP_M410: quickstop_by_M410 = true; break;
#if ENABLED(EP_BABYSTEPPING)
case EP_M293: babystep.ep_babysteps++; break;
case EP_M294: babystep.ep_babysteps--; break;
#endif
#if HAS_MEDIA
case EP_M524: sd_abort_by_M524 = true; break;
#endif
#if ENABLED(HOST_PROMPT_SUPPORT)
case EP_M876SN: hostui.handle_response(M876_reason); break;
#endif
#if ENABLED(REALTIME_REPORTING_COMMANDS)
case EP_GRBL_STATUS: report_current_position_moving(); break;
case EP_GRBL_PAUSE: quickpause_stepper(); break;
case EP_GRBL_RESUME: quickresume_stepper(); break;
#endif
#if ENABLED(SOFT_RESET_VIA_SERIAL)
case EP_KILL: hal.reboot(); break;
#endif
default: break;
}
state = EP_RESET;
}
}
}

#endif // EMERGENCY_PARSER
Loading

0 comments on commit a63000f

Please sign in to comment.