Closed loop spindle

More
15 Jun 2016 13:05 #76068 by jeeybee
Closed loop spindle was created by jeeybee
Hello

I'm converting an old DAHLIH to linux cnc and have some trouble with the spindle control.
The spindle work fine and I can control it and all but the PID does not seem to work as it should
it seem like what ever I change the PID settings to the PID output only changes +- 0.05
For example if the spindle is set to 100rpm and the pid feedback shows 95 then the pid output changes to 100.05 and if its over then it sets to 99.95 so it seem to regulate as it should but why does it change so little?

Here are the HAL and INI settings: (a bit messy)

[SPINDLE_9]
P = 100
I = 0.0
D = 0.0
FF0 = 1.0
FF1 = 0.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0
MAX_OUTPUT = 6000
ENCODER_SCALE = 1
OUTPUT_SCALE = 6000
OUTPUT_MIN_LIMIT = 0.0
OUTPUT_MAX_LIMIT = 6000.0
#*******************
# SPINDLE S
#*******************

setp pid.3.Pgain [SPINDLE_9]P
setp pid.3.Igain [SPINDLE_9]I
setp pid.3.Dgain [SPINDLE_9]D
setp pid.3.bias [SPINDLE_9]BIAS
setp pid.3.FF0 [SPINDLE_9]FF0
setp pid.3.FF1 [SPINDLE_9]FF1
setp pid.3.FF2 [SPINDLE_9]FF2
setp pid.3.deadband [SPINDLE_9]DEADBAND
setp pid.3.maxoutput [SPINDLE_9]MAX_OUTPUT
setp pid.3.error-previous-target true
setp pid.3.maxerror .0005

net spindle-index-enable <=> pid.3.index-enable
net spindle-enable => pid.3.enable
net spindle-vel-cmd-rpm-abs => pid.3.command
#net spindle-vel-fb-rpm => pid.3.feedback
net spindle-fb-rpm => pid.3.feedback
net spindle-output <= pid.3.output

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

setp hm2_[HOSTMOT2](BOARD).0.7i77.0.4.analogout5-scalemax [SPINDLE_9]OUTPUT_SCALE
setp hm2_[HOSTMOT2](BOARD).0.7i77.0.4.analogout5-minlim [SPINDLE_9]OUTPUT_MIN_LIMIT
setp hm2_[HOSTMOT2](BOARD).0.7i77.0.4.analogout5-maxlim [SPINDLE_9]OUTPUT_MAX_LIMIT

net spindle-enable => hm2_[HOSTMOT2](BOARD).0.7i77.0.4.spinena

net spindle-output => hm2_[HOSTMOT2](BOARD).0.7i77.0.4.analogout5



# ---Encoder feedback signals/setup---


# add the encoder to HAL and attach it to threads.
loadrt encoder num_chan=1
addf encoder.update-counters servo-thread
addf encoder.capture-position servo-thread

# set the HAL encoder to 1 pulses per revolution.
setp encoder.0.position-scale 1

# set the HAL encoder to non-quadrature simple counting using A only.
setp encoder.0.counter-mode true

# connect the HAL encoder outputs to LinuxCNC.
#net spindle-position encoder.0.position => motion.spindle-revs
#net spindle-velocity encoder.0.velocity => motion.spindle-speed-in
#net spindle-index-enable encoder.0.index-enable <=> motion.spindle-index-enable

# connect the HAL encoder inputs to the real encoder.
net spindle_index_in <= hm2_[HOSTMOT2](BOARD).0.7i77.0.0.input-11
net spindle_index_in => encoder.0.phase-A
net spindle-phase-b encoder.0.phase-B
net spindle_index_in => encoder.0.phase-Z



net spindle-revs <= encoder.0.position-interpolated
net spindle-vel-fb-rps <= encoder.0.velocity
net spindle-index-enable <=> encoder.0.index-enable

# ---setup spindle control signals---

net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd-rps-abs <= motion.spindle-speed-out-rps-abs
net spindle-vel-cmd-rpm <= motion.spindle-speed-out
net spindle-vel-cmd-rpm-abs <= motion.spindle-speed-out-abs
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-rps => motion.spindle-speed-in
net spindle-index-enable <=> motion.spindle-index-enable

# ---Setup spindle at speed signals---

sets spindle-at-speed true

# Use ACTUAL spindle velocity from spindle encoder
# spindle-velocity bounces around so we filter it with lowpass
# spindle-velocity is signed so we use absolute component to remove sign
# ACTUAL velocity is in RPS not RPM so we scale it.

setp scale.spindle.gain 60
setp lowpass.spindle.gain 1.000000
net spindle-vel-fb-rps => scale.spindle.in
net spindle-fb-rpm scale.spindle.out => abs.spindle.in


net spindle-fb-rpm-abs abs.spindle.out => lowpass.spindle.in
net spindle-fb-rpm-abs-filtered lowpass.spindle.out

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

More
15 Jun 2016 14:15 #76079 by PCW
Replied by PCW on topic Closed loop spindle
I would change this

setp pid.3.maxerror .0005

to this

setp pid.3.maxerror 0

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

More
15 Jun 2016 15:40 #76098 by jeeybee
Replied by jeeybee on topic Closed loop spindle
Thank you very much

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

More
18 Jun 2016 08:55 #76242 by jeeybee
Replied by jeeybee on topic Closed loop spindle
Ran into some trouble:
With the 7i80 and the real time kernel my servo period of 1250000 is not enough for more than 3000rpm on the spindle as I use a software encoder that updates on the servo thread.
Can I use the 7i77 to handle the counting for me in some encoder mode even though I have a 24v proximity switch connected to a regular input?

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

More
18 Jun 2016 12:17 #76256 by PCW
Replied by PCW on topic Closed loop spindle
The 7I77 encoder inputs are designed for 5V signals, but you can connect a
24V signal if you divide it down to 5V with a couple of resistors.

Also if your proximity sensor is NPN type you can connect it directly

how many counts per turn is your encoder?

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

More
04 Jul 2016 14:37 #76965 by jeeybee
Replied by jeeybee on topic Closed loop spindle
I have connected the proximity switch to the encoder 4 input-a with a couple of resistors to divide the voltage to 5v so now I got the signal and the speed control is working.

Now I wonder how the index signal works that is used for syncronized movements, I cant really find where the index signal goes in to linuxcnc, there is a motion.spindle-index-enable but where is the motion.spindle-index-input?
Where can I see the index signal in halmeter to make sure its working?

And now I have only the A phase of the encoder so how do I configure that to also work as index signal?

I only find examples like: this net spindle-index-enable encoder.0.index-enable <=> motion.spindle-index-enable
Does this automatically turn the Z phase to index signal?

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

More
04 Jul 2016 15:49 #76970 by jeeybee
Replied by jeeybee on topic Closed loop spindle
And one more question, If I set the spindle speed to something, the PID loop only put out half the speed, so if I set it to 1000 then I the pid.3.output will be 500.
The pid.3.feedback show 500, so the feedback is correct
The pid.3.command show 1000
The PID values are now P1 I0 D0 and if I add a little I-value then it works itselft up to the correct speed but why does it start with only half the commanded value?

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

More
04 Jul 2016 16:24 - 04 Jul 2016 16:29 #76972 by PCW
Replied by PCW on topic Closed loop spindle
Thats the problem with just P, it needs an error to have any output

The PID output will be P*(command-feedback) so 500 is correct for a command of 1000 a feedback of 500 and a P of 1

This is what feed-forward is for. For velocity loops you will want to set FF0 to 1.0 so the
PID output is 1000 before any (P term driven) corrections.

With FF0 of 1 the PID output is now command*1 + P*(command-feedback)

Note if you only have one pulse per turn you will not get very good speed regulation (it will limit your P term to small values)
Last edit: 04 Jul 2016 16:29 by PCW.

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

More
04 Jul 2016 18:02 #76982 by andypugh
Replied by andypugh on topic Closed loop spindle

Now I wonder how the index signal works that is used for syncronized movements, I cant really find where the index signal goes in to linuxcnc, there is a motion.spindle-index-enable but where is the motion.spindle-index-input?
Where can I see the index signal in halmeter to make sure its working?


The spindle encoder input needs to go to an encoder counter. With only one signal you would need to connect it to both Phase A and the index of one of the 7i77 encoder counter modules.

Then, in HAL, you will have pins for spindle position, spindle speed and index-enable, and those need to be connected in HAL to the matching motion.spindle pins. (be aware that motion.spindle.revs is spindle revolutions, ie position, not rpm)

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

More
06 Jul 2016 16:43 #77091 by jeeybee
Replied by jeeybee on topic Closed loop spindle
FF0 = 1 solved it
And I connected the proximity switch to both A and Z.
Thanks.

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

Time to create page: 0.088 seconds
Powered by Kunena Forum