1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-29 09:10:03 +02:00

Parking delay fix (#770)

* Changed delay type

- mc_dwell was causing a recursive loop the overflowed the stack
- See https://discord.com/channels/780079161460916227/786061602754396160/809288050387189782

* Changed spindle delays from floats to ints in spindle classes

- Used local copies, because I did not want to change/break the existing setting.

* Cleaning up parking

- Added a coolant delay setting
- Made an enum class for the dwell types
- Got rid of the safety door sepcific delays

* Update Grbl.h
This commit is contained in:
bdring
2021-02-13 18:22:09 -06:00
committed by GitHub
parent 447d1739f3
commit 04304141c5
12 changed files with 48 additions and 29 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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 <sdkconfig.h>
#include <Arduino.h>

View File

@@ -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,

View File

@@ -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) {

View File

@@ -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);

View File

@@ -666,7 +666,8 @@ static void protocol_exec_rt_suspend() {
sys.step_control.updateSpindleRpm = true;
} 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

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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();
};

View File

@@ -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);