PWM Closed Loop Spindle Control

More
26 Sep 2022 21:15 #252803 by Brian_S
I'm having trouble getting closed loop spindle control to work with LinuxCNC 2.8.4 on a RPi using the GPIO driver as an output.

I'm following along with this example: wiki.linuxcnc.org/cgi-bin/wiki.pl?Closed...pindle_Speed_Control and I cannot get any output from the PID.

Here's an openloop PWM that is working (though I haven't done any scaling for the non-linear response). It gives good PWM on the correct RPi GPIO pin:
# In order to have spindle feedback we need to use the encoder functions
# See the Spindle Feedback section of the docs: https://linuxcnc.org/docs/html/examples/spindle.html

loadrt encoder num_chan=1
addf encoder.update-counters   base-thread
addf encoder.capture-position  servo-thread

loadrt pwmgen output_type=0
addf pwmgen.update             servo-thread
addf pwmgen.make-pulses        base-thread

# Set the spindle's top speed in RPM
setp pwmgen.0.scale            2000

# Set the PWM base frequency in Hz. The filter in the hardware is optimised for 10Hz
setp pwmgen.0.pwm-freq         10

net spindle-speed-cmd spindle.0.speed-out => pwmgen.0.value
net spindle-on spindle.0.on => pwmgen.0.enable
net spindle-pwm pwmgen.0.pwm => hal_pi_gpio.pin-05-out

# The standard Denford Orac position disc has 48 pulses per revolution
setp encoder.0.position-scale 48

# This is not a quadrature encoder (with A and B signals) so we use just a simple counter mode
setp encoder.0.counter-mode true

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

# Hook the spindle encoder HAL to the physical pins
net spindle-phase-a encoder.0.phase-A <= hal_pi_gpio.pin-29-in
net spindle-phase-b encoder.0.phase-B
net spindle-index encoder.0.phase-Z <= hal_pi_gpio.pin-26-in

Here's the relevant section from the HAL file for the PID control that gives no PWM output. I tried making the PID transparent even to start with using the FF0 setting, but I just can't get anything output. I'm sure I've screwed something silly up. Any ideas?

# In order to have spindle feedback we need to use the encoder functions
# See the Spindle Feedback section of the docs: https://linuxcnc.org/docs/html/examples/spindle.html

loadrt encoder num_chan=1
addf encoder.update-counters base-thread
addf encoder.capture-position servo-thread

loadrt pwmgen output_type=0
addf pwmgen.update servo-thread
addf pwmgen.make-pulses base-thread

loadrt pid num_chan=1
addf pid.0.do-pid-calcs servo-thread
setp pid.0.FF0 1.0
setp pid.0.Pgain 0
setp pid.0.Igain 0
setp pid.0.Dgain 0
setp pid.0.maxoutput 2000

# Set the spindle's top speed in RPM
setp pwmgen.0.scale 2000

# Convert revolutions per second (RPS) to revolutions per minute (RPM) for the output
setp scale.0.gain 60

# Set the PWM base frequency in Hz. The filter in the hardware is optimised for 10Hz
setp pwmgen.0.pwm-freq 10

# TODO: See what this setting actually does
# setp pwmgen.0.dither-pwm true

net spindle-enable             spindle.0.on              pwmgen.0.enable      pid.0.enable

# The standard Denford Orac position disc has 48 pulses per revolution
setp encoder.0.position-scale 48

# This is not a quadrature encoder (with A and B signals) so we use just a simple counter mode
setp encoder.0.counter-mode true

# Connect the HAL encoder outputs to LinuxCNC
net spindle-position           encoder.0.position        spindle.0.revs
net spindle-index-enable       encoder.0.index-enable    spindle.0.index-enable
net spindle-velocity           encoder.0.velocity        scale.0.in

# Hook the spindle encoder HAL to the physical pins
net spindle-phase-a            encoder.0.phase-A         hal_pi_gpio.pin-29-in
net spindle-phase-b            encoder.0.phase-B
net spindle-index              encoder.0.phase-Z         hal_pi_gpio.pin-26-in

net spindle-velocity-rpm       pid.0.feedback            spindle.0.speed-in    scale.0.out
net pid_command                pid.0.command             spindle.0.speed-out   sum2.0.in0
net pid_output                 pid.0.output              sum2.0.in1

net pwmgen_value               pwmgen.0.value            sum2.0.out
net pwmgen_pwm                 pwmgen.0.pwm              hal_pi_gpio.pin-05-out

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

More
26 Sep 2022 21:41 #252804 by PCW
Replied by PCW on topic PWM Closed Loop Spindle Control
Missing the sum2 addf maybe?

With pid enable true and pid max_output not limiting the output,
the pid comps output should = the command with FF0=0

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

More
26 Sep 2022 21:51 #252805 by Brian_S
OMG, I'm such a dumbass!

Didn't have:
addf sum2.0 servo-thread

Thanks so much for the quick response and the info!

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

Time to create page: 0.069 seconds
Powered by Kunena Forum