Giter VIP home page Giter VIP logo

plugins_spindle's Introduction

Spindle plugins

This plugin adds support for some VFD spindles via ModBus (RS485) and a spindle selection plugin.

VFD spindles

VFD spindle support is enabled in my_machine.h by uncommenting \\#define VFD_SPINDLE and changing the VFD spindle number to the desired type or -1 for all.
A list of supported VFDs and associated spindle numbers can be found here.

If all spindles or dual spindle is enabled the active spindle is configured by setting $395.
Note that the setting value not the same as the VFD spindle number used in my_machine.h, either use a sender that supports grblHAL setting enumerations for configuration or output a list with the $$=395 command to find the correct setting value.

If a single VFD spindle is added to the firmware its ModBus address is configured by setting $360 (default 1).
If more than one then the ModBus address is set by one of the following settings depending on the spindle number it is assigned to:

$476 - ModBus address of VFD bound to spindle 0, default 1. Available when spindle 0 is configured as a VFD spindle by $395.
$477 - ModBus address of VFD bound to spindle 1, default 2. Available when spindle 1 is configured as a VFD spindle by $511.
$478 - ModBus address of VFD bound to spindle 2, default 3. Available when spindle 2 is configured as a VFD spindle by $512.
$479 - ModBus address of VFD bound to spindle 4, default 4. Available when spindle 3 is configured as a VFD spindle by $513.

GS20 and YL-620

Setting $461 can be used to set the RPM to HZ relationship. Default value is 60.

MODVFD

The MODVFD spindle uses different register values for the control and RPM functions. The functionality is similar to the VFDMODcomponent from LinuxCNC. The following settings are available:

$462 - Register for Run/stop, default value is 8192.
$463 - Set Frequency Register, default value is 8193.
$464 - Get Frequency Register, default value is 8451.
$465 - Command word for CW, default value is 18.
$466 - Command word for CCW, default value is 34.
$467 - Command word for stop, default value is 1.
$468 - RPM value multiplier for programming RPM, default value is 50.
$469 - RPM value divider for programming RPM, default value is 60.
$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.


Additional spindles

Additional spindles may be added by plugin code. If of a generic kind they might be added to this repo based on a pull request.


Spindle selection

grblHAL can operate in three different spindle modes depending on compile time configuration:

  • Only a single spindle is allowed.
    None of the settings or the M-code documented below is available.

  • Up to 321 spindles can be added but only one of up to four1 can be active at a time. Spindle switching is by tool number (see below) or M104:
    Use M104P0 and M104P1 to set the active spindle as spindle number 0 or 1 respectively.
    Use M104Q<n> where <n> is the spindle number to set as the active spindle.

  • Up to 32 spindles can be added and up to four can be active at a time.
    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!

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.

$395 - bind spindle number 0 to the given spindle id. This setting is available when two or more spindles are added.
$511 - bind spindle number 1 to the given spindle id. This setting is available when two or more spindles are added.
$512 - bind spindle number 2 to the given spindle id. This setting is available when three or more spindles are added.
$513 - bind spindle number 3 to the given spindle id. This setting is available when four or more spindles are added.

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.

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.

$520 - lowest tool number for selecting spindle 0, ignored if 0 - normally leave at 0. If set > 0 tool numbers lower than the value will not cause a spindle change.
$521 - lowest tool number for selecting spindle 1, ignored if 0.
$522 - lowest tool number for selecting spindle 2, ignored if 0.
$523 - lowest tool number for selecting spindle 3, ignored if 0.

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 the controlled point (tooltip) to the required position.

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


2023-02-13

plugins_spindle's People

Contributors

andrewmarles avatar aselle avatar dietz0r avatar dresco avatar terjeio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

plugins_spindle's Issues

Spindle RPM override not taking effect.

Apologies, I can only test this with my vfd_support branch modifications and my GS20 VFD , but I just wanted to report my experiences with the new spindle switching feature.

https://github.com/Expatria-Technologies/Plugins_spindle

The switching works as expected, both with the M code and with the startup spindle setting. And when the device is idle or in hold, I can use the spindle speed override and it works as expected. However, if we are in a run state it seems the spindle override is not taking effect. I will try to get some better insights into what could be going on.

Thanks as always for these cool new features.

modbus_poll should change timeout->silent only for async packet

The risk of current implementation is to miss timeout state in modbus_send_rtu, because second call of modbus_poll will change it to silent.
Currently it works, just because modbus_poll is called from modbus_send_rtu, but this is very dangerous - in other conditions modbus_poll can be called by core main thread, because it hooks grbl.on_execute_realtime.
And I think that intention was that modbus_poll procedure handles this state transition for async packet, whereas for blocking packet timeout state will be changed to silent/idle by modbus_send_rtu code.

Proposed fix:
image

Additionally, I didn't find on_rx_exception callback for timeout case for async packet.

modbus_rtu receives zero length packet

image
Shouldn't rx_len be used as loop counter? Otherwise received packed has zero rx_length.

UPD: I see, that rx_len is used below, in CRC check. Ok, then we can't use it in loop. But it is very confusing to get packet in receive callback with zero length. Maybe restore packet->msg.rx_length = rx_len after CRC check?

$465 and $466

Hello,

i am trying to get a SIEMENS VFD running but $465 and $466 seem to only accept values up to 255.

In my case the CW and CCW commands would be 1151 and 3199 sice the vfd uses bit 11 for direction.

If i set $465 and $466 to the values 1151 and 3199 it always writes 127 to the modbus register.

Is there any workaround for that?

Thanks in advance!

Stream claiming logic with MODBUS_RTU_STREAM defined

Hi,

Am wondering whether there is an error with the current logic for claiming serial streams?

Have been looking at the F7 driver, and as best as I can see, the instance member checked in the following code is always 0,1, or 2 - and not the number from the SERIALn_PORT / MODBUS_RTU_STREAM definition?

#if MODBUS_RTU_STREAM >= 0
if(sstream->type == StreamType_Serial && sstream->instance == MODBUS_RTU_STREAM) {
#else
if(sstream->type == StreamType_Serial && sstream->flags.modbus_ready && !sstream->flags.claimed) {
#endif

I've been trying to verify this with the F7/H7 Nucleo reference map;

  • Without MODBUS_RTU_STREAM defined, it takes the first available stream which works fine.
  • With MODBUS_RTU_STREAM defined as SERIAL1_PORT, this also works but I think just coincidentally? As SERIAL1_PORT is defined in the reference map as 1.
  • If SERIAL1_PORT is defined as something else (say 11, or 2, or 21), this will result in a [MSG:Warning: Modbus failed to initialize!] error, and then becomes unresponsive.
  • Same story if MODBUS_RTU_STREAM / SERIAL2_PORT is used instead. Works fine if defined as 2, but not 1/11/21 etc.

Speed tolerance based on present speed instead of top speed

    if(settings.spindle.at_speed_tolerance > 0.0f) {
        spindle_data.rpm_low_limit = rpm / (1.0f + settings.spindle.at_speed_tolerance);
        spindle_data.rpm_high_limit = rpm * (1.0f + settings.spindle.at_speed_tolerance);
    }

This code from huanyang.c applies speed tolerance percentage to the present speed setpoint which implies that speed accuracy of VFDs improve as the speed decreases. For example a 10000 RPM motor with a 1% speed tolerance would be +/- 100 RPM at 10000RPM but +/- 10 RPM at 1000RPM. The physics governing speed accuracy on VFDs cause the the speed accuracy to be the same or worse as the speed decreases. I believe the speed tolerance should always be based on percentage of top speed.
Thanks,
Jeff

H100 VFD

The board is MKS Tinybee.

I have several problems with this driver:

  • does not increase speed (always works at the min speed set in the register (my set is 7200 rpm));
  • M5 does not always stop the spindle, sometimes it stops with M3 S0 or M3 S0 must precede M5;
  • M3 and M4 always rotate in the same direction.

I analyzed the data flow on Modbus by comparing a working configuration to verify what happens (I attach the files).
H100 whith FluidNC.txt
H100 whith grblHAL.txt

Whith grblHAL the commands M3, M4 and M5 are received correctly, but he speed S(xxxx) is written in the register with address 512 instead of 513, and I think it is the cause of the speed limitation and maybe also the other problems.

This log is when IOSENDER send M3 S10000 (firmware fluiNC):

[14/09/2023 15:36:49]
Modbus Response (COM11)
Address: 1
Function: 6 (0x06) - Write Single Register
Address: 513
Value: 1666
Checksum: 0x5a73 - OK

[14/09/2023 15:36:50]
Modbus Response (COM11)
Address: 1
Function: 4 (0x04) - Read Input Registers
Byte Count: 4
Values: 05 c2 06 82
Register0: 1474
Register1: 1666
Checksum: 0xd975 - OK

[14/09/2023 15:36:50]
Modbus Response (COM11)
Address: 1
Function: 4 (0x04) - Read Input Registers
Byte Count: 4
Values: 06 6f 06 82
Register0: 1647
Register1: 1666
Checksum: 0x48d0 - OK

[14/09/2023 15:36:50]
Modbus Response (COM11)
Address: 1
Function: 4 (0x04) - Read Input Registers
Byte Count: 4
Values: 06 82 06 82
Register0: 1666
Register1: 1666
Checksum: 0xd8e5 - OK

The spindle run at 10000 rpm correctly.

This log is when IOSENDER send M3 S10000 (firmware grblHAL):

(send M3 S10000)

[14/09/2023 17:21:16]
Modbus Response (COM11)
Address: 1
Function: 5 (0x05) - Write Single Coil
Address: 73
Value: 65280
Checksum: 0x5dec - OK

[14/09/2023 17:21:16]
Modbus Response (COM11)
Address: 1
Function: 6 (0x06) - Write Single Register
Address: 512 <<<<<<<<<<<<<<<<< (not is 513)
Value: 1670
Checksum: 0x0a70 - OK

[14/09/2023 17:21:16]
Modbus Response (COM11)
Address: 1
Function: 4 (0x04) - Read Input Registers
Byte Count: 4
Values: 00 73 00 32
Register0: 115
Register1: 50 <<<<<<<<<<<<<<<<<<< (always locked to 50)
Checksum: 0x8b8a - OK

[14/09/2023 17:21:17]
Modbus Response (COM11)
Address: 1
Function: 4 (0x04) - Read Input Registers
Byte Count: 4
Values: 02 af 00 32
Register0: 687
Register1: 50
Checksum: 0x4bc8 - OK

[14/09/2023 17:21:18]
Modbus Response (COM11)
Address: 1
Function: 4 (0x04) - Read Input Registers
Byte Count: 4
Values: 04 b0 00 32
Register0: 1200 <<<<<<<<<<<<<<<<<<< (instant speeds 1200=7200 rpm)
Register1: 50
Checksum: 0x7a86 - OK

[14/09/2023 17:21:22]
Modbus Response (COM11)
Address: 1
Function: 4 (0x04) - Read Input Registers
Byte Count: 4
Values: 04 b0 00 32
Register0: 1200
Register1: 50
Checksum: 0x7a86 - OK

Register1 (which should set the speed to reach) is blocked at 50. The splindle run to min speed 7200 rpm

I attach the manual of my VFD
new H100 manual V1.8.pdf

Is there anyone who uses this driver or has done any testing?
Thanks

Huanyang FC01 VFD (new model)

A user of the H7 driver has one of these new Huanyang VFDs.

Has shared a manual here, appears to be Modbus RTU compliant, so I think it should work with @andrewmarles MODVFD spindle type..

I can take some guesses at the settings based on the manual, but wanted to open a ticket here to get some more eyes on it. I would imagine these are going to become more popular.

VFD parameters (page 63).
Looks like it defaults to 19200 baud, even parity, 8 data bits, 1 stop bit.
From memory, grblHAL is expecting N,8,1 - so would need to change parameter P14.02 accordingly.

Modbus registers (page 84)
$462 - Register for Run/stop (default value is 8192) - 8192 (0x2000)
$463 - Set Frequency Register (default value is 8193) - 8193 (0x2001)
$464 - Get Frequency Register (default value is 8451) - 12289 (0x3001)
$465 - Command word for CW (default value is 18) - 1
$466 - Command word for CCW (default value is 34) - 2
$467 - Command word for stop (default value is 1) - 5
$468 - RPM value multiplier for programming RPM (default value is 50) - 100?
$469 - RPM value divider for programming RPM (default value is 60) - 60?
$470 - RPM value multiplier for reading RPM (default value is 60) - ?
$471 - RPM value divider for reading RPM (default value is 100) - ?

Page 85 mentions settings P00.01, and P00.02 needed for Modbus control, although P00.02 is not listed anywhere else in manual?

Move modbus code to separate folder?

Hi Terje, how would you feel about moving the modbus files out of here to their own folder? I think this would be cleaner for any future plugins that also use modbus..

Don't think I can make a pull request for this, as it would need a new submodule - but changes would be (1) creating a new 'modbus' source folder in STM32CubeIDE, (2) moving the two modbus.* files, and (3) changing the include path in huangyang.h as follows;

diff --git a/spindle/huanyang.h b/spindle/huanyang.h
index 22d8e41..e8f219c 100644
--- a/spindle/huanyang.h
+++ b/spindle/huanyang.h
@@ -37,7 +37,7 @@
 #endif
 #define VFD_SPINDLE 1
 
-#include "modbus.h"
+#include "modbus/modbus.h"
 
 void huanyang_init (modbus_stream_t *stream);

I have a Huangyang VFD here on the bench that I'm testing with, using the STM32F4xx driver. (My interest here is that I'm picking up on my modbus control panel & plugin work again).

Regards, Jon.

Spindle refactoring, issue with original Huanyang logic

Looks like the refactoring has impacted speed control for original Huanyang VFDs..

Here it's setting spindle_hal->rpm_max to the configured RPM @ 50Hz, which is then enforced in spindle_set_rpm()

case VFD_GetMaxRPM50:
if(spindle_hal) {
spindle_hal->cap.rpm_range_locked = On;
spindle_hal->rpm_max = rpm_max50 = (float)((msg->adu[4] << 8) | msg->adu[5]);
}
break;

Stepper Spindle Enable signal to be isolated from axis enable

I have just started testing the stepper spindle. The obvious practical issue I feel is spindle enable and axis enable both are hard bound somewhere in code, so I cant really move an axis to a precise location while rotating the spindle by hand to see if the tool touched the surface. All the other parameters like Spindle enable, direction, rpm, acceleration, works as expected.

VFD as default spindle ($395) does not expose VFD settings

The dynamic spindle selection seems to work well for VFD spindles when they are selected as spindle > 0. The is_vfd_spindle and _is_modvfd_selected functions expose the appropriate settings and they appear to work as expected.

But if I set the default spindle to be one of the VFD spindles, it never enumerates correctly. $476 is never exposed, nor do the MODVFD settings if that spindle is selected. It does appear that the MODVFD spindle is in fact being activated by the core as I can see traffic on the RS485 interface and it generates error14 when it can't communicate. I have spent a fair amount of time trying to figure out where it is going wrong but no success yet.

Spindle speed tolerance limits math

We just had an in depth discussion with some users on the VFD pluging reporting unexpected behaviour such as: gcode commencing before spindle at speed (despite a tolerance and delay being set) and also the spindle seemingly ignoring settings and not alarming out despite not having reached speeds at the defined time.

Reported settings:

$340: Spindle at speed tolerance: 5 percent
$392: Spindle on delay: 1 sec

The users VFD was configured for a 10 sec ramp.
Expected behaviour would be that the controller issues an alarm 14 after 1 sec because spindle is at around 2400rpm during the 1 sec aceleration time.

Observed behaviour:
M3 S18000 - alarm 14 after 1 sec
M3 S10000 - acelerates for 10 sec to 10000rpm, no alarm was issued after 1 sec
M3 S12000 - also acelerates slowly, no alarm after 1 sec
M3 S13000 - also acelerates slowly, no alarm after 1 sec
M3 S14000 - alarm 14 after 1 sec -

after digging through the code a bit i found this: (in huanyang.c - line 130 )

 if(settings.spindle.at_speed_tolerance > 0.0f) {
            spindle_data.rpm_low_limit = rpm / (1.0f + settings.spindle.at_speed_tolerance);
            spindle_data.rpm_high_limit = rpm * (1.0f + settings.spindle.at_speed_tolerance);
        }

Since the spindle at speed tolerance is also stored as a two digit decimal i believe the tolerance limits are calculated wrongly.
For example the tolerance of 5.0 from above would result in the folowing checks:
18000rpm / 6 = 3000rpm lower limit - which correctly errors out
10000rpm / 6 = 1666rpm lower limit - this passes the 1 second check interval and continues to acelerate to full issued speed
this explains why S14000 ist starting to fail as it should, it's crossing the 2400rpm aceleration line of the vfd

i believe the relevant portion of the code should look like this to function correctly as a percentage:

        if(settings.spindle.at_speed_tolerance > 0.0f) {
            spindle_data.rpm_low_limit = rpm / (1.0f + (settings.spindle.at_speed_tolerance / 100));
            spindle_data.rpm_high_limit = rpm * (1.0f + (settings.spindle.at_speed_tolerance / 100));
        }

Hope i got everyting right and this helps.

Spindle load feedback with multiple spindles

Am going to have another look at spindle load reporting for VFD spindles, this time just as a percentage (following discussion in previous PR, and in line with how it's done on other machines).

Am planning to query the maximum amps during spindle configuration, and then the actual amps periodically along with the rpm. Can then use a calculated load percentage for feedback in the realtime report etc. So far so good..

I have a question though, I only want to add this additional report data if the spindle is selected. For instance if I switch away from the Huanyang spindle to the PWM spindle with M104, then I'd want to stop adding the data in the Huanyang plugin realtime report. Is there a way within the spindle plugin to determine whether the spindle is currently active?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.