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 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  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_h_off_1 = 1.0;
  127. mx_co_h_off_2 = 3.5;
  128. mx_co_h_off_3 = mx_co_h - 2 * (mx_co_h_off_1 + mx_co_h_off_2);
  129. mx_co_r = 0.4;
  130. // https://geekhack.org/index.php?topic=71550.0
  131. mx_co_th = 1.5 - 0.1;
  132. mx_co_b_add = 1.0;
  133. mx_co_b_w = mx_co_w + mx_co_b_add;
  134. mx_co_b_h = mx_co_h + mx_co_b_add;
  135. mx_travel = 3.9;
  136. // ######################
  137. // ### Implementation ###
  138. // ######################
  139. base_dia = 62;
  140. grub_screw_dia = 2.8;
  141. grub_channel_dia = 4.0;
  142. roller_thread_dia = roller_dia + 5.0;
  143. roller_h = roller_dia + 7.0;
  144. roller_ball_h_off = 0.4;
  145. roller_ball_hold_off = 0.5;
  146. roller_thread_hole = roller_dia - 1;
  147. roller_small_hole = sphere_r_at_h(roller_ball_hold_off, roller_dia / 2) * 2;
  148. roller_ridge_h = 1.5;
  149. roller_mount_angle_off = 90;
  150. roller_mount_dia = roller_thread_dia + 2.0;
  151. ball_h = 15; // todo
  152. switch_test_w = 25;
  153. roller_mount_holder_gap = 0.8;
  154. sensor_pcb_mount_gap = 2.0;
  155. sensor_pcb_support_h = 1.6 + 3.4;
  156. sw1_rot_x = -5;
  157. sw1_rot_z = -30 * (left_hand_version ? -1 : 1);
  158. sw1_trans_x = 0;
  159. sw1_trans_y = -base_dia / 2 - 0;
  160. sw1_trans_z = -17;
  161. sw2_rot_x = -5;
  162. sw2_rot_z = 15 * (left_hand_version ? -1 : 1);
  163. sw2_trans_x = 0;
  164. sw2_trans_y = -base_dia / 2 - 0;
  165. sw2_trans_z = -17;
  166. sw3_rot_x = -5;
  167. sw3_rot_z = 125 * (left_hand_version ? -1 : 1);
  168. sw3_trans_x = 0;
  169. sw3_trans_y = -base_dia / 2 - 0;
  170. sw3_trans_z = -17;
  171. sw4_rot_x = -5;
  172. sw4_rot_z = -125 * (left_hand_version ? -1 : 1);
  173. sw4_trans_x = 0;
  174. sw4_trans_y = -base_dia / 2 - 0;
  175. sw4_trans_z = -17;
  176. sw_mount_w = mx_co_w + 7;
  177. sw_mount_co_l = 10;
  178. bottom_base_wall = wall + 0.5;
  179. bottom_base_below_zero = bottom_base_wall + 4.5;
  180. pico_co_w = pico_w + 1;
  181. pico_co_l = pico_l + 1;
  182. reset_button_dia = 4.0;
  183. reset_button_off_x = 7;
  184. reset_button_off_y = 12.15;
  185. pico_support_w = 6.5;
  186. pico_support_l = 5;
  187. pico_screw_depth = 6;
  188. pico_screw_d = 1.8;
  189. usb_cutout_grow_l = 10;
  190. usb_cutout_grow_x = 20;
  191. usb_cutout_grow_y = 40;
  192. usb_cutout_w_add = 1;
  193. usb_cutout_h_add = 0.6;
  194. assembly_dist = 20;
  195. roller_holder_sider_cut = 1.5;
  196. roller_holder_h_compensation = -0.1;
  197. bottom_add_wall = 4;
  198. screw_dia = 3.2;
  199. screw_off = base_dia / 2 - 10;
  200. screw_head_d = 6.0;
  201. screw_head_h = 3.5;
  202. screw_angles = [ 15, -15, 180 + 15, 180 - 15 ];
  203. screw_insert_dia = 4.8;
  204. screw_insert_h = 6.0;
  205. function sphere_r_at_h(h, r) = r * sin(acos(h / r));
  206. function sphere_angle_at_rh(h, r) = acos(h / r);
  207. module mx_switch_cutout(h) {
  208. translate([-mx_co_w / 2 - mx_co_w_add, -mx_co_h / 2, 0]) {
  209. linear_extrude(h + 1) {
  210. translate([mx_co_w_add, 0]) {
  211. square([mx_co_w, mx_co_h]);
  212. for (x = [mx_co_r / 2, mx_co_w - mx_co_r / 2])
  213. for (y = [mx_co_r / 2, mx_co_h - mx_co_r / 2])
  214. translate([x, y])
  215. circle(r = mx_co_r);
  216. }
  217. for (x = [0, mx_co_w + mx_co_w_add])
  218. for (y = [0, mx_co_h_off_2 + mx_co_h_off_3])
  219. translate([x, mx_co_h_off_1 + y, 0])
  220. square([mx_co_w_add, mx_co_h_off_2]);
  221. }
  222. translate([mx_co_w_add - mx_co_b_add / 2, -mx_co_b_add / 2, -1])
  223. cube([mx_co_b_w, mx_co_b_h, h - mx_co_th + 1]);
  224. }
  225. }
  226. module mx_switch_test() {
  227. difference() {
  228. translate([-switch_test_w / 2, -switch_test_w / 2, 0])
  229. cube([switch_test_w, switch_test_w, wall]);
  230. mx_switch_cutout(wall);
  231. translate([0, -switch_test_w / 2 + 1, wall - 1.0])
  232. linear_extrude(1.1)
  233. text("switch test", size = 3, halign = "center");
  234. }
  235. %translate([0, 0, wall])
  236. rotate([0, 0, 180])
  237. mx_switch($t);
  238. }
  239. module pico_own() {
  240. translate([-pico_w / 2, -pico_l / 2, 0])
  241. difference() {
  242. union() {
  243. color("green")
  244. cube([pico_w, pico_l, pico_d]);
  245. translate([(pico_w - pico_usb_w) / 2, pico_l - pico_usb_d + pico_usb_off, pico_d])
  246. cube([pico_usb_w, pico_usb_d, pico_usb_h]);
  247. }
  248. for (x = [0, pico_hole_d_x])
  249. for (y = [0, pico_hole_d_y])
  250. translate([pico_hole_x + x, pico_hole_y + y, -1])
  251. cylinder(d = pico_hole_d, h = pico_d + 2);
  252. }
  253. }
  254. module pico_wrap() {
  255. //if (use_external_pico_model)
  256. translate([-pico_w / 2, -pico_l / 2, 0])
  257. pico();
  258. //else
  259. pico_own();
  260. }
  261. module sensor_lens_cutout_intern() {
  262. cylinder(d = sensor_lens_cutout_r * 2, h = $e);
  263. translate([-sensor_lens_cutout_r, 0, 0])
  264. cube([sensor_lens_cutout_r * 2, sensor_lens_cutout_w, $e]);
  265. }
  266. module rounded_cube(x, y, z, r) {
  267. hull()
  268. for (tx = [r, x - r])
  269. for (ty = [r, y - r])
  270. translate([tx, ty, 0])
  271. cylinder(d = r * 2, h = z);
  272. }
  273. module sensor_lens_cutout() {
  274. translate([0, 0, sensor_lens_cutout_to_chip])
  275. hull() {
  276. translate([0, 0, sensor_lens_baseplate_h - $e])
  277. sensor_lens_cutout_intern();
  278. scale(1 + sensor_lens_cutout_growth * sensor_lens_baseplate_h)
  279. sensor_lens_cutout_intern();
  280. }
  281. translate([-sensor_lens_d / 2, -sensor_lens_w + sensor_lens_off, 0])
  282. rounded_cube(sensor_lens_d, sensor_lens_w, sensor_lens_cutout_to_chip, 6);
  283. translate([-3 / 2, -sensor_lens_w + sensor_lens_off - 0.5, 0])
  284. cube([3, 0.5, sensor_lens_cutout_to_chip]);
  285. }
  286. module sensor() {
  287. translate([-sensor_w / 2, -sensor_l / 2, 0])
  288. difference() {
  289. color("green")
  290. cube([sensor_w, sensor_l, sensor_pcb_h]);
  291. translate([sensor_cut_off_x, sensor_cut_off_y, -1])
  292. cube([sensor_cut_w, sensor_cut_h, sensor_pcb_h + 2]);
  293. for (x = [0, sensor_hole_dist_x])
  294. for (y = [0, sensor_hole_dist_y])
  295. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, -1])
  296. cylinder(d = sensor_hole_dia, h = sensor_pcb_h + 2);
  297. }
  298. color("#303030")
  299. 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])
  300. cube([sensor_chip_w, sensor_chip_l, sensor_chip_h]);
  301. translate([0, -sensor_l / 2 - 15 * sensor_pin_pitch + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1, 0])
  302. for (p = [0 : 15])
  303. translate([0, p * sensor_pin_pitch, 0])
  304. for (x = [-sensor_pin_dist / 2, sensor_pin_dist / 2])
  305. if (((p % 2 == 0) && (x < 0))
  306. || ((p % 2 == 1) && (x > 0)))
  307. translate([-sensor_pin_d / 2 + x, -sensor_pin_w / 2, -sensor_chip_h + sensor_pin_off_top])
  308. cube([sensor_pin_d, sensor_pin_w, sensor_pin_h]);
  309. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, 0]) {
  310. color("cyan")
  311. translate([0, 0, -sensor_chip_h + 1])
  312. cylinder(d = 0.2, h = sensor_ball_to_chip_bottom - 1);
  313. %color("blue")
  314. sensor_lens_cutout();
  315. }
  316. }
  317. module ball_and_roller() {
  318. color("red")
  319. sphere(d = ball_dia, $fn = $fn * 2);
  320. for (r = [0 : roller_count - 1])
  321. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  322. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  323. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  324. translate([0, 0, -roller_dia / 2])
  325. roller_holder();
  326. }
  327. module roller_holder() {
  328. translate([0, 0, -roller_h + roller_dia / 2])
  329. difference() {
  330. color("magenta")
  331. union() {
  332. translate([0, 0, roller_h-roller_dia/2 + roller_ball_h_off-3])
  333. cylinder(d1 = roller_mount_dia, d2=roller_dia+1, h = 3);
  334. cylinder(d = roller_mount_dia, h = roller_h-roller_dia/2 + roller_ball_h_off-3);
  335. }
  336. translate([-roller_mount_dia / 2 - 1, roller_mount_dia / 2 - roller_holder_sider_cut, -1])
  337. cube([roller_mount_dia + 2, roller_mount_dia / 2 + 1, roller_h + 2]);
  338. translate([0, 0, -$e])
  339. cylinder(d = roller_thread_hole, h = $e+ roller_h - roller_dia / 2 + roller_ball_h_off + roller_ball_hold_off);
  340. translate([0, 0, roller_h - roller_dia / 2 + roller_holder_h_compensation])
  341. sphere(d = roller_dia, $fn = $fn * 2);
  342. if (cut_roller_holder)
  343. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
  344. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  345. }
  346. %color("blue")
  347. sphere(d = roller_dia, $fn = $fn * 2);
  348. }
  349. module roller_mount() {
  350. translate([0, 0, -1-roller_h + roller_dia / 2]) {
  351. difference() {
  352. cylinder(d=roller_mount_dia+wall,h=roller_h/2);
  353. translate([0, 0, 1])
  354. cylinder(d=roller_mount_dia+$c*2,h=roller_h/2+$e);
  355. if (cut_roller_holder)
  356. translate([-roller_thread_dia / 2 - 1, -roller_thread_dia, -1])
  357. cube([roller_thread_dia + 2, roller_thread_dia, roller_h + 2]);
  358. }
  359. }
  360. }
  361. module roller_mount_test() {
  362. roller_holder();
  363. roller_mount();
  364. }
  365. module roller_mount_tri_hull() {
  366. for (r = [0 : roller_count - 1])
  367. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  368. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  369. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  370. translate([0, 0, -roller_h])
  371. cylinder(d = roller_mount_dia + wall + 1, h = roller_h - 3);
  372. translate([0, 0, -ball_dia / 2 - 11])
  373. cylinder(d = base_dia, h = $e);
  374. }
  375. module roller_mount_tri_body() {
  376. // space for roller holder
  377. for (r = [0 : roller_count - 1])
  378. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  379. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  380. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  381. translate([0, 0, -roller_h])
  382. cylinder(d = roller_mount_dia + roller_mount_holder_gap, h = ball_dia / 2 + roller_h);
  383. // room for ball itself
  384. sphere($fn = $fn * 2, d = ball_dia + $c * 2 + 4);
  385. // grub screws
  386. for (r = [0 : roller_count - 1])
  387. rotate([0, 0, roller_mount_angle_off + 360 / roller_count * r])
  388. translate([sphere_r_at_h(roller_ball_h - ball_dia / 2, ball_dia / 2), 0, -ball_dia / 2 + roller_ball_h])
  389. rotate([0, 180 + sphere_angle_at_rh(roller_ball_h - ball_dia / 2, ball_dia / 2), 0])
  390. translate([0, 0, -roller_h/2])
  391. rotate([0,-90,0])
  392. translate([-2, 0, 2]) {
  393. cylinder(d = grub_screw_dia, h = ball_dia);
  394. translate([0, 0, roller_mount_dia / 4 + wall])
  395. cylinder(d = grub_channel_dia, h = ball_dia);
  396. }
  397. // sensor lens
  398. translate([0, 0, -ball_dia / 2 - ball_h])
  399. 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])
  400. translate([0, -sensor_l / 2 + sensor_cut_off_y + sensor_cut_h - sensor_cut_edge_to_pin1 - sensor_pin1_to_optical_center, 0])
  401. sensor_lens_cutout();
  402. // sensor pcb
  403. translate([-1, -1, -ball_dia / 2 - ball_h])
  404. 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])
  405. translate([-sensor_w / 2, -sensor_l / 2, -10])
  406. cube([sensor_w + 2, sensor_l + 2, sensor_pcb_h + 10 + sensor_pcb_mount_gap]);
  407. }
  408. module roller_mount_sensor_pcb_support() {
  409. translate([-sensor_w / 2, -sensor_l / 2, sensor_pcb_h])
  410. translate([0, 0, -ball_dia / 2 - ball_h])
  411. 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])
  412. for (x = [0, sensor_hole_dist_x])
  413. for (y = [0, sensor_hole_dist_y])
  414. translate([sensor_hole_off_x + x, sensor_hole_off_y + y, 0])
  415. difference() {
  416. union() {
  417. color("magenta")
  418. cylinder(d = sensor_hole_dia + 1.5, h = sensor_pcb_mount_gap);
  419. if (draw_supports)
  420. color("black")
  421. translate([0, 0, -sensor_pcb_support_h])
  422. cylinder(d = sensor_hole_dia + 0.5, h = sensor_pcb_support_h);
  423. }
  424. cylinder(d = sensor_hole_dia - 0.2, h = sensor_pcb_mount_gap + 1);
  425. }
  426. if (draw_supports)
  427. color("black")
  428. for (x = [-5, 0, 5])
  429. for (y = [-8, 0, 6.5])
  430. if (((x == 0) && (y != 0)) || ((x != 0) && (y == 0)))
  431. translate([x, y + 2, -30])
  432. cylinder(d = sensor_hole_dia + 0.5, h = 8.5);
  433. if (draw_sensor)
  434. %translate([0, 0, -ball_dia / 2 - ball_h])
  435. 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])
  436. sensor();
  437. }
  438. // TODO holes for pcb screws not going into body!!
  439. module roller_mount_tri() {
  440. if (draw_ball_roller)
  441. %ball_and_roller();
  442. difference() {
  443. hull()
  444. roller_mount_tri_hull();
  445. roller_mount_tri_body();
  446. // TODO test cable cutout
  447. translate([-6, 0, -30.1])
  448. cube([12, 50, 2]);
  449. if (cut_roller_holder)
  450. translate([0, -base_dia / 2 - 1, -40])
  451. cube([base_dia / 2 + 1, base_dia + 2, 40]);
  452. }
  453. roller_mount_sensor_pcb_support();
  454. }
  455. module trackball_top() {
  456. translate([0, 0, ball_dia / 2 + ball_h]) {
  457. if (draw_ball_roller)
  458. %ball_and_roller();
  459. difference() {
  460. color("orange")
  461. hull() {
  462. roller_mount_tri_hull();
  463. rotate([0, 0, sw1_rot_z])
  464. translate([sw1_trans_x, sw1_trans_y, sw1_trans_z])
  465. rotate([90 + sw1_rot_x, 0, 0])
  466. translate([0, 0, -0.5])
  467. cube([sw_mount_w, sw_mount_w, 1], center = true);
  468. rotate([0, 0, sw2_rot_z])
  469. translate([sw2_trans_x, sw2_trans_y, sw2_trans_z])
  470. rotate([90 + sw2_rot_x, 0, 0])
  471. translate([0, 0, -0.5])
  472. cube([sw_mount_w, sw_mount_w, 1], center = true);
  473. rotate([0, 0, sw3_rot_z])
  474. translate([sw3_trans_x, sw3_trans_y, sw3_trans_z])
  475. rotate([90 + sw3_rot_x, 0, 0])
  476. translate([0, 0, -0.5])
  477. cube([sw_mount_w, sw_mount_w, 1], center = true);
  478. rotate([0, 0, sw4_rot_z])
  479. translate([sw4_trans_x, sw4_trans_y, sw4_trans_z])
  480. rotate([90 + sw4_rot_x, 0, 0])
  481. translate([0, 0, -0.5])
  482. cube([sw_mount_w, sw_mount_w, 1], center = true);
  483. }
  484. roller_mount_tri_body();
  485. if (cut_roller_holder)
  486. translate([0, -base_dia / 2 - 1, -40])
  487. cube([base_dia / 2 + 1, base_dia + 2, 40]);
  488. rotate([0, 0, sw1_rot_z])
  489. translate([sw1_trans_x, sw1_trans_y, sw1_trans_z])
  490. rotate([90 + sw1_rot_x, 0, 0])
  491. translate([0, 0, -sw_mount_co_l]) {
  492. mx_switch_cutout(sw_mount_co_l + 1);
  493. translate([0, 0, 2])
  494. rotate([90, 0, 0])
  495. cylinder(d = 4, h = 20);
  496. }
  497. rotate([0, 0, sw2_rot_z])
  498. translate([sw2_trans_x, sw2_trans_y, sw2_trans_z])
  499. rotate([90 + sw2_rot_x, 0, 0])
  500. translate([0, 0, -sw_mount_co_l]) {
  501. mx_switch_cutout(sw_mount_co_l + 1);
  502. translate([0, 0, 2])
  503. rotate([90, 0, 0])
  504. cylinder(d = 4, h = 20);
  505. }
  506. rotate([0, 0, sw3_rot_z])
  507. translate([sw3_trans_x, sw3_trans_y, sw3_trans_z])
  508. rotate([90 + sw3_rot_x, 0, 0])
  509. translate([0, 0, -sw_mount_co_l]) {
  510. mx_switch_cutout(sw_mount_co_l + 1);
  511. translate([0, 0, 2])
  512. rotate([90, 0, 0])
  513. cylinder(d = 4, h = 20);
  514. }
  515. rotate([0, 0, sw4_rot_z])
  516. translate([sw4_trans_x, sw4_trans_y, sw4_trans_z])
  517. rotate([90 + sw4_rot_x, 0, 0])
  518. translate([0, 0, -sw_mount_co_l]) {
  519. mx_switch_cutout(sw_mount_co_l + 1);
  520. translate([0, 0, 2])
  521. rotate([90, 0, 0])
  522. cylinder(d = 4, h = 20);
  523. }
  524. /*
  525. hull() {
  526. rotate([0, 0, sw1_rot_z])
  527. translate([sw1_trans_x, sw1_trans_y, sw1_trans_z])
  528. rotate([90 + sw1_rot_x, 0, 0])
  529. translate([0, 0, -sw_mount_co_l + 5])
  530. mx_switch_cutout(sw_mount_co_l - 10);
  531. rotate([0, 0, sw2_rot_z])
  532. translate([sw2_trans_x, sw2_trans_y, sw2_trans_z])
  533. rotate([90 + sw2_rot_x, 0, 0])
  534. translate([0, 0, -sw_mount_co_l + 5])
  535. mx_switch_cutout(sw_mount_co_l - 10);
  536. }
  537. */
  538. for (r = screw_angles)
  539. rotate([0, 0, r])
  540. translate([screw_off, 0, -ball_dia / 2 - 11 -1]) {
  541. cylinder(d = screw_insert_dia, h = screw_insert_h + 1);
  542. }
  543. }
  544. roller_mount_sensor_pcb_support();
  545. if (draw_switches) {
  546. %rotate([0, 0, sw1_rot_z])
  547. translate([sw1_trans_x, sw1_trans_y, sw1_trans_z])
  548. rotate([90 + sw1_rot_x, 0, 0])
  549. mx_switch($t);
  550. %rotate([0, 0, sw2_rot_z])
  551. translate([sw2_trans_x, sw2_trans_y, sw2_trans_z])
  552. rotate([90 + sw2_rot_x, 0, 0])
  553. mx_switch($t);
  554. %rotate([0, 0, sw3_rot_z])
  555. translate([sw3_trans_x, sw3_trans_y, sw3_trans_z])
  556. rotate([90 + sw3_rot_x, 0, 0])
  557. mx_switch($t);
  558. %rotate([0, 0, sw4_rot_z])
  559. translate([sw4_trans_x, sw4_trans_y, sw4_trans_z])
  560. rotate([90 + sw4_rot_x, 0, 0])
  561. mx_switch($t);
  562. }
  563. }
  564. }
  565. module trackball_bottom_wrap() {
  566. %rotate([0, 180, 0])
  567. pico_wrap();
  568. color("magenta")
  569. translate([0, 0, -bottom_base_below_zero])
  570. difference() {
  571. cylinder(d = base_dia, h = bottom_base_below_zero + ball_h - 11);
  572. translate([0, 0, bottom_base_wall])
  573. cylinder(d = base_dia - bottom_base_wall * 2 - bottom_add_wall, h = bottom_base_below_zero + ball_h - 11);
  574. translate([-pico_co_w / 2, -pico_co_l / 2, bottom_base_wall])
  575. cube([pico_co_w, pico_co_l, bottom_base_below_zero + ball_h - 11]);
  576. translate([pico_w / 2 - reset_button_off_x, pico_l / 2 - reset_button_off_y, -1])
  577. cylinder(d = reset_button_dia, h = bottom_base_wall + 2);
  578. if (cut_roller_holder)
  579. translate([-base_dia / 2 - 1, -base_dia / 2 - 1, -10])
  580. cube([base_dia / 2 + 1, base_dia + 2, 40]);
  581. }
  582. color("cyan")
  583. for (x = [-1, 1])
  584. for (y = [-1, 1])
  585. translate([x * (pico_co_w - pico_support_w) / 2, y * (pico_co_l - pico_support_l) / 2, 0])
  586. translate([-pico_support_w / 2, -pico_support_l / 2, -bottom_base_below_zero + bottom_base_wall])
  587. cube([pico_support_w, pico_support_l, bottom_base_below_zero - bottom_base_wall - pico_d]);
  588. color("cyan")
  589. for (r = screw_angles)
  590. rotate([0, 0, r])
  591. translate([screw_off, 0, -bottom_base_below_zero + bottom_base_wall])
  592. cylinder(d = screw_head_d + 4, h = bottom_base_below_zero + ball_h - 11 - bottom_base_wall);
  593. }
  594. module usb_cutout() {
  595. hull() {
  596. translate([-usb_cutout_w_add / 2, 0, -usb_cutout_h_add / 2])
  597. cube([pico_usb_w + usb_cutout_w_add, 1, pico_usb_h + usb_cutout_h_add]);
  598. translate([-usb_cutout_grow_x / 2, usb_cutout_grow_l, -usb_cutout_grow_y / 2])
  599. cube([pico_usb_w + usb_cutout_grow_x, 1, pico_usb_h + usb_cutout_grow_y]);
  600. }
  601. }
  602. module trackball_bottom() {
  603. difference() {
  604. trackball_bottom_wrap();
  605. for (x = [0, pico_hole_d_x])
  606. for (y = [0, pico_hole_d_y])
  607. translate([-pico_w / 2, -pico_l / 2, 0])
  608. translate([pico_hole_x + x, pico_hole_y + y, -pico_d - pico_screw_depth])
  609. cylinder(d = pico_screw_d, h = pico_d + pico_screw_depth + 1);
  610. rotate([0, 180, 0])
  611. translate([-pico_w / 2, -pico_l / 2, 0])
  612. translate([(pico_w - pico_usb_w) / 2, pico_l - 1 + pico_usb_off, pico_d])
  613. usb_cutout();
  614. for (r = screw_angles)
  615. rotate([0, 0, r])
  616. translate([screw_off, 0, -bottom_base_below_zero - 1]) {
  617. cylinder(d = screw_dia, h = bottom_base_below_zero + 30);
  618. cylinder(d = screw_head_d, h = screw_head_h + 1);
  619. }
  620. }
  621. }
  622. module assembly() {
  623. translate([0, 0, assembly_dist / 2])
  624. trackball_top();
  625. translate([0, 0, -assembly_dist / 2])
  626. trackball_bottom();
  627. }
  628. module print() {
  629. translate([-40, 0, -4])
  630. trackball_top();
  631. translate([40, 0, bottom_base_below_zero])
  632. trackball_bottom();
  633. for (y = [-20, 0, 20])
  634. translate([0, y, 8.5])
  635. roller_holder();
  636. }