v1.1c: New sleep mode. Laser mode and other bug fixes.
- New $SLP sleep mode that will disable spindle, coolant, and stepper enable pins. Allows users to disable their steppers without having to alter their settings. A reset is required to exit and re-initializes in alarm state. - Laser mode wasn’t updating the spindle PWM correctly (effected spindle speed overrides) and not checking for modal states either. Fixed both issues. - While in laser mode, parking motions are ignored, since the power off delay with the retract motion would burn the material. It will just turn off and not move. A restore immediately powers up and resumes. No delays. - Changing rpm max and min settings did not update the spindle PWM calculations. Now fixed. - Increased default planner buffer from 16 to 17 block. It seems to be stable, but need to monitor this carefully. - Removed software debounce routine for limit pins. Obsolete. - Fixed a couple parking motion bugs. One related to restoring incorrectly and the other the parking rate wasn’t compatible with the planner structs. - Fixed a bug caused by refactoring the critical alarms in a recent push. Soft limits weren’t invoking a critical alarm. - Updated the documentation with the new sleep feature and added some more details to the change summary.
This commit is contained in:
parent
e2e2bb5242
commit
d1037268c8
20 changed files with 176 additions and 202 deletions
140
grbl/protocol.c
140
grbl/protocol.c
|
|
@ -47,8 +47,11 @@ void protocol_main_loop()
|
|||
}
|
||||
#endif
|
||||
// Check for and report alarm state after a reset, error, or an initial power up.
|
||||
if (sys.state == STATE_ALARM) {
|
||||
// NOTE: Sleep mode disables the stepper drivers and position can't be guaranteed.
|
||||
// Re-initialize the sleep state as an ALARM mode to ensure user homes or acknowledges.
|
||||
if (sys.state & (STATE_ALARM | STATE_SLEEP)) {
|
||||
report_feedback_message(MESSAGE_ALARM_LOCK);
|
||||
sys.state = STATE_ALARM; // Ensure alarm state is set.
|
||||
} else {
|
||||
// Check if the safety door is open.
|
||||
sys.state = STATE_IDLE;
|
||||
|
|
@ -155,7 +158,6 @@ void protocol_main_loop()
|
|||
|
||||
protocol_execute_realtime(); // Runtime command check point.
|
||||
if (sys.abort) { return; } // Bail to main() program loop to reset system.
|
||||
|
||||
}
|
||||
|
||||
return; /* Never reached */
|
||||
|
|
@ -221,7 +223,7 @@ void protocol_exec_rt_system()
|
|||
sys.state = STATE_ALARM; // Set system alarm state
|
||||
report_alarm_message(rt_exec);
|
||||
// Halt everything upon a critical event flag. Currently hard and soft limits flag this.
|
||||
if ((rt_exec == EXEC_ALARM_HARD_LIMIT) || (rt_exec == EXEC_ALARM_HARD_LIMIT)) {
|
||||
if ((rt_exec == EXEC_ALARM_HARD_LIMIT) || (rt_exec == EXEC_ALARM_SOFT_LIMIT)) {
|
||||
report_feedback_message(MESSAGE_CRITICAL_EVENT);
|
||||
system_clear_exec_state_flag(EXEC_RESET); // Disable any existing reset
|
||||
do {
|
||||
|
|
@ -252,25 +254,23 @@ void protocol_exec_rt_system()
|
|||
|
||||
// NOTE: Once hold is initiated, the system immediately enters a suspend state to block all
|
||||
// main program processes until either reset or resumed. This ensures a hold completes safely.
|
||||
if (rt_exec & (EXEC_MOTION_CANCEL | EXEC_FEED_HOLD | EXEC_SAFETY_DOOR)) {
|
||||
if (rt_exec & (EXEC_MOTION_CANCEL | EXEC_FEED_HOLD | EXEC_SAFETY_DOOR | EXEC_SLEEP)) {
|
||||
|
||||
// State check for allowable states for hold methods.
|
||||
if ((sys.state == STATE_IDLE) ||
|
||||
(sys.state & (STATE_CYCLE | STATE_HOMING | STATE_HOLD | STATE_SAFETY_DOOR | STATE_JOG))) {
|
||||
|
||||
if (!(sys.state & (STATE_ALARM | STATE_CHECK_MODE))) {
|
||||
|
||||
// If in CYCLE or JOG states, immediately initiate a motion HOLD.
|
||||
if (sys.state & (STATE_CYCLE | STATE_JOG)) {
|
||||
if (!(sys.suspend & (SUSPEND_MOTION_CANCEL | SUSPEND_JOG_CANCEL))) { // Block, if already holding.
|
||||
st_update_plan_block_parameters(); // Notify stepper module to recompute for hold deceleration.
|
||||
sys.step_control = STEP_CONTROL_EXECUTE_HOLD; // Initiate suspend state with active flag.
|
||||
if (sys.state == STATE_JOG) { sys.suspend |= SUSPEND_JOG_CANCEL; } // Jog cancelled upon any hold event.
|
||||
if (sys.state == STATE_JOG) { // Jog cancelled upon any hold event, except for sleeping.
|
||||
if (!(rt_exec & EXEC_SLEEP)) { sys.suspend |= SUSPEND_JOG_CANCEL; }
|
||||
}
|
||||
}
|
||||
}
|
||||
// If IDLE, Grbl is not in motion. Simply indicate suspend state and hold is complete.
|
||||
if (sys.state == STATE_IDLE) {
|
||||
sys.suspend = SUSPEND_HOLD_COMPLETE;
|
||||
sys.step_control = STEP_CONTROL_END_MOTION;
|
||||
}
|
||||
if (sys.state == STATE_IDLE) { sys.suspend = SUSPEND_HOLD_COMPLETE; }
|
||||
|
||||
// Execute and flag a motion cancel with deceleration and return to idle. Used primarily by probing cycle
|
||||
// to halt and cancel the remainder of the motion.
|
||||
|
|
@ -283,9 +283,8 @@ void protocol_exec_rt_system()
|
|||
|
||||
// Execute a feed hold with deceleration, if required. Then, suspend system.
|
||||
if (rt_exec & EXEC_FEED_HOLD) {
|
||||
// Block SAFETY_DOOR state from prematurely changing back to HOLD, which should only
|
||||
// occur if the safety door switch closes.
|
||||
if (!(sys.state & (STATE_SAFETY_DOOR | STATE_JOG))) { sys.state = STATE_HOLD; }
|
||||
// Block SAFETY_DOOR, JOG, and SLEEP states from changing to HOLD state.
|
||||
if (!(sys.state & (STATE_SAFETY_DOOR | STATE_JOG | STATE_SLEEP))) { sys.state = STATE_HOLD; }
|
||||
}
|
||||
|
||||
// Execute a safety door stop with a feed hold and disable spindle/coolant.
|
||||
|
|
@ -296,8 +295,8 @@ void protocol_exec_rt_system()
|
|||
// If jogging, block safety door methods until jog cancel is complete. Just flag that it happened.
|
||||
if (!(sys.suspend & SUSPEND_JOG_CANCEL)) {
|
||||
// Check if the safety re-opened during a restore parking motion only. Ignore if
|
||||
// already retracting or parked.
|
||||
if (sys.suspend & SUSPEND_SAFETY_DOOR_AJAR) {
|
||||
// already retracting, parked or in sleep state.
|
||||
if (sys.state == STATE_SAFETY_DOOR) {
|
||||
if (sys.suspend & SUSPEND_INITIATE_RESTORE) { // Actively restoring
|
||||
#ifdef PARKING_ENABLE
|
||||
// Set hold and reset appropriate control flags to restart parking sequence.
|
||||
|
|
@ -311,16 +310,21 @@ void protocol_exec_rt_system()
|
|||
sys.suspend |= SUSPEND_RESTART_RETRACT;
|
||||
}
|
||||
}
|
||||
sys.state = STATE_SAFETY_DOOR;
|
||||
if (sys.state != STATE_SLEEP) { sys.state = STATE_SAFETY_DOOR; }
|
||||
}
|
||||
// NOTE: This flag doesn't change when the door closes, unlike sys.state. Ensures any parking motions
|
||||
// are executed if the door switch closes and the state returns to HOLD.
|
||||
sys.suspend |= SUSPEND_SAFETY_DOOR_AJAR;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
system_clear_exec_state_flag((EXEC_MOTION_CANCEL | EXEC_FEED_HOLD | EXEC_SAFETY_DOOR));
|
||||
if (rt_exec & EXEC_SLEEP) {
|
||||
if (sys.state == STATE_ALARM) { sys.suspend |= (SUSPEND_RETRACT_COMPLETE|SUSPEND_HOLD_COMPLETE); }
|
||||
sys.state = STATE_SLEEP;
|
||||
}
|
||||
|
||||
system_clear_exec_state_flag((EXEC_MOTION_CANCEL | EXEC_FEED_HOLD | EXEC_SAFETY_DOOR | EXEC_SLEEP));
|
||||
}
|
||||
|
||||
// Execute a cycle start by starting the stepper interrupt to begin executing the blocks in queue.
|
||||
|
|
@ -363,52 +367,13 @@ void protocol_exec_rt_system()
|
|||
system_clear_exec_state_flag(EXEC_CYCLE_START);
|
||||
}
|
||||
|
||||
// if (rt_exec & EXEC_CYCLE_START) {
|
||||
// // Block if called at same time as the hold commands: feed hold, motion cancel, and safety door.
|
||||
// // Ensures auto-cycle-start doesn't resume a hold without an explicit user-input.
|
||||
// if (!(rt_exec & (EXEC_FEED_HOLD | EXEC_MOTION_CANCEL | EXEC_SAFETY_DOOR))) {
|
||||
// // Cycle start only when IDLE or when a hold is complete and ready to resume.
|
||||
// // NOTE: SAFETY_DOOR is implicitly blocked. It reverts to HOLD when the door is closed.
|
||||
// if ((sys.state == STATE_IDLE) || ((sys.state & STATE_HOLD) && (sys.suspend & SUSPEND_HOLD_COMPLETE))) {
|
||||
// if (sys.suspend & SUSPEND_SAFETY_DOOR_AJAR) {
|
||||
// if (sys.suspend & SUSPEND_RETRACT_COMPLETE) {
|
||||
// if bit_isfalse(sys.suspend,SUSPEND_RESTORE_COMPLETE) {
|
||||
// // Flag to re-energize powered components and restore original position, if disabled by SAFETY_DOOR.
|
||||
// // NOTE: For a safety door to resume, the switch must be closed, as indicated by HOLD state, and
|
||||
// // the retraction execution is complete, which implies the initial feed hold is not active. To
|
||||
// // restore normal operation, the restore procedures must be initiated by the following flag. Once,
|
||||
// // they are complete, it will call CYCLE_START automatically to resume and exit the suspend.
|
||||
// sys.suspend |= SUSPEND_INITIATE_RESTORE;
|
||||
// } else {
|
||||
// bit_false(sys.suspend,SUSPEND_SAFETY_DOOR_AJAR);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (!(sys.suspend & SUSPEND_SAFETY_DOOR_AJAR)) {
|
||||
// // Start cycle only if queued motions exist in planner buffer and the motion is not canceled.
|
||||
// sys.step_control = STEP_CONTROL_NORMAL_OP; // Restore step control to normal operation
|
||||
// if (plan_get_current_block() && bit_isfalse(sys.suspend,SUSPEND_MOTION_CANCEL)) {
|
||||
// sys.suspend = SUSPEND_DISABLE; // Break suspend state.
|
||||
// sys.state = STATE_CYCLE;
|
||||
// st_prep_buffer(); // Initialize step segment buffer before beginning cycle.
|
||||
// st_wake_up();
|
||||
// } else { // Otherwise, do nothing. Set and resume IDLE state.
|
||||
// sys.suspend = SUSPEND_DISABLE; // Break suspend state.
|
||||
// sys.state = STATE_IDLE;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// system_clear_exec_state_flag(EXEC_CYCLE_START);
|
||||
// }
|
||||
|
||||
if (rt_exec & EXEC_CYCLE_STOP) {
|
||||
// Reinitializes the cycle plan and stepper system after a feed hold for a resume. Called by
|
||||
// realtime command execution in the main program, ensuring that the planner re-plans safely.
|
||||
// NOTE: Bresenham algorithm variables are still maintained through both the planner and stepper
|
||||
// cycle reinitializations. The stepper path should continue exactly as if nothing has happened.
|
||||
// NOTE: EXEC_CYCLE_STOP is set by the stepper subsystem when a cycle or feed hold completes.
|
||||
if ((sys.state & (STATE_HOLD | STATE_SAFETY_DOOR)) && !(sys.soft_limit) && !(sys.suspend & SUSPEND_JOG_CANCEL)) {
|
||||
if ((sys.state & (STATE_HOLD|STATE_SAFETY_DOOR|STATE_SLEEP)) && !(sys.soft_limit) && !(sys.suspend & SUSPEND_JOG_CANCEL)) {
|
||||
// Hold complete. Set to indicate ready to resume. Remain in HOLD or DOOR states until user
|
||||
// has issued a resume command or reset.
|
||||
plan_cycle_reinitialize();
|
||||
|
|
@ -480,6 +445,7 @@ void protocol_exec_rt_system()
|
|||
last_s_override = max(last_s_override,MIN_SPINDLE_SPEED_OVERRIDE);
|
||||
|
||||
if (last_s_override != sys.spindle_speed_ovr) {
|
||||
bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM);
|
||||
sys.spindle_speed_ovr = last_s_override;
|
||||
sys.report_ovr_counter = REPORT_OVR_REFRESH_BUSY_COUNT; // Set to report change immediately
|
||||
}
|
||||
|
|
@ -534,7 +500,7 @@ void protocol_exec_rt_system()
|
|||
#endif
|
||||
|
||||
// Reload step segment buffer
|
||||
if (sys.state & (STATE_CYCLE | STATE_HOLD | STATE_SAFETY_DOOR | STATE_HOMING | STATE_JOG)) {
|
||||
if (sys.state & (STATE_CYCLE | STATE_HOLD | STATE_SAFETY_DOOR | STATE_HOMING | STATE_SLEEP| STATE_JOG)) {
|
||||
st_prep_buffer();
|
||||
}
|
||||
|
||||
|
|
@ -586,9 +552,10 @@ static void protocol_exec_rt_suspend()
|
|||
// Block until initial hold is complete and the machine has stopped motion.
|
||||
if (sys.suspend & SUSPEND_HOLD_COMPLETE) {
|
||||
|
||||
// Safety door manager. Handles de/re-energizing, switch state checks, and parking motions.
|
||||
if (sys.suspend & SUSPEND_SAFETY_DOOR_AJAR) {
|
||||
|
||||
// Parking manager. Handles de/re-energizing, switch state checks, and parking motions for
|
||||
// the safety door and sleep states.
|
||||
if (sys.state & (STATE_SAFETY_DOOR | STATE_SLEEP)) {
|
||||
|
||||
// Handles retraction motions and de-energizing.
|
||||
if (bit_isfalse(sys.suspend,SUSPEND_RETRACT_COMPLETE)) {
|
||||
|
||||
|
|
@ -610,11 +577,12 @@ static void protocol_exec_rt_suspend()
|
|||
retract_waypoint = min(retract_waypoint,PARKING_TARGET);
|
||||
}
|
||||
|
||||
// Execute slow pull-out parking retract motion. Parking requires homing enabled and
|
||||
// the current location not exceeding the parking target location.
|
||||
// Execute slow pull-out parking retract motion. Parking requires homing enabled, the
|
||||
// current location not exceeding the parking target location, and laser mode disabled.
|
||||
// NOTE: State is will remain DOOR, until the de-energizing and retract is complete.
|
||||
if ((bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) &&
|
||||
(parking_target[PARKING_AXIS] < PARKING_TARGET)) {
|
||||
(parking_target[PARKING_AXIS] < PARKING_TARGET) &&
|
||||
bit_isfalse(settings.flags,BITFLAG_LASER_MODE)) {
|
||||
|
||||
// Retract spindle by pullout distance. Ensure retraction motion moves away from
|
||||
// the workpiece and waypoint motion doesn't exceed the parking target location.
|
||||
|
|
@ -637,6 +605,7 @@ static void protocol_exec_rt_suspend()
|
|||
} else {
|
||||
|
||||
// Parking motion not possible. Just disable the spindle and coolant.
|
||||
// NOTE: Laser mode does not start a parking motion to ensure the laser stops immediately.
|
||||
spindle_stop(); // De-energize
|
||||
coolant_set_state(COOLANT_DISABLE); // De-energize
|
||||
|
||||
|
|
@ -649,8 +618,18 @@ static void protocol_exec_rt_suspend()
|
|||
|
||||
} else {
|
||||
|
||||
|
||||
if (sys.state == STATE_SLEEP) {
|
||||
report_feedback_message(MESSAGE_SLEEP_MODE);
|
||||
// Spindle and coolant should already be stopped, but do it again just to be sure.
|
||||
spindle_stop(); // De-energize
|
||||
coolant_set_state(COOLANT_DISABLE); // De-energize
|
||||
st_go_idle(); // Disable steppers
|
||||
while (!(sys.abort)) { protocol_exec_rt_system(); } // Do nothing until reset.
|
||||
return; // Abort received. Return to re-initialize.
|
||||
}
|
||||
|
||||
// Allows resuming from parking/safety door. Actively checks if safety door is closed and ready to resume.
|
||||
// NOTE: This unlocks the SAFETY_DOOR state to a HOLD state, such that CYCLE_START can activate a resume.
|
||||
if (sys.state == STATE_SAFETY_DOOR) {
|
||||
if (!(system_check_safety_door_ajar())) {
|
||||
sys.suspend &= ~(SUSPEND_SAFETY_DOOR_AJAR); // Reset door ajar flag to denote ready to resume.
|
||||
|
|
@ -663,7 +642,7 @@ static void protocol_exec_rt_suspend()
|
|||
#ifdef PARKING_ENABLE
|
||||
// Execute fast restore motion to the pull-out position. Parking requires homing enabled.
|
||||
// NOTE: State is will remain DOOR, until the de-energizing and retract is complete.
|
||||
if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) {
|
||||
if ((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) {
|
||||
// Check to ensure the motion doesn't move below pull-out position.
|
||||
if (parking_target[PARKING_AXIS] <= PARKING_TARGET) {
|
||||
parking_target[PARKING_AXIS] = retract_waypoint;
|
||||
|
|
@ -677,13 +656,19 @@ static void protocol_exec_rt_suspend()
|
|||
if (gc_state.modal.spindle != SPINDLE_DISABLE) {
|
||||
// Block if safety door re-opened during prior restore actions.
|
||||
if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) {
|
||||
spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)), restore_spindle_speed);
|
||||
delay_sec(SAFETY_DOOR_SPINDLE_DELAY, DELAY_MODE_SYS_SUSPEND);
|
||||
if (bit_istrue(settings.flags,BITFLAG_LASER_MODE)) {
|
||||
// When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts.
|
||||
bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM);
|
||||
} else {
|
||||
spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)), restore_spindle_speed);
|
||||
delay_sec(SAFETY_DOOR_SPINDLE_DELAY, DELAY_MODE_SYS_SUSPEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gc_state.modal.coolant != COOLANT_DISABLE) {
|
||||
// Block if safety door re-opened during prior restore actions.
|
||||
if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) {
|
||||
// NOTE: Laser mode will honor this delay. An exhaust system is often controlled by this pin.
|
||||
coolant_set_state((restore_condition & (PL_COND_FLAG_COOLANT_FLOOD | PL_COND_FLAG_COOLANT_FLOOD)));
|
||||
delay_sec(SAFETY_DOOR_COOLANT_DELAY, DELAY_MODE_SYS_SUSPEND);
|
||||
}
|
||||
|
|
@ -691,14 +676,14 @@ static void protocol_exec_rt_suspend()
|
|||
|
||||
#ifdef PARKING_ENABLE
|
||||
// Execute slow plunge motion from pull-out position to resume position.
|
||||
if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) {
|
||||
if ((settings.flags & (BITFLAG_HOMING_ENABLE|BITFLAG_LASER_MODE)) == BITFLAG_HOMING_ENABLE) {
|
||||
// Block if safety door re-opened during prior restore actions.
|
||||
if (bit_isfalse(sys.suspend,SUSPEND_RESTART_RETRACT)) {
|
||||
// Regardless if the retract parking motion was a valid/safe motion or not, the
|
||||
// restore parking motion should logically be valid, either by returning to the
|
||||
// original position through valid machine space or by not moving at all.
|
||||
pl_data->feed_rate = PARKING_PULLOUT_RATE;
|
||||
mc_parking_motion(parking_target, pl_data);
|
||||
mc_parking_motion(restore_target, pl_data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -728,8 +713,13 @@ static void protocol_exec_rt_suspend()
|
|||
|
||||
if (gc_state.modal.spindle != SPINDLE_DISABLE) {
|
||||
report_feedback_message(MESSAGE_SPINDLE_RESTORE);
|
||||
spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)), restore_spindle_speed);
|
||||
delay_sec(SAFETY_DOOR_SPINDLE_DELAY, DELAY_MODE_SYS_SUSPEND);
|
||||
if (bit_istrue(settings.flags,BITFLAG_LASER_MODE)) {
|
||||
// When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts.
|
||||
bit_true(sys.step_control, STEP_CONTROL_UPDATE_SPINDLE_PWM);
|
||||
} else {
|
||||
spindle_set_state((restore_condition & (PL_COND_FLAG_SPINDLE_CW | PL_COND_FLAG_SPINDLE_CCW)), restore_spindle_speed);
|
||||
delay_sec(SAFETY_DOOR_SPINDLE_DELAY, DELAY_MODE_SYS_SUSPEND);
|
||||
}
|
||||
}
|
||||
if (sys.toggle_ovr_mask & TOGGLE_OVR_STOP_RESTORE_CYCLE) {
|
||||
system_set_exec_state_flag(EXEC_CYCLE_START); // Set to resume program.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue