Skip to content

Commit d91ed40

Browse files
authored
Merge pull request #15 from dzimmanck/feature/change_to_mm
Feature/change to mm
2 parents 5cd7a0e + a9b4a16 commit d91ed40

File tree

11 files changed

+179
-235
lines changed

11 files changed

+179
-235
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
### Added
1313

14-
-Minor code cleanups
14+
## [v0.1.4]
15+
16+
### Fixed
17+
18+
### Added
19+
-Change convention to assume dimensions are specified in mm rather than m
20+
-Add support for coreloss calculations
21+
-Add support for more complex CAD part generation for cores
22+
-Minor code cleanups and API changes
23+
-Some documentation cleanup
24+
-Change the estimate_est method to be inherited from a base Winding class and to use materials
1525

1626
## [v0.1.3]
1727

planar_magnetics/cores/cores.py

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ def calculate_core_extension(area: float, radius: float, opening_width: float) -
5353

5454

5555
class Core:
56+
"""A magnetic core object
57+
58+
Args:
59+
centerpost_radius: The centerpost radius in mm
60+
window_width: The winding window width in mm
61+
window_height: The winding window height in mm
62+
opening_width: The core termination opening widths in mm
63+
gap: The core cap in mm
64+
65+
Attributes:
66+
centerpost_area: The area of the centerpost in square mm
67+
volume: The core volume in cubic mm
68+
"""
69+
5670
def __init__(
5771
self,
5872
centerpost_radius: float,
@@ -108,6 +122,9 @@ def get_coreloss(
108122
"""Calculate the coreloss using steinmetz parameters
109123
"""
110124

125+
# This is not tested, so raise error
126+
raise NotImplementedError
127+
111128
k, alpha, beta = ferrite.get_steinmetz_parameters(temperature)
112129

113130
Pv = k * f ** alpha * B ** beta
@@ -117,7 +134,7 @@ def get_coreloss(
117134
def to_parts(
118135
self,
119136
freecad_path: str = "C:/Program Files/FreeCAD 0.19/bin",
120-
tol: float = 0.1e-3,
137+
tol: float = 0.1,
121138
spacer_thickness: float = 0.0,
122139
):
123140

@@ -132,97 +149,82 @@ def to_parts(
132149
import Part
133150

134151
# create the center piece
135-
circle = Part.makeCircle(1e3 * self.centerpost_radius)
152+
circle = Part.makeCircle(self.centerpost_radius)
136153
wire = Part.Wire(circle)
137154
disk = Part.Face(wire)
138-
centerpost = disk.extrude(cad.Vector(0, 0, 1e3 * self.window_height / 2))
155+
centerpost = disk.extrude(cad.Vector(0, 0, self.window_height / 2))
139156
to_gap = self.centerpost_radius + self.window_width / 2 - self.gap / 2
140-
circle = Part.makeCircle(
141-
1e3 * to_gap, cad.Vector(0, 0, 1e3 * self.window_height / 2)
142-
)
157+
circle = Part.makeCircle(to_gap, cad.Vector(0, 0, self.window_height / 2))
143158
wire = Part.Wire(circle)
144159
disk = Part.Face(wire)
145-
topplate = disk.extrude(cad.Vector(0, 0, 1e3 * self.plate_thickness))
160+
topplate = disk.extrude(cad.Vector(0, 0, self.plate_thickness))
146161
centerpiece = centerpost.fuse(topplate)
147162

148163
# create the top plate
149164
square = Part.makePlane(
150-
1e3 * self.width,
151-
1e3 * self.width,
152-
cad.Vector(
153-
-1e3 * self.width / 2,
154-
-1e3 * self.width / 2,
155-
1e3 * self.window_height / 2,
156-
),
165+
self.width,
166+
self.width,
167+
cad.Vector(-self.width / 2, -self.width / 2, self.window_height / 2,),
157168
)
158169
circle = Part.makeCircle(
159-
1e3 * (to_gap + self.gap), cad.Vector(0, 0, 1e3 * self.window_height / 2)
170+
to_gap + self.gap, cad.Vector(0, 0, self.window_height / 2)
160171
)
161172
wire = Part.Wire(circle)
162173
disk = Part.Face(wire)
163174
topplate_face = square.cut(disk)
164-
topplate = topplate_face.extrude(cad.Vector(0, 0, 1e3 * self.plate_thickness))
175+
topplate = topplate_face.extrude(cad.Vector(0, 0, self.plate_thickness))
165176

166177
# create the legs
167178
opening_left_to_right = Part.makePlane(
168-
1e3 * self.width,
169-
1e3 * self.opening_width,
179+
self.width,
180+
self.opening_width,
170181
cad.Vector(
171-
-1e3 * self.width / 2,
172-
-1e3 * self.opening_width / 2,
173-
1e3 * self.window_height / 2,
182+
-self.width / 2, -self.opening_width / 2, self.window_height / 2,
174183
),
175184
)
176185
opening_front_to_back = Part.makePlane(
177-
1e3 * self.opening_width,
178-
1e3 * self.width,
186+
self.opening_width,
187+
self.width,
179188
cad.Vector(
180-
-1e3 * self.opening_width / 2,
181-
-1e3 * self.width / 2,
182-
1e3 * self.window_height / 2,
189+
-self.opening_width / 2, -self.width / 2, self.window_height / 2,
183190
),
184191
)
185192
circle = Part.makeCircle(
186-
1e3 * self.outerpost_radius, cad.Vector(0, 0, 1e3 * self.window_height / 2),
193+
self.outerpost_radius, cad.Vector(0, 0, self.window_height / 2),
187194
)
188195
wire = Part.Wire(circle)
189196
disk = Part.Face(wire)
190197
leg_face = square.cut(disk)
191198
legs_face = leg_face.cut(opening_left_to_right)
192199
legs_face = legs_face.cut(opening_front_to_back)
193-
legs = legs_face.extrude(cad.Vector(0, 0, -1e3 * self.window_height / 2))
200+
legs = legs_face.extrude(cad.Vector(0, 0, -self.window_height / 2))
194201

195202
# fuse the legs to the top plate
196203
topplate = topplate.fuse(legs)
197204

198205
# create the spacer
199206
circle = Part.makeCircle(
200-
1e3 * (self.outerpost_radius - tol),
201-
cad.Vector(0, 0, 1e3 * self.window_height / 2),
207+
self.outerpost_radius - tol, cad.Vector(0, 0, self.window_height / 2),
202208
)
203209
wire = Part.Wire(circle)
204210
disk = Part.Face(wire)
205211
circle = Part.makeCircle(
206-
1e3 * (self.centerpost_radius + tol),
207-
cad.Vector(0, 0, 1e3 * self.window_height / 2),
212+
self.centerpost_radius + tol, cad.Vector(0, 0, self.window_height / 2),
208213
)
209214
wire = Part.Wire(circle)
210215
cutout = Part.Face(wire)
211216
washer = disk.cut(cutout)
212-
spacer = washer.extrude(cad.Vector(0, 0, -1e3 * spacer_thickness))
217+
spacer = washer.extrude(cad.Vector(0, 0, -spacer_thickness))
213218
circle = Part.makeCircle(
214-
1e3 * (to_gap + self.gap - tol),
215-
cad.Vector(0, 0, 1e3 * self.window_height / 2),
219+
to_gap + self.gap - tol, cad.Vector(0, 0, self.window_height / 2),
216220
)
217221
wire = Part.Wire(circle)
218222
disk = Part.Face(wire)
219-
circle = Part.makeCircle(
220-
1e3 * (to_gap + tol), cad.Vector(0, 0, 1e3 * self.window_height / 2)
221-
)
223+
circle = Part.makeCircle(to_gap + tol, cad.Vector(0, 0, self.window_height / 2))
222224
wire = Part.Wire(circle)
223225
cutout = Part.Face(wire)
224226
washer = disk.cut(cutout)
225-
gap_spacer = washer.extrude(cad.Vector(0, 0, 1e3 * self.plate_thickness))
227+
gap_spacer = washer.extrude(cad.Vector(0, 0, self.plate_thickness))
226228
spacer = spacer.fuse(gap_spacer)
227229

228230
if not self.gap:
@@ -275,9 +277,7 @@ def to_step(
275277
# # bottom_half = top_half.mirror(cad.Vector(0, 0, 0), cad.Vector(0, 0, -1))
276278
part.exportStep(filename)
277279

278-
def create_pcb_cutouts(
279-
self, center: Point = Point(0, 0), clearance: float = 0.5e-3
280-
):
280+
def create_pcb_cutouts(self, center: Point = Point(0, 0), clearance: float = 0.5):
281281
"""Generate cutout polygons"""
282282

283283
# calculate the radius of the outer post cutouts
@@ -295,7 +295,7 @@ def create_pcb_cutouts(
295295
centerpost = Polygon(
296296
[Arc(center, self.centerpost_radius + clearance, -math.pi, math.pi)],
297297
"Edge.Cuts",
298-
0.1e-3,
298+
0.1,
299299
"none",
300300
)
301301

@@ -308,31 +308,31 @@ def create_pcb_cutouts(
308308
corner1 = arc.end + Point(0, cutout_extension)
309309
corner3 = arc.start + Point(cutout_extension, 0)
310310
corner2 = Point(corner3.x, corner1.y)
311-
leg1 = Polygon([arc, corner1, corner2, corner3], "Edge.Cuts", 0.1e-3, "none")
311+
leg1 = Polygon([arc, corner1, corner2, corner3], "Edge.Cuts", 0.1, "none")
312312

313313
start_angle += math.pi / 2
314314
end_angle += math.pi / 2
315315
arc = Arc(center, outer_cutout_radius, start_angle, end_angle)
316316
corner1 = arc.end + Point(-cutout_extension, 0)
317317
corner3 = arc.start + Point(0, cutout_extension)
318318
corner2 = Point(corner1.x, corner3.y)
319-
leg2 = Polygon([arc, corner1, corner2, corner3], "Edge.Cuts", 0.1e-3, "none")
319+
leg2 = Polygon([arc, corner1, corner2, corner3], "Edge.Cuts", 0.1, "none")
320320

321321
start_angle += math.pi / 2
322322
end_angle += math.pi / 2
323323
arc = Arc(center, outer_cutout_radius, start_angle, end_angle)
324324
corner1 = arc.end + Point(0, -cutout_extension)
325325
corner3 = arc.start + Point(-cutout_extension, 0)
326326
corner2 = Point(corner3.x, corner1.y)
327-
leg3 = Polygon([arc, corner1, corner2, corner3], "Edge.Cuts", 0.1e-3, "none")
327+
leg3 = Polygon([arc, corner1, corner2, corner3], "Edge.Cuts", 0.1, "none")
328328

329329
start_angle += math.pi / 2
330330
end_angle += math.pi / 2
331331
arc = Arc(center, outer_cutout_radius, start_angle, end_angle)
332332
corner1 = arc.end + Point(cutout_extension, 0)
333333
corner3 = arc.start + Point(0, -cutout_extension)
334334
corner2 = Point(corner1.x, corner2.y)
335-
leg4 = Polygon([arc, corner1, corner2, corner3], "Edge.Cuts", 0.1e-3, "none")
335+
leg4 = Polygon([arc, corner1, corner2, corner3], "Edge.Cuts", 0.1, "none")
336336

337337
cutouts = [centerpost, leg1, leg2, leg3, leg4]
338338

@@ -341,5 +341,5 @@ def create_pcb_cutouts(
341341

342342
if __name__ == "__main__":
343343

344-
core = Core(8.6e-3, 6e-3, 6e-3, 3e-3, 0.5e-3)
344+
core = Core(8.6, 6, 6, 3, 0.5)
345345
core.to_step("core.step")

planar_magnetics/creepage.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,25 @@ def description(self):
3333

3434
# Creepage table
3535
CREEPAGE_TABLE = {
36-
15: [0.05e-3, 0.1e-3, 0.1e-3, 0.05e-3, 0.13e-3, 0.13e-3, 0.13e-3],
37-
30: [0.05e-3, 0.1e-3, 0.1e-3, 0.05e-3, 0.13e-3, 0.25e-3, 0.13e-3],
38-
50: [0.1e-3, 0.6e-3, 0.6e-3, 0.13e-3, 0.13e-3, 0.4e-3, 0.13e-3],
39-
100: [0.1e-3, 0.6e-3, 1.5e-3, 0.13e-3, 0.13e-3, 0.5e-3, 0.13e-3],
40-
150: [0.2e-3, 0.6e-3, 3.2e-3, 0.4e-3, 0.4e-3, 0.8e-3, 0.4e-3],
41-
170: [0.2e-3, 1.25e-3, 3.2e-3, 0.4e-3, 0.4e-3, 0.8e-3, 0.4e-3],
42-
250: [0.2e-3, 1.25e-3, 6.4e-3, 0.4e-3, 0.4e-3, 0.8e-3, 0.4e-3],
43-
300: [0.2e-3, 1.25e-3, 12.5e-3, 0.4e-3, 0.4e-3, 0.8e-3, 0.4e-3],
44-
500: [0.25e-3, 2.5e-3, 12.5e-3, 0.8e-3, 0.8e-3, 1.5e-3, 0.8e-3],
36+
15: [0.05, 0.1, 0.1, 0.05, 0.13, 0.13, 0.13],
37+
30: [0.05, 0.1, 0.1, 0.05, 0.13, 0.25, 0.13],
38+
50: [0.1, 0.6, 0.6, 0.13, 0.13, 0.4, 0.13],
39+
100: [0.1, 0.6, 1.5, 0.13, 0.13, 0.5, 0.13],
40+
150: [0.2, 0.6, 3.2, 0.4, 0.4, 0.8, 0.4],
41+
170: [0.2, 1.25, 3.2, 0.4, 0.4, 0.8, 0.4],
42+
250: [0.2, 1.25, 6.4, 0.4, 0.4, 0.8, 0.4],
43+
300: [0.2, 1.25, 12.5, 0.4, 0.4, 0.8, 0.4],
44+
500: [0.25, 2.5, 12.5, 0.8, 0.8, 1.5, 0.8],
4545
}
4646

4747
PER_VOLT_TABLE = [
48-
0.0025e-3,
49-
0.005e-3,
50-
0.025e-3,
51-
0.00305e-3,
52-
0.00305e-3,
53-
0.00305e-3,
54-
0.00305e-3,
48+
0.0025,
49+
0.005,
50+
0.025,
51+
0.00305,
52+
0.00305,
53+
0.00305,
54+
0.00305,
5555
]
5656

5757

planar_magnetics/geometry.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Point:
4040
y: float
4141

4242
def __str__(self):
43-
return f"{self.x*1e3} {self.y*1e3}"
43+
return f"{self.x} {self.y}"
4444

4545
def __add__(self, other: Point) -> Point:
4646
return Point(self.x + other.x, self.y + other.y)
@@ -264,36 +264,15 @@ def to_wire(
264264
# first covert the polygon into a simple path of points
265265
points = self.to_pwl_path()
266266

267-
verts = [cad.Vector(1e3 * p[0], 1e3 * p[1], z) for p in points]
267+
verts = [cad.Vector(p[0], p[1], z) for p in points]
268268

269269
if closed:
270270
if verts[0] != verts[-1]:
271271
verts.append(verts[0])
272272

273273
return Part.makePolygon(verts)
274274

275-
# # convert the path into a list of line segments
276-
# segments = [
277-
# Part.LineSegment(
278-
# cad.Vector(1e3 * a[0], 1e3 * a[1], z),
279-
# cad.Vector(1e3 * b[0], 1e3 * b[1], z),
280-
# )
281-
# for a, b in zip(points[:-1], points[1:])
282-
# ]
283-
284-
# # if points[0] != points[-1]:
285-
# # segments.append(
286-
# # Part.LineSegment(
287-
# # cad.Vector(1e3 * points[-1][0], 1e3 * points[-1][1], z),
288-
# # cad.Vector(1e3 * points[0][0], 1e3 * points[0][1], z),
289-
# # )
290-
# # )
291-
292-
# shapes = [segment.toShape() for segment in segments]
293-
294-
# return Part.Wire(shapes, closed=True)
295-
296-
def export_to_dxf(
275+
def to_dxf(
297276
self,
298277
filename: Union[str, Path],
299278
version: str = "R2000",

0 commit comments

Comments
 (0)