zellhalter_v2.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import cadquery as cq
  2. from cadquery.occ_impl.exporters import ExportTypes
  3. from ocp_vscode import show, show_object
  4. ###### Parameter #####
  5. cells_per_row = 8
  6. rows = 2
  7. cell_diam = 18.44
  8. cell_length = 65
  9. dist_to_ground = 66.9
  10. space_all = 140
  11. space_single = space_all / (cells_per_row - 1)
  12. space_rows = 33.7
  13. dist_segments = 57.5
  14. strip_width = 10.4
  15. print_height = 15
  16. wall_thick = 1.7
  17. eps = 0.15
  18. hole_diam = 2.4
  19. hole_depth = 10
  20. board_connector_length = dist_to_ground + wall_thick
  21. lip_width = 1.5
  22. lip_thick = 1.5
  23. ############
  24. cell_locs = [(x * space_single, y * space_rows) for x in range(0, cells_per_row) for y in range(0, rows)]
  25. strip_locs = [(-cell_diam/4, y * space_rows) for y in range(0, rows)]
  26. connector_locs = [(x * space_single * 2, (y + 0.5) * space_rows) for x in range(0, int(cells_per_row/2)) for y in range(0, rows-1)]
  27. cell_edge = cell_diam/2 - 1.5
  28. board_con_locs_with_rot = [
  29. ((-.5 * space_single, -cell_edge), 0),
  30. ((-.5 * space_single, space_rows + cell_edge), 180),
  31. ((1.5 * space_single, space_rows - cell_edge), 0),
  32. ((5.5 * space_single, cell_edge), 180),
  33. ((5.5 * space_single, space_rows - cell_edge), 0),
  34. ]
  35. # Zellkreise
  36. cell_base = (
  37. cq.Workplane()
  38. .pushPoints(cell_locs)
  39. .eachpoint(
  40. lambda loc: (
  41. cq.Workplane()
  42. .circle(cell_diam/2 + eps + wall_thick)
  43. .extrude(print_height)
  44. .val()
  45. .located(loc)
  46. )
  47. )
  48. )
  49. # Ausschnitt für die Zellen
  50. cell_cutout = (
  51. cq.Workplane()
  52. .pushPoints(cell_locs)
  53. .eachpoint(
  54. lambda loc: (
  55. cq.Workplane()
  56. .circle(cell_diam/2 + eps)
  57. .extrude(print_height-wall_thick)
  58. .val()
  59. .located(loc)
  60. )
  61. )
  62. )
  63. # Ausschnitt für die Lötfahne
  64. strips_cut = (
  65. cq.Workplane()
  66. .pushPoints(strip_locs)
  67. .eachpoint(
  68. lambda loc: (
  69. cq.Workplane().workplane(offset=print_height-2*wall_thick)
  70. .rect(space_all + cell_diam/2+wall_thick, strip_width, centered=(False, True))
  71. .extrude(wall_thick*2)
  72. # Dreieckiger Ausschnitt für besseres bridging
  73. .faces("<Z")
  74. .workplane()
  75. .rect(space_all + cell_diam/2+wall_thick, strip_width, centered=(False, True))
  76. .workplane(offset=wall_thick*2)
  77. .rect(space_all + cell_diam/2+wall_thick, eps, centered=(False, True))
  78. .loft()
  79. .val()
  80. .located(loc)
  81. )
  82. )
  83. )
  84. strips_wall = (
  85. cq.Workplane()
  86. .pushPoints(strip_locs)
  87. .eachpoint(
  88. lambda loc: (
  89. cq.Workplane()
  90. .rect(space_all+ 2*wall_thick, strip_width + 2*wall_thick, centered=(False, True))
  91. .extrude(print_height)
  92. .val()
  93. .located(loc)
  94. )
  95. )
  96. )
  97. base_cutout = (
  98. cell_base.union(strips_wall)
  99. .cut(cell_cutout)
  100. .cut(strips_cut)
  101. )#.faces("<Z").chamfer(wall_thick/4)
  102. connectors = (
  103. cq.Workplane()
  104. .pushPoints(connector_locs)
  105. .eachpoint(
  106. lambda loc: (
  107. cq.Workplane().workplane(offset=wall_thick)
  108. .rect(wall_thick, space_rows - cell_diam - wall_thick, centered=(False, True))
  109. .extrude(print_height-wall_thick)
  110. .val()
  111. .located(loc)
  112. )
  113. )
  114. )
  115. base_connected = base_cutout.union(connectors)
  116. connector_width = hole_diam + wall_thick*1.5
  117. board_con = (
  118. cq.Workplane()
  119. .rect(connector_width, connector_width)
  120. .extrude(board_connector_length)
  121. .faces("+Y")
  122. .edges("|Z")
  123. .chamfer(wall_thick)
  124. .faces("<Z")
  125. .workplane()
  126. .rect(connector_width+lip_width, connector_width)
  127. .extrude(lip_width)
  128. .faces(">Z")
  129. .workplane()
  130. .circle(hole_diam/2)
  131. .cutBlind(-hole_depth)
  132. )
  133. board_con_outside = (
  134. cq.Workplane()
  135. .rect(connector_width + 2 * eps, connector_width + 2 * eps)
  136. .extrude(print_height)
  137. )
  138. board_con_hull = (
  139. cq.Workplane()
  140. .rect(connector_width + 2 * (wall_thick + eps), connector_width + 2 * (wall_thick + eps))
  141. .extrude(print_height)
  142. .edges("|Z")
  143. .chamfer(wall_thick)
  144. )
  145. con_placed = []
  146. for location, angle in board_con_locs_with_rot:
  147. # Connector nur für Visualisierung
  148. con = board_con.translate(location)
  149. con = con.rotateAboutCenter((0,0,1), angle)
  150. # Ausschnitt für den Connector
  151. chamfer_face = "-Y" if angle >= 180 else "+Y"
  152. con_outside = board_con_outside.faces(chamfer_face).edges("|Z").chamfer(wall_thick)
  153. con_outside = con_outside.translate(location)
  154. con_placed.append(con)
  155. # Verdickte Hülle für den Connector
  156. hull = board_con_hull.translate(location).cut(cell_base).cut(strips_cut)
  157. base_connected = base_connected.union(hull).cut(con_outside)
  158. # Begrenzungsbox für den gesamten Zellhalter (sonst schneidet man den nächsten Halter)
  159. boundary_box = (
  160. base_connected.workplane(centerOption="CenterOfBoundBox")
  161. .box(1000, dist_segments, 1000,combine=False)
  162. )
  163. base_connected = base_connected.intersect(boundary_box)
  164. show_object(base_connected)
  165. show_object(con_placed)
  166. with open(r"zellhalter_v2_base.step", "w") as fp:
  167. cq.exporters.exportShape(base_connected, ExportTypes.STEP, fp)
  168. with open(r"zellhalter_v2_connector.step", "w") as fp:
  169. cq.exporters.exportShape(board_con, ExportTypes.STEP, fp)