Hi! I have a feature request.
I would love if spindles could be defined that output a RC servo signal instead of a 0-100% duty cycle PWM. I'm using a brushless motor as a spindle, and I'm sure you've seen on the internet that I am not alone in doing so. Right now I'm controlling it using the M280 command, but this does not translate from RPM and is not compatible with any standard post-processor for CAM softwares. Also: Servos can not be defined as tools, which has implications when trying to implement a toolchanger which I plan to do.
For syntax, I suggest M950 C"pin" Rnn S Laaa:bbb
Where a naked S without a value indicates that the spindle should use a servo signal. Admittedly this in inconsistent with the current definition of M950 which does not allow having S and R in the same line, but perhaps that is acceptable. If possible it would also make sense for aaa and bbb to allow negative values, to intuitively define counter-clockwise rotation. Adding the Q parameter to this line should probably produce an error, unless the current servo implementation supports different frequencies?
Expected behavior:
M950 C"outputpin" R1 S L-10000:10000
should define spindle1 using servo signal on outputpin with max rpm 10000 in both directions.
M563 P1 R1
should define this spindle as as tool 1.
M5
should set active spindle to 0 rpm as interpolated between aaa and bbb (in this example outputpin to 1,5 ms pulse length). But not define rpm to 0 as interpreted by M3 or M4. Issuing an M3 or M4 without the S parameter after having issued an M5 should make the spindle resume last used RPM. I'm not entirely sure what the G-code standards say about toolchanges in this context, if the tool has changed (and/or the active spindle has changed), should the new tool/spindle inherit the last used RPM? I think it should, if you want another speed you should actively command this by including the S-parameter.
M3 S"5000"
should make outputpin generate 1,75 ms pulse length
M4 S"5000"
should make outputpin generate 1,25 ms pulse length
It may be wise to have the M950 command always initiate the output to 0 rpm upon define, to make sure that a connected ESC if powered intiatites properly and does not move. Alternatively it could be a recommendation in the G-code manual to always issue an M5 command directly after the define, but this would imply the M5 should have an additional argument to allow disabling any of the defined spindles, if there are more than one.
This may not be a high priority feature, but on the other hand since the duet can already output this type of signal I'm hoping that it's so easy to implement that it can be added pretty quickly. It would help me a lot, and I'm sure I won't be the only one to use this feature in the future.
This could also be achieved by more powerful parameters for the rpm, although it would be less user friendly. For an example, you could expand the L parameter to Laaa:AAA:bbb:BBB where aaa=minimum PRM, AAA is minimum duty cycle, bbb is max RPM, and BBB is the maximum duty cycle. If aaa and bbb also accepts negative values this would allow any type range of pwm to be defined, including 0-10v or 0-5v VFDs or industrial servo drives where 0 rpm is somewhere in the middle and they can rotate both ways. But it is important in all these cases that the M5 command outputs 0 rpm and not 0 pwm (plus pulling spindle enable pin low, if defined).