TinySpHEAR_common.scad 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. //
  2. // Spherical Harmonics Ear Project (*SpHEAR)
  3. //
  4. // TinySpHEAR, First Order (B-format) Ambisonics Microphone
  5. // Common Modules and Variables
  6. //
  7. // Copyright 2015-2019, Fernando Lopez-Lezcano, All Rights Reserved
  8. // nando@ccrma.stanford.edu
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. // 3d Models released under the Creative Commons license as follows:
  24. // Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
  25. // http://creativecommons.org/licenses/by-nc-sa/4.0/
  26. // https://en.wikipedia.org/wiki/Tetrahedron
  27. // angle of capsule to vertical axis = atan(sqrt(2)) = 54.7356103172
  28. ////
  29. //// default model parameters
  30. ////
  31. // height and eccentricity of top connector
  32. mount_top_height = 15.0;
  33. mount_top_eccentricity = 1.3;
  34. // microphone stand mount
  35. //
  36. // diameter of existing shielded wires (x 4)
  37. mic_wire_diam = 1.5;
  38. mic_wire_hole_radius = 3.0;
  39. mic_wire_hole_offset = 5;
  40. // standard microphone stand
  41. // measured diameter = 13.5, inside diameter of sleeve = 13.79 (
  42. mic_mount_radius = 13.50 / 2;
  43. // add this to inside diameter
  44. mic_mount_fit = 0.2;
  45. mic_mount_slot_height = 11.5;
  46. mic_mount_slot_width = 4.25;
  47. mic_mount_slot_radius = 6.25 / 2;
  48. mic_mount_wall = 1.5;
  49. mic_mount_height = 20.0 + mic_wire_hole_offset + mic_wire_hole_radius + 2 * mic_mount_wall;
  50. // back (leads) and front (components) clearance of pcb
  51. pcb_front = pcb_version == 2 ? 10.00 : 13.25;
  52. pcb_back = pcb_version == 2 ? 2.0 : 3.0;
  53. // calculated minimum "radius" of microphone box
  54. box_radius = pcb_front + (pcb_thickness + pcb_tfit) + pcb_back + (pcb_version == 2 ? 1 : 2) * wall;
  55. // calculated main body corner radius
  56. mount_corner = box_radius - pcb_width / 2 + pcb_slot_depth + (pcb_version == 2 ? 1 : 4);
  57. // calculated radius at the corners
  58. box_corner_radius = (box_radius + wall - mount_corner) / sin(45) + mount_corner;
  59. // windscreen thread radius (for version 1 of microphone)
  60. windscreen_thread_radius = box_corner_radius + windscreen_thread_depth;
  61. //// end of model parameters
  62. ////
  63. //// rendering control
  64. // what type of connection to use between capsule holders:
  65. // 0 -> original cylindrical angled legs
  66. // 1 -> interlocking horizontal legs
  67. // 2 -> interlocking vertical legs
  68. connect = 1;
  69. // how many mount ridges to create
  70. // 0 -> no ridges
  71. // 1 -> 1 ridge
  72. // 2 -> 2 ridges
  73. ridges = 1;
  74. //// end of rendering control
  75. ////
  76. // elevation angle for the capsule holders (fixed for this microphone)
  77. elev_angle = atan(sqrt(1/2));
  78. // angles of the connection legs and adjacent capsule holders
  79. leg_angles_top =
  80. [
  81. [-120, elev_angle],
  82. [0, elev_angle],
  83. [120, elev_angle]
  84. ];
  85. leg_angles_bot =
  86. [
  87. [-120, elev_angle],
  88. [120, elev_angle]
  89. ];
  90. // adjustment for the inner radius of the capsule holder
  91. // measured inside diameter of a trial print was around 7.5 to 8.2
  92. // instead of 10, capsule diameter was 9.99)
  93. fudge = 0.12;
  94. // adjustment for fit of slots in connection legs and mount
  95. // 0.1: initial setting
  96. // 0.1 ->0.15: Ultimaker 2 + Extended plus APL (2016.06.17)
  97. fit = 0.15;
  98. // microphone structure geometry
  99. capsule_sep_min = (mic_radius - capsule_height) * cos(elev_angle) - (capsule_radius + wall) * sin(elev_angle);
  100. capsule_sep_max = mic_radius * cos(elev_angle) - (capsule_radius + wall) * sin(elev_angle);
  101. capsule_bottom = mic_radius * sin(elev_angle) + (capsule_radius + wall) * cos(elev_angle);
  102. mount_radius_capsule = capsule_sep_max;
  103. // simple microphone mount, clips into standard microphone stand
  104. //
  105. // angles: angles for mount slots
  106. // wall: thickness of cylinder wall
  107. // stand_wall: thickness of stand mount wall
  108. // separation: height of mount with respect of the microphone assembly (for display)
  109. module ellipsoid(height, rad_bot, rad_top, eccentricity) {
  110. linear_extrude(height = height, scale = [eccentricity, rad_top / rad_bot]) {
  111. circle(r = rad_bot, $fn = facets);
  112. }
  113. }
  114. module mount (angles, wall, stand_wall, separation) {
  115. translate([0, 0, -separation]) {
  116. difference() {
  117. union() {
  118. // conic section
  119. translate([0, 0, mic_mount_height + mount_height]) {
  120. rotate([0, 0, 45]) {
  121. difference() {
  122. ellipsoid(mount_top_height, mount_radius + wall, mount_radius_capsule, mount_top_eccentricity);
  123. ellipsoid(mount_top_height, mount_radius, mount_radius_capsule * 0.5, mount_top_eccentricity * 1.05);
  124. }
  125. }
  126. }
  127. // stalk
  128. translate([0, 0, mic_mount_height + mount_height * 2/3]) {
  129. difference() {
  130. cylinder(r = mount_radius + wall, h = mount_height / 3, $fn = facets);
  131. // make the hole for the mount
  132. cylinder(r = mount_radius, h = mount_height / 3, $fn = facets);
  133. }
  134. }
  135. // transition to stand mount
  136. translate([0, 0, mic_mount_height]) {
  137. difference() {
  138. cylinder(r2 = mount_radius + wall, r1 = mic_mount_radius + mic_mount_fit + stand_wall,
  139. h = mount_height * 2 / 3, $fn = facets);
  140. // make the hole for the mount
  141. cylinder(r2 = mount_radius, r1 = mic_mount_radius + mic_mount_fit,
  142. h = mount_height * 2 / 3, $fn = facets);
  143. }
  144. }
  145. // stand mount
  146. translate([0, 0, 0]) {
  147. difference() {
  148. union() {
  149. // main mount cylinder
  150. translate([0, 0, 0]) {
  151. difference() {
  152. cylinder(r = mic_mount_radius + mic_mount_fit + stand_wall, h = mic_mount_height, $fn = facets);
  153. // make the hole for the mount (* 1.5 to cut the ridge as well)
  154. cylinder(r = mic_mount_radius + mic_mount_fit, h = mic_mount_height, $fn = facets);
  155. }
  156. }
  157. }
  158. // slot for fitting into microphone stand
  159. translate([mic_mount_radius - stand_wall / 2, - mic_mount_slot_width / 2, 0]) {
  160. cube([2 * stand_wall, mic_mount_slot_width, mic_mount_slot_height]);
  161. }
  162. // eyelet for microphone stand
  163. translate([mic_mount_radius - stand_wall / 2, 0, mic_mount_slot_height]) {
  164. rotate([0, 90, 0]) {
  165. cylinder(r = mic_mount_slot_radius, h = 2 * stand_wall, $fn = facets);
  166. }
  167. }
  168. // hole for microphone wiring
  169. translate([mic_mount_radius - stand_wall / 2, 0, mic_mount_height - mic_wire_hole_offset]) {
  170. rotate([0, 90, 0]) {
  171. cylinder(r = mic_wire_hole_radius, h = 2 * stand_wall, $fn = facets);
  172. }
  173. }
  174. }
  175. }
  176. }
  177. // indentations that match the two lower capsule holders
  178. translate([0, 0, mic_mount_height + mount_height + mount_top_height +
  179. (mic_radius - capsule_height) + capsule_height * cos(elev_angle)]) {
  180. rotate([0, (90 + elev_angle), angles[0]]) {
  181. translate([0, 0, mic_radius - capsule_height]) {
  182. capsule([], 0, 1, ridge_wfit, ridge_hfit, 1);
  183. }
  184. }
  185. rotate([0, (90 + elev_angle), angles[1]]) {
  186. translate([0, 0, mic_radius - capsule_height]) {
  187. capsule([], 0, 1, ridge_wfit, ridge_hfit, 1);
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. // render a tetrahedral capsule array
  195. //
  196. module render_tetra_capsule_array_old(z_offset) {
  197. translate([0, 0, z_offset]) {
  198. // all four capsules
  199. rotate([0, (90 - elev_angle), 45]) {
  200. translate([0, 0, mic_radius - capsule_height]) {
  201. capsule(leg_angles_top, 60, 0, 0.0, 0.0, 0);
  202. }
  203. }
  204. rotate([0, (90 - elev_angle), -135]) {
  205. translate([0, 0, mic_radius - capsule_height]) {
  206. capsule(leg_angles_top, 60, 0, 0.0, 0.0, 0);
  207. }
  208. }
  209. rotate([0, (90 + elev_angle), -45]) {
  210. translate([0, 0, mic_radius - capsule_height]) {
  211. capsule(leg_angles_bot, 0, 1, 0.0, 0.0, 0);
  212. }
  213. }
  214. rotate([0, (90 + elev_angle), 135]) {
  215. translate([0, 0, mic_radius - capsule_height]) {
  216. capsule(leg_angles_bot, 0, 1, 0.0, 0.0, 0);
  217. }
  218. }
  219. }
  220. }
  221. module render_tetra_capsule_array(z_offset, r_offset) {
  222. translate([0, 0, z_offset]) {
  223. // all four capsules
  224. rotate([0, (90 - elev_angle), 45]) {
  225. translate([0, 0, mic_radius - capsule_height + r_offset]) {
  226. capsule(leg_angles_top, 60, 0, 0.0, 0.0, 0);
  227. }
  228. }
  229. rotate([0, (90 - elev_angle), -135]) {
  230. translate([0, 0, mic_radius - capsule_height + r_offset]) {
  231. capsule(leg_angles_top, 60, 0, 0.0, 0.0, 0);
  232. }
  233. }
  234. rotate([0, (90 + elev_angle), -45]) {
  235. translate([0, 0, mic_radius - capsule_height + r_offset]) {
  236. capsule(leg_angles_top, 0, 0, 0.0, 0.0, 0);
  237. }
  238. }
  239. rotate([0, (90 + elev_angle), 135]) {
  240. translate([0, 0, mic_radius - capsule_height + r_offset]) {
  241. capsule(leg_angles_top, 0, 0, 0.0, 0.0, 0);
  242. }
  243. }
  244. }
  245. }
  246. // render individual capsules
  247. //
  248. module render_tetra_capsule_top() {
  249. capsule(leg_angles_top, 60, 0, 0.0, 0.0, 0);
  250. }
  251. module render_tetra_capsule_bot() {
  252. capsule(leg_angles_bot, 0, 1, 0.0, 0.0, 0);
  253. }
  254. // render simple microphone stand mount
  255. //
  256. module render_simple_stand_mount(z_offset) {
  257. translate([0, 0, z_offset]) {
  258. mount([-45, 135], mount_wall, mic_mount_wall, mic_mount_height + mount_top_height + mount_height + capsule_bottom);
  259. }
  260. }
  261. // capsule holder with conical mount
  262. //
  263. // ratio of capsule radius to transition length
  264. transition_ratio = 1.0;
  265. // ratio of capsule radius to bottom radius of holder
  266. holder_ratio = 0.4;
  267. // diameter of microphone capsule cable (Mogami 2490)
  268. capsule_cable_diam = 1.7;
  269. module capsule_holder(ratio, transition, hollow = true) {
  270. capsule_h = capsule_height;
  271. difference() {
  272. // main capsule holder, use a conical bore to press fit the capsule
  273. f = 0.05;
  274. cylinder(r = capsule_radius + fudge + wall, h = capsule_h, $fn = cfacets);
  275. if (hollow) cylinder(r1 = capsule_radius + fudge - f, r2 = capsule_radius + fudge, h = capsule_h + thin_mint, $fn = cfacets);
  276. }
  277. // conical transition into core sphere
  278. transition_h = transition * capsule_radius;
  279. translate([0, 0, - transition_h]) {
  280. difference() {
  281. cylinder(r2 = capsule_radius + fudge + wall, r1 = (capsule_radius) * ratio + wall, h = transition_h, $fn = facets);
  282. // add overhang so that we have a stop when inserting the capsule
  283. overhang = 0.2;
  284. if (hollow) cylinder(r2 = capsule_radius + fudge - overhang, r1 = (capsule_radius) * ratio, h = transition_h, $fn = facets);
  285. // add holes in the walls of the conical transition
  286. if (hollow) {
  287. for (r = [0:36:179]) {
  288. rotate([0, 90, r]) {
  289. translate([-transition_h, 0, -capsule_radius - 2 * wall])
  290. scale([3.5, 1.25, 1]) cylinder(r = 1.0, h = (capsule_radius + 2 * wall) * 2, $fn = facets);
  291. }
  292. }
  293. }
  294. }
  295. // lip to insert holder into core
  296. lip_d = 1.4 * wall;
  297. translate([0, 0, hollow == false ? -3 : -lip_d]) {
  298. difference() {
  299. // if not hollow make the ring longer to cut into core
  300. // cylinder(r = (capsule_radius) * ratio + wall + (hollow == true ? 0 : fit/2),
  301. cylinder(r = (capsule_radius) * ratio + wall + (hollow == true ? 0 : 0),
  302. h = hollow == true ? lip_d : 4.0, $fn = facets);
  303. if (hollow) { cylinder(r = capsule_cable_diam/2 * 1.4, h = lip_d + thin_mint, $fn = facets); }
  304. }
  305. }
  306. }
  307. }
  308. // new stype capsule array
  309. // the spherical core and mounting stalk
  310. //
  311. // render = 0: the full sphere (for visualization)
  312. // render = 1: upper half
  313. // render = -1: lower half with stalk
  314. // thickness of ring that connects both halves of the core sphere
  315. core_ring_height = 5.0;
  316. // holes for screws that hold together both halves of the sphere
  317. module capsule_holder_screws(radius, wall, screw_r, shift = 0) {
  318. h_offset = 1.2;
  319. for (r = [90, 270]) {
  320. for (t = [0, 45]) {
  321. m = t > 0 ? 1 : 0;
  322. // 11.5 matches the angle for the flat shaves in the core
  323. mirror([0, 0, m]) rotate([0, 11.5, r + t]) translate([-(radius + 2 * wall), 0, shift]) {
  324. rotate([0, 90, 0]) {
  325. cylinder(r = screw_r, h = radius, $fn = facets);
  326. }
  327. }
  328. }
  329. }
  330. }
  331. // ring that connects the two halves of the core sphere
  332. module capsule_holder_ring(offset = 3.5, shift = 0) {
  333. s_radius = mic_radius - capsule_radius * (1 + transition_ratio) + offset;
  334. ring_h = core_ring_height - 0.2;
  335. translate([0, 0, -ring_h/2]) difference() {
  336. cylinder(r = s_radius - 2.5 * wall - fit, h = ring_h, $fn = facets);
  337. cylinder(r = s_radius - 4 * wall - fit, h = ring_h, $fn = facets);
  338. // shift the holes slightly so the two halves are pressed together
  339. translate([0, 0, ring_h/2]) capsule_holder_screws(s_radius, wall, 0.65, shift);
  340. }
  341. }
  342. // spherical core
  343. module capsule_holder_core(top_radius, render = 0, offset = 3.5) {
  344. s_radius = mic_radius - capsule_radius * (1 + transition_ratio) + offset;
  345. difference() {
  346. union() {
  347. difference() {
  348. // core
  349. sphere(r = s_radius, $fn = facets);
  350. sphere(r = s_radius - 2.5 * wall, $fn = facets);
  351. // shave sides as well (cosmetic, really)
  352. for (az = [-45, 135]) rotate([0, -elev_angle, az]) {
  353. translate([s_radius - 0.5 * wall, -s_radius/2, -s_radius/2]) {
  354. cube([s_radius, s_radius, s_radius]);
  355. }
  356. }
  357. for (az = [45, -135]) rotate([0, elev_angle, az]) {
  358. translate([s_radius - 0.5 * wall, -s_radius/2, -s_radius/2]) {
  359. cube([s_radius, s_radius, s_radius]);
  360. }
  361. }
  362. // remove one half of the sphere
  363. if (render == 1) {
  364. translate([-mic_radius, -mic_radius, -mic_radius * 2]) cube([mic_radius * 2, mic_radius * 2, mic_radius * 2]);
  365. }
  366. if (render == -1) {
  367. translate([-mic_radius, -mic_radius, 0]) cube([mic_radius * 2, mic_radius * 2, mic_radius * 2]);
  368. }
  369. // make space for connection ring
  370. ring_h = core_ring_height;
  371. translate([0, 0, -ring_h/2]) {
  372. cylinder(r = s_radius - 2.5 * wall, h = ring_h, $fn = facets);
  373. }
  374. // hole for stalk
  375. if (render == -1) {
  376. translate([0, 0, -mic_radius]) cylinder(r = mount_radius - 2*wall, h = mic_radius, $fn = facets);
  377. }
  378. }
  379. // stalk that transitions into flare
  380. if (render == -1) {
  381. //stalk_len = 15.0;
  382. // normal length plus 10 to insert into flare
  383. stalk_len = stalk_height + 10.0 + 10.0;
  384. inset = wall;
  385. translate([0, 0, - (stalk_len - inset + s_radius)]) {
  386. difference() {
  387. cylinder(r = top_radius, h = stalk_len + inset, $fn = facets);
  388. cylinder(r = top_radius - wall, h = stalk_len + inset + thin_mint, $fn = facets);
  389. }
  390. }
  391. // add flange for coupling into flare
  392. translate([0, 0, - (stalk_height - inset - 0.5 + 10.0 + 10.0)]) {
  393. difference() {
  394. cylinder(r2 = top_radius, r1 = top_radius + wall, h = 10.0, $fn = facets);
  395. cylinder(r2 = top_radius - wall, r1 = top_radius, h = 10.0, $fn = facets);
  396. }
  397. }
  398. translate([top_radius, 0, - (stalk_height - inset - 0.5 + 10.0 + 10.0 + 10.0)]) {
  399. // add key to stalk so orientation is always correct
  400. difference() {
  401. cylinder(r = 0.4, h = 10.0, $fn = facets);
  402. }
  403. }
  404. }
  405. }
  406. // make holes for capsule holders
  407. render_tetra_capsule_holder_array(false);
  408. }
  409. // index for aligning the two halves of core sphere
  410. rotate([0, 0, 0]) translate([s_radius, 0, 0]) {
  411. difference() {
  412. scale([1, 1, 2]) sphere(r = 0.5, $fn = facets);
  413. translate([-2.2, -1, -4]) cube([2, 2, 8]);
  414. if (render == 1) {
  415. translate([-2, -1, -8]) cube([4, 2, 8]);
  416. }
  417. if (render == -1) {
  418. translate([-2, -1, 0]) cube([4, 2, 8]);
  419. }
  420. }
  421. }
  422. }
  423. holder_ratio = 0.4;
  424. transition_ratio = 0.8;
  425. module render_tetra_capsule_holder_array(hollow = true) {
  426. // all four capsules
  427. rotate([0, (90 - elev_angle), 45]) {
  428. translate([0, 0, mic_radius - capsule_height]) {
  429. capsule_holder(holder_ratio, transition_ratio, hollow);
  430. }
  431. }
  432. rotate([0, (90 - elev_angle), -135]) {
  433. translate([0, 0, mic_radius - capsule_height]) {
  434. capsule_holder(holder_ratio, transition_ratio, hollow);
  435. }
  436. }
  437. rotate([0, (90 + elev_angle), -45]) {
  438. translate([0, 0, mic_radius - capsule_height]) {
  439. capsule_holder(holder_ratio, transition_ratio, hollow);
  440. }
  441. }
  442. rotate([0, (90 + elev_angle), 135]) {
  443. translate([0, 0, mic_radius - capsule_height]) {
  444. capsule_holder(holder_ratio, transition_ratio, hollow);
  445. }
  446. }
  447. }