-
Notifications
You must be signed in to change notification settings - Fork 18
/
mx-knob.scad
197 lines (171 loc) · 6.56 KB
/
mx-knob.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* Copyright (c) 2019, Gilles Bouissac
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* Description: Knob modelisation
* Author: Gilles Bouissac
*/
use <mx-screw.scad>
use <bevel.scad>
// ----------------------------------------
//
// API
//
// ----------------------------------------
MFG = 0.01; // ManiFold Guard
VGG = 1; // Visual Glich Guard
MARGIN = 0.2;
NOZZLE = 0.4;
CAP_GRIP = 0.3; // Amount of overlap between cap grips and knob handle
HANDLE_CAP_GAP = 10;
// Knob that for mx hexagonal screw
// - screw: the screw: M2(), M3() etc...
// - diameter: required diameter, can be larger if the screw don't fit
// computed from screw dimensions if -1
// - height: required total height, can be larger if the screw don't fit
// computed from screw dimensions if -1
// - cap_height: required total height for the fap
// computed if -1
module mxKnob( screw, diameter=-1, height=-1, part=0, cap_height=-1 ) {
bottom_t = mxGetHeadDP(screw)/3;
wall_t = mxGetHeadDP(screw)/4;
base_h = mxGetHexagonalHeadL(screw)+bottom_t;
base_r = mxGetHeadDP(screw)/2+wall_t/2;
knob_h_min = mxGetHeadDP(screw) + wall_t;
knob_r_min = mxGetHeadDP(screw)/2+2*wall_t/2;
knob_h = height>knob_h_min ? height : knob_h_min;
knob_r = diameter/2>knob_r_min ? diameter/2 : knob_r_min;
cap_r = min(knob_r-wall_t,base_r);
cap_h = cap_height==-1 ? min(cap_r, knob_h-base_h-NOZZLE) : cap_height;
if ( part==0 ) {
translate( [0,0,knob_h+min(HANDLE_CAP_GAP,cap_h)] )
color ( "white" )
mxKnobCap ( cap_r, cap_h, screw, wall_t );
mxKnobHandle ( knob_r, knob_h, bottom_t, base_r, base_h, cap_r, cap_h, screw, wall_t );
}
if ( part==1 ) {
mxKnobHandle ( knob_r, knob_h, bottom_t, base_r, base_h, cap_r, cap_h, screw, wall_t );
%translate( [0,0,knob_h-cap_h] )
mxKnobCap ( cap_r, cap_h, screw, wall_t );
}
if ( part==2 ) {
rotate( [180,0,0] ) {
translate( [0,0,-cap_h] )
mxKnobCap ( cap_r, cap_h, screw, wall_t );
%
translate( [0,0,-knob_h] )
mxKnobHandle ( knob_r, knob_h, bottom_t, base_r, base_h, cap_r, cap_h, screw, wall_t );
}
}
if ( part==3 ) {
// Special rendering, the cap in the knob
translate( [0,0,knob_h-cap_h] )
color ( "white" )
mxKnobCap ( cap_r, cap_h, screw, wall_t );
mxKnobHandle ( knob_r, knob_h, bottom_t, base_r, base_h, cap_r, cap_h, screw, wall_t );
}
}
// ----------------------------------------
//
// Implementation
//
// ----------------------------------------
// Complete knob handle
module mxKnobHandle ( knob_r, knob_h, base_t, base_r, base_h, cap_r, cap_h, screw, wall_t ) {
difference() {
mxKnobHandleShape ( knob_r, knob_h, cap_r, screw, wall_t );
mxKnobHandleHoles ( knob_r, knob_h, cap_r, screw, wall_t );
translate( [0,0,knob_h-cap_h] )
mxKnobCapPassage ( cap_r, cap_h, wall_t );
}
mxKnobBase ( base_r, base_h, screw, base_t, wall_t);
}
// Knob base with inlay for the screw
// - thickness: wall thickness
module mxKnobBase ( base_r, base_h, screw, bottom_t, wall_t ) {
difference() {
cylinder( r=base_r, h=base_h );
translate( [0,0,bottom_t+MFG] )
rotate( [180,0,0] )
mxBoltHexagonalPassage( screw );
translate( [base_r,base_r,+base_h] )
bevelCutArc( base_r-MFG, 2*base_h, 360 ) ;
}
}
// Knob handle with screw passage and grips
module mxKnobHandleShape ( knob_r, knob_h, cap_r, screw, thickness ) {
sphere_r = knob_r*1.2;
intersection() {
cylinder( r=knob_r, h=knob_h );
translate( [0,0,sphere_r+thickness/2] ) {
sphere( r=sphere_r );
cylinder( r=sphere_r, h=knob_h );
}
}
}
// Knob handle with screw passage and grips
module mxKnobHandleHoles ( knob_r, knob_h, cap_r, screw, thickness ) {
grip_d = mxGetThreadD(screw);
grip_nb = 9;
// Main hole
cylinder( r=cap_r, h=knob_h+MFG );
// Beveling of top part
translate( [knob_r,knob_r,0] )
bevelCutArc( knob_r-MFG, 2*knob_h, 360,
$bevel=thickness*2/3,
$bevelProfile=bevelArc() ) ;
// Handle grips
for ( a=[0:360/grip_nb:360] ) {
rotate( [0,0,a] )
translate( [knob_r+grip_d/3,0,0] )
cylinder( r=grip_d/2, h=knob_h+VGG );
}
}
// Knob cap
module mxKnobCap ( cap_r, cap_h, screw, thickness ) {
local_cap_r1 = cap_r-MARGIN;
local_cap_r2 = local_cap_r1+thickness/3;
local_scale = local_cap_r2/local_cap_r1;
cap_thickness = 4*NOZZLE;
difference() {
union() {
// Main shape
cylinder( r=local_cap_r1, h=cap_h );
// Top hat
translate( [0,0,cap_h-thickness] )
linear_extrude( height=thickness, scale=local_scale )
circle( r=local_cap_r1 );
// Grips
for ( a=[0:120:360] )
rotate( [0,0,a] )
translate( [cap_r-cap_thickness/2+CAP_GRIP,0,0] )
cylinder( r=cap_thickness/2, h=cap_h );
}
// Main hole
cylinder( r=local_cap_r1-cap_thickness, h=cap_h-thickness );
// Final beveling of bottom part
translate( [local_cap_r2,local_cap_r2,cap_h] )
bevelCutArc( local_cap_r2-MFG, 2*cap_h, 360, $bevel=thickness/3+0.5 ) ;
}
// Pole to keep the screw in place
// This allow as well to pull up the cap by pushing back the screw
cylinder( r=mxGetThreadD(screw)/2, h=cap_h );
}
module mxKnobCapPassage ( cap_r, cap_h, thickness ) {
local_cap_r = cap_r;
local_scale = (local_cap_r+thickness/3)/local_cap_r;
cylinder( r=local_cap_r, h=cap_h );
translate( [0,0,cap_h-thickness] )
linear_extrude( height=thickness+MFG, scale=local_scale )
circle( r=local_cap_r );
}
// ----------------------------------------
//
// Showcase
//
// ----------------------------------------
mxKnob ( M6(), part=0, $fn=100 );