Thanks gents, finally got it sorted out after working through the scaling
Here's the hal code for a 5-position selector switch:
setp halui.max-velocity.direct-value true
setp halui.max-velocity.scale [see below]
setp mux16.0.in00 [value] #triggered by switch position 1 (unconnected, no input)
setp mux16.0.in01 [value] #triggers mux16.sel0
setp mux16.0.in02 [value] #triggers mux16.sel1
setp mux16.0.in04 [value] #triggers mux16.sel2
setp mux16.0.in08 [value] #triggers mux16.sel3
# position 1 of the selector switch is left unconnected as a 'dead' position. That will make the first switch position 'off'
net MAXVEL_1 <= [HMOT](CARD0).7i84.0.1.input-23
net MAXVEL_1 => mux16.0.sel0
net MAXVEL_2 <= [HMOT](CARD0).7i84.0.1.input-22
net MAXVEL_2 => mux16.0.sel1
net MAXVEL_3 <= [HMOT](CARD0).7i84.0.1.input-21
net MAXVEL_3 => mux16.0.sel2
net MAXVEL_4 <= [HMOT](CARD0).7i84.0.1.input-20
net MAXVEL_4 => mux16.0.sel3
net MAXVEL_IN <= mux16.0.out-s
net MAXVEL_IN => halui.max-velocity.counts
GOTCHA'S:
- The mux16.N.inXX values must be edited if the MAX_VELOCITY value in the INI file is changed.
- The .in00-inXX pins only react to whole numbers. This means it's hard to get exact desired max velocity numbers, but it's close enough for a global override.
- The max velocity briefly drops to zero during switch changes. This drop to zero speed may cause issues on particular machines. Mux16.N.suppress-no-input pin eliminates the drop, but you lose the 'dead' position with zero output. You will only have 4 effective positions (speeds) if you aren't multiplexing. Perhaps 0%, 5%, 25%, and 100% would be acceptable for most people.
- Not sure how this affects QtPyVcp GUI's (Probe Basic specifically), as the PB devs have added a MAX_LINEAR_VELOCITY and MAX_ANGULAR_VELOCITY setting. This scheme may need fine-tuning once I start moving my 4th axis around.
For an INI file MAX_VELOCITY = 1.5 (90ipm, my test speed) I wound up with the following values:
EXAMPLE 1 (
mux16.N.suppress-no-input False):
halui.max-velocity.scale = 0.1
.in00 = 0 [0ipm]
.in01 = 1 [6ipm]
.in02 = 2 [12ipm]
.in04 = 7 [42ipm]
.in08 = 15 [90ipm]
EXAMPLE 2 (
mux16.N.suppress-no-input True):
halui.max-velocity.scale = 0.1
.in01 = 0 [0ipm]
.in02 = 1 [6ipm]
.in04 = 4 [24ipm]
.in08 = 15 [90ipm]