Another approach to assembly solver (A2plus)

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
topyra
Posts: 12
Joined: Thu Nov 12, 2020 8:55 pm

Re: Another approach to assembly solver (A2plus)

Post by topyra »

kbwbe wrote: Sat Nov 28, 2020 9:40 pm Compared to other numeric solvers the one of A2+ is not sensitive to redundant constraints and sometimes an additional constraint can stabilize computations. With adding the pointOnLine constraint at least i could extend the range where the simulation is working properly.
Ok, got it.
Thank you for help.
topyra
Posts: 12
Joined: Thu Nov 12, 2020 8:55 pm

Re: Another approach to assembly solver (A2plus)

Post by topyra »

I also noticed that solver works more stable then in animate mode, when I just change constraint parameter and click solve.

So in my example I changed from axisCoincident constraint between shock absorber top and bottom (kunckle) to circularEgde between edges with offset.
And with simple macro I can animate this with way more rare instabilities (mostly because I added few more constraints now for axle and constant velocity joints)

Code: Select all

for x in range(10, 150, 10):
	FreeCAD.getDocument('frontAsm').getObject('circularEdge_005_mirror').offset = str(x)+' mm'
	Gui.runCommand('a2p_SolverCommand',0)
	Gui.updateGui()

for x in range(140, 10, -10):
	FreeCAD.getDocument('frontAsm').getObject('circularEdge_005_mirror').offset = str(x)+' mm'
	Gui.runCommand('a2p_SolverCommand',0)
	Gui.updateGui()
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

topyra wrote: Sun Nov 29, 2020 8:27 pm And with simple macro I can animate this with way more rare instabilities
Did your assembly fail during script execution ?
I added one circularEdge constraint, adapted it's name in the script and it is working on my side.
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
topyra
Posts: 12
Joined: Thu Nov 12, 2020 8:55 pm

Re: Another approach to assembly solver (A2plus)

Post by topyra »

kbwbe wrote: Sun Nov 29, 2020 9:19 pm Did your assembly fail during script execution ?
I added one circularEdge constraint, adapted it's name in the script and it is working on my side.
In model that I sent before it works without fails.
But now I have a bit complicated model, with added few more constraints and now it sometimes fail, even when configured from script.

Possibly too much constraints at the time right now
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

topyra wrote: Sun Nov 29, 2020 9:46 pm In model that I sent before it works without fails.
But now I have a bit complicated model, with added few more constraints and now it sometimes fail, even when configured from script.

Possibly too much constraints at the time right now
If your new assembly isn't top secret, please post it. I will then have a look. There are still other optimizations possible (Adjustments to the solver).
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
topyra
Posts: 12
Joined: Thu Nov 12, 2020 8:55 pm

Re: Another approach to assembly solver (A2plus)

Post by topyra »

In my model I fixed ShockBtmRF_001 to KuckleRF_001 with two circularEdges - it is not necessary (in previous model two parts was merged), but I like to use it that way to simulate wheel alignment setting using eccentric fasteners between that two parts.
But it not caused serious convergency problems.
When I added green axles, the problems start to rise and right now, just when you load model in it default position solver is unable to solve it.
In some orientations it still works, but really hard.

I also took a look into source of your solver.
I like how it is written - nice clean code, that I can read and understood even with nearly lack of Python knowledge.
But maybe it is good time for me to finally learn Python ? ;) (as a C/C++ programmer I can't get used to Python indentations)

I was able to do step-by-step simulation by changing solverControlData to do more smaller steps of pos/spinAccuracy, and not requiring accuracy below 0.05, but I looked around whole your code.
I spent only 2h looking into it. so just got some basics of your concept, maybe you would like to use some of my experience with similar problem, that I resolved with similar idea as your.
Main difference was that I was not applying 'move' to rigids to lower an error, but I was applying just a force like a spring - when error was bigger, there was bigger force applied for both rigids to bring then closer to proper position.

Each rigid body had own mass and moment of inertia (I think for such FreeCAD solver it could even be a random - I love randomness in numeric simulations) - so applied force changes a speed of rigid body and rotation around body mass center (when applied not directly into mass center it generates torque).

It would end with endless vibrations, so each constrain also applying a dump force. Each constrain measuring it own stretching/squeezing (could be also rotating etc) speed measured just like: (last_frame_length-this_frame_length)/frame_time and applying dumping force proportional to that speed, but with opposite direction.

To stabilize calculations I added in similar way as you, some 'play' distance that was permitted error for each constrain.

Finally every rigid calculates resultant force and torque that changes speed and rotation of this rigid.
Then each timeframe results in changing position and rotation of each rigid.

With ~100 simple constrains, and few thousands steps per frame I was able to solve it still with 60fps (and it was 10 years ago on one thread) - for sure my constrains was simpler, and permitted errors was higher.

I think it could be good idea to use more physical-like simulation - changing speed and rotation between each convergency step should give result even faster.
Attachments
suspension.tar.gz
(360.59 KiB) Downloaded 166 times
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

topyra wrote: Mon Nov 30, 2020 11:00 pm
Hi @topyra,
thank you very much for your detailed feedback. I see, you have a lot of experience with simulations.
topyra wrote: Mon Nov 30, 2020 11:00 pm But maybe it is good time for me to finally learn Python ? ;) (as a C/C++ programmer I can't get used to Python indentations)
Very good idea. A good IDE is managing the indentations. (I use Eclipse with the PyDev plugin)
topyra wrote: Mon Nov 30, 2020 11:00 pm ... that I resolved with similar idea as your.
Main difference was that I was not applying 'move' to rigids to lower an error, but I was applying just a force like a spring - when error was bigger, there was bigger force applied for both rigids to bring then closer to proper position.

Each rigid body had own mass and moment of inertia (I think for such FreeCAD solver it could even be a random - I love randomness in numeric simulations) - so applied force changes a speed of rigid body and rotation around body mass center (when applied not directly into mass center it generates torque).

It would end with endless vibrations, so each constrain also applying a dump force. Each constrain measuring it own stretching/squeezing (could be also rotating etc) speed measured just like: (last_frame_length-this_frame_length)/frame_time and applying dumping force proportional to that speed, but with opposite direction.
When i remember correctly the start of this project, i tried something similar. Perhaps i have made to many mistakes, so i did not have success.

topyra wrote: Mon Nov 30, 2020 11:00 pm Then each timeframe results in changing position and rotation of each rigid.
With ~100 simple constrains, and few thousands steps per frame I was able to solve it still with 60fps (and it was 10 years ago on one thread) - for sure my constrains was simpler, and permitted errors was higher.
Using Python instead of C/C++ is much slower, because Python is an interpreter language. You can calculate factor 50-100 slower.
topyra wrote: Mon Nov 30, 2020 11:00 pm I think it could be good idea to use more physical-like simulation - changing speed and rotation between each convergency step should give result even faster.
Trying this again is a fine exercise for rainy weekends.

Thank you for your files. I will try to analyse what the problem is. In past, such instabilities often dealed with calculating (moving) refpoints. An example is the nearest point between to axes. With each calculation step it can jump from one place to a far away another one.

P.S: or it was just a programming bug. :D

Greetings,
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
topyra
Posts: 12
Joined: Thu Nov 12, 2020 8:55 pm

Re: Another approach to assembly solver (A2plus)

Post by topyra »

kbwbe wrote: Tue Dec 01, 2020 3:59 pm
Thank you for your files. I will try to analyse what the problem is.
So far I figured out that problem is in two circularEdge constrains that connects armRF_ShockBtmRF_001 and armRF_KnuckleRF_001

i.e. for armRF_KnuckleRF_001 one of constrains returns moveVector.x = ~ 0.08020..., but second returns ~ -0.08173
And despite that both constrains have significant error ~0.08 (that is biggest error here) moveVectorSum is about zero and step do not going to solve.

From model side it may be fixed just by remove this two constrains and merge this two parts.

But from solver point of view it looks like the issue is with adding move vectors that in this case subtracts two moves in opposite direction.
In physics when object is pushed in two opposite directions it do not move, but when this forces are applied in different origins (and that is what we have here) the object starts to rotate.

In time based simulation with applied force, the rotation coming from each force is around mass center, around axis that direction is (AFAIR) dot product of force direction and origin (in LCS where mass center is in 0,0,0), divided by moment of inertia of rigid.
Sum of rotation vectors from all the forces applied to rigid is the resulting rotation.

You are working on 'moves', but guess rotation should be calculated in similar way - I need to think for a while on it.
I found that you already calculate it in depRefPoints_Spin and depMoveVectors_Spin, but this rotation is way too slow, or there is something else not right here - I'll try to debug it out.

BTW - do you know how to draw, from Python level, a 3D arrow of given origin and direction?
It would greatly improve my debug capabilities to draw some arrows representing all the intermediate vectors that are used to calculate each step of solving.
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

topyra wrote: Tue Dec 01, 2020 8:20 pm BTW - do you know how to draw, from Python level, a 3D arrow of given origin and direction?
It would greatly improve my debug capabilities to draw some arrows representing all the intermediate vectors that are used to calculate each step of solving.
I have made a help request in the scripting section.
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Another approach to assembly solver (A2plus)

Post by Kunda1 »

kbwbe wrote: Wed Dec 02, 2020 10:42 am I have made a help request in the scripting section.
Hi @kbwbe, care to post a link to said thread?

Edit: found it
https://forum.freecadweb.org/viewtopic. ... 92#p453592
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply