Skip to content

Multi input AND/OR; - #4720

Merged
andypugh merged 1 commit into
LinuxCNC:masterfrom
dirkx:feat-multi-input-and-or
Oct 28, 2026
Merged

andypugh merged 1 commit into
LinuxCNC:masterfrom
dirkx:feat-multi-input-and-or

Conversation

@dirkx

@dirkx dirkx commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Multi input AND/OR; much along the lines of logic(9) but with a controlled unconnected pin value that helps during machine conversation (as you can simply comment out some feed) and an easier to read name.

Should implement all @BsAtHome and others their suggestions in issue #4711 and #4721. Manual pages converted to adoc.

…olled unconnected pin value that helps during machine conversation and an easier to read name.
option default_personality 8;
option default_count 1;

license "ASLv2";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of license is that?

It would probably fail for RTAI because anything not GPL will taint the kernel.

Besides, if you need this specific license, then it must also be added to debian/copyright, which needs consensus to ensure compatibility.

@dirkx dirkx Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to GPL; Was the Apache Software License v2

@@ -0,0 +1,36 @@
component and "Multi input AND gate";
pin in bool in##[128:personality] = 1 "input pins, up to personality-1";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 128 not excessive?

Can you give an example where you'd need more than 40..50 inputs AND'ed together?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the case I have here/that started here was steps control in a 2D conveyer belt/palletrizer is 4x5 position = 20 pallets x (8 mount sensors) + 5 normal interlocks. So I rounded up to the next multiple of 2. Happy to make that 64.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other case is a pneumatic sorter where I have two sets(in/out) of blockage/low-pressure/high pressure detects in each of the 41 (don't ask -- I suspect the designer mixed inches v.s metric) linear stations. Though in this case you could roll up each of the 2x3 sets into a 41 OR and then combine each pair with a normal OR into the 3 outputs needed for the pump/tank.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convinced. I guess it would probably be better to use 255 instead of 128. That would give pins in-00 through in-99 and then three digits up til in-254.

The reason for not having this at 256 is that logic uses the last byte (does personality & 0xff). That effectively creates pins 0..254 on the outset in logic.

@@ -0,0 +1,33 @@
component or "Arbitrary input OR gate";
pin in bool in##[128:personality] = 0 "in";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc string "in" is a bit thin, isn't it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grin :) took it from one of the other modules - elaborated :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - was not able to remove it - as a "" or none will give corrupted output / seems to concatenate the in and out. So have instead made it a more elaborate string.

@@ -0,0 +1,33 @@
component or "Arbitrary input OR gate";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AND gate you use the term "Multi". Why is this "Arbitrary"? What is arbitrary about these inputs?

Why not retain the comp doc string I wrote?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -0,0 +1,36 @@
component and "Multi input AND gate";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component naming and and or may prove confusing with and2 and or2. That is why I called them and_n and or_n. The underscore is converted into a dash for the hal internals, but if you don't like that, then you can use names=.

So, any particular reason to the naming?

@dirkx dirkx Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None particularly; but _n seeded a bit extra. Changed to _n.

function _ "Logical AND";

see_also """
*or*(9),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use emphasis. The post-processor cannot handle it and links will no longer be provided in the html version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grin :) took it from one of the other modules; now removed.


option period no;
option default_personality 8;
option default_count 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default count is implicitly one. Why set it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grin :) took it from one of the other modules - removed :)

is TRUE.
""";

function _ "Logical AND";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you add a doc string. But in the or you don't. Not consistent. You may also want to elaborate... I think it is rather obvious that it calculates the logical AND. But what makes this so special, that is why you document it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - will fix by removing this for the AND

@andypugh

Copy link
Copy Markdown
Collaborator

If the main improvement over "logic" is that this one allows for a default value for unconnected inputs, would it make more sense to modify "logic" to support this?

@dirkx

dirkx commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

That was exaxtly my first approach - the problem is that this gets quite complex/weird for things like an xor/xand and so on; you almost have to introduce third HiZ style state (which makes things slow as you need to do it every loop - as halcmd can chance something).

And given how trivial and AND and OR are; and how common these are (lots of stations on a line all needing to request hydraulics or air and this OR-ed together for the main pump; or lots of interlocks getting combined) -- this was easy/natural and also makes the hal files easy to read/understand.

Obviously the other approach would be to generate more of the HAL files with some m4 or similar macro language; and make the numbering/creation much more automatic/generated. But that makes the CE/machine directive and other paperwork a lot more complex. So hence this strawman.

@rene-dev

Copy link
Copy Markdown
Member

would these replace and2 and or2?

@grandixximo

grandixximo commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

would these replace and2 and or2?

I don't think so, these seems to be useful for when you have to group together alarm signals or similar into one single output, but and2/or2 are much more versatile than that.

@andypugh
andypugh merged commit 536d1ba into LinuxCNC:master Oct 28, 2026
17 checks passed
@BsAtHome

Copy link
Copy Markdown
Contributor

@andypugh Why was this merged? I had a lot of comments that were replied upon but never changed in the code.

@andypugh

Copy link
Copy Markdown
Collaborator

@andypugh Why was this merged? I had a lot of comments that were replied upon but never changed in the code.

I mis-read and thought that the issues had been addressed.

@andypugh

Copy link
Copy Markdown
Collaborator

It does not appear to be possible to re-open the PR, which is going to complicate matters.

@grandixximo

Copy link
Copy Markdown
Contributor

@dirkx are you able to work on the review pointers, and send in a new PR?

@BsAtHome

Copy link
Copy Markdown
Contributor

It does not appear to be possible to re-open the PR, which is going to complicate matters.

Yeah, that is a bummer...

@dirkx you should re-submit the PR with the suggested changes, which you also acknowledged. Then it will run through review once again.

@dirkx

dirkx commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Ack. Done as #4746.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants