#####################################################################
# Spindel VFD closed loop : PID NEAR SCALE OFFSET for Rev/stop/fw -10v 0v 
+10v
# from 0/24v PWM to +-10v isolator/convertissor
#####################################################################

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

addf pid.spindle.do-pid-calcs             servo-thread
addf offset.pwmgen.update-output          servo-thread
addf near.at-speed                        servo-thread
addf scale.spindle-vel-rpm                slow-thread
addf and2.spindle-ena                     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

# setup hardwar (encoder + PWMgen)
setp hpg.encoder.00.chan.00.scale [SPINDLE]ENCODER_SCALE
setp hpg.encoder.00.chan.00.counter-mode 0

setp hpg.pwmgen.00.pwm_period [SPINDLE]PWM_PERIOD
setp hpg.pwmgen.00.out.00.enable 1                # allow to be at offset 
value else when spindle is off

# offset the pid output the value of max output to shift the pwm output 
above 12v for output 0v from +-10 DAC
setp offset.pwmgen.offset [SPINDLE]OFFSET_OUTPUT
net DAC-ctrl-in <= pid.spindle.output
net DAC-ctrl-in => offset.pwmgen.in
#net spindle-vel-cmd-rps => offset.pwmgen.in     # for bypass PID only for 
some test

# 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

# encoder connections
net spindle-index-enable <= motion.spindle-index-enable
net spindle-index-enable <=> hpg.encoder.00.chan.00.index-enable
net spindle-index-enable => pid.spindle.index-enable

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-vel-rpm.in
net spindle-vel-fb-rps => pid.spindle.feedback

net spindle-vel-rpm <= scale.spindle-vel-rpm.out
net spindle-vel-cmd <= motion.spindle-speed-out

# 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                  # moved in 
the orient mux2

# Spindle control signals + and2 for stop spindle after stop GUI
net spindle-enable <= motion.spindle-on
net spindle-enable => and2.spindle-ena.in0
net drv-enable => and2.spindle-ena.in1
net spindle-and2enable <= and2.spindle-ena.out
net spindle-and2enable => pid.spindle.enable
#net spindle-and2enable => fur.do-6                               # moved 
in the orient or2

# Spindle at speed near signal
setp near.at-speed.scale [SPINDLE]AT_SPEED_SCALE
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 

#####################################################################


#####################################################################
# Spindle orient mode
#####################################################################
loadrt orient names=orient.spindle
loadrt pid    names=pid.orient-value
loadrt offset names=offset.orient
loadrt near   names=near.orient
loadrt or2    names=or2.orient-ena
loadrt and2   names=and2.orient-ena
loadrt mux2   names=mux2.orient-value

addf orient.spindle                       servo-thread
addf pid.orient-value.do-pid-calcs        servo-thread
addf offset.orient.update-output          servo-thread
addf near.orient                          servo-thread
addf or2.orient-ena                       servo-thread
addf and2.orient-ena                      servo-thread
addf mux2.orient-value                    servo-thread

# setup Orient Spindle PID
setp pid.orient-value.Pgain     [ORIENT]P
setp pid.orient-value.Igain     [ORIENT]I
setp pid.orient-value.Dgain     [ORIENT]D
setp pid.orient-value.FF0       [ORIENT]FF0
setp pid.orient-value.FF1       [ORIENT]FF1
setp pid.orient-value.FF2       [ORIENT]FF2
setp pid.orient-value.bias      [ORIENT]BIAS
setp pid.orient-value.deadband  [ORIENT]DEADBAND
setp pid.orient-value.maxerror  [ORIENT]MAX_ERROR
setp pid.orient-value.maxoutput [ORIENT]MAX_OUTPUT


# Set asked mode from M19 P0/1/2
net spindle-orient-mode <= motion.spindle-orient-mode
net spindle-orient-mode => orient.spindle.mode

# encoder connections
net spindle-index-enable => pid.orient-value.index-enable                  
# need investigation


# Spindle orient control signals + and2 for stop spindle after stop GUI
net spindle-orient-enable <= motion.spindle-orient
net spindle-orient-enable => and2.orient-ena.in0
net drv-enable => and2.orient-ena.in1
net spindle-orient-and2enable <= and2.orient-ena.out
net spindle-orient-and2enable => orient.spindle.enable
net spindle-orient-and2enable => mux2.orient-value.sel
net spindle-orient-and2enable => pid.orient-value.enable


# enable out for controler from regular spindle or orient mode
net spindle-and2enable => or2.orient-ena.in0
net spindle-orient-and2enable => or2.orient-ena.in1
net spindle-orient-or2enable <= or2.orient-ena.out
net spindle-orient-or2enable => fur.do-6


# Spindle at orient near signal
setp near.orient.scale [ORIENT]AT_ANGLE_SCALE     #AT_ANGLE_SCALE = 1.12
net spindle-pos => orient.spindle.position
net spindle-pos => pid.orient-value.feedback
net spindle-pos => near.orient.in2

net spindle-orient_cmd <= motion.spindle-orient-angle
net spindle-orient_cmd => near.orient.in1
net spindle-orient_cmd => orient.spindle.angle

net spindle-is-oriented <= near.orient.out
net spindle-is-oriented => motion.spindle-is-oriented


# Rotation command in degree
net spindle-orient-pid-cmd <= orient.spindle.command
net spindle-orient-pid-cmd => pid.orient-value.command


# offset the pid output the value of max output to shift the pwm output 
above 12v for output 0v from +-10 DAC
setp offset.orient.offset [SPINDLE]OFFSET_OUTPUT
net DAC-ctrl-orient-in <= pid.orient-value.output
net DAC-ctrl-orient-in => offset.orient.in


# offset output to feed to pwmgen output + mux with regular spindle modul
net DAC-ctrl-orient-out <= offset.orient.out
net DAC-ctrl-orient-out <= mux2.orient-value.in1
net DAC-ctrl-out        => mux2.orient-value.in0
net DAC-computed-ctrl-out <= mux2.orient-value.out
net DAC-computed-ctrl-out => hpg.pwmgen.00.out.00.value



#####################################################################


-- 
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/da48f2b9-f214-4dd1-930b-6675375ad75b%40googlegroups.com.

Reply via email to