diff --git a/coil_generator-12.ipynb b/coil_generator-12.ipynb index 45de5a9..bc418f3 100644 --- a/coil_generator-12.ipynb +++ b/coil_generator-12.ipynb @@ -286,8 +286,13 @@ " coil_A_f = translate(rotate(points_f, angle), COIL_CENTER_RADIUS, angle)\n", " coil_A_b = translate(rotate(points_b, angle), COIL_CENTER_RADIUS, angle)\n", " else:\n", - " coil_A_f = translate(rotate(flip_y(points_f), angle), COIL_CENTER_RADIUS, angle)\n", - " coil_A_b = translate(rotate(flip_y(points_b), angle), COIL_CENTER_RADIUS, angle)\n", + " # slightly nudge the coils so that they don't overlap when flipped\n", + " coil_A_f = translate(\n", + " rotate(flip_y(points_f), angle - 2), COIL_CENTER_RADIUS, angle\n", + " )\n", + " coil_A_b = translate(\n", + " rotate(flip_y(points_b), angle - 2), COIL_CENTER_RADIUS, angle\n", + " )\n", " # keep track of the coils\n", " coils_f.append(coil_A_f)\n", " coils_b.append(coil_A_b)\n", @@ -300,7 +305,7 @@ " )\n", "\n", "# raidus for connecting the bottoms of the coils together\n", - "connection_radius1 = STATOR_HOLE_RADIUS + TRACK_SPACING + TRACK_WIDTH\n", + "connection_radius1 = STATOR_HOLE_RADIUS + 0.5\n", "\n", "# create tracks to link the A coils around the center\n", "connection_via_radius_A = connection_radius1 + TRACK_SPACING + VIA_DIAM / 2\n", @@ -356,14 +361,14 @@ "vias.append(create_via(coil_C3_C4_inner[-1]))\n", "\n", "# connect the last three coils together\n", - "common_connection_radius = STATOR_RADIUS - TRACK_SPACING - TRACK_WIDTH\n", + "common_connection_radius = SCREW_HOLE_RADIUS - (SCREW_HOLE_DRILL_DIAM / 2 + 0.5)\n", "tracks_f.append(draw_arc(9 * 360 / 12, 11 * 360 / 12, common_connection_radius))\n", "coils_f[9].append(get_arc_point(9 * 360 / 12, common_connection_radius))\n", "coils_f[10].append(get_arc_point(10 * 360 / 12, common_connection_radius))\n", "coils_f[11].append(get_arc_point(11 * 360 / 12, common_connection_radius))\n", "\n", "# connect the outer A coils together\n", - "outer_connection_radius_A = STATOR_RADIUS - TRACK_SPACING - TRACK_WIDTH\n", + "outer_connection_radius_A = SCREW_HOLE_RADIUS + (SCREW_HOLE_DRILL_DIAM / 2 + 0.5)\n", "tracks_f.append(draw_arc(3 * 360 / 12, 6 * 360 / 12, outer_connection_radius_A))\n", "coils_f[3].append(get_arc_point(3 * 360 / 12, outer_connection_radius_A))\n", "coils_f[6].append(get_arc_point(6 * 360 / 12, outer_connection_radius_A))\n", @@ -381,7 +386,8 @@ "vias.append(create_via(get_arc_point(7 * 360 / 12, outer_connection_radius_B)))\n", "\n", "# connect the outer C coilds together\n", - "outer_connection_radius_C = outer_connection_radius_B - TRACK_SPACING - VIA_DIAM / 2\n", + "outer_connection_radius_C = SCREW_HOLE_RADIUS - (SCREW_HOLE_DRILL_DIAM / 2 + 0.5)\n", + "# outer_connection_radius_C = outer_connection_radius_B - TRACK_SPACING - VIA_DIAM / 2\n", "tracks_b.append(draw_arc(5 * 360 / 12, 8 * 360 / 12, outer_connection_radius_C))\n", "coils_f[5].append(get_arc_point(5 * 360 / 12, outer_connection_radius_C))\n", "coils_f[8].append(get_arc_point(8 * 360 / 12, outer_connection_radius_C))\n", @@ -407,6 +413,14 @@ "]\n", "\n", "# create the pads for connecting the inputs to the coils\n", + "silk.append(\n", + " create_silk((INPUT_PAD_RADIUS - PAD_HEIGHT - 2.5, PAD_PITCH), \"C\", \"b\", 2.5, -900)\n", + ")\n", + "silk.append(create_silk((INPUT_PAD_RADIUS - PAD_HEIGHT - 2.5, 0), \"B\", \"b\", 2.5, -900))\n", + "silk.append(\n", + " create_silk((INPUT_PAD_RADIUS - PAD_HEIGHT - 2.5, -PAD_PITCH), \"A\", \"b\", 2.5, -900)\n", + ")\n", + "\n", "pads.append(create_pad((INPUT_PAD_RADIUS, -PAD_PITCH), PAD_WIDTH, PAD_HEIGHT, \"b\"))\n", "pads.append(create_pad((INPUT_PAD_RADIUS, 0), PAD_WIDTH, PAD_HEIGHT, \"b\"))\n", "pads.append(create_pad((INPUT_PAD_RADIUS, PAD_PITCH), PAD_WIDTH, PAD_HEIGHT, \"b\"))\n", diff --git a/coil_generator-6.ipynb b/coil_generator-6.ipynb index 73186b5..17ac694 100644 --- a/coil_generator-6.ipynb +++ b/coil_generator-6.ipynb @@ -448,45 +448,22 @@ " for angle in [45, 135, 225, 315]\n", "]\n", "\n", - "# connect the coils to the input 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", - "# create the pins at CONNECTION_PINS radius - 2 for each of the coils, A, B and C\n", - "# pins.append(create_pin(CONNECTION_PINS_RADIUS, angle_A - 30, \"A\"))\n", - "# pins.append(create_pin(CONNECTION_PINS_RADIUS, angle_A + 30, \"A\"))\n", - "\n", - "# pins.append(create_pin(CONNECTION_PINS_RADIUS, angle_B - 30, \"B\"))\n", - "# pins.append(create_pin(CONNECTION_PINS_RADIUS, angle_B + 30, \"B\"))\n", - "\n", - "# pins.append(create_pin(CONNECTION_PINS_RADIUS, angle_C - 30, \"C\"))\n", - "# pins.append(create_pin(CONNECTION_PINS_RADIUS, angle_C + 30, \"C\"))\n", - "\n", - "\n", "# create the pads for connecting the inputs to the coils\n", + "silk.append(\n", + " create_silk((-PAD_PITCH, INPUT_PAD_RADIUS - PAD_HEIGHT - 2.5), \"C\", \"b\", 2.5)\n", + ")\n", "pads.append(create_pad((-PAD_PITCH, INPUT_PAD_RADIUS), PAD_HEIGHT, PAD_WIDTH, \"b\"))\n", + "\n", + "silk.append(create_silk((0, INPUT_PAD_RADIUS - PAD_HEIGHT - 2.5), \"B\", \"b\", 2.5))\n", "pads.append(create_pad((0, INPUT_PAD_RADIUS), PAD_HEIGHT, PAD_WIDTH, \"b\"))\n", + "\n", + "silk.append(\n", + " create_silk((PAD_PITCH, INPUT_PAD_RADIUS - PAD_HEIGHT - 2.5), \"A\", \"b\", 2.5)\n", + ")\n", "pads.append(create_pad((PAD_PITCH, INPUT_PAD_RADIUS), PAD_HEIGHT, PAD_WIDTH, \"b\"))\n", "\n", "# connect coil A to the middle pad\n", - "input_pad_connection_radius = STATOR_RADIUS - TRACK_SPACING - TRACK_WIDTH\n", + "input_pad_connection_radius = SCREW_HOLE_RADIUS + SCREW_HOLE_DRILL_DIAM / 2 + 0.5\n", "tracks_f.append(\n", " draw_arc(angle_A, 80, input_pad_connection_radius, 5)\n", " + [(PAD_PITCH, INPUT_PAD_RADIUS + VIA_DIAM)]\n", diff --git a/coil_plugin.py b/coil_plugin.py index 7283485..3962563 100644 --- a/coil_plugin.py +++ b/coil_plugin.py @@ -1,6 +1,7 @@ import pcbnew import json import wx +import math def create_tracks(board, group, net, layer, thickness, coords): @@ -121,11 +122,38 @@ class CoilPlugin(pcbnew.ActionPlugin): pcb_txt.SetText(text["text"]) pcb_txt.SetPosition(pcbnew.wxPointMM(text["x"], text["y"])) pcb_txt.SetHorizJustify(pcbnew.GR_TEXT_HJUSTIFY_CENTER) - pcb_txt.SetTextSize(pcbnew.wxSize(5000000, 5000000)) + pcb_txt.Rotate( + pcbnew.wxPointMM(text["x"], text["y"]), text["angle"] + ) + pcb_txt.SetTextSize( + pcbnew.wxSize( + text["size"] * pcbnew.IU_PER_MM, + text["size"] * pcbnew.IU_PER_MM, + ) + ) pcb_txt.SetLayer(pcbnew.F_SilkS) + if text["layer"] == "b": + pcb_txt.Flip(pcbnew.wxPointMM(text["x"], text["y"]), True) board.Add(pcb_txt) # pcb_group.AddItem(pcb_txt) + # create the mounting holes + for hole in coil_data["mountingHoles"]: + module = pcbnew.FOOTPRINT(board) + module.SetPosition(pcbnew.wxPointMM(hole["x"], hole["y"])) + board.Add(module) + pcb_pad = pcbnew.PAD(module) + pcb_pad.SetSize(pcbnew.wxSizeMM(hole["diameter"], hole["diameter"])) + pcb_pad.SetShape(pcbnew.PAD_SHAPE_CIRCLE) + pcb_pad.SetAttribute(pcbnew.PAD_ATTRIB_NPTH) + # pcb_pad.SetLayerSet(pcb_pad.NPTHMask()) + pcb_pad.SetDrillSize( + pcbnew.wxSizeMM(hole["diameter"], hole["diameter"]) + ) + pcb_pad.SetPosition(pcbnew.wxPointMM(hole["x"], hole["y"])) + module.Add(pcb_pad) + # pcb_group.AddItem(pcb_hole) + # create the stator outline arc = pcbnew.PCB_SHAPE(board) arc.SetShape(pcbnew.SHAPE_T_CIRCLE) diff --git a/pcb_json.py b/pcb_json.py index bca66e4..93435a8 100644 --- a/pcb_json.py +++ b/pcb_json.py @@ -22,11 +22,14 @@ def create_pad(point, width, height, layer): } -def create_silk(point, text): +def create_silk(point, text, layer="f", size=5, angle=0): return { "x": point[0], "y": point[1], "text": text, + "layer": layer, + "size": size, + "angle": angle, } @@ -86,7 +89,7 @@ def dump_json( "f": [create_track_json(points) for points in tracks_f], "b": [create_track_json(points) for points in tracks_b], }, - "mounting_holes": mounting_holes, + "mountingHoles": mounting_holes, } json.dump(json_result, open(filename, "w")) return json_result @@ -158,14 +161,17 @@ def plot_json(json_result): # plot the silk for silk in json_result["silk"]: + color = "cyan" + if silk["layer"] == "b": + color = "magenta" ax.text( silk["x"], silk["y"], silk["text"], horizontalalignment="center", verticalalignment="center", - color="black", - fontsize=50, + color=color, + fontsize=silk["size"] * 10, ) # plot the vias @@ -188,7 +194,7 @@ def plot_json(json_result): ) # plot the mounting holes - for hole in json_result["mounting_holes"]: + for hole in json_result["mountingHoles"]: ax.add_patch( plt.Circle( (hole["x"], hole["y"]),