설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

trackball.scad 13KB

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