Real Newbie needs some help and advice
- tommylight
- Away
- Moderator
Less
More
- Posts: 19488
- Thank you received: 6535
09 Feb 2021 22:45 #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.
The following user(s) said Thank You: rodw
Please Log in or Create an account to join the conversation.
- The Feral Engineer
- Offline
- Senior Member
Less
More
- Posts: 79
- Thank you received: 22
09 Feb 2021 22:56 #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
The following user(s) said Thank You: Mike_Eitel
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
Less
More
- Posts: 10810
- Thank you received: 3559
10 Feb 2021 01:07 #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 loveEMC2 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
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
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 or Create an account to join the conversation.
- The Feral Engineer
- Offline
- Senior Member
Less
More
- Posts: 79
- Thank you received: 22
10 Feb 2021 02:08 #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 or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
Less
More
- Posts: 10810
- Thank you received: 3559
10 Feb 2021 05:31 #198244
by rodw
Well with halcompile you don't even need that!
Replied by rodw on topic Real Newbie needs some help and advice
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 or Create an account to join the conversation.
- The Feral Engineer
- Offline
- Senior Member
Less
More
- Posts: 79
- Thank you received: 22
10 Feb 2021 05:39 #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 or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
Less
More
- Posts: 10810
- Thank you received: 3559
10 Feb 2021 06:35 #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 withand through the code you will see references to the state likeAnd at the end of that section, the next state is setSo 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:
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.
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
switch(state){
case IDLE:
case TORCH_ON:
state = ARC_OK;
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.
The following user(s) said Thank You: The Feral Engineer
Please Log in or Create an account to join the conversation.
- The Feral Engineer
- Offline
- Senior Member
Less
More
- Posts: 79
- Thank you received: 22
10 Feb 2021 23:06 #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 or Create an account to join the conversation.
Time to create page: 0.065 seconds