diff options
author | Tom Short <tshort.rlists@gmail.com> | 2017-03-02 16:53:03 -0500 |
---|---|---|
committer | Tom Short <tshort.rlists@gmail.com> | 2017-03-02 16:53:03 -0500 |
commit | 284ee475026cccb9945d4240c2345ad7e8d4755f (patch) | |
tree | ad1758ce27bfd936b9c8c7fc59f458a1ba68b223 /src/dactyl_keyboard | |
parent | e1ede3d95595bb8e03e8e2a064e0ba6f449946d8 (diff) |
First try at manuform layout
Diffstat (limited to 'src/dactyl_keyboard')
-rw-r--r-- | src/dactyl_keyboard/dactyl-manuform.clj | 405 |
1 files changed, 405 insertions, 0 deletions
diff --git a/src/dactyl_keyboard/dactyl-manuform.clj b/src/dactyl_keyboard/dactyl-manuform.clj new file mode 100644 index 0000000..49cae0d --- /dev/null +++ b/src/dactyl_keyboard/dactyl-manuform.clj @@ -0,0 +1,405 @@ +(ns dactyl-keyboard.dactyl + (:refer-clojure :exclude [use import]) + (:require [scad-clj.scad :refer :all] + [scad-clj.model :refer :all] + [unicode-math.core :refer :all])) + +;;;;;;;;;;;;;;;;; +;; Switch Hole ;; +;;;;;;;;;;;;;;;;; + +(def keyswitch-height 14.4) ;; Was 14.1, then 14.25 +(def keyswitch-width 14.4) + +(def sa-profile-key-height 12.7) + +(def plate-thickness 4) +(def mount-width (+ keyswitch-width 3)) +(def mount-height (+ keyswitch-height 3)) + +(def single-plate + (let [top-wall (->> (cube (+ keyswitch-width 3) 1.5 plate-thickness) + (translate [0 + (+ (/ 1.5 2) (/ keyswitch-height 2)) + (/ plate-thickness 2)])) + left-wall (->> (cube 1.5 (+ keyswitch-height 3) plate-thickness) + (translate [(+ (/ 1.5 2) (/ keyswitch-width 2)) + 0 + (/ plate-thickness 2)])) + side-nub (->> (binding [*fn* 30] (cylinder 1 2.75)) + (rotate (/ π 2) [1 0 0]) + (translate [(+ (/ keyswitch-width 2)) 0 1]) + (hull (->> (cube 1.5 2.75 plate-thickness) + (translate [(+ (/ 1.5 2) (/ keyswitch-width 2)) + 0 + (/ plate-thickness 2)])))) + plate-half (union top-wall left-wall (with-fn 100 side-nub))] + (union plate-half + (->> plate-half + (mirror [1 0 0]) + (mirror [0 1 0]))))) + +;;;;;;;;;;;;;;;; +;; SA Keycaps ;; +;;;;;;;;;;;;;;;; + +(def sa-length 18.25) +(def sa-double-length 37.5) +(def sa-cap {1 (let [bl2 (/ 18.5 2) + m (/ 17 2) + key-cap (hull (->> (polygon [[bl2 bl2] [bl2 (- bl2)] [(- bl2) (- bl2)] [(- bl2) bl2]]) + (extrude-linear {:height 0.1 :twist 0 :convexity 0}) + (translate [0 0 0.05])) + (->> (polygon [[m m] [m (- m)] [(- m) (- m)] [(- m) m]]) + (extrude-linear {:height 0.1 :twist 0 :convexity 0}) + (translate [0 0 6])) + (->> (polygon [[6 6] [6 -6] [-6 -6] [-6 6]]) + (extrude-linear {:height 0.1 :twist 0 :convexity 0}) + (translate [0 0 12])))] + (->> key-cap + (translate [0 0 (+ 5 plate-thickness)]) + (color [220/255 163/255 163/255 1]))) + 2 (let [bl2 (/ sa-double-length 2) + bw2 (/ 18.25 2) + key-cap (hull (->> (polygon [[bw2 bl2] [bw2 (- bl2)] [(- bw2) (- bl2)] [(- bw2) bl2]]) + (extrude-linear {:height 0.1 :twist 0 :convexity 0}) + (translate [0 0 0.05])) + (->> (polygon [[6 16] [6 -16] [-6 -16] [-6 16]]) + (extrude-linear {:height 0.1 :twist 0 :convexity 0}) + (translate [0 0 12])))] + (->> key-cap + (translate [0 0 (+ 5 plate-thickness)]) + (color [127/255 159/255 127/255 1]))) + 1.5 (let [bl2 (/ 18.25 2) + bw2 (/ 28 2) + key-cap (hull (->> (polygon [[bw2 bl2] [bw2 (- bl2)] [(- bw2) (- bl2)] [(- bw2) bl2]]) + (extrude-linear {:height 0.1 :twist 0 :convexity 0}) + (translate [0 0 0.05])) + (->> (polygon [[11 6] [-11 6] [-11 -6] [11 -6]]) + (extrude-linear {:height 0.1 :twist 0 :convexity 0}) + (translate [0 0 12])))] + (->> key-cap + (translate [0 0 (+ 5 plate-thickness)]) + (color [240/255 223/255 175/255 1])))}) + +;;;;;;;;;;;;;;;;;;;;;;;;; +;; Placement Functions ;; +;;;;;;;;;;;;;;;;;;;;;;;;; + +(def columns (range 0 6)) +(def rows (range 0 4)) + +(def α (/ π 12)) +(def β (/ π 26)) +(def cap-top-height (+ plate-thickness sa-profile-key-height)) +(def row-radius (+ (/ (/ (+ mount-height 1/2) 2) + (Math/sin (/ α 2))) + cap-top-height)) +(def column-radius (+ (/ (/ (+ mount-width 2.0) 2) + (Math/sin (/ β 2))) + cap-top-height)) + +(defn key-place [column row shape] + (let [row-placed-shape (->> shape + (translate [0 0 (- row-radius)]) + (rotate (* α (- 1 row)) [1 0 0]) ; controls front-back tilt + (translate [0 0 row-radius])) + column-offset (cond + (= column 2) [0 2.82 -4.5] + (>= column 4) [0 -5.8 5.64] + :else [0 0 0]) + column-angle (* β (- 3 column)) ; controls left-right tilt / tenting + placed-shape (->> row-placed-shape + (translate [0 0 (- column-radius)]) + (rotate column-angle [0 1 0]) + (translate [0 0 column-radius]) + (translate column-offset))] + (->> placed-shape + (rotate (/ π 12) [0 1 0]) + (translate [0 0 13])))) + +(defn case-place [column row shape] + (let [row-placed-shape (->> shape + (translate [0 0 (- row-radius)]) + (rotate (* α (- 1 row)) [1 0 0]) + (translate [0 0 row-radius])) + column-offset [0 -4.35 5.64] + column-angle (* β (- 3 column)) + placed-shape (->> row-placed-shape + (translate [0 0 (- column-radius)]) + (rotate column-angle [0 1 0]) + (translate [0 0 column-radius]) + (translate column-offset))] + (->> placed-shape + (rotate (/ π 12) [0 1 0]) + (translate [0 0 13])))) + +(def key-holes + (apply union + (for [column columns + row rows + :when (or (.contains [2 3] column) + (not= row (last rows)))] + (->> single-plate + (key-place column row))))) + +(def caps + (apply union + (for [column columns + row rows + :when (or (.contains [2 3] column) + (not= row (last rows)))] + (->> (sa-cap (if (= column 5) 1 1)) + (key-place column row))))) + +;;;;;;;;;;;;;;;;;;;; +;; Web Connectors ;; +;;;;;;;;;;;;;;;;;;;; + +(def web-thickness 3.5) +(def post-size 0.1) +(def web-post (->> (cube post-size post-size web-thickness) + (translate [0 0 (+ (/ web-thickness -2) + plate-thickness)]))) + +(def post-adj (/ post-size 2)) +(def web-post-tr (translate [(- (/ mount-width 2) post-adj) (- (/ mount-height 2) post-adj) 0] web-post)) +(def web-post-tl (translate [(+ (/ mount-width -2) post-adj) (- (/ mount-height 2) post-adj) 0] web-post)) +(def web-post-bl (translate [(+ (/ mount-width -2) post-adj) (+ (/ mount-height -2) post-adj) 0] web-post)) +(def web-post-br (translate [(- (/ mount-width 2) post-adj) (+ (/ mount-height -2) post-adj) 0] web-post)) + +(defn triangle-hulls [& shapes] + (apply union + (map (partial apply hull) + (partition 3 1 shapes)))) + +(def connectors + (apply union + (concat + ;; Row connections + (for [column (drop-last columns) + row rows + :when (or (.contains [2] column) + (not= row (last rows)))] + (triangle-hulls + (key-place (inc column) row web-post-tl) + (key-place column row web-post-tr) + (key-place (inc column) row web-post-bl) + (key-place column row web-post-br))) + + ;; Column connections + (for [column columns + row (drop-last rows) + ; :when (or (.contains [2 3] column) + ; (not= row 2)) + ] + (triangle-hulls + (key-place column row web-post-bl) + (key-place column row web-post-br) + (key-place column (inc row) web-post-tl) + (key-place column (inc row) web-post-tr))) + + ;; Diagonal connections + (for [column (drop-last columns) + row (drop-last rows) + ; :when (or (.contains [ 1 2 3] column) + ; (not= row 2)) + ] + (triangle-hulls + (key-place column row web-post-br) + (key-place column (inc row) web-post-tr) + (key-place (inc column) row web-post-bl) + (key-place (inc column) (inc row) web-post-tl)))))) + +;;;;;;;;;;;; +;; Thumbs ;; +;;;;;;;;;;;; +(def thumborigin [-25 -35 40]) + +(defn deg2rad [degrees] + (* (/ degrees 180) pi)) + +(defn thumb-a1-place [shape] + (->> shape + (rotate (deg2rad 10) [1 0 0]) + (rotate (deg2rad -23) [0 1 0]) + (rotate (deg2rad -3) [0 0 1]) + (translate thumborigin) + (translate [-16 -23 -3]) + )) +(defn thumb-a2-place [shape] + (->> shape + (rotate (deg2rad 15) [1 0 0]) + (rotate (deg2rad -35) [0 1 0]) + (rotate (deg2rad 54) [0 0 1]) + (translate thumborigin) + (translate [-28 -50 -16]) + )) +(defn thumb-a3-place [shape] + (->> shape + (rotate (deg2rad 6) [1 0 0]) + (rotate (deg2rad -34) [0 1 0]) + (rotate (deg2rad 74) [0 0 1]) + (translate thumborigin) + (translate [-35 -65 -27]))) +(defn thumb-b1-place [shape] + (->> shape + (rotate (deg2rad 10) [1 0 0]) + (rotate (deg2rad -23) [0 1 0]) + (rotate (deg2rad -3) [0 0 1]) + (translate thumborigin) + (translate [-36 -21 -5]))) +(defn thumb-b2-place [shape] + (->> shape + (rotate (deg2rad 6) [1 0 0]) + (rotate (deg2rad -34) [0 1 0]) + (rotate (deg2rad 70) [0 0 1]) + (translate thumborigin) + (translate [-51 -34 -16]) + )) +(defn thumb-b3-place [shape] + (->> shape + (rotate (deg2rad 3) [1 0 0]) + (rotate (deg2rad -35) [0 1 0]) + (rotate (deg2rad 52) [0 0 1]) + (translate thumborigin) + (translate [-55 -52 -28]) + )) + +(defn thumb-1x-layout [shape] + (union + (thumb-a2-place shape) + (thumb-a3-place shape) + (thumb-b2-place shape) + (thumb-b3-place shape))) + +(defn thumb-15x-layout [shape] + (union + (thumb-a1-place shape) + (thumb-b1-place shape))) + +(def larger-plate + (let [plate-height (/ (- sa-double-length mount-height) 3) + top-plate (->> (cube mount-width plate-height web-thickness) + (translate [0 (/ (+ plate-height mount-height) 2) + (- plate-thickness (/ web-thickness 2))])) + ] + (union top-plate (mirror [0 1 0] top-plate)))) + +(def thumbcaps + (union + (thumb-1x-layout (sa-cap 1)) + (thumb-15x-layout (rotate (/ π 2) [0 0 1] (sa-cap 1.5))))) + +(def thumb-connectors + (union + (apply union + (concat + (for [column [2] row [1]] + (triangle-hulls (thumb-place column row web-post-br) + (thumb-place column row web-post-tr) + (thumb-place (dec column) row web-post-bl) + (thumb-place (dec column) row web-post-tl))) + (for [column [2] row [0 1]] + (triangle-hulls + (thumb-place column row web-post-bl) + (thumb-place column row web-post-br) + (thumb-place column (dec row) web-post-tl) + (thumb-place column (dec row) web-post-tr))))) + (let [plate-height (/ (- sa-double-length mount-height) 2) + thumb-tl (->> web-post-tl + (translate [0 plate-height 0])) + thumb-bl (->> web-post-bl + (translate [0 (- plate-height) 0])) + thumb-tr (->> web-post-tr + (translate [0 plate-height 0])) + thumb-br (->> web-post-br + (translate [0 (- plate-height) 0]))] + (union + + ;;Connecting the two doubles + (triangle-hulls (thumb-place 0 -1/2 thumb-tl) + (thumb-place 0 -1/2 thumb-bl) + (thumb-place 1 -1/2 thumb-tr) + (thumb-place 1 -1/2 thumb-br)) + + ;;Connecting the double to the one above it + (triangle-hulls (thumb-place 1 -1/2 thumb-tr) + (thumb-place 1 -1/2 thumb-tl) + (thumb-place 1 1 web-post-br) + (thumb-place 1 1 web-post-bl)) + + ;;Connecting the 4 with the double in the bottom left + (triangle-hulls (thumb-place 1 1 web-post-bl) + (thumb-place 1 -1/2 thumb-tl) + (thumb-place 2 1 web-post-br) + (thumb-place 2 0 web-post-tr)) + + ;;Connecting the two singles with the middle double + (hull (thumb-place 1 -1/2 thumb-tl) + (thumb-place 1 -1/2 thumb-bl) + (thumb-place 2 0 web-post-br) + (thumb-place 2 -1 web-post-tr)) + (hull (thumb-place 1 -1/2 thumb-tl) + (thumb-place 2 0 web-post-tr) + (thumb-place 2 0 web-post-br)) + (hull (thumb-place 1 -1/2 thumb-bl) + (thumb-place 2 -1 web-post-tr) + (thumb-place 2 -1 web-post-br)) + + ;;Connecting the thumb to everything + (triangle-hulls (thumb-place 0 -1/2 thumb-br) + (key-place 1 4 web-post-bl) + (thumb-place 0 -1/2 thumb-tr) + (key-place 1 4 web-post-tl) + (key-place 1 3 web-post-bl) + (thumb-place 0 -1/2 thumb-tr) + (key-place 0 3 web-post-br) + (key-place 0 3 web-post-bl) + (thumb-place 0 -1/2 thumb-tr) + (thumb-place 0 -1/2 thumb-tl) + (key-place 0 3 web-post-bl) + (thumb-place 1 -1/2 thumb-tr) + (thumb-place 1 1 web-post-br) + (key-place 0 3 web-post-bl) + (key-place 0 3 web-post-tl) + (thumb-place 1 1 web-post-br) + (thumb-place 1 1 web-post-tr)) + (hull (thumb-place 0 -1/2 web-post-tr) + (thumb-place 0 -1/2 thumb-tr) + (key-place 1 4 web-post-bl) + (key-place 1 4 web-post-tl)))))) + +(def thumb + (union +; thumb-connectors + thumbcaps + (thumb-1x-layout single-plate) + (thumb-15x-layout single-plate) + (thumb-15x-layout larger-plate) + )) + +(spit "repl.scad" + (write-scad (union + key-holes + connectors + caps + thumb + ; thumbcaps + ; front-wall + ; right-wall + ; new-case + ))) + +;;;;;;;;;; +;; Case ;; +;;;;;;;;;; + +;; In column units +(def right-wall-column (+ (last columns) 0.55)) +(def left-wall-column (- (first columns) 1/2)) +(def thumb-back-y 0.93) +(def thumb-right-wall (- -1/2 0.05)) +(def thumb-front-row (+ -1 0.07)) +(def thumb-left-wall-column (+ 5/2 0.05)) +(def back-y 0.02) |