Skip to content
Permalink
Browse files

Stop spindle on HALT

When a machine enters a `HALT` state for any reason, the spindle should
stop for safety along with everything else.  This commit changes the
default behavior to `turn_off` the spindle `on_halt`.  I added an
optional `spindle.ignore_on_halt` config parameter that defaults to
`false` in case anyone needs the previous less-safe behavior.

I believe this addresses #1069.

I confirmed functionality on `PWMSpindleControl` via `M957` as well as a
physical scope while causing `HALT` via `M112` or `^X` over the serial
interface.

I found some weirdness in `AnalogSpindleControl` around `report_speed`,
but I'll address that in another PR.  I did confirm that `turn_off` is
being called `on_halt` as it should be and the PWM duty cycle is reduced
to 0 even though `M957` (`report_speed`) continues to report that the
spindle is moving.

Without having the equipment for the other side of the RS485 connection,
I can't do much to test `ModbusSpindleContol`, but
`HuanyangSpindleControl`, the only supported Modbus VFD right now,
implements `turn_off`, so I don't see any reason it shouldn't work fine
with this change.
  • Loading branch information...
cilynx committed Nov 19, 2017
1 parent f6e0e44 commit 92dc23fbcbdcdb6c4bf69a372b0083ac30b49816
@@ -21,6 +21,7 @@
#define spindle_pwm_pin_checksum CHECKSUM("pwm_pin")
#define spindle_pwm_period_checksum CHECKSUM("pwm_period")
#define spindle_switch_on_pin_checksum CHECKSUM("switch_on_pin")
#define spindle_ignore_on_halt_checksum CHECKSUM("ignore_on_halt")

void AnalogSpindleControl::on_module_loaded()
{
@@ -61,6 +62,9 @@ void AnalogSpindleControl::on_module_loaded()
}
// register for events
register_for_event(ON_GCODE_RECEIVED);
if (!THEKERNEL->config->value(spindle_checksum, spindle_ignore_on_halt_checksum)->by_default(false)->as_bool()) {
register_for_event(ON_HALT);
}
}

void AnalogSpindleControl::turn_on()
@@ -19,6 +19,7 @@
#define spindle_rx_pin_checksum CHECKSUM("rx_pin")
#define spindle_tx_pin_checksum CHECKSUM("tx_pin")
#define spindle_dir_pin_checksum CHECKSUM("dir_pin")
#define spindle_ignore_on_halt_checksum CHECKSUM("ignore_on_halt")

void ModbusSpindleControl::on_module_loaded()
{
@@ -51,5 +52,8 @@ void ModbusSpindleControl::on_module_loaded()

// register for events
register_for_event(ON_GCODE_RECEIVED);
if (!THEKERNEL->config->value(spindle_checksum, spindle_ignore_on_halt_checksum)->by_default(false)->as_bool()) {
register_for_event(ON_HALT);
}
}

@@ -35,6 +35,7 @@
#define spindle_control_I_checksum CHECKSUM("control_I")
#define spindle_control_D_checksum CHECKSUM("control_D")
#define spindle_control_smoothing_checksum CHECKSUM("control_smoothing")
#define spindle_ignore_on_halt_checksum CHECKSUM("ignore_on_halt")

#define UPDATE_FREQ 1000

@@ -108,7 +109,11 @@ void PWMSpindleControl::on_module_loaded()

THEKERNEL->slow_ticker->attach(UPDATE_FREQ, this, &PWMSpindleControl::on_update_speed);

// register for events
register_for_event(ON_GCODE_RECEIVED);
if (!THEKERNEL->config->value(spindle_checksum, spindle_ignore_on_halt_checksum)->by_default(false)->as_bool()) {
register_for_event(ON_HALT);
}
}

void PWMSpindleControl::on_pin_rise()
@@ -63,3 +63,11 @@ void SpindleControl::on_gcode_received(void *argument)

}

void SpindleControl::on_halt(void *argument)
{
if (argument == nullptr) {
if(spindle_on) {
turn_off();
}
}
}
@@ -21,6 +21,7 @@ class SpindleControl: public Module {

private:
void on_gcode_received(void *argument);
void on_halt(void *argument);

virtual void turn_on(void) {};
virtual void turn_off(void) {};

0 comments on commit 92dc23f

Please sign in to comment.
You can’t perform that action at this time.