then, good practice is to read the forum:
Assembly 4 workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Assembly 4 workbench
Re: Assembly 4 workbench
Attempting to insert a fastener from the fastener icon in A4. and I get:Zolko wrote:
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'
(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."
Re: Assembly 4 workbench
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...
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."
Re: Assembly 4 workbench
that's very strange. Can you please try to run the commanddrmacro 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'
Code: Select all
>>> Gui.listCommands()
that's also quite strange. Mine says:Version: 0.19.
Build type: Release
Branch: unknown
Hash: 0cf8279f00017ed2913e0c17beda77c733f98350
...
OCC version: 7.3.0
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 ?
Re: Assembly 4 workbench
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.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...
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.
- alonso_jamm
- Posts: 77
- Joined: Mon Nov 11, 2019 11:32 pm
Re: Assembly 4 workbench
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:
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.
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.
Re: Assembly 4 workbench
This looks really cool. I just came back from vacations and will take a look at it ASAP. Thanxalonso_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.
Re: Assembly 4 workbench
This error occurred just in one commit, git commit 9b529bc45c, but since it caused regressions a compatibility fix was quickly made, git commit 76e7429489.drmacro wrote: ↑Mon Aug 03, 2020 5:15 pmCode: Select all
... module 'FreeCADGui' has no attribute 'listCommands'
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.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: Assembly 4 workbench
First of all, nice dialogs, nice integration with the rest of the UI. Unfortunately, I always get an error when updating the assembly: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.
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})
Code: Select all
def eval(self, x):
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.
- alonso_jamm
- Posts: 77
- Joined: Mon Nov 11, 2019 11:32 pm
Re: Assembly 4 workbench
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?Zolko wrote: ↑Fri Aug 21, 2020 2:01 pmFirst of all, nice dialogs, nice integration with the rest of the UI. Unfortunately, I always get an error when updating the assembly: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.
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
but the eval method is defined as:Code: Select all
solution = minimize(self.eval, x0, method="trust-ncg", jac=self.grad, hess=self.hess, options={"gtol": 1e-8, "disp": True})
shouldn't some x values be provided ?Code: Select all
def eval(self, x):
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?
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.