Hal Logic Question
- Todd Zuercher
- Topic Author
- Away
- Platinum Member
Less
More
- Posts: 5007
- Thank you received: 1441
03 Feb 2019 20:12 #125604
by Todd Zuercher
Hal Logic Question was created by Todd Zuercher
I have a general hal logic question. What might be the easiest way to detect and display the order that 3 (or more) inputs were activated and display which was 1st, 2nd, 3rd...?
Please Log in or Create an account to join the conversation.
03 Feb 2019 21:00 - 03 Feb 2019 21:00 #125609
by PCW
Replied by PCW on topic Hal Logic Question
I dont see any obvious way to do this with existing components
but a component with a reset input and some number of boolean
inputs could count thread cycles and rank inputs as to order and perhaps
time relative to the first event (with some scheme to deal with ties)
but a component with a reset input and some number of boolean
inputs could count thread cycles and rank inputs as to order and perhaps
time relative to the first event (with some scheme to deal with ties)
Last edit: 03 Feb 2019 21:00 by PCW.
Please Log in or Create an account to join the conversation.
03 Feb 2019 21:38 - 03 Feb 2019 21:48 #125611
by Grotius
Replied by Grotius on topic Hal Logic Question
Todd,
I have made a short component for you.
You can compile it by typing : halcompile --compile Todd.comp
You can test it. But you have to know how you want to implement value's to your further gui.
If i know that, i can release a full code for you.
Bitwise is kind of to simple to make a array. So i want to know how you can read in multiple value's or how you want to do that in your way. Keep in mind. It must be done in your way. Then i can do maybe some trick's for you.
You can install the component directly by typing : sudo halcompile --install Todd.comp
I don't know your current installation type. Usually the --compile function is used by develloppers. --install will copy it to
I have made a short component for you.
You can compile it by typing : halcompile --compile Todd.comp
Warning: Spoiler!
component Todd "Todd's component";
description
"""
Component for Todd.
""";
author "Todd";
license "GPLv2 or greater";
option singleton yes;
// Input Pins
pin in bit reset "reset";
pin in bit input_0 "input_0_trigger";
pin in bit input_1 "input_1_trigger";
pin in bit input_2 "input_2_trigger";
pin out bit output_0 "output_0_triggered";
pin out float output_0_time "output_0_time_that_was_triggered";
pin out bit output_1;
pin out float output_1_time;
pin out bit output_2;
pin out float output_2_time;
variable double Time; //timer
function _;
;;
FUNCTION(_) {
Time += fperiod;
// Time = 0; // This is optional, delete // at front.
if(input_0 && !input_1 && !input_2){ // here it gets input 0, time out is captured.
output_0 = 1;
output_0_time = Time;
}
if(!input_0 && input_1 && !input_2){
output_1 = 1;
output_1_time = Time;
}
if(!input_0 && !input_1 && input_2){
output_2 = 1;
output_2_time = Time;
}
if(reset){
output_0 = 0;
output_1 = 0;
output_2 = 0;
output_0_time = 0;
output_1_time = 0;
output_2_time = 0;
}
}
description
"""
Component for Todd.
""";
author "Todd";
license "GPLv2 or greater";
option singleton yes;
// Input Pins
pin in bit reset "reset";
pin in bit input_0 "input_0_trigger";
pin in bit input_1 "input_1_trigger";
pin in bit input_2 "input_2_trigger";
pin out bit output_0 "output_0_triggered";
pin out float output_0_time "output_0_time_that_was_triggered";
pin out bit output_1;
pin out float output_1_time;
pin out bit output_2;
pin out float output_2_time;
variable double Time; //timer
function _;
;;
FUNCTION(_) {
Time += fperiod;
// Time = 0; // This is optional, delete // at front.
if(input_0 && !input_1 && !input_2){ // here it gets input 0, time out is captured.
output_0 = 1;
output_0_time = Time;
}
if(!input_0 && input_1 && !input_2){
output_1 = 1;
output_1_time = Time;
}
if(!input_0 && !input_1 && input_2){
output_2 = 1;
output_2_time = Time;
}
if(reset){
output_0 = 0;
output_1 = 0;
output_2 = 0;
output_0_time = 0;
output_1_time = 0;
output_2_time = 0;
}
}
You can test it. But you have to know how you want to implement value's to your further gui.
If i know that, i can release a full code for you.
Bitwise is kind of to simple to make a array. So i want to know how you can read in multiple value's or how you want to do that in your way. Keep in mind. It must be done in your way. Then i can do maybe some trick's for you.
You can install the component directly by typing : sudo halcompile --install Todd.comp
I don't know your current installation type. Usually the --compile function is used by develloppers. --install will copy it to
This message contains confidential information
Attachments:
Last edit: 03 Feb 2019 21:48 by Grotius.
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Topic Author
- Away
- Platinum Member
Less
More
- Posts: 5007
- Thank you received: 1441
04 Feb 2019 22:43 #125699
by Todd Zuercher
Replied by Todd Zuercher on topic Hal Logic Question
I ended up just doing it with Classicladder. It was relatively simple for me there. But trying only with Hal logic was a very confusing pain and I gave up. After setting it up in ladder, I can see that it would have taken at least 9 flipflops, 9 or2 and 3 and2 to sort the order of finish for 3 inputs. All that is quite hard to follow and assemble in a hal file, but it only took 4 rungs of ladder logic.
Please Log in or Create an account to join the conversation.
- Mike_Eitel
- Offline
- Platinum Member
Less
More
- Posts: 1150
- Thank you received: 184
05 Feb 2019 19:58 #125759
by Mike_Eitel
Replied by Mike_Eitel on topic Hal Logic Question
I'm totally agree. My only concern is that I have no glue how much overhead is need for CL.
Please Log in or Create an account to join the conversation.
05 Feb 2019 20:57 - 05 Feb 2019 20:57 #125762
by rodw
Replied by rodw on topic Hal Logic Question
If you are a carpenter problems can only be solved with a hammer (or Hal or Classic ladder).
If you take the time to learn C, suddenly you have a whole toolshop at your disposal via the rich halcompile environment.
I think PCW and Grotius are on the right track to use a component and I know a few months ago Grotius had no clue about C. This is a great problem to start with and I'd recommend you take the time to learn just enough about C to write a component that solves your problem and a whole Linuxcnc new world will open. Just by reading the component code on git hub will teach you so much!
github.com/LinuxCNC/linuxcnc/tree/master/src/hal/components
Most of us who can program read a lot of other people's code as we learnt how to do it. Start by reading up on data types, then learn how it/then/else works. You probably do that in G code now so its just translating one language to another.
If you take the time to learn C, suddenly you have a whole toolshop at your disposal via the rich halcompile environment.
I think PCW and Grotius are on the right track to use a component and I know a few months ago Grotius had no clue about C. This is a great problem to start with and I'd recommend you take the time to learn just enough about C to write a component that solves your problem and a whole Linuxcnc new world will open. Just by reading the component code on git hub will teach you so much!
github.com/LinuxCNC/linuxcnc/tree/master/src/hal/components
Most of us who can program read a lot of other people's code as we learnt how to do it. Start by reading up on data types, then learn how it/then/else works. You probably do that in G code now so its just translating one language to another.
Last edit: 05 Feb 2019 20:57 by rodw.
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Topic Author
- Away
- Platinum Member
Less
More
- Posts: 5007
- Thank you received: 1441
05 Feb 2019 21:06 #125763
by Todd Zuercher
Replied by Todd Zuercher on topic Hal Logic Question
The overhead of CL is minimal, and doesn't effect how this old dumpster dived Celeron D PC I'm running it on runs. Maybe CL's overhead might be a problem on a RPi.
Learning C might be nice, but I need this to be working by tonight, and I had it working yesterday with CL.
Learning C might be nice, but I need this to be working by tonight, and I had it working yesterday with CL.
Please Log in or Create an account to join the conversation.
- Mike_Eitel
- Offline
- Platinum Member
Less
More
- Posts: 1150
- Thank you received: 184
06 Feb 2019 17:35 #125833
by Mike_Eitel
Replied by Mike_Eitel on topic Hal Logic Question
Hi Rod
I disagree.
In my pro life i did a lot of plc. I do not like cl much, the real thing for such work is iec61131. ( Used it already when it was still 1131)
I love and use the compile feature, but for doing pure logic a plc languague is better.
m5c
I disagree.
In my pro life i did a lot of plc. I do not like cl much, the real thing for such work is iec61131. ( Used it already when it was still 1131)
I love and use the compile feature, but for doing pure logic a plc languague is better.
m5c
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Topic Author
- Away
- Platinum Member
Less
More
- Posts: 5007
- Thank you received: 1441
06 Feb 2019 18:50 #125845
by Todd Zuercher
Replied by Todd Zuercher on topic Hal Logic Question
If you know an open source alternative to CL that can be integrated with Linuxcnc. I'm sure the developers would welcome it inclusion as a replacement for CL. CL in Linuxcnc has been sort of an unloved orphan for some time, but soldiers on for lack of a suitable replacement.
Please Log in or Create an account to join the conversation.
- Mike_Eitel
- Offline
- Platinum Member
Less
More
- Posts: 1150
- Thank you received: 184
06 Feb 2019 20:42 - 06 Feb 2019 21:39 #125866
by Mike_Eitel
Replied by Mike_Eitel on topic Hal Logic Question
For sure not any iec61131.
That ist heavy stuff. It's probably bigger than lcnc. Also you can buy it cheapo for rpi.
You can get an idea by watching coresys in YouTube. And you can see that it has powerfull ladder included as one of the standard 5-6 languagues.
I myself use either ST (structured text) or FB (funktion block) or SFC (structured funktion chart), depending the functionality i have to solve.
But, i have no proposal to. replace CL by ???.
Just make it a bit more user frindly. Commenting and alias etc. is all a bit tricky. Und why only 6 ranks, not more?
Quite some adjustments, to get it better looking, I had to do by modifying the file with an normal editor. Brrrrr.
Mike
That ist heavy stuff. It's probably bigger than lcnc. Also you can buy it cheapo for rpi.
You can get an idea by watching coresys in YouTube. And you can see that it has powerfull ladder included as one of the standard 5-6 languagues.
I myself use either ST (structured text) or FB (funktion block) or SFC (structured funktion chart), depending the functionality i have to solve.
But, i have no proposal to. replace CL by ???.
Just make it a bit more user frindly. Commenting and alias etc. is all a bit tricky. Und why only 6 ranks, not more?
Quite some adjustments, to get it better looking, I had to do by modifying the file with an normal editor. Brrrrr.
Mike
Last edit: 06 Feb 2019 21:39 by Mike_Eitel. Reason: Some more text ;-()
Please Log in or Create an account to join the conversation.
Time to create page: 0.080 seconds