Seafoxc

Factory I/O is a simulation software to learn PLC programming. 
You can use OpenPLC to connect with the Modbus protocol to Factory I/O. 
This code is written to run the "production line" one of the Factory I/O scene's.  

Is used the OpenPLC Runtime on Windows for this project and the language is FBD. 

Factory IO post.jpg   

The line exist out of two CNC machine centers and some conveyers. The CNC centers look difficult but it is a lot easier then it seems. 

I made a small video (3:20min) to give you an idea what the code does. 

https://youtu.be/20qy7CKbF7E


Explanation program 

First I started with some good RTFM (Read The F***ng manual) about the machine center:  https://docs.factoryio.com/manual/parts/stations/

Then I opened the scene's and changed all the variables. 
I use a variable name based if it is an Input or Output, The location, The object and the function. 

I_ = Input
Q_ = Output
Z = Zone
MC = Machine Center
Sens = Sensor
Pb = Pushbutton
BC = Band Conveyer
RC = Roller Conveyer

So for example: I_Z01BC01ArrivedSens
is an input in Zone 1 and is the arrived sensor of Band Conveyer 01. 

I added the adjusted Scene to the ZIP file. 

Object oriented programming

You have a few objects in the program like the belt conveyers but there is not a lot of control for those in the scene (no manual switch not a lot of sensors) so I did not bother to write a Function block for that. I did made a function block for the Machine center. 

FB machine center.jpgSo both Machine centers use the same function block. 

This code can be improved upon to make it easier to spot mechanical or electrical failures but it is just for training and learning so I will put my time in solving the next scene's. 
 
How to run the code?

Factory I/O set-up

First of all you need Factory I/O (There is a free trail for 30 days without credit card) => Factoryio.com.


Then you unzip the file added to this post and you copy the scene "Production_Line_renamed_var.factoryIO" to the default location of the Factory I/O scene's. 

Documents\Factory IO\MyScenes

You open Factory I/O and open the scene and go to "drivers" (key "F4").

The mapping should be already made but some options should be checked/changed.


driver.jpg 

- Write down the IP address (to be entered in the settings for OpenPLC Runtime slave settings). 

Check the configuration (IP address and Network adaptor can be different). 


settings driver.jpg 

OpenPLC Runtime settings

 - Run Open PLC runtime and add a slave. 


OpenPLCRuntime settings.jpg

- Change the IP address to the same address as in Factory I/O settings. 

Make sure the addresses look like this:



slave good.jpg 

- Upload the OpenPLC runtime project "MachineCenter.st" (file from ZIP file). 
- Set the OpenPLC in Run
- Set Factory I/O in the play setting. 

 

In the Zip file there is also the OpenPLC editor file for you to change and take a look at. 

Let me know what you think if you downloaded it. 

If you are stuck on setting up Factory I/O with OpenPLC you can also find a video on how to do it on my YouTube Channel. 







I have no Idea what I'm doing...
Reply 3 0
thiagoralves
Awesome write up! Thanks!!
Reply 1 0
BenKissBox
Nice work !
So bad that free version of Factory I/O does not support Modbus. The first version I see supporting it cost 400 euros 😕
It would be so cool to have something free with Modbus support, even with a limited number of I/Os.

A long, long time ago,I used one developed by a french company. It was very basic, running under DOS, no 3D of course 😂
I am pretty sure I still have the C source code somewhere, your video gives me the envy to look for it (I think it can be shared safely)

Benoit
Reply 1 0
thiagoralves
Well, they provide a 30-day trial for the "ultimate" edition that has all drivers included. You can try that for yourself. Usually 30 days is enough to have much fun 🙂
Reply 0 0
BenKissBox
Except that my wife would kill me if I spend 30 days to play with the software, in order not to waste any of the offered time 😂
Reply 0 0
fr.noname
Seafoxc, thank you very much. You´re great
Reply 1 0
bleaq
Thank you for that great work,but how could i make the machining cener produces lides not base?
Reply 0 0
Seafoxc
@bleaq You have to change the variable in the main program that is connected to I_ProducingLids to True.Answer.jpg 
If "I_ProducingLids" is false it will make Bases. If you run my program you have two FBD's Machine center where when is configured to make baces and the other one Lids.  
I have no Idea what I'm doing...
Reply 0 0
bleaq
@Seafoxc thanks bro i got it.
i have another quistion.The arm moves befor the door of the machining center is completly opened ,so it might hit the door how can i fix that issue?
Reply 0 0
Seafoxc
@bleaq This can't be done. All of the robot movements are controlled by Factory I/O and not the PLC. The machinecenters are mostly driven by Factory I/O and not a lot of PLC programming is needed to control them. It is definitely not a good representation for PLC communication with a robot (I have some experience with that). But it would also overcomplicate things.  
I have no Idea what I'm doing...
Reply 0 0
bleaq
@Seafoxc could you recomend any software and vidoes to control robot using PLC i am very keen on that field. 
thanks for your help
Reply 0 0
Seafoxc
@bleaq I will search Youtube for it tomorrow (today is an extremely busy) My experience is limited to one car company so there will be a lot of different ways I guess. 
I have no Idea what I'm doing...
Reply 0 0
salem_a

Hi,

I would like to know if the variables of this program are controllable in read and write or only in read please
I am creating a lab using OpenPLC and Factory IO with a pentest aimed at modifying the values of the registers but if this program does not allow the writing of Modbus variables, my lab will not work.
Thanks in advance for your response

Reply 0 0
Seafoxc
@salam_a  I'm more of a industrial programmer then a cyber security person but I'm 99% sure you can modify the output variables. They start with the prefix "Q_". 
I have no Idea what I'm doing...
Reply 1 0
thiagoralves
Per definition, Modbus allows writing to coils (digital outputs) and holding registers (analog outputs and memory). You cannot write to inputs using Modbus as the protocol does not provide a function for that. Still, even if you write to outputs, the PLC logic program will have precedence, which means that if the PLC program tells the output to be false, it will remain false even if you send a Modbus request for it to be true. This is not any cybersecurity enhancement, it is just the normal behavior of most PLCs in the market
Reply 1 0
Reply