I just worked through something similar to this for an MPG but wanted my selector switch to also change the jog value and be useful for my jog increment buttons. I used mux16 because it was the easiest way to select 5 values without using a complex set of or2 statements. I did use an encoder for my max velocity but the mpg selector portion should be what you are looking for. I have yet to test my hal since I finished it right before leaving for work.
Some thoughts on implementing it for max-velocity would be to use the selector to manipulate the halui.max-velocity.scale as I didn't see anything other than halui.max-velocity.counts that was an input value. To do this you would need to use the halui.max-velocity.direct-value true. Thsi causes the input logic for the value to be (.counts * .scale)
If you did that then you could:
setp halui.max-velocity.counts 1
and then mux 16 different scale values for the selector switch. These values would be in percent of max ini value I believe:
setp mux16.0.in0 0.05 # this would be 5 ipm using your example.
Any way here is my relevant code I used:
Code:
# --- Max-Velocity Override ---
setp encoder.3.x4-mode 1
net max-vel-chA <= hm2_7i92.0.7i84.0.2.input-30
net max-vel-chA => encoder.3.phase-A
net max-vel-chB <= hm2_7i92.0.7i84.0.2.input-31
net max-vel-chB => encoder.3.phase-B
net max-vel-output <= encoder.3.counts
net max-vel-output => halui.max-velocity.counts
setp halui.max-velocity.count-enable 1
setp halui.max-velocity.scale .1
# --- Jogging ---
net select-x-axis <= hm2_7i92.0.7i84.0.2.input-05
net select-x-axis => halui.axis.x.select => halui.joint.0.select
net select-x-axis => axis.x.jog-enable => joint.0.jog-enable
net select-y-axis <= hm2_7i92.0.7i84.0.2.input-06
net select-y-axis => halui.axis.y.select => halui.joint.1.select
net select-y-axis => axis.y.jog-enable => joint.1.jog-enable
net select-z-axis <= hm2_7i92.0.7i84.0.2.input-07
net select-z-axis => halui.axis.z.select => halui.joint.2.select
net select-z-axis => axis.z.jog-enable => joint.2.jog-enable
net sel-inc-plus <= hm2_7i92.0.7i84.0.2.input-22
net sel-inc-plus => halui.axis.selected.increment-plus => halui.joint.selected.increment-plus
net sel-inc-minus <= hm2_7i92.0.7i84.0.2.input-23
net sel-inc-minus => halui.axis.selected.increment-minus => halui.joint.selected.increment-minus
net sel-jog-plus <= hm2_7i92.0.7i84.0.2.input-20
net sel-jog-plus => halui.axis.selected.plus => halui.joint.selected.plus
net sel-jog-minus <= hm2_7i92.0.7i84.0.2.input-21
net sel-jog-minus => halui.axis.selected.minus => halui.joint.selected.minus
net sel-jog-vel <= scale.jog.out
net sel-jog-vel => halui.axis.jog-speed => halui.joint.jog-speed
#setp scale.jog.gain 10000
setp scale.jog.gain 10
# --- MPG ---
setp mux16.inc.in00 0.0001
setp mux16.inc.in01 0.0005
setp mux16.inc.in02 0.0010
setp mux16.inc.in04 0.0050
setp mux16.inc.in08 0.0100
setp mux16.inc.debounce-time 0.200
setp axis.x.jog-vel-mode 1
setp axis.y.jog-vel-mode 1
setp axis.z.jog-vel-mode 1
setp joint.0.jog-vel-mode 1
setp joint.1.jog-vel-mode 1
setp joint.2.jog-vel-mode 1
net mpg-count <= hm2_7i92.0.7i84.0.2.enc0.count
net mpg-count => axis.x.jog-counts => joint.0.jog-counts
net mpg-count => axis.y.jog-counts => joint.1.jog-counts
net mpg-count => axis.z.jog-counts => joint.2.jog-counts
net mpg-scale <= mux16.inc.out-f
net mpg-scale => axis.x.jog-scale => joint.0.jog-scale
net mpg-scale => axis.y.jog-scale => joint.1.jog-scale
net mpg-scale => axis.z.jog-scale => joint.2.jog-scale
net mpg-scale => scale.jog.in
#No increment switch needed for .0001
net inc-select-b <= hm2_7i92.0.7i84.0.2.input-01
net inc-select-b => mux16.inc.sel0
net inc-select-c <= hm2_7i92.0.7i84.0.2.input-02
net inc-select-c => mux16.inc.sel1
net inc-select-d <= hm2_7i92.0.7i84.0.2.input-03
net inc-select-d => mux16.inc.sel2
net inc-select-e <= hm2_7i92.0.7i84.0.2.input-04
net inc-select-e => mux16.inc.sel3