FC Gears: Feedback thread

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
drmacro
Veteran
Posts: 8870
Joined: Sun Mar 02, 2014 4:35 pm

Re: FC Gears: Feedback thread

Post by drmacro »

Cadder wrote: Tue Dec 06, 2022 8:43 am
chrisb wrote: Tue Dec 06, 2022 8:38 am Please elaborate: add your FreeCAD infos and describe how you change it.
Well, I use Realthunder fork, so it's other issue.
Help>About, Copy to clipboard.

It provides the details like so, simply paste...

Code: Select all

OS: Debian GNU/Linux 11 (bullseye) (XFCE/lightdm-xsession)
Word size of FreeCAD: 64-bit
Version: 0.21.0.31238 (Git)
Build type: Release
Branch: master
Hash: 6f0afb4d0b8b7a901a8b5b54e07c25e36e840548
Python 3.9.2, Qt 5.15.2, Coin 4.0.0, Vtk 7.1.1, OCC 7.5.1
Locale: English/United States (en_US)
Installed mods: 
  * parts_library
  * kicadStepUpMod 10.16.5
  * Manipulator 1.4.9
  * PrefExtras
  * QuickMeasure 2022.10.28
  * MyDefaults 2022.9.15
  * ZolkoBase 0.0.1
  * DynamicData 2.46.0
  * fasteners 0.4.25
  * Nodes 0.1.25
  * MacMechX 2022.9.15
  * ExtremeProDark 2.6.4
  * ProDarkThemePreferencePack 1.0.0
  * fcgear 1.0.0
  * plugins
  * Pyramids-and-Polyhedrons
  * Defeaturing 1.2.0
  * Assembly4 0.12.4
  * BaseTest 0.0.1
  * OpticsWorkbench 1.0.9
  * workfeature-macro
  * sheetmetal 0.2.59
  * A2plus 0.4.60f
  * CurvedShapes 1.0.4
  * BasicMech 0.0.1
  * Dracula 0.0.2
  * Curves 0.6.4
  * workfeature
  * lattice2 1.0.0
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Cadder
Posts: 46
Joined: Sat Sep 03, 2022 6:52 am

Re: FC Gears: Feedback thread

Post by Cadder »

drmacro wrote: Tue Dec 06, 2022 4:06 pm Help>About, Copy to clipboard.
It provides the details like so, simply paste...
Actually there is no bug here, just tessellation preferences should be configured with lower values.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: FC Gears: Feedback thread

Post by onekk »

Is here the correct place to ask help for freecad.gears addon?

I want to script some gears using some data to replicate a model, and I have some problem in finding a correct match.

I have used the PartDesign module as it is available in FC without too much hassle, but I have some doubt in the correctness of the guess I have made.

Currently I'm using:

Code: Select all

OS: Artix Linux (openbox)
Word size of FreeCAD: 64-bit
Version: 0.20.2.29603 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.20.2)
Hash: 930dd9a76203a3260b1e6256c70c1c3cad8c5cb8
Python 3.10.8, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: Italian/Italy (it_IT)
Installed mods: 
  * CurvedShapes 1.0.4
  * ScriptWB-v1
  * QuickMeasure 2022.10.28
  * freecad.gears 1.0.0
  * Assembly4 0.12.7
  * fasteners 0.4.56
  * toSketch 1.0.1
  * Curves 0.6.8
  * Help 1.0.3


Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
jonasb
Posts: 162
Joined: Tue Dec 22, 2020 7:57 pm

Re: FC Gears: Feedback thread

Post by jonasb »

onekk wrote: Fri Apr 14, 2023 5:18 pm Is here the correct place to ask help for freecad.gears addon?
I guess so. "FC Gears" and "freecad.gears" are virtually the same, where the later is just the actual python module's name.
onekk wrote: Fri Apr 14, 2023 5:18 pm I have used the PartDesign module as it is available in FC without too much hassle, but I have some doubt in the correctness of the guess I have made.
Please note that the involute gear feature of PartDesign and "FC Gears" are completely independent. So if your question is about the PartDesign feature, I'd suggest to open a dedicated thread.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: FC Gears: Feedback thread

Post by onekk »

jonasb wrote: Sun Apr 16, 2023 8:03 am ...
Here a test code:
gears_asm.py
(6.82 KiB) Downloaded 21 times
You could set test_g to False to see gears and not the pitch circle (pd in the code)

Code: Select all

    # Set test_g to True to see the pd circles
    test_g = True
This code use the a actual PD implementation code, only to obtain the profile and then extrude it.

I could see that probably shaft positions are wrong, so as "pitch circles" don't touch, probably a first problem is found, I could move some shaft positions as it is a gear train and only first shaft and end shaft position affect the model.

What I want to achieve is:
  • design it with scripting using freecad.gears WB
  • check for correct position the whole gear train, I have tuned solids viewobjects with this code:

    Code: Select all

        for obj in (g1a_do, g1b_do, g2_do, g3_do, g4_do):
            obj.ViewObject.AngularDeflection = 5.00
            obj.ViewObject.Deviation = 0.01
    
  • design with scripting a worm gear to couple with a gear to make something similar to a steering gear see below.
Gears train:

gears.jpg
gears.jpg (12.33 KiB) Viewed 936 times

Steering:

gears_steer.jpg
gears_steer.jpg (4.03 KiB) Viewed 936 times

coupling gear: 20 tooth gear with a 0.417 in pitch diameter.
worm pitch diameter is 0.333 in


TIA for any help.

Regards

Carlo D.

Sorry edited multiple times :oops:
Last edited by onekk on Thu Apr 20, 2023 9:11 am, edited 2 times in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: FC Gears: Feedback thread

Post by onekk »

Here som mockup of a working code:

Code: Select all

"""Sample code.

This code was written as an sample code

Name: 20230507-gears.py

Author: Carlo Dormeletti
Copyright: 2023
Licence: CC BY-NC-ND 4.0 IT
"""
# Standard library imports
import math  # noqa
import os  # noqa
import sys  # noqa

from math import asin, atan, cos, degrees,  pi, radians, sin, sqrt  # noqa

# FreeCAD imports
import FreeCAD  # noqa
import FreeCADGui  # noqa
import Part
import Sketcher

from FreeCAD import Placement, Rotation  # noqa

# Path management
MODULE_PATH = os.path.dirname(__file__)
DATA_DIR = FreeCAD.getUserAppDataDir()

DBG_LOAD = False

if MODULE_PATH not in sys.path:
    if DBG_LOAD is True:
        print("no module path")
    sys.path.insert(-1, MODULE_PATH)
else:
    if DBG_LOAD is True:
        print("module path is present")

# External WB
from freecad.gears.features import ViewProviderGear, InvoluteGear

GE_ICONPATH = os.path.join(DATA_DIR, "Mod/freecad.gears/freecad/gears/icons/")

# print(f'DATA_DIR: {DATA_DIR}')
# print(f'ICONPATH: {GE_ICONPATH}')

# START Shortcuts
V3d = FreeCAD.Vector

VEC0 = V3d(0, 0, 0)
ROT0 = Rotation(0, 0, 0)

DirX = V3d(1, 0, 0)
DirY = V3d(0, 1, 0)
DirZ = V3d(0, 0, 1)

# Helpers methods

def clear_doc(doc_name):
    """Clear the document deleting all the objects.

    Parameters
    ----------
    doc_name : string
      document name

    Returns
    -------
    None
    """
    doc = FreeCAD.getDocument(doc_name)
    try:
        while len(doc.Objects) > 0:
            doc.removeObject(doc.Objects[0].Name)
    except Exception as e:
        print(f'Exception:  {e}')


# SERVICE METHODS

def ensure_document(doc_name, action=0):
    """Ensure existence of document with doc_name and clear the doc.

    Parameters
    ----------
    doc_name : string
        document name
    action : int
        clear action if document exist
          0: do nothing
          1: close and reopen the document with the same name
          2: delete all objects

    Returns
    -------
    doc_name : string
        Document name from obj.Name
    """
    doc_root = FreeCAD.listDocuments()
    doc_exist = False

    for d_name, doc in doc_root.items():
        # debug info do not delete
        print(f"ED: doc name = {d_name}")

        if d_name == doc_name:
            print("Match name")
            if action == 1:
                # when using clear_doc() is not possible like in Part.Design
                FreeCAD.closeDocument(doc_name)
                doc_exist = False
            elif action == 2:
                doc_exist = True
                clear_doc(doc_name)
                FreeCAD.setActiveDocument(d_name)
            else:
                doc_exist = True
                FreeCAD.setActiveDocument(d_name)

    if doc_exist is False:
        # debug info do not delete
        # print("ED: Create = {}".format(doc_name))
        FreeCAD.newDocument(doc_name)

    return FreeCAD.activeDocument().Name


def setview(doc_name, t_v=0):
    """Set viewport in 3D view."""
    FreeCAD.setActiveDocument(doc_name)

    VIEW = FreeCAD.Gui.ActiveDocument.ActiveView

    if t_v == 0:
        VIEW.viewTop()
    elif t_v == 1:
        VIEW.viewFront()
    else:
        VIEW.viewAxometric()
    VIEW.setAxisCross(True)
    VIEW.fitAll()


# CODE GOES HERE

def make_invgear(d_doc, gear_nm, th, pd):
    """Make an involute gear."""
    IconPath = os.path.join(GE_ICONPATH, 'involutegear.svg')
    print(f'icon: {IconPath}')
    # test a gear
    obj = d_doc.addObject("Part::FeaturePython", gear_nm)
    gear = InvoluteGear(obj)
    # porperties
    g_mod = pd/th
    obj.teeth = th
    obj.height = '2.5 mm'
    obj.module = f'{g_mod} in'

    # generate
    gear.generate_gear_shape(obj)
    ViewProviderGear(obj.ViewObject, IconPath)

    return obj.Name


if __name__ == "__main__":
    # ensure we have a document
    doc1_name = "gears_test"
    out_doc = ensure_document(doc1_name, 2)

    dest_doc = FreeCAD.activeDocument()

    make_invgear(dest_doc, "involute_test", 16, .333)
    # operational code go here

    dest_doc.recompute()
    setview(out_doc, 1)

here the code in case someone would want to download it:
20230507-gears.py
(3.97 KiB) Downloaded 17 times
I have some doubt.

I have some data about gears:

Code: Select all

teeth   Pitch diameter
32       .667 in
80      1.667 in
66      1.375 in
16       .333 in
120     2.500 in
and I have found around some formulas that tells that module is equal to the pitch diameter / number of teeth so I've put in the formula:

Code: Select all

    obj = d_doc.addObject("Part::FeaturePython", gear_nm)
    gear = InvoluteGear(obj)
    # porperties
    g_mod = pd/th * 2.54
    obj.teeth = th
    obj.height = '2.5 mm'
    obj.module = f'{g_mod} mm'
How to check the correctness of the data?

reading in :

https://wiki.freecad.org/FCGear_InvoluteGear#Notes

Edit: I have dw in properties under "computed" and it seems that is pitch diameter.

Some test seem to reveal that is correctly working.

Someone could explain some technical hints about gears?

tested on:

Code: Select all

OS: Artix Linux (openbox)
Word size of FreeCAD: 64-bit
Version: 0.20.2.29603 (Git) AppImage
Build type: Release
Branch: (HEAD detached at 0.20.2)
Hash: 930dd9a76203a3260b1e6256c70c1c3cad8c5cb8
Python 3.10.8, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: Italian/Italy (it_IT)
Installed mods: 
  * CurvedShapes 1.0.4
  * ScriptWB-v1
  * QuickMeasure 2022.10.28
  * freecad.gears 1.0.0
  * Assembly4 0.50.1
  * fasteners 0.4.56
  * toSketch 1.0.1
  * Curves 0.6.8
  * Help 1.0.3

TIA and Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
bambuko
Veteran
Posts: 2165
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: FC Gears: Feedback thread

Post by bambuko »

question, please:
Why is "gears workbench" called "freecad gears workbench" ?
None of the others feel the need to use word freecad in their name?
Because addons are listed in alphabetic order, it ends up being listed in a "wrong" place :mrgreen:
Just me being anally retentive and obsessive :lol:
sorry :oops: and thank you for a great workbench!


Screenshot_20231226_124347.png
Screenshot_20231226_124347.png (166.42 KiB) Viewed 498 times
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: FC Gears: Feedback thread

Post by looo »

ok the question is: why calling workbenches freecad.<wokbench_name>?

I found this naming convention very convenient:
freecad.gears is a namespace module. This means it extends the freecad namespace. So in python you import the freecad relevant stuff via:

Code: Select all

from freecad import gears
or:

Code: Select all

import freecad.gears
which is nice as the freecad.gears module is only useful with freecad. Without freecad there is not much you can do with this module. But on the other hand the module has no differences compared to a normal python module. So combining the worlds of freecad-packaging and python-packaging.

With this structure it's possible to create a pipit package for the freecad.gears workbench or create a condo-package... This is especially nice if you have a lot of dependencies. Yeah, the add-on-manager can handle also pip dependencies, but for a lot of dependencies I would not trust this process and use alternative ways to install the workbench. For example this is done with the freecad.glider workbench. This is basically a freecad-gui for openglider. This workbench is not available via the add-on-manager because handling the dependencies is a nightmare. Also via pip this is not so easy. So there is the possibility to install freecad.glider via the conda-packagemanager...

I was never very happy with the add-on-manager. This is just another solution for a problem that was already solved (or partially solved, packaging in general is not so easy with python :)). In my eyes it would be better to distribute packages via pip or conda and create a gui in freecad for these package-manager...

As you can see with freecad.gears I introduced some changes for the latest FreeCAD main-brach (yes it's now called main, not master anymore). So there are issues with older versions of freecad and the freecad.gears workbench. Adding version checks like this [1] solves this issue, but this is not very nice. It would be nicer to handle this with different versions of the package.

Additionally the add-on-manager format added a version for packages. Again python has a way to do this already... So now there are two versions to keep updated instead of one [2, 3]

But it is what it is. There is the option to distribute via add-on-manager (which is nice for development, and fast for testing), then there is the option to distribute with pip, conda for more advanced packaging and for sure you can also distribute with system-package managers...

So accepting that the packaging world of python, freecad and in general is a little bit messy and use what fits best for you.
Regarding the naming of freecad.gears: In my eyes this is a good way to name freecad extensions. And if all would use name-space modules and extend the freecad-namespace this would be a great solution (we discussed this in the past: search for namespace, name-clashes ...) But it's up to everyone to use what fits best and accept and expect a little bit of mess in the open-source world :)

[1]https://github.com/looooo/freecad.gears ... f8803d157d
[2]https://github.com/looooo/freecad.gears ... fe9378e45d
[3]https://github.com/looooo/freecad.gears ... d1572d52f7
User avatar
bambuko
Veteran
Posts: 2165
Joined: Thu Oct 24, 2019 12:53 pm
Location: UK, England, North Devon

Re: FC Gears: Feedback thread

Post by bambuko »

looo wrote: Tue Dec 26, 2023 1:40 pm ...
Thank you for detailed explanation and an update.

I understand your point and the only comment I'd make is that,
regardless of the merits of one or other naming convention,
it would be desirable to have consistency,
but ... such is the nature of addons and open source ;) that every developer can do their own thing
(after all it is easy to handle - just curiosity on my part)

Talking about addon manager - am I correct in thinking that you cannot have different addons for link branch and main branch?
They both share the same location? (not a problem, just curiosity :) again)
I am using Link branch and Assembly3
you can also download ... and try it here
excellent Assembly3 tutorials here
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: FC Gears: Feedback thread

Post by looo »

bambuko wrote: Tue Dec 26, 2023 2:01 pm Talking about addon manager - am I correct in thinking that you cannot have different addons for link branch and main branch?
They both share the same location? (not a problem, just curiosity :) again)
I am not an expert on the add-on-manager, not sure if you can set the location where the addonmanager installs addons.


Again for this it's great to have conda. With conda it's possible to have different freecad versions side by side in different environments. So if adding would be installable with conda it would be easy to have different free cad-versions with different addons in different envs... But there are not many addons for freecad installable via pip / conda, so this is not an option. Just talking about the theoretical options :)
Post Reply