Another approach to assembly solver (A2plus)

Discussion about the development of the Assembly workbench.
kbwbe
Posts: 939
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Postby kbwbe » Tue Jul 17, 2018 9:44 am

project4 wrote:
Tue Jul 17, 2018 5:41 am
Please elaborate that. An example will definitely help.
The required section "if __main__"... is in github repo now, within all branches..
If you now create a symlink within your FreeCAD Makro-Folder pointing to your development-folder/solversystem.py, you can invoke solversystem.py
from FreeCAD's makro manager. So you can solve manual via makro and test the changes you have done.
project4 wrote:
Tue Jul 17, 2018 5:41 am
How do you and Turro are developing?
I am editing python code with Eclipse + pyDev addon. I have a symlink from FreeCAD's Mod-Folder to complete Dev-Workbenchfolder. So iam working
usually with the actual development version...
project4 wrote:
Tue Jul 17, 2018 5:41 am
kbwbe wrote: I can supply some test assemblies, done with A2plus. So you would have more test material. What do you like PM ? Zip here ?
ZIP here could be great. Might be useful to others as well.
Find 2 files attached. They are fully constrained. You have only to hit "solve" after loading. The crankshaft file is the absolute performace killer.
There are some small error messages when opening the pump file. It is nothing severe and caused by a previous version i used.
.
project4 wrote:
Tue Jul 17, 2018 5:41 am
kbwbe wrote: So what do you mean exactly with "cache" ?
I think there are some data that might be cached.
For example, with my test assembly that has only 5 parts and few constraints the loadSystem function takes 2ms, if there are no parts added/removed from the assembly, it might not be needed to rebuild the whole structure again.

I've asked about A2 caching. You wrote somewhere that you didn't take its caching logic since you thought it might have problems.
- If you need solving, something has been changed in assembly. Therefore you always will have to reload system. I think no cache needed.
- I did not use Hamish's cache, but implemented a own one for updating/reimporting parts. So A2plus only opens file once during reimport if there are more than one instance of a part in assembly.
Attachments
pump.fcstd
(682.18 KiB) Downloaded 14 times
crankshaft.fcstd
(37.85 KiB) Downloaded 13 times
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.45c, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
project4
Posts: 153
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Postby project4 » Tue Jul 17, 2018 1:32 pm

Guys, a little brainstorming using Turro's chart:
Cattura1.PNG
Cattura1.PNG (37.11 KiB) Viewed 233 times
Assuming the arrows are in both directions, since I don't want to follow the 2'nd rule of father->son relation, so lets say the algorithm don't know who is the father and who is the son...

I start calculations from Part1 since it's fixed in place, so Part1 can say to Parts 2,3,4: I'm your father!
Assuming all 3 parts (2,3,4) are now in the working queue (since its father said so).
Those 3 parts are looking on the links they have, part4 have 3 links that are not in the working queue yet, so those are only candidates for next calculations, meaning part4 can be calculated without a problem at that stage.

Part 2 and 3 look on their links and find that both are children of the same father, and have some next candidates as well.
Assuming there is no rule 2 and we don't know that part2 is pointing to part3, does that mean parts 2 and 3 should be calculated together to resolve them both?
project4
Posts: 153
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Postby project4 » Tue Jul 17, 2018 1:44 pm

Turro75 wrote: ping
kbwbe wrote: ping
as I understood, that's the right way to notify you by a post...
kbwbe
Posts: 939
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Postby kbwbe » Tue Jul 17, 2018 3:05 pm

project4 wrote:
Tue Jul 17, 2018 1:32 pm
Guys, a little brainstorming using Turro's chart:
Cattura1.PNG
Cattura1.PNG (37.11 KiB) Viewed 220 times
project4 wrote:
Tue Jul 17, 2018 1:32 pm
Assuming the arrows are in both directions, since I don't want to follow the 2'nd rule of father->son relation, so lets say the algorithm don't know who is the father and who is the son...
I would try this way also, as users will do mistakes.. (Turro does not like it, i know, but let's try out)
project4 wrote:
Tue Jul 17, 2018 1:32 pm
I start calculations from Part1 since it's fixed in place, so Part1 can say to Parts 2,3,4: I'm your father!
Assuming all 3 parts (2,3,4) are now in the working queue (since its father said so).
All parts which are constrained directly to ANY fixpart (there could be more), I would place to the working queue (=partial system). I agree...
project4 wrote:
Tue Jul 17, 2018 1:32 pm
Those 3 parts are looking on the links they have, part4 have 3 links that are not in the working queue yet, so those are only candidates for next calculations, meaning part4 can be calculated without a problem at that stage.
.
I do not agree. As part 6 is a child of part 2 and part 4, final placement of part 2 and part 4 is depending on relations to part 6
So part 6 has to be added to the partial system. Placement of Part 4 can only be calculated all together with partial system.

Similar for part 7, depending on part 3 and part 4. Part 7 has to be added to the partial system, as it is influencing placements of part 3+4.

Especially for this diagram, only part 5 and part 8 can be calculated after solving all other parts by partial system, within next step.

So i think it will be a bit more complicated.

Edit1:
Perhaps we should speak instead of father/son relations in way of "ancestors" and "descendants". Each part which has more than one ancestor in working queue, has to be added to the partial system. (Somehow this way, its only an idea)
/Edit1
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.45c, 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: 175
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Postby Turro75 » Tue Jul 17, 2018 3:34 pm

Guys I just realized we have a problem (Houston...):

Since we are talking about a single assembly there are no issues on placing objs within a specific tolerance.It's just a matter of time and how large You set the maxstep parameter in the solver.

When we use an assembly as an imported subassembly we hardly ever get a perfectly aligned object, if we try to constraint several not perfectly aligned obj we rapidly goes out of accuracy and the second assembly won't be solved, never.

imagine a subassembly where a plane EDIT (I meant a face) EDIT which is constrained to be vertical in fact has an angle of 0.009°(so within accuracy if accuracy = 0.01°) , import this subassembly twice, rotate one by 180deg and try to constraints them as parallel and to XZ plane and perpendicular to XY plane. The same plane on the second obj will have an angle of -0.009°, since the angle between them is actually 0.018 I'll never get them parallel to XZ within accuracy, that's it, it doesn't matter which accuracy You use, You'll get always an error of accuracy*2.
Of course importing the second assembly in another assembly will increase the chance to fail on constraints.
project4
Posts: 153
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Postby project4 » Tue Jul 17, 2018 3:48 pm

kbwbe wrote:
Tue Jul 17, 2018 3:05 pm
All parts which are constrained directly to ANY fixpart (there could be more), I would place to the working queue (=partial system). I agree...
Indeed.
I do not agree. As part 6 is a child of part 2 and part 4, final placement of part 2 and part 4 is depending on relations to part 6
So part 6 has to be added to the partial system. Placement of Part 4 can only be calculated all together with partial system.

Similar for part 7, depending on part 3 and part 4. Part 7 has to be added to the partial system, as it is influencing placements of part 3+4.

Especially for this diagram, only part 5 and part 8 can be calculated after solving all other parts by partial system, within next step.
Ok, thanks. Now I get the point.
My mind was fixed on a specific scenario, but obviously there are much more options, so all the related parts should be calculated together.

I've refactored the code in more object oriented way (we are using Python after all), so now its much easier to play with the logic and see the flow...
Don't know if I'll have time today to continue with that, but I'm pretty close to the implementation.
kbwbe
Posts: 939
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Postby kbwbe » Tue Jul 17, 2018 4:25 pm

Turro75 wrote:
Tue Jul 17, 2018 3:34 pm
Guys I just realized we have a problem (Houston...):

Since we are talking about a single assembly there are no issues on placing objs within a specific tolerance.It's just a matter of time and how large You set the maxstep parameter in the solver.

When we use an assembly as an imported subassembly we hardly ever get a perfectly aligned object, if we try to constraint several not perfectly aligned obj we rapidly goes out of accuracy and the second assembly won't be solved, never.

imagine a subassembly where a plane EDIT (I meant a face) EDIT which is constrained to be vertical in fact has an angle of 0.009°(so within accuracy if accuracy = 0.01°) , import this subassembly twice, rotate one by 180deg and try to constraints them as parallel and to XZ plane and perpendicular to XY plane. The same plane on the second obj will have an angle of -0.009°, since the angle between them is actually 0.018 I'll never get them parallel to XZ within accuracy, that's it, it doesn't matter which accuracy You use, You'll get always an error of accuracy*2.
Of course importing the second assembly in another assembly will increase the chance to fail on constraints.
Hi Turro,
this is really a problem. My hope is, that it relates to every iterative solver on world and there should to be a solution how to handle.
As computations of complex relations are never exact. Perhaps we have to define a min accuracy the solver has to reach, but if possible it tries to increase it to a "desired" accuracy in some way to get better adjusted sub assemblies.

We will need the algorithms discussed in thread before very much. As i recognized that reachable accuray decreases somehow exponential with number of involved parts. There is no way out. We have to solve partial systems effectively and as accurate as possible. Otherwise we can forget imported sub-assemblies.

Head up, take a beer after that shock !

Edit1:
Another "hope". Solver is able to distribute errors over several constraints. It works somehow on an "elastic" system. So it could be possible, that these effects are not so bad as you and me fear !
/Edit1
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.45c, 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: 175
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Postby Turro75 » Tue Jul 17, 2018 5:00 pm

kbwbe wrote:
Tue Jul 17, 2018 4:25 pm
Turro75 wrote:
Tue Jul 17, 2018 3:34 pm
Guys I just realized we have a problem (Houston...):

Since we are talking about a single assembly there are no issues on placing objs within a specific tolerance.It's just a matter of time and how large You set the maxstep parameter in the solver.

When we use an assembly as an imported subassembly we hardly ever get a perfectly aligned object, if we try to constraint several not perfectly aligned obj we rapidly goes out of accuracy and the second assembly won't be solved, never.

imagine a subassembly where a plane EDIT (I meant a face) EDIT which is constrained to be vertical in fact has an angle of 0.009°(so within accuracy if accuracy = 0.01°) , import this subassembly twice, rotate one by 180deg and try to constraints them as parallel and to XZ plane and perpendicular to XY plane. The same plane on the second obj will have an angle of -0.009°, since the angle between them is actually 0.018 I'll never get them parallel to XZ within accuracy, that's it, it doesn't matter which accuracy You use, You'll get always an error of accuracy*2.
Of course importing the second assembly in another assembly will increase the chance to fail on constraints.
Hi Turro,
this is really a problem. My hope is, that it relates to every iterative solver on world and there should to be a solution how to handle.
As computations of complex relations are never exact. Perhaps we have to define a min accuracy the solver has to reach, but if possible it tries to increase it to a "desired" accuracy in some way to get better adjusted sub assemblies.

We wil need the algorithms discussed in thread before very much. As i recognized that reachable accuray decreases somehow exponential with number of involved parts. There is no way out. We have to solve partial systems effectively and as accurate as possible. Otherwise we can forget imported sub-assemblies.

Head up, take a beer after that shock !

Edit1:
Another "hope". Solver is able to distribute errors over several constraints. It works somehow on an "elastic" system. So it could be possible, that these effects are not so bad as you and me fear !
/Edit1

Brainstorming mode ON:

I have another idea, let's say we use the solver at a first stage to put all objects "almost" in place by using a low tolerance (i.e 0.3 or 0.1), this should be fast enough even on very complex assemblies, in my test I pass from 100k (accuracy 0.01) downto 4k steps (accuracy 0.3) if I change a constraints which require a large angle movement.

After this first step we could switch to another approach such as alignment. We'll have the same issues as order of solving constraints but at least the resulting object is "perfect".

Brainstorming mode still ON...
Turro75
Posts: 175
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Postby Turro75 » Tue Jul 17, 2018 5:14 pm

in the meanwhile something to read at the beach....

https://www.cs.cmu.edu/~rapidproto/mech ... hpt4.html
kbwbe
Posts: 939
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Postby kbwbe » Tue Jul 17, 2018 5:18 pm

Turro75 wrote:
Tue Jul 17, 2018 5:00 pm

Brainstorming mode ON:

I have another idea, let's say we use the solver at a first stage to put all objects "almost" in place by using a low tolerance (i.e 0.3 or 0.1), this should be fast enough even on very complex assemblies, in my test I pass from 100k (accuracy 0.01) downto 4k steps (accuracy 0.3) if I change a constraints which require a large angle movement.

After this first step we could switch to another approach such as alignment. We'll have the same issues as order of solving constraints but at least the resulting object is "perfect".

Brainstorming mode still ON...
Joining brainstorming mode...

First implement partials systems perfectly. It is also an improvement for your "rough pulling together" with enlarged tolerances.
After that: alignment mode..
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.45c, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench