mirror of
https://github.com/atomic14/kicad-coil-plugins.git
synced 2024-10-18 09:06:57 +00:00
686 lines
24 KiB
Text
686 lines
24 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import numpy as np\n",
|
|
"\n",
|
|
"# import matplotlib as plt\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import scipy\n",
|
|
"from skspatial.objects import LineSegment, Line, Vector\n",
|
|
"from enum import Enum\n",
|
|
"\n",
|
|
"Layer = Enum(\"Layer\", \"FRONT BACK\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"VIA_DIAM = 0.8\n",
|
|
"VIA_DRILL = 0.4\n",
|
|
"STATOR_HOLE_RADIUS = 5\n",
|
|
"TRACK_WIDTH = 0.127\n",
|
|
"TRACK_SPACING = 0.127\n",
|
|
"TURNS = 18\n",
|
|
"STATOR_RADIUS = 18\n",
|
|
"COIL_CENTER_RADIUS = 11.5\n",
|
|
"# where to place the pins\n",
|
|
"CONNECTION_PINS_RADIUS = 16\n",
|
|
"USE_SPIRAL = False"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# get the point on an arc at the given angle\n",
|
|
"def get_arc_point(angle, radius):\n",
|
|
" return (\n",
|
|
" radius * np.cos(np.deg2rad(angle)),\n",
|
|
" radius * np.sin(np.deg2rad(angle)),\n",
|
|
" )\n",
|
|
"\n",
|
|
"\n",
|
|
"# draw an arc\n",
|
|
"def draw_arc(start_angle, end_angle, radius, step=10):\n",
|
|
" points = []\n",
|
|
" for angle in np.arange(start_angle, end_angle + step, step):\n",
|
|
" x = radius * np.cos(np.deg2rad(angle))\n",
|
|
" y = radius * np.sin(np.deg2rad(angle))\n",
|
|
" points.append((x, y))\n",
|
|
" return points\n",
|
|
"\n",
|
|
"\n",
|
|
"# roate the points by the required angle\n",
|
|
"def rotate(points, angle):\n",
|
|
" return [\n",
|
|
" [\n",
|
|
" x * np.cos(np.deg2rad(angle)) - y * np.sin(np.deg2rad(angle)),\n",
|
|
" x * np.sin(np.deg2rad(angle)) + y * np.cos(np.deg2rad(angle)),\n",
|
|
" ]\n",
|
|
" for x, y in points\n",
|
|
" ]\n",
|
|
"\n",
|
|
"\n",
|
|
"# move the points out to the distance at the requited angle\n",
|
|
"def translate(points, distance, angle):\n",
|
|
" return [\n",
|
|
" [\n",
|
|
" x + distance * np.cos(np.deg2rad(angle)),\n",
|
|
" y + distance * np.sin(np.deg2rad(angle)),\n",
|
|
" ]\n",
|
|
" for x, y in points\n",
|
|
" ]\n",
|
|
"\n",
|
|
"\n",
|
|
"# flip the y coordinate\n",
|
|
"def flip_y(points):\n",
|
|
" return [[x, -y] for x, y in points]\n",
|
|
"\n",
|
|
"\n",
|
|
"def flip_x(points):\n",
|
|
" return [[-x, y] for x, y in points]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Arbitrary Coil Generation"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# templates must be simetric around the X axis and must include the center points on both size (e.g. (X1, 0).... (X2, 0) )\n",
|
|
"# template must also be convex\n",
|
|
"template = [\n",
|
|
" (-0.6, 0),\n",
|
|
" (-0.6, -0.6),\n",
|
|
" (0.5, -1.2),\n",
|
|
" (0.95, -0.4),\n",
|
|
" (0.95, 0),\n",
|
|
" (0.95, 0.4),\n",
|
|
" (0.5, 1.2),\n",
|
|
" (-0.6, 0.6),\n",
|
|
"]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# plot the template shape wrapping around to the first point\n",
|
|
"df = pd.DataFrame(template + [template[0]], columns=[\"x\", \"y\"])\n",
|
|
"ax = df.plot.line(x=\"x\", y=\"y\", color=\"blue\")\n",
|
|
"ax.axis(\"equal\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def calculate_point(point, point1, point2, spacing, turn):\n",
|
|
" reference_vector = Vector([-100, 0])\n",
|
|
" angle = np.rad2deg(Vector(point).angle_between(reference_vector))\n",
|
|
" if point[1] > 0:\n",
|
|
" angle = 360 - angle\n",
|
|
" vector = Vector(point1) - Vector(point2)\n",
|
|
" normal = vector / np.linalg.norm(vector)\n",
|
|
" # rotate the vector 90 degrees\n",
|
|
" normal = np.array([-normal[1], normal[0]])\n",
|
|
" # move the point along the normal vector by the spacing\n",
|
|
" offset = spacing * (turn * 360 + angle) / 360\n",
|
|
" coil_point = point + normal * offset\n",
|
|
" return (coil_point[0], coil_point[1])\n",
|
|
"\n",
|
|
"\n",
|
|
"def get_points(template, turns, spacing):\n",
|
|
" coil_points = []\n",
|
|
" reference_vector = Vector([-100, 0])\n",
|
|
" template_index = 0\n",
|
|
" template_length = len(template)\n",
|
|
" for turn in range(turns * template_length):\n",
|
|
" point1 = template[template_index % template_length]\n",
|
|
" point2 = template[(template_index + 1) % template_length]\n",
|
|
"\n",
|
|
" # calculate the new positions of the points\n",
|
|
" coil_point1 = calculate_point(\n",
|
|
" point1, point1, point2, spacing, template_index // template_length\n",
|
|
" )\n",
|
|
" coil_point2 = calculate_point(\n",
|
|
" point2, point1, point2, spacing, (template_index + 1) // template_length\n",
|
|
" )\n",
|
|
" # add an intermediate point which is the intersection of this new line with the previous line (if there is one)\n",
|
|
" # this prevents any cutting of corners\n",
|
|
" if len(coil_points) >= 2:\n",
|
|
" # create a line from the previous two points\n",
|
|
" line1 = Line(\n",
|
|
" coil_points[len(coil_points) - 2],\n",
|
|
" np.array(coil_points[len(coil_points) - 1])\n",
|
|
" - np.array(coil_points[len(coil_points) - 2]),\n",
|
|
" )\n",
|
|
" # create a line from the two new points\n",
|
|
" line2 = Line(\n",
|
|
" np.array(coil_point1),\n",
|
|
" np.array(np.array(coil_point1) - np.array(coil_point2)),\n",
|
|
" )\n",
|
|
" # find the intersection of the two lines\n",
|
|
" try:\n",
|
|
" intersection = line1.intersect_line(line2)\n",
|
|
" coil_points.append(intersection)\n",
|
|
" except:\n",
|
|
" pass\n",
|
|
" coil_points.append(coil_point1)\n",
|
|
" coil_points.append(coil_point2)\n",
|
|
"\n",
|
|
" template_index = template_index + 1\n",
|
|
" return coil_points\n",
|
|
"\n",
|
|
"\n",
|
|
"def optimize_points(points):\n",
|
|
" # follow the line and remove points that are in the same direction as the previous poin\n",
|
|
" # keep doing this until the direction changes significantly\n",
|
|
" # this is a very simple optimization that removes a lot of points\n",
|
|
" # it's not perfect but it's a good start\n",
|
|
" optimized_points = []\n",
|
|
" for i in range(len(points)):\n",
|
|
" if i == 0:\n",
|
|
" optimized_points.append(points[i])\n",
|
|
" else:\n",
|
|
" vector1 = np.array(points[i]) - np.array(points[i - 1])\n",
|
|
" vector2 = np.array(points[(i + 1) % len(points)]) - np.array(points[i])\n",
|
|
" length1 = np.linalg.norm(vector1)\n",
|
|
" length2 = np.linalg.norm(vector2)\n",
|
|
" if length1 > 0 and length2 > 0:\n",
|
|
" dot = np.dot(vector1, vector2) / (length1 * length2)\n",
|
|
" # clamp dot between -1 and 1\n",
|
|
" dot = max(-1, min(1, dot))\n",
|
|
" angle = np.arccos(dot)\n",
|
|
" if angle > np.deg2rad(5):\n",
|
|
" optimized_points.append(points[i])\n",
|
|
" print(\"Optimised from {} to {} points\".format(len(points), len(optimized_points)))\n",
|
|
" return optimized_points\n",
|
|
"\n",
|
|
"\n",
|
|
"def chaikin(points, iterations):\n",
|
|
" if iterations == 0:\n",
|
|
" return points\n",
|
|
" l = len(points)\n",
|
|
" smoothed = []\n",
|
|
" for i in range(l - 1):\n",
|
|
" x1, y1 = points[i]\n",
|
|
" x2, y2 = points[i + 1]\n",
|
|
" smoothed.append([0.9 * x1 + 0.1 * x2, 0.9 * y1 + 0.1 * y2])\n",
|
|
" smoothed.append([0.1 * x1 + 0.9 * x2, 0.1 * y1 + 0.9 * y2])\n",
|
|
" smoothed.append(points[l - 1])\n",
|
|
" return chaikin(smoothed, iterations - 1)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"if not USE_SPIRAL:\n",
|
|
" template_f = []\n",
|
|
" for i in range(len(template)):\n",
|
|
" template_f.append(template[len(template) - i - len(template) // 2])\n",
|
|
" template_f = flip_x(template_f)\n",
|
|
" points_f = chaikin(\n",
|
|
" optimize_points(\n",
|
|
" flip_x(get_points(template_f, TURNS, TRACK_SPACING + TRACK_WIDTH))\n",
|
|
" ),\n",
|
|
" 2,\n",
|
|
" )\n",
|
|
" points_b = chaikin(\n",
|
|
" optimize_points(get_points(template, TURNS, TRACK_SPACING + TRACK_WIDTH)), 2\n",
|
|
" )\n",
|
|
"\n",
|
|
" points_f = [(0, 0)] + points_f\n",
|
|
" points_b = [(0, 0)] + points_b\n",
|
|
"\n",
|
|
" df = pd.DataFrame(points_f, columns=[\"x\", \"y\"])\n",
|
|
" ax = df.plot.line(x=\"x\", y=\"y\", color=\"blue\")\n",
|
|
" ax.axis(\"equal\")\n",
|
|
" df = pd.DataFrame(points_b, columns=[\"x\", \"y\"])\n",
|
|
" ax = df.plot.line(x=\"x\", y=\"y\", color=\"red\", ax=ax)\n",
|
|
"\n",
|
|
" print(\"Track points\", len(points_f), len(points_b))\n",
|
|
"else:\n",
|
|
" print(\"Using spiral\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Basic Spiral Coil Generation"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def get_spiral(turns, start_radius, thickness, layer=Layer.FRONT):\n",
|
|
" points = []\n",
|
|
" # create a starting point in the center\n",
|
|
" for angle in np.arange(0, turns * 360, 1):\n",
|
|
" radius = start_radius + thickness * angle / 360\n",
|
|
" if layer == Layer.BACK:\n",
|
|
" x = radius * np.cos(np.deg2rad(angle + 180))\n",
|
|
" y = radius * np.sin(np.deg2rad(angle + 180))\n",
|
|
" points.append((x, -y))\n",
|
|
" else:\n",
|
|
" x = radius * np.cos(np.deg2rad(angle))\n",
|
|
" y = radius * np.sin(np.deg2rad(angle))\n",
|
|
" points.append((x, y))\n",
|
|
" return points"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"if USE_SPIRAL:\n",
|
|
" points_f = get_spiral(\n",
|
|
" TURNS, VIA_DIAM / 2 + TRACK_SPACING, TRACK_SPACING + TRACK_WIDTH, Layer.FRONT\n",
|
|
" )\n",
|
|
" points_b = get_spiral(\n",
|
|
" TURNS, VIA_DIAM / 2 + TRACK_SPACING, TRACK_SPACING + TRACK_WIDTH, Layer.BACK\n",
|
|
" )\n",
|
|
"\n",
|
|
" points_f = [(0, 0)] + points_f\n",
|
|
" points_b = [(0, 0)] + points_b\n",
|
|
" print(\"Track points\", len(points_f), len(points_b))\n",
|
|
"else:\n",
|
|
" print(\"Using template\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Generate PCB Layout"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# calculat the total length of the track to compute the resistance\n",
|
|
"total_length_front = 0\n",
|
|
"for i in range(len(points_f) - 1):\n",
|
|
" total_length_front += np.linalg.norm(\n",
|
|
" np.array(points_f[i + 1]) - np.array(points_f[i])\n",
|
|
" )\n",
|
|
"print(\"Total length front\", total_length_front)\n",
|
|
"\n",
|
|
"total_length_back = 0\n",
|
|
"for i in range(len(points_b) - 1):\n",
|
|
" total_length_back += np.linalg.norm(\n",
|
|
" np.array(points_b[i + 1]) - np.array(points_b[i])\n",
|
|
" )\n",
|
|
"print(\"Total length back\", total_length_back)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"vias = []\n",
|
|
"tracks_f = []\n",
|
|
"tracks_b = []\n",
|
|
"pads = []\n",
|
|
"\n",
|
|
"angle_A = 0\n",
|
|
"angle_B = 120\n",
|
|
"angle_C = 240\n",
|
|
"\n",
|
|
"\n",
|
|
"def create_pad(radius, angle, name):\n",
|
|
" return {\n",
|
|
" \"x\": radius * np.cos(np.deg2rad(angle)),\n",
|
|
" \"y\": radius * np.sin(np.deg2rad(angle)),\n",
|
|
" \"name\": name,\n",
|
|
" }\n",
|
|
"\n",
|
|
"\n",
|
|
"# create the pads at CONNECTION_PINS radius - 2 for each of the coils, A, B and C\n",
|
|
"pads.append(create_pad(CONNECTION_PINS_RADIUS, angle_A - 30, \"A\"))\n",
|
|
"pads.append(create_pad(CONNECTION_PINS_RADIUS, angle_A + 30, \"A\"))\n",
|
|
"\n",
|
|
"pads.append(create_pad(CONNECTION_PINS_RADIUS, angle_B - 30, \"B\"))\n",
|
|
"pads.append(create_pad(CONNECTION_PINS_RADIUS, angle_B + 30, \"B\"))\n",
|
|
"\n",
|
|
"pads.append(create_pad(CONNECTION_PINS_RADIUS, angle_C - 30, \"C\"))\n",
|
|
"pads.append(create_pad(CONNECTION_PINS_RADIUS, angle_C + 30, \"C\"))\n",
|
|
"\n",
|
|
"\n",
|
|
"def create_via(point):\n",
|
|
" return {\"x\": point[0], \"y\": point[1]}\n",
|
|
"\n",
|
|
"\n",
|
|
"# the main coils\n",
|
|
"coil_A_f = translate(rotate(points_f, angle_A), COIL_CENTER_RADIUS, angle_A)\n",
|
|
"coil_A_b = translate(rotate(points_b, angle_A), COIL_CENTER_RADIUS, angle_A)\n",
|
|
"tracks_f.append(coil_A_f)\n",
|
|
"tracks_b.append(coil_A_b)\n",
|
|
"\n",
|
|
"coil_B_f = translate(rotate(points_f, angle_B), COIL_CENTER_RADIUS, angle_B)\n",
|
|
"coil_B_b = translate(rotate(points_b, angle_B), COIL_CENTER_RADIUS, angle_B)\n",
|
|
"tracks_f.append(coil_B_f)\n",
|
|
"tracks_b.append(coil_B_b)\n",
|
|
"\n",
|
|
"coil_C_f = translate(rotate(points_f, angle_C), COIL_CENTER_RADIUS, angle_C)\n",
|
|
"coil_C_b = translate(rotate(points_b, angle_C), COIL_CENTER_RADIUS, angle_C)\n",
|
|
"tracks_f.append(coil_C_f)\n",
|
|
"tracks_b.append(coil_C_b)\n",
|
|
"\n",
|
|
"# the opposite coils - for more power!\n",
|
|
"angle_A_opp = angle_A + 180\n",
|
|
"angle_B_opp = angle_B + 180\n",
|
|
"angle_C_opp = angle_C + 180\n",
|
|
"\n",
|
|
"coil_A_opp_f = translate(\n",
|
|
" rotate(flip_y(points_f), angle_A_opp), COIL_CENTER_RADIUS, angle_A_opp\n",
|
|
")\n",
|
|
"coil_A_opp_b = translate(\n",
|
|
" rotate(flip_y(points_b), angle_A_opp), COIL_CENTER_RADIUS, angle_A_opp\n",
|
|
")\n",
|
|
"tracks_f.append(coil_A_opp_f)\n",
|
|
"tracks_b.append(coil_A_opp_b)\n",
|
|
"\n",
|
|
"coil_B_opp_f = translate(\n",
|
|
" rotate(flip_y(points_f), angle_B_opp), COIL_CENTER_RADIUS, angle_B_opp\n",
|
|
")\n",
|
|
"coil_B_opp_b = translate(\n",
|
|
" rotate(flip_y(points_b), angle_B_opp), COIL_CENTER_RADIUS, angle_B_opp\n",
|
|
")\n",
|
|
"tracks_f.append(coil_B_opp_f)\n",
|
|
"tracks_b.append(coil_B_opp_b)\n",
|
|
"\n",
|
|
"coil_C_opp_f = translate(\n",
|
|
" rotate(flip_y(points_f), angle_C_opp), COIL_CENTER_RADIUS, angle_C_opp\n",
|
|
")\n",
|
|
"coil_C_opp_b = translate(\n",
|
|
" rotate(flip_y(points_b), angle_C_opp), COIL_CENTER_RADIUS, angle_C_opp\n",
|
|
")\n",
|
|
"tracks_f.append(coil_C_opp_f)\n",
|
|
"tracks_b.append(coil_C_opp_b)\n",
|
|
"\n",
|
|
"# connect the front and back coils together\n",
|
|
"vias.append(create_via(get_arc_point(angle_A, COIL_CENTER_RADIUS)))\n",
|
|
"vias.append(create_via(get_arc_point(angle_B, COIL_CENTER_RADIUS)))\n",
|
|
"vias.append(create_via(get_arc_point(angle_C, COIL_CENTER_RADIUS)))\n",
|
|
"vias.append(create_via(get_arc_point(angle_A_opp, COIL_CENTER_RADIUS)))\n",
|
|
"vias.append(create_via(get_arc_point(angle_B_opp, COIL_CENTER_RADIUS)))\n",
|
|
"vias.append(create_via(get_arc_point(angle_C_opp, COIL_CENTER_RADIUS)))\n",
|
|
"\n",
|
|
"# connect the front copper opposite coils together\n",
|
|
"common_connection_radius = STATOR_RADIUS - (VIA_DIAM / 2 + TRACK_SPACING)\n",
|
|
"common_coil_connections_b = draw_arc(angle_A_opp, angle_C_opp, common_connection_radius)\n",
|
|
"coil_A_opp_f.append(get_arc_point(angle_A_opp, common_connection_radius))\n",
|
|
"coil_B_opp_f.append(get_arc_point(angle_B_opp, common_connection_radius))\n",
|
|
"coil_C_opp_f.append(get_arc_point(angle_C_opp, common_connection_radius))\n",
|
|
"\n",
|
|
"tracks_b.append(common_coil_connections_b)\n",
|
|
"\n",
|
|
"vias.append(create_via(get_arc_point(angle_A_opp, common_connection_radius)))\n",
|
|
"vias.append(create_via(get_arc_point(angle_B_opp, common_connection_radius)))\n",
|
|
"vias.append(create_via(get_arc_point(angle_C_opp, common_connection_radius)))\n",
|
|
"\n",
|
|
"# connect the coils to the pads\n",
|
|
"coil_A_f.append(get_arc_point(angle_A, common_connection_radius))\n",
|
|
"coil_B_f.append(get_arc_point(angle_B, common_connection_radius))\n",
|
|
"coil_C_f.append(get_arc_point(angle_C, common_connection_radius))\n",
|
|
"\n",
|
|
"tracks_f.append(\n",
|
|
" [get_arc_point(angle_A - 30, CONNECTION_PINS_RADIUS)]\n",
|
|
" + draw_arc(angle_A - 30, angle_A + 30, common_connection_radius)\n",
|
|
" + [get_arc_point(angle_A + 30, CONNECTION_PINS_RADIUS)]\n",
|
|
")\n",
|
|
"tracks_f.append(\n",
|
|
" [get_arc_point(angle_B - 30, CONNECTION_PINS_RADIUS)]\n",
|
|
" + draw_arc(angle_B - 30, angle_B + 30, common_connection_radius)\n",
|
|
" + [get_arc_point(angle_B + 30, CONNECTION_PINS_RADIUS)]\n",
|
|
")\n",
|
|
"tracks_f.append(\n",
|
|
" [get_arc_point(angle_C - 30, CONNECTION_PINS_RADIUS)]\n",
|
|
" + draw_arc(angle_C - 30, angle_C + 30, common_connection_radius)\n",
|
|
" + [get_arc_point(angle_C + 30, CONNECTION_PINS_RADIUS)]\n",
|
|
")\n",
|
|
"\n",
|
|
"# wires for connecting to opposite coils\n",
|
|
"connection_radius1 = STATOR_HOLE_RADIUS + (TRACK_SPACING)\n",
|
|
"connection_radius2 = connection_radius1 + (TRACK_SPACING + VIA_DIAM / 2)\n",
|
|
"\n",
|
|
"# draw a 45 degree line from each coil at connection radius 1\n",
|
|
"# then connect up to connection radius 2\n",
|
|
"# draw a 45 degree line to the opposite coil\n",
|
|
"\n",
|
|
"# coil A\n",
|
|
"coil_A_b.append(get_arc_point(angle_A, connection_radius1))\n",
|
|
"coil_A_opp_b.append(get_arc_point(angle_A_opp, connection_radius2))\n",
|
|
"a_connection_b = draw_arc(angle_A, angle_A + 90, connection_radius1)\n",
|
|
"a_connection_f = draw_arc(angle_A + 90, angle_A + 180, connection_radius2)\n",
|
|
"a_connection_b.append(a_connection_f[0])\n",
|
|
"\n",
|
|
"tracks_f.append(a_connection_f)\n",
|
|
"tracks_b.append(a_connection_b)\n",
|
|
"\n",
|
|
"# coil B\n",
|
|
"coil_B_b.append(get_arc_point(angle_B, connection_radius1))\n",
|
|
"coil_B_opp_b.append(get_arc_point(angle_B_opp, connection_radius2))\n",
|
|
"b_connection_b = draw_arc(angle_B, angle_B + 90, connection_radius1)\n",
|
|
"b_connection_f = draw_arc(angle_B + 90, angle_B + 180, connection_radius2)\n",
|
|
"b_connection_b.append(b_connection_f[0])\n",
|
|
"\n",
|
|
"tracks_f.append(b_connection_f)\n",
|
|
"tracks_b.append(b_connection_b)\n",
|
|
"\n",
|
|
"# coil C\n",
|
|
"coil_C_b.append(get_arc_point(angle_C, connection_radius1))\n",
|
|
"coil_C_opp_b.append(get_arc_point(angle_C_opp, connection_radius2))\n",
|
|
"c_connection_b = draw_arc(angle_C, angle_C + 90, connection_radius1)\n",
|
|
"c_connection_f = draw_arc(angle_C + 90, angle_C + 180, connection_radius2)\n",
|
|
"c_connection_b.append(c_connection_f[0])\n",
|
|
"\n",
|
|
"tracks_f.append(c_connection_f)\n",
|
|
"tracks_b.append(c_connection_b)\n",
|
|
"\n",
|
|
"vias.append(create_via(a_connection_f[0]))\n",
|
|
"vias.append(create_via(b_connection_f[0]))\n",
|
|
"vias.append(create_via(c_connection_f[0]))\n",
|
|
"\n",
|
|
"vias.append(create_via(a_connection_f[-1]))\n",
|
|
"vias.append(create_via(b_connection_f[-1]))\n",
|
|
"vias.append(create_via(c_connection_f[-1]))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def create_track(points):\n",
|
|
" return [{\"x\": x, \"y\": y} for x, y in points]\n",
|
|
"\n",
|
|
"\n",
|
|
"# dump out the results to json\n",
|
|
"json_result = {\n",
|
|
" \"parameters\": {\n",
|
|
" \"trackWidth\": TRACK_WIDTH,\n",
|
|
" \"statorHoleRadius\": STATOR_HOLE_RADIUS,\n",
|
|
" \"statorRadius\": STATOR_RADIUS,\n",
|
|
" \"viaDiameter\": VIA_DIAM,\n",
|
|
" \"viaDrillDiameter\": VIA_DRILL,\n",
|
|
" },\n",
|
|
" \"vias\": vias,\n",
|
|
" \"pads\": pads,\n",
|
|
" \"silk\": [\n",
|
|
" {\n",
|
|
" \"x\": COIL_CENTER_RADIUS * np.cos(np.deg2rad(angle_A)),\n",
|
|
" \"y\": COIL_CENTER_RADIUS * np.sin(np.deg2rad(angle_A)),\n",
|
|
" \"text\": \"A\",\n",
|
|
" },\n",
|
|
" {\n",
|
|
" \"x\": COIL_CENTER_RADIUS * np.cos(np.deg2rad(angle_B)),\n",
|
|
" \"y\": COIL_CENTER_RADIUS * np.sin(np.deg2rad(angle_B)),\n",
|
|
" \"text\": \"B\",\n",
|
|
" },\n",
|
|
" {\n",
|
|
" \"x\": COIL_CENTER_RADIUS * np.cos(np.deg2rad(angle_C)),\n",
|
|
" \"y\": COIL_CENTER_RADIUS * np.sin(np.deg2rad(angle_C)),\n",
|
|
" \"text\": \"C\",\n",
|
|
" },\n",
|
|
" ],\n",
|
|
" \"tracks\": {\n",
|
|
" \"f\": [create_track(points) for points in tracks_f],\n",
|
|
" \"b\": [create_track(points) for points in tracks_b],\n",
|
|
" },\n",
|
|
"}\n",
|
|
"\n",
|
|
"import json\n",
|
|
"\n",
|
|
"json.dump(json_result, open(\"coil.json\", \"w\"))\n",
|
|
"\n",
|
|
"\n",
|
|
"# df = pd.DataFrame(coil_A_f, columns=[\"x\", \"y\"])\n",
|
|
"# ax = df.plot.line(x=\"x\", y=\"y\", label=\"Coil A\", color=\"blue\")\n",
|
|
"# ax.axis(\"equal\")\n",
|
|
"# df = pd.DataFrame(coil_A_b, columns=[\"x\", \"y\"])\n",
|
|
"# ax = df.plot.line(x=\"x\", y=\"y\", label=\"Coil B\", color=\"green\")\n",
|
|
"# ax.axis(\"equal\")\n",
|
|
"\n",
|
|
"\n",
|
|
"# plot the back tracks\n",
|
|
"ax = None\n",
|
|
"for track in json_result[\"tracks\"][\"b\"]:\n",
|
|
" df = pd.DataFrame(track, columns=[\"x\", \"y\"])\n",
|
|
" ax = df.plot.line(x=\"x\", y=\"y\", color=\"blue\", ax=ax)\n",
|
|
" ax.axis(\"equal\")\n",
|
|
"\n",
|
|
"# plot the front tracks\n",
|
|
"for track in json_result[\"tracks\"][\"f\"]:\n",
|
|
" df = pd.DataFrame(track, columns=[\"x\", \"y\"])\n",
|
|
" ax = df.plot.line(x=\"x\", y=\"y\", color=\"red\", ax=ax)\n",
|
|
" ax.axis(\"equal\")\n",
|
|
"\n",
|
|
"# hide the legend\n",
|
|
"ax.legend().set_visible(False)\n",
|
|
"# make the plot bigger\n",
|
|
"ax.figure.set_size_inches(10, 10)\n",
|
|
"\n",
|
|
"# plot the vias\n",
|
|
"for via in json_result[\"vias\"]:\n",
|
|
" ax.add_patch(\n",
|
|
" plt.Circle(\n",
|
|
" (via[\"x\"], via[\"y\"]),\n",
|
|
" radius=VIA_DIAM / 2,\n",
|
|
" fill=True,\n",
|
|
" color=\"black\",\n",
|
|
" )\n",
|
|
" )\n",
|
|
" ax.add_patch(\n",
|
|
" plt.Circle(\n",
|
|
" (via[\"x\"], via[\"y\"]),\n",
|
|
" radius=VIA_DRILL / 2,\n",
|
|
" fill=True,\n",
|
|
" color=\"white\",\n",
|
|
" )\n",
|
|
" )\n",
|
|
"\n",
|
|
"# plot the edge cuts\n",
|
|
"ax.add_patch(\n",
|
|
" plt.Circle(\n",
|
|
" (0, 0),\n",
|
|
" radius=STATOR_RADIUS,\n",
|
|
" fill=False,\n",
|
|
" color=\"yellow\",\n",
|
|
" )\n",
|
|
")\n",
|
|
"ax.add_patch(\n",
|
|
" plt.Circle(\n",
|
|
" (0, 0),\n",
|
|
" radius=STATOR_HOLE_RADIUS,\n",
|
|
" fill=False,\n",
|
|
" color=\"yellow\",\n",
|
|
" )\n",
|
|
")\n",
|
|
"\n",
|
|
"# plot the pads\n",
|
|
"for pad in json_result[\"pads\"]:\n",
|
|
" ax.add_patch(\n",
|
|
" plt.Circle(\n",
|
|
" (pad[\"x\"], pad[\"y\"]),\n",
|
|
" radius=1.7 / 2,\n",
|
|
" fill=True,\n",
|
|
" color=\"yellow\",\n",
|
|
" )\n",
|
|
" )\n",
|
|
" ax.add_patch(\n",
|
|
" plt.Circle(\n",
|
|
" (pad[\"x\"], pad[\"y\"]),\n",
|
|
" radius=1.0 / 2,\n",
|
|
" fill=True,\n",
|
|
" color=\"white\",\n",
|
|
" )\n",
|
|
" )"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3.10.7 ('venv': venv)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.7"
|
|
},
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "fc384f9db26c31784edfba3761ba3d2c7b2f9b8a63e03a9eb0778fc35334efe1"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|