mirror of
https://github.com/atomic14/kicad-coil-plugins.git
synced 2024-10-18 09:06:57 +00:00
New version with edge cuts
This commit is contained in:
parent
71fae64083
commit
a7fe16f903
5 changed files with 117 additions and 81 deletions
|
@ -408,12 +408,6 @@
|
|||
" create_via(get_arc_point(8 * 360 / 12 + COIL_ROTATION, outer_connection_radius_C))\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# create mounting holes at 45 degree angles\n",
|
||||
"mounting_holes = [\n",
|
||||
" create_mounting_hole(get_arc_point(angle, SCREW_HOLE_RADIUS), SCREW_HOLE_DRILL_DIAM)\n",
|
||||
" for angle in [45, 135, 225, 315]\n",
|
||||
"]\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",
|
||||
|
@ -460,12 +454,49 @@
|
|||
"tracks_b.append(draw_arc(coil_angles[0], -pad_angle, pad_connection_point_x, 1))\n",
|
||||
"tracks_b.append(draw_arc(coil_angles[2], pad_angle, pad_connection_point_x, 1))\n",
|
||||
"\n",
|
||||
"nibble_angle_size = 360 * SCREW_HOLE_DRILL_DIAM / (2 * np.pi * STATOR_RADIUS)\n",
|
||||
"\n",
|
||||
"outer_cuts = (\n",
|
||||
" draw_arc(-45 + nibble_angle_size / 2, 45 - nibble_angle_size / 2, STATOR_RADIUS, 5)\n",
|
||||
" + translate(\n",
|
||||
" rotate(draw_arc(1, 179, SCREW_HOLE_DRILL_DIAM / 2, 5)[::-1], 135),\n",
|
||||
" STATOR_RADIUS,\n",
|
||||
" 45,\n",
|
||||
" )\n",
|
||||
" + draw_arc(\n",
|
||||
" 45 + nibble_angle_size / 2, 135 - nibble_angle_size / 2, STATOR_RADIUS, 5\n",
|
||||
" )\n",
|
||||
" + translate(\n",
|
||||
" rotate(draw_arc(1, 179, SCREW_HOLE_DRILL_DIAM / 2, 5), 225)[::-1],\n",
|
||||
" STATOR_RADIUS,\n",
|
||||
" 135,\n",
|
||||
" )\n",
|
||||
" + draw_arc(\n",
|
||||
" 135 + nibble_angle_size / 2, 225 - nibble_angle_size / 2, STATOR_RADIUS, 5\n",
|
||||
" )\n",
|
||||
" + translate(\n",
|
||||
" rotate(draw_arc(1, 179, SCREW_HOLE_DRILL_DIAM / 2, 5), 315)[::-1],\n",
|
||||
" STATOR_RADIUS,\n",
|
||||
" 225,\n",
|
||||
" )\n",
|
||||
" + draw_arc(\n",
|
||||
" 225 + nibble_angle_size / 2, 315 - nibble_angle_size / 2, STATOR_RADIUS, 5\n",
|
||||
" )\n",
|
||||
" + translate(\n",
|
||||
" rotate(draw_arc(1, 179, SCREW_HOLE_DRILL_DIAM / 2, 5), 45)[::-1],\n",
|
||||
" STATOR_RADIUS,\n",
|
||||
" 315,\n",
|
||||
" )\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"edge_cuts = [\n",
|
||||
" outer_cuts,\n",
|
||||
" draw_arc(0, 360, STATOR_HOLE_RADIUS, 1),\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# dump out the json version\n",
|
||||
"json_result = dump_json(\n",
|
||||
" filename=\"coils_12.json\",\n",
|
||||
" stator_radius=STATOR_RADIUS,\n",
|
||||
" stator_hole_radius=STATOR_HOLE_RADIUS,\n",
|
||||
" track_width=TRACK_WIDTH,\n",
|
||||
" pin_diam=PIN_DIAM,\n",
|
||||
" pin_drill=PIN_DRILL,\n",
|
||||
|
@ -480,6 +511,7 @@
|
|||
" tracks_in2=tracks_in2,\n",
|
||||
" tracks_b=tracks_b,\n",
|
||||
" mounting_holes=mounting_holes,\n",
|
||||
" edge_cuts=edge_cuts,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
|
|
|
@ -451,10 +451,11 @@
|
|||
"]\n",
|
||||
"\n",
|
||||
"# create mounting holes at 45 degree angles\n",
|
||||
"mounting_holes = [\n",
|
||||
" create_mounting_hole(get_arc_point(angle, SCREW_HOLE_RADIUS), SCREW_HOLE_DRILL_DIAM)\n",
|
||||
" for angle in [45, 135, 225, 315]\n",
|
||||
"]\n",
|
||||
"# mounting_holes = [\n",
|
||||
"# create_mounting_hole(get_arc_point(angle, SCREW_HOLE_RADIUS), SCREW_HOLE_DRILL_DIAM)\n",
|
||||
"# for angle in [45, 135, 225, 315]\n",
|
||||
"# ]\n",
|
||||
"mounting_holes = []\n",
|
||||
"\n",
|
||||
"# create the pads for connecting the inputs to the coils\n",
|
||||
"silk.append(\n",
|
||||
|
@ -523,12 +524,49 @@
|
|||
" + [get_arc_point(angle_C - 30, input_connection_radius)]\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"nibble_angle_size = 360 * SCREW_HOLE_DRILL_DIAM / (2 * np.pi * STATOR_RADIUS)\n",
|
||||
"\n",
|
||||
"outer_cuts = (\n",
|
||||
" draw_arc(-45 + nibble_angle_size / 2, 45 - nibble_angle_size / 2, STATOR_RADIUS, 5)\n",
|
||||
" + translate(\n",
|
||||
" rotate(draw_arc(1, 179, SCREW_HOLE_DRILL_DIAM / 2, 5)[::-1], 135),\n",
|
||||
" STATOR_RADIUS,\n",
|
||||
" 45,\n",
|
||||
" )\n",
|
||||
" + draw_arc(\n",
|
||||
" 45 + nibble_angle_size / 2, 135 - nibble_angle_size / 2, STATOR_RADIUS, 5\n",
|
||||
" )\n",
|
||||
" + translate(\n",
|
||||
" rotate(draw_arc(1, 179, SCREW_HOLE_DRILL_DIAM / 2, 5), 225)[::-1],\n",
|
||||
" STATOR_RADIUS,\n",
|
||||
" 135,\n",
|
||||
" )\n",
|
||||
" + draw_arc(\n",
|
||||
" 135 + nibble_angle_size / 2, 225 - nibble_angle_size / 2, STATOR_RADIUS, 5\n",
|
||||
" )\n",
|
||||
" + translate(\n",
|
||||
" rotate(draw_arc(1, 179, SCREW_HOLE_DRILL_DIAM / 2, 5), 315)[::-1],\n",
|
||||
" STATOR_RADIUS,\n",
|
||||
" 225,\n",
|
||||
" )\n",
|
||||
" + draw_arc(\n",
|
||||
" 225 + nibble_angle_size / 2, 315 - nibble_angle_size / 2, STATOR_RADIUS, 5\n",
|
||||
" )\n",
|
||||
" + translate(\n",
|
||||
" rotate(draw_arc(1, 179, SCREW_HOLE_DRILL_DIAM / 2, 5), 45)[::-1],\n",
|
||||
" STATOR_RADIUS,\n",
|
||||
" 315,\n",
|
||||
" )\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"edge_cuts = [\n",
|
||||
" outer_cuts,\n",
|
||||
" draw_arc(0, 360, STATOR_HOLE_RADIUS, 1),\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"# dump out the json version\n",
|
||||
"json_result = dump_json(\n",
|
||||
" filename=\"coils_6.json\",\n",
|
||||
" stator_radius=STATOR_RADIUS,\n",
|
||||
" stator_hole_radius=STATOR_HOLE_RADIUS,\n",
|
||||
" track_width=TRACK_WIDTH,\n",
|
||||
" pin_diam=PIN_DIAM,\n",
|
||||
" pin_drill=PIN_DRILL,\n",
|
||||
|
@ -543,6 +581,7 @@
|
|||
" tracks_in2=tracks_in2,\n",
|
||||
" tracks_b=tracks_b,\n",
|
||||
" mounting_holes=mounting_holes,\n",
|
||||
" edge_cuts=edge_cuts,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
|
|
|
@ -47,8 +47,6 @@ class CoilPlugin(pcbnew.ActionPlugin):
|
|||
coil_data = json.load(f)
|
||||
# parameters
|
||||
track_width = coil_data["parameters"]["trackWidth"]
|
||||
stator_hole_radius = coil_data["parameters"]["statorHoleRadius"]
|
||||
stator_radius = coil_data["parameters"]["statorRadius"]
|
||||
pin_diameter = coil_data["parameters"]["pinDiameter"]
|
||||
pin_drill = coil_data["parameters"]["pinDrillDiameter"]
|
||||
via_diameter = coil_data["parameters"]["viaDiameter"]
|
||||
|
@ -175,41 +173,20 @@ class CoilPlugin(pcbnew.ActionPlugin):
|
|||
module.Add(pcb_pad)
|
||||
# pcb_group.AddItem(pcb_hole)
|
||||
|
||||
# create the stator outline
|
||||
arc = pcbnew.PCB_SHAPE(board)
|
||||
arc.SetShape(pcbnew.SHAPE_T_CIRCLE)
|
||||
arc.SetFilled(False)
|
||||
arc.SetStart(pcbnew.wxPointMM(CENTER_X, CENTER_Y))
|
||||
arc.SetEnd(pcbnew.wxPointMM(CENTER_X + stator_radius, CENTER_Y))
|
||||
arc.SetCenter(pcbnew.wxPointMM(CENTER_X, CENTER_Y))
|
||||
arc.SetLayer(pcbnew.Edge_Cuts)
|
||||
arc.SetWidth(int(0.1 * pcbnew.IU_PER_MM))
|
||||
board.Add(arc)
|
||||
# pcb_group.AddItem(arc)
|
||||
|
||||
# crate the outline using a vector
|
||||
# outline = pcbnew.PCB_SHAPE(board)
|
||||
# outline.SetShape(pcbnew.SHAPE_T_POLYGON)
|
||||
# outline.SetFilled(False)
|
||||
# outline.SetLayer(pcbnew.Edge_Cuts)
|
||||
# outline.SetWidth(int(0.1 * pcbnew.IU_PER_MM))
|
||||
# for point in coil_data["outline"]:
|
||||
# x = point["x"] + CENTER_X
|
||||
# y = point["y"] + CENTER_Y
|
||||
# outline.Append(pcbnew.wxPointMM(x, y))
|
||||
# board.Add(outline)
|
||||
|
||||
# create the center hole
|
||||
arc = pcbnew.PCB_SHAPE(board)
|
||||
arc.SetShape(pcbnew.SHAPE_T_CIRCLE)
|
||||
arc.SetFilled(False)
|
||||
arc.SetStart(pcbnew.wxPointMM(CENTER_X, CENTER_Y))
|
||||
arc.SetEnd(pcbnew.wxPointMM(CENTER_X + stator_hole_radius, CENTER_Y))
|
||||
arc.SetCenter(pcbnew.wxPointMM(CENTER_X, CENTER_Y))
|
||||
arc.SetLayer(pcbnew.Edge_Cuts)
|
||||
arc.SetWidth(int(0.1 * pcbnew.IU_PER_MM))
|
||||
board.Add(arc)
|
||||
# pcb_group.AddItem(arc)
|
||||
# crate the edge cuts
|
||||
for edge_cut in coil_data["edgeCuts"]:
|
||||
ec = pcbnew.PCB_SHAPE(board)
|
||||
ec.SetShape(pcbnew.SHAPE_T_POLY)
|
||||
ec.SetFilled(False)
|
||||
ec.SetLayer(pcbnew.Edge_Cuts)
|
||||
ec.SetWidth(int(0.1 * pcbnew.IU_PER_MM))
|
||||
v = pcbnew.wxPoint_Vector()
|
||||
for point in edge_cut:
|
||||
x = point["x"] + CENTER_X
|
||||
y = point["y"] + CENTER_Y
|
||||
v.append(pcbnew.wxPointMM(x, y))
|
||||
ec.SetPolyPoints(v)
|
||||
board.Add(ec)
|
||||
|
||||
|
||||
CoilPlugin().register() # Instantiate and register to Pcbnew])
|
||||
|
|
|
@ -16,10 +16,14 @@ def draw_arc(start_angle, end_angle, radius, step=5):
|
|||
start_angle, end_angle = end_angle, start_angle
|
||||
|
||||
points = []
|
||||
for angle in np.arange(start_angle, end_angle + step, step):
|
||||
for angle in np.arange(start_angle, end_angle, step):
|
||||
x = radius * np.cos(np.deg2rad(angle))
|
||||
y = radius * np.sin(np.deg2rad(angle))
|
||||
points.append((x, y))
|
||||
if angle != end_angle:
|
||||
x = radius * np.cos(np.deg2rad(end_angle))
|
||||
y = radius * np.sin(np.deg2rad(end_angle))
|
||||
points.append((x, y))
|
||||
return points
|
||||
|
||||
|
||||
|
|
42
pcb_json.py
42
pcb_json.py
|
@ -58,8 +58,6 @@ def create_track_json(points):
|
|||
|
||||
def dump_json(
|
||||
filename,
|
||||
stator_radius,
|
||||
stator_hole_radius,
|
||||
track_width,
|
||||
pin_diam,
|
||||
pin_drill,
|
||||
|
@ -74,13 +72,12 @@ def dump_json(
|
|||
tracks_in2,
|
||||
tracks_b,
|
||||
mounting_holes,
|
||||
edge_cuts
|
||||
):
|
||||
# dump out the results to json
|
||||
json_result = {
|
||||
"parameters": {
|
||||
"trackWidth": track_width,
|
||||
"statorHoleRadius": stator_hole_radius,
|
||||
"statorRadius": stator_radius,
|
||||
"viaDiameter": via_diam,
|
||||
"viaDrillDiameter": via_drill,
|
||||
"pinDiameter": pin_diam,
|
||||
|
@ -97,14 +94,13 @@ def dump_json(
|
|||
"b": [create_track_json(points) for points in tracks_b],
|
||||
},
|
||||
"mountingHoles": mounting_holes,
|
||||
"edgeCuts": [create_track_json(points) for points in edge_cuts],
|
||||
}
|
||||
json.dump(json_result, open(filename, "w"))
|
||||
return json_result
|
||||
|
||||
|
||||
def plot_json(json_result):
|
||||
stator_radius = json_result["parameters"]["statorRadius"]
|
||||
stator_hole_radius = json_result["parameters"]["statorHoleRadius"]
|
||||
pin_diam = json_result["parameters"]["pinDiameter"]
|
||||
pin_drill = json_result["parameters"]["pinDrillDiameter"]
|
||||
# track_width = json_result["parameters"]["trackWidth"]
|
||||
|
@ -123,14 +119,9 @@ def plot_json(json_result):
|
|||
ax = df.plot.line(x="x", y="y", color="red", ax=ax)
|
||||
ax.axis("equal")
|
||||
|
||||
# hide the legend
|
||||
ax.legend().set_visible(False)
|
||||
# make the plot bigger
|
||||
ax.figure.set_size_inches(11, 11)
|
||||
|
||||
# set the axis range
|
||||
ax.set_xlim(-stator_radius - 1, stator_radius + 1)
|
||||
ax.set_ylim(-stator_radius - 1, stator_radius + 1)
|
||||
ax.set_xlim(-30, 30)
|
||||
ax.set_ylim(-30, 30)
|
||||
|
||||
# plot the pads
|
||||
for pad in json_result["pads"]:
|
||||
|
@ -214,21 +205,14 @@ def plot_json(json_result):
|
|||
)
|
||||
|
||||
# plot the edge cuts
|
||||
ax.add_patch(
|
||||
plt.Circle(
|
||||
(0, 0),
|
||||
radius=stator_radius,
|
||||
fill=False,
|
||||
color="orange",
|
||||
)
|
||||
)
|
||||
ax.add_patch(
|
||||
plt.Circle(
|
||||
(0, 0),
|
||||
radius=stator_hole_radius,
|
||||
fill=False,
|
||||
color="orange",
|
||||
)
|
||||
)
|
||||
for edge_cut in json_result["edgeCuts"]:
|
||||
df = pd.DataFrame(edge_cut, columns=["x", "y"])
|
||||
ax = df.plot.line(x="x", y="y", color="orange", ax=ax)
|
||||
|
||||
# hide the legend
|
||||
ax.legend().set_visible(False)
|
||||
# make the plot bigger
|
||||
ax.figure.set_size_inches(11, 11)
|
||||
|
||||
# save to file
|
||||
ax.figure.savefig("coils.png")
|
||||
|
|
Loading…
Reference in a new issue