diff --git a/g2core/canonical_machine.h b/g2core/canonical_machine.h index a5e49b4f..db353a83 100644 --- a/g2core/canonical_machine.h +++ b/g2core/canonical_machine.h @@ -115,10 +115,10 @@ typedef enum { // feedhold state machine FEEDHOLD_SYNC, // start hold - sync to latest aline segment FEEDHOLD_DECEL_CONTINUE, // in deceleration that will not end at zero FEEDHOLD_DECEL_TO_ZERO, // in deceleration that will go to zero - FEEDHOLD_DECEL_COMPLETE, // feedhold deceleration has completed - FEEDHOLD_MOTORS_STOPPING, // waiting to complete deceleration once planner motion stops - FEEDHOLD_ACTIONS_START, // enter secondary planner and perform feedhold actions (once) - FEEDHOLD_ACTIONS_WAIT, // wait for feedhold actions to complete + FEEDHOLD_DECEL_COMPLETE, // feedhold deceleration has completed, but motors may not have stopped yet + FEEDHOLD_MOTORS_STOPPING, // waiting for motors to have stopped on hold point (motion stop) + FEEDHOLD_P2_START, // enter secondary planner and perform feedhold actions (once) + FEEDHOLD_P2_WAIT, // wait for feedhold actions to complete FEEDHOLD_HOLD, // holding (steady state) Must be last state FEEDHOLD_P2_EXIT // set when p2 feedhold is finishing } cmFeedholdState; diff --git a/g2core/cycle_feedhold.cpp b/g2core/cycle_feedhold.cpp index 496a2d2b..bdae316d 100644 --- a/g2core/cycle_feedhold.cpp +++ b/g2core/cycle_feedhold.cpp @@ -67,7 +67,7 @@ static stat_t _feedhold_alarm_exit(void); * A feedhold exit request (~) received while in either p1 or p2 will execute the * feedhold exit actions: * - Resume coolant (if paused) - * - Resume spindle (if paseud) with spinup delay + * - Resume spindle (if paused) with spinup delay * - Move back to starting location in XY, then plunge in Z * Motion will resume in p1 after the exit actions complete * @@ -76,7 +76,8 @@ static stat_t _feedhold_alarm_exit(void); */ /* * Feedhold Processing - Performs the following cases (listed in rough sequence order): - * (0) - Feedhold request arrives or cm_start_hold() + * + * (0) - Feedhold request arrives or cm_start_hold() is called * * Control transfers to plan_exec.cpp feedhold functions: * @@ -93,22 +94,17 @@ static stat_t _feedhold_alarm_exit(void); * (unlikely, but handled as 1b). * * (2) - The block has decelerated to some velocity > zero, so needs continuation into next block - * - * (3) - The block has decelerated to zero velocity - * (3a) - The end of deceleration is detected inline in mp_exec_aline() - * (3b) - The end of deceleration is signaled and state is transitioned - * - * (4) - Finished all the runtime work, now wait for the motors to stop + * (3) - The end of deceleration is detected inline in mp_exec_aline() + * (4) - Finished all runtime work, now wait for the motors to stop on HOLD point. When they do: * (4a) - It's a homing or probing feedhold - ditch the remaining buffer & go directly to OFF * (4b) - It's a p2 feedhold - ditch the remaining buffer & signal we want a p2 queue flush * (4c) - It's a normal feedhold - signal we want the p2 entry actions to execute * - * (5) - The steppers have stopped. No motion should occur. Allows hold actions to complete - * * Control transfers back to cycle_feedhold.cpp feedhold functions: * - * (6) - Removing the hold state and there is queued motion - see cycle_feedhold.cpp - * (7) - Removing the hold state and there is no queued motion - see cycle_feedhold.cpp + * (5) - Run the P2 entry actions and transition to HOLD state when complete + * (6) - Remove the hold state / there is queued motion - see cycle_feedhold.cpp + * (7) - Remove the hold state / there is no queued motion - see cycle_feedhold.cpp */ /**************************************************************************************** @@ -211,7 +207,7 @@ stat_t cm_feedhold_sequencing_callback() cm1.hold_state = FEEDHOLD_SYNC; // invokes hold from aline execution } } - if (cm1.hold_state == FEEDHOLD_ACTIONS_START) { // perform Z lift, spindle & coolant actions + if (cm1.hold_state == FEEDHOLD_P2_START) { // enter p2 planner; perform Z lift, spindle & coolant actions _run_p1_hold_entry_actions(); } @@ -271,7 +267,7 @@ stat_t cm_feedhold_command_blocker() } /**************************************************************************************** - * _run_p1_hold_entry_actions() - run actions in p2 that complete the p1 hold + * _run_p1_hold_entry_actions() - run actions in p2 that complete the p1 hold * _sync_to_p1_hold_entry_actions_done() - final state change occurs here * * This function assumes that the feedhold sequencing callback has resolved all @@ -287,13 +283,13 @@ stat_t cm_feedhold_command_blocker() * from an interrupt, so it only sets a flag. */ -static void _sync_to_p1_hold_entry_actions_done(float* vect, bool* flag) +static void _sync_to_p1_hold_entry_actions_done(float* vect, bool* flag) // Complete case (5) { cm1.hold_state = FEEDHOLD_HOLD; sr_request_status_report(SR_REQUEST_IMMEDIATE); } -static stat_t _run_p1_hold_entry_actions() +static stat_t _run_p1_hold_entry_actions() // Execute Case (5) { // do not perform entry actions if in alarm state if (cm_is_alarmed()) { @@ -301,7 +297,7 @@ static stat_t _run_p1_hold_entry_actions() return (STAT_OK); } - cm->hold_state = FEEDHOLD_ACTIONS_WAIT; // penultimate state before transitioning to HOLD + cm->hold_state = FEEDHOLD_P2_WAIT; // penultimate state before transitioning to HOLD // copy the primary canonical machine to the secondary, // fix the planner pointer, and reset the secondary planner @@ -360,7 +356,7 @@ static stat_t _run_p1_hold_entry_actions() * the sync runs from an interrupt. Finalization needs to run from the main loop. */ -static stat_t _run_p1_hold_exit_actions() // LATER: if value == true return with offset corrections +static stat_t _run_p1_hold_exit_actions() // Execute Cases (6) and (7) { // perform end-hold actions --- while still in secondary machine coolant_control_sync(COOLANT_RESUME, COOLANT_BOTH); // resume coolant if paused diff --git a/g2core/plan_exec.cpp b/g2core/plan_exec.cpp index 9c2cc5b4..620f6d9c 100644 --- a/g2core/plan_exec.cpp +++ b/g2core/plan_exec.cpp @@ -480,9 +480,9 @@ stat_t mp_exec_aline(mpBuf_t *bf) // Feedhold Processing - We need to handle the following cases (listed in rough sequence order): if (cm->motion_state == MOTION_HOLD) { - // if FEEDHOLD_ACTIONS_START, FEEDHOLD_ACTIONS_WAIT, FEEDHOLD HOLD or FEEDHOLD_P2_EXIT - if (cm->hold_state >= FEEDHOLD_ACTIONS_START) { // handles _exec_aline_feedhold_processing case (7) - return (STAT_NOOP); // VERY IMPORTANT to exit as a NOOP. Do not load another move + // if FEEDHOLD_P2_START, FEEDHOLD_P2_WAIT, FEEDHOLD HOLD or FEEDHOLD_P2_EXIT + if (cm->hold_state >= FEEDHOLD_P2_START) { // handles _exec_aline_feedhold_processing case (7) + return (STAT_NOOP); // VERY IMPORTANT to exit as a NOOP. Do not load another move } // STAT_OK terminates aline execution for this move // STAT_NOOP terminates execution and does not load another move @@ -517,7 +517,7 @@ stat_t mp_exec_aline(mpBuf_t *bf) bf->plannable = false; } - // Feedhold Case (3b): Look for the end of the deceleration to transition HOLD states + // Feedhold Case (3): Look for the end of the deceleration to transition HOLD states // This code sets states used by _exec_feedhold_processing() helper. if (cm->hold_state == FEEDHOLD_DECEL_TO_ZERO) { if ((status == STAT_OK) || (status == STAT_NOOP)) { @@ -1050,7 +1050,7 @@ static stat_t _exec_aline_feedhold(mpBuf_t *bf) st_request_forward_plan(); // replan the current bf buffer // Set state to enable transition to p2 and perform entry actions in the p2 planner - cm->hold_state = FEEDHOLD_ACTIONS_START; // executes entirely out of p2 planner + cm->hold_state = FEEDHOLD_P2_START; // executes entirely out of p2 planner } sr_request_status_report(SR_REQUEST_IMMEDIATE); @@ -1059,8 +1059,9 @@ static stat_t _exec_aline_feedhold(mpBuf_t *bf) return (STAT_NOOP); // hold here. leave with a NOOP so it does not attempt another load and exec. } - // Case (3b) - Decelerated to zero. See also Feedhold Case (3a) in mp_exec_aline() + // Case (3') - Decelerated to zero. See also Feedhold Case (3) in mp_exec_aline() // Update the run buffer then force a replan of the whole planner queue. Replans from zero velocity + // This state might not appear necessary, but it is to handle closely packed !~ and other cases if (cm->hold_state == FEEDHOLD_DECEL_COMPLETE) { cm->hold_state = FEEDHOLD_MOTORS_STOPPING; // wait for the motors to come to a complete stop return (STAT_OK); // exit from mp_exec_aline()