TinySpHEAR_common.scad 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. //
  2. // TinySpHEAR, Tiny Spherical Harmonics Ear,
  3. // First Order (B-format) Ambisonics Microphone Common Modules and Variables
  4. //
  5. // Copyright 2015-2016, Fernando Lopez-Lezcano, All Rights Reserved
  6. // nando@ccrma.stanford.edu
  7. //
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation, either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. //
  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. //// model parameters
  30. // dimensions of the electret microphone capsule
  31. capsule_radius = 5;
  32. capsule_height = 4.5;
  33. // distance between the face of a capsule and the center of array
  34. //
  35. // for a 10mm capsule: with vertical legs -> 10.5mm min radius
  36. // with horizontal legs -> 10mm min radius
  37. mic_radius = 9.6;
  38. // dimensions of the capsule holder connection legs
  39. // a width of 4mm is too thin, 5mm prints better
  40. leg_width = 5;
  41. leg_thick = 1.75;
  42. // wall thickness of the capsule holder
  43. wall = 1;
  44. // width of the ridge that connects to the mount
  45. // measured: ridge = 2.20mm, slot = 2.0 .. 2.35mm
  46. ridge_width = 2.0;
  47. ridge_slot_width = 2.0;
  48. // add to the thickness of ridges
  49. ridge_fit = 0.1;
  50. // dimensions of microphone mount
  51. mount_radius = 3.5;
  52. mount_wall = 0.75;
  53. // height and eccentricity of top connector
  54. mount_top_height = 15.0;
  55. mount_top_eccentricity = 1.3;
  56. // height of mount
  57. mount_height = 40;
  58. // microphone stand mount
  59. //
  60. // diameter of existing shielded wires (x 4)
  61. mic_wire_diam = 1.5;
  62. mic_wire_hole_radius = 3.0;
  63. mic_wire_hole_offset = 5;
  64. // standard microphone stand
  65. // measured diameter = 13.5, inside diameter of sleeve = 13.79 (
  66. mic_mount_radius = 13.50 / 2;
  67. // add this to inside diameter
  68. mic_mount_fit = 0.1;
  69. mic_mount_slot_height = 11.5;
  70. mic_mount_slot_width = 4.25;
  71. mic_mount_slot_radius = 6.25 / 2;
  72. mic_mount_wall = 1.5;
  73. mic_mount_height = 35.0 + mic_wire_hole_offset + mic_wire_hole_radius + 2 * mic_mount_wall;
  74. //// end of model parameters
  75. ////
  76. //// rendering control
  77. // what to render:
  78. // 0 -> ready to print
  79. // set = 0 -> one capsule, set = 1 -> four capsules
  80. // 1 -> the whole microhone with four capsules
  81. rendermic = 0;
  82. renderset = 1;
  83. // what type of connection to use between capsule holders:
  84. // 0 -> original cylindrical angled legs
  85. // 1 -> interlocking horizontal legs
  86. // 2 -> interlocking vertical legs
  87. connect = 1;
  88. // how many mount ridges to create
  89. // 0 -> no ridges
  90. // 1 -> 1 ridge
  91. // 2 -> 2 ridges
  92. ridges = 1;
  93. //// end of rendering control
  94. ////
  95. // elevation angle for the capsule holders (fixed for this microphone)
  96. elev_angle = atan(sqrt(1/2));
  97. // angles of the connection legs and adjacent capsule holders
  98. leg_angles_top =
  99. [
  100. [-120, elev_angle],
  101. [0, elev_angle],
  102. [120, elev_angle]
  103. ];
  104. leg_angles_bot =
  105. [
  106. [-120, elev_angle],
  107. [120, elev_angle]
  108. ];
  109. // adjustment for the inner radius of the capsule holder
  110. // measured inside diameter of a trial print was around 7.5 to 8.2
  111. // instead of 10, capsule diameter was 9.99)
  112. fudge = 0.15;
  113. // adjustment for fit of slots in connection legs and mount
  114. // 0.1: initial setting
  115. // 0.1 ->0.2: Ultimaker 2 + Extended plus APL (2016.06.10)
  116. fit = 0.2;
  117. // number of facets for rendering cylinders
  118. facets = 64;
  119. // microphone structure geometry
  120. capsule_sep_min = (mic_radius - capsule_height) * cos(elev_angle) - (capsule_radius + wall) * sin(elev_angle);
  121. capsule_sep_max = mic_radius * cos(elev_angle) - (capsule_radius + wall) * sin(elev_angle);
  122. capsule_bottom = mic_radius * sin(elev_angle) + (capsule_radius + wall) * cos(elev_angle);
  123. mount_radius_capsule = capsule_sep_max;
  124. ////////
  125. // microphone capsule holder
  126. // azimuth: horizontal orientation of the capsule
  127. // elevation: vertical orientation of the capsule
  128. // mounts: vectors containing the angle of the mount and the angle to the adjacent capsule
  129. // twist: rotate the whole capsule to match mounting legs
  130. // ridge: add 0, 1 or 2 ridges for attaching the structure to the mount
  131. // ridge_fit: tune the fit, used for carving slots in mount
  132. // solid: make the capsule holder solid, used in the mount code to carve the capsule rests
  133. // rfit: adjust height of ridges when carving out the capsule rests
  134. module capsule (azimuth, elevation, mounts, twist, ridge, ridge_fit = 0.0, solid = 0, rfit = 0) {
  135. rotate([0, 0, azimuth]) {
  136. rotate([0, (90 - elevation), 0]) {
  137. translate([0, 0, (rendermic == 0 && solid == 0) ? 0 : mic_radius - capsule_height]) {
  138. difference () {
  139. union () {
  140. // main capsule holder
  141. cylinder(r = capsule_radius + wall, h = capsule_height, $fn = facets);
  142. // the mounting legs
  143. for (angles = mounts) {
  144. rotate([0, 0, angles[0] + twist]) {
  145. // connect with cylindrical beams, very pretty
  146. if (connect == 0) {
  147. leg_length = mic_radius * cos(angles[1]) - capsule_radius * sin(angles[1]);
  148. translate([capsule_radius - wall, 0, capsule_height - wall]) {
  149. rotate([0, 180 - angles[1], 0]) {
  150. cylinder(d = leg_width, h = leg_length - 0.3, center = false, $fn = facets);
  151. }
  152. }
  153. }
  154. // connect with horizontal legs
  155. if (connect == 1) {
  156. leg_length = (mic_radius - capsule_height + leg_thick) * tan(90 - angles[1]) - capsule_radius;
  157. slot_depth = leg_thick * cos(90 - 2 * angles[1]) + wall + fit;
  158. translate([capsule_radius + leg_length + fudge, - leg_width / 3, 0]) {
  159. rotate([0, -90, 0]) {
  160. difference() {
  161. // thickness, width
  162. cube([leg_thick, leg_width, leg_length]);
  163. // cut slot in connector
  164. translate([0, leg_width / 3 - (fit / 2), 0]) {
  165. cube([leg_thick, leg_width / 3 + fit, slot_depth]);
  166. }
  167. }
  168. }
  169. }
  170. }
  171. // connect with vertical legs
  172. if (connect == 2) {
  173. // fix this 0.2 == (2 * fudge?)
  174. leg_length = (mic_radius * tan(90 - angles[1]) - capsule_radius) * tan(angles[1]) - 0.2;
  175. slot_depth = leg_thick * cos (90 - (2 * angles[1]));
  176. translate([capsule_radius - leg_thick / 2 + fudge, - leg_width / 3,
  177. - leg_length + capsule_height]) {
  178. difference() {
  179. // the connection
  180. difference() {
  181. cube([leg_thick + leg_thick / 2, leg_width, leg_length]);
  182. translate([-leg_thick + wall - fudge, 0, - capsule_height + fudge]) {
  183. cube([leg_thick, leg_width, leg_length]);
  184. }
  185. }
  186. // cut slot in connector
  187. translate([0, leg_width / 3 - (fit / 2), 0]) {
  188. cube([leg_thick + leg_thick / 2, leg_width / 3 + fit, slot_depth]);
  189. }
  190. }
  191. }
  192. }
  193. }
  194. }
  195. // add ridges for microphone mount
  196. ridge_length = (mic_radius - capsule_height) / tan(elev_angle) - (capsule_radius + wall);
  197. if (ridge == 2) {
  198. rotate([0, 0, twist]) {
  199. translate([capsule_radius + wall - ridge_length / 2, (ridge_width - ridge_fit) / 2, 0]) {
  200. cube([ridge_length * 3 / 2, ridge_width - ridge_fit, capsule_height + rfit], center = false);
  201. }
  202. translate([capsule_radius + wall - ridge_length / 2, - (ridge_width - ridge_fit) * 3 / 2, 0]) {
  203. cube([ridge_length * 3 / 2, ridge_width - ridge_fit, capsule_height + rfit], center = false);
  204. }
  205. }
  206. }
  207. if (ridge == 1) {
  208. rotate([0, 0, twist]) {
  209. translate([capsule_radius + wall - ridge_length / 2, - (ridge_width - ridge_fit) / 2, 0]) {
  210. cube([ridge_length * 3 / 2, ridge_width - ridge_fit, capsule_height + rfit], center = false);
  211. }
  212. }
  213. }
  214. }
  215. // make the hole for the capsule (also cuts leg overhang for vertical connectors)
  216. if (solid != 1) {
  217. translate ([0, 0, -capsule_height]) {
  218. cylinder(r = capsule_radius + fudge, h = capsule_height * 2, $fn = facets);
  219. }
  220. }
  221. // remove any extra connecting beam material from the face of the holder
  222. if (connect == 0) {
  223. translate ([0, 0, capsule_height]) {
  224. cylinder(r = capsule_radius + wall * 2, h = 2, $fn = facets);
  225. }
  226. }
  227. }
  228. }
  229. }
  230. }
  231. }
  232. // microphone mount
  233. //
  234. // clips into standard microphone stand
  235. //
  236. // angles: angles for mount slots
  237. // wall: thickness of cylinder wall
  238. // stand_wall: thickness of stand mount wall
  239. // separation: height of mount with respect of the microphone assembly
  240. module ellipsoid(height, rad_bot, rad_top, eccentricity) {
  241. linear_extrude(height = height, scale = [eccentricity, rad_top / rad_bot]) {
  242. circle(r = rad_bot, $fn = facets);
  243. }
  244. }
  245. module mount (angles, wall, stand_wall, separation) {
  246. translate([0, 0, -separation]) {
  247. difference() {
  248. union() {
  249. // conic section
  250. translate([0, 0, mic_mount_height + mount_height]) {
  251. rotate([0, 0, 45]) {
  252. difference() {
  253. ellipsoid(mount_top_height, mount_radius + wall, mount_radius_capsule, mount_top_eccentricity);
  254. ellipsoid(mount_top_height, mount_radius, mount_radius_capsule * 0.5, mount_top_eccentricity * 1.05);
  255. }
  256. }
  257. }
  258. // stalk
  259. translate([0, 0, mic_mount_height + mount_height * 2/3]) {
  260. difference() {
  261. cylinder(r = mount_radius + wall, h = mount_height / 3, $fn = facets);
  262. // make the hole for the mount
  263. cylinder(r = mount_radius, h = mount_height / 3, $fn = facets);
  264. }
  265. }
  266. // transition to stand mount
  267. translate([0, 0, mic_mount_height]) {
  268. difference() {
  269. cylinder(r2 = mount_radius + wall, r1 = mic_mount_radius + mic_mount_fit + stand_wall,
  270. h = mount_height * 2 / 3, $fn = facets);
  271. // make the hole for the mount
  272. cylinder(r2 = mount_radius, r1 = mic_mount_radius + mic_mount_fit,
  273. h = mount_height * 2 / 3, $fn = facets);
  274. }
  275. }
  276. // stand mount
  277. translate([0, 0, 0]) {
  278. difference() {
  279. union() {
  280. // main mount cylinder
  281. translate([0, 0, 0]) {
  282. difference() {
  283. cylinder(r = mic_mount_radius + mic_mount_fit + stand_wall, h = mic_mount_height, $fn = facets);
  284. // make the hole for the mount (* 1.5 to cut the ridge as well)
  285. cylinder(r = mic_mount_radius + mic_mount_fit, h = mic_mount_height, $fn = facets);
  286. }
  287. }
  288. }
  289. // slot for fitting into microphone stand
  290. translate([mic_mount_radius - stand_wall / 2, - mic_mount_slot_width / 2, 0]) {
  291. cube([2 * stand_wall, mic_mount_slot_width, mic_mount_slot_height]);
  292. }
  293. // eyelet for microphone stand
  294. translate([mic_mount_radius - stand_wall / 2, 0, mic_mount_slot_height]) {
  295. rotate([0, 90, 0]) {
  296. cylinder(r = mic_mount_slot_radius, h = 2 * stand_wall, $fn = facets);
  297. }
  298. }
  299. // hole for microphone wiring
  300. translate([mic_mount_radius - stand_wall / 2, 0, mic_mount_height - mic_wire_hole_offset]) {
  301. rotate([0, 90, 0]) {
  302. cylinder(r = mic_wire_hole_radius, h = 2 * stand_wall, $fn = facets);
  303. }
  304. }
  305. }
  306. }
  307. }
  308. // indentations that match the two lower capsule holders
  309. translate([0, 0, mic_mount_height + mount_height + mount_top_height +
  310. (mic_radius - capsule_height) + capsule_height * sin(elev_angle)]) {
  311. capsule(angles[0], -elev_angle, [], 0, 1, 0.1, 1);
  312. capsule(angles[1], -elev_angle, [], 0, 1, 0.1, 1);
  313. }
  314. }
  315. }
  316. }