Assembly 4 workbench

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Post by Zolko »

alonso_jamm wrote: Fri Aug 21, 2020 10:00 pm That is interesting. I don't get this error, does it happen on different documents (even on documents without constraints)?
This happens even on a document containing an new empty Asm4 Model. With a new empty document I get 'App.Document' object has no attribute 'Constraints'. There is a helper function checkModel() in libAsm4 to avoid this, that you can use like:

Code: Select all

import libAsm4 as Asm4
if Asm4.checkModel():
    ...

Maybe my assumption was wrong. Maybe we are using two different scipy versions. The scipy version I have is 1.5.2 which version are you using?
I am using the FreeCAD AppImage:

OS: Ubuntu 18.04.3 LTS (KDE/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22257 (Git) AppImage
Build type: Release
Branch: master
Hash: 93bb9646c36a84efdc3be4e4ca60c7e0234a6233
Python version: 3.8.5
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United Kingdom (en_GB)

Code: Select all

>>> import scipy
>>> print (scipy.version.version)
1.4.1
What FreeCAD are you using ?
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
alonso_jamm
Posts: 77
Joined: Mon Nov 11, 2019 11:32 pm

Re: Assembly 4 workbench

Post by alonso_jamm »

Zolko wrote: Fri Aug 21, 2020 10:51 pm What FreeCAD are you using ?
I am also using the AppImage:

OS: Manjaro Linux (KDE//usr/share/xsessions/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.21775 (Git) AppImage
Build type: Release
Branch: master
Hash: 1f741aa511e898849e46ed14515fce416fe32acb
Python version: 3.8.2
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: English/United States (en_US)

It seems that the different scipy versions was the problem. I think shouldn't have assumed that the cost function was going to be called before the gradient and hessian. Anyway, I fixed the issue; now the solver checks if the cost function has been evaluated in the current point before returning the gradient or the hessian. I checked using scipy to 1.4.1 and the solver worked as expected.

I also added a check to see if there is a model in the document before trying to solve the constraints. Now it should not throw an error while updating the assembly in an empty document.
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Post by Zolko »

alonso_jamm wrote: Sat Aug 22, 2020 2:52 am I also added a check to see if there is a model in the document before trying to solve the constraints. Now it should not throw an error while updating the assembly in an empty document.
yes, your latest code doesn't produce these errors and seems to do the job. Cool. Now we can progress. My first concerns:

1) from a usability perspective, I'd select an LCS and then click on adding constraints, and the selected LCS should be considered only

2) when constraining an LCS that has existing constraints, the field should be pre-filled. Should be easier with (1).

3) if you apply the fix constraint, I suppose it's relative to the assembly origin ? If we could select which LCS is the related LCS w.r.t. which we fix the LCS, this could be a first step for some more complex constraints, for not much hassle (I think). Would this be doable ?

4) Isn't there a risk of interference between namespaces of other solvers ? I've encountered some warnings/errors that I traced to the solver from Asm3. Could you please consider giving this solver a unique name ?

This is really great, please keep up the good work. EDIT: I think (3) and (4) should have priority.
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
alonso_jamm
Posts: 77
Joined: Mon Nov 11, 2019 11:32 pm

Re: Assembly 4 workbench

Post by alonso_jamm »

Zolko wrote: Sat Aug 22, 2020 10:03 pm 1) from a usability perspective, I'd select an LCS and then click on adding constraints, and the selected LCS should be considered only

2) when constraining an LCS that has existing constraints, the field should be pre-filled. Should be easier with (1).
I am planning on improving the datum object selection. The current method is the barely minimum for the assembly to work.

Zolko wrote: Sat Aug 22, 2020 10:03 pm 3) if you apply the fix constraint, I suppose it's relative to the assembly origin ? If we could select which LCS is the related LCS w.r.t. which we fix the LCS, this could be a first step for some more complex constraints, for not much hassle (I think). Would this be doable ?
The way it works now is that the coordinates of datum objects are fixed with respect to the global coordinates. I didn't think of fixing them with respect to an arbitrary LCS, but I think it is possible.

Zolko wrote: Sat Aug 22, 2020 10:03 pm 4) Isn't there a risk of interference between namespaces of other solvers ? I've encountered some warnings/errors that I traced to the solver from Asm3. Could you please consider giving this solver a unique name ?

I don't mind changing the solver name. I just don't know if there is a risk of interference between the namespaces. Can you explain more about those warnings/errors?
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Post by Zolko »

alonso_jamm wrote: Sun Aug 23, 2020 2:00 pm
Zolko wrote: Sat Aug 22, 2020 10:03 pm 3) if you apply the fix constraint, I suppose it's relative to the assembly origin ? If we could select which LCS is the related LCS w.r.t. which we fix the LCS, this could be a first step for some more complex constraints, for not much hassle (I think). Would this be doable ?
The way it works now is that the coordinates of datum objects are fixed with respect to the global coordinates. I didn't think of fixing them with respect to an arbitrary LCS, but I think it is possible.
this might be easier than you think: I see that you set the Placement property of the calculated object in updateAssemblyCmd. Another way of doing this is to attach the datum LCS_2 to another datum LCS_1 by:

Code: Select all

LCS_2.Support = LCS_1
LCS_2.MapMode = 'ObjectXY'
LCS_1 and LCS_2 are the FreeCAD objects, as per App.ActiveDocument.getObject(obj_name)

and then set the AttachmentOffset the same way as you do with the Placement (they are both App::Placement types). This way, the position of LCS_2 is relative to LCS_1 without any more work. The dialog "Add equality" would then be unnecessary, there could be a unique "Add Constraint" dialog where you select the reference datum object from the list, and the offsets along the 6 DoF to this reference.

Does that make sense ?
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
alonso_jamm
Posts: 77
Joined: Mon Nov 11, 2019 11:32 pm

Re: Assembly 4 workbench

Post by alonso_jamm »

Zolko wrote: Sun Aug 23, 2020 8:01 pm this might be easier than you think: I see that you set the Placement property of the calculated object in updateAssemblyCmd. Another way of doing this is to attach the datum LCS_2 to another datum LCS_1 by:

Code: Select all

LCS_2.Support = LCS_1
LCS_2.MapMode = 'ObjectXY'
LCS_1 and LCS_2 are the FreeCAD objects, as per App.ActiveDocument.getObject(obj_name)

and then set the AttachmentOffset the same way as you do with the Placement (they are both App::Placement types). This way, the position of LCS_2 is relative to LCS_1 without any more work. The dialog "Add equality" would then be unnecessary, there could be a unique "Add Constraint" dialog where you select the reference datum object from the list, and the offsets along the 6 DoF to this reference.

Does that make sense ?
The solver is "dumb," it barely knows anything about FreeCAD. The general way of how it works is: first it gets the current positions of the objects to be constrained; then it minimizes equations that represent the constraints using the initial values of the positions of the objects; and finally it sets the resulting values to the objects' placements. That is, the solver only knows how to get the placements and how to set them. It doesn't know anything about attachments which means that the solver won't work correctly if two objects are attached. For example, if LCS_2 is attached to LCS_1 and we have a constraint between LCS_2 and LCS_3, then the solver will try to set the position of LCS_2 to some calculated value (it will try to do this for example: App.ActiveDocument.LCS_2.Placement.Base.x = 3). Some sort of "attachment checker" is needed in order to have attachments work with the solver.

I am also not sure if attachments can help with fixing arbitrary placement components while leaving others completely free. I think it is possible to fix an object with respect to an LCS by using the inverse of the placement of the LCS.
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Post by Zolko »

alonso_jamm wrote: Mon Aug 24, 2020 4:07 am The solver is "dumb," it barely knows anything about FreeCAD. The general way of how it works is: first it gets the current positions of the objects to be constrained; then it minimizes equations that represent the constraints using the initial values of the positions of the objects; and finally it sets the resulting values to the objects' placements. That is, the solver only knows how to get the placements and how to set them. It doesn't know anything about attachments which means that the solver won't work correctly if two objects are attached. For example, if LCS_2 is attached to LCS_1 and we have a constraint between LCS_2 and LCS_3, then the solver will try to set the position of LCS_2 to some calculated value (it will try to do this for example: App.ActiveDocument.LCS_2.Placement.Base.x = 3). Some sort of "attachment checker" is needed in order to have attachments work with the solver.
OK, I begin to understand.

In my mind, a typical workflow for constraints would be that of an assembly with 3 parts:
  • parts 1 and 2 are attached in the assembly by master sketch and LCS
  • part 3 is constrained on part1 and part2.
For example, part1 has a hole, into which part3 is inserted free to rotate. The orientation of that rotation is given by some reference in part2. For that, part3 would have an LCS that is attached to the corresponding LCS in part1, but with 1 DoF. This DoF is calculated with a constraint set on the reference LCS coming from part2. The simplest example would be a parallelogram.

My intuition was that is was easier to deal with 1 DoF, but after reading your method may-be it's better to have a solver do either nothing or all the calculations for a given part, but mixing them could be difficult. If the latter, we need to add all the different constraint types (colinear, coplanar ..).

Do I understand the principle correctly ?

In which case I propose to add a property to datum objects that tell what sort of placement they have :

Code: Select all

datum.addProperty('App::PropertyString', 'PlacementMethod', 'Attachment')
and this PlacementMethod can be Manual, ExpressionEngine, AttachEngine, SolverName. And the Solver would only deal with datum objects that have the PlacementMethod set correctly.

If we want to create a constraint on a datum that is in a part, we need to create a (virtual ?) clone of the datum inside the assembly (all it needs is an App::PropertyPlacement property, could be created as a property of the respective constraint), make the calculations with the clone, and attach the parts to that clone. Something like that. This "clone" is probably quite similar to the "Elements" stuff in Asm3.
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
alonso_jamm
Posts: 77
Joined: Mon Nov 11, 2019 11:32 pm

Re: Assembly 4 workbench

Post by alonso_jamm »

Zolko wrote: Mon Aug 24, 2020 12:02 pm
OK, I begin to understand.

In my mind, a typical workflow for constraints would be that of an assembly with 3 parts:
  • parts 1 and 2 are attached in the assembly by master sketch and LCS
  • part 3 is constrained on part1 and part2.
For example, part1 has a hole, into which part3 is inserted free to rotate. The orientation of that rotation is given by some reference in part2. For that, part3 would have an LCS that is attached to the corresponding LCS in part1, but with 1 DoF. This DoF is calculated with a constraint set on the reference LCS coming from part2. The simplest example would be a parallelogram.

My intuition was that is was easier to deal with 1 DoF, but after reading your method may-be it's better to have a solver do either nothing or all the calculations for a given part, but mixing them could be difficult. If the latter, we need to add all the different constraint types (colinear, coplanar ..).

Do I understand the principle correctly ?

In which case I propose to add a property to datum objects that tell what sort of placement they have :

Code: Select all

datum.addProperty('App::PropertyString', 'PlacementMethod', 'Attachment')
and this PlacementMethod can be Manual, ExpressionEngine, AttachEngine, SolverName. And the Solver would only deal with datum objects that have the PlacementMethod set correctly.

If we want to create a constraint on a datum that is in a part, we need to create a (virtual ?) clone of the datum inside the assembly (all it needs is an App::PropertyPlacement property, could be created as a property of the respective constraint), make the calculations with the clone, and attach the parts to that clone. Something like that. This "clone" is probably quite similar to the "Elements" stuff in Asm3.
I think the solver can treat attachments as equality constraints with an offset. Expressions could be treated as fixed constraint internally. So we may not need to add properties to the datum objects and the user would not have to think about setting a placement method correctly.
DDM
Posts: 88
Joined: Tue Feb 05, 2019 9:06 am

Re: Assembly 4 workbench

Post by DDM »

Hi Zolko,

I hope you can answer to my question.
I create a simple assembly (a column with a base plate) with assembly 4.
I would transform my assembly in an arch element using Arch/BIM workbenches.
The new object, named "Structure", has the holes of the base plate as squares (zoom the base plate of the "Structure" object)
I tried also to calculate the volume of the "Strcuture" and the result is strange, not a real number. (see the worksheet inside the Steel_Column_Asembly4.FCStd file)

I tried to arrange the links of the parts manually with a Part Container (see the file Steel_Column_Part_Container_Assembly.FCStd file).
The arch object "Structure" is shown correctly and the calculation of its volume is also correct.

Recently the Arch/BIM developers added the part containers as base of the arch objects, so my conclusion is that the model generated with Assembly4 is not a part container or am I wrong?
Do you have any suggestion to use the model generated withASM4 as a base for an arch/BIM workbench object?

Thanks in advance for your help.
Cheers, Marco

FC info
OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22266 (Git)
Build type: Release
Branch: master
Hash: 1a6bbf8127e8957f64dec5d6d37710542f2a6c83
Python version: 3.8.5
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: Italian/Italy (it_IT)
Attachments
Steel_Column_Part_Container_Assembly.FCStd
(39.18 KiB) Downloaded 65 times
Steel_Column_Assembly4.FCStd
(39.95 KiB) Downloaded 59 times
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Post by Zolko »

DDM wrote: Tue Aug 25, 2020 3:24 pm Do you have any suggestion to use the model generated withASM4 as a base for an arch/BIM workbench object?
this is a bug an Arch/BIM: when you delete the LCS_Origin in the Model, the calculation is correct (you have to recompute the objects). You can recreate the same bug when creating a datum object inside Part_Container_Assembly.
try the Assembly4 workbench for FreCAD — tutorials here and here
Post Reply