help with component creation
- Thayloreing
- Offline
- Senior Member
Less
More
- Posts: 72
- Thank you received: 2
19 May 2024 19:49 #300974
by Thayloreing
help with component creation was created by Thayloreing
I want to make a component to select between two float inputs, but I know very little about programming, I made this program, and I wanted someone to help me by taking a look and indicating if there was any error, I haven't tested it yet, my other question is how can I load it? it in linuxcnc so I can use it, thank you in advance thank you
component sel_float "Two-input multiplexer with float inputs, conditional output, and selector";
pin in float in0;pin in float in1;pin in bit sel_in;pin out float out "The output is computed based on the values of in0, in1, and sel_in according to the following rule: If sel_in=1, out is the value of in0. If sel_in=0, out is the value of in1.";
function _ nofp;license "GPL";author "trhs";
FUNCTION(_) { if (sel_in == 1) { out = in0; } else { out = in1; }}
component sel_float "Two-input multiplexer with float inputs, conditional output, and selector";
pin in float in0;pin in float in1;pin in bit sel_in;pin out float out "The output is computed based on the values of in0, in1, and sel_in according to the following rule: If sel_in=1, out is the value of in0. If sel_in=0, out is the value of in1.";
function _ nofp;license "GPL";author "trhs";
FUNCTION(_) { if (sel_in == 1) { out = in0; } else { out = in1; }}
Please Log in or Create an account to join the conversation.
- phillc54
- Offline
- Platinum Member
Less
More
- Posts: 5704
- Thank you received: 2084
20 May 2024 02:04 #300983
by phillc54
Replied by phillc54 on topic help with component creation
There is an existing mux2 component that you could use.
linuxcnc.org/docs/2.9/html/man/man9/mux2.9.html
linuxcnc.org/docs/2.9/html/man/man9/mux2.9.html
The following user(s) said Thank You: Thayloreing
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
Less
More
- Posts: 10761
- Thank you received: 3543
20 May 2024 13:34 #301005
by rodw
Replied by rodw on topic help with component creation
You will find its source code here github.com/LinuxCNC/linuxcnc/tree/master/src/hal/components
Best way to learn C is to read it!
Not sure if it will help but try changing your if statement. Sometimes int and bool are not interchangeable.
FUNCTION(_)
{
if (sel_in) {
out = in0;
}
else {
out = in1;
}
}
Best way to learn C is to read it!
Not sure if it will help but try changing your if statement. Sometimes int and bool are not interchangeable.
FUNCTION(_)
{
if (sel_in) {
out = in0;
}
else {
out = in1;
}
}
Please Log in or Create an account to join the conversation.
Time to create page: 0.050 seconds