Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

trackball.scad 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * Trackball
  3. * Copyright 2022 Thomas Buck - thomas@xythobuz.de
  4. *
  5. * Required parts:
  6. * - 1x Raspberry Pi Pico
  7. * - 5x Cherry MX compatible switches and keycaps
  8. * - 1x Billard ball, diameter 38mm
  9. * - 3x Si3N4 static bearing balls, diameter 3mm
  10. * - 3x spring, diameter 2mm, length 10mm
  11. * - 1x PMW3360 sensor with breakout board
  12. * - 8x M2 screw, length 5mm
  13. * - 8x M2 heat melt insert, length 4mm
  14. *
  15. * For the PMW3360 breakout board get this:
  16. * https://github.com/jfedor2/pmw3360-breakout
  17. *
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation, either version 3 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * See <http://www.gnu.org/licenses/>.
  29. */
  30. // https://www.thingiverse.com/thing:421524
  31. use <external/cherry_mx.scad>
  32. // ######################
  33. // ## Rendering Select ##
  34. // ######################
  35. //ball_and_roller();
  36. //pico();
  37. //sensor();
  38. //mx_switch_cutout(wall);
  39. //mx_switch_test();
  40. //roller_mount_test();
  41. roller_mount_tri();
  42. //roller_holder();
  43. //trackball();
  44. // #######################
  45. // #### Configuration ####
  46. // #######################
  47. ball_dia = 38.0;
  48. roller_dia = 3.0;
  49. roller_ball_h = 8;
  50. roller_count = 3;
  51. wall = 3.0;
  52. $c = 0.1;
  53. $e = 0.01;
  54. cut_roller_holder = false;
  55. // #######################
  56. // ## Raspberry Pi Pico ##
  57. // #######################
  58. pico_w = 21;
  59. pico_l = 51;
  60. pico_d = 1.6; // todo
  61. pico_hole_d = 2.1;
  62. pico_hole_x = 4.8;
  63. pico_hole_y = 2.0;
  64. pico_hole_d_x = 11.4;
  65. pico_hole_d_y = pico_l - 2 * pico_hole_y;
  66. pico_usb_w = 8.0;
  67. pico_usb_h = 3.0; // todo
  68. pico_usb_d = 10.0; // todo
  69. pico_usb_off = 1.3;
  70. pico_h = pico_d + 1; // todo
  71. // ######################
  72. // ### PMW3360 Sensor ###
  73. // ######################
  74. // https://github.com/jfedor2/pmw3360-breakout
  75. sensor_w = 22;
  76. sensor_l = 34;
  77. sensor_pcb_h = 1.6;
  78. sensor_hole_dia = 2.2;
  79. sensor_hole_off_x = 3.0;
  80. sensor_hole_off_y = 3.0;
  81. sensor_hole_dist_x = 16.0;
  82. sensor_hole_dist_y = 24.5;
  83. sensor_cut_w = 8.0 + 0.5;
  84. sensor_cut_h = 17.26;
  85. sensor_cut_off_x = 7.0 - 0.25;
  86. sensor_cut_off_y = 5.27;
  87. sensor_cut_edge_to_pin1 = 2.75;
  88. sensor_edge_to_pin1 = 1.52;
  89. sensor_ball_to_lens_top = 2.4;
  90. sensor_ball_to_chip_bottom = 9.81;
  91. sensor_chip_w = 9.1;
  92. sensor_chip_l = 16.2;
  93. sensor_chip_h = 2.21;
  94. sensor_pin_w = 0.5;
  95. sensor_pin_h = 4.51;
  96. sensor_pin_d = 0.2;
  97. sensor_pin_dist = 10.7;
  98. sensor_pin_off_top = 0.5;
  99. sensor_pin_pitch = 0.89;
  100. sensor_pin1_to_optical_center = 5.66;
  101. sensor_lens_cutout_r = 2.0;
  102. sensor_lens_cutout_w = 4.0;
  103. sensor_lens_cutout_growth = 0.25;
  104. sensor_lens_cutout_to_chip = 6.71 - 1.60;
  105. sensor_lens_baseplate_h = 2.40;
  106. sensor_lens_d = 19.0;
  107. sensor_lens_w = 21.35;
  108. sensor_lens_off = 10.97;
  109. // ######################
  110. // ## MX Switch Cutout ##
  111. // ######################
  112. // https://geekhack.org/index.php?topic=70654.0
  113. mx_co_w = 14.0;
  114. mx_co_w_add = 0.8;
  115. mx_co_h = 14.0;
  116. mx_co_h_off_1 = 1.0;
  117. mx_co_h_off_2 = 3.5;
  118. mx_co_h_off_3 = mx_co_h - 2 * (mx_co_h_off_1 + mx_co_h_off_2);
  119. mx_co_r = 0.4;
  120. // https://geekhack.org/index.php?topic=71550.0
  121. mx_co_th = 1.5 - 0.1;
  122. mx_co_b_add = 1.0;
  123. mx_co_b_w = mx_co_w + mx_co_b_add;
  124. mx_co_b_h = mx_co_h + mx_co_b_add;
  125. mx_travel = 3.9;
  126. // ######################
  127. // ### Implementation ###
  128. // ######################
  129. base_dia = pico_l + 9;
  130. m3_thread = 2.7;
  131. m2_thread = 1.8;
  132. roller_thread_dia = roller_dia + 5.0;
  133. roller_h = roller_dia + 7.0;
  134. roller_ball_h_off = 0.4;
  135. roller_ball_hold_off = 0.5;
  136. roller_thread_hole = roller_dia - 1;
  137. roller_small_hole = sphere_r_at_h(roller_ball_hold_off, roller_dia / 2) * 2;
  138. roller_ridge_h = 1.5;
  139. roller_mount_angle_off = 90;
  140. roller_mount_dia = roller_thread_dia + 2.0;
  141. ball_h = 15; // todo
  142. switch_test_w = 25;
  143. $fn = 100;
  144. function sphere_r_at_h(h, r) = r * sin(acos(h / r));
  145. function sphere_angle_at_rh(h, r) = acos(h / r);
  146. module mx_switch_cutout(h) {
  147. translate([-mx_co_w / 2 - mx_co_w_add, -mx_co_h / 2, 0]) {
  148. linear_extrude(h + 1) {
  149. translate([mx_co_w_add, 0]) {
  150. square([mx_co_w, mx_co_h]);
  151. for (x = [mx_co_r / 2, mx_co_w - mx_co_r / 2])
  152. for (y = [mx_co_r / 2, mx_co_h - mx_co_r / 2])
  153. translate([x, y])
  154. circle(r = mx_co_r);
  155. }
  156. for (x = [0, mx_co_w + mx_co_w_add])
  157. for (y = [0, mx_co_h_off_2 + mx_co_h_off_3])
  158. translate([x, mx_co_h_off_1 + y, 0])
  159. square([mx_co_w_add, mx_co_h_off_2]);
  160. }
  161. translate([mx_co_w_add - mx_co_b_add / 2, -mx_co_b_add / 2, -1])
  162. cube([mx_co_b_w, mx_co_b_h, h - mx_co_th + 1]);
  163. }
  164. }
  165. module mx_switch_test() {
  166. difference() {
  167. translate([-switch_test_w / 2, -switch_test_w / 2, 0])
  168. cube([switch_test_w, switch_test_w, wall]);
  169. mx_switch_cutout(wall);
  170. translate([0, -switch_test_w / 2 + 1, wall - 1.0])
  171. linear_extrude(1.1)
  172. text("switch test", size = 3, halign = "center");
  173. }
  174. %translate([0, 0, wall])
  175. rotate([0, 0, 180])
  176. mx_switch($t);
  177. }
  178. module pico() {
  179. translate([-pico_w / 2, -pico_l / 2, 0])
  180. difference() {
  181. union() {
  182. color("green")
  183. cube([pico_w, pico_l, pico_d]);
  184. translate([(pico_w - pico_usb_w) / 2, pico_l - pico_usb_d + pico_usb_off, pico_d])
  185. cube([pico_usb_w, pico_usb_d, pico_usb_h]);
  186. }
  187. for (x = [0, pico_hole_d_x])
  188. for (y = [0, pico_hole_d_y])
  189. translate([pico_hole_x + x, pico_hole_y + y, -1])
  190. cylinder(d = pico_hole_d, h = pico_d + 2);
  191. }
  192. }
  193. module sensor_lens_cutout_intern() {
  194. cylinder(d = sensor_lens_cutout_r * 2, h = $e);
  195. translate([-sensor_lens_cutout_r, 0, 0])
  196. cube([sensor_lens_cutout_r * 2, sensor_lens_cutout_w, $e]);
  197. }
  198. module rounded_cube(x, y, z, r) {
  199. hull()
  200. for (tx = [r, x - r])
  201. for (ty = [r, y - r])
  202. translate([tx, ty, 0])
  203. cylinder(d = r * 2, h = z);
  204. }
  205. module sensor_lens_cutout() {
  206. translate([0, 0, sensor_lens_cutout_to_chip])
  207. hull() {
  208. translate([0, 0, sensor_lens_baseplate_h - $e])
  209. sensor_lens_cutout_intern();
  210. scale(1 + sensor_lens_cutout_growth * sensor_lens_baseplate_h)
  211. sensor_lens_cutout_intern();
  212. }
  213. translate([-sensor_lens_d / 2, -sensor_lens_w + sensor_lens_off, 0])
  214. rounded_cube(sensor_lens_d, sensor_lens_w, sensor_lens_cutout_to_chip, 6);
  215. translate([-3 / 2, -sensor_lens_w + sensor_lens_off - 0.5, 0])
  216. cube([3, 0.5, sensor_lens_cutout_to_chip]);
  217. }
  218. module sensor() {
  219. translate([-sensor_w / 2, -sensor_l / 2, 0])
  220. difference() {
  221. color("green")
  222. cube([sensor_w, sensor_l, sensor_pcb_h]);
  223. translate([sensor_cut_off_x, sensor_cut_off_y, -1])
  224. cube([sensor_cut_w, sensor_cut_h, sensor_pcb_h + 2]);
  225. for (x = [0, sensor_hole_dist_x])
  226. for (y = [0, sensor_hole_dist_y])
  227. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, -1])
  228. cylinder(d = sensor_hole_dia, h = sensor_pcb_h + 2);
  229. }
  230. color("#303030")
  231. translate([-sensor_chip_w / 2, -sensor_l / 2 - sensor_chip_l + sensor_edge_to_pin1 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1, -sensor_chip_h])
  232. cube([sensor_chip_w, sensor_chip_l, sensor_chip_h]);
  233. translate([0, -sensor_l / 2 - 15 * sensor_pin_pitch + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1, 0])
  234. for (p = [0 : 15])
  235. translate([0, p * sensor_pin_pitch, 0])
  236. for (x = [-sensor_pin_dist / 2, sensor_pin_dist / 2])
  237. if (((p % 2 == 0) && (x < 0))
  238. || ((p % 2 == 1) && (x > 0)))
  239. translate([-sensor_pin_d / 2 + x, -sensor_pin_w / 2, -sensor_chip_h + sensor_pin_off_top])
  240. cube([sensor_pin_d, sensor_pin_w, sensor_pin_h]);
  241. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, 0]) {
  242. color("cyan")
  243. translate([0, 0, -sensor_chip_h + 1])
  244. cylinder(d = 0.2, h = sensor_ball_to_chip_bottom - 1);
  245. %color("blue")
  246. sensor_lens_cutout();
  247. }
  248. }
  249. module ball_and_roller() {
  250. color("red")
  251. sphere(d = ball_dia, $fn = $fn * 2);
  252. for (r = [0 : roller_count - 1])
  253. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  254. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  255. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  256. translate([0, 0, -roller_dia / 2])
  257. roller_holder();
  258. }
  259. module roller_holder() {
  260. translate([0, 0, -roller_h + roller_dia / 2])
  261. difference() {
  262. color("magenta")
  263. union() {
  264. // top screw part
  265. translate([0, 0, roller_h-roller_dia/2 + roller_ball_h_off-3])
  266. cylinder(d1 = roller_mount_dia, d2=roller_dia+1, h = 3);
  267. cylinder(d = roller_mount_dia, h = roller_h-roller_dia/2 + roller_ball_h_off-3);
  268. }
  269. translate([0, 0, -$e])
  270. cylinder(d = roller_thread_hole, h = $e+ roller_h - roller_dia / 2 + roller_ball_h_off + roller_ball_hold_off);
  271. translate([0, 0, roller_h - roller_dia / 2])
  272. sphere(d = roller_dia, $fn = $fn * 2);
  273. if (cut_roller_holder)
  274. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
  275. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  276. }
  277. %color("blue")
  278. sphere(d = roller_dia, $fn = $fn * 2);
  279. }
  280. module roller_mount() {
  281. translate([0, 0, -1-roller_h + roller_dia / 2]) {
  282. difference() {
  283. cylinder(d=roller_mount_dia+wall,h=roller_h/2);
  284. translate([0, 0, 1])
  285. cylinder(d=roller_mount_dia+$c*2,h=roller_h/2+$e);
  286. if (cut_roller_holder)
  287. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
  288. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  289. }
  290. }
  291. }
  292. module roller_mount_test() {
  293. roller_holder();
  294. roller_mount();
  295. }
  296. roller_mount_holder_gap = 0.8;
  297. sensor_pcb_mount_gap = 2.0;
  298. sensor_pcb_support_h = 1.6 + 3.4;
  299. module roller_mount_tri() {
  300. %ball_and_roller();
  301. difference() {
  302. union() {
  303. difference() {
  304. hull() {
  305. for (r = [0 : roller_count - 1])
  306. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  307. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  308. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  309. translate([0, 0, -roller_h])
  310. cylinder(d = roller_mount_dia + wall + 1, h = roller_h - 3);
  311. translate([0, 0, -ball_dia / 2 - 11])
  312. cylinder(d = base_dia, h = $e);
  313. }
  314. for (r = [0 : roller_count - 1])
  315. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  316. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  317. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  318. translate([0, 0, -roller_h])
  319. cylinder(d = roller_mount_dia + roller_mount_holder_gap, h = ball_dia / 2 + roller_h);
  320. sphere($fn = $fn * 2, d = ball_dia + $c * 2 + 4);
  321. }
  322. }
  323. for (r = [0 : roller_count - 1])
  324. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  325. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  326. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  327. translate([0, 0, -roller_h/2])
  328. rotate([0,-90,0])
  329. translate([-2, 0, 2]) {
  330. cylinder(d = m2_thread, h = ball_dia);
  331. translate([0, 0, roller_mount_dia / 4 + wall])
  332. cylinder(d = m2_thread + 1, h = ball_dia);
  333. }
  334. translate([0, 0, -ball_dia / 2 - ball_h])
  335. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  336. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, 0])
  337. sensor_lens_cutout();
  338. translate([-1, -1, -ball_dia / 2 - ball_h])
  339. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  340. translate([-sensor_w / 2, -sensor_l / 2, -10])
  341. cube([sensor_w + 2, sensor_l + 2, sensor_pcb_h + 10 + sensor_pcb_mount_gap]);
  342. // TODO test cable cutout
  343. translate([-6, 0, -30.1])
  344. cube([12, 50, 2]);
  345. if (cut_roller_holder)
  346. translate([0, -base_dia / 2 - 1, -40])
  347. cube([base_dia / 2 + 1, base_dia + 2, 40]);
  348. }
  349. translate([-sensor_w / 2, -sensor_l / 2, sensor_pcb_h])
  350. translate([0, 0, -ball_dia / 2 - ball_h])
  351. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  352. for (x = [0, sensor_hole_dist_x])
  353. for (y = [0, sensor_hole_dist_y])
  354. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, 0])
  355. difference() {
  356. union() {
  357. color("magenta")
  358. cylinder(d = sensor_hole_dia + 1.5, h = sensor_pcb_mount_gap);
  359. color("black")
  360. translate([0, 0, -sensor_pcb_support_h])
  361. cylinder(d = sensor_hole_dia + 0.5, h = sensor_pcb_support_h);
  362. }
  363. cylinder(d = sensor_hole_dia - 0.2, h = sensor_pcb_mount_gap + 1);
  364. }
  365. color("black")
  366. for (x = [-5, 0, 5])
  367. for (y = [-8, 0, 6.5])
  368. if (((x == 0) && (y != 0)) || ((x != 0) && (y == 0)))
  369. translate([x, y + 2, -30])
  370. cylinder(d = sensor_hole_dia + 0.5, h = 8.5);
  371. %translate([0, 0, -ball_dia / 2 - ball_h])
  372. translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  373. sensor();
  374. }
  375. module trackball() {
  376. %translate([0, 0, ball_dia / 2 + ball_h])
  377. ball_and_roller();
  378. %rotate([0, 180, 0])
  379. pico();
  380. %translate([0, sensor_l / 2 - sensor_cut_off_y - sensor_cut_h + sensor_cut_edge_to_pin1 + sensor_pin1_to_optical_center, ball_h + sensor_chip_h - sensor_ball_to_chip_bottom])
  381. sensor();
  382. translate([0, 0, ball_dia / 2 + ball_h])
  383. for (r = [0 : roller_count - 1])
  384. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  385. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  386. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  387. translate([0, 0, -roller_dia / 2])
  388. roller_mount();
  389. color("grey")
  390. translate([0, 0, -8])
  391. cylinder(d = base_dia, h = wall);
  392. }