- Configuring LinuxCNC
- Advanced Configuration
- (Solved) Synchronize multiple spindles? (lathe subspindle)
(Solved) Synchronize multiple spindles? (lathe subspindle)
09 Feb 2024 04:21 #292909
by spumco
Replied by spumco on topic (Solved) Synchronize multiple spindles? (lathe subspindle)
Major progress synchronizing the spindles tonight after re-reading Andy's earlier post(s) for about the 100th time.
mux2 #1 to connect main spindle encoder position to subspindle stepgen position-command
mux2 #2 to switch sub stepgen-type from velocity to position mode
Now the main spindle accel/decel PID doesn't matter as the sub just follows the main, including the caxis.comp return-to-last-position move.
Very slight delay on spindle start, but the encoder positions don't lie - following looks tight. Sub PID is still open-loop.
Still to work out...
mux2 #1 to connect main spindle encoder position to subspindle stepgen position-command
mux2 #2 to switch sub stepgen-type from velocity to position mode
Now the main spindle accel/decel PID doesn't matter as the sub just follows the main, including the caxis.comp return-to-last-position move.
Very slight delay on spindle start, but the encoder positions don't lie - following looks tight. Sub PID is still open-loop.
Still to work out...
- M-codes to
- Orient sub to 0
- enable/disable sync with the two mux2 selects
- Figure out how to set the sub position to the same value as the main position at enable.
- If I run the main by itself on sync enable the sub rotates at max speed to align the two positions. No following error as it's not an axis/joint... but still not ideal.
- Can't reset the main position as I'd lose the C-axis home or zero position
Attachments:
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
10 Feb 2024 23:21 #293042
by spumco
Replied by spumco on topic (Solved) Synchronize multiple spindles? (lathe subspindle)
Well that took some mental gymnastics but it works like magic now.
After a few days and a million iterations it finally sunk in what values and connections needed to be joined up.
First hurdle... Andy's 'sample-hold' mux2 just wasn't sinking in, no matter how many times I read it or fiddled around. Probaby a character defect on my part.
I did manage to understand that the whole point of his mux2 was to overcome the glaring deficiency in LCNC's standard sample-hold.comp. i.e. that it only works with s32 data type. So... what if I just copied the existing sample-hold.comp, substituted 'float' for 's32', and renamed & installed it?
Holy [insert vulgar exclamation here], it worked.
I now have a tidy sample-hold-float component and don't need the mysterious mux2 feeding back in to itself.
So now the logic looks like this, in English (mostly):
When enabled, neither spindle does 'catch-up' or wild antics.
Start the main spindle and the sub is tightly slaved to the main, including with CSS and when the main does the caxis.comp return-to-last position rapid.
Turn it off again, still no ill behavior - Magic.
So I now have:
Next step - interlocking so I can only turn on sync when spindles are stopped.
Side note - this comp seems really useful. Wonder if it should be added to the LCNC mainstream?
component sample_hold_float "Sample and Hold Float";
pin in float in;
pin in bit hold;
pin out float out;
function _ nofp;
license "GPL";
author "Stephen Wille Padnos & Spumco";
;;
FUNCTION(_) {
if (!hold) {
out = in;
}
}
############################################
###SYNCHRONIZE SUB WITH MAIN FOR PART-OFF###
############################################
net SPIN1-REVS <= hm2_[MESA](BOARD).0.encoder.00.position
net SPIN1-REVS => spindle.1.revs
#M100 sets ON / M101 sets OFF
net SPIN1-SYNC-CMD => mux2.s1synccmd.sel
net SPIN1-SYNC-CMD => mux2.s1syncstep.sel
net SPIN1-SYNC-CMD => sampholdf.s1.hold
#SUBTRACT SUB POSITION FROM MAIN POSITION
setp sum2.s1.gain1 -1
net SPIN0-REVS => sum2.s1.in0 #
net SPIN1-REVS => sum2.s1.in1 #
net SPIN1-REVS-OFFSET <= sum2.s1.out #
#LATCH POSITION DIFFERENCE AT SYNC (CUSTOM SAMPLE-HOLD-FLOAT COMP)
net SPIN1-REVS-OFFSET => sampholdf.s1.in #
net SPIN-REVS-HOLD <= sampholdf.s1.out #
#SUBTRACT LATCHED VALUE FROM CURRENT MAIN POSITION
setp sum2.s1sync.gain1 -1
net SPIN0-REVS => sum2.s1sync.in0 #
net SPIN1-REVS-HOLD => sum2.s1sync.in1 #
net SPIN1-REVS-SYNC <= sum2.s1sync.out #
#SEND MAIN POSITION MINUS OFFSET TO SUB STEPGEN
net SPIN1-REVS => mux2.s1synccmd.in0 #SUB NORMAL OUTPUT
net SPIN1-REVS-SYNC => mux2.s1synccmd.in1 #SUB SYNCH W/MAIN
net SPIN1-SYNC-OUT <= mux2.s1synccmd.out
net SPIN1-SYNC-OUT => hm2_[MESA](BOARD).0.stepgen.03.position-cmd
#SWITCH STEPGEN FROM VELOCITY TO POSITION AT SYNC
setp mux2.s1syncstep.in0 1
setp mux2.s1syncstep.in1 0
net SPIN1-STEP-SEL <= mux2.s1syncstep.out
net SPIN1-STEP-SEL => conv_fu32_s1sync.in
net SPIN1-STEP-SEL-U32 <= conv_fu32_s1sync.out
net SPIN1-STEP-SEL-U32 => conv_u32b_s1sync.in
net SPIN1-STEP-SEL-BIT <= conv_u32b_s1sync.out
net SPIN1-STEP-SEL-BIT => hm2_[MESA](BOARD).0.stepgen.03.control-type
After a few days and a million iterations it finally sunk in what values and connections needed to be joined up.
First hurdle... Andy's 'sample-hold' mux2 just wasn't sinking in, no matter how many times I read it or fiddled around. Probaby a character defect on my part.
I did manage to understand that the whole point of his mux2 was to overcome the glaring deficiency in LCNC's standard sample-hold.comp. i.e. that it only works with s32 data type. So... what if I just copied the existing sample-hold.comp, substituted 'float' for 's32', and renamed & installed it?
Holy [insert vulgar exclamation here], it worked.
I now have a tidy sample-hold-float component and don't need the mysterious mux2 feeding back in to itself.
So now the logic looks like this, in English (mostly):
- sum2 #1: main-spin position - sub-spin position = sub position offset
- sum2 #2: main-spin position - latched sub offset = difference between main and sub is 'locked'
- At synch command
- Sample-hold-float - capture sub position offset value from sum2 #1
- Mux2 #1 - switch sub stepgen from velocity to position mode
- Mux2 #2 - sum2 #2 sent to sub stepgen position command
When enabled, neither spindle does 'catch-up' or wild antics.
Start the main spindle and the sub is tightly slaved to the main, including with CSS and when the main does the caxis.comp return-to-last position rapid.
Turn it off again, still no ill behavior - Magic.
So I now have:
- C-axis main spindle
- Subspindle w/CSS & orient
- Synchronized main & sub w/CSS on-demand
Next step - interlocking so I can only turn on sync when spindles are stopped.
Side note - this comp seems really useful. Wonder if it should be added to the LCNC mainstream?
Warning: Spoiler!
component sample_hold_float "Sample and Hold Float";
pin in float in;
pin in bit hold;
pin out float out;
function _ nofp;
license "GPL";
author "Stephen Wille Padnos & Spumco";
;;
FUNCTION(_) {
if (!hold) {
out = in;
}
}
Warning: Spoiler!
############################################
###SYNCHRONIZE SUB WITH MAIN FOR PART-OFF###
############################################
net SPIN1-REVS <= hm2_[MESA](BOARD).0.encoder.00.position
net SPIN1-REVS => spindle.1.revs
#M100 sets ON / M101 sets OFF
net SPIN1-SYNC-CMD => mux2.s1synccmd.sel
net SPIN1-SYNC-CMD => mux2.s1syncstep.sel
net SPIN1-SYNC-CMD => sampholdf.s1.hold
#SUBTRACT SUB POSITION FROM MAIN POSITION
setp sum2.s1.gain1 -1
net SPIN0-REVS => sum2.s1.in0 #
net SPIN1-REVS => sum2.s1.in1 #
net SPIN1-REVS-OFFSET <= sum2.s1.out #
#LATCH POSITION DIFFERENCE AT SYNC (CUSTOM SAMPLE-HOLD-FLOAT COMP)
net SPIN1-REVS-OFFSET => sampholdf.s1.in #
net SPIN-REVS-HOLD <= sampholdf.s1.out #
#SUBTRACT LATCHED VALUE FROM CURRENT MAIN POSITION
setp sum2.s1sync.gain1 -1
net SPIN0-REVS => sum2.s1sync.in0 #
net SPIN1-REVS-HOLD => sum2.s1sync.in1 #
net SPIN1-REVS-SYNC <= sum2.s1sync.out #
#SEND MAIN POSITION MINUS OFFSET TO SUB STEPGEN
net SPIN1-REVS => mux2.s1synccmd.in0 #SUB NORMAL OUTPUT
net SPIN1-REVS-SYNC => mux2.s1synccmd.in1 #SUB SYNCH W/MAIN
net SPIN1-SYNC-OUT <= mux2.s1synccmd.out
net SPIN1-SYNC-OUT => hm2_[MESA](BOARD).0.stepgen.03.position-cmd
#SWITCH STEPGEN FROM VELOCITY TO POSITION AT SYNC
setp mux2.s1syncstep.in0 1
setp mux2.s1syncstep.in1 0
net SPIN1-STEP-SEL <= mux2.s1syncstep.out
net SPIN1-STEP-SEL => conv_fu32_s1sync.in
net SPIN1-STEP-SEL-U32 <= conv_fu32_s1sync.out
net SPIN1-STEP-SEL-U32 => conv_u32b_s1sync.in
net SPIN1-STEP-SEL-BIT <= conv_u32b_s1sync.out
net SPIN1-STEP-SEL-BIT => hm2_[MESA](BOARD).0.stepgen.03.control-type
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19201
- Thank you received: 6436
10 Feb 2024 23:40 #293045
by tommylight
Replied by tommylight on topic (Solved) Synchronize multiple spindles? (lathe subspindle)
Shooting from the hip here, but since the comp is quite simple, maybe adding a check for both spindle speeds could be easy enough by getting the spindle.0.out and spindle.1.out or whatever spindle out values are in use (getting rusty here) and sending those through inverted and2.
Also renaming the comp to avoid confusion.
Great work, and thank you for detailed explanations.
Also renaming the comp to avoid confusion.
Great work, and thank you for detailed explanations.
The following user(s) said Thank You: spumco
Please Log in or Create an account to join the conversation.
11 Feb 2024 00:29 #293047
by spumco
Replied by spumco on topic (Solved) Synchronize multiple spindles? (lathe subspindle)
I named the new file 'sample-hold-float.comp' before running halcompile. Couldn't believe it was that easy.
I'm not too worried about the spindle speed interlock. I've already got an interlock in classic ladder so my drawbars can't open while the spindles are running. I'll probably tie the M100/M101 to another rung with the same interlock so I can't sync or unsync unless the spindles are stopped.
I'm not too worried about the spindle speed interlock. I've already got an interlock in classic ladder so my drawbars can't open while the spindles are running. I'll probably tie the M100/M101 to another rung with the same interlock so I can't sync or unsync unless the spindles are stopped.
The following user(s) said Thank You: jpg
Please Log in or Create an account to join the conversation.
13 Feb 2024 02:05 #293186
by spumco
Replied by spumco on topic (Solved) Synchronize multiple spindles? (lathe subspindle)
Last piece of the puzzle is driving me nuts.
While watching the sub do it's thing, it occurred to me that the sub needs to spin opposite the main during normal M3 commands. Reason being that the backside tooling hasn't changed handedness, and a RH drill or tap needs a 'normal' M3 spindle direction.
But they still need to turn the same direction when synchronized.
Step 1 - reprogram drive so M3 results in opposite direction. Done.
Step 2 - reprogram drive so M3 results in positive encoder direction. Done
So now I've got to rearrange the encoder value choreography somehow so that
Any bright ideas?
Current not-working attempt:
#SYNC - SUBTRACT DIFFERENCE BETWEEN MAIN AND SUB POSITION
setp sum2.s1.gain1 -1
net SPIN0-REVS => sum2.s1.in0 #MAIN SPIN ENCODER POSITION
net SPIN1-REVS => sum2.s1.in1 #SUB SPIN ENCODER POSITION
net SPIN1-REVS-OFFSET <= sum2.s1.out
#SYNC - LATCH DIFFERENCE BETWEEN MAIN AND SUB POSITION (CUSTOM SAMPLE-HOLD-FLOAT COMP)
net SPIN1-REVS-OFFSET => sampholdf.s1.in
net SPIN1-REVS-HOLD <= sampholdf.s1.out #MAIN TO SUB OFFSET VALUE
net SPIN1-REVS-HOLD-ABS => abs.s1sync.in
net SPIN1-REVS-HOLD-ABS => abs.s1sync.out
#SYNC - SUBTRACT LATCHED DIFFERENCE VALUE FROM MAIN POSITION
setp sum2.s1sync.gain1 -1
net SPIN0-REVS => sum2.s1sync.in0
net SPIN1-REVS-HOLD-ABS => sum2.s1sync.in1
net SPIN1-REVS-SYNC <= sum2.s1sync.out #MAIN POSITION MINUS SUB OFFSET
#SYNC - INVERT MAIN SPINDLE POSITION VALUE
setp scale.s1sync.gain -1
net SPIN1-REVS-SYNC => scale.s1sync.in #MAIN POSITION MINUS SUB OFFSET
net SPIN1-REVS-SYNC-INV <= scale.s1sync.out #MAIN POSITION MINUS SUB OFFSET INVERTED
#SYNC - SEND OFFSET MAIN POSITION TO SUB STEPGEN POSITION CMD
net SPIN1-REVS-SYNC-INV => mux2.s1synccmd.in1 #SYNC ON
net SPIN1-SYNC-OUT <= mux2.s1synccmd.out
net SPIN1-SYNC-OUT => hm2_[MESA](BOARD).0.stepgen.03.position-cmd
While watching the sub do it's thing, it occurred to me that the sub needs to spin opposite the main during normal M3 commands. Reason being that the backside tooling hasn't changed handedness, and a RH drill or tap needs a 'normal' M3 spindle direction.
But they still need to turn the same direction when synchronized.
Step 1 - reprogram drive so M3 results in opposite direction. Done.
Step 2 - reprogram drive so M3 results in positive encoder direction. Done
So now I've got to rearrange the encoder value choreography somehow so that
- Main-spin encoder count increase
- Opposite output to sub stepgen
- AND the offset remains the same
Any bright ideas?
Current not-working attempt:
Warning: Spoiler!
#SYNC - SUBTRACT DIFFERENCE BETWEEN MAIN AND SUB POSITION
setp sum2.s1.gain1 -1
net SPIN0-REVS => sum2.s1.in0 #MAIN SPIN ENCODER POSITION
net SPIN1-REVS => sum2.s1.in1 #SUB SPIN ENCODER POSITION
net SPIN1-REVS-OFFSET <= sum2.s1.out
#SYNC - LATCH DIFFERENCE BETWEEN MAIN AND SUB POSITION (CUSTOM SAMPLE-HOLD-FLOAT COMP)
net SPIN1-REVS-OFFSET => sampholdf.s1.in
net SPIN1-REVS-HOLD <= sampholdf.s1.out #MAIN TO SUB OFFSET VALUE
net SPIN1-REVS-HOLD-ABS => abs.s1sync.in
net SPIN1-REVS-HOLD-ABS => abs.s1sync.out
#SYNC - SUBTRACT LATCHED DIFFERENCE VALUE FROM MAIN POSITION
setp sum2.s1sync.gain1 -1
net SPIN0-REVS => sum2.s1sync.in0
net SPIN1-REVS-HOLD-ABS => sum2.s1sync.in1
net SPIN1-REVS-SYNC <= sum2.s1sync.out #MAIN POSITION MINUS SUB OFFSET
#SYNC - INVERT MAIN SPINDLE POSITION VALUE
setp scale.s1sync.gain -1
net SPIN1-REVS-SYNC => scale.s1sync.in #MAIN POSITION MINUS SUB OFFSET
net SPIN1-REVS-SYNC-INV <= scale.s1sync.out #MAIN POSITION MINUS SUB OFFSET INVERTED
#SYNC - SEND OFFSET MAIN POSITION TO SUB STEPGEN POSITION CMD
net SPIN1-REVS-SYNC-INV => mux2.s1synccmd.in1 #SYNC ON
net SPIN1-SYNC-OUT <= mux2.s1synccmd.out
net SPIN1-SYNC-OUT => hm2_[MESA](BOARD).0.stepgen.03.position-cmd
Please Log in or Create an account to join the conversation.
13 Feb 2024 05:12 #293196
by spumco
Replied by spumco on topic (Solved) Synchronize multiple spindles? (lathe subspindle)
YES!
Trick is not to worry about the offset.
My brain is hamburger now, but I have a well-behaved subspindle that rotates opposite the main at M3 while rotating with the main when synchronized.
@Tommy - you want me to change the title to [SOLVED]?
Trick is not to worry about the offset.
- Step 1
- Sample-hold the main position
- Sample-hold the sub position
- Step 2
- Subtract main position from latched main value
- This is the incremental value the main moves
- Step 3
- Invert the increment value
- Step 4
- Add the inverted increment value to the latched sub position
- Step 5
- Send the incrementing position to the stepgen position
My brain is hamburger now, but I have a well-behaved subspindle that rotates opposite the main at M3 while rotating with the main when synchronized.
@Tommy - you want me to change the title to [SOLVED]?
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19201
- Thank you received: 6436
13 Feb 2024 12:51 #293219
by tommylight
Replied by tommylight on topic (Solved) Synchronize multiple spindles? (lathe subspindle)
Done, thank you.
The following user(s) said Thank You: spumco
Please Log in or Create an account to join the conversation.
- Configuring LinuxCNC
- Advanced Configuration
- (Solved) Synchronize multiple spindles? (lathe subspindle)
Time to create page: 0.093 seconds