No Description
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 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. /*
  2. * Trackball
  3. *
  4. * Copyright (c) 2022 - 2023 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * Required parts:
  7. * - 1x Raspberry Pi Pico
  8. * - 4x Cherry MX compatible switches and keycaps
  9. * - 1x Billard ball, diameter 38mm
  10. * - 3x Si3N4 static bearing balls, diameter 3mm
  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. // https://www.printables.com/model/210898-raspberry-pi-pico-case
  33. use <external/pico_case.scad>
  34. // ######################
  35. // ## Rendering Select ##
  36. // ######################
  37. //ball_and_roller();
  38. //pico_wrap();
  39. //sensor();
  40. //mx_switch_cutout(wall);
  41. //mx_switch_test();
  42. //roller_mount_test();
  43. //roller_holder();
  44. //roller_mount_tri();
  45. trackball_top();
  46. //trackball_bottom();
  47. //assembly();
  48. //print();
  49. // #######################
  50. // #### Configuration ####
  51. // #######################
  52. $fn = 200;//42;
  53. ball_dia = 38.0;
  54. roller_dia = 3.0;
  55. roller_ball_h = ball_dia / 2 - 5;
  56. roller_count = 3;
  57. wall = 3.0;
  58. $c = 0.1;
  59. $e = 0.01;
  60. left_hand_version = false;
  61. cut_roller_holder = false;
  62. draw_supports = false;
  63. draw_ball_roller = true;
  64. draw_switches = true;
  65. draw_sensor = true;
  66. use_external_pico_model = true;
  67. draw_keycap = false;
  68. // #######################
  69. // ## Raspberry Pi Pico ##
  70. // #######################
  71. pico_w = 21;
  72. pico_l = 51;
  73. pico_d = 1.0;
  74. pico_hole_d = 2.1;
  75. pico_hole_x = 4.8;
  76. pico_hole_y = 2.0;
  77. pico_hole_d_x = 11.4;
  78. pico_hole_d_y = pico_l - 2 * pico_hole_y;
  79. pico_usb_w = 8.0;
  80. pico_usb_h = 2.8;
  81. pico_usb_d = 6.0;
  82. pico_usb_off = 1.3;
  83. // ######################
  84. // ### PMW3360 Sensor ###
  85. // ######################
  86. // https://github.com/jfedor2/pmw3360-breakout
  87. sensor_w = 22;
  88. sensor_l = 34;
  89. sensor_pcb_h = 1.6;
  90. sensor_hole_dia = 2.2;
  91. sensor_hole_off_x = 3.0;
  92. sensor_hole_off_y = 3.0;
  93. sensor_hole_dist_x = 16.0;
  94. sensor_hole_dist_y = 24.5;
  95. sensor_cut_w = 8.0 + 0.5;
  96. sensor_cut_h = 17.26;
  97. sensor_cut_off_x = 7.0 - 0.25;
  98. sensor_cut_off_y = 5.27;
  99. sensor_cut_edge_to_pin1 = 2.75;
  100. sensor_edge_to_pin1 = 1.52;
  101. sensor_ball_to_lens_top = 2.4;
  102. sensor_ball_to_chip_bottom = 9.81;
  103. sensor_chip_w = 9.1;
  104. sensor_chip_l = 16.2;
  105. sensor_chip_h = 2.21;
  106. sensor_pin_w = 0.5;
  107. sensor_pin_h = 4.51;
  108. sensor_pin_d = 0.2;
  109. sensor_pin_dist = 10.7;
  110. sensor_pin_off_top = 0.5;
  111. sensor_pin_pitch = 0.89;
  112. sensor_pin1_to_optical_center = 5.66;
  113. sensor_lens_cutout_r = 2.0;
  114. sensor_lens_cutout_w = 4.0;
  115. sensor_lens_cutout_growth = 0.25;
  116. sensor_lens_cutout_to_chip = 6.71 - 1.60;
  117. sensor_lens_baseplate_h = 2.40;
  118. sensor_lens_d = 19.0 + 1.0;
  119. sensor_lens_w = 21.35 + 0.2;
  120. sensor_lens_off = 10.97;
  121. // ######################
  122. // ## MX Switch Cutout ##
  123. // ######################
  124. // https://geekhack.org/index.php?topic=70654.0
  125. mx_co_w = 14.0;
  126. mx_co_w_add = 0.8;
  127. mx_co_h = 14.0;
  128. mx_co_keycap_w = mx_co_w + 2.5*2;
  129. mx_co_keycap_h = mx_co_h + 2.5*2;
  130. mx_co_h_off_1 = 1.0;
  131. mx_co_h_off_2 = 3.5;
  132. mx_co_h_off_3 = mx_co_h - 2 * (mx_co_h_off_1 + mx_co_h_off_2);
  133. mx_co_r = 0.4;
  134. // https://geekhack.org/index.php?topic=71550.0
  135. mx_co_th = 1.5 - 0.1;
  136. mx_co_b_add = 1.0;
  137. mx_co_b_w = mx_co_w + mx_co_b_add;
  138. mx_co_b_h = mx_co_h + mx_co_b_add;
  139. mx_travel = 3.9;
  140. // ######################
  141. // ### Implementation ###
  142. // ######################
  143. base_dia = 62;
  144. grub_screw_dia = 2.8;
  145. grub_channel_dia = 4.0;
  146. roller_thread_dia = roller_dia + 5.0;
  147. roller_h = roller_dia + 7.0;
  148. roller_ball_h_off = 0.4;
  149. roller_ball_hold_off = 0.5;
  150. roller_thread_hole = roller_dia - 1;
  151. roller_small_hole = sphere_r_at_h(roller_ball_hold_off, roller_dia / 2) * 2;
  152. roller_ridge_h = 1.5;
  153. roller_mount_angle_off = 90-5;
  154. roller_mount_dia = roller_thread_dia + 2.0;
  155. ball_h = 15; // todo
  156. switch_test_w = 25;
  157. roller_mount_holder_gap = 0.8;
  158. sensor_pcb_mount_gap = 2.0;
  159. sensor_pcb_support_h = 1.6 + 3.4;
  160. // rotate translate
  161. sw = [ // x z_pre_T z_post_T
  162. [ [-5, 0, -33 * (left_hand_version ? -1 : 1)], [0,-base_dia / 2 - 2,-14.5]],// thumb
  163. [ [-5, -15, 3 * (left_hand_version ? -1 : 1)], [0,-base_dia / 2 - 2,-14.5]],// thumb
  164. //[ [-5, 0, -70 * (left_hand_version ? -1 : 1)], [0,-base_dia / 2 - 0,-14.5]],// thumb
  165. [ [-5, -15, 140 * (left_hand_version ? -1 : 1)], [0,-base_dia / 2 - 3,-14.5]],// middle
  166. [ [-5, 0, 100 * (left_hand_version ? -1 : 1)], [0,-base_dia / 2 - 2,-14.5]],// ring
  167. ];
  168. sw_mount_w = mx_co_w + 7;
  169. sw_mount_co_l = 10;
  170. bottom_base_wall = wall + 0.5;
  171. bottom_base_below_zero = bottom_base_wall + 4.5;
  172. pico_co_w = pico_w + 1;
  173. pico_co_l = pico_l + 1;
  174. reset_button_dia = 4.0;
  175. reset_button_off_x = 7;
  176. reset_button_off_y = 12.15;
  177. pico_support_w = 6.5;
  178. pico_support_l = 5;
  179. pico_screw_depth = 6;
  180. pico_screw_d = 1.8;
  181. usb_cutout_grow_l = 10;
  182. usb_cutout_grow_x = 20;
  183. usb_cutout_grow_y = 10;
  184. usb_cutout_w_add = 1;
  185. usb_cutout_h_add = 0.6;
  186. assembly_dist = 20;
  187. roller_holder_sider_cut = 1.5;
  188. roller_holder_h_compensation = -0.1;
  189. bottom_add_wall = 4;
  190. screw_dia = 3.2;
  191. screw_off = base_dia / 2 - 10;
  192. screw_head_d = 6.0;
  193. screw_head_h = 3.5;
  194. //screw_angles = [ 30, -15, 180 + 40, 180 - 30 ];
  195. screw_angles = [ 15, -15, 180 + 15, 180 - 15 ];
  196. screw_insert_dia = 4.8;
  197. screw_insert_h = 6.0;
  198. function sphere_r_at_h(h, r) = r * sin(acos(h / r));
  199. function sphere_angle_at_rh(h, r) = acos(h / r);
  200. module mx_switch_cutout(h) {
  201. translate([-mx_co_w / 2 - mx_co_w_add, -mx_co_h / 2, 0]) {
  202. linear_extrude(h + 1) {
  203. translate([mx_co_w_add, 0]) {
  204. square([mx_co_w, mx_co_h]);
  205. for (x = [mx_co_r / 2, mx_co_w - mx_co_r / 2])
  206. for (y = [mx_co_r / 2, mx_co_h - mx_co_r / 2])
  207. translate([x, y])
  208. circle(r = mx_co_r);
  209. }
  210. for (x = [0, mx_co_w + mx_co_w_add])
  211. for (y = [0, mx_co_h_off_2 + mx_co_h_off_3])
  212. translate([x, mx_co_h_off_1 + y, 0])
  213. square([mx_co_w_add, mx_co_h_off_2]);
  214. }
  215. translate([mx_co_w_add - mx_co_b_add / 2, -mx_co_b_add / 2, -1])
  216. cube([mx_co_b_w, mx_co_b_h, h - mx_co_th + 1]);
  217. }
  218. translate([-mx_co_keycap_w/2,-mx_co_keycap_h/2, h])
  219. cube([mx_co_keycap_w, mx_co_keycap_h, 50]);
  220. }
  221. module mx_switch_test() {
  222. difference() {
  223. translate([-switch_test_w / 2, -switch_test_w / 2, 0])
  224. cube([switch_test_w, switch_test_w, wall]);
  225. mx_switch_cutout(wall);
  226. translate([0, -switch_test_w / 2 + 1, wall - 1.0])
  227. linear_extrude(1.1)
  228. text("switch test", size = 3, halign = "center");
  229. }
  230. %translate([0, 0, wall])
  231. rotate([0, 0, 180])
  232. mx_switch($t);
  233. }
  234. module pico_own() {
  235. translate([-pico_w / 2, -pico_l / 2, 0])
  236. difference() {
  237. union() {
  238. color("green")
  239. cube([pico_w, pico_l, pico_d]);
  240. translate([(pico_w - pico_usb_w) / 2, pico_l - pico_usb_d + pico_usb_off, pico_d])
  241. cube([pico_usb_w, pico_usb_d, pico_usb_h]);
  242. }
  243. for (x = [0, pico_hole_d_x])
  244. for (y = [0, pico_hole_d_y])
  245. translate([pico_hole_x + x, pico_hole_y + y, -1])
  246. cylinder(d = pico_hole_d, h = pico_d + 2);
  247. }
  248. }
  249. module pico_wrap() {
  250. translate([0,0,3.9])
  251. rotate([0,180,0])
  252. if (use_external_pico_model)
  253. translate([-pico_w / 2, -pico_l / 2, 0])
  254. pico();
  255. else
  256. pico_own();
  257. }
  258. module sensor_lens_cutout_intern() {
  259. cylinder(d = sensor_lens_cutout_r * 2, h = $e);
  260. translate([-sensor_lens_cutout_r, 0, 0])
  261. cube([sensor_lens_cutout_r * 2, sensor_lens_cutout_w, $e]);
  262. }
  263. module rounded_cube(x, y, z, r) {
  264. hull()
  265. for (tx = [r, x - r])
  266. for (ty = [r, y - r])
  267. translate([tx, ty, 0])
  268. cylinder(d = r * 2, h = z);
  269. }
  270. module sensor_lens_cutout() {
  271. translate([0, 0, sensor_lens_cutout_to_chip])
  272. hull() {
  273. translate([0, 0, sensor_lens_baseplate_h - $e])
  274. sensor_lens_cutout_intern();
  275. scale(1 + sensor_lens_cutout_growth * sensor_lens_baseplate_h)
  276. sensor_lens_cutout_intern();
  277. }
  278. translate([-sensor_lens_d / 2, -sensor_lens_w + sensor_lens_off, 0])
  279. rounded_cube(sensor_lens_d, sensor_lens_w, sensor_lens_cutout_to_chip, 6);
  280. translate([-3 / 2, -sensor_lens_w + sensor_lens_off - 0.5, 0])
  281. cube([3, 0.5, sensor_lens_cutout_to_chip]);
  282. }
  283. module sensor() {
  284. translate([-sensor_w / 2, -sensor_l / 2, 0])
  285. difference() {
  286. color("green")
  287. cube([sensor_w, sensor_l, sensor_pcb_h]);
  288. translate([sensor_cut_off_x, sensor_cut_off_y, -1])
  289. cube([sensor_cut_w, sensor_cut_h, sensor_pcb_h + 2]);
  290. for (x = [0, sensor_hole_dist_x])
  291. for (y = [0, sensor_hole_dist_y])
  292. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, -1])
  293. cylinder(d = sensor_hole_dia, h = sensor_pcb_h + 2);
  294. }
  295. color("#303030")
  296. 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])
  297. cube([sensor_chip_w, sensor_chip_l, sensor_chip_h]);
  298. translate([0, -sensor_l / 2 - 15 * sensor_pin_pitch + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1, 0])
  299. for (p = [0 : 15])
  300. translate([0, p * sensor_pin_pitch, 0])
  301. for (x = [-sensor_pin_dist / 2, sensor_pin_dist / 2])
  302. if (((p % 2 == 0) && (x < 0))
  303. || ((p % 2 == 1) && (x > 0)))
  304. translate([-sensor_pin_d / 2 + x, -sensor_pin_w / 2, -sensor_chip_h + sensor_pin_off_top])
  305. cube([sensor_pin_d, sensor_pin_w, sensor_pin_h]);
  306. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, 0]) {
  307. color("cyan")
  308. translate([0, 0, -sensor_chip_h + 1])
  309. cylinder(d = 0.2, h = sensor_ball_to_chip_bottom - 1);
  310. %color("blue")
  311. sensor_lens_cutout();
  312. }
  313. }
  314. module ball_and_roller() {
  315. color("red")
  316. sphere(d = ball_dia, $fn = $fn);
  317. for (r = [0 : roller_count - 1])
  318. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  319. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  320. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  321. translate([0, 0, -roller_dia / 2])
  322. roller_holder();
  323. }
  324. module roller_holder() {
  325. translate([0, 0, -roller_h + roller_dia / 2])
  326. difference() {
  327. color("magenta")
  328. union() {
  329. translate([0, 0, roller_h-roller_dia/2 + roller_ball_h_off-3])
  330. cylinder(d1 = roller_mount_dia, d2=roller_dia+1, h = 3);
  331. cylinder(d = roller_mount_dia, h = roller_h-roller_dia/2 + roller_ball_h_off-3);
  332. }
  333. translate([-roller_mount_dia / 2 - 1, roller_mount_dia / 2 - roller_holder_sider_cut, -1])
  334. cube([roller_mount_dia + 2, roller_mount_dia / 2 + 1, roller_h + 2]);
  335. translate([0, 0, -$e])
  336. cylinder(d = roller_thread_hole, h = $e+ roller_h - roller_dia / 2 + roller_ball_h_off + roller_ball_hold_off);
  337. translate([0, 0, roller_h - roller_dia / 2 + roller_holder_h_compensation])
  338. sphere(d = roller_dia, $fn = $fn);
  339. if (cut_roller_holder)
  340. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
  341. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  342. }
  343. %color("blue")
  344. sphere(d = roller_dia, $fn = $fn);
  345. }
  346. module roller_mount() {
  347. translate([0, 0, -1-roller_h + roller_dia / 2]) {
  348. difference() {
  349. cylinder(d=roller_mount_dia+wall,h=roller_h/2);
  350. translate([0, 0, 1])
  351. cylinder(d=roller_mount_dia+$c*2,h=roller_h/2+$e);
  352. if (cut_roller_holder)
  353. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
  354. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  355. }
  356. }
  357. }
  358. module roller_mount_test() {
  359. roller_holder();
  360. roller_mount();
  361. }
  362. module roller_mount_tri_hull() {
  363. for (r = [0 : roller_count - 1])
  364. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  365. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  366. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  367. translate([0, 0, -roller_h])
  368. cylinder(d = roller_mount_dia + wall + 1, h = roller_h - 3);
  369. translate([0, 0, -ball_dia / 2 - 11])
  370. cylinder(d = base_dia, h = $e);
  371. }
  372. module roller_mount_tri_body() {
  373. // space for roller holder
  374. for (r = [0 : roller_count - 1])
  375. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  376. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  377. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  378. translate([0, 0, -roller_h])
  379. cylinder(d = roller_mount_dia + roller_mount_holder_gap, h = ball_dia / 2 + roller_h);
  380. // room for ball itself
  381. sphere($fn = $fn * 2, d = ball_dia + $c * 2 + 4);
  382. // grub screws
  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_h/2])
  388. rotate([0,-90,0])
  389. translate([-2, 0, 2]) {
  390. cylinder(d = grub_screw_dia, h = ball_dia);
  391. translate([0, 0, roller_mount_dia / 4 + wall])
  392. cylinder(d = grub_channel_dia, h = ball_dia);
  393. }
  394. // sensor lens
  395. translate([0, 0, -ball_dia / 2 - ball_h])
  396. 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])
  397. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, 0])
  398. sensor_lens_cutout();
  399. // sensor pcb
  400. translate([-1, -1, -ball_dia / 2 - ball_h])
  401. 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])
  402. translate([-sensor_w / 2, -sensor_l / 2, -10])
  403. cube([sensor_w + 2, sensor_l + 2, sensor_pcb_h + 10 + sensor_pcb_mount_gap]);
  404. }
  405. module roller_mount_sensor_pcb_support() {
  406. translate([-sensor_w / 2, -sensor_l / 2, sensor_pcb_h])
  407. translate([0, 0, -ball_dia / 2 - ball_h])
  408. 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])
  409. for (x = [0, sensor_hole_dist_x])
  410. for (y = [0, sensor_hole_dist_y])
  411. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, 0])
  412. difference() {
  413. union() {
  414. color("magenta")
  415. cylinder(d = sensor_hole_dia + 1.5, h = sensor_pcb_mount_gap);
  416. if (draw_supports)
  417. color("black")
  418. translate([0, 0, -sensor_pcb_support_h])
  419. cylinder(d = sensor_hole_dia + 0.5, h = sensor_pcb_support_h);
  420. }
  421. cylinder(d = sensor_hole_dia - 0.2, h = sensor_pcb_mount_gap + 1);
  422. }
  423. if (draw_supports)
  424. color("black")
  425. for (x = [-5, 0, 5])
  426. for (y = [-8, 0, 6.5])
  427. if (((x == 0) && (y != 0)) || ((x != 0) && (y == 0)))
  428. translate([x, y + 2, -30])
  429. cylinder(d = sensor_hole_dia + 0.5, h = 8.5);
  430. if (draw_sensor)
  431. %translate([0, 0, -ball_dia / 2 - ball_h])
  432. 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])
  433. sensor();
  434. }
  435. // TODO holes for pcb screws not going into body!!
  436. module roller_mount_tri() {
  437. if (draw_ball_roller)
  438. %ball_and_roller();
  439. difference() {
  440. hull()
  441. roller_mount_tri_hull();
  442. roller_mount_tri_body();
  443. // TODO test cable cutout
  444. translate([-6, 0, -30.1])
  445. cube([12, 50, 2]);
  446. if (cut_roller_holder)
  447. translate([0, -base_dia / 2 - 1, -40])
  448. cube([base_dia / 2 + 1, base_dia + 2, 40]);
  449. }
  450. roller_mount_sensor_pcb_support();
  451. }
  452. module fully_rounded_cube(p,r,center) {
  453. for(x=[r,p[0]-r],
  454. y=[r,p[1]-r],
  455. z=[r,p[2]-r]
  456. ){
  457. translate([x,y,z])
  458. sphere(r,$fn=$fn/8);
  459. }
  460. }
  461. module trackball_top() {
  462. translate([0, 0, ball_dia / 2 + ball_h]) {
  463. if (draw_ball_roller)
  464. %ball_and_roller();
  465. difference() {
  466. color("orange")
  467. hull() {
  468. r=4;
  469. roller_mount_tri_hull();
  470. for ( i = [0:len(sw)-1] ){
  471. rotate([0,0,sw[i][0][2]])
  472. translate(sw[i][1])
  473. rotate([90+sw[i][0][0],0,sw[i][0][1]])
  474. translate([-sw_mount_w/2-r, -sw_mount_w/2-r, -r-r/2])
  475. fully_rounded_cube([sw_mount_w+r*2, sw_mount_w+r*2, 0], r);
  476. }
  477. }
  478. roller_mount_tri_body();
  479. if (cut_roller_holder)
  480. translate([0, -base_dia / 2 - 1, -40])
  481. cube([base_dia / 2 + 1, base_dia + 2, 40]);
  482. for ( i = [0:len(sw)-1] ){
  483. rotate([0,0,sw[i][0][2]])
  484. translate(sw[i][1])
  485. rotate([90+sw[i][0][0],0,sw[i][0][1]])
  486. translate([0, 0, -sw_mount_co_l]) {
  487. mx_switch_cutout(sw_mount_co_l + 1);
  488. translate([0, 0, 2])
  489. rotate([90, 0, 0])
  490. cylinder(d = 4, h = 20);
  491. rotate([0,-sw[i][0][1],0])
  492. translate([0,-15,3])
  493. rotate([0,180,0])
  494. cylinder(d=3,h=40);
  495. }
  496. }
  497. for (r = screw_angles)
  498. rotate([0, 0, r])
  499. translate([screw_off, 0, -ball_dia / 2 - 11 -1]) {
  500. cylinder(d = screw_insert_dia, h = screw_insert_h + 1);
  501. }
  502. for (x = [0, pico_hole_d_x])
  503. for (y = [0, pico_hole_d_y])
  504. rotate([0,0,0])
  505. translate([-pico_w / 2, -pico_l / 2, -25])
  506. translate([pico_hole_x + x, pico_hole_y + y, -pico_d - pico_screw_depth])
  507. cylinder(d = pico_screw_d, h = pico_d + pico_screw_depth + 1);
  508. rotate([0, 180, 0])
  509. translate([-pico_w / 2, -pico_l / 2, 0])
  510. translate([(pico_w - pico_usb_w) / 2, pico_l - 1 + pico_usb_off, 30])
  511. usb_cutout();
  512. }
  513. roller_mount_sensor_pcb_support();
  514. if (draw_switches)
  515. for ( i = [0:len(sw)-1] ){
  516. %rotate([0,0,sw[i][0][2]])
  517. translate(sw[i][1])
  518. rotate([90+sw[i][0][0],0,sw[i][0][1]])
  519. translate([0, 0, 1.])
  520. mx_switch($t);
  521. }
  522. if (draw_keycap)
  523. for ( i = [0:len(sw)-1] ){
  524. %rotate([0,0,sw[i][0][2]])
  525. translate(sw[i][1])
  526. rotate([90+sw[i][0][0],0,sw[i][0][1]])
  527. translate([0, 0, 1.])
  528. mx_switch($t);
  529. }
  530. }
  531. }
  532. module trackball_bottom_wrap() {
  533. color("magenta")
  534. translate([0, 0, -3.0])
  535. difference() {
  536. cylinder(d = base_dia, h = bottom_base_below_zero + ball_h - 16);
  537. translate([0, 0, bottom_base_wall])
  538. cylinder(d = base_dia - bottom_base_wall * 2 - bottom_add_wall, h = bottom_base_below_zero + ball_h - 15);
  539. translate([-pico_co_w / 2, -pico_co_l / 2, 2.5])
  540. cube([pico_co_w, pico_co_l, bottom_base_below_zero + ball_h - 11]);
  541. translate([pico_w / 2 - reset_button_off_x, pico_l / 2 - reset_button_off_y, -1])
  542. cylinder(d = reset_button_dia, h = bottom_base_wall + 2);
  543. }
  544. color("cyan")
  545. for (r = screw_angles)
  546. rotate([0, 0, r])
  547. translate([screw_off, 0, -3])
  548. cylinder(d = screw_head_d + 4, h = bottom_base_below_zero + ball_h - 16 );
  549. }
  550. module usb_cutout() {
  551. translate([8,1,4.5])
  552. rotate([0,180,0]) {
  553. translate([-usb_cutout_w_add / 2, -2, -usb_cutout_h_add / 2])
  554. cube([pico_usb_w + usb_cutout_w_add, 5, pico_usb_h + usb_cutout_h_add]);
  555. hull() {
  556. translate([-usb_cutout_w_add / 2, 1, -usb_cutout_h_add / 2])
  557. cube([pico_usb_w + usb_cutout_w_add, $e, pico_usb_h + usb_cutout_h_add]);
  558. translate([-usb_cutout_grow_x / 2, 1+usb_cutout_grow_l, -usb_cutout_grow_y / 2])
  559. cube([pico_usb_w + usb_cutout_grow_x, $e, pico_usb_h + usb_cutout_grow_y]);
  560. translate([-usb_cutout_grow_x / 2, 1+usb_cutout_grow_l*10, -usb_cutout_grow_y / 2])
  561. cube([pico_usb_w + usb_cutout_grow_x, $e, pico_usb_h + usb_cutout_grow_y]);
  562. }
  563. }
  564. }
  565. module trackball_bottom() {
  566. difference() {
  567. trackball_bottom_wrap();
  568. translate([0, 0, ball_dia / 2 + ball_h])
  569. rotate([0, 180, 0])
  570. translate([-pico_w / 2, -pico_l / 2, 0])
  571. translate([(pico_w - pico_usb_w) / 2, pico_l - 1 + pico_usb_off, 30])
  572. usb_cutout();
  573. for (r = screw_angles)
  574. rotate([0, 0, r])
  575. translate([screw_off, 0, -$e-3]) {
  576. cylinder(d = screw_dia, h = bottom_base_below_zero + 30);
  577. cylinder(d = screw_head_d, h = screw_head_h + 1);
  578. }
  579. }
  580. }
  581. module assembly() {
  582. translate([0, 0, assembly_dist / 2])
  583. trackball_top();
  584. translate([0, 0, -assembly_dist / 2])
  585. trackball_bottom();
  586. }
  587. module print() {
  588. translate([-40, 0, -4])
  589. trackball_top();
  590. translate([40, 0, bottom_base_below_zero])
  591. trackball_bottom();
  592. for (y = [-20, 0, 20])
  593. translate([0, y, 8.5])
  594. roller_holder();
  595. }