From ec209ecba7b29019ab077c586cde6a1b28f211de Mon Sep 17 00:00:00 2001 From: Terje Io Date: Thu, 4 Apr 2024 16:40:07 +0200 Subject: [PATCH] Fixed polar kinematics feed rate handling, some tuning. Ref. issue #475. Allowed plugins to inject commands when controller is in alarm state. --- README.md | 2 +- changelog.md | 22 ++++++++++++++++++++- grbl.h | 2 +- kinematics/delta.c | 2 +- kinematics/polar.c | 49 ++++++++++++++++++++++++++++++++-------------- motion_control.c | 2 +- planner.c | 8 ++++---- protocol.c | 2 +- settings.c | 2 +- 9 files changed, 65 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 3c07005..75b77a9 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ It has been written to complement grblHAL and has features such as proper keyboa --- -Latest build date is 20240402, see the [changelog](changelog.md) for details. +Latest build date is 20240404, see the [changelog](changelog.md) for details. __NOTE:__ Build 20240222 has moved the probe input to the ioPorts pool of inputs and will be allocated from it when configured. The change is major and _potentially dangerous_, it may damage your probe, so please _verify correct operation_ after installing this, or later, builds. diff --git a/changelog.md b/changelog.md index 3c44cab..46a57d2 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,25 @@ ## grblHAL changelog +Build 20240404 + +Core: + +* Fixed polar kinematics feed rate handling, some tuning. Ref. issue [#475](https://github.com/grblHAL/core/issues/475). + +* Allowed plugins to inject commands when controller is in alarm state. Ref. keypad plugin issue [#11](https://github.com/grblHAL/Plugin_keypad/issues/11). + +Drivers: + +* STM32F1xx, STM32F3xx, STM32F4xx, STM32F7xx and iMXRT1062: now calls stepper enable via HAL. Ref. spindle issue [#28](https://github.com/grblHAL/Plugins_spindle/issues/28). + +Plugins: + +* Spindle: improved motor enable support for stepper spindle. Ref. issue [#28](https://github.com/grblHAL/Plugins_spindle/issues/28). + +* Plasma: removed stray code causing compilation failure. + +--- + Build 20240402 Core: @@ -12,7 +32,7 @@ Drivers: * iMXRT1062: fixed typo in step inject code causing direction signal to fail for A+ axes. -Plugings: +Plugins: * Spindle: added motor enable support for stepper spindle. diff --git a/grbl.h b/grbl.h index f98a36b..89e142e 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20240402 +#define GRBL_BUILD 20240404 #define GRBL_URL "https://github.com/grblHAL" diff --git a/kinematics/delta.c b/kinematics/delta.c index 178318b..945d2b5 100644 --- a/kinematics/delta.c +++ b/kinematics/delta.c @@ -290,7 +290,7 @@ static float *delta_segment_line (float *target, float *position, plan_line_data } else if(!pl_data->condition.rapid_motion && distance != 0.0f) { float rate_multiplier = get_distance(mpos.values, machine.last_pos.values) / distance; pl_data->feed_rate *= rate_multiplier; - pl_data->rate_multiplier = 1.0 / rate_multiplier; + pl_data->rate_multiplier = 1.0f / rate_multiplier; } memcpy(&machine.last_pos, &mpos, sizeof(coord_data_t)); diff --git a/kinematics/polar.c b/kinematics/polar.c index d7cc8f5..9db460f 100644 --- a/kinematics/polar.c +++ b/kinematics/polar.c @@ -7,18 +7,18 @@ Note: homing is not implemented! - Grbl is free software: you can redistribute it and/or modify + grblHAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - Grbl is distributed in the hope that it will be useful, + grblHAL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with Grbl. If not, see . + along with grblHAL. If not, see . */ #include "../grbl.h" @@ -39,6 +39,7 @@ static bool jog_cancel = false; static coord_data_t last_pos = {0}; +static on_program_completed_ptr on_program_completed; static on_report_options_ptr on_report_options; // Simple hypotenuse computation function. @@ -68,17 +69,15 @@ static float *transform_to_cartesian (float *target, float *position) // Returns machine position in mm converted from system position steps. static float *polar_convert_array_steps_to_mpos (float *position, int32_t *steps) { - float cpos[N_AXIS]; + coord_data_t cpos; uint_fast8_t idx = N_AXIS; do { idx--; - cpos[idx] = steps[idx] / settings.axis[idx].steps_per_mm; + cpos.values[idx] = steps[idx] / settings.axis[idx].steps_per_mm; } while(idx); - return transform_to_cartesian(position, cpos); - - return position; + return transform_to_cartesian(position, cpos.values); } // Transform absolute position from cartesian coordinate system to polar coordinate system @@ -130,7 +129,6 @@ static float *polar_segment_line (float *target, float *position, plan_line_data static bool segmented; static float r_offset, distance; static coord_data_t delta, segment_target, final_target, cpos; -// static plan_line_data_t plan; uint_fast8_t idx = N_AXIS; @@ -159,6 +157,8 @@ static float *polar_segment_line (float *target, float *position, plan_line_data delta.values[idx] = delta.values[idx] / (float)iterations; } while(idx); + distance /= (float)iterations; + } else { iterations = 1; memcpy(&segment_target, &final_target, sizeof(coord_data_t)); @@ -175,7 +175,6 @@ static float *polar_segment_line (float *target, float *position, plan_line_data idx--; segment_target.values[idx] += delta.values[idx]; } while(idx); - } else memcpy(&segment_target, &final_target, sizeof(coord_data_t)); @@ -183,9 +182,11 @@ static float *polar_segment_line (float *target, float *position, plan_line_data transform_from_cartesian(cpos.values, segment_target.values); segment_target.values[RADIUS_AXIS] += r_offset; - if(!pl_data->condition.rapid_motion) { - float fr_mul = distance / get_distance(last_pos.values, cpos.values); - pl_data->feed_rate *= fr_mul == 0.0f ? 1.0 : (fr_mul < 0.5f ? 0.5f : fr_mul); + if(!pl_data->condition.rapid_motion && segmented) { + float rate_multiplier = get_distance(last_pos.values, cpos.values) / distance; + rate_multiplier = rate_multiplier == 0.0f ? 1.0 : (rate_multiplier < 0.5f ? 0.5f : rate_multiplier); + pl_data->feed_rate *= rate_multiplier; + pl_data->rate_multiplier = 1.0f / rate_multiplier; } memcpy(&last_pos, &cpos, sizeof(coord_data_t)); @@ -228,7 +229,7 @@ static void report_options (bool newopt) on_report_options(newopt); if(!newopt) - hal.stream.write("[KINEMATICS:Polar v0.01]" ASCII_EOL); + hal.stream.write("[KINEMATICS:Polar v0.02]" ASCII_EOL); } static bool polar_homing_cycle (axes_signals_t cycle, axes_signals_t auto_square) @@ -238,6 +239,21 @@ static bool polar_homing_cycle (axes_signals_t cycle, axes_signals_t auto_square return false; } +static void onProgramCompleted (program_flow_t program_flow, bool check_mode) +{ + coord_data_t cpos; + + memset(last_pos.values, 0, sizeof(coord_data_t)); + transform_from_cartesian(cpos.values, gc_state.position); + memcpy(&last_pos, &cpos, sizeof(coord_data_t)); + + sys.position[POLAR_AXIS] = lroundf(last_pos.values[POLAR_AXIS] * settings.axis[POLAR_AXIS].steps_per_mm); + plan_sync_position(); + + if(on_program_completed) + on_program_completed(program_flow, check_mode); +} + // Initialize API pointers for Wall Plotter kinematics void polar_init (void) { @@ -251,6 +267,9 @@ void polar_init (void) grbl.home_machine = polar_homing_cycle; grbl.on_jog_cancel = cancel_jog; + on_program_completed = grbl.on_program_completed; + grbl.on_program_completed = onProgramCompleted; + on_report_options = grbl.on_report_options; grbl.on_report_options = report_options; } diff --git a/motion_control.c b/motion_control.c index 70e7aee..30ad89b 100644 --- a/motion_control.c +++ b/motion_control.c @@ -79,7 +79,7 @@ bool mc_line (float *target, plan_line_data_t *pl_data) { #ifdef KINEMATICS_API float feed_rate = pl_data->feed_rate; - pl_data->rate_multiplier = 1.0; + pl_data->rate_multiplier = 1.0f; target = kinematics.segment_line(target, plan_get_position(), pl_data, true); #endif diff --git a/planner.c b/planner.c index fce0b4a..0453410 100644 --- a/planner.c +++ b/planner.c @@ -503,15 +503,15 @@ bool plan_buffer_line (float *target, plan_line_data_t *pl_data) block->millimeters = convert_delta_vector_to_unit_vector(unit_vec); block->acceleration = limit_acceleration_by_axis_maximum(unit_vec); block->rapid_rate = limit_max_rate_by_axis_maximum(unit_vec); +#ifdef KINEMATICS_API + block->rate_multiplier = pl_data->rate_multiplier; +#endif // Store programmed rate. if (block->condition.rapid_motion) block->programmed_rate = block->rapid_rate; else { block->programmed_rate = pl_data->feed_rate; -#ifdef KINEMATICS_API - block->rate_multiplier = pl_data->rate_multiplier; -#endif if (block->condition.inverse_time) block->programmed_rate *= block->millimeters; } @@ -692,6 +692,6 @@ void plan_data_init (plan_line_data_t *plan_data) plan_data->spindle.hal = gc_state.spindle.hal ? gc_state.spindle.hal : spindle_get(0); plan_data->condition.target_validated = plan_data->condition.target_valid = sys.soft_limits.mask == 0; #ifdef KINEMATICS_API - plan_data->rate_multiplier = 1.0; + plan_data->rate_multiplier = 1.0f; #endif } diff --git a/protocol.c b/protocol.c index 5d7d158..59735a5 100644 --- a/protocol.c +++ b/protocol.c @@ -74,7 +74,7 @@ static void protocol_exec_rt_suspend (sys_state_t state); bool protocol_enqueue_gcode (char *gcode) { bool ok = xcommand[0] == '\0' && - (state_get() == STATE_IDLE || (state_get() & (STATE_JOG|STATE_TOOL_CHANGE))) && + (state_get() == STATE_IDLE || (state_get() & (STATE_ALARM|STATE_JOG|STATE_TOOL_CHANGE))) && bit_isfalse(sys.rt_exec_state, EXEC_MOTION_CANCEL); if(ok && gc_state.file_run) diff --git a/settings.c b/settings.c index 773e3cd..7df9d69 100644 --- a/settings.c +++ b/settings.c @@ -1662,7 +1662,7 @@ static uint32_t get_int (setting_id_t id) homing.use_limit_switches = settings.homing.flags.use_limit_switches; value = homing.value; #else - value = settings.homing.flags.enable; + value = settings.homing.flags.enabled; #endif break;