Create new HAL component

More
13 Jul 2019 22:24 #139270 by persei8
How hard is it to write a new HAL component? I need a 3 input AND but there is only 2 input AND. This would be used to create an all_homed signal for 3 axes since there doesn't seem to be one existing. I know, I could use a couple of 2-in ANDs or a LUT but the point is I want to know how to do it. I could use the existing code as a template, but I don't know where it is. I found linuxcnc.org/docs/2.4/html/hal_comp.html#r1_14_7 but where do I get the comp tool? Thanks.

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

More
14 Jul 2019 00:23 #139277 by cmorley
Replied by cmorley on topic Create new HAL component
Are you using 2.8 or master? It's called halcompile there.
Also if using a gscreen or glade style screen in 2.8/master you can get a all-homed signal that you could connect to a HAL pin (just another option)

Chris M

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

More
14 Jul 2019 01:09 - 15 Jul 2019 06:35 #139278 by rodw
Replied by rodw on topic Create new HAL component
Well you could use the logic component to create a 3 input AND
linuxcnc.org/docs/devel/html/man/man9/logic.9.html

But where is the fun in that?

The source code for master (V 2.9) hal components are here:

github.com/LinuxCNC/linuxcnc/tree/master/src/hal/components

help yourself to the and2.comp file and modify to your needs. It would be a very good starter exercise
So to compile and install all you need to do is
halcompile  --install myand3.comp

If you are not using a run in place version (eg compiled from source), you will need to use sudo.
sudo halcompile --install myand3.comp 

Its so much fun to be able to extend linuxcnc like this and halcompile is well documented on the main documentation page of linuxcnc.
Last edit: 15 Jul 2019 06:35 by rodw.

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

More
14 Jul 2019 07:07 #139285 by pl7i92
Replied by pl7i92 on topic Create new HAL component
with the and2 chain you are better up as you can see what happend if it fails
the user comp just gets it is or it is not

and all GUI gets signaling to show if your axis are homed
eighter axis with a icon
or gscreen gmoccapy with color

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

More
14 Jul 2019 16:12 - 14 Jul 2019 16:45 #139317 by persei8
Replied by persei8 on topic Create new HAL component
That's the info I needed. However, I do not have halcompile.
sudo apt-get install linuxcnc-dev results in:

Reading package lists... Done
Building dependency tree
Reading state information... Done
Package linuxcnc-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'linuxcnc-dev' has no installation candidate
I do have the buildbot repository in /etc/apt/sources.list.d/linuxcnc-buildbot.list
If you tell me I have to build it from source, then I am done with it and will just use the python code I have now.

EDIT:
Never mind. Its sudo apt-get install linuxcnc-uspace-dev
Last edit: 14 Jul 2019 16:45 by persei8. Reason: Found it.

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

More
14 Jul 2019 17:29 #139322 by persei8
Replied by persei8 on topic Create new HAL component
It worked!
except the command is sudo halcompile --install and3.comp
In case anyone wants to know the result of this exercise, the following is in my custom.hal file.

loadrt and3 names=and3_0
net home_x joint.0.homed => and3_0.in0
net home_y joint.1.homed => and3_0.in1
net home_z joint.2.homed => and3_0.in2
net all_homed and3_0.out
addf and3_0 servo-thread

and then

net all_homed gscreen.hal_led_all_homed

in the postgui hal file

The result is that a LED lights up when all 3 axes are homed, without using python code.
Thanks to all for the help. And if you actually want a AND3 component, I attached the comp file.
Attachments:

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

More
15 Jul 2019 06:37 #139372 by rodw
Replied by rodw on topic Create new HAL component

It worked!
except the command is sudo halcompile --install and3.comp

Thanks to all for the help. And if you actually want a AND3 component, I attached the comp file.


Great work. Sorry about the wrong example. Its funny how it all works when you are typing at the console.

Welcome to the magical world of hal components!

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

More
16 Jul 2019 12:10 #139553 by andypugh
Replied by andypugh on topic Create new HAL component
It's also worth learning how to use the LUT5 component for this. It allows you to specify a true or false output for every possible combination of 5 input bits.
This is rather useful for interlocks etc. (for example if door is open and spindle is not on and pedal is pressed then release tool).
LUT5 becomes especially interesting when the output is fed back to one of the inpiuts, then it can exhibit useful latching behaviour.

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

More
11 Jun 2022 16:10 #244940 by wasausky
Replied by wasausky on topic Create new HAL component
Hi everyone. it happens that I have to update the hal_pin_gpio and cpuinfo component.

because the revision that I have in the raspberry is not in the list of these components.

my question is:
if I recompile the component, will it be rewritten? Or do you have to create another one?

Also, in the case of the 3 ands, if you recompile the component several times until you finish, you would be rewriting it or creating different components.

Thank you for your answers.

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

More
15 Jun 2022 10:11 #245173 by andypugh
Replied by andypugh on topic Create new HAL component
You can try modifying cpuinfo.c and compiling / installing with halcompile

sudo halcompile --install cpuinfo.c

I think that it probably won't work, but it's worth trying.

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

Time to create page: 0.131 seconds
Powered by Kunena Forum