VirtualPlant — a 3D Factory Simulator
Tags: godot, opcua, plc
Published: 2022-11-09 20:11:25

Thanks to a little time working-from-home at the start of 2021, I decided to embark on a small prototype of a 3D factory simulator.

I had used commercial simulation software before such as CIROS, Siemens NX, and Factory.io, All of them are great software- much broader in scope than this little project — but since all of these are paid software, and I like the challenge of writing software from scratch, i figured i would see what i can come up with myself…


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d98klh3pzgl8bvvs1r3l.jpeg)

---

###Goals
I set myself a few goals to achieve

Any Physical or Soft PLC with OPCUA should be able to communicate with the virtual environment
The environment should be physics based
The environment should be flexible enough to be expandable to multiple use cases

The engine of choice was Godot. I chose Godot as I had used it a year or so earlier, and it was completely cross-platform, and open-source allowing me to develop on both my mac and windows systems. VirtualPlant will build and run on Windows/Linux/Mac — and is to my knowledge the only Factory simulator to do so.
The communication to PLC’s would be handled by node-opcua. I chose to abstract this to a second language as (1) I had used node-opcua previously (2) Theoretically, the abstraction means future communication drivers can be written without the need to edit the program itself.
Godot communicates with the drivers via WebSockets
(Basic) 3D work was completed in blender.

### Comms Structure

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ehauke2g2rirmxo4grti.png)

---

###Initial Prototypes

Some early test work, getting the physics to behave nicely, and testing a very simple OPCUA driver, which I eventually re-wrote

{% embed https://www.youtube.com/watch?v=AVyEjZSSBq4 %}

A little extra eye candy later, and things stopped looking quite so primary-school

{% embed https://www.youtube.com/watch?v=T2N_FqrIFQc %}

###Feature Creep
One shortcoming of this project, is since the end-goal was to “have fun and make something useful” I didn’t really know where to stop.

Once basic conveyors, sensors and gates were implemented, I simply kept going.

I added Robot Arms, With full IK, and a vacuum gripper, so that you can pick place and control the position from your PLC program

{% embed https://www.youtube.com/watch?v=sdvsgZ9FwOM %}

I added Liquid Handling (In a limited capacity, including colour mixing

{% embed https://www.youtube.com/watch?v=99KuPYWt38k %}

And Finally, I added it all together.

Robots, and Liquid and Boxes full of liquid.

{% embed https://www.youtube.com/watch?v=99KuPYWt38k %}
So after a week or so’s work, I’m fairly pleased with the software.


---

{% embed https://www.youtube.com/watch?v=US_obtj7SvU %}

It works pretty well, has an integrated OPCUA Server and Client, and could be a useful teaching tool. Unfortunately, as time moves on, I am unable to keep up development of this software — So it will probably sit in limbo for a while, until i work out a good use case.
If anyone has any suggestions, please let me know :)

For now, documentation and more information is available at https://virtualplant.didacticservices.co.uk/#/

Please contact me if you would like to give it a try.