Assembly 4 workbench

Discussion about the development of the Assembly workbench.
User avatar
Zolko
Posts: 1007
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Postby Zolko » Sun Aug 02, 2020 2:46 pm

iman wrote:
Sun Jul 26, 2020 8:50 am
This is exactly I want to do, It will be very nice and natural if we can just add new LCS on the Assembly it self just like we add LCS on part
then, good practice is to read the forum:

WayofWood wrote:
Sat Jul 11, 2020 4:47 pm
Zolko wrote:
Sat Jul 11, 2020 4:09 pm
you can attach the LCS_in_Model to an LCS_in_childPart with the Place_Datum command. Better yet, select LCS_in_childPart in the tree and click Import_Datum.
Thanks a lot! This was the missing bit of information. With an imported LCS the subassembly is easy to position in the overall master.
try the Assembly4 workbench for FreCAD v0.19
install with Tools > Addon Manager > Assembly4 — tutorials here and here
drmacro
Posts: 1490
Joined: Sun Mar 02, 2014 4:35 pm

Re: Assembly 4 workbench

Postby drmacro » Mon Aug 03, 2020 5:15 pm

Zolko wrote:
Attempting to insert a fastener from the fastener icon in A4. and I get:

Code: Select all

Running the Python command 'Asm4_insertScrew' failed:
Traceback (most recent call last):
  File "/home/mac/.FreeCAD/Mod/Assembly4/FastenersLib.py", line 609, in Activated
    if not 'FSChangeParams' in Gui.listCommands():

module 'FreeCADGui' has no attribute 'listCommands'
Haven't tried a fastener for a week or so...updated A4 from Addon Manager, no change.

(Fastener workbench works fine...)





OS: Ubuntu 20.04.1 LTS (XFCE/ubuntustudio)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Branch: unknown
Hash: 0cf8279f00017ed2913e0c17beda77c733f98350
Python version: 3.8.2
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.3.0
Locale: English/United States (en_US)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD
drmacro
Posts: 1490
Joined: Sun Mar 02, 2014 4:35 pm

Re: Assembly 4 workbench

Postby drmacro » Mon Aug 03, 2020 5:23 pm

General question about A4 behavior.

It seems that there are a lot of changes to the assembly file and the part files with very little provocation.

Some times I know of nothing changing in the part files, it doesn't even appear that they were loaded.

But, if I do a close all, it wants to save them.

In some cases, after the assembly file is closed some of the part files remain, but, weren't loaded and are greyed in the feature tree.

oh, and why: "Partial loaded document 'yoke_altern' cannot be saved" when the file has not been opened or changed... :?

Just want to understand what's going on behind the scenes... ;)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."

My beginners, written treatise: Learning FreeCAD
User avatar
Zolko
Posts: 1007
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Postby Zolko » Tue Aug 04, 2020 7:21 pm

drmacro wrote:
Mon Aug 03, 2020 5:15 pm
Attempting to insert a fastener from the fastener icon in A4. and I get:

Code: Select all

File "/home/mac/.FreeCAD/Mod/Assembly4/FastenersLib.py", line 609, in Activated
    if not 'FSChangeParams' in Gui.listCommands():

module 'FreeCADGui' has no attribute 'listCommands'
that's very strange. Can you please try to run the command

Code: Select all

>>> Gui.listCommands()
in the python console ?

Version: 0.19.
Build type: Release
Branch: unknown
Hash: 0cf8279f00017ed2913e0c17beda77c733f98350
...
OCC version: 7.3.0
that's also quite strange. Mine says:


Version: 0.19.21775 (Git) AppImage
Build type: Release
Branch: master
Hash: 1f741aa511e898849e46ed14515fce416fe32acb
...
OCC version: 7.4.0


How did you get that version of FreeCAD ?
try the Assembly4 workbench for FreCAD v0.19
install with Tools > Addon Manager > Assembly4 — tutorials here and here
User avatar
Zolko
Posts: 1007
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Postby Zolko » Tue Aug 04, 2020 7:28 pm

drmacro wrote:
Mon Aug 03, 2020 5:23 pm
It seems that there are a lot of changes to the assembly file and the part files with very little provocation.

In some cases, after the assembly file is closed some of the part files remain, but, weren't loaded and are greyed in the feature tree.

oh, and why: "Partial loaded document 'yoke_altern' cannot be saved" when the file has not been opened or changed... :?

Just want to understand what's going on behind the scenes... ;)
Partial loading of files doesn't (always) work very well, better to disable it in the settings. Also, objects are "touched" when recomputed, and thus appear modified to FreeCAD even though they where not modified by the user.

All this is standard (now, since v0.19) App::Link behaviour, not specific to Asm4. Please be aware that while the App::Link interface is very usable and stable, it's also new to FreeCAD and still has some rough edges. These will hopefully be ironed out in the coming releases.
try the Assembly4 workbench for FreCAD v0.19
install with Tools > Addon Manager > Assembly4 — tutorials here and here
User avatar
alonso_jamm
Posts: 37
Joined: Mon Nov 11, 2019 11:32 pm

Re: Assembly 4 workbench

Postby alonso_jamm » Mon Aug 10, 2020 8:19 pm

Hello, I tried to make a solver for Assembly 4. The work I have done is in my fork of the assembly under the solver branch. I see it more as a sort of proof of concept of how a solver for Assembly 4 could work. This solver only works on datum objects inside the active document. So it can be used to construct the functional structure of an assembly. So far it only has two types of constraints, an "equality" constraint and a "fix" constraint. The equality constraint can be used to set parameters of the placement of two datum objects equal. For example, to set the x-position of both objects equal and leaving all the other placement parameters free. And the fix constraint sets the parameters of the placement of an object to a certain value. For example, setting the x-position of an object to 5.00mm. I made a video showing the solver in action:
phpBB [video]


I don't really see this solver as a replacement of sketches or attachments since it is slower than both of them. However, I think it is a cool proof of concept since adding the solver to Assembly 4 was rather simple. Maybe in the future we could add a better solver to Assembly 4 in a similar way I added my solver.
User avatar
Zolko
Posts: 1007
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Postby Zolko » Fri Aug 14, 2020 10:02 am

alonso_jamm wrote:
Mon Aug 10, 2020 8:19 pm
Hello, I tried to make a solver for Assembly 4. The work I have done is in my fork of the assembly under the solver branch.
This looks really cool. I just came back from vacations and will take a look at it ASAP. Thanx
try the Assembly4 workbench for FreCAD v0.19
install with Tools > Addon Manager > Assembly4 — tutorials here and here
vocx
Posts: 5068
Joined: Thu Oct 18, 2018 9:18 pm

Re: Assembly 4 workbench

Postby vocx » Sat Aug 15, 2020 2:18 am

drmacro wrote:
Mon Aug 03, 2020 5:15 pm

Code: Select all

...
module 'FreeCADGui' has no attribute 'listCommands'
This error occurred just in one commit, git commit 9b529bc45c, but since it caused regressions a compatibility fix was quickly made, git commit 76e7429489.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
Zolko
Posts: 1007
Joined: Mon Dec 17, 2018 10:02 am

Re: Assembly 4 workbench

Postby Zolko » Fri Aug 21, 2020 2:01 pm

alonso_jamm wrote:
Mon Aug 10, 2020 8:19 pm
Hello, I tried to make a solver for Assembly 4. The work I have done is in my fork of the assembly under the solver branch.
First of all, nice dialogs, nice integration with the rest of the UI. Unfortunately, I always get an error when updating the assembly:

Code: Select all

Running the Python command 'Asm4_updateAssembly' failed:
Traceback (most recent call last):
  File "/home/hubertz/.FreeCAD/Mod/FreeCAD_Assembly4-solver/updateAssemblyCmd.py", line 55, in Activated
    solved = sol.solve(x_i)
  File "/home/hubertz/.FreeCAD/Mod/FreeCAD_Assembly4-solver/solver/Solver.py", line 44, in solve
    solution = minimize(self.eval, x0,  method="trust-ncg",
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/_minimize.py", line 627, in minimize
    return _minimize_trust_ncg(fun, x0, args, jac, hess, hessp,
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/_trustregion_ncg.py", line 39, in _minimize_trust_ncg
    return _minimize_trust_region(fun, x0, args=args, jac=jac, hess=hess,
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/_trustregion.py", line 182, in _minimize_trust_region
    while m.jac_mag >= gtol:
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/_trustregion.py", line 71, in jac_mag
    self._g_mag = scipy.linalg.norm(self.jac)
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/_trustregion.py", line 51, in jac
    self._g = self._jac(self._x)
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/optimize.py", line 327, in function_wrapper
    return function(*(wrapper_args + args))
  File "/home/hubertz/.FreeCAD/Mod/FreeCAD_Assembly4-solver/solver/Solver.py", line 27, in grad
    return self.val.grad

'NoneType' object has no attribute 'grad'

in line 44, there is

Code: Select all

solution = minimize(self.eval, x0,  method="trust-ncg", jac=self.grad, hess=self.hess, options={"gtol": 1e-8, "disp": True})
but the eval method is defined as:

Code: Select all

def eval(self, x):
shouldn't some x values be provided ?




The best test-case to check whether the solver can be used for real-world problems is the hexapod. For that, we need to set the length of a segment, or the distance of a point to a plane, but this constraint doesn't seem to exist (yet).

I'm really enthusiastic to make this thing work, thank-you for the work.
try the Assembly4 workbench for FreCAD v0.19
install with Tools > Addon Manager > Assembly4 — tutorials here and here
User avatar
alonso_jamm
Posts: 37
Joined: Mon Nov 11, 2019 11:32 pm

Re: Assembly 4 workbench

Postby alonso_jamm » Fri Aug 21, 2020 10:00 pm

Zolko wrote:
Fri Aug 21, 2020 2:01 pm
alonso_jamm wrote:
Mon Aug 10, 2020 8:19 pm
Hello, I tried to make a solver for Assembly 4. The work I have done is in my fork of the assembly under the solver branch.
First of all, nice dialogs, nice integration with the rest of the UI. Unfortunately, I always get an error when updating the assembly:

Code: Select all

Running the Python command 'Asm4_updateAssembly' failed:
Traceback (most recent call last):
  File "/home/hubertz/.FreeCAD/Mod/FreeCAD_Assembly4-solver/updateAssemblyCmd.py", line 55, in Activated
    solved = sol.solve(x_i)
  File "/home/hubertz/.FreeCAD/Mod/FreeCAD_Assembly4-solver/solver/Solver.py", line 44, in solve
    solution = minimize(self.eval, x0,  method="trust-ncg",
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/_minimize.py", line 627, in minimize
    return _minimize_trust_ncg(fun, x0, args, jac, hess, hessp,
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/_trustregion_ncg.py", line 39, in _minimize_trust_ncg
    return _minimize_trust_region(fun, x0, args=args, jac=jac, hess=hess,
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/_trustregion.py", line 182, in _minimize_trust_region
    while m.jac_mag >= gtol:
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/_trustregion.py", line 71, in jac_mag
    self._g_mag = scipy.linalg.norm(self.jac)
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/_trustregion.py", line 51, in jac
    self._g = self._jac(self._x)
  File "/tmp/.mount_FreeCAafOCKi/usr/lib/python3.8/site-packages/scipy/optimize/optimize.py", line 327, in function_wrapper
    return function(*(wrapper_args + args))
  File "/home/hubertz/.FreeCAD/Mod/FreeCAD_Assembly4-solver/solver/Solver.py", line 27, in grad
    return self.val.grad

'NoneType' object has no attribute 'grad'

in line 44, there is

Code: Select all

solution = minimize(self.eval, x0,  method="trust-ncg", jac=self.grad, hess=self.hess, options={"gtol": 1e-8, "disp": True})
but the eval method is defined as:

Code: Select all

def eval(self, x):
shouldn't some x values be provided ?
That is interesting. I don't get this error, does it happen on different documents (even on documents without constraints)? can you upload the document where that error happens?

The minimize function uses several functions to do its calculations. The self.eval is one of them, we need to pass the function as an argument.

I use hyper dual numbers to calculate the gradient and hessian matrices for the solver. Since the minimize function only works with arrays of real values, the solver has to transform the numpy arrays of real values to lists of hyper duals and vice versa. The conversion of numpy arrays of reals to a list of hyper duals happens in the self.eval function. This function stores the resulting hyper dual number in self.val and returns the real part of the hyper dual which is the value of the function at the specified point (the input x). And when self.grad or self.hess are called, they just return the gradient and hessian parts of the hyper dual stored in self.val. Which means that I assume that self.eval is called first. The error you get says that self.val is None when calling self.grad which either means that self.grad was called before self.eval or self.eval failed silently.

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?

Zolko wrote:
Fri Aug 21, 2020 2:01 pm
The best test-case to check whether the solver can be used for real-world problems is the hexapod. For that, we need to set the length of a segment, or the distance of a point to a plane, but this constraint doesn't seem to exist (yet).
I am planning on adding more constraints. But first I need to refactor some of the code first and maybe modify the fix and equality constraints. I believe that the way these two constraints work leaves too many objects in the tree. I think that I can combine the equality constraints between two objects into only one constraint object instead of up to 6 constraint objects. Once I finish that, I will work on adding more constraints like distance constraints.