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

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