From 8657be7d5c81751306de8eed1b186b587b83f73d Mon Sep 17 00:00:00 2001 From: looooo Date: Sat, 6 Jan 2024 20:26:49 +0100 Subject: [PATCH] update notebook --- .../cutting_tool_worm_assembly.ipynb | 175 ++++++++++-------- freecad/gears/timinggear_t.py | 1 - 2 files changed, 99 insertions(+), 77 deletions(-) diff --git a/examples/worm_cutting_tool/cutting_tool_worm_assembly.ipynb b/examples/worm_cutting_tool/cutting_tool_worm_assembly.ipynb index 64c291d..63dda44 100644 --- a/examples/worm_cutting_tool/cutting_tool_worm_assembly.ipynb +++ b/examples/worm_cutting_tool/cutting_tool_worm_assembly.ipynb @@ -425,43 +425,17 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 12, "id": "0811a6d6-4544-4a99-b4bd-ba5cf6b9027e", "metadata": {}, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "-2.605082438917929\n", - "-2.5926567550137163\n", - "-2.576276171400715\n", - "-2.5572968584132614\n", - "-2.5371037205738425\n", - "-2.516988590529518\n", - "-2.497957291921094\n", - "-2.4810015545771567\n", - "-2.4665124345839313\n", - "-2.455011136367867\n", - "-2.4464950349176995\n", - "-2.4409613820509275\n", - "-2.438356798763718\n", - "-2.438428922923462\n", - "-2.4408671029182987\n", - "-2.445442245573777\n", - "-2.4521135558911062\n", - "-2.460220787391342\n", - "-2.469626739199975\n", - "-2.4799773695959573\n" - ] - }, { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 6, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -474,16 +448,12 @@ "from pygears.transformation import numeric_transformation\n", "\n", "debug = False\n", - "def compute():\n", - " module = 1.\n", - " num_threads = 3\n", - " alpha = np.deg2rad(20.)\n", + "def compute_involute(module=1, teeth=15, height=5, worm_pitch_diameter=10, num_threads=1, alpha=np.deg2rad(20)):\n", " x = 0.\n", - " r_w = 7.5\n", - " y_p = 5\n", + " r_w = module * teeth / 2\n", + " y_p = worm_pitch_diameter / 2\n", " r_thales = r_w / 2.\n", " y_thales = y_p + r_thales\n", - " height = 5.\n", " \n", " def length(y):\n", " return (x**2 + y**2)**(0.5)\n", @@ -493,12 +463,12 @@ " \n", " def z(y, t):\n", " r = length(y)\n", - " return module * num_threads * np.arcsin(x / r) / 2 + r * np.tan(alpha) + t\n", + " return - module * num_threads * np.arcsin(x / r) / 2 + r * np.tan(alpha) + t\n", " # return r * np.tan(alpha) + t\n", " \n", " def dz_dy(y):\n", " r = length(y)\n", - " return -module * num_threads * x * dlength_dy(y) / \\\n", + " return module * num_threads * x * dlength_dy(y) / \\\n", " (2 * np.sqrt(1 - x ** 2 / r ** 2 ) * r ** 2) + \\\n", " np.tan(alpha) * dlength_dy(y)\n", " # return np.tan(alpha) * dlength_dy(y)\n", @@ -519,9 +489,9 @@ "\n", " def min_head(pars):\n", " y, t = pars\n", - " r_0 = y_p - module # * (1 + clearence)\n", - " y_inner = r_0 * np.cos(np.arcsin(x / r_0))\n", - " return ddistance_yp_dy(y, t) ** 2 + (y - y_inner) ** 2\n", + " r_0 = y_p - 2 * module # * (1 + clearence)\n", + " # y_inner = r_0 * np.cos(np.arcsin(x / r_0))\n", + " return ddistance_yp_dy(y, t) ** 2 + (y - r_0) ** 2\n", "\n", " def analytic_solution_for_x_0():\n", " t = - (r_w + y_p) * np.tan(alpha)\n", @@ -536,25 +506,26 @@ " print(f\"normal analytic: {ddistance_yp_dy(start[0], start[1])}\")\n", " print()\n", "\n", + " # t_end is once computed for x=0\n", + " t_end = sp.optimize.minimize(min_head, [y_p, 0.]).x[1]\n", "\n", " xyz = []\n", " for x in np.linspace(-height / 2, height / 2, 20):\n", " xyz_section = []\n", " t_start = sp.optimize.minimize(min_ground, start).x[1]\n", - " # t_end = sp.optimize.minimize(min_head, [y_p, 0.]).x[1]\n", - " t_end = 3\n", " for t in np.linspace(t_start, t_end, 20):\n", - " # compute the transformation\n", - " T0 = numeric_transformation((y_p * np.tan(alpha) + np.sign(alpha) * module * np.pi / 4) / r_w,\n", - " np.array([0., 0., 1.]), \n", - " np.array([0., 0.,0.]))\n", - " T1 = numeric_transformation(np.pi / 2.,\n", - " np.array([0., 1., 0.]),\n", - " np.array([0., y_p + r_w, 0.]))\n", - " T2 = numeric_transformation(-t / r_w,\n", - " np.array([0., 0., 1.]),\n", - " np.array([0., 0., 0.]))\n", - " T = T0 @ np.linalg.inv(T2) @ np.linalg.inv(T1)\n", + "\n", + " # compute the time (t) dependent transformation\n", + " phi = np.pi / 2\n", + " phi += y_p * np.tan(alpha) / r_w\n", + " phi += - np.sign(alpha) * module * np.pi / 4. / r_w\n", + " phi += t / r_w\n", + " T_0 = numeric_transformation(phi, np.array([0., 0., 1.]))\n", + " T_1 = numeric_transformation(-np.pi / 2, np.array([0., 1., 0.]))\n", + " T_2 = numeric_transformation(0., np.array([0., 0., 1.]), np.array([0, y_p + r_w, 0.]))\n", + " T = np.linalg.inv(T_2 @ T_1 @ T_0)\n", + " \n", + " # find point on curve for given t\n", " y = sp.optimize.minimize(distance_yp, y_p, (t)).x[0]\n", " z_i = z(y, t) # - y_p * np.tan(alpha) + np.sign(alpha) * module * np.pi / 4\n", " point = np.array([x, y, z_i, 1.])\n", @@ -562,43 +533,95 @@ " xyz.append(np.array(xyz_section))\n", "\n", " return np.array(xyz)\n", - "\n", - "\n", - "curves = []\n", - "for line in compute().transpose(1, 0, 2):\n", - " bs = part.BSplineCurve()\n", - " points = [app.Vector(*point) for point in line]\n", - " bs.interpolate(points)\n", - " curves.append(bs.toShape())\n", - "\n", - "part.show(part.makeLoft(curves))" + " \n", + "# create two surfaces one for positive alpha and one for negative alpha\n", + "\n", + "for alpha in [np.deg2rad(- 20), np.deg2rad(20)]: \n", + " curves = []\n", + " for line in compute_involute(alpha=alpha).transpose(1, 0, 2):\n", + " bs = part.BSplineCurve()\n", + " points = [app.Vector(*point) for point in line]\n", + " bs.interpolate(points)\n", + " curves.append(bs.toShape())\n", + " part.show(part.makeLoft(curves))\n", + "\n", + "# create cutting survaces for head and bottom\n", + "# 1. compute strat and end of phi\n", + "\n", + "height = 5\n", + "worm_pitch_diameter = 10\n", + "teeth = 15\n", + "y_p = worm_pitch_diameter / 2\n", + "r_w = 7.5\n", + "module = 1.\n", + "clearence = 0.25\n", + "head = 0.\n", + "\n", + "r_head = y_p - module * (1 + head)\n", + "r_foot = y_p + module * (1 + clearence)\n", + "\n", + "phi_head = np.arcsin(height / 2 / r_head) # from + phi to - phi\n", + "phi_foot = np.arcsin(height / 2 / r_foot)\n", + "\n", + "line_head = []\n", + "for phi_i in np.linspace(-phi_head, phi_head, 10):\n", + " x = r_w + y_p - np.cos(phi_i) * r_head\n", + " z = np.sin(phi_i) * r_head\n", + " line_head.append([x, 0., z, 1])\n", + "\n", + "line_foot = []\n", + "for phi_i in np.linspace(-phi_head, phi_head, 10):\n", + " x = r_w + y_p - np.cos(phi_i) * r_foot\n", + " z = np.sin(phi_i) * r_foot\n", + " line_foot.append([x, 0., z, 1])\n", + "\n", + "curves_head = []\n", + "curves_foot = []\n", + "phi_j_max = 2 * np.pi / teeth\n", + "for phi_j in np.linspace(-phi_j_max, phi_j_max, 10):\n", + " T = numeric_transformation(phi_j, np.array([0., 0., 1.]))\n", + " temp_points_foot = [app.Vector(*(T @ point)[:3]) for point in line_foot]\n", + " temp_points_head = [app.Vector(*(T @ point)[:3]) for point in line_head]\n", + " bsp_foot = part.BSplineCurve()\n", + " bsp_head = part.BSplineCurve()\n", + " bsp_foot.interpolate(temp_points_foot)\n", + " bsp_head.interpolate(temp_points_head)\n", + " curves_foot.append(bsp_foot.toShape())\n", + " curves_head.append(bsp_head.toShape())\n", + "\n", + "part.show(part.makeLoft(curves_foot))\n", + "part.show(part.makeLoft(curves_head))" ] }, { "cell_type": "code", - "execution_count": 5, - "id": "d804123e-3a1f-418a-b042-3619b1286c29", + "execution_count": 4, + "id": "5737ef53-ab3c-4ea4-98e7-09cfc111f956", "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "[1, 2]" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function numeric_transformation in module pygears.transformation:\n", + "\n", + "numeric_transformation(angle, axis, translation=array([0., 0., 0.]))\n", + " see http://en.wikipedia.org/wiki/SO%284%29#The_Euler.E2.80.93Rodrigues_formula_for_3D_rotations\n", + " angle: angle of rotation\n", + " axis: the axis of the rotation\n", + " translation: translation of transformation\n", + "\n" + ] } ], "source": [ - "[1,2,3,4][:2]" + "help(numeric_transformation)" ] }, { "cell_type": "code", "execution_count": null, - "id": "012a264b-12b2-4fa3-a734-60251262e914", + "id": "cfcc64d4-3756-431d-a78b-a81d30c5f6db", "metadata": {}, "outputs": [], "source": [] diff --git a/freecad/gears/timinggear_t.py b/freecad/gears/timinggear_t.py index 8299c96..c50c7e0 100644 --- a/freecad/gears/timinggear_t.py +++ b/freecad/gears/timinggear_t.py @@ -30,7 +30,6 @@ class TimingGearT(BaseGear): def __init__(self, obj): - print("hello gear") obj.addProperty("App::PropertyLength", "pitch", "base", "pitch of gear") obj.addProperty("App::PropertyInteger", "teeth", "base", "number of teeth") obj.addProperty(