Realtime Reporting, S000, P000, R000 (#19330)

This commit is contained in:
fedetony
2021-04-16 08:59:28 +02:00
committed by GitHub
parent 58cc4b7043
commit 32dba5e0c7
17 changed files with 275 additions and 70 deletions

View File

@ -230,6 +230,50 @@ void report_current_position_projected() {
stepper.report_a_position(planner.position);
}
#if EITHER(FULL_REPORT_TO_HOST_FEATURE, REALTIME_REPORTING_COMMANDS)
M_StateEnum M_State_grbl = M_INIT;
/**
* Output the current grbl compatible state to serial while moving
*/
void report_current_grblstate_moving() { SERIAL_ECHOLNPAIR("S_XYZ:", int(M_State_grbl)); }
/**
* Output the current position (processed) to serial while moving
*/
void report_current_position_moving() {
get_cartesian_from_steppers();
const xyz_pos_t lpos = cartes.asLogical();
SERIAL_ECHOPAIR("X:", lpos.x, " Y:", lpos.y, " Z:", lpos.z, " E:", current_position.e);
stepper.report_positions();
#if IS_SCARA
scara_report_positions();
#endif
report_current_grblstate_moving();
}
/**
* Set a Grbl-compatible state from the current marlin_state
*/
M_StateEnum grbl_state_for_marlin_state() {
switch (marlin_state) {
case MF_INITIALIZING: return M_INIT;
case MF_SD_COMPLETE: return M_ALARM;
case MF_WAITING: return M_IDLE;
case MF_STOPPED: return M_END;
case MF_RUNNING: return M_RUNNING;
case MF_PAUSED: return M_HOLD;
case MF_KILLED: return M_ERROR;
default: return M_IDLE;
}
}
#endif
/**
* Run out the planner buffer and re-sync the current
* position from the last-updated stepper positions.
@ -241,6 +285,20 @@ void quickstop_stepper() {
sync_plan_position();
}
#if ENABLED(REALTIME_REPORTING_COMMANDS)
void quickpause_stepper() {
planner.quick_pause();
//planner.synchronize();
}
void quickresume_stepper() {
planner.quick_resume();
//planner.synchronize();
}
#endif
/**
* Set the planner/stepper positions directly from current_position with
* no kinematic translation. Used for homing axes and cartesian/core syncing.

View File

@ -211,14 +211,49 @@ void report_real_position();
void report_current_position();
void report_current_position_projected();
#if EITHER(FULL_REPORT_TO_HOST_FEATURE, REALTIME_REPORTING_COMMANDS)
#define HAS_GRBL_STATE 1
/**
* Machine states for GRBL or TinyG
*/
enum M_StateEnum : uint8_t {
M_INIT = 0, // 0 machine is initializing
M_RESET, // 1 machine is ready for use
M_ALARM, // 2 machine is in alarm state (soft shut down)
M_IDLE, // 3 program stop or no more blocks (M0, M1, M60)
M_END, // 4 program end via M2, M30
M_RUNNING, // 5 motion is running
M_HOLD, // 6 motion is holding
M_PROBE, // 7 probe cycle active
M_CYCLING, // 8 machine is running (cycling)
M_HOMING, // 9 machine is homing
M_JOGGING, // 10 machine is jogging
M_ERROR // 11 machine is in hard alarm state (shut down)
};
extern M_StateEnum M_State_grbl;
M_StateEnum grbl_state_for_marlin_state();
void report_current_grblstate_moving();
void report_current_position_moving();
#if ENABLED(FULL_REPORT_TO_HOST_FEATURE)
inline void set_and_report_grblstate(const M_StateEnum state) {
M_State_grbl = state;
report_current_grblstate_moving();
}
#endif
#if ENABLED(REALTIME_REPORTING_COMMANDS)
void quickpause_stepper();
void quickresume_stepper();
#endif
#endif
void get_cartesian_from_steppers();
void set_current_from_steppers_for_axis(const AxisEnum axis);
void quickstop_stepper();
/**
* sync_plan_position
*
* Set the planner/stepper positions directly from current_position with
* no kinematic translation. Used for homing axes and cartesian/core syncing.
*/

View File

@ -1650,6 +1650,24 @@ void Planner::quick_stop() {
stepper.quick_stop();
}
#if ENABLED(REALTIME_REPORTING_COMMANDS)
void Planner::quick_pause() {
// Suspend until quick_resume is called
// Don't empty buffers or queues
const bool did_suspend = stepper.suspend();
if (did_suspend)
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(M_HOLD));
}
// Resume if suspended
void Planner::quick_resume() {
TERN_(FULL_REPORT_TO_HOST_FEATURE, set_and_report_grblstate(grbl_state_for_marlin_state()));
stepper.wake_up();
}
#endif
void Planner::endstop_triggered(const AxisEnum axis) {
// Record stepper position and discard the current block
stepper.endstop_triggered(axis);

View File

@ -873,6 +873,13 @@ class Planner {
// a Full Shutdown is required, or when endstops are hit)
static void quick_stop();
#if ENABLED(REALTIME_REPORTING_COMMANDS)
// Force a quick pause of the machine (e.g., when a pause is required in the middle of move).
// NOTE: Hard-stops will lose steps so encoders are highly recommended if using these!
static void quick_pause();
static void quick_resume();
#endif
// Called when an endstop is triggered. Causes the machine to stop inmediately
static void endstop_triggered(const AxisEnum axis);