diff --git a/Grbl_Esp32/src/Config.h b/Grbl_Esp32/src/Config.h index 2feece69..f53ca288 100644 --- a/Grbl_Esp32/src/Config.h +++ b/Grbl_Esp32/src/Config.h @@ -258,11 +258,6 @@ static const uint8_t NHomingLocateCycle = 1; // Integer (1-128) // previous tool path, as if nothing happened. #define ENABLE_SAFETY_DOOR_INPUT_PIN // ESP32 Leave this enabled for now .. code for undefined not ready -// After the safety door switch has been toggled and restored, this setting sets the power-up delay -// between restoring the spindle and coolant and resuming the cycle. -const double SAFETY_DOOR_SPINDLE_DELAY = 4.0; // Float (seconds) -const double SAFETY_DOOR_COOLANT_DELAY = 1.0; // Float (seconds) - // Inverts select limit pin states based on the following mask. This effects all limit pin functions, // such as hard limits and homing. However, this is different from overall invert limits setting. // This build option will invert only the limit pins defined here, and then the invert limits setting @@ -582,8 +577,8 @@ const int DEBOUNCE_PERIOD = 32; // in milliseconds default 32 microseconds // Configure options for the parking motion, if enabled. #define PARKING_AXIS Z_AXIS // Define which axis that performs the parking motion const double PARKING_TARGET = -5.0; // Parking axis target. In mm, as machine coordinate. -const double PARKING_RATE = 500.0; // Parking fast rate after pull-out in mm/min. -const double PARKING_PULLOUT_RATE = 100.0; // Pull-out/plunge slow feed rate in mm/min. +const double PARKING_RATE = 800.0; // Parking fast rate after pull-out in mm/min. +const double PARKING_PULLOUT_RATE = 250.0; // Pull-out/plunge slow feed rate in mm/min. const double PARKING_PULLOUT_INCREMENT = 5.0; // Spindle pull-out and plunge distance in mm. Incremental distance. // Must be positive value or equal to zero. diff --git a/Grbl_Esp32/src/Defaults.h b/Grbl_Esp32/src/Defaults.h index 41776f56..b31197de 100644 --- a/Grbl_Esp32/src/Defaults.h +++ b/Grbl_Esp32/src/Defaults.h @@ -187,6 +187,10 @@ # define DEFAULT_SPINDLE_DELAY_SPINUP 0 #endif +#ifndef DEFAULT_COOLANT_DELAY_TURNON +# define DEFAULT_COOLANT_DELAY_TURNON 1.0 +#endif + #ifndef DEFAULT_SPINDLE_DELAY_SPINDOWN # define DEFAULT_SPINDLE_DELAY_SPINDOWN 0 #endif diff --git a/Grbl_Esp32/src/Grbl.h b/Grbl_Esp32/src/Grbl.h index 0d35d07c..82a85a84 100644 --- a/Grbl_Esp32/src/Grbl.h +++ b/Grbl_Esp32/src/Grbl.h @@ -23,7 +23,7 @@ // Grbl versioning system const char* const GRBL_VERSION = "1.3a"; -const char* const GRBL_VERSION_BUILD = "20210204"; +const char* const GRBL_VERSION_BUILD = "20210213"; //#include #include diff --git a/Grbl_Esp32/src/MotionControl.cpp b/Grbl_Esp32/src/MotionControl.cpp index 3387ef23..aa02fec1 100644 --- a/Grbl_Esp32/src/MotionControl.cpp +++ b/Grbl_Esp32/src/MotionControl.cpp @@ -225,11 +225,11 @@ void mc_arc(float* target, // Execute dwell in seconds. void mc_dwell(float seconds) { - if (sys.state == State::CheckMode) { + if (seconds == 0 || sys.state == State::CheckMode) { return; } protocol_buffer_synchronize(); - delay_sec(seconds, DELAY_MODE_DWELL); + delay_sec(seconds, DwellMode::Dwell); } // return true if the mask has exactly one bit set, diff --git a/Grbl_Esp32/src/NutsBolts.cpp b/Grbl_Esp32/src/NutsBolts.cpp index 036be861..51245465 100644 --- a/Grbl_Esp32/src/NutsBolts.cpp +++ b/Grbl_Esp32/src/NutsBolts.cpp @@ -112,15 +112,15 @@ void delay_ms(uint16_t ms) { } // Non-blocking delay function used for general operation and suspend features. -void delay_sec(float seconds, uint8_t mode) { +void delay_sec(float seconds, DwellMode mode) { uint16_t i = ceil(1000 / DWELL_TIME_STEP * seconds); while (i-- > 0) { if (sys.abort) { return; } - if (mode == DELAY_MODE_DWELL) { + if (mode == DwellMode::Dwell) { protocol_execute_realtime(); - } else { // DELAY_MODE_SYS_SUSPEND + } else { // DwellMode::SysSuspend // Execute rt_system() only to avoid nesting suspend loops. protocol_exec_rt_system(); if (sys.suspend.bit.restartRetract) { diff --git a/Grbl_Esp32/src/NutsBolts.h b/Grbl_Esp32/src/NutsBolts.h index d133638f..15705065 100644 --- a/Grbl_Esp32/src/NutsBolts.h +++ b/Grbl_Esp32/src/NutsBolts.h @@ -25,6 +25,11 @@ // #define false 0 // #define true 1 +enum class DwellMode : uint8_t { + Dwell = 0, // (Default: Must be zero) + SysSuspend = 1, //G92.1 (Do not alter value) +}; + const double SOME_LARGE_VALUE = 1.0E+38; // Axis array index values. Must start with 0 and be continuous. @@ -57,8 +62,6 @@ static inline int toMotor2(int axis) { const double MM_PER_INCH = (25.40); const double INCH_PER_MM = (0.0393701); -const int DELAY_MODE_DWELL = 0; -const int DELAY_MODE_SYS_SUSPEND = 1; // Useful macros #define clear_vector(a) memset(a, 0, sizeof(a)) @@ -87,7 +90,7 @@ const int DELAY_MODE_SYS_SUSPEND = 1; uint8_t read_float(const char* line, uint8_t* char_counter, float* float_ptr); // Non-blocking delay function used for general operation and suspend features. -void delay_sec(float seconds, uint8_t mode); +void delay_sec(float seconds, DwellMode mode); // Delays variable-defined milliseconds. Compiler compatibility fix for _delay_ms(). void delay_ms(uint16_t ms); diff --git a/Grbl_Esp32/src/Protocol.cpp b/Grbl_Esp32/src/Protocol.cpp index bfda25f5..126015e8 100644 --- a/Grbl_Esp32/src/Protocol.cpp +++ b/Grbl_Esp32/src/Protocol.cpp @@ -664,9 +664,10 @@ static void protocol_exec_rt_suspend() { if (spindle->inLaserMode()) { // When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts. sys.step_control.updateSpindleRpm = true; - } else { + } else { spindle->set_state(restore_spindle, (uint32_t)restore_spindle_speed); - delay_sec(SAFETY_DOOR_SPINDLE_DELAY, DELAY_MODE_SYS_SUSPEND); + // restore delay is done in the spindle class + //delay_sec(spindle_delay_spinup->get(), DwellMode::SysSuspend); } } } @@ -675,7 +676,7 @@ static void protocol_exec_rt_suspend() { if (!sys.suspend.bit.restartRetract) { // NOTE: Laser mode will honor this delay. An exhaust system is often controlled by this pin. coolant_set_state(restore_coolant); - delay_sec(SAFETY_DOOR_COOLANT_DELAY, DELAY_MODE_SYS_SUSPEND); + delay_sec(coolant_start_delay->get(), DwellMode::SysSuspend); } } #ifdef PARKING_ENABLE diff --git a/Grbl_Esp32/src/SettingsDefinitions.cpp b/Grbl_Esp32/src/SettingsDefinitions.cpp index bde5e97f..1808e94f 100644 --- a/Grbl_Esp32/src/SettingsDefinitions.cpp +++ b/Grbl_Esp32/src/SettingsDefinitions.cpp @@ -46,6 +46,7 @@ FloatSetting* rpm_max; FloatSetting* rpm_min; FloatSetting* spindle_delay_spinup; FloatSetting* spindle_delay_spindown; +FloatSetting* coolant_start_delay; FlagSetting* spindle_enbl_off_with_zero_speed; FlagSetting* spindle_enable_invert; FlagSetting* spindle_output_invert; @@ -345,8 +346,12 @@ void make_settings() { spindle_pwm_freq = new FloatSetting(EXTENDED, WG, "33", "Spindle/PWM/Frequency", DEFAULT_SPINDLE_FREQ, 0, 100000, checkSpindleChange); spindle_output_invert = new FlagSetting(GRBL, WG, NULL, "Spindle/PWM/Invert", DEFAULT_INVERT_SPINDLE_OUTPUT_PIN, checkSpindleChange); - spindle_delay_spinup = new FloatSetting(EXTENDED, WG, NULL, "Spindle/Delay/SpinUp", DEFAULT_SPINDLE_DELAY_SPINUP, 0, 30); - spindle_delay_spindown = new FloatSetting(EXTENDED, WG, NULL, "Spindle/Delay/SpinDown", DEFAULT_SPINDLE_DELAY_SPINUP, 0, 30); + spindle_delay_spinup = + new FloatSetting(EXTENDED, WG, NULL, "Spindle/Delay/SpinUp", DEFAULT_SPINDLE_DELAY_SPINUP, 0, 30, checkSpindleChange); + spindle_delay_spindown = + new FloatSetting(EXTENDED, WG, NULL, "Spindle/Delay/SpinDown", DEFAULT_SPINDLE_DELAY_SPINUP, 0, 30, checkSpindleChange); + coolant_start_delay = + new FloatSetting(EXTENDED, WG, NULL, "Coolant/Delay/TurnOn", DEFAULT_COOLANT_DELAY_TURNON, 0, 30); spindle_enbl_off_with_zero_speed = new FlagSetting(GRBL, WG, NULL, "Spindle/Enable/OffWithSpeed", DEFAULT_SPINDLE_ENABLE_OFF_WITH_ZERO_SPEED, checkSpindleChange); diff --git a/Grbl_Esp32/src/SettingsDefinitions.h b/Grbl_Esp32/src/SettingsDefinitions.h index 95c229e9..0fe91de1 100644 --- a/Grbl_Esp32/src/SettingsDefinitions.h +++ b/Grbl_Esp32/src/SettingsDefinitions.h @@ -48,6 +48,7 @@ extern FloatSetting* rpm_max; extern FloatSetting* rpm_min; extern FloatSetting* spindle_delay_spinup; extern FloatSetting* spindle_delay_spindown; +extern FloatSetting* coolant_start_delay; extern FlagSetting* spindle_enbl_off_with_zero_speed; extern FlagSetting* spindle_enable_invert; extern FlagSetting* spindle_output_invert; diff --git a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp index ba364768..402af6e4 100644 --- a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp @@ -114,6 +114,9 @@ namespace Spindles { // _pwm_gradient = (_pwm_max_value - _pwm_min_value) / (_max_rpm - _min_rpm); _pwm_chan_num = 0; // Channel 0 is reserved for spindle use + + _spinup_delay = spindle_delay_spinup->get() * 1000.0; + _spindown_delay = spindle_delay_spindown->get() * 1000.0; } uint32_t PWM::set_rpm(uint32_t rpm) { @@ -163,14 +166,14 @@ namespace Spindles { sys.spindle_speed = 0; stop(); if (use_delays && (_current_state != state)) { - mc_dwell(spindle_delay_spindown->get()); + delay(_spinup_delay); } } else { set_dir_pin(state == SpindleState::Cw); set_rpm(rpm); set_enable_pin(state != SpindleState::Disable); // must be done after setting rpm for enable features to work if (use_delays && (_current_state != state)) { - mc_dwell(spindle_delay_spinup->get()); + delay(_spindown_delay); } } diff --git a/Grbl_Esp32/src/Spindles/Spindle.h b/Grbl_Esp32/src/Spindles/Spindle.h index 6851544a..2f507767 100644 --- a/Grbl_Esp32/src/Spindles/Spindle.h +++ b/Grbl_Esp32/src/Spindles/Spindle.h @@ -73,6 +73,8 @@ namespace Spindles { bool is_reversable; bool use_delays; // will SpinUp and SpinDown delays be used. volatile SpindleState _current_state = SpindleState::Disable; + uint32_t _spinup_delay; + uint32_t _spindown_delay; static void select(); }; diff --git a/Grbl_Esp32/src/Spindles/VFDSpindle.cpp b/Grbl_Esp32/src/Spindles/VFDSpindle.cpp index 512e243a..76e30c80 100644 --- a/Grbl_Esp32/src/Spindles/VFDSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/VFDSpindle.cpp @@ -326,6 +326,9 @@ namespace Spindles { _min_rpm = rpm_min->get(); _max_rpm = rpm_max->get(); + _spinup_delay = spindle_delay_spinup->get() * 1000.0; + _spindown_delay = spindle_delay_spindown->get() * 1000.0; + return pins_settings_ok; } @@ -348,16 +351,18 @@ namespace Spindles { if (_current_state != state) { // already at the desired state. This function gets called a lot. set_mode(state, critical); // critical if we are in a job set_rpm(rpm); + + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Spin1"); + if (state == SpindleState::Disable) { sys.spindle_speed = 0; - if (_current_state != state) { - mc_dwell(spindle_delay_spindown->get()); - } + delay(_spindown_delay); + } else { - if (_current_state != state) { - mc_dwell(spindle_delay_spinup->get()); - } + delay(_spinup_delay); } + + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Spin2"); } else { if (_current_rpm != rpm) { set_rpm(rpm);