Skip to content

Commit

Permalink
Improved settings changes handling. Added a bit of documentation. Ref…
Browse files Browse the repository at this point in the history
…. issue #30.
  • Loading branch information
terjeio committed Jan 7, 2025
1 parent c3020ab commit fae56f9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,28 @@ the [VFDMOD](https://github.com/aekhv/vfdmod)component from LinuxCNC. The follow
`$470` - RPM value multiplier for reading RPM, default value is `60`.
`$471` - RPM value divider for reading RPM, default value is `100`.

__NOTE:__ settings for ModBus addresses requires a hard reset after changing spindle binding settings \(see below\) before becoming available.
> [!NOTE]
> Settings for ModBus addresses requires a hard reset after changing spindle binding settings \(see below\) before becoming available.
___
#### Stepper spindle

*** Experimental, not tested in a machine ***

The stepper spindle binds to/claims the highest numbered axis > the Z-axis currently _without_ hiding it from control by motion G-codes.
Setting units for the bound axis are changed to _step/rev_, _rev/min_ and _rev/sec^2_, note that some senders may show these in the settings UI, some may not.

Settings `$30` \(min. spindle speed\) and `$31` \(max. spindle speed) is used to set the RPM range, but be aware that `$31` will be capped by the max. rate set for the axis.

Since steps are used to control the motor the angular position can be calculated from the step count, thus this spindle can be used for spindle synced motion without adding an encoder.
"at speed" fucntionality is also available.

> [!NOTE]
> Keep settings within stepper motor specifications, avoid using high microstepping settings. Using a closed loop stepper may be advantageous.
> [!NOTE]
> Some drivers use interrupts to generate steps, some use polling. If polling is used step generation might be jittery, especially at higher RPMs.
---

### Additional spindles

Expand All @@ -65,7 +84,9 @@ Use `M104Q<n>` where `<n>` is the _spindle number_ to set as the active spindle.
The spindle to control is adressed by the `$` gcode word followed by the spindle number,
available for the `S`, `M3`, `M4`, `M5`, `M51`, `G33`, `G76`, `G96` and `G97` gcode commands.
Spindle switching by tool number or `M104` is not available in this mode.
__NOTE:__ This mode is work in progress and functionality is not yet complete!

> [!NOTE]
> This mode is work in progress and functionality is not yet complete!
The spindles are dynamically assigned a _spindle id_ at registration, starting from 0. $-settings are then used to tell grblHAL which are to be enabled,
by _spindle number_.
Expand All @@ -77,7 +98,8 @@ by _spindle number_.

Available spindles with _spindle id_, and _spindle number_ if bound, can be listed by the `$spindles` command. `$$=<n>` where `<n>` is a setting number above can be used for listing allowed values.

__NOTES:__ `$395` defaults to _spindle id_ 0, this is normally the driver provided PWM spindle but can be another spindle if only one spindle can be registered. Spindle 0 cannot be disabled.
> [!NOTE]
> `$395` defaults to _spindle id_ 0, this is normally the driver provided PWM spindle but can be another spindle if only one spindle can be registered. Spindle 0 cannot be disabled.
If the grblHAL is configured to handle only one active spindle at a time then $-settings can be used to assign a range of tool numbers to
each spindle number. The spindle is then activated on a `M6T<n>` command where `<n>` is the tool number.
Expand All @@ -89,15 +111,19 @@ each spindle number. The spindle is then activated on a `M6T<n>` command where `

Tool number vs. spindle is checked from the highest to the lowest spindle number, if all are set to 0 no spindle change takes place.

__NOTE:__ settings for tool number assignments requires a hard reset after changing spindle enable settings before becoming available.
__NOTE:__ when switching between spindles any offset between the spindles must be handled by gcode commands, typically by applying an offset and moving
> [!NOTE]
> settings for tool number assignments requires a hard reset after changing spindle enable settings before becoming available.
> [!NOTE]
> when switching between spindles any offset between the spindles must be handled by gcode commands, typically by applying an offset and moving
the controlled point \(tooltip\) to the required position.

<sup>1</sup> These numbers are defined by compile time configuration and can be lower.

---

__NOTE:__ if laser mode is enabled by the `$32` setting it will only be honoured if the current spindle is a PWM spindle capable of laser mode.
> [!NOTE]
> If laser mode is enabled by the `$32` setting it will only be honoured if the current spindle is a PWM spindle capable of laser mode.
---
2023-02-13
2025-01-07
26 changes: 13 additions & 13 deletions stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Part of grblHAL
Copyright (c) 2023-2024 Terje Io
Copyright (c) 2023-2025 Terje Io
grblHAL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -29,7 +29,7 @@
#if SPINDLE_ENABLE & (1<<SPINDLE_STEPPER)

#if N_AXIS < 4
//#error Stepper spindle can only bind to an axis > Z axis!
#error Stepper spindle can only bind to an axis > Z axis!
#endif

#include "grbl/stepper2.h"
Expand Down Expand Up @@ -161,7 +161,6 @@ static spindle_data_t *spindleGetData (spindle_data_request_t request)
return &spindle_data;
}


static void spindleDataReset (void)
{
offset = st2_get_position(motor);
Expand All @@ -185,23 +184,24 @@ static void settingsChanged (settings_t *settings, settings_changed_flags_t chan
{
settings_changed(settings, changed);

if(changed.spindle) {
spindle_ptrs_t *spindle = spindle_get_hal(spindle_id, SpindleHAL_Configured);

if(changed.spindle || spindle->rpm_max != settings->axis[axis_idx].max_rate) {

spindle_ptrs_t *spindle = spindle_get_hal(spindle_id, SpindleHAL_Configured);
spindle_ptrs_t *spindle_hal;

spindle->rpm_min = settings->pwm_spindle.rpm_min;
spindle->rpm_max = settings->pwm_spindle.rpm_max;
spindle->rpm_max = min(settings->pwm_spindle.rpm_max, settings->axis[axis_idx].max_rate);
spindle->at_speed_tolerance = settings->spindle.at_speed_tolerance;
spindle_data.at_speed_enabled = settings->spindle.at_speed_tolerance >= 0.0f;
}
}

/*
static void raise_alarm (sys_state_t state)
{
system_raise_alarm(Alarm_Spindle);
if((spindle_hal = spindle_get_hal(spindle_id, SpindleHAL_Active))) {
spindle_hal->rpm_min = spindle->rpm_min;
spindle_hal->rpm_max = spindle->rpm_max;
spindle_hal->at_speed_tolerance = spindle->at_speed_tolerance;
}
}
}
*/

#ifdef GRBL_ESP32

Expand Down

0 comments on commit fae56f9

Please sign in to comment.