Need help with the orient component for spindle activation (M19)

More
15 Mar 2022 19:13 #237361 by jpg
I put back the "spindle HAL" part if you have an idea :


# HAL config file for vismach simulation of vertical milling machine
# This file deomstrates closed-loop spindle control in both position and 
loadrt encoder num_chan=2
loadrt abs count=1
loadrt scale count=1
loadrt lowpass count=1
loadrt pwmgen output_type=1
loadrt or2 count=3



addf encoder.update-counters base-thread
addf pwmgen.make-pulses base-thread


loadrt mult2 count=1
addf mult2.0            servo-thread

addf encoder.capture-position servo-thread

addf pwmgen.update servo-thread
addf abs.0 servo-thread
addf scale.0 servo-thread
addf lowpass.0 servo-thread
addf or2.0 servo-thread
addf or2.1 servo-thread

#net spindle-cmd-rpm => pwmgen.0.value
#net spindle-on <= motion.spindle-on => pwmgen.0.enable
net spindle-pwm <= pwmgen.0.pwm
setp pwmgen.0.pwm-freq 0.0
setp pwmgen.0.scale 1500.0
setp pwmgen.0.offset 0.133333333333

setp pwmgen.0.dither-pwm true
#net spindle-cmd-rpm     <= motion.spindle-speed-out
net spindle-cmd-rpm-abs <= motion.spindle-speed-out-abs
net spindle-cmd-rps     <= motion.spindle-speed-out-rps
net spindle-cmd-rps-abs <= motion.spindle-speed-out-rps-abs
net spindle-at-speed    => motion.spindle-at-speed
net spindle-cw <= motion.spindle-forward
net spindle-ccw <= motion.spindle-reverse

setp encoder.0.position-scale 800.000000
#net spindle-position encoder.0.position => motion.spindle-revs
#net spindle-velocity-feedback-rps encoder.0.velocity => motion.spindle-speed-in
net spindle-index-enable encoder.0.index-enable <=> motion.spindle-index-enable
net spindle-phase-a encoder.0.phase-A
net spindle-phase-b encoder.0.phase-B
net spindle-index encoder.0.phase-Z


#net spindle-cw      => parport.0.pin-14-out
#net spindle-ccw     => parport.0.pin-16-out
setp parport.0.pin-17-out-invert 1
net spindle-pwm     pwmgen.0.pwm parport.0.pin-17-out
net spindle-index   <= parport.0.pin-11-in-not
net spindle-phase-b <= parport.0.pin-12-in
net spindle-phase-a <= parport.0.pin-13-in



#net spindle-on <= motion.spindle-on  

# Velocity modes. 

# see wiki.linuxcnc.org/cgi-bin/wiki.pl?SpindleOrient for a diagram

# Note that the connections of the signals to "hardware" are all in the 
# sim_vmc.hal file rather than here

# First load 2x pid components. These would normally have to be loaded at
# the same time as the Axis PID components

loadrt pid num_chan=2 
addf pid.0.do-pid-calcs servo-thread # Velocity
addf pid.1.do-pid-calcs servo-thread # Position

loadrt orient
addf orient.0 servo-thread

loadrt mux2 #This has already been loaded in the sim_vmc.hal
addf mux2.0 servo-thread # chooses which pid output goes to the spindle speed control

#Use this to detect that the spindle is oriented
#in the 2.8 release there will be a pin for this as an output of the orient comp
#and the edge-detector isn't needed

loadrt near count=1  #(loaded in sim_vmc.hal)
loadrt edge
addf near.0         servo-thread
addf edge.0         servo-thread
setp edge.0.both 0
setp edge.0.in-edge 0
setp edge.0.out-width-ns 10000000

net spindle-pos pid.1.feedback orient.0.position

net spindle-vel     pid.0.feedback  encoder.0.velocity => motion.spindle-speed-in
net spindle-vel-cmd     motion.spindle-speed-out pid.0.command
net spindle-vel-pid     pid.0.output mux2.0.in0

net spindle-pos     pid.1.feedback orient.0.position near.0.in1  encoder.0.position => motion.spindle-revs 
net spindle-pos-cmd     orient.0.command pid.1.command near.0.in2
net spindle-angle     motion.spindle-orient-angle orient.0.angle
net spindle-pos-pid     pid.1.output mux2.0.in1
setp near.0.difference  0.0005
net spindle-in-pos-raw near.0.out edge.0.in #not needed v2.8+, use orient.0.is-oriented
net spindle-in-pos     edge.0.out motion.spindle-is-oriented

# this switches modes
net orient-mode     motion.spindle-orient orient.0.enable pid.1.enable mux2.0.sel
net velocity-mode    motion.spindle-on pid.0.enable pwmgen.0.enable 
net orient-dir        motion.spindle-orient-mode orient.0.mode

# this is simple for the simulated spindle.
#net spindle-cmd     mux2.0.out

#for a real spindle run by a VFD
# loadrt abs
# addf abs.0.servo-thread
net spindle-cmd-fb-filtered-rps     mux2.0.out   abs.0.in
net spindle-fb-filtered-cmd-abs-rpm     abs.0.out pwmgen.0.value => scale.0.in
#net spindle-fb-filtered-abs-rps  abs.0.out =>   scale.0.in
setp parport.0.pin-17-out-invert 1
net spindle-pwm     pwmgen.0.pwm parport.0.pin-17-out
net spindle-fwd     abs.0.is-positive parport.0.pin-14-out
net spindle-rev     abs.0.is-negative parport.0.pin-16-out

# Tune the PID from the INI values
setp pid.0.Pgain [SPINDLE]PGAIN_V
setp pid.0.Igain [SPINDLE]IGAIN_V
setp pid.0.Dgain [SPINDLE]DGAIN_V
setp pid.0.FF0     [SPINDLE]FF0_V
setp pid.0.FF1   [SPINDLE]FF1_V
setp pid.1.Pgain [SPINDLE]PGAIN_P
setp pid.1.Igain [SPINDLE]IGAIN_P
setp pid.1.Dgain [SPINDLE]DGAIN_P
setp pid.1.FF0     [SPINDLE]FF0_P
setp pid.1.FF1   [SPINDLE]FF1_P
 

Please Log in or Create an account to join the conversation.

More
15 Mar 2022 21:50 #237388 by andypugh
# this switches modes
net orient-mode     motion.spindle-orient orient.0.enable pid.1.enable mux2.0.sel
net velocity-mode    motion.spindle-on pid.0.enable pwmgen.0.enable 
net orient-dir        motion.spindle-orient-mode orient.0.mode

Is pwmgen.0.enable set in orient mode? It looks like it isn't.

Please Log in or Create an account to join the conversation.

More
15 Mar 2022 21:57 #237390 by jpg
How to define it in this mode?

Please Log in or Create an account to join the conversation.

More
15 Mar 2022 23:51 #237413 by andypugh
Can you check with halmeter if it is or isn't enabled first?

If it isn't, then the answer is probably an "or2" component so that the pwmgen is enabled if the spindle is on or orient is active. Something a bit like:
loadrt or2
...
addf or2.0 servo-thread
...
# this switches modes
net orient-mode     motion.spindle-orient orient.0.enable pid.1.enable mux2.0.sel or2.0.in0
net velocity-mode    motion.spindle-on pid.0.enable or2.0.in1
net spindle-pwm-enable or2.0.out pwmgen.0.enable 
net orient-dir        motion.spindle-orient-mode orient.0.mode

But it is likely that you already have an or2 loaded somewhere, so need to add an extra and then this new one won't be or2.0
The following user(s) said Thank You: jpg

Please Log in or Create an account to join the conversation.

More
16 Mar 2022 05:39 - 16 Mar 2022 06:01 #237435 by jpg
Thanks Andy, I'm watching this tonight when I get home from work and nothing changes?

"net spindle-fwd     abs.0.is-positive parport.0.pin-14-out
net spindle-rev     abs.0.is-negative parport.0.pin-16-out"


well, I just tried it, ... it works both ways!! yes!! bravo and a big thank you to you Andy :-)
there is just a little curious thing, when I type M19 r25 (and only with this value), the spindle does not stop and starts again in the other direction and only with this value, curious

 
Last edit: 16 Mar 2022 06:01 by jpg.

Please Log in or Create an account to join the conversation.

More
16 Mar 2022 11:10 #237458 by andypugh
Have you tried tuning the PID values?

Please Log in or Create an account to join the conversation.

More
16 Mar 2022 12:17 #237463 by jpg
hello, I try your values tonight, but I already noticed that with M19 R25 , ORIENT do not stop
you have to type M5

Please Log in or Create an account to join the conversation.

More
16 Mar 2022 12:31 #237465 by andypugh
"Tuning" isn't using my values, it is adjusting the values to get the best response. I have no way to know what the right numbers are.

As for the not stopping thing, does it oscillate around the set angle, or does it rotate continuously?
The following user(s) said Thank You: jpg

Please Log in or Create an account to join the conversation.

More
16 Mar 2022 18:45 - 16 Mar 2022 18:49 #237484 by jpg
Good evening Andy, I have just made some tests by modifying INI, the whole works very well, what is just curious, they are specific values which do not stop the spindle in ORIENT mode, I noted these values there: M19 r25, r65 and r155 (with these values, the spindle does not stop and restarts in the other direction) the values M19 R24.9 work (finally, the spindle stops), ORIENT seems to be allergic to these 3 angles, strange?


 
Last edit: 16 Mar 2022 18:49 by jpg.

Please Log in or Create an account to join the conversation.

More
16 Mar 2022 19:21 #237487 by andypugh
Very, very strange.

Do you need those angles, or just 0 for toolchange?

Please Log in or Create an account to join the conversation.

Time to create page: 0.126 seconds
Powered by Kunena Forum