Another approach to assembly solver (A2plus)
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Another approach to assembly solver (A2plus)
Hi all,
I just detected, that the new version string of FC0.18.1 also broke the solving of constraints.
This is fixed with A2plus version v0.4.14
Please update your A2plus WB.
I just detected, that the new version string of FC0.18.1 also broke the solving of constraints.
This is fixed with A2plus version v0.4.14
Please update your A2plus WB.
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
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
-
- Posts: 115
- Joined: Wed May 30, 2018 6:59 pm
Re: Another approach to assembly solver (A2plus)
Could be possible to add this functionality for a Top - Down Modelling?
https://www.youtube.com/watch?v=tvzAcA8KNg0
here's follow the Macro, but I'm sure some skilled man could improve it.
Code: Select all
import os
import a2p_importpart as update
import PartDesignGui
assemblyName = App.ActiveDocument.Name
sel = FreeCADGui.Selection.getSelection()
update.a2p_EditPartCommand.Activated(sel)
pathPart = App.ActiveDocument.FileName
nameFile = App.ActiveDocument.Name
fN = App.getDocument(nameFile) #dleggo la struttura del file
skPath = fN.Objects[0].sourceFile
labelSk = fN.Objects[0].Label
FreeCAD.openDocument (skPath)
nameSk = App.ActiveDocument.Name
obj = App.ActiveDocument.RootObjects
for i in obj:
if i.Label == nameFile:
Gui.showObject(i)
else:
Gui.hideObject(i)
FreeCAD.ActiveDocument.save()
FreeCAD.setActiveDocument(nameFile)
update.a2p_UpdateImportedPartsCommand.Activated(labelSk)
FreeCAD.ActiveDocument.save()
FreeCAD.setActiveDocument(assemblyName)
update.a2p_UpdateImportedPartsCommand.Activated(sel)
FreeCAD.closeDocument (nameSk)
FreeCAD.closeDocument (nameFile)
Re: Another approach to assembly solver (A2plus)
Hi!
I have a problem with constraining one part in my test assembly.
No plane constraints are available for DTW50W_scanner (axial and circular work well). Any idea what might be wrong?
Test file attached.
A2plus version 0.4.15
Cheers,
Mateusz
UPDATE: Assembly 2 does not have any problem constraining this part...
I hope this is right place to ask.kbwbe wrote:
I have a problem with constraining one part in my test assembly.
No plane constraints are available for DTW50W_scanner (axial and circular work well). Any idea what might be wrong?
Test file attached.
A2plus version 0.4.15
Code: Select all
OS: Debian GNU/Linux buster/sid (KDE//usr/share/xsessions/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.16474 (Git)
Build type: Debug
Branch: master
Hash: 746997e48411f22a150b95b6fdbb9b02cbe741d5
Python version: 2.7.16
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Polish/Poland (pl_PL)
Mateusz
UPDATE: Assembly 2 does not have any problem constraining this part...
- Attachments
-
- test_v1.FCStd
- (114.9 KiB) Downloaded 79 times
Re: Another approach to assembly solver (A2plus)
Hi Mateusz,
i had a look at your file. The problematic part (DTW50W_scanner) does not have plane faces. Everything what seems to be a plane face is a BSplineSurface object in reality. Therefore A2plus does not accept them.
A2plus does not support BSplineSurfaces at moment. (Assembly2 does...)
Have a look at the report view in the following screenshot..
.
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
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
Re: Another approach to assembly solver (A2plus)
Thank you for a _very quick_ answer! Now I can stop banging my head against the wall.
FYI the model comes from the manufacturer in IGES format.
Ok. I'll try to work around this.kbwbe wrote: A2plus does not support BSplineSurfaces at moment. (Assembly2 does...)
Thank you for your great work!
Cheers,
Mateusz
Re: Another approach to assembly solver (A2plus)
I have come up with this hack but it does not work as expected yet. Do you have any pointers what else should be changed? It creates broken constraints.
Thank you!
Cheers,
Mateusz
Thank you!
Code: Select all
diff --git a/a2p_constraints.py b/a2p_constraints.py
index 01f7d1f..155d5cd 100644
--- a/a2p_constraints.py
+++ b/a2p_constraints.py
@@ -513,8 +513,20 @@ class PlaneConstraint(BasicConstraint):
c = self.constraintObject
plane1 = getObjectFaceFromName(self.ob1, c.SubElement1)
plane2 = getObjectFaceFromName(self.ob2, c.SubElement2)
- normal1 = plane1.Surface.Axis
- normal2 = plane2.Surface.Axis
+ if str(plane1.Surface) == '<BSplineSurface object>':
+ plane_norm, plane_pos, error = fit_plane_to_surface1(plane1.Surface)
+ normal1 = FreeCAD.Vector(plane_norm[0], plane_norm[1], plane_norm[2])
+ Msg('Normal 1 - my:{}\n'.format(normal1))
+ else:
+ normal1 = plane1.Surface.Axis
+ Msg('Normal 1:{}\n'.format(normal1))
+ if str(plane2.Surface) == '<BSplineSurface object>':
+ plane_norm2, plane_pos2, error2 = fit_plane_to_surface1(plane2.Surface)
+ normal2 = FreeCAD.Vector(plane_norm2[0], plane_norm2[1], plane_norm2[2])
+ Msg('Normal 2 - my:{}\n'.format(normal2))
+ else:
+ normal2 = plane2.Surface.Axis
+ Msg('Normal 2:{}\n'.format(normal2))
angle = math.degrees(normal1.getAngle(normal2))
if angle <= 90.0:
self.direction = "aligned"
diff --git a/a2plib.py b/a2plib.py
index cc8ef92..657a8fc 100644
--- a/a2plib.py
+++ b/a2plib.py
@@ -33,6 +33,9 @@ import sys
import copy
import platform
from a2p_viewProviderProxies import *
+import numpy
+crossProduct = numpy.cross
+dotProduct = numpy.dot
PYVERSION = sys.version_info[0]
@@ -97,6 +100,14 @@ else:
OPERATING_SYSTEM = "OTHER"
+def fit_plane_to_surface1( surface, n_u=3, n_v=3 ):
+ uv = sum( [ [ (u,v) for u in numpy.linspace(0,1,n_u)] for v in numpy.linspace(0,1,n_v) ], [] )
+ P = [ surface.value(u,v) for u,v in uv ] #positions at u,v points
+ N = [ crossProduct( *surface.tangent(u,v) ) for u,v in uv ]
+ plane_norm = sum(N) / len(N) #plane's normal, averaging done to reduce error
+ plane_pos = P[0]
+ error = sum([ abs( dotProduct(p - plane_pos, plane_norm) ) for p in P ])
+ return plane_norm, plane_pos, error
#------------------------------------------------------------------------------
def to_bytes(tx):
@@ -604,6 +615,8 @@ def planeSelected( selection ):
face = getObjectFaceFromName( selection.Object, subElement)
if str(face.Surface) == '<Plane object>':
return True
+ elif str(face.Surface) == '<BSplineSurface object>':
+ return True
return False
#------------------------------------------------------------------------------
def vertexSelected( selection ):
Mateusz
Re: Another approach to assembly solver (A2plus)
Hi Mateusz,
thank you for your effort. I reworked your code and implemented it to A2plus. Now it accepts (flat) BSplineSurfaces as plane references.
This is the commit, if you want to have a look at the changes...
https://github.com/kbwbe/A2plus/commit/ ... adac4d078d
Please update your A2plus WB to V0.4.16
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
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
Re: Another approach to assembly solver (A2plus)
Thanks to both of you.kbwbe wrote: ↑Sun Apr 14, 2019 10:53 amHi Mateusz,
thank you for your effort. I reworked your code and implemented it to A2plus. Now it accepts (flat) BSplineSurfaces as plane references.
This is the commit, if you want to have a look at the changes...
https://github.com/kbwbe/A2plus/commit/ ... adac4d078d
Please update your A2plus WB to V0.4.16
Re: Another approach to assembly solver (A2plus)
+1
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
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