Super-PID spindle speed feedback

More
21 Nov 2014 08:29 #53255 by Delron
Hi all!

I have a Super-PID running.... mostly, but tuning the PWM for linear speed control is busting my but.
But what is really confusing me is getting LinuxCNC to read the RPM from the TACK output on the Super-PID to use for "Spindle-At-Speed" and "Spindle-Speed" components.
I've been scouring the site and simple getting very confused.

Can anyone offer some expearenced advise?

Thanks in advance for any help.

Cheers!

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

More
23 Nov 2014 02:37 #53297 by cmorley
Took me a while to realize what a super-PID was...
What kind of signal does it return to linuxcnc for feedback?

Chris M

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

More
23 Nov 2014 06:56 #53302 by BobS
Delron:

I connected the superPID tach output to a LinuxCNC encoder with the encoder in 'counter-mode'. Here is the relevant section of the .hal file for spindle control (both input and output). Note I use a MesaNet motion control card but using the parallel port driver ought to be similar.

--- (cut) ---

##################
# Spindle
##################

setp hm2_5i25.0.pwmgen.00.scale 30150
setp hm2_5i25.0.pwmgen.pwm_frequency 50

# gpio pins default to input
setp hm2_5i25.0.gpio.007.is_output TRUE
net spindle-enable motion.spindle-on => hm2_5i25.0.gpio.007.out

net spindle-speed-cmd motion.spindle-speed-out => hm2_5i25.0.pwmgen.00.value
net spindle-enable => hm2_5i25.0.pwmgen.00.enable

setp hm2_5i25.0.encoder.00.counter-mode TRUE
net spindle-velocity hm2_5i25.0.encoder.00.velocity => motion.spindle-speed-in

--- (cut) ---

HTH

BobS

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

More
24 Nov 2014 05:58 #53331 by Delron
Hi Chis,

The tack output to the PID is a single 5v pulse per revolution to the BOB (LinuxCNC).
I have got an encoder running and seeing it, but the spindle velocity number being returned by HAL is not even close to 1-to-1. It's also jumpy, so some filtering and scaling must be required.
I've pulled my hair out trying everything I can find, but it's been overwhelming.

Cheers!

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

More
24 Nov 2014 06:02 #53333 by Delron
Hi BobS,

Thanks for the info. Looks like your encoder setup is pretty simple. Your Mesa board must make it a simpler endeavour?

Cheers!

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

More
24 Nov 2014 06:07 - 24 Nov 2014 20:30 #53334 by Delron
Here is my HAL file.


# Generated by stepconf at Sat Mar  8 15:23:39 2014
# If you make changes to this file, they will be
# overwritten when you run stepconf again
loadrt trivkins
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt probe_parport
loadrt hal_parport cfg="0x378 out 0xdcf0 in "
setp parport.0.reset-time 3000
loadrt stepgen step_type=0,0,0
loadrt pwmgen output_type=0
loadrt abs count=1
loadrt classicladder_rt numPhysInputs=15 numPhysOutputs=15 numS32in=10 numS32out=10 numFloatIn=10 numFloatOut=10
loadrt debounce cfg=4
setp debounce.0.delay 20
addf debounce.0 base-thread

addf parport.0.read base-thread
addf parport.0.write base-thread
addf parport.0.reset base-thread
addf parport.1.read base-thread
addf parport.1.write base-thread
addf parport.1.reset base-thread
addf stepgen.make-pulses base-thread
addf pwmgen.make-pulses base-thread

addf stepgen.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf classicladder.0.refresh servo-thread
addf stepgen.update-freq servo-thread
addf pwmgen.update servo-thread
addf abs.0 servo-thread


#*******************
#	SPINDLE
#*******************
loadrt encoder
addf encoder.update-counters base-thread
addf encoder.capture-position servo-thread
setp encoder.0.position-scale 1
setp encoder.0.counter-mode 1
net spindle-velocity encoder.0.velocity => motion.spindle-speed-in
net spindle-pulse parport.1.pin-15-in => encoder.0.phase-A
net spindle-at-speed => motion.spindle-at-speed


net spindle-cmd <= motion.spindle-speed-out => pwmgen.0.value
net spindle-on <= motion.spindle-on => pwmgen.0.enable
net spindle-pwm <= pwmgen.0.pwm => parport.1.pin-16-out
setp pwmgen.0.pwm-freq 50.0
setp pwmgen.0.scale 30050.0
setp pwmgen.0.offset 0.000998336106489
setp pwmgen.0.dither-pwm true
net spindle-at-speed => motion.spindle-at-speed
setp parport.1.pin-17-out-invert 1
net spindle-on => parport.1.pin-17-out


#*******************
#	PROBE
#*******************
net debounce-probe-in debounce.0.3.in <= parport.0.pin-11-in
net probe-in debounce.0.3.out => motion.probe-input
net probe-in => motion.probe-input
net dout-02 <= motion.digital-out-02


#*******************
#	HOMING
#*******************
net debounce-home-x debounce.0.0.in <= parport.0.pin-12-in-not
net home-x debounce.0.0.out
net debounce-home-y debounce.0.1.in <= parport.0.pin-13-in-not
net home-y debounce.0.1.out
net debounce-home-z debounce.0.2.in <= parport.0.pin-15-in-not
net home-z debounce.0.2.out


net estop-ext <= parport.0.pin-10-in
net xstep => parport.0.pin-02-out
setp parport.0.pin-02-out-reset 1
net xdir => parport.0.pin-03-out
net ystep => parport.0.pin-04-out
setp parport.0.pin-04-out-reset 1
setp parport.0.pin-05-out-invert 1
net ydir => parport.0.pin-05-out
net ystep => parport.0.pin-06-out
setp parport.0.pin-06-out-reset 1
setp parport.0.pin-07-out-invert 1
net ydir => parport.0.pin-07-out
net zstep => parport.0.pin-08-out
setp parport.0.pin-08-out-reset 1
setp parport.0.pin-09-out-invert 1
net zdir => parport.0.pin-09-out


setp stepgen.0.position-scale [AXIS_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 0
setp stepgen.0.dirhold 28000
setp stepgen.0.dirsetup 28000
setp stepgen.0.maxaccel [AXIS_0]STEPGEN_MAXACCEL
net xpos-cmd axis.0.motor-pos-cmd => stepgen.0.position-cmd
net xpos-fb stepgen.0.position-fb => axis.0.motor-pos-fb
net xstep <= stepgen.0.step
net xdir <= stepgen.0.dir
net xenable axis.0.amp-enable-out => stepgen.0.enable
net home-x => axis.0.home-sw-in

setp stepgen.1.position-scale [AXIS_1]SCALE
setp stepgen.1.steplen 1
setp stepgen.1.stepspace 0
setp stepgen.1.dirhold 28000
setp stepgen.1.dirsetup 28000
setp stepgen.1.maxaccel [AXIS_1]STEPGEN_MAXACCEL
net ypos-cmd axis.1.motor-pos-cmd => stepgen.1.position-cmd
net ypos-fb stepgen.1.position-fb => axis.1.motor-pos-fb
net ystep <= stepgen.1.step
net ydir <= stepgen.1.dir
net yenable axis.1.amp-enable-out => stepgen.1.enable
net home-y => axis.1.home-sw-in

setp stepgen.2.position-scale [AXIS_2]SCALE
setp stepgen.2.steplen 1
setp stepgen.2.stepspace 0
setp stepgen.2.dirhold 28000
setp stepgen.2.dirsetup 28000
setp stepgen.2.maxaccel [AXIS_2]STEPGEN_MAXACCEL
net zpos-cmd axis.2.motor-pos-cmd => stepgen.2.position-cmd
net zpos-fb stepgen.2.position-fb => axis.2.motor-pos-fb
net zstep <= stepgen.2.step
net zdir <= stepgen.2.dir
net zenable axis.2.amp-enable-out => stepgen.2.enable
net home-z => axis.2.home-sw-in

net estop-out <= iocontrol.0.user-enable-out
net estop-ext => iocontrol.0.emc-enable-in

loadusr -W hal_manualtoolchange
net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change
net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
Last edit: 24 Nov 2014 20:30 by BigJohnT. Reason: add code tags

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

More
24 Nov 2014 06:18 #53335 by Delron
I forgot to say that I did manage to get the control out to the PID working linear and well.

What I'm still having trouble with is the tack signal back to LinuxCNC to get the RPM meter and "Spindle-At-Speed" control working properly.

Problem is the spindle can take a second or two to get up to speed and has crashed my bit in the work piece as a result.
I have to start the job, then quickly pause, click spindle on, wait, then hit resume to avoid hitting the piece before the bit is up to speed.
A little annoying to say the least.

Thanks again for any help you can offer.

Cheers!

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

More
24 Nov 2014 07:56 #53341 by BobS
In your G-code add G4 P... just after turning on the spindle to allow it time to spool up.

...
(turn on spindle CW and set speed to 12000 RPM)
M3 S12000
(dwell 4 seconds for spindle to spool up)
G4 P4.0
...

BobS

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

More
25 Nov 2014 07:11 #53367 by andypugh

What I'm still having trouble with is the tack signal back to LinuxCNC to get the RPM meter and "Spindle-At-Speed" control working properly.


Firstly you might need to set the encoder scale to 60 rather than 1 to get rpm. The encoder velocity is revs per second.

To filter the speed you can use "lowpass". The man-page is here, and contains all the information you need:
www.linuxcnc.org/docs/html/man/man9/lowpass.9.html

When I say "all the information you need" that is nothing like the same as claiming that it tells you how to use the component.

The Synopsis tell you how to load the component into HAL. In this case
loadrt lowpass count=1

The Function tells you what the HAL name of the component is that you add to a thread in HAL. in this case
addf lowpass.0  servo-thread

The Pins tell you how to connect it in HAL. Without seeing your HAL file I need to guess here, but something like
net this-is-the-unfiltered-speed encoder.0.velocity => lowpass.0.in
#At this point the RPM meter hasn't been created and I haven't got round to at-speed yet
#So this signal as-yet has no input pins.
net and-this-is-the-filtered-speed lowpass.0.out
Note that a "net" command is always followed by a signal name that you can choose freely yourself, then as many pin names (that must already exist, having been created by a component) as needed.
And in this case the filter constant is set by a parameter. You will need to tweak this to suit.
setp lowpass.0.gain 0.99

Normally for spindle-at-speed folk use the "near" component:
www.linuxcnc.org/docs/html/man/man9/near.9.html

Again, the information is there, but no clues how to use that information.
loadrt near count=1
addf near.0 servo-thread
#we already created a signal to hold the filtered value, use it again.
net and-this-is-the-filtered-speed near.0.in1
# I have no idea what your HAL file uses for the spindle velocity signa;
net spindle-velocity-command near.0.in2
net spindle-at-speed-flag near.0.out => motion.spindle-at-speed
And, finally, the parameter that sets how near is "near"
setp near.0.scale 0.9

If you want the list of "motion" pins, here they are:
www.linuxcnc.org/docs/html/man/man9/motion.9.html
And, in fact, all the HAL components you can use are near the bottom here:
www.linuxcnc.org/docs/html/

To set up the spindle speed gauge you need something like
net and-this-is-the-filtered-speed pyvcp.spindle-speed
But that has to be in the postgui HAL file that runs after the GUI has created a spindle speed meter to link to.
The following user(s) said Thank You: Delron

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

More
26 Nov 2014 07:53 - 26 Nov 2014 07:56 #53418 by Delron
Thanks Andy!

I tried to implement your ideas, but still having some issues.
I scaled the encoder to see the proper RPM. Had to use 0.0165, not 60.
The lowpass component does not seem to affect the glitches I see. The RPM meter shows correctly, but every few seconds or so it can jump thousands in either direction.
Spindle at speed does not work at all.

Here are the relevant HAL lines in my setup.

my_mill.hal

#*******************
# SPINDLE
#*******************
loadrt scale count=1
loadrt lowpass count=1
addf lowpass.0 servo-thread
loadrt encoder num_chan=1
addf encoder.update-counters base-thread
addf encoder.capture-position servo-thread
setp encoder.0.position-scale 0.0165
setp encoder.0.counter-mode 1
net spindle-velocity encoder.0.velocity => motion.spindle-speed-in
net spindle-pulse parport.1.pin-15-in => encoder.0.phase-A

#net spindle-at-speed => motion.spindle-at-speed

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

net spindle-cmd <= motion.spindle-speed-out => pwmgen.0.value
net spindle-on <= motion.spindle-on => pwmgen.0.enable
net spindle-pwm <= pwmgen.0.pwm => parport.1.pin-16-out
setp pwmgen.0.pwm-freq 50.0
setp pwmgen.0.scale 30050.0
setp pwmgen.0.offset 0.000998336106489
setp pwmgen.0.dither-pwm true
net spindle-at-speed => motion.spindle-at-speed
setp parport.1.pin-17-out-invert 1
net spindle-on => parport.1.pin-17-out





custom_postgui.hal

# **** Setup of spindle speed display using pyvcp -START ****

# set the spindle speed inputs to agree if within 1%
setp scale.0.gain 1
setp lowpass.0.gain 0.010000
net spindle-velocity => lowpass.0.in
net spindle-fb-filtered-rps lowpass.0.out => abs.0.in
net spindle-fb-filtered-abs-rps abs.0.out => scale.0.in
#net spindle-fb-filtered-abs-rpm scale.0.out => pyvcp.spindle-speed
####the above rpm filters signal does not work at all. HAL meter shows "0" when running.
net spindle-velocity => pyvcp.spindle-speed




net spindle-at-speed => pyvcp.spindle-at-speed-led

# connect one input to the commanded spindle speed
net spindle-cmd => near.0.in1

# connect one input to the encoder-measured spindle speed
net spindle-velocity => near.0.in2

# connect the output to the spindle-at-speed input
net spindle-at-speed motion.spindle-at-speed <= near.0.out


Cheers!
Last edit: 26 Nov 2014 07:56 by Delron.

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

Time to create page: 0.841 seconds
Powered by Kunena Forum