diff --git a/README.md b/README.md
index 06b60ef..3290a56 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 20230126, see the [changelog](changelog.md) for details.
+Latest build date is 20230128, see the [changelog](changelog.md) for details.
__NOTE:__ A settings reset will be performed on an update of builds earlier than 20230125. Backup and restore of settings is recommended.
__IMPORTANT!__ A new setting has been introduced for ganged axes motors in build 20211121.
I have only bench tested this for a couple of drivers, correct function should be verified after updating by those who have more than three motors configured.
@@ -87,4 +87,4 @@ List of Supported G-Codes:
Some [plugins](https://github.com/grblHAL/plugins) implements additional M-codes.
---
-2023-01-26
+2023-01-28
diff --git a/changelog.md b/changelog.md
index dc48b9b..189f242 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,24 @@
## grblHAL changelog
+Build 20230128
+
+Core:
+
+* Some internal changes to allow homing feed rate override from plugins, reserved setting numbers for per axis homing feedrate settings \(not used by the core\).
+
+Motors plugin:
+
+* Fix for issue [#9](https://github.com/grblHAL/Plugins_motor/issues/9), added settings for per axis homing feed rates.
+__NOTE:__ Per axis homing feedrates will only be used for Trinamic driven axes with sensorless homing enabled, others will still use feedrates as set by the `$24` and `$25` settings.
+__NOTE:__ If more than one axis is homed in a cycle and the homing feedrates differ the cycle will be skipped.
+__NOTE:__ Per axis feedrates is currently for experimental use/testing - may be removed in a later build.
+
+Trinamic plugin:
+
+* Fix for issue [#41](https://github.com/grblHAL/RP2040/issues/41#issuecomment-1379449288), wrong PWM autoscale mode selected for sensorless homing.
+
+---
+
Build 20230126
Core:
diff --git a/core_handlers.h b/core_handlers.h
index 7656698..76d3723 100644
--- a/core_handlers.h
+++ b/core_handlers.h
@@ -32,6 +32,7 @@
#include "settings.h"
#include "report.h"
#include "planner.h"
+#include "machine_limits.h"
typedef enum {
OverrideChanged_FeedRate = 0,
@@ -91,7 +92,7 @@ typedef void (*on_realtime_report_ptr)(stream_write_ptr stream_write, report_tra
typedef void (*on_unknown_feedback_message_ptr)(stream_write_ptr stream_write);
typedef void (*on_stream_changed_ptr)(stream_type_t type);
typedef bool (*on_laser_ppi_enable_ptr)(uint_fast16_t ppi, uint_fast16_t pulse_length);
-typedef void (*on_homing_rate_set_ptr)(axes_signals_t axes, float rate, bool pulloff);
+typedef void (*on_homing_rate_set_ptr)(axes_signals_t axes, float rate, homing_mode_t mode);
typedef void (*on_homing_completed_ptr)(void);
typedef bool (*on_probe_fixture_ptr)(tool_data_t *tool, bool at_g59_3, bool on);
typedef bool (*on_probe_start_ptr)(axes_signals_t axes, float *target, plan_line_data_t *pl_data);
diff --git a/grbl.h b/grbl.h
index 80e0e20..b480f63 100644
--- a/grbl.h
+++ b/grbl.h
@@ -42,7 +42,7 @@
#else
#define GRBL_VERSION "1.1f"
#endif
-#define GRBL_BUILD 20230126
+#define GRBL_BUILD 20230128
#define GRBL_URL "https://github.com/grblHAL"
diff --git a/hal.h b/hal.h
index 34ed45d..d160f2b 100644
--- a/hal.h
+++ b/hal.h
@@ -173,12 +173,14 @@ typedef struct {
* Homing *
************/
+typedef float (*homing_get_feedrate_ptr)(axes_signals_t axes, homing_mode_t mode);
+
//! Limit switches handler for homing cycle.
typedef struct {
limits_get_state_ptr get_state; //!< Handler for getting limit switches status. Usually set to the same function as _hal.limits.get_state_.
+ homing_get_feedrate_ptr get_feedrate;
} homing_ptrs_t;
-
/*****************************
* Control signal switches *
*****************************/
diff --git a/machine_limits.c b/machine_limits.c
index 022451b..2c841b3 100644
--- a/machine_limits.c
+++ b/machine_limits.c
@@ -221,6 +221,10 @@ static bool limits_pull_off (axes_signals_t axis, float distance)
return true; // Note: failure is returned above if move fails.
}
+static float limits_get_homing_rate (axes_signals_t cycle, homing_mode_t mode)
+{
+ return mode == HomingMode_Locate ? settings.homing.feed_rate : settings.homing.seek_rate;
+}
// Homes the specified cycle axes, sets the machine position, and performs a pull-off motion after
// completing. Homing is a special motion case, which involves rapid uncontrolled stops to locate
@@ -233,15 +237,19 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar
if (ABORTED) // Block if system reset has been issued.
return false;
+ if(hal.homing.get_feedrate == NULL)
+ hal.homing.get_feedrate = limits_get_homing_rate;
+
int32_t initial_trigger_position = 0, autosquare_fail_distance = 0;
uint_fast8_t n_cycle = (2 * settings.homing.locate_cycles + 1);
uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0;
- coord_data_t target;
- float max_travel = 0.0f, homing_rate = settings.homing.seek_rate;
- bool approach = true, autosquare_check = false;
+ bool autosquare_check = false;
+ float max_travel = 0.0f, homing_rate;
+ homing_mode_t mode = HomingMode_Seek;
axes_signals_t axislock, homing_state;
limit_signals_t limits_state;
squaring_mode_t squaring_mode = SquaringMode_Both;
+ coord_data_t target;
plan_line_data_t plan_data;
// Initialize plan data struct for homing motion.
@@ -281,6 +289,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar
if(max_travel == 0.0f)
return true;
+ if((homing_rate = hal.homing.get_feedrate(cycle, HomingMode_Seek)) == 0.0f)
+ return false;
+
if(auto_square.mask) {
float fail_distance = (-settings.homing.dual_axis.fail_length_percent / 100.0f) * settings.axis[dual_motor_axis].max_travel;
fail_distance = min(fail_distance, settings.homing.dual_axis.fail_distance_max);
@@ -309,29 +320,28 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar
#endif
// Set target direction based on cycle mask and homing cycle approach state.
if (bit_istrue(settings.homing.dir_mask.value, bit(idx)))
- target.values[idx] = approach ? - max_travel : max_travel;
+ target.values[idx] = mode == HomingMode_Pulloff ? max_travel : - max_travel;
else
- target.values[idx] = approach ? max_travel : - max_travel;
+ target.values[idx] = mode == HomingMode_Pulloff ? - max_travel : max_travel;
// Apply axislock to the step port pins active in this cycle.
axislock.mask |= step_pin[idx];
}
} while(idx);
- sys.homing_axis_lock.mask = axislock.mask;
-
#ifdef KINEMATICS_API
if(kinematics.homing_cycle_get_feedrate)
homing_rate = kinematics.homing_cycle_get_feedrate(homing_rate, cycle);
#endif
if(grbl.on_homing_rate_set)
- grbl.on_homing_rate_set(cycle, homing_rate, !approach);
+ grbl.on_homing_rate_set(cycle, homing_rate, mode);
homing_rate *= sqrtf(n_active_axis); // [sqrt(N_AXIS)] Adjust so individual axes all move at homing rate.
// Perform homing cycle. Planner buffer should be empty, as required to initiate the homing cycle.
plan_data.feed_rate = homing_rate; // Set current homing rate.
+ sys.homing_axis_lock.mask = axislock.mask;
#ifdef KINEMATICS_API
coord_data_t k_target;
@@ -347,7 +357,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar
do {
- if (approach) {
+ if (mode != HomingMode_Pulloff) {
// Check homing switches state. Lock out cycle axes when they change.
homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode);
@@ -386,7 +396,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar
}
}
- st_prep_buffer(); // Check and prep segment buffer. NOTE: Should take no longer than 200us.
+ st_prep_buffer(); // Check and prep segment buffer.
// Exit routines: No time to run protocol_execute_realtime() in this loop.
if (sys.rt_exec_state & (EXEC_SAFETY_DOOR | EXEC_RESET | EXEC_CYCLE_COMPLETE)) {
@@ -402,11 +412,11 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar
system_set_exec_alarm(Alarm_HomingFailDoor);
// Homing failure condition: Homing switch(es) still engaged after pull-off motion
- if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask))
+ if (mode == HomingMode_Pulloff && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask))
system_set_exec_alarm(Alarm_FailPulloff);
// Homing failure condition: Limit switch not found during approach.
- if (approach && (rt_exec & EXEC_CYCLE_COMPLETE))
+ if (mode != HomingMode_Pulloff && (rt_exec & EXEC_CYCLE_COMPLETE))
system_set_exec_alarm(Alarm_HomingFailApproach);
if (sys.rt_exec_alarm) {
@@ -427,20 +437,18 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar
st_reset(); // Immediately force kill steppers and reset step segment buffer.
hal.delay_ms(settings.homing.debounce_delay, NULL); // Delay to allow transient dynamics to dissipate.
- // Reverse direction and reset homing rate for locate cycle(s).
- approach = !approach;
+ // Reverse direction and reset homing rate for cycle(s).
+ mode = mode == HomingMode_Pulloff ? HomingMode_Locate : HomingMode_Pulloff;
+ homing_rate = hal.homing.get_feedrate(cycle, mode);
// After first cycle, homing enters locating phase. Shorten search to pull-off distance.
- if (approach) {
+ if (mode == HomingMode_Locate) {
// Only one initial pass for auto squared axis when both motors are active
//if(mode == SquaringMode_Both && auto_square.mask)
// cycle.mask &= ~auto_square.mask;
max_travel = settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR;
- homing_rate = settings.homing.feed_rate;
- } else {
+ } else
max_travel = settings.homing.pulloff;
- homing_rate = settings.homing.seek_rate;
- }
if(auto_square.mask) {
autosquare_check = false;
diff --git a/machine_limits.h b/machine_limits.h
index 4e183c4..e6467ec 100644
--- a/machine_limits.h
+++ b/machine_limits.h
@@ -26,6 +26,13 @@
#include "nuts_bolts.h"
+typedef enum
+{
+ HomingMode_Seek = 0,
+ HomingMode_Locate,
+ HomingMode_Pulloff
+} homing_mode_t;
+
// Perform one portion of the homing cycle based on the input settings.
status_code_t limits_go_home (axes_signals_t cycle);
diff --git a/settings.c b/settings.c
index c387f96..494c922 100644
--- a/settings.c
+++ b/settings.c
@@ -2118,6 +2118,8 @@ bool settings_iterator (const setting_detail_t *setting, setting_output_ptr call
case Setting_AxisMicroSteps:
case Setting_AxisBacklash:
case Setting_AxisAutoSquareOffset:
+ case Setting_AxisHomingFeedRate:
+ case Setting_AxisHomingSeekRate:
case Setting_AxisExtended0:
case Setting_AxisExtended1:
case Setting_AxisExtended2:
diff --git a/settings.h b/settings.h
index 73c7336..5fbf6de 100644
--- a/settings.h
+++ b/settings.h
@@ -155,7 +155,7 @@ typedef enum {
// Reserving settings in the range 100 - 299 for axis settings.
Setting_AxisSettingsBase = 100, // Reserved for core settings
- Setting_AxisSettingsMax = Setting_AxisSettingsBase + AXIS_SETTINGS_INCREMENT * 7 + N_AXIS,
+ Setting_AxisSettingsMax = Setting_AxisSettingsBase + AXIS_SETTINGS_INCREMENT * 9 + N_AXIS,
Setting_AxisSettingsBase2 = 200, // Reserved for driver/plugin settings
Setting_AxisSettingsMax2 = Setting_AxisSettingsBase2 + AXIS_SETTINGS_INCREMENT * 9 + N_AXIS,
//
@@ -338,6 +338,8 @@ typedef enum {
Setting_AxisMicroSteps = Setting_AxisSettingsBase + 5 * AXIS_SETTINGS_INCREMENT,
Setting_AxisBacklash = Setting_AxisSettingsBase + 6 * AXIS_SETTINGS_INCREMENT,
Setting_AxisAutoSquareOffset = Setting_AxisSettingsBase + 7 * AXIS_SETTINGS_INCREMENT,
+ Setting_AxisHomingFeedRate = Setting_AxisSettingsBase + 8 * AXIS_SETTINGS_INCREMENT,
+ Setting_AxisHomingSeekRate = Setting_AxisSettingsBase + 9 * AXIS_SETTINGS_INCREMENT,
// Calculated base values for driver/plugin stepper settings
Setting_AxisExtended0 = Setting_AxisSettingsBase2,