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!
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (assembly2relaunch)

Post by Turro75 »

Hello Kbwbe,

if You like I would talk about the solver (please correct me if I'm wrong):

1)the calculation starts by reading the contraints and creating a list of the objs which are constrained
2) for each object a RIGID obj is created, a list of them is created
3) from 109 to 337 some reference entity are prepared according to the sort of constraint, I guess rid1 and rid2 are pointers to rigid previously created. (what if the same obj share more constraints?)
4)calc_mov_data seems doing the work, for each RIGID the center of boundingbox and a movevector is calculated according to the constraint.
5) for each movestep all RIGID objs are moved by approximating to the desired movevector. Every 100 steps it is checked if the target of each constraints is achieved (is this done in parallel?).

In this way I cannot know which constraints failed, how about inserting a debugging values to print out how many steps required for each constraints?
It is very useful for fine tuning I guess.

Hey I don't want to teach You! I'm just curious and I'm looking for help You on finishing the beast.
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (assembly2relaunch)

Post by kbwbe »

Hi to everyone,

find bugfixed version here: https://github.com/kbwbe/A2plus

What has been fixed:
- solver does not damage placements any more. This caused sometimes an invalid 3D view.
- Changing of a of a constraints property (e.g. offset/direction/angle) caused multiple solves of the whole system and high system load. Fixed.
- Due to last mentioned fix automatic solving of constraints is now usable again.
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
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (assembly2relaunch)

Post by kbwbe »

Hi @Turro75,

your are really good at reading code. You recognized nearly all important things .
Turro75 wrote: Mon Jul 09, 2018 10:37 pm Hello Kbwbe,

if You like I would talk about the solver (please correct me if I'm wrong):

1)the calculation starts by reading the constraints and creating a list of the objs which are constrained
2) for each object a RIGID obj is created, a list of them is created
3) from 109 to 337 some reference entity are prepared according to the sort of constraint, I guess rig1 and rig2 are pointers to rigid previously created. (what if the same obj share more constraints?)
.
At 1+2) is correct.
At 3) As a constraint always affects two RIGID's, there are created 2 dependencies objects, each assigned to the correct RIGID. RIG1+RIG2
These dependencies are added to a list within the RIGID data structure, called "dependencies". Therefore one RIGID can manage a lot of constraints related to it.
.
Turro75 wrote: Mon Jul 09, 2018 10:37 pm 4)calc_mov_data seems doing the work, for each RIGID the center of boundingbox and a movevector is calculated according to the constraint.
5) for each movestep all RIGID objs are moved by approximating to the desired movevector. Every 100 steps it is checked if the target of each constraints is achieved (is this done in parallel?).
.
At 4) calcMoveData() does the main calculation work. Correct. But it is much more calculated as only a move vector. If it only would do this,
RIGID's could not rotate to required position. Therefore a lot of "spins" are calculated.
The main types are:
a) Spin required to align some axes
b) Spin caused by attraction of reference points (something like flying asteroids in space, which attract each other).
As both spins are derived in different methods, they have to be "weighted" before combining to an effective "spin".
Rotation Center is always the boundbox center, which was determined during loading.

Turro75 wrote: Mon Jul 09, 2018 10:37 pm In this way I cannot know which constraints failed, how about inserting a debugging values to print out how many steps required for each constraints?
It is very useful for fine tuning I guess.
Your recognized this correctly. A wrong placed constraint is disturbing the whole calculation system. Position- and spin-Errors will be distributed
over whole calculation system. So Solver will fail to find a solution with required accuracy. It is difficult to find the wrong constraint.
As each constraint is calculated with same number of steps as others, it also difficult to track where the problem is.

Best way is setting a constraint and checking it instantly via solving the system. An undo function will be sure needed.

This behavior will change at point, when some logic is added to solver concerning order of calculations. (Future versions i hope...)
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
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (assembly2relaunch)

Post by manuelkrause »

Hi @kbwbe!

Great work! Thank you for the update -- I knew you'd get this fixed :-)

Maybe that I encounter an issue with 'angledPlanesConstraint'. I don't know how to describe it straightforward, so please let me pose some questions: Is there a limitation in the max. possible angle property of the constraint, namely 180°? At least in one case within my crankshaft I wasn't able to go beyond this value, aiming at 240°, then getting mismatches (I fixed it by trial and error with other constraints finally.) Can it be dependant on the initial placement angle?

TIA,
Manuel
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (assembly2relaunch)

Post by kbwbe »

Hi Manuel,

angledPlanesConstraint does not like 0 degrees and 180 degrees. In this case the rotation axis will get lost. The parts will freeze in this position. If necessary, you have to rotate the part manually over the critical points. Only angles between 0.1 and 179.9 aprox should be used.

If you want to have 0 or 180 degrees, then planesParallelConstraint is better.

Sorry, but you can not rotate your crank shaft completely around with this constraint.
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
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (assembly2relaunch)

Post by Turro75 »

Manuel
Place the object at an almost right angle then create the constraint.
It should be fine. Then adjust the angle by small steps.

Even expensive commercial cad struggld with angled constraints
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (assembly2relaunch)

Post by manuelkrause »

@kbwbe and @Turro75,

many thanks for your hints! No problem to do it in this fashion and thanks for confirming that it's no bug. One (e.g. me) only should know about it to get it right, and somehow I've had managed it on my own. I've never had problems experimenting within CAD software loosing patience, what was quite beneficial since learning into FreeCAD. ;-)

I also like to thank @Turro75 for his comparative statements regarding commercial CAD systems, unfortunately I don't have the opportunity to use them for years now. I've tried FreeCAD years ago and found it unusable, then came back to it some months ago and was surprised about the improvements.

Thanks @kbwbe for taking up the assembly topic that I consider really important for FreeCAD's usability and a larger base of users. The latter point shouldn't be underestimated.

And, for my today's assemblies I can also confirm, that I don't get messed up assemblies any more at all. And, when using the proper constraints and values I got at most a "Total steps used: 5600", what still computes fastly on here (especially taking into account my old notebook). This progress really makes me lucky!

Manuel
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (assembly2relaunch)

Post by manuelkrause »

@kbwbe:
What do you think: Can I help you a little by adding some more documentation to the README.md at "Usage of A2plus workbench:"? First only a feature list with some copy&paste of the tooltips' information?
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (assembly2relaunch)

Post by kbwbe »

manuelkrause wrote: Tue Jul 10, 2018 4:31 pm
And, for my today's assemblies I can also confirm, that I don't get messed up assemblies any more at all. And, when using the proper constraints and values I got at most a "Total steps used: 5600", what still computes fastly on here (especially taking into account my old notebook).
.
Thank you for feedback! Very fine ! ;)
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
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (assembly2relaunch)

Post by kbwbe »

manuelkrause wrote: Tue Jul 10, 2018 5:08 pm @kbwbe:
What do you think: Can I help you a little by adding some more documentation to the README.md at "Usage of A2plus workbench:"? First only a feature list with some copy&paste of the tooltips' information?
Appreciated. Please PM drafts.
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
Post Reply