Well, it seems people are following along. I had a request overnight to explains some of my HAL code. It just goes to show once you understand something, you gloss over the detail where the hard bits live. This was not meant to be a tutorial, but for the other beginners like me here goes:
You should know by now that
loadrt loads a HAL module into your setup
Once you load a module, you usually need to put it in the thread you want to use it in with
addf
So you usually need a
loadrt and an
addf statement before you can use it.
Some HAL modules need you to set a parameter to a given value. you use
setp to do that.
With some modules (like
or.2), you may use them in multiple places so you need to add a count parameter. I've already got 3 or2 statements in use so I added one more here
Real computers count starting from 0. Just ask any assembly language or C programmer. Once you start counting from 0, a lot of things become a lot easier. So HAL numbers each of the statements as or2.0, or2.1, or2.2, or2.3. As this is the 4th
or i've added, I am using or2.3.
But more importantly, because I am using a 7i76e, I need to load the mesa driver hm2_eth.
Code:
loadrt hm2_eth board_ip="10.10.10.10" config="firmware=hm2/7i76/7i76e.BIT num_encoders=1 num_pwmgens=0 num_stepgens=5 sserial_port_0=2xxxx"
pncconf makes a valiant effort at making this statement but you probably need to tell it the ip address its installed on. If you read the documentation, you need to place the driver in mode 2. This is the bit that does that
sserial_port_0=2xxxx. I found this example on the forum here so I copied it. Don't ask me what the other statements do.
I'm using master branch to get the gantry joint axis feature and I think this has meant some code has changed as the axis module now has axis.x, axis.y etc instead of axis.0, axis.1 etc. So lets look at the next snippet which just sets up some defaults.
Code:
setp axis.x.jog-vel-mode 0
net x-jog-counter <= hm2_7i76e.0.7i76.0.0.enc0.count
net x-jog-counter => axis.x.jog-counts
The
jog-vel-mode parameter can be either 0 or 1. I've set it to 0 so that a given jog step completes. Using a 1 here means that motion stops as soon as you stop turning the wheel.
The next 2 lines read the 7i76e enc0.count and sends it to axis X so that HAL knows which axis to move. You can fold this up onto one line but I broke it up for ease of reading (so try to do this yourself as a training exercise. I did.)
So lets deal with the scale selection. To conserve pins most examples use the mux4 hal component and I realised I left these lines out of my example to load it (now corrected)
Code:
loadrt mux4 count=1
addf mux4.0 servo-thread
This conserves pins once you can work out how to wire in a binary coded switch
these next lines do 3 things. They load the value of the input pins (I'm using 21 & 22) used by the selector switch into a variable I created but along the way, it also loads the value of these pins into an or2 statement. They also send the pin values to our mux4 component inputs.
Code:
net mux-in1 or2.3.in0 <= hm2_7i76e.0.7i76.0.0.input-22 => mux4.0.sel0
net mux-in2 or2.3.in1 <= hm2_7i76e.0.7i76.0.0.input-21 => mux4.0.sel1
I think you could break these up onto more lines to make it easier to read so try doing that as a learning exercise.
Before an axis can be jogged, it needs to be enabled using
x-jog-enable and that is the purpose of my or.2 output. It will be true (1) whenever a scale is selected with the switch and 0 when the switch is in the off position
Code:
net x-jog-enable <= or2.3.out
net x-jog-enable => axis.x.jog-enable
Now we need to set the scale according to the position table I documented in the previous post using setp.
Code:
# jog scale for each switch position in mm
setp mux4.0.in0 0.0
setp mux4.0.in1 1.0
setp mux4.0.in2 0.1
setp mux4.0.in3 0.01
You will need to alter the scale values if your machine is using inches.
And now finally tell axis.x which scale to use
Code:
net x-jog-scale mux4.0.out => axis.x.jog-scale
So there you have it. A working single axis MPG handwheel using the Mesa ENC0 input and a scale selector switch.
I think Andy said somewhere once that this stuff is hard becasue it really is hard but I hope that this explains whats going on.