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!
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 »

project4 wrote: Wed Jul 18, 2018 7:03 am I'm not good with math and din't really understood all the move and rotations code, so I would ask some questions to understand the solver concepts:

What will be harder to solve:
1. An assembly with 100 parts all at once
2. Or solve parts 1+2, after that solve parts 1+2+3, after that 1+2+3+4 and so on?

If the solver should work similar to human interactions with the parts, than it sounds like the second option is more logical.
Human won't throw everything on the table and try to squish it together, one will set 2 parts, rotate them a bit, add a screw, add another part and so on.

So my logic says that the scene should be assembled as an incremental process.
The added part should be added to the scene in proper place according to one of the constraints that connects it to already fixed parts and after that trying to resolve all together, so other constrains will move/rotate it to the needed position.

What do you say?
Solving parts 1+2, after that solve parts 1+2+3, after that 1+2+3+4 and so on is much easier for the solver:
It reduces calculation time drastically. But unfortunately it is not always possible.
See 6DOF platform example. It is impossible for solver to calculate it this way.

Therefore it is the job of the new algorithm, to find smallest possible groups of parts to solve, starting with parts related to fixed ones.
The smallest group is found, if the placements can be calculated independent of the remaining parts.

I expect speeding up solver factor 10 minimum, if the assembly can be split up. There will be no effect for 6DOF platform example.
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 (A2plus)

Post by Turro75 »

Guys I updated the 6dof chart and the Manuel engine
Manuel Engine Analisys.PNG
Manuel Engine Analisys.PNG (36.63 KiB) Viewed 1325 times
assembly_6dof_analisys.PNG
assembly_6dof_analisys.PNG (24.64 KiB) Viewed 1325 times
The target is understanding if the solver could split in sub assemblies if a son has 6 or more as sum of all constraints and the involved fathers also have 6 or more which should means they could be fixed.

We need some more assemblies to split in charts to understand if it a good approach
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 »

Hi at all,

Find my proposal for partial systems of Manuel's crankshaft...
.
Crankshaft-partial-Systems.png
Crankshaft-partial-Systems.png (758.81 KiB) Viewed 1321 times
.
Edit1
Assume about 500 steps per partial system necessary to solve very exact. => 3000 steps about needed, fast and much more accurate as solving all together. It will be a little bit slower compared to fixing each part after the other.
/Edit1
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
project4
Posts: 237
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Post by project4 »

Ok, I'm convinced that working with parental relationship makes sense than other linking methods.

Meanwhile I have a code that traverses the connections and created father/children relationships between the rigids, including the distance from the fixed part.
For example, this is the result for the 6dof model:

Code: Select all

platform_001 - distance 0
   cylinder_002 - distance 1
      piston_003 - distance 2
         piston_004 - distance 3
            platform_002 - distance 4
   cylinder_001 - distance 1
      piston_006 - distance 2
         piston_005 - distance 3
            platform_002 - distance 4
   cylinder_003 - distance 1
      piston_004 - distance 3
         platform_002 - distance 4
   cylinder_004 - distance 1
      piston_002 - distance 2
         piston_001 - distance 3
            platform_002 - distance 4
   cylinder_005 - distance 1
      piston_001 - distance 3
         platform_002 - distance 4
   cylinder_006 - distance 1
      piston_005 - distance 3
         platform_002 - distance 4
pump and crankshaft have strange namings, so it will not be that clear if its ok, but you can check it as well:

Code: Select all

Kurbelscheibe_2_001 - distance 0
   KW_Bolzen_28x60_001 - distance 1
      Kurbelscheibe_2_001001 - distance 2
         KW_Zyl2_3_001 - distance 3
            Kurbelscheibe_2_001002 - distance 4
               KW_Bolzen_28x60_001001 - distance 5
                  Kurbelscheibe_2_001003 - distance 6
                     KW_Zyl2_3_001001 - distance 7
                        Kurbelscheibe_2_001004 - distance 8
                           KW_Bolzen_28x60_001002 - distance 9
                              Kurbelscheibe_2_001005 - distance 10
                                 KW_Zyl1_001001 - distance 11
                           Kurbelscheibe_2_001005 - distance 10
                              KW_Zyl1_001001 - distance 11
                     Kurbelscheibe_2_001004 - distance 8
                        KW_Bolzen_28x60_001002 - distance 9
                           Kurbelscheibe_2_001005 - distance 10
                              KW_Zyl1_001001 - distance 11
                        Kurbelscheibe_2_001005 - distance 10
                           KW_Zyl1_001001 - distance 11
               Kurbelscheibe_2_001003 - distance 6
                  KW_Zyl2_3_001001 - distance 7
                     Kurbelscheibe_2_001004 - distance 8
                        KW_Bolzen_28x60_001002 - distance 9
                           Kurbelscheibe_2_001005 - distance 10
                              KW_Zyl1_001001 - distance 11
                        Kurbelscheibe_2_001005 - distance 10
                           KW_Zyl1_001001 - distance 11
                  Kurbelscheibe_2_001004 - distance 8
                     KW_Bolzen_28x60_001002 - distance 9
                        Kurbelscheibe_2_001005 - distance 10
                           KW_Zyl1_001001 - distance 11
                     Kurbelscheibe_2_001005 - distance 10
                        KW_Zyl1_001001 - distance 11
         Kurbelscheibe_2_001002 - distance 4
            KW_Bolzen_28x60_001001 - distance 5
               Kurbelscheibe_2_001003 - distance 6
                  KW_Zyl2_3_001001 - distance 7
                     Kurbelscheibe_2_001004 - distance 8
                        KW_Bolzen_28x60_001002 - distance 9
                           Kurbelscheibe_2_001005 - distance 10
                              KW_Zyl1_001001 - distance 11
                        Kurbelscheibe_2_001005 - distance 10
                           KW_Zyl1_001001 - distance 11
                  Kurbelscheibe_2_001004 - distance 8
                     KW_Bolzen_28x60_001002 - distance 9
                        Kurbelscheibe_2_001005 - distance 10
                           KW_Zyl1_001001 - distance 11
                     Kurbelscheibe_2_001005 - distance 10
                        KW_Zyl1_001001 - distance 11
            Kurbelscheibe_2_001003 - distance 6
               KW_Zyl2_3_001001 - distance 7
                  Kurbelscheibe_2_001004 - distance 8
                     KW_Bolzen_28x60_001002 - distance 9
                        Kurbelscheibe_2_001005 - distance 10
                           KW_Zyl1_001001 - distance 11
                     Kurbelscheibe_2_001005 - distance 10
                        KW_Zyl1_001001 - distance 11
               Kurbelscheibe_2_001004 - distance 8
                  KW_Bolzen_28x60_001002 - distance 9
                     Kurbelscheibe_2_001005 - distance 10
                        KW_Zyl1_001001 - distance 11
                  Kurbelscheibe_2_001005 - distance 10
                     KW_Zyl1_001001 - distance 11
   KW_Zyl1_001 - distance 1
   Kurbelscheibe_2_001001 - distance 2
      KW_Zyl2_3_001 - distance 3
         Kurbelscheibe_2_001002 - distance 4
            KW_Bolzen_28x60_001001 - distance 5
               Kurbelscheibe_2_001003 - distance 6
                  KW_Zyl2_3_001001 - distance 7
                     Kurbelscheibe_2_001004 - distance 8
                        KW_Bolzen_28x60_001002 - distance 9
                           Kurbelscheibe_2_001005 - distance 10
                              KW_Zyl1_001001 - distance 11
                        Kurbelscheibe_2_001005 - distance 10
                           KW_Zyl1_001001 - distance 11
                  Kurbelscheibe_2_001004 - distance 8
                     KW_Bolzen_28x60_001002 - distance 9
                        Kurbelscheibe_2_001005 - distance 10
                           KW_Zyl1_001001 - distance 11
                     Kurbelscheibe_2_001005 - distance 10
                        KW_Zyl1_001001 - distance 11
            Kurbelscheibe_2_001003 - distance 6
               KW_Zyl2_3_001001 - distance 7
                  Kurbelscheibe_2_001004 - distance 8
                     KW_Bolzen_28x60_001002 - distance 9
                        Kurbelscheibe_2_001005 - distance 10
                           KW_Zyl1_001001 - distance 11
                     Kurbelscheibe_2_001005 - distance 10
                        KW_Zyl1_001001 - distance 11
               Kurbelscheibe_2_001004 - distance 8
                  KW_Bolzen_28x60_001002 - distance 9
                     Kurbelscheibe_2_001005 - distance 10
                        KW_Zyl1_001001 - distance 11
                  Kurbelscheibe_2_001005 - distance 10
                     KW_Zyl1_001001 - distance 11
      Kurbelscheibe_2_001002 - distance 4
         KW_Bolzen_28x60_001001 - distance 5
            Kurbelscheibe_2_001003 - distance 6
               KW_Zyl2_3_001001 - distance 7
                  Kurbelscheibe_2_001004 - distance 8
                     KW_Bolzen_28x60_001002 - distance 9
                        Kurbelscheibe_2_001005 - distance 10
                           KW_Zyl1_001001 - distance 11
                     Kurbelscheibe_2_001005 - distance 10
                        KW_Zyl1_001001 - distance 11
               Kurbelscheibe_2_001004 - distance 8
                  KW_Bolzen_28x60_001002 - distance 9
                     Kurbelscheibe_2_001005 - distance 10
                        KW_Zyl1_001001 - distance 11
                  Kurbelscheibe_2_001005 - distance 10
                     KW_Zyl1_001001 - distance 11
         Kurbelscheibe_2_001003 - distance 6
            KW_Zyl2_3_001001 - distance 7
               Kurbelscheibe_2_001004 - distance 8
                  KW_Bolzen_28x60_001002 - distance 9
                     Kurbelscheibe_2_001005 - distance 10
                        KW_Zyl1_001001 - distance 11
                  Kurbelscheibe_2_001005 - distance 10
                     KW_Zyl1_001001 - distance 11
            Kurbelscheibe_2_001004 - distance 8
               KW_Bolzen_28x60_001002 - distance 9
                  Kurbelscheibe_2_001005 - distance 10
                     KW_Zyl1_001001 - distance 11
               Kurbelscheibe_2_001005 - distance 10
                  KW_Zyl1_001001 - distance 11
The analysis is recursive multi-pass and might take some time for very complex parts, but if it saves the computation time and frees the user from selecting the parts in a specific order, it might still worth it. That stage is a good candidate for caching as I mentioned. The rigids list should be rebuilt only when something is deleted or added.

Now I should try adding parts to the scene by their distance from the fixed and recompute...
project4
Posts: 237
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Post by project4 »

kbwbe wrote: Wed Jul 18, 2018 8:52 am Hi at all,

Find my proposal for partial systems of Manuel's crankshaft...
.Crankshaft-partial-Systems.png
.
Edit1
Assume about 500 steps per partial system necessary to solve very exact. => 3000 steps about needed, fast and much more accurate as solving all together. It will be a little bit slower compared to fixing each part after the other.
/Edit1
Please explain your decisions, why selecting those specific parts...
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 »

Hi @project4,

Diagram again:
.
Crankshaft-partial-Systems.png
Crankshaft-partial-Systems.png (758.81 KiB) Viewed 1305 times
.
- Algorithm should start with searching parts directly related to fix parts.
- So it finds in step 1 the part A5, C5, D7, been fixed to B6
- These are added to partial system 1
- It does not matter, that two branches are found (A5 is a separate branch), as Solver will not waste time if there is more than one branch
- Off topic remark: Interesting is, if thinking constraints beeing bidirectional, you have a loop between B6,C5,D7. I will come back to this later in post. A2plus solver internally is working bidirectional.

- Algorithm should now solve PS1 and mark all parts as tempfixed.

- When algorithm is doing its next step, it is looking again which remaining parts are linked to fixed/tempfixed parts.
- So it will find E5 and F7 directly related to D7, which is tempfixed. D7 will not be moved by solver, as been tempfixed.
- So it defines that the relations between D7, E5 and F7 has to be calculated as next partial system.

And so on until ready.
A first alorithm doing this would be easy. But there is another difficulty:

- think C5 is been split up into 3 different but chained parts. You will get intermediate parts within the loop i mentioned above. They are a bit more difficult to find.

The advantage of my proposal is, that complex relations are solvable always, what could be damaged by other algorithms if tempfixing parts to early.
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
project4
Posts: 237
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Post by project4 »

kbwbe wrote: Wed Jul 18, 2018 10:30 am - Algorithm should start with searching parts directly related to fix parts.
- So it finds in step 1 the part A5, C5, D7, been fixed to B6
- These are added to partial system 1
- It does not matter, that two branches are found (A5 is a separate branch), as Solver will not waste time if there is more than one branch
- Off topic remark: Interesting is, if thinking constraints beeing bidirectional, you have a loop between B6,C5,D7. I will come back to this later in post. A2plus solver internally is working bidirectional.

- Algorithm should now solve PS1 and mark all parts as tempfixed.

- When algorithm is doing its next step, it is looking again which remaining parts are linked to fixed/tempfixed parts.
- So it will find E5 and F7 directly related to D7, which is tempfixed. D7 will not be moved by solver, as been tempfixed.
- So it defines that the relations between D7, E5 and F7 has to be calculated as next partial system.

And so on until ready.
Ok, so far it looks like for the next computation only childrens of the tempfixed rigids should be added to the computation.

You always mention the computations as "partial system", but in fact when stage 2 should be calculated, it should be calculated together with the result of the stage1, right? Not as a standalone stage2.
It will always be incremental, parts only from stage1, after that parts from stage1+stage2, after that stage1+stage2+stage3.
The way you write it confuses my logic...
kbwbe wrote: Wed Jul 18, 2018 10:30 am
- think C5 is been split up into 3 different but chained parts. You will get intermediate parts within the loop i mentioned above. They are a bit more difficult to find.

The advantage of my proposal is, that complex relations are solvable always, what could be damaged by other algorithms if tempfixing parts to early.
The code I have that build the hierarchy don't loop, it counts the distance from the fixed part, so it looks like adding the children of all the tempfixed parts will have the exact effect as you described (in case the computation is incremental as I wrote before in that post)
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 »

project4 wrote: Wed Jul 18, 2018 10:46 am
You always mention the computations as "partial system", but in fact when stage 2 should be calculated, it should be calculated together with the result of the stage1, right? Not as a standalone stage2.
It will always be incremental, parts only from stage1, after that parts from stage1+stage2, after that stage1+stage2+stage3.
The way you write it confuses my logic...
.
OK. As result of solving a partial system in a step, there are more tempfixed parts. Solver will have no work to do with them.
Therefore solving next partial system uses results of previous ones.
project4 wrote: Wed Jul 18, 2018 10:46 am
kbwbe wrote: Wed Jul 18, 2018 10:30 am - think C5 is been split up into 3 different but chained parts. You will get intermediate parts within the loop i mentioned above. They are a bit more difficult to find.
The advantage of my proposal is, that complex relations are solvable always, what could be damaged by other algorithms if tempfixing parts to early.

The code I have that build the hierarchy don't loop, it counts the distance from the fixed part, so it looks like adding the children of all the tempfixed parts will have the exact effect as you described (in case the computation is incremental as I wrote before in that post)
.
I will have a deeper look at your systematics this evening
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
project4
Posts: 237
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Post by project4 »

Ok...
The code of hierarchy and adding parts to the scene based on the distance from the fixed part looks ok.
The resolver fails and I think its because there are dependencies to rigids that are not calculated...

Right now all the dependencies are added to all the rigids on load.

I have a workList of the rigids that are calculated. After every scene I have addList with new rigids added to the workList.
The dependencies loading is done based on the constraints list, so there is no fast way to get to the needed constraints from the added rigid objects...
Maybe I'll add a reference from rigid to constraint and when the rigids are added to the workList I'll check if both objects referenced by the constraint are in the work list already.
But the objects in the constraint are names and not references to rigids.... brrrr...
Don't want to do too many lookups by name.

Maybe you'll have some ideas while I will be away...
kbwbe wrote: Wed Jul 18, 2018 11:01 am Ping
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Post by Turro75 »

kbwbe wrote: Wed Jul 18, 2018 8:52 am Hi at all,

Find my proposal for partial systems of Manuel's crankshaft...
.Crankshaft-partial-Systems.png
.
Edit1
Assume about 500 steps per partial system necessary to solve very exact. => 3000 steps about needed, fast and much more accurate as solving all together. It will be a little bit slower compared to fixing each part after the other.
/Edit1
Hi Kbwbe,

I'm thinking about this:

1st rule:
first check if any fixed part has son which have not sons (in the example A) so first step is solve A+B. I think it's better fuse them in a single rigid for further solve which involve part B.

2 rule:
as second step try to solve any constraints which involves a fixed part and any son which has a him and all his fathers with number of 6 or more.
In the example no one constraint match this. each solved group must be fused in a single rigid used any time any of its objs are involved in a movement.

3 rule:
repeat step 2 as no constraints that match the 2nd rule

last rule:
look for objects block such as H+I+L but it is difficult as in the example the boject in the middle isn't well constrained ( number <6)
I'm still thinking about this.

cranckshaft analisys.PNG
cranckshaft analisys.PNG (27.32 KiB) Viewed 1257 times
Post Reply