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
salem_a
So if I want to provoke emergency stop or stopping the conveyor in remote can write in outputs for example  Q_Z01MC01Stop or Q_Z01MC02Stop or other ? (see picture of my Modbus driver in attached file please  ?
Reply 0 0
thiagoralves
If ladder logic is not controlling these outputs directly, yes, you can.
Reply 0 0
salem_a
What does it mean ? How can I check if  ladder logic is not controlling these outputs please ?
For information line production line program is opened by factory IO and connected to OpenPLC
Reply 0 0
Seafoxc
salem_a wrote:
What does it mean ? How can I check if  ladder logic is not controlling these outputs please ?
For information line production line program is opened by factory IO and connected to OpenPLC


To get a better understanding of what Is possible with forcing ModbusCoils with other software, I would advise the Radzio Modbus tool  https://en.radzio.dxp.pl/modbus-master-simulator/ (it is free).

Modbus_Radzio.jpg

Use the following settings, and then this device acts like a master and can also manipulate the values to Factory IO (The slave device).
First, try writing Coils with the Modbus tool without OpenPLC and ensure you get the hang of it (I always need to reconnect after forcing a value before it becomes active in Factory IO and also open a new file in Radzio to monitor this new status of the values).

When OpenPLC runtime is running => The PLC updates these values to FactoryIO (the slave device) and overwrites the values almost instantly (cycle time of the program).

When you put the OpenPLC runtime in stop => OpenPLC keeps writing the latest status of the Output register to the PLC (Not the same as in a real PLC with Modbus I guess? )

When you turn off OpenPLC, you can modify the values again with Radzio Tool. 
In the configuration, I use all the Outputs defined in Factory IO, so you can not manipulate any values by simply overwriting them once. 

What is the goal you want to achieve? 



 
I have no Idea what I'm doing...
Reply 1 0
mhe

Seafoxc wrote:

...When OpenPLC runtime is running => The PLC updates these values to FactoryIO (the slave device) and overwrites the values almost instantly (cycle time of the program).

When you put the OpenPLC runtime in stop => OpenPLC keeps writing the latest status of the Output register to the PLC (Not the same as in a real PLC with Modbus I guess? ) ...

The first statement is like I think about PLC and modbus master/slave communication.

But what is the sense of second statement "OpenPLC keeps writing the latest status of the Output register to the PLC" >>> what is OpenPLC ... PLC ... modbus master and modbus slave. And what is the difference between "keeps" and "cycle time of the program"?

I need help for clarification 🙋

Reply 0 0
thiagoralves
The second statement is not true. When the runtime stops, there is no writing or reading anymore
Reply 0 0
gqaiser
Hi,
Could someone please identify which sensors are used in the Production line scene?
Reply 0 0
gqaiser
Hi,
Could someone please identify which sensors are used in the Production line scene?
Seafoxc wrote:

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://www.youtube.com/watch?v=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. 







Hi,
Could someone please identify which sensors are used in the Production line scene?
Reply 0 0
Seafoxc
gqaiser wrote:
Hi,
Could someone please identify which sensors are used in the Production line scene?
 
gqaiser wrote:
Hi,
Could someone please identify which sensors are used in the Production line scene?
If you mean on the conveyers? Photoelectric Sensors of the type "sender => reflector".
I have no Idea what I'm doing...
Reply 0 0
gqaiser
Seafoxc wrote:
If you mean on the conveyers? Photoelectric Sensors of the type "sender => reflector".
What about Machine? Is there any sensor used in Machine? 
Reply 0 0
Seafoxc
I have no Idea what I'm doing...
Reply 0 0
RexJustesen
How would you use OpenPLC on a raspberry pi and set up the modbus server/client for factory I/O, I tried setting up the modbus client and was able to connect but when I tried running the Production Line it would not start. I may need to do more RTFM lol but some guidance would be very helpful. 
Reply 0 0
thiagoralves
Configure your Factory IO to use the Modbus Server driver (modbus slave). Then on OpenPLC runtime, add your Factory IO Modbus as a slave device. Take note of the IP Address, port, and registers that the driver exposes, and then fill out the fields on the OpenPLC slave device page accordingly. You will have to pick the Generic Modbus TCP template to be able to fill out the fields manually.
Reply 1 0
RexJustesen
Thank you I got it to work, so I set up the server as my Laptop and then put it as a slave device on my raspberry pi
[203128%2F8427318%2Fmceclip0]
[203128%2F8427317%2Fmceclip0]
Reply 0 0
RexJustesen
Could you control the robotic arms in the scene with OpenPLC and then output the Accelerometer, gyroscope current and other data outside of the PLC to say a csv over modbus? Or could I even use a Siemens IPC and the modbus connector to send that data to the Siemens databus? 
Reply 0 0
Reply