Tonights update - still there there yet but I think it's getting close.
I standardized on pid.s and pid.1 for velocity and position respectively. I tried using the code above but ran into a couple issues - first it seems like I needed to loadrt pwgen (not sure if I did it correctly) and then once I got past that stage the config loaded with this error:
Code:
Signal 'spindle-cmd' of type 'bit' cannot add pin 'hm2_5i25.0.7i77.0.1.analogout5' of type 'float'
Ok - this didn't seem right so I commented that line out and decided to trace and confirm all the signals just to make sure the logic was happening correctly.
Using this diagram
I opened all the pertinent HAL Meter boxes and ran two tests:
1. I turned the spindle by hand and ensured all the pins appeared to be reading encoder, velocity, position information correct [PASSED]
2. Feed it codes through the MDI to verify the position/velocity mode logic is working [PASSED]
I took "screenshots" to show the values and confirmation (yes I took a photo of my monitor because I'm completely stupid when it comes to Linux!!) I sent
M19 R50 Q20
for the orient command and
M3 S400
for the velocity command.
Ok so this seems good so far. At this point I am getting a value out of mux2.0.out fore each scenario but I cannot successfully pass it to hm2_5i25.0.7i77.0.1.analogout5.
For reference, here is the spindle portion of my HAL file. Yes it is a complete disaster from all the cut/paste/comment out experiments.
lagunmatic.hal
Code:
#*******************
# SPINDLE S
#*******************
loadrt pwmgen output_type=0
addf pwmgen.update servo-thread
setp pid.s.Pgain [SPINDLE]P
setp pid.s.Igain [SPINDLE]I
setp pid.s.Dgain [SPINDLE]D
setp pid.s.bias [SPINDLE]BIAS
setp pid.s.FF0 [SPINDLE]FF0
setp pid.s.FF1 [SPINDLE]FF1
setp pid.s.FF2 [SPINDLE]FF2
setp pid.s.deadband [SPINDLE]DEADBAND
setp pid.s.maxoutput [SPINDLE]MAX_OUTPUT
setp pid.s.error-previous-target true
net spindle-index-enable <=> pid.s.index-enable
#net spindle-enable => pid.s.enable
#net spindle-vel-cmd-rpm => pid.s.command
#net spindle-vel-fb-rpm => pid.s.feedback
#net spindle-output <= pid.s.output
# ---PWM Generator signals/setup---
setp hm2_5i25.0.7i77.0.1.analogout5-scalemax [SPINDLE]OUTPUT_SCALE
setp hm2_5i25.0.7i77.0.1.analogout5-minlim [SPINDLE]OUTPUT_MIN_LIMIT
setp hm2_5i25.0.7i77.0.1.analogout5-maxlim [SPINDLE]OUTPUT_MAX_LIMIT
#net spindle-output => hm2_5i25.0.7i77.0.1.analogout5
net spindle-enable => hm2_5i25.0.7i77.0.1.spinena
#####
net spindle-pos pid.1.feedback orient.0.position
net spindle-vel pid.s.feedback hm2_5i25.0.encoder.05.velocity
net spindle-vel-cmd motion.spindle-speed-out pid.s.command
net spindle-vel-pid pid.s.output mux2.0.in0
net spindle-pos pid.1.feedback orient.0.position near.0.in1 hm2_5i25.0.encoder.05.position
net spindle-pos-cmd orient.0.command pid.1.command near.0.in2
net spindle-angle motion.spindle-orient-angle orient.0.angle
net spindle-pos-pid pid.1.output mux2.0.in1
setp near.0.difference 0.0005
net spindle-in-pos-raw near.0.out edge.0.in #not needed v2.8+, use orient.0.is-oriented
net spindle-in-pos edge.0.out motion.spindle-is-oriented
# this switches modes
net orient-mode motion.spindle-orient orient.0.enable pid.1.enable mux2.0.sel
net velocity-mode motion.spindle-on pid.s.enable pwmgen.0.enable
net orient-dir motion.spindle-orient-mode orient.0.mode
#loadrt pwmgen output_type=0
#addf pwmgen.update servo-thread
#addf pwmgen.make-pulses base-thread
#net spindle-speed-cmd motion.spindle-speed-out => pwmgen.0.value
#net spindle-on motion.spindle-on => pwmgen.0.enable
# Set the spindle's top speed in RPM
setp pwmgen.0.scale 10000
net spindle-cmd pwmgen.0.pwm hm2_5i25.0.7i77.0.1.analogout5
# Tune the PID from the INI values
setp pid.1.Pgain [SPINDLE]PGAIN_P
setp pid.1.Igain [SPINDLE]IGAIN_P
setp pid.1.Dgain [SPINDLE]DGAIN_P
setp pid.1.FF0 [SPINDLE]FF0_P
setp pid.1.FF1 [SPINDLE]FF1_P
#####
# ---Encoder feedback signals/setup---
setp hm2_5i25.0.encoder.05.counter-mode 0
setp hm2_5i25.0.encoder.05.filter 1
setp hm2_5i25.0.encoder.05.index-invert 0
setp hm2_5i25.0.encoder.05.index-mask 0
setp hm2_5i25.0.encoder.05.index-mask-invert 0
setp hm2_5i25.0.encoder.05.scale [SPINDLE]ENCODER_SCALE
#net spindle-revs <= hm2_5i25.0.encoder.05.position
#net spindle-vel-fb-rps <= hm2_5i25.0.encoder.05.velocity
net spindle-index-enable <=> hm2_5i25.0.encoder.05.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-pos => motion.spindle-revs
net spindle-at-speed => motion.spindle-at-speed
net spindle-vel => motion.spindle-speed-in
net spindle-index-enable <=> motion.spindle-index-enable
# ---Setup spindle at speed signals---
sets spindle-at-speed true