zellhalter_v2.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 = [
  29. (-.5 * space_single, -cell_edge),
  30. (-.5 * space_single, space_rows + cell_edge),
  31. (1.5 * space_single, space_rows - cell_edge),
  32. (5.5 * space_single, cell_edge),
  33. (5.5 * space_single, space_rows - cell_edge)
  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. .val()
  73. .located(loc)
  74. )
  75. )
  76. )
  77. strips_wall = (
  78. cq.Workplane()
  79. .pushPoints(strip_locs)
  80. .eachpoint(
  81. lambda loc: (
  82. cq.Workplane()
  83. .rect(space_all+ 2*wall_thick, strip_width + 2*wall_thick, centered=(False, True))
  84. .extrude(print_height)
  85. .val()
  86. .located(loc)
  87. )
  88. )
  89. )
  90. base_cutout = (
  91. cell_base.union(strips_wall)
  92. .cut(cell_cutout)
  93. .cut(strips_cut)
  94. )#.faces("<Z").chamfer(wall_thick/4)
  95. connectors = (
  96. cq.Workplane()
  97. .pushPoints(connector_locs)
  98. .eachpoint(
  99. lambda loc: (
  100. cq.Workplane().workplane(offset=wall_thick)
  101. .rect(wall_thick, space_rows - cell_diam - wall_thick, centered=(False, True))
  102. .extrude(print_height-wall_thick)
  103. .val()
  104. .located(loc)
  105. )
  106. )
  107. )
  108. base_connected = base_cutout.union(connectors)
  109. connector_width = hole_diam + wall_thick*1.5
  110. board_con = (
  111. cq.Workplane()
  112. .rect(connector_width, connector_width)
  113. .extrude(board_connector_length)
  114. .faces("<Z")
  115. .workplane()
  116. .rect(connector_width+lip_width, connector_width+lip_width)
  117. .extrude(lip_width)
  118. .edges("|Z")
  119. .chamfer(wall_thick)
  120. .faces(">Z")
  121. .workplane()
  122. .circle(hole_diam/2)
  123. .cutBlind(-hole_depth)
  124. )
  125. board_con_outside = (
  126. cq.Workplane()
  127. .rect(connector_width + eps, connector_width + eps)
  128. .extrude(print_height)
  129. .edges("|Z")
  130. .chamfer(wall_thick)
  131. )
  132. board_con_hull = (
  133. cq.Workplane()
  134. .rect(connector_width + 2 * (wall_thick + eps), connector_width + 2 * (wall_thick + eps))
  135. .extrude(print_height)
  136. .edges("|Z")
  137. .chamfer(wall_thick)
  138. )
  139. con_placed = []
  140. for loc in board_con_locs:
  141. con = board_con.translate(loc)
  142. con_outside = board_con_outside.translate(loc)
  143. con_placed.append(con)
  144. hull = board_con_hull.translate(loc).cut(cell_base).cut(strips_cut)
  145. base_connected = base_connected.union(hull).cut(con_outside)
  146. boundary_box = (
  147. base_connected.workplane(centerOption="CenterOfBoundBox")
  148. .box(1000, dist_segments, 1000,combine=False)
  149. )
  150. base_connected = base_connected.intersect(boundary_box)
  151. show_object(base_connected)
  152. show_object(con_placed)
  153. with open(r"zellhalter_v2_base.step", "w") as fp:
  154. cq.exporters.exportShape(base_connected, ExportTypes.STEP, fp)
  155. with open(r"zellhalter_v2_connector.step", "w") as fp:
  156. cq.exporters.exportShape(board_con, ExportTypes.STEP, fp)