Looking at it again you're on the right track if you really want to use the 
R-0-F thing. It's pretty hard to help you with this because of the way your 
files are written. Your expectations of what pid is supposed to do is 
probably off. What you saw happen with the pid output is exactly what 
should have happened given the circumstances.

(pid Igain = 0, Bias = 60, Pgain = 1, scale = 120, min =-115, max = 115)
>
> ask M4 S3300 = 5% pwm so value are 4.95
> ask M4 S1 = ~50% pwm so value are 60
> ask M3 S1 = ~50% pwm so value are 60
> ask M3 S3300 = 95% so value are 114.95
>

*Pgain *is the *Propotional* change to the output vs the input. *Igain* is 
the *Integral* response of time vs the Error. Here  you ask for a speed of 
3300rpms and since there is no encoder it always sees 0rpm. The output of 
the PID (supposed to be controlling a motor) has to increase to try to get 
the input (supposed to be an encoder attached to the motor) to increase. 
This is the whole point of "closed loop'" control. Since you have a 
proportional gain that is much higher than the integral gain, it just 
shoots to the max and stays there since the pid output cannot satisfy the 
input (no motor, no encoder). What you have here is large changes made with 
no time consideration.

the problem come when i change Pgain = 0 and Igain = 0.1 or 1 etc
>
> ask M4 S3300 = 0% pwm so value decrease quickly to -120
> ask M4 S1 = ~50% pwm so value are 60 but decrease slowly to -120
> ask M3 S1 = ~50% pwm so value are 60 increase slowly to 120
> ask M3 S3300 = 100% so value are 120
>

This is not a problem, this is what you are asking for. You have no, or 
very little proportional gain set so the output will not act aggressively 
to the input, it will make very small changes incrementally. Couple that 
with the fact that you have now included Integral (time) gain to the pid. 
What you wound up with here is that it is making very small changes slowly. 
This is backwards from how you tune a PID but it doesn't matter because you 
have nothing to feedback and close the loop. The only thing you can get 
from this is what the minimum and maximum outputs were, but that's not 
really relevant because you're limiting the pid.

Because of the way you have the hal/ini files written it took me a while to 
realize what you were trying to do. I decided to write it myself because I 
enjoy a challenge, which this certainly is because of the hardware you 
chose to use. It's funny because by the time I was done I realized you were 
really on the right track. Do yourself a favor and don't worry about the 
low pass filter and the 5%-95% thing until after you have a working 
spindle. Your hal file is super hard to read and confusing....and I look at 
hal files all day. Your main problem I think is using bias of pid for the 
offset. This is written like a legacy (linuxCNC) hal file but it works fine 
with MK. You can change the loadrt's and addf's to newinst if you want. 
Double check for errors because I can't load these files since I don't use 
the same hardware.

##### HAL FIle

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

loadrt pid names=pid.spindle
loadrt offset names=offset.pwmgen
loadrt near names=near.at-speed
loadrt scale names=scale.spindle-vel-rpm 

addf pid.spindle.do-pid-calcs             servo-thread
addf offset.pwmgen.update-output.funct    servo-thread
addf near.at-speed                        servo-thread
addf scale.spindle-speed-rpm              servo-thread

# scale RPS to RPM
setp scale.spindle-vel-rpm.gain [SPINDLE]VELOCITY_RPM_GAIN

# setup Spindle PID
setp pid.spindle.Pgain     [SPINDLE]P
setp pid.spindle.Igain     [SPINDLE]I
setp pid.spindle.Dgain     [SPINDLE]D
setp pid.spindle.FF0       [SPINDLE]FF0
setp pid.spindle.FF1       [SPINDLE]FF1
setp pid.spindle.FF2       [SPINDLE]FF2
setp pid.spindle.bias      [SPINDLE]BIAS
setp pid.spindle.deadband  [SPINDLE]DEADBAND
setp pid.spindle.maxerror  [SPINDLE]MAX_ERROR
setp pid.spindle.maxoutput [SPINDLE]MAX_OUTPUT

setp hpg.encoder.00.chan.00.scale [SPINDLE]ENCODER_SCALE
setp hpg.encoder.00.chan.00.counter-mode 0

setp hpg.pwmgen.00.out.00.pwm_period [SPINDLE]PWM_PERIOD

setp near.at-speed.scale [SPINDLE]AT_SPEED_SCALE

# offset the pid output the value of max output to shift the output above 0
setp offset.pwmgen.offset [SPINDLE]MAX_OUTPUT
net DAC-ctrl-in <= pid.spindle.out
net DAC-ctrl-in => offset.pwmgen.in

# scale max expected input * 2 to equal a PWM duty cycle of 1.0 
setp hpg.pwmgen.00.out.00.scale [SPINDLE]PWM_OUTPUT_SCALE

# set the pwmgen output pin
setp hpg.pwmgen.00.out.00.pin 921

# encoder connections
net spindle-pos <= hpg.encoder.00.chan.00.position 
net spindle-pos => motion.spindle-revs

net spindle-vel-fb-rps <= hpg.encoder.00.chan.00.velocity
net spindle-vel-fb-rps => motion.spindle-speed-in
net spindle-vel-fb-rps => scale.spindle-speed-rpm.in
net spindle-vel-scaled-rpm <= scale.spindle-speed-rpm

# Speed command in RPS
net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd-rps => pid.spindle.command

# offset output to feed to pwmgen output
net DAC-ctrl-out <= offset.pwmgen.out
net DAC-ctrl-out => hpg.pwmgen.00.out.00.value


# Spindle control signals
net spindle-enable <= motion.spindle-on
net spindle-enable => pid.spindle.enable
net spindle-enable => fur.do-6
net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd-rps => near.at-speed.in1 
net spindle-vel-fb-rps  => near.at-speed.in2
net spindle-at-speed <= near.at-speed.out
net spindle-at-speed => motion.spindle-at-speed 


##### INI File

#############
# SPINDLE
#############

[SPINDLE]
# PID, input is RPS
OUTPUT_PERIOD =  10000000
P = 0.1
I = 0.0
D = 0.0
FF0 = 0.0
FF1 = 0.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0
MAX_ERROR = 0.0
#Max desired spindle speed in RPMs (3300) / 60 = Spindle Speed in RPS. 
MAX_OUTPUT = 55.00
# quadrature mode (mode-0) is encoder PPR * 4
ENCODER_SCALE = 1600
# scale pid output to pwm control value. Max duty cycle of 1.0 / (Max speed 
* 2) ---range of both directions
PWM_OUTPUT_SCALE = 110
# PWMgen output frequency in Hz
PWM_PERIOD = 10000000
AT_SPEED_SCALE = 1.01
VELOCITY_RPM_GAIN = 60







-- 
website: http://www.machinekit.io blog: http://blog.machinekit.io github: 
https://github.com/machinekit
--- 
You received this message because you are subscribed to the Google Groups 
"Machinekit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to machinekit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/machinekit/bb111ed2-ed85-40f7-afea-fd3a6b57eee6%40googlegroups.com.

Reply via email to