- Posts: 22010
- Thank you received: 3
Real Newbie needs some help and advice
- tommylight
-
- Online
- Administrator
-
Less
More
5 years 8 months ago #198210
by tommylight
Replied by tommylight on topic Real Newbie needs some help and advice
For me HAL was the best thing ever since i know electronics so that just worked for me.
And it is the single most reason i love EMC2/LinuxCNC.
And it is the single most reason i love EMC2/LinuxCNC.
Please Log in to join the conversation.
- The Feral Engineer
- Offline
- Senior Member
-
Less
More
- Posts: 79
- Thank you received: 0
5 years 8 months ago #198213
by The Feral Engineer
Replied by The Feral Engineer on topic Real Newbie needs some help and advice
I like both and will continue to use both
Please Log in to join the conversation.
5 years 8 months ago #198234
by rodw
But the ability to write your own component to extend the system is the best thing ever since I know programming so that just worked for me.
And it is the single most reason i love [strike]EMC2[/strike] Linuxcnc....
Really the architecture of Hal where complex systems can be broken up into small discrete components firewalled from the rest of the system and you can write your own which is treated as if its part of the core code is Hal's hidden gem (for those that venture there). And it often gets rid of the obfuscation in hal files some have mentioned...
Replied by rodw on topic Real Newbie needs some help and advice
tommylight wrote: For me HAL was the best thing ever since i know electronics so that just worked for me.
And it is the single most reason i love EMC2/LinuxCNC.
But the ability to write your own component to extend the system is the best thing ever since I know programming so that just worked for me.
And it is the single most reason i love [strike]EMC2[/strike] Linuxcnc....
Really the architecture of Hal where complex systems can be broken up into small discrete components firewalled from the rest of the system and you can write your own which is treated as if its part of the core code is Hal's hidden gem (for those that venture there). And it often gets rid of the obfuscation in hal files some have mentioned...
Please Log in to join the conversation.
- The Feral Engineer
- Offline
- Senior Member
-
Less
More
- Posts: 79
- Thank you received: 0
5 years 8 months ago #198237
by The Feral Engineer
Replied by The Feral Engineer on topic Real Newbie needs some help and advice
All i know about C is #include<stdio.h> and even that is probably wrong
Please Log in to join the conversation.
5 years 8 months ago #198244
by rodw
Well with halcompile you don't even need that!
Replied by rodw on topic Real Newbie needs some help and advice
The Feral Engineer wrote: All i know about C is #include<stdio.h> and even that is probably wrong
Well with halcompile you don't even need that!
Please Log in to join the conversation.
- The Feral Engineer
- Offline
- Senior Member
-
Less
More
- Posts: 79
- Thank you received: 0
5 years 8 months ago #198247
by The Feral Engineer
Replied by The Feral Engineer on topic Real Newbie needs some help and advice
Can you send me information on getting that to work? I tried to find information on it and it was piecemeal at best. I got busy, so I kinda gave up my search for a while, but I'd love to get into that. If you have anything you can send me to get me started with it, I'd greatly appreciate it.
Please Log in to join the conversation.
5 years 8 months ago #198249
by rodw
Replied by rodw on topic Real Newbie needs some help and advice
The halcompile docs are pretty good.
linuxcnc.org/docs/devel/html/hal/comp.html
But then duck over to git and have a look at the source for some of the core components (like and2) in this folder for inspiration. You learn so much just reading code.
github.com/LinuxCNC/linuxcnc/tree/master/src/hal/components
Copy one of these and use it as a template to write your own component. Thats how I do it!
Just ignore all the documentation stuff at the beginning. They are processed to make the man pages.
You just have to remember that the servo thread is a timer interrupt service loop that fires every millisecond and every hal component has to be serviced in that millisecond or following errors will occur. So a component needs to short sharp and sweet! Do not use any for or while loops. You do not need to use them as you can simply loop using the servo loop (eg increment a variable this time round and increment it again the next invocation until you get the result you want!.
You will also need to understand variable scope, eg. global variables, and static variables. Basically, global variables above the function keep their value between loops. variables in the function are created on every call so there is no memory of its value unless it is defined as a static variable.
Often you need to do something on the first pass through a component to set some values or something. I usually do it something like this:
Or you want to save a value so you can use it next time (which may also require some config on the first pass.
The other useful construct is a state machine. State machines have several steps that they will pass through and you can use a switch() statement to work though each step. once step 1 is satisfied, set a variable to the next step and so on and then the last state sets it back to the first state.
plasmac.comp has a lot of states defined from line 266 as an ENUM. The state machine begins on line 609 with
and through the code you will see references to the state like
And at the end of that section, the next state is set
So the next pass through the process, execution will commence at
Mind you Plasmac is not a stellar example of the short sharp sweet components I started with but careful use of states allows this 1800 line component work perfectly! It would be possible to break it up into smaller components at the expense of greater complexity in the hal file. If you look at the core components, they are often just a couple of lines or < 10 lines.
Anyway, that should get you going.
linuxcnc.org/docs/devel/html/hal/comp.html
But then duck over to git and have a look at the source for some of the core components (like and2) in this folder for inspiration. You learn so much just reading code.
github.com/LinuxCNC/linuxcnc/tree/master/src/hal/components
Copy one of these and use it as a template to write your own component. Thats how I do it!
Just ignore all the documentation stuff at the beginning. They are processed to make the man pages.
You just have to remember that the servo thread is a timer interrupt service loop that fires every millisecond and every hal component has to be serviced in that millisecond or following errors will occur. So a component needs to short sharp and sweet! Do not use any for or while loops. You do not need to use them as you can simply loop using the servo loop (eg increment a variable this time round and increment it again the next invocation until you get the result you want!.
You will also need to understand variable scope, eg. global variables, and static variables. Basically, global variables above the function keep their value between loops. variables in the function are created on every call so there is no memory of its value unless it is defined as a static variable.
Often you need to do something on the first pass through a component to set some values or something. I usually do it something like this:
Code:
static int first_pass = 1;
if first_pass{
// do some configuration stuff
first_pass = 0;
}
Or you want to save a value so you can use it next time (which may also require some config on the first pass.
Code:
static int last_value;
int this_value = my_hal_pin;
int delta = this_value - last_value;
// do some stuff
//At the end, save this value to be last value
last_value = this_value;
The other useful construct is a state machine. State machines have several steps that they will pass through and you can use a switch() statement to work though each step. once step 1 is satisfied, set a variable to the next step and so on and then the last state sets it back to the first state.
plasmac.comp has a lot of states defined from line 266 as an ENUM. The state machine begins on line 609 with
Code:
switch(state){
case IDLE:
Code:
case TORCH_ON:
Code:
state = ARC_OK;
Code:
case ARC_OK:
Mind you Plasmac is not a stellar example of the short sharp sweet components I started with but careful use of states allows this 1800 line component work perfectly! It would be possible to break it up into smaller components at the expense of greater complexity in the hal file. If you look at the core components, they are often just a couple of lines or < 10 lines.
Anyway, that should get you going.
Please Log in to join the conversation.
- The Feral Engineer
- Offline
- Senior Member
-
Less
More
- Posts: 79
- Thank you received: 0
5 years 8 months ago #198334
by The Feral Engineer
Replied by The Feral Engineer on topic Real Newbie needs some help and advice
Very eager to get on this. Thank you, sir.
Please Log in to join the conversation.
Time to create page: 0.067 seconds
