best practice for creating a "digital twin" - simulation version of a real machi

More
13 Nov 2022 21:13 #256606 by piflixe
Dear LinuxCNC community!

I thought it would be practical to have a simulation version of our real machine. The simulation could be used to test several things eg. changes and compatibility on post-processor, tweaking of the UI or custom UI elements, changes to the ini config, training of team-members to the use of LinuxCNC etc.

So my aim is to have a digital twin version of the real machine, as close as possible without extraordinary effort or overhead. However, I would like the simulation to always reflect the latest changes to the config of the real machine. So I am wondering if there is best practice for that. I could think of several options:
- is there a way of having a "if SIMULATION" syntax in the config files?
- is there way of including / excluding certain files to the ini / hal? then the simulation / real machine sections could be stored in different files and the main file would only include parts of the configs that apply to both real machine and simulation config.
- something else?

Some links I found in the forum so far:
- simalar question , but unanswered
- tbc

thank you for your help!

Please Log in or Create an account to join the conversation.

More
13 Nov 2022 22:24 #256619 by andypugh
It is possible for HAL files to be written in Tcl, which can allow for conditional execution.

However it might be simpler to have two separate INI files which share the common stuff via an INCLUDE.

linuxcnc.org/docs/stable/html/config/ini....html#_include_files

So they would have some HAL files in common, and the same axis definitions, but one would connect to a Vismach model and one to the real hardware.

So each twin would have an INI something like:
#INCLUDE main.inc
[HAL]
common.hal
simulator.hal

And the other:
#INCLUDE main.inc
[HAL]
common.hal
hardware.hal
The following user(s) said Thank You: piflixe

Please Log in or Create an account to join the conversation.

More
13 Nov 2022 22:25 #256620 by andypugh
Just be aware that any [SECTION] that needs to be different has to be included in its entirety, you can't distribute a [SECTION] throughout the substantive document.

Please Log in or Create an account to join the conversation.

More
14 Nov 2022 12:39 #256680 by piflixe
thanks so much for the quick reply! I will try that straight away.

Yes I thought that [SECTION]s can't be torn apart but thanks anyway for the hint!

Please Log in or Create an account to join the conversation.

More
28 Nov 2022 21:29 #257896 by piflixe
I tried splitting the ini file as described above. I then copied the hal files from the simulation example into the config folder and linked them in the [HAL] section.

However, homing seems not to work correctly. I think the reason for this is that my homing direction is different than in the simulation example. I tried to figure out how the simulated_home.hal works but I couldn't find the virtual home switches in the hal file.

Could anyone point out to me how I can solve this or give some advice?
Thank you!

Please Log in or Create an account to join the conversation.

More
28 Nov 2022 22:33 #257903 by andypugh
You probably found the file? github.com/LinuxCNC/linuxcnc/blob/master...b/simulated_home.hal

It is using the "comp" HAL component to make something that behaves a bit like a home switch:
linuxcnc.org/docs/stable/html/man/man9/comp.9.html

(the hysteresis makes it behave a little like a real switch)

This sets the home switch positions, you would probably need to change the numbers.
net Xhomeswpos => comp_x.in0
net Yhomeswpos => comp_y.in0
net Zhomeswpos => comp_z.in0

sets Xhomeswpos 1
sets Yhomeswpos .5
sets Zhomeswpos 2

And You might also need to swap in0 and in1 for each comp so that it works in the direction that you want.

Also, personally I would change
net Xhomeswpos => comp_x.in0
sets Xhomeswpos 1

To
setp comp_x.in0 1

Which has exactly the same effect.

Please Log in or Create an account to join the conversation.

More
30 Dec 2022 22:35 #260584 by piflixe
just for reference to other users who might encounter the same issue: attached you find the modified simulated_home.hal . I kindly ask to change the file on github as well or at least add the comments to make it more human-readable.  

File Attachment:

File Name: simulated_home.hal
File Size:1 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
30 Dec 2022 22:44 #260591 by JT
You can do a pull request and get credit for the added information.
github.com/LinuxCNC/linuxcnc/pulls

JT
The following user(s) said Thank You: piflixe

Please Log in or Create an account to join the conversation.

More
02 Jan 2023 10:11 - 02 Jan 2023 10:12 #260757 by piflixe
Thanks for the remark. That's what I did: github.com/LinuxCNC/linuxcnc/pull/2236 - still a git novice but always keen on learning new git functions.
Last edit: 02 Jan 2023 10:12 by piflixe. Reason: added link to pull request

Please Log in or Create an account to join the conversation.

Time to create page: 2.107 seconds
Powered by Kunena Forum