Skip to content

Commit

Permalink
Fix for issue #264, stepper motors not disabled when entering sleep m…
Browse files Browse the repository at this point in the history
…ode.

Fix for recent regression that disabled G7/G8 handling in lathe mode.
  • Loading branch information
terjeio committed Mar 11, 2023
1 parent c7a6f04 commit 71aa2a4
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ It has been written to complement grblHAL and has features such as proper keyboa

---

Latest build date is 20230302, see the [changelog](changelog.md) for details.
Latest build date is 20230311, see the [changelog](changelog.md) for details.
__NOTE:__ A settings reset will be performed on an update of builds earlier than 20230125. Backup and restore of settings is recommended.
__IMPORTANT!__ A new setting has been introduced for ganged axes motors in build 20211121.
I have only bench tested this for a couple of drivers, correct function should be verified after updating by those who have more than three motors configured.
Expand Down
15 changes: 13 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
## grblHAL changelog

<a name="2023032"/>20230302
<a name="20230311"/>20230311

Core:

* Fix for isisue #264, stepper motors not disabled when entering sleep mode.
__NOTE:__ all stepper motors will now be disabled even if the $37 setting is set to keep some enabled.

* Fix for recent regression that disabled G7/G8 handling in lathe mode.

---

<a name="20230302"/>20230302

Core:

Expand All @@ -16,7 +27,7 @@ Drivers:

Plugins:

* Keypad: Type fix for homed status field.
* Keypad: I2C display protocol plugin, type fix for homed status field.

---

Expand Down
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
For the most part, users will not need to directly modify these, but they are here for
specific needs, i.e. performance tuning or adjusting to non-typical machines.
<br>__IMPORTANT:__ Symbol/macro names starting with `DEFAULT_` contains default values for run-time
configuarble settings that can be changed with `$=<setting id>` commands.
configurable settings that can be changed with `$=<setting id>` commands.
Any changes to these requires a full re-compiling of the source code to propagate them.
A reset of non-volatile storage with `$RST=*` after reflashing is also required.
*/
Expand Down
2 changes: 1 addition & 1 deletion gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ status_code_t gc_execute_block (char *block)
gc_block.values.xyz[idx] *= MM_PER_INCH;
} while(idx);

if (command_words.G1 && gc_state.modal.diameter_mode != gc_block.modal.diameter_mode) {
if (command_words.G15 && gc_state.modal.diameter_mode != gc_block.modal.diameter_mode) {
gc_state.modal.diameter_mode = gc_block.modal.diameter_mode;
system_add_rt_report(Report_LatheXMode);
}
Expand Down
2 changes: 1 addition & 1 deletion grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#else
#define GRBL_VERSION "1.1f"
#endif
#define GRBL_BUILD 20230302
#define GRBL_BUILD 20230311

#define GRBL_URL "https://github.com/grblHAL"

Expand Down
1 change: 0 additions & 1 deletion sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ static void sleep_execute()
// If reached, sleep counter has expired. Execute sleep procedures.
// Notify user that Grbl has timed out and will be parking.
// To exit sleep, resume or reset. Either way, the job will not be recoverable.
grbl.report.feedback_message(Message_SleepMode);
system_set_exec_state_flag(EXEC_SLEEP);
}

Expand Down
23 changes: 19 additions & 4 deletions state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,16 @@ static void state_restore_conditions (restore_condition_t *condition)
}
}

bool initiate_hold (uint_fast16_t new_state)
static void enter_sleep (void)
{
st_go_idle();
spindle_all_off();
hal.coolant.set_state((coolant_state_t){0});
grbl.report.feedback_message(Message_SleepMode);
stateHandler = state_noop;
}

static bool initiate_hold (uint_fast16_t new_state)
{
spindle_ptrs_t *spindle;
spindle_num_t spindle_num = N_SYS_SPINDLE;
Expand Down Expand Up @@ -304,6 +313,8 @@ void state_set (sys_state_t new_state)
}
} else
sys_state = new_state;
if(sys_state == STATE_SLEEP && stateHandler != state_await_waypoint_retract)
enter_sleep();
break;

case STATE_ALARM:
Expand Down Expand Up @@ -532,13 +543,13 @@ static void state_await_hold (uint_fast16_t rt_exec)
// 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_all_off(); // De-energize
if (!settings.safety_door.flags.keep_coolant_on)
hal.coolant.set_state((coolant_state_t){0}); // De-energize
if (!settings.safety_door.flags.keep_coolant_on || sys_state == STATE_SLEEP)
hal.coolant.set_state((coolant_state_t){0}); // De-energize
sys.parking_state = hal.control.get_state().safety_door_ajar ? Parking_DoorAjar : Parking_DoorClosed;
}
} else {
spindle_all_off(); // De-energize
if (!settings.safety_door.flags.keep_coolant_on)
if (!settings.safety_door.flags.keep_coolant_on || sys_state == STATE_SLEEP)
hal.coolant.set_state((coolant_state_t){0}); // De-energize
sys.parking_state = hal.control.get_state().safety_door_ajar ? Parking_DoorAjar : Parking_DoorClosed;
}
Expand All @@ -565,6 +576,10 @@ static void state_await_resume (uint_fast16_t rt_exec)
st_parking_restore_buffer(); // Restore step segment buffer to normal run state.
}
sys.parking_state = hal.control.get_state().safety_door_ajar ? Parking_DoorAjar : Parking_DoorClosed;
if(sys_state == STATE_SLEEP) {
enter_sleep();
return;
}
}

if (rt_exec & EXEC_SLEEP)
Expand Down
13 changes: 8 additions & 5 deletions stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ void st_deenergize (void)
}
}


// Stepper state initialization. Cycle should only start if the st.cycle_start flag is
// enabled. Startup init and limits call this function but shouldn't start the cycle.
void st_wake_up (void)
Expand Down Expand Up @@ -230,10 +229,14 @@ ISR_CODE void ISR_FUNC(st_go_idle)(void)

// Set stepper driver idle state, disabled or enabled, depending on settings and circumstances.
if (((settings.steppers.idle_lock_time != 255) || sys.rt_exec_alarm || state == STATE_SLEEP) && state != STATE_HOMING) {
// Force stepper dwell to lock axes for a defined amount of time to ensure the axes come to a complete
// stop and not drift from residual inertial forces at the end of the last movement.
sys.steppers_deenergize = true;
hal.delay_ms(settings.steppers.idle_lock_time, st_deenergize);
if(state == STATE_SLEEP)
hal.stepper.enable((axes_signals_t){0});
else {
// Force stepper dwell to lock axes for a defined amount of time to ensure the axes come to a complete
// stop and not drift from residual inertial forces at the end of the last movement.
sys.steppers_deenergize = true;
hal.delay_ms(settings.steppers.idle_lock_time, st_deenergize);
}
} else
hal.stepper.enable(settings.steppers.idle_lock_time == 255 ? (axes_signals_t){AXES_BITMASK} : settings.steppers.deenergize);
}
Expand Down

0 comments on commit 71aa2a4

Please sign in to comment.