SPINDLE PWB with PID and ENCODER

More
31 Aug 2012 05:05 - 31 Aug 2012 10:07 #23787 by aike
SPINDLE PWB with PID and ENCODER was created by aike
Hi!
I want to make spindle feedback with auto adjust speed using pid.
I use external encoder for 1000 ticks per round, very simple frequency invertor for 11KWt, AC asinchronous motor 10kW and Mesa 7I43 FPGA board.
All these items are in photos below.

Below is the text ini and hal file
The question:
Is PID setting right or not?


From .INI file
###############################################################################
#********************
# Spindle
#********************
[SPINDLE_9]
#MAX VELOCITY RPS
MAX_VELOCITY = 30.0
#FREQUENCY FOR INVERTOR
PWM_FREQUNCY = 2000
MAX_ACCELERATION = 20.0
#MAX - 1800 RPM
OUTPUT_SCALE = 1800.0
OUTPUT_OFFSET = 0.0
MAX_OUTPUT = 10.0
#ENCODR 1000 TICKS PER ROUND
INPUT_SCALE = 4000.0
DEADBAND = 0.01
###############################################################################

from .HAL file
###############################################################################
loadrt pid num_chan=3
loadrt sum2 count=1

addf sum2.0 servo-thread
addf pid.0.do-pid-calcs servo-thread
addf pid.1.do-pid-calcs servo-thread
addf pid.2.do-pid-calcs servo-thread


#*******************
# SPINDLE S
#*******************

# ---PWM Generator signals/setup---

setp hm2_[HOSTMOT2](BOARD).0.pwmgen.00.output-type 1
setp hm2_[HOSTMOT2](BOARD).0.pwmgen.00.scale [SPINDLE_9]OUTPUT_SCALE
setp hm2_[HOSTMOT2](BOARD).0.pwmgen.pwm_frequency [SPINDLE_9]PWM_FREQUNCY

# ---SPINDLE encoder setup---

setp hm2_[HOSTMOT2](BOARD).0.encoder.02.counter-mode 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.filter 1
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.index-invert 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.index-mask 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.index-mask-invert 0
setp hm2_[HOSTMOT2](BOARD).0.encoder.02.scale [SPINDLE_9]INPUT_SCALE

# ---SPINDLE PID setup---

setp pid.2.Pgain 1
setp pid.2.Igain 0
setp pid.2.Dgain 0
setp pid.2.bias 0
setp pid.2.FF0 0
setp pid.2.FF1 0
setp pid.2.FF2 0
setp pid.2.deadband [SPINDLE_9]DEADBAND
setp pid.2.maxoutput 0


# ---setup spindle control signals---

net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd <= motion.spindle-speed-out
net spindle-enable <= motion.spindle-on
net spindle-cw <= motion.spindle-forward
net spindle-ccw <= motion.spindle-reverse
net spindle-brake <= motion.spindle-brake
net spindle-revs => motion.spindle-revs
net spindle-at-speed => motion.spindle-at-speed
net spindle-vel-fb => motion.spindle-speed-in
net spindle-index-enable <=> motion.spindle-index-enable

net spindle-revs <= hm2_[HOSTMOT2](BOARD).0.encoder.02.position
net spindle-vel-fb <= hm2_[HOSTMOT2](BOARD).0.encoder.02.velocity
net spindle-index-enable <=> hm2_[HOSTMOT2](BOARD).0.encoder.02.index-enable

# --- SPINDLE ENABLE ---
net spindle-enable => hm2_[HOSTMOT2](BOARD).0.pwmgen.00.enable

# --- SPINDLE ABSOLUT VELOCITY ---
net absolute-spindle-vel => hm2_[HOSTMOT2](BOARD).0.pwmgen.00.value


# ---PID/SPINDLE control signals

net spindle-vel-cmd-rps => pid.2.command
net spindle-vel-fb => pid.2.feedback
net spindle-enable => pid.2.enable
net spindle-pid-pre <= pid.2.output

#convert from round per second to round per minut
net spindle-pid-pre => sum2.0.in0
setp sum2.0.gain0 60

#sum the spindle velocity comand
net spindle-vel-cmd => sum2.0.in1

#the output signal pid+command
net spindle-pid-out <= sum2.0.out
net spindle-pid-out => abs.spindle.in

#the result for PWM gen
net absolute-spindle-vel <= abs.spindle.out
###############################################################################

the photo of
Attachments:
Last edit: 31 Aug 2012 10:07 by aike.

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

More
31 Aug 2012 05:19 - 31 Aug 2012 05:22 #23788 by aike
Replied by aike on topic Re:SPINDLE PWB with PID and ENCODER
photo below
Attachments:
Last edit: 31 Aug 2012 05:22 by aike.

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

More
31 Aug 2012 05:24 #23789 by aike
Replied by aike on topic Re:SPINDLE PWB with PID and ENCODER
Attachments:

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

More
31 Aug 2012 05:25 #23790 by aike
Replied by aike on topic Re:SPINDLE PWB with PID and ENCODER
Attachments:

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

More
31 Aug 2012 05:26 #23791 by aike
Replied by aike on topic Re:SPINDLE PWB with PID and ENCODER
Attachments:

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

More
31 Aug 2012 09:21 #23793 by andypugh
Replied by andypugh on topic Re:SPINDLE PWB with PID and ENCODER
aike wrote:

Is PID setting write or not?


Almost certainly not.

Start with PGain IGain DGain all zero and adjust the FF0 Gain until you get the correct speed at one particular speed demand.

Then increase the Igain until the speed settles at the rate you want at other speed requests.

You might want to set the FF0 a little low so that the speed never over-shoots.

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

More
01 Sep 2012 02:54 #23820 by aike
Replied by aike on topic Re:SPINDLE PWB with PID and ENCODER
Thank you!
I will try today.

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

More
05 Sep 2012 17:05 #23937 by aike
Replied by aike on topic Re:SPINDLE PWB with PID and ENCODER
I did it.
The video and photo later, but the final result
Pgain = 0
Igain = 0,4
Dgain = 0
FF0 = 0,5
FF1 = 0
FF2 = 0
deadband = 0,01
maxoutput = 0

The stable 99% (unstable of spindle frequency less 1%)

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

More
07 Sep 2012 08:26 #24004 by aike
Replied by aike on topic Re:SPINDLE PWB with PID and ENCODER
1. Install linuxcnc-dev. It is because of "comp" command (to compile and install
module).

2. Create file passthru.comp (thank to forum)
############### start file passthru.comp ######################################
component passthru "Joins OUT to I/O pins";
pin in float in;
pin io float out;
function _;
license "GPL";
;;



FUNCTION(_) {
out = in;
}
############### start file passthru.comp ######################################

3. Make command "sudo comp --install passthru.comp

4. Add next strings to pyvcp file .xml

<labelframe text="Spindle PID Tuning">
<font>("Helvetica",10)</font>
<hbox>
<spinbox>
<halpin>"FF0-spinbox"</halpin>
<min_>0</min_>
<max_>1</max_>
<initval>0.4</initval>
<resolution>0.1</resolution>
<format>"2.3f"</format>
<font>("Helvetica",8)</font>
</spinbox>
<label>
<text>"FF0 gain"</text>
</label>

<spinbox>
<halpin>"I-spinbox"</halpin>
<min_>0</min_>
<max_>1</max_>
<initval>0.5</initval>
<resolution>0.1</resolution>
<format>"2.3f"</format>
<font>("Helvetica",8)</font>
</spinbox>
<label>
<text>"I gain"</text>
</label>
</hbox>
</labelframe>


5. Add such strings to hal file(s) (one or more)

loadrt pid num_chan=1
loadrt mult2 count=1
loadrt passthru count=2

addf mult2.0 servo-thread
addf passthru.0 servo-thread
addf passthru.1 servo-thread
addf pid.0.do-pid-calcs servo-thread


net FF0-gain-in <= pyvcp.FF0-spinbox
net I-gain-in <= pyvcp.I-spinbox

net spindle-vel-fb <= hm2_[HOSTMOT2](BOARD).0.encoder.02.velocity


setp pid.2.Pgain 0
setp pid.2.Igain 0
setp pid.2.Dgain 0
setp pid.2.bias 0
setp pid.2.FF0 0
setp pid.2.FF1 0
setp pid.2.FF2 0
setp pid.2.deadband [SPINDLE_9]DEADBAND
setp pid.2.maxoutput 0

net FF0-gain-in => passthru.0.in
net FF0-gain-out <= passthru.0.out
net FF0-gain-out => pid.0.FF0

net I-gain-in => passthru.1.in
net I-gain-out <= passthru.1.out
net I-gain-out => pid.0.Igain

net spindle-enable => pid.0.enable

#RPM
net spindle-vel-cmd => pid.0.command
#convert from RPS to RPM
net spindle-vel-fb => mult2.0.in0
setp mult2.0.in1 60
#output is RPM
net encoder-vel-fb <= mult2.0.out
net encoder-vel-fb => pid.0.feedback
#RPM
net spindle-pid-out <= pid.0.output
net spindle-pid-out => abs.spindle.in
net absolute-spindle-vel <= abs.spindle.out

# --- SPINDLE ENABLE ---
net spindle-enable => hm2_[HOSTMOT2](BOARD).0.pwmgen.00.enable

# --- SPINDLE ABSOLUT VELOCITY ---
net absolute-spindle-vel => hm2_[HOSTMOT2](BOARD).0.pwmgen.00.value

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

More
07 Sep 2012 09:06 #24005 by andypugh
Replied by andypugh on topic Re:SPINDLE PWB with PID and ENCODER
aike wrote:

1. Install linuxcnc-dev
....
2. Create file passthru.comp (thank to forum)


It's probably easier to use the aleady-existing "tristate_float" component.
You need to setp the enable pin to true in the HAL file, but other than that the behaviour is identical.

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

Time to create page: 0.078 seconds
Powered by Kunena Forum