mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-29 01:00:00 +02:00
Enable per motor fix (#771)
* - moved invert option in front of per motor enables. * Added code to prevent motors_set_disable() from setting values that already exist. * Added the enable delay from PR 720 * Adding a defined default for step enable delay * Fixing feed rates with kinematics and arcs. - Kinematics changes the feed rate and the loop that creates arc was re-using the altered rate. This caused a runaway situation.
This commit is contained in:
@@ -42,6 +42,10 @@
|
|||||||
# define DEFAULT_STEP_PULSE_MICROSECONDS 3 // $0
|
# define DEFAULT_STEP_PULSE_MICROSECONDS 3 // $0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DEFAULT_STEP_ENABLE_DELAY
|
||||||
|
# define DEFAULT_STEP_ENABLE_DELAY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef DEFAULT_STEPPER_IDLE_LOCK_TIME
|
#ifndef DEFAULT_STEPPER_IDLE_LOCK_TIME
|
||||||
# define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // $1 msec (0-254, 255 keeps steppers enabled)
|
# define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // $1 msec (0-254, 255 keeps steppers enabled)
|
||||||
#endif
|
#endif
|
||||||
|
@@ -184,8 +184,9 @@ void mc_arc(float* target,
|
|||||||
float cos_Ti;
|
float cos_Ti;
|
||||||
float r_axisi;
|
float r_axisi;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
for (i = 1; i < segments; i++) { // Increment (segments-1).
|
float original_feedrate = pl_data->feed_rate; // Kinematics may alter the feedrate, so save an original copy
|
||||||
|
for (i = 1; i < segments; i++) { // Increment (segments-1).
|
||||||
if (count < N_ARC_CORRECTION) {
|
if (count < N_ARC_CORRECTION) {
|
||||||
// Apply vector rotation matrix. ~40 usec
|
// Apply vector rotation matrix. ~40 usec
|
||||||
r_axisi = r_axis0 * sin_T + r_axis1 * cos_T;
|
r_axisi = r_axis0 * sin_T + r_axis1 * cos_T;
|
||||||
@@ -206,6 +207,7 @@ void mc_arc(float* target,
|
|||||||
position[axis_1] = center_axis1 + r_axis1;
|
position[axis_1] = center_axis1 + r_axis1;
|
||||||
position[axis_linear] += linear_per_segment;
|
position[axis_linear] += linear_per_segment;
|
||||||
#ifdef USE_KINEMATICS
|
#ifdef USE_KINEMATICS
|
||||||
|
pl_data->feed_rate = original_feedrate; // This restores the feedrate kinematics may have altered
|
||||||
mc_line_kins(position, pl_data, previous_position);
|
mc_line_kins(position, pl_data, previous_position);
|
||||||
previous_position[axis_0] = position[axis_0];
|
previous_position[axis_0] = position[axis_0];
|
||||||
previous_position[axis_1] = position[axis_1];
|
previous_position[axis_1] = position[axis_1];
|
||||||
|
@@ -413,7 +413,19 @@ void init_motors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void motors_set_disable(bool disable, uint8_t mask) {
|
void motors_set_disable(bool disable, uint8_t mask) {
|
||||||
static bool previous_state = true;
|
static bool prev_disable = true;
|
||||||
|
static uint8_t prev_mask = 0;
|
||||||
|
|
||||||
|
if ((disable == prev_disable) && (mask == prev_mask)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev_disable = disable;
|
||||||
|
prev_mask = mask;
|
||||||
|
|
||||||
|
if (step_enable_invert->get()) {
|
||||||
|
disable = !disable; // Apply pin invert.
|
||||||
|
}
|
||||||
|
|
||||||
// now loop through all the motors to see if they can individually disable
|
// now loop through all the motors to see if they can individually disable
|
||||||
auto n_axis = number_axis->get();
|
auto n_axis = number_axis->get();
|
||||||
@@ -425,11 +437,19 @@ void motors_set_disable(bool disable, uint8_t mask) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// invert only inverts the global stepper disable pin.
|
// global disable.
|
||||||
if (step_enable_invert->get()) {
|
|
||||||
disable = !disable; // Apply pin invert.
|
|
||||||
}
|
|
||||||
digitalWrite(STEPPERS_DISABLE_PIN, disable);
|
digitalWrite(STEPPERS_DISABLE_PIN, disable);
|
||||||
|
|
||||||
|
// Add an optional delay for stepper drivers. that need time
|
||||||
|
// Some need time after the enable before they can step.
|
||||||
|
auto wait_disable_change = enable_delay_microseconds->get();
|
||||||
|
if (wait_disable_change != 0) {
|
||||||
|
auto disable_start_time = esp_timer_get_time() + wait_disable_change;
|
||||||
|
|
||||||
|
while ((esp_timer_get_time() - disable_start_time) < 0) {
|
||||||
|
NOP();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void motors_read_settings() {
|
void motors_read_settings() {
|
||||||
|
@@ -10,6 +10,7 @@ StringSetting* build_info;
|
|||||||
|
|
||||||
IntSetting* pulse_microseconds;
|
IntSetting* pulse_microseconds;
|
||||||
IntSetting* stepper_idle_lock_time;
|
IntSetting* stepper_idle_lock_time;
|
||||||
|
IntSetting* enable_delay_microseconds;
|
||||||
|
|
||||||
AxisMaskSetting* step_invert_mask;
|
AxisMaskSetting* step_invert_mask;
|
||||||
AxisMaskSetting* dir_invert_mask;
|
AxisMaskSetting* dir_invert_mask;
|
||||||
@@ -399,6 +400,7 @@ void make_settings() {
|
|||||||
step_invert_mask = new AxisMaskSetting(GRBL, WG, "2", "Stepper/StepInvert", DEFAULT_STEPPING_INVERT_MASK, postMotorSetting);
|
step_invert_mask = new AxisMaskSetting(GRBL, WG, "2", "Stepper/StepInvert", DEFAULT_STEPPING_INVERT_MASK, postMotorSetting);
|
||||||
stepper_idle_lock_time = new IntSetting(GRBL, WG, "1", "Stepper/IdleTime", DEFAULT_STEPPER_IDLE_LOCK_TIME, 0, 255);
|
stepper_idle_lock_time = new IntSetting(GRBL, WG, "1", "Stepper/IdleTime", DEFAULT_STEPPER_IDLE_LOCK_TIME, 0, 255);
|
||||||
pulse_microseconds = new IntSetting(GRBL, WG, "0", "Stepper/Pulse", DEFAULT_STEP_PULSE_MICROSECONDS, 3, 1000);
|
pulse_microseconds = new IntSetting(GRBL, WG, "0", "Stepper/Pulse", DEFAULT_STEP_PULSE_MICROSECONDS, 3, 1000);
|
||||||
|
enable_delay_microseconds = new IntSetting(EXTENDED, WG, NULL, "Stepper/Enable/Delay", DEFAULT_STEP_ENABLE_DELAY, 0, 1000); // microseconds
|
||||||
|
|
||||||
stallguard_debug_mask = new AxisMaskSetting(EXTENDED, WG, NULL, "Report/StallGuard", 0, postMotorSetting);
|
stallguard_debug_mask = new AxisMaskSetting(EXTENDED, WG, NULL, "Report/StallGuard", 0, postMotorSetting);
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ extern StringSetting* build_info;
|
|||||||
|
|
||||||
extern IntSetting* pulse_microseconds;
|
extern IntSetting* pulse_microseconds;
|
||||||
extern IntSetting* stepper_idle_lock_time;
|
extern IntSetting* stepper_idle_lock_time;
|
||||||
|
extern IntSetting* enable_delay_microseconds;
|
||||||
|
|
||||||
extern AxisMaskSetting* step_invert_mask;
|
extern AxisMaskSetting* step_invert_mask;
|
||||||
extern AxisMaskSetting* dir_invert_mask;
|
extern AxisMaskSetting* dir_invert_mask;
|
||||||
|
Reference in New Issue
Block a user