Linuxcnc equivalent of UCCNC macros, macroloops, plugins
- cmorley
- Offline
- Moderator
Less
More
- Posts: 7777
- Thank you received: 2073
29 Jun 2022 12:59 #246157
by cmorley
HAL is used to dynamically connect things together. By reading the HAL pin directly, you are forced to change your program if you connect your hardware differently.
ie:
Hardware -> mesa card -> your program
vrs:
hardware -> mesa card -> motion -> linuxcnc Status -> your program
The first is easier to understand (because you need to know less of how linuxcnc works).
The second allows things on the left of 'linuxcnc Status' to change while your program will still works.
But ya when starting out - just getting something to work is the most important!
Chris
Replied by cmorley on topic Linuxcnc equivalent of UCCNC macros, macroloops, plugins
While Andy's example is great when you are starting out or in a hurray (and sometimes you need to do it anyways), It is a disadvantage if you need to change how your system is connected together,
[/code]import linuxcnc s = linuxcnc.stat() s.poll() analogin = s.ain That gives you a python tuple (a specific python type of list) of the (default number of) 64 integer values. To just get a specific integer use this: [code]# used with code above. analogin0 = analogin[0] analogin1 = analogin[1] # etc Gstat is a useful library for working with linuxcnc in python (not sure what version of linuxcnc you are using.) http://linuxcnc.org/docs/devel/html/gui/gstat.html Thanks Cmorley, I knew how to do the first part of the code but wasn't up to the second bit you showed me, where you get individual values from the tuple, so that's useful. Problem is I wouldn't know what the analogue value referred to. In Andy's example it states the input I'm reading is input number 0, on 7i76E, board number 0. So at present the Linuxcnc Status values such as "ain", "din", "dout", etc are a complete mystery to me. Thanks for the info and link to Gstat too.
HAL is used to dynamically connect things together. By reading the HAL pin directly, you are forced to change your program if you connect your hardware differently.
ie:
Hardware -> mesa card -> your program
vrs:
hardware -> mesa card -> motion -> linuxcnc Status -> your program
The first is easier to understand (because you need to know less of how linuxcnc works).
The second allows things on the left of 'linuxcnc Status' to change while your program will still works.
But ya when starting out - just getting something to work is the most important!
Chris
Please Log in or Create an account to join the conversation.
- beefy
- Offline
- Elite Member
Less
More
- Posts: 224
- Thank you received: 56
29 Jun 2022 17:14 - 29 Jun 2022 17:18 #246177
by beefy
Replied by beefy on topic Linuxcnc equivalent of UCCNC macros, macroloops, plugins
Ah, it's all slowly coming together, thanks Phill / Chris. It's amazing how just a few simple explanations from you guys help me piece things together. The manual has a lot of information but I'm finding one thing is connected to something else a few hundred pages away.
Because I've programmed macros & plugins in UCCNC in C#, I think I've been focusing too much on Python alone, and not realising that Hal is the gateway to physical I/O as well as lots of other stuff. I've been in a mindset of thinking Python will give me more control than Hal.
Chris, I moved to Linuxcnc for Qtplasmac which I have working. I have a habit of learning stuff before I have a use for it, but once the knowledge is gained I then get eager to find a use for it LOL. One day I'd like to convert my big lathe and mill to CNC and hopefully by that time I'll have all the knowledge I need. Just need another kidney stone to give me a few weeks off work for study.
Keith.
Because I've programmed macros & plugins in UCCNC in C#, I think I've been focusing too much on Python alone, and not realising that Hal is the gateway to physical I/O as well as lots of other stuff. I've been in a mindset of thinking Python will give me more control than Hal.
Chris, I moved to Linuxcnc for Qtplasmac which I have working. I have a habit of learning stuff before I have a use for it, but once the knowledge is gained I then get eager to find a use for it LOL. One day I'd like to convert my big lathe and mill to CNC and hopefully by that time I'll have all the knowledge I need. Just need another kidney stone to give me a few weeks off work for study.
Keith.
Last edit: 29 Jun 2022 17:18 by beefy.
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
Less
More
- Posts: 23170
- Thank you received: 4860
29 Jun 2022 18:10 #246182
by andypugh
You have to programme in a particular way, realising that your code will export a function that will be called every thread cycle. This means that the function has to complete, every time, in much less than a thead cycle.
This is typically achieved by programming a state machine.
One example is here (just one that I am working on right now, it's definitely not the simplest of examples, but I know that it has a time delay in it, so shows how to do that without the function halting:
Cases 3 and 5 delay for a predetermined time before changing the state for next time the function is called. (the timer is initialised in the state that sets that state)
Docs for halcompile: linuxcnc.org/docs/stable/html/hal/comp.html
Replied by andypugh on topic Linuxcnc equivalent of UCCNC macros, macroloops, plugins
Ah, well, you can programme in C if you want. In many cases that is better as your component runs in the realtime layer, so can be art of the motion controller. In fact one of them (bldc) is intended for software commutation of brushless motors where realtime response is critical.Because I've programmed macros & plugins in UCCNC in C#, I think I've been focusing too much on Python alone,
You have to programme in a particular way, realising that your code will export a function that will be called every thread cycle. This means that the function has to complete, every time, in much less than a thead cycle.
This is typically achieved by programming a state machine.
One example is here (just one that I am working on right now, it's definitely not the simplest of examples, but I know that it has a time delay in it, so shows how to do that without the function halting:
Cases 3 and 5 delay for a predetermined time before changing the state for next time the function is called. (the timer is initialised in the state that sets that state)
Docs for halcompile: linuxcnc.org/docs/stable/html/hal/comp.html
The following user(s) said Thank You: beefy
Please Log in or Create an account to join the conversation.
Time to create page: 0.054 seconds