Passing parameters to Hal Component

More
18 Nov 2016 19:54 #82967 by an92626
I have written a hal component to clamp and unclamp my drawbar (see attached file). The original component worked, but I need to add a test so that the component does not work if the spindle is turning. I want to pass pid.s.enable to the hal component so it will know if the spindle is turning, and if it is turning, the hal component will exit and do nothing. I used the following lines in my hal file to pass parameters to my clamping hal component, and the last line to pass aparamter so the hal component knows if the spindle is turning.

net clampsignal drawbar.clamp => hm2_5i25.0.7i77.0.0.input-10
net unclampsignal drawbar.unclamp => hm2_5i25.0.7i77.0.0.input-09
net solenoidsignal drawbar.solenoid <= hm2_5i25.0.7i77.0.0.output-02
net drawbar-spindle-on drawbar.spinning <= pid.s.enable

The last line fails since "pid.s.enable" is already assigned to pin "spindle-enable" in the top level hal file. In my clamping hal component I have the statement "pin in bit spinning" which defines an input pin called "spinning" for the hal component which the hal component will test, and if true and the spindle is spinning, the hal component exits and does nothing. How would I format a hal statement to assign the value of "pid.s.enable" or the pin value of "spindle-enable" to my component input value of "drawbar.spinning"?

I have lots of experience programing in fortran and c, and I can see that the statement "net drawbar-spindle-on drawbar.spinning <= pid.s.enable" is trying to assign a value to the input parameter called "spinning" of the hal component called "drawbar", but I do not get how to tell it what value to assign to the input parameter "drawbar.spinning". Can these pins and signals such as "pid.s.enable" or "spindle-enable" only be assigned once, and if so, is there some other way to pass this value to the hal component? I am not looking for another way to clamp and unclamp my spindle. I want to use my hal component and understand and solve this parameter passing problem because I plan on writing other hal components which will have the same issues.
Attachments:

Please Log in or Create an account to join the conversation.

More
18 Nov 2016 20:15 #82969 by PCW
A "in" component pin (like pid.s.enable) can only be driven by a single "out" pin

That is, it makes no sense to have more than 1 logical source drive a pin as the
state of the pin is undefined when the multiple sources driving that pin are different

Normally for pins that are single bits (boolean) the solution is to add a logical component
(say AND or OR, to combine the two sources that drive the "in" pin)

Please Log in or Create an account to join the conversation.

More
18 Nov 2016 21:31 #82973 by an92626
With some trial and error I was able to figure out the problem.

pid.s.enable is a pin and in the top level hal file it is assigned to the signal spindle-enable.

Now I want to pass this value into my hal component drawbar so I can use it as the input pin "spinning" as part of the logical "if" tests within the function inside of my hal component.

I finally realized that the hal command "net" that associated a signal with a pin actually works in both directions. If I place the command "net spindle-enable drawbar.spinning" in my upper level hal file, (wihich is defined as net "signal" "pin") it will make the connection so that the input pin "drawbar.spinning" that is used within the function in my hal component, will have the same value as the signal "spindle-enable".

For those of you who are programmers, we always look at the code of A=B as assigning the value of B to A, and that is how I originally looked at the "net" command of only assigning a pin (the second variable) to the signal (the first variable). In the hal statement "net", you need to look at the "net" statement as basically an equivalency that works in both directions. "net spindle-enable drawbar.spinning" will set the signal "spindle-enable" equal to the pin "drawbar.spinning", and it will set the pin "drawbar.spinning" equal to the signal "spindle-enable". As it explains in the basic hal manual, it is like connecting a wire between these two terminals (i.e. variables) so the equivalency can go in either direction. Once I finally understood that the "net" command is bi-directional then I figured out how to assign the value of "spindle-enable" to the input pin of "drawbar.spinning" within my hal component.

Please Log in or Create an account to join the conversation.

More
18 Nov 2016 21:44 - 18 Nov 2016 21:44 #82974 by PCW
The net command is _NOT_ bidirectional in the case of simple "in" and "out" pins
In this case the signal takes the value of the single "out" pin and conveys it to
all "in" pins connected to the same net
Last edit: 18 Nov 2016 21:44 by PCW.

Please Log in or Create an account to join the conversation.

More
18 Nov 2016 21:54 - 18 Nov 2016 21:59 #82977 by Todd Zuercher
While hal net commands are written net "signal name" "pin". You have to remember pins are directional with outputs and input. It might be better to visualize the pin to signal relation ship like this.
"pin-out" => "signal name" => "pin-in1" => "pin-in2"...
And remember that same signal will connect its pin-out value with as many pin-ins you like spanning multiple hal files. If you wanted to you could put all your pin-out connections in one hal file and all pin-in connections in a different file. You can put all of a signals pin connections in a single net command on one line, or you could put each pin connection on its own line with separate net commands. So when you added your "net spindle-enable drawbar.spinning" command it did not matter which of your hal files you put it in. As long as it is read after your component creates the "drawbar.spinning" pin. If that pin was created by your gui for instance, the net command using it would have to be in your postguihal file.

Keep plugging away, looks like you're getting the hang of this.
Last edit: 18 Nov 2016 21:59 by Todd Zuercher.

Please Log in or Create an account to join the conversation.

More
18 Nov 2016 22:45 #82979 by an92626
OK. Let's try this again.
I solved my original problem by entering the statement

"net spindle-enable drawbar.spinning " (statement 1)

and that statement set "drawbar.spinning" equal to the value of "spindle-enable" (the value on the right was set to the value on the left).

With the hal command:

net clampsignal drawbar.clamp => hm2_5i25.0.7i77.0.0.input-10 (statement 2)

I know that statement 2 sets "drawbar.clamp" to the same value as hm2_5i25.0.7i77.0.0.input-10. I may have the arrow thing going the wrong direction, but the manual said the arrow thing is for readability only.

So what does statement 2 do to the signal clampsignal? Does it set clampsignal to the same value as drawbar.clamp?

I am pretty sure it does not set drawbar.clamp equal to clampsignal since clampsignal is not defined and I know that drawbar.clamp ended up being set to hm2_5i25.0.7i77.0.0.input-10.

So my confusion is that in statement 1 the equivalency is going from left to right (the right value of drawbar.spinning was set to the left value of spindel-enable), and in the other is it going from right to left, (setting the value of clampsignal equal to drawbar.clamp), or does it do nothing?

Is the directional difference caused by the presence of the third term of hm2_5i25.0.7i77.0.0.input-10 ?

Please Log in or Create an account to join the conversation.

More
18 Nov 2016 23:02 - 18 Nov 2016 23:52 #82980 by PCW
The direction is entirely determined by the type of the pins
hm2_5i25.0.7i77.0.0.input-10 is a pin of type "OUT"
so it is the data_source for the signal clampsignal
which can now be connected to as many pins of type "IN"
(data_sinks) that you wish
Last edit: 18 Nov 2016 23:52 by PCW.

Please Log in or Create an account to join the conversation.

More
19 Nov 2016 13:07 - 19 Nov 2016 13:11 #82986 by Todd Zuercher
Like Peter said, the direction is determined by what the pin is not it's location.
I'll show you a few examples all of which are equivalent. (as you saw in the manuals the arrows are meaningless and are ignored they are only for your readability, it does not matter if they are right or wrong other than to be confusing.)
net clampsignal => drawbar.clamp <= hm2_5i25.0.7i77.0.0.input-10
is the same as
net clampsignal <= hm2_5i25.0.7i77.0.0.input-10 => drawbar.clamp
is the same as
net clampsignal <= hm2_5i25.0.7i77.0.0.input-10
net clampsignal => drawbar.clamp
is the same as
net clampsignal => drawbar.clamp
net clampsignal <= hm2_5i25.0.7i77.0.0.input-10
Last edit: 19 Nov 2016 13:11 by Todd Zuercher.

Please Log in or Create an account to join the conversation.

Time to create page: 0.072 seconds
Powered by Kunena Forum