[suggestion] Add PLC (Programmable Logic Controller) to electricity items
11 replies, posted
Since the game has logic gates, then why not make a super hard to craft item that takes very rare crafting items to build called a PLC? (it should be very hard to make because it would make a player's base very OP w/o needing a wall full of logic gates or require advance boolean logic understanding).
A programmable logic controller is a controller used in manufacturing to automate processes that has electrical inputs and outputs that are programmed/reprogrammed to perform a function using ladder logic instead of programming language statements like used for PC's or your Raspberry pi or Arduino, or whatever is the hot item for microcontrollers these days. It's a bit like a "visual style" programming that follows an electrical wiring diagram, only it's virtual, but works like the real thing as though real switches and relays are wired up, but not. Let me explain.
So the PLC will look like a box that takes power and has an output section and input section with terminal screws and will be labeled for each screw terminal with letters or numbers. So you may have a PLC from XYZ manufacturer that has 6 inputs and 4 outputs. The terminal screws on the input section could be labeled as A0, A1, A2, A3, A4 and A5. and the output section could be B0, B1, B2 and B3. The letters are used in ladder logic to id what terminal you want the program you write to get signals from and where to output them at when logical conditions you programmed are met.
In the software you have many rows and many columns in the programmer software for inputs' side and a single column with many rows at the very far end for the outputs' side. The rows are the 'rungs" of the ladder logic and the columns are where the switch contacts are placed or in the output section it could be a relay coil, timing block, math block, etc..
So to write a program you put in contacts and assign them one of the many terminal letter id's as printed on the terminal block input side. So maybe you have like 5 virtual contacts that all needs to be true in order for some virtual relay output coil to be energized and is assigned one of the output terminal letter id's.
Example:
INPUT SECTION OUTPUT SECTION
----------|A0|--------|A1|---------|A2|----------|A3|---------|A4|-------------------||||-------------------(B0)-----------
In the above, when power is applied to all 5 virtual contacts to the real world input terminals labeled the same, then the virtual output coil B0 will be on and the power to the real world terminal B0 will be active. This example circuit is the same thing as a 5 input AND logic gate where all 5 inputs must be true in order for output to be true. These contact are called normally open in that they are in their active state when power is applied to the input terminals.
The opposite to this is the normally closed contact that will be an open circuit when power is applied. Just like the blocker in rust. So:
Example of normally closed contacts |/|:
---------|/A0|--------|/A1|-----------||||--------------(B0)-----------
Here the output B0 is active as long as neither A0 or B0 are active. Just like having two blockers on a wire in rust.
And here is how you do a rust memory cell in ladder logic:
-------|A0|---------------------------||||------------(B0)----------
| |
|------|B0|-----|
In the above example when power is applied to the real world terminal A0, the virtual contact will be true and the output coil, B0 will energize. Removal of power from A0 will not turn off B0 because B0 is keeping a contact active that is wired parallel to the A0 contact. So it "remembers" the last state.
Finally, I want to leave you guys with a real world program I did on a PLC:
https://files.facepunch.com/forum/upload/387730/ed4d1650-6181-4a40-8d98-7ebf2baa4aeb/PLCExample.jpg
Ok I have no idea what any of this means XD
It does the work of many logic gates into one compact unit that all you need to know is that a ladder rung that has continuity from left to all the way to the right side where the output is, will result in the output being active. And any break in that continuity by a contact will have no continuity unless said contact is active by input signal applied to the input terminal. So you can do all logic functions with virtual switch contacts. The device would look something like this or go to google search for images and type in PLC:
Inputs Outputs
________________
|A0 B0|
|A1 B1|
|A2 B2|
|_______________|
The logic functions are as follows when programming the PLC:
Always ON. No break in continuity.
----------------------------------------------||||--------------( )--------
AND logic is any contacts in series on a rung.
--------| |------| |-------
OR logic is any contacts in parallel on a rung.
--------| |---------------
| |
|-------| |------|
NOT logic is the normally closed contact.
---------|/|---------
XOR Logic.
--------|A0|-------|/A1|----------------------------
| |
|-------|/A0|------|A1 |-------|
Memory logic or Flip-Flop is where an active input contact switch makes a virtual relay coil or a control bit stay active such that when said input contact is no longer active, the output virtual relay keeps the rung active by the contact controlled by the virtual relay coil wired parallel to the input contact:
--------|A0|------------------------------------||||-------------(B0)---------
| |
|-------|B0|------|
To have reset function you could do this.
--------|A0|---------------|/A1|------------------||||-------------(B0)---------
| |
|-------|B0|------|
Then you have virtual relays that do not map to a real world output terminal, but instead are used to control input contacts in the software in the PLC.
--------------------------| |---------------| |--------------------||||--------(C0)----------
Above, the C output coil (control bit) does not control a real world output, but can be used to make an input contact active on its own rung (If wired as flip flop) or on another rung.
Finally you have function output blocks that do specific things when a rung attached to them is active: like count up or down, time on or time off, math, or sequencer(drum), etc...The function blocks do the same function that stand alone devices could do , but is instead a software version that mimics the real thing and can control the outputs to the real world on the PLC.
Here are a few examples:
https://files.facepunch.com/forum/upload/387730/3829f327-dbf3-499c-a384-38163d58cc64/Untitled2.jpg
I program these as part of my job. They're pretty easy to learn and you can do a ridiculous amount of stuff with them. I wouldn't mind at all if these were added.
I heard from Vice (A rust youtuber that does base builds and electrics) that he asked helk about something similar and he said this is way too complicated for rust and not many people would use it
I figured I'd used the same words and setup to describe the workings as rust does for the electrical components. Here is some ideas. Maybe I can get Helk to see this forum post?
Here is what it could look like in rust (Well I'm no artist lol, just a concept to get an idea):
https://files.facepunch.com/forum/upload/387730/bdb4e524-f6f8-4539-920e-d6e8189a8fd1/PLCrust.jpg
The programming interface when player double clicks on the PLC display:
https://files.facepunch.com/forum/upload/387730/fbd42e16-e1fd-46fc-ab91-bb0fb4b58cae/PLCprogramlayout.jpg
Here are some example ideas of how to hook this up to other components in rust:
https://files.facepunch.com/forum/upload/387730/78fffddd-c756-4d06-986f-ead6ce7c762b/flipfloptrap.jpg
and
https://files.facepunch.com/forum/upload/387730/fbe9a8dd-bf6d-4378-b633-1789cfb8d95b/doorcontroller.jpg
Make it as hard as you want, but please make it intuitive for complete noobs like me to be able to make some things with all of that x'D
I wish I had this when I was making my Master Code lock.
https://files.facepunch.com/forum/upload/381043/b208c2a0-3c04-4e15-b248-8c9e16343b95/Rust 1_2_2019 6_44_49 PM.avi
I already suggested this in another thread.
The basic Idea was to allow a " storage box" of gates to be collected, then either a logic equation Or a drawn logic system to be implemented.
The reason being was to make the logic stateful & scalable.
But I don't see a reason to make it overly complicated, you could still use the same existing parts, and drawing area, but you force it to be a black box to reduce node count.
As it stands..... as the number of inputs increases the node count goes up exponentially in computing requirements, and the computing requires every node is monitored and re calculated., (combiners & splitters make this way worse, implementing a "nand" gate takes 9 nodes of re-calculation instead of 3)
with a black box it is a "micro second" calculation/ straight look up, as it stands you are into Milisecond turn around & tree systems. (root nodes effect branches... good luck)
This is explained as the "corn/rice grain" on the first square of a chess board , 2 grains on the second etc....... 4,8 etc.
If you work on FPGA's (programmable logic) you will soon realize that as it stands it is an untenable position... thats why mentor graphics & others charge thousands of $ for their logic simulation software.
I think using logic gates or logic equations programming interface for the PLC to add to this game would make it harder. A programmable logic controller was made to be programmed by non-computer/ non-EE savvy electricians in the manufacturing plant. That is why PLC's use contact symbols and coil symbols to represent input and outputs just like ladder wiring diagrams are drawn. It's a visual style programming that brings wiring diagrams to "life", basically. If you can visualize the flow of power from left to right and see that a contact symbol ( ----| |----) is like an open to that flow, then you can visualize closing that contact by making it turn "on" when the letter/numeral from the input terminal you choose that is assigned to that contact, gets power, which makes the contact turn "on" and thus, continues the flow of power on to the right until some other obstacle is in the way or you get to the end where it turns on a relay coil ( 0 ) that is assigned an output terminal letter/numeral.
Here is what I mean:
https://files.facepunch.com/forum/upload/387730/8964fc14-7784-431c-85af-f956e677bafc/example1.jpg
In top area of picture, no power is being applied to the terminal pin X001. When I hook power to terminal X001 on my PLC, it will then highlight the contact symbol blue, to show that it is now active and allowing "power flow" to continue from left to right until it reaches the output coil that is assigned to output terminal Y001, which then turns on power to that output terminal on the PLC.The END statement tells the PLC that no more ladder code is left, and to start the re-scan back to the beginning.
Here is how a PLC executes instructions. First, it looks at all the inputs and stores their states to a binary input image table. Then It starts at the very top of the ladder program area at the very left and starts to evaluate the contact symbols on the ladder rung from left to right, checking the input image table for zeros and ones it got from the input pins that correspond to your assigned pin(s) you gave the contact(s). One's turn on contacts, zero's turn them off, unless its an inverted contact or also called a normally close contact, then zero turns it on. Then it will either store a zero or a one to the output image table if the rung evaluated true all the way to the output coil symbol, but it DOES NOT turn on the output pins yet. Next, it goes down to the next rung and does the same thing, and on and on, until it reaches the END statement.
Once it has reached the end statement, it will then turn on or off the output terminals that correspond to the output image table's one's and zero's assigned terminal pins. FInally, it starts execution back at the beginning to do the whole process again. A complete scan time is when it has done all those functions up to the END state. Usually, PLC's have a scan time of a few microseconds to a few milliseconds.
It would be nice indeed to use a PLC in rust, and it not too overcomplicated since people are now using the same gates as in a plc program.
instead of the STEP7 symbols we might use the rust symbolics? to make it more understandable?
As it stands..... as the number of inputs increases the node count goes up exponentially in computing requirements, and the computing requires every node is monitored and re calculated., (combiners & splitters make this way worse, implementing a "nand" gate takes 9 nodes of re-calculation instead of 3)
They could have an optimization method put in that would be like a compiler. It would further reduce nodes by simplifying the logic in smart ways like a compiler. To me most of what a compiler does is PFM so I might be using this analogy wrong.
Sorry, you need to Log In to post a reply to this thread.