FreeCAD as pre-post processor for MBDyn

About the development of the FEM module/workbench.

Moderator: bernd

User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by mfasano »

I tried your workbench and was able to create a single pendulum and a double pendulum that ran the simulation successfully. The animation only worked for the single. Though the code works there are errors generated with many of the commands

The error I got trying to animate the double pendulum was,

Code: Select all

Running the Python command 'MBdyn_Animate1' failed:
Traceback (most recent call last):
  File "C:\Users\Matt\Documents\FreeCAD_0.19.22894_Win-LPv12.1.6_vc14.x-x86-64\Mod\freecad-mbdyn-dynamics-workbench-master\MBdynGui.py", line 316, in Activated
    dyn.StartAnimation()
  File "C:\Users\Matt\Documents\FreeCAD_0.19.22894_Win-LPv12.1.6_vc14.x-x86-64\Mod\freecad-mbdyn-dynamics-workbench-master\dynamics.py", line 371, in StartAnimation
    ani.start()
  File "C:\Users\Matt\Documents\FreeCAD_0.19.22894_Win-LPv12.1.6_vc14.x-x86-64\Mod\freecad-mbdyn-dynamics-workbench-master\animation.py", line 281, in start
    self.retrieve()
  File "C:\Users\Matt\Documents\FreeCAD_0.19.22894_Win-LPv12.1.6_vc14.x-x86-64\Mod\freecad-mbdyn-dynamics-workbench-master\animation.py", line 106, in retrieve
    aux1 = FreeCAD.ActiveDocument.getObjectsByLabel('structural: '+str(x))[0] #Every body must have a structural node linked to it    

list index out of range
One thing I found strange is when I create the world reference, the part design model in the Solids group lost the hierarchy in the model tree.
Here is a link to the picture of the tree before
https://github.com/mfasano727/MBDynFCwb ... t_tree.JPG

and after
https://github.com/mfasano727/MBDynFCwb ... ee_mbd.JPG

I liked some of the features of the workbench, like highlighting the objects on the viewscreen when you hover over them on the tree.

I will try to look at you code, and try other models soon.

Here is my version info.
OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22894 (Git)
Build type: Release
Branch: master
Hash: 9eb080488d970d313c538473e7272117ea0a7cd1
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: FreeCAD as pre-post processor for MBDyn

Post by realthunder »

josegegas wrote: Tue Jan 26, 2021 3:41 am This is an idea I´ve had in mind for a while. I have seen people struggle to write an assembly workbench for FreeCAD for years. There is assembly 2, but it only works for assembies with few parts and it often cannot solve relatively complicated assembies. Assembly 4 is a nice tool, but the lack of a solver capable of telling you how your assembly will move is a limitation. I think the reason for FreeCAD lacking an assembly workbench with the capabilities of most commercial packages is that it is quite complex to program/solve the ODEs needed. MBDyn does exactly this, it solves the assembly before performing the dynamic simulation. I think it may be worth to explore the idea of using MBDyn, or parts of it, to program an assemby workbench for FreeCAD. This workbench would generate nodes for each bodies and apply some constraints, then pass an input file for MBDyn to solve the assemby and may be even return the kinematics, so that the user can see an animated assembly, not a full MBD simmulation, but just the motion of the bodies. What do you think?
Hi, asm3 author here. Not sure if you've heard of my assembly workbench. It is designed to work with some solver. I am using SolveSpace solver at the moment. It works fine, but got license problem, so can't easily bundle with FreeCAD. Besides, I am also looking for a way to hook with some physics simulator. Looks like MBDyn might be a fit. Does MBDyn handle collision detection also?
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by mfasano »

realthunder wrote: Thu Jan 28, 2021 12:55 pm
josegegas wrote: Tue Jan 26, 2021 3:41 am This is an idea I´ve had in mind for a while. I have seen people struggle to write an assembly workbench for FreeCAD for years. There is assembly 2, but it only works for assembies with few parts and it often cannot solve relatively complicated assembies. Assembly 4 is a nice tool, but the lack of a solver capable of telling you how your assembly will move is a limitation. I think the reason for FreeCAD lacking an assembly workbench with the capabilities of most commercial packages is that it is quite complex to program/solve the ODEs needed. MBDyn does exactly this, it solves the assembly before performing the dynamic simulation. I think it may be worth to explore the idea of using MBDyn, or parts of it, to program an assemby workbench for FreeCAD. This workbench would generate nodes for each bodies and apply some constraints, then pass an input file for MBDyn to solve the assemby and may be even return the kinematics, so that the user can see an animated assembly, not a full MBD simmulation, but just the motion of the bodies. What do you think?
Hi, asm3 author here. Not sure if you've heard of my assembly workbench. It is designed to work with some solver. I am using SolveSpace solver at the moment. It works fine, but got license problem, so can't easily bundle with FreeCAD. Besides, I am also looking for a way to hook with some physics simulator. Looks like MBDyn might be a fit. Does MBDyn handle collision detection also?
I do not believe MBDyn does collision detection. The input file is not given information about the geometry of the bodies. If MBDyn were to be used as a solver in this way, I guess it would require some modification. It may only be matter of separating the functions that does the initial assembly. I don't know about solving only the kinematics. I am only a user of MBDyn.

@realthunder do you have any ideas about collision detection. They use octrees in gaming for that, but I don't see that as needed since geometry of the parts is already well defined.
User avatar
ceremcem
Posts: 226
Joined: Sun Jan 07, 2018 11:10 am

Re: FreeCAD as pre-post processor for MBDyn

Post by ceremcem »

josegegas wrote: Tue Jan 26, 2021 3:41 am I think the reason for FreeCAD lacking an assembly workbench with the capabilities of most commercial packages is that it is quite complex to program/solve the ODEs needed. MBDyn does exactly this, it solves the assembly before performing the dynamic simulation.
What do you think about Assembly3? It works quite nice in our production line. Do you think the efforts can be merged (or shifted to Assembly3)?
User avatar
mfasano
Posts: 122
Joined: Wed Apr 11, 2018 12:31 pm

Re: FreeCAD as pre-post processor for MBDyn

Post by mfasano »

ceremcem wrote: Thu Jan 28, 2021 6:06 pm What do you think about Assembly3? It works quite nice in our production line. Do you think the efforts can be merged (or shifted to Assembly3)?
I thought about how to use MBDyn with an assembly workbench that uses a solver. I wondered if it would be easier to use an MBDyn joint element called the total joint. It is a joint that can be configured to mimic any other joint MBDyn has available. I thought it might be easier to configure the total joint to match the constraints rather than try to figure which specific joint to use.
josegegas
Posts: 255
Joined: Sat Feb 11, 2017 12:54 am
Location: New Zealand

Re: FreeCAD as pre-post processor for MBDyn

Post by josegegas »

mfasano wrote: Thu Jan 28, 2021 11:19 am I tried your workbench and was able to create a single pendulum and a double pendulum that ran the simulation successfully. The animation only worked for the single. Though the code works there are errors generated with many of the commands

The error I got trying to animate the double pendulum was,

Code: Select all

Running the Python command 'MBdyn_Animate1' failed:
Traceback (most recent call last):
  File "C:\Users\Matt\Documents\FreeCAD_0.19.22894_Win-LPv12.1.6_vc14.x-x86-64\Mod\freecad-mbdyn-dynamics-workbench-master\MBdynGui.py", line 316, in Activated
    dyn.StartAnimation()
  File "C:\Users\Matt\Documents\FreeCAD_0.19.22894_Win-LPv12.1.6_vc14.x-x86-64\Mod\freecad-mbdyn-dynamics-workbench-master\dynamics.py", line 371, in StartAnimation
    ani.start()
  File "C:\Users\Matt\Documents\FreeCAD_0.19.22894_Win-LPv12.1.6_vc14.x-x86-64\Mod\freecad-mbdyn-dynamics-workbench-master\animation.py", line 281, in start
    self.retrieve()
  File "C:\Users\Matt\Documents\FreeCAD_0.19.22894_Win-LPv12.1.6_vc14.x-x86-64\Mod\freecad-mbdyn-dynamics-workbench-master\animation.py", line 106, in retrieve
    aux1 = FreeCAD.ActiveDocument.getObjectsByLabel('structural: '+str(x))[0] #Every body must have a structural node linked to it    

list index out of range
One thing I found strange is when I create the world reference, the part design model in the Solids group lost the hierarchy in the model tree.
Here is a link to the picture of the tree before
https://github.com/mfasano727/MBDynFCwb ... t_tree.JPG

and after
https://github.com/mfasano727/MBDynFCwb ... ee_mbd.JPG

I liked some of the features of the workbench, like highlighting the objects on the viewscreen when you hover over them on the tree.

I will try to look at you code, and try other models soon.

Here is my version info.
OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22894 (Git)
Build type: Release
Branch: master
Hash: 9eb080488d970d313c538473e7272117ea0a7cd1
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)
Hi. It is great you were able to reproduce the pendulums! Even considering I still didn´t make a tutorial. One key idea of the working process Is to create simple (non-parametric) parts before you set a simulation. The reason is that I sometimes find problems when obtaining the mass and inertia of parametric parts. So the idea is to go to part->create a simple copy of all your parts and then work with these non-parametric parts for the MBD simulation. I bet the errors you got were because of this. Also, you will find the non-parametric models of all the examples in the "samples" folder or from the FreeCAD menu, so you can work with these models.

I also downloaded your workbench and were able to set the pendulum example. I think a good plan may be to take the best parts of both workbenches and try to combine them. My workbench is lacking a propper configuration manager, so that for example the user can select the working folder and the path to an executable of MBDyn. I see yours already has this. We may start combining both workbenches, taking the best of each.... By the way, I am working on a new animation.py and will be updating the repository soon. This new file will basically do the same animation but will hopefully be simpler and for sure shorter...
josegegas
Posts: 255
Joined: Sat Feb 11, 2017 12:54 am
Location: New Zealand

Re: FreeCAD as pre-post processor for MBDyn

Post by josegegas »

mfasano wrote: Thu Jan 28, 2021 1:28 pm
realthunder wrote: Thu Jan 28, 2021 12:55 pm
josegegas wrote: Tue Jan 26, 2021 3:41 am This is an idea I´ve had in mind for a while. I have seen people struggle to write an assembly workbench for FreeCAD for years. There is assembly 2, but it only works for assembies with few parts and it often cannot solve relatively complicated assembies. Assembly 4 is a nice tool, but the lack of a solver capable of telling you how your assembly will move is a limitation. I think the reason for FreeCAD lacking an assembly workbench with the capabilities of most commercial packages is that it is quite complex to program/solve the ODEs needed. MBDyn does exactly this, it solves the assembly before performing the dynamic simulation. I think it may be worth to explore the idea of using MBDyn, or parts of it, to program an assemby workbench for FreeCAD. This workbench would generate nodes for each bodies and apply some constraints, then pass an input file for MBDyn to solve the assemby and may be even return the kinematics, so that the user can see an animated assembly, not a full MBD simmulation, but just the motion of the bodies. What do you think?
Hi, asm3 author here. Not sure if you've heard of my assembly workbench. It is designed to work with some solver. I am using SolveSpace solver at the moment. It works fine, but got license problem, so can't easily bundle with FreeCAD. Besides, I am also looking for a way to hook with some physics simulator. Looks like MBDyn might be a fit. Does MBDyn handle collision detection also?
I do not believe MBDyn does collision detection. The input file is not given information about the geometry of the bodies. If MBDyn were to be used as a solver in this way, I guess it would require some modification. It may only be matter of separating the functions that does the initial assembly. I don't know about solving only the kinematics. I am only a user of MBDyn.

@realthunder do you have any ideas about collision detection. They use octrees in gaming for that, but I don't see that as needed since geometry of the parts is already well defined.
I think it depends what you whant to model. It may be difficult to model the collision of entire parts, but one can easily model the collision of two nodes, as is shown in this example:

https://www.sky-engin.jp/en/MBDynTutori ... hap26.html

I recently simulated this robot gripper using my workbench:

https://www.youtube.com/watch?v=SSBGMisHZho

And someone asked me if there is any kind of collision or contact in the simulation. There is not. The bolt simply moves sincronised with the gripper. However it should not be that hard to model the contact between the gripper and the bolt with a code similar to that in the link above.

To try to identify collision between any of the parts would be much harder. For this one would have to give MBDyn information about the geometry, which I do not think is possible.
Last edited by josegegas on Fri Jan 29, 2021 3:37 am, edited 1 time in total.
josegegas
Posts: 255
Joined: Sat Feb 11, 2017 12:54 am
Location: New Zealand

Re: FreeCAD as pre-post processor for MBDyn

Post by josegegas »

mfasano wrote: Thu Jan 28, 2021 6:31 pm
ceremcem wrote: Thu Jan 28, 2021 6:06 pm What do you think about Assembly3? It works quite nice in our production line. Do you think the efforts can be merged (or shifted to Assembly3)?
I thought about how to use MBDyn with an assembly workbench that uses a solver. I wondered if it would be easier to use an MBDyn joint element called the total joint. It is a joint that can be configured to mimic any other joint MBDyn has available. I thought it might be easier to configure the total joint to match the constraints rather than try to figure which specific joint to use.
Yes I have also been thinking the total joint would be easier to use, because we would only have to program one scripted object to create a total joint within FreeCAD, and use it to model a wide range of assemblies, however my attempts to do so did not go well. Total joints have more parameters to set than the other joints, which makes them more difficult to integarte with FreeCAD.
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: FreeCAD as pre-post processor for MBDyn

Post by realthunder »

mfasano wrote: Thu Jan 28, 2021 1:28 pm @realthunder do you have any ideas about collision detection. They use octrees in gaming for that, but I don't see that as needed since geometry of the parts is already well defined.
Most detection algorithm can't work with arbitrary geometry. It usually assumes the meshes are convex. So you'll first need to decompose the mesh into parts of convexed ones, e.g. with this. But I think it also needs a specialized iterative solver that can back down if collision happens.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
josegegas
Posts: 255
Joined: Sat Feb 11, 2017 12:54 am
Location: New Zealand

Re: FreeCAD as pre-post processor for MBDyn

Post by josegegas »

realthunder wrote: Thu Jan 28, 2021 12:55 pm
josegegas wrote: Tue Jan 26, 2021 3:41 am This is an idea I´ve had in mind for a while. I have seen people struggle to write an assembly workbench for FreeCAD for years. There is assembly 2, but it only works for assembies with few parts and it often cannot solve relatively complicated assembies. Assembly 4 is a nice tool, but the lack of a solver capable of telling you how your assembly will move is a limitation. I think the reason for FreeCAD lacking an assembly workbench with the capabilities of most commercial packages is that it is quite complex to program/solve the ODEs needed. MBDyn does exactly this, it solves the assembly before performing the dynamic simulation. I think it may be worth to explore the idea of using MBDyn, or parts of it, to program an assemby workbench for FreeCAD. This workbench would generate nodes for each bodies and apply some constraints, then pass an input file for MBDyn to solve the assemby and may be even return the kinematics, so that the user can see an animated assembly, not a full MBD simmulation, but just the motion of the bodies. What do you think?
Hi, asm3 author here. Not sure if you've heard of my assembly workbench. It is designed to work with some solver. I am using SolveSpace solver at the moment. It works fine, but got license problem, so can't easily bundle with FreeCAD. Besides, I am also looking for a way to hook with some physics simulator. Looks like MBDyn might be a fit. Does MBDyn handle collision detection also?
Have a look at this example:

https://www.sky-engin.jp/en/MBDynExampl ... /ex25.html

I am not sure if it will be possible to work with complex shapes though. In this example only the radius and thickness of the coin are enough to define its geometry. I have never tried to model an example like this one using more complicated shapes...
Post Reply