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 (A2plus)

Post by Turro75 »

kbwbe wrote: Sat Jul 14, 2018 4:15 pm @Turro75,

please HELP !

I am trying to reassemble my platform-testfile (attached again).
The file is my previous version i assembled before. It works with your optimized algorithm in this state.

When i delete all constraints and reassemble it following your rules, in early state solver failure happens.

Can you please test and confirm or post back correctly assembled platform ?
So i could have a look what i am doing wrong.
it is because You started constraining bottom plate to the cilynders and then You constrained piston to cylinders right?
the first step is solving the first step which is the point coincidence (spherical in this case) on each which lock z-x-y but leaves free Yaw, pitch and roll. the problem is that after this solve step the placement of the cylinders is (wrongly) considered as locked. This assembly needs them still free on rotation. this is the dark side of my approach, perfect for mechanical and sequencial chained assemblies where in this case the best approach is trying to solve all together. The way at the moment is setting constraints in away that all Object1 of each constraints isn't a fixed part as it was your assembly before.

the solution will be handling DOF.
Last edited by Turro75 on Sat Jul 14, 2018 4:53 pm, edited 1 time in total.
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 »

Thank you...
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
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Another approach to assembly solver (A2plus)

Post by Jee-Bee »

Turro75 wrote: Sat Jul 14, 2018 1:31 pm 1) in an assembly at least one part must be marked as fixed
2) when creating a constraint always select as first the reference object and then the object that must be moved.
3) manually pay attention to recursive constraint creation
I don't agree with you're points... at least first 2 not.
  1. The fist point is probably the way to interpret the meaning of fixed. For me is marking fixed something like add a part to an assembly moving it around a bit and when it looks nice mark it fixed but it don't have any constaint even if it's locked.
    Every Part have 6 degrees of freedom and every position and orientation in the model space is possible but valid. When all 6 dofs are constraint is preferable above fixed.
  2. Thouldn't be an issue since the assembly is leading and not the added part. If the assebly is moving to the part there is something wrong. Only difficulty at least within FreeCAD all parts are equal in FreeCAD...
  3. If you mean you shouldn't do more that the needed constraints... i don't agree.
    Earlier i had to do with models with a lot of holes for EMC free doors. And i made once the mistake that if i added two constraints on (2 x 2) holes it was good. The door was made and the door doesn't fit. Off course they came to me but i was hey in the model everything works. But after some trials we figured out it was a lucky shot of me. In the two sets of holes there was a max difference of 0.2 - 0.3 mm and that was enough that a door didn't assembled.
    Since then i add at least 3 or 4 constraints on sets of holes. And the assembly solver should accept that!
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Post by Turro75 »

Jee-Bee wrote: Sat Jul 14, 2018 5:40 pm
Turro75 wrote: Sat Jul 14, 2018 1:31 pm 1) in an assembly at least one part must be marked as fixed
2) when creating a constraint always select as first the reference object and then the object that must be moved.
3) manually pay attention to recursive constraint creation
I don't agree with you're points... at least first 2 not.
  1. The fist point is probably the way to interpret the meaning of fixed. For me is marking fixed something like add a part to an assembly moving it around a bit and when it looks nice mark it fixed but it don't have any constaint even if it's locked.
    Every Part have 6 degrees of freedom and every position and orientation in the model space is possible but valid. When all 6 dofs are constraint is preferable above fixed.
  2. Thouldn't be an issue since the assembly is leading and not the added part. If the assebly is moving to the part there is something wrong. Only difficulty at least within FreeCAD all parts are equal in FreeCAD...
  3. If you mean you shouldn't do more that the needed constraints... i don't agree.
    Earlier i had to do with models with a lot of holes for EMC free doors. And i made once the mistake that if i added two constraints on (2 x 2) holes it was good. The door was made and the door doesn't fit. Off course they came to me but i was hey in the model everything works. But after some trials we figured out it was a lucky shot of me. In the two sets of holes there was a max difference of 0.2 - 0.3 mm and that was enough that a door didn't assembled.
    Since then i add at least 3 or 4 constraints on sets of holes. And the assembly solver should accept that!
Fixed means not moved by the solver, of course it can be manually placed where needed. It is a good behavior place the fixed (reference) object near origin to help the solver during calculation.

As there are several kind of cad for different targets ( mechanical, arch, naval, etc ) there are different kind of assemblies. My needs are better solved by using that technique. Of course there are other ways. I simply reports what I learned during years of modelling and what teachers explained me while trainings.

During cad training one of the main rule for making a robust assembly that won't break and need to be rebuilded after some modification was simply avoid the random use of reference and moveable parts. You should imagine how you ideally would build the assembly in the reality and then create constraints following that path.
In the experiment I'm doing the first object selected during constraint creation is the fixed part and the second is the part that moves relative to the first obj.
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Another approach to assembly solver (A2plus)

Post by manuelkrause »

Hi, you brave assemblers! ;-)

Today I've given @Turro75's solversystem.py a try, too. Main reason was, not being able to give free the "fixed" set crankshaft and add the appropriate A2plus constraints (while still having all other constraints in place).

In general I absolutely agree with @Turro75's rules on how to make a valid and reasonable assembly, in fact it's just the same I've had learned and what worked best with CAD systems I've used. Of course, one is free and sometimes forced to try other approaches i.e. different assembly paths when the solver behaves too stubborn. IMO, avoiding circular or contradicting dependencies is the most important thing, one should pay attentention to, when assembling.

O.k., now to my experiences with @Turro75's solversystem.py:
* It works really fast for the first constraints.
* Sometimes it does just nothing in the scene, although reporting success. I've noticed it first with a 'planeParallel' where I haven't obeyed the FATHER->SON relationship from a 'fixed' part to the one to be moved. This can also happen with 'planeCoincident' and 'angledPlanes'. ATM, I assume, this happened where it wasn't clear, what should be FATHER and what the SON.
* ATM, it seems like it doesn't deal correctly with manually edited Placement values in 'Property view' on an already constrained parts. One effect on here was: My first part, engine housings, suddenly got moved away although set "fixed", resulting in a quite scrambled assembly. (BTW, second part, crankshaft, also set 'fixed', remained in place.)

I know, this is all quite experimental stuff, so don't read this as complaint. Maybe this info helps to get attention to the corresponding code to be fixed.

Best regards, and thank you for your work,
Manuel
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Post by Turro75 »

Thanks Manuel for your testing

the reason of the failure are pretty clear to me, first let me explain the output of the solver:

it starts analysing all constraints in the assembly by setting an object as SON this is second object selected when constraint has been created, its position is relative to the first object which is set as FATHER, the true or false means if an object is locked or free to move:

Code: Select all

SON: tube100_001 = False
     FATHER: MainBody_001 = True
Added tube100_001 with 2 dependencies
Constraint involved: circularEdgeConstraint_001__tube100_001 
SON: turning_90deg_001 = False
     FATHER: tube100_001 = False
SON: tube100_002 = False
     FATHER: turning_90deg_001 = False
when it find a SON where all Fathers are locked it adds the constraints to the list of the constraints that must solved.

when the constraints are solved, it locks all SON already solved (this is the reason why on some assemblies it won't work!) and restart the scan where some more objects are locked so new constraints will be solved and so on. When there are no constraints that have a SON with all FATHER locked, it takes all constrains not yet solved and try to solve them all together.

I will change it as if it fails to solve in this way it reverts to original solver.

If You want You can simply change the constraints that involve the fixed part of Your assembly, simply select the fixed part as second object. This will avoid any constraints match the scan so the original solver will take place.
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 »

Turro75 wrote: Sun Jul 15, 2018 2:21 pm
I will change it as if it fails to solve in this way it reverts to original solver.
Hi @Turro75.
Please ensure optimized solver falling back to original one on failure. This is highly appreciated as solver has to work always and has not to fail in special cases.

If i get a modified version which is able to do, i can merge it after intensive testing. With current version it is not possible.
But i am sure you will make it happen. ;)
Last edited by kbwbe on Sun Jul 15, 2018 3:57 pm, edited 1 time in total.
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 (A2plus)

Post by manuelkrause »

@Turro75:

I'll most likely play around with your solver a little more after your proposals.

Thank you for your added explanations. I think I've understood the base of your concept. And it's equal with my experience for my first constraints and for when I wrongly mixed best FATHER and SON relation.
But I haven't understood all. When having two FATHERS and a SON to be moved and rotated, according to constraint1->FATHER1(move) and constraint2->FATHER2(rotate), does it work? It's just a shot into the blue, but that may be the problem I'm facing ATM.

And that a Property - FIXED part gets moved by solver constraints is a showstopping NOGO. (Even if the constraints are calculated & solved perfectly.) That concerns me very much ATM, as it happened again.

Side question: When providing an assembly file for your testing, is it sufficient to only post this, or do you need the individual sub-assembly files as well? I haven't any insight about the contents of the assembly .fcstd file.
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Post by Turro75 »

kbwbe wrote: Sun Jul 15, 2018 2:41 pm
Turro75 wrote: Sun Jul 15, 2018 2:21 pm
I will change it as if it fails to solve in this way it reverts to original solver.
Hi @Turro75.
Please ensure optimized solver falling back to original one on failure. This is highly appreciated as solver has to work always and has not to fail in special cases.

If i get a modified version which is able to do, i can merge it after intensive testing. With current version it is not possible.
But i am sure you will make it happen. ;)
I tried, it behaves very bad. probably at the moment the best is revert to old logic. let me a couple of days...

In the meanwhile I'm looking for a long term solution which could be:

1) the solver is effective but slow (actually python on my laptop is slow), since it is pure math it would make sense rewriting calcmovedata and moverigids in c++ or freepascal and use them as external dll overriding the overhead due to python's slowness, I'm confident it will boost a lot the solving timing allowing a better precision and increasing the number of max steps.

2) the idea to split the assembly in several sub assemblies to lower the load on solver isn't so bad, I'm thinking about determine if an obj is fully constrained to its father (all 6 DOF locked to the father)so creating a part container of both and use the container as boundbox reference. after the system is fully solved, simply delete the part container keeping globalplacement of sub objects. In theory it would work but I'm not so confident on future of part containers.
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Post by Turro75 »

manuelkrause wrote: Sun Jul 15, 2018 3:55 pm @Turro75:

I'll most likely play around with your solver a little more after your proposals.

Thank you for your added explanations. I think I've understood the base of your concept. And it's equal with my experience for my first constraints and for when I wrongly mixed best FATHER and SON relation.
But I haven't understood all. When having two FATHERS and a SON to be moved and rotated, according to constraint1->FATHER1(move) and constraint2->FATHER2(rotate), does it work? It's just a shot into the blue, but that may be the problem I'm facing ATM.

And that a Property - FIXED part gets moved by solver constraints is a showstopping NOGO. (Even if the constraints are calculated & solved perfectly.) That concerns me very much ATM, as it happened again.

Side question: When providing an assembly file for your testing, is it sufficient to only post this, or do you need the individual sub-assembly files as well? I haven't any insight about the contents of the assembly .fcstd file.
the logic solves together all constraints where the fathers have fixed position, if one of the fathers isn't yet locked it skips that constraints unless the second father become locked.

fixed parts shouldn't be moved at all by solver, in fact it skips them, may be a bug in the updating position function. I'll check.

it is enough the assembly as it contains all the shapes. single part files are only needed in case of editing.
Post Reply