Browse Source

first version of extruder gearbox working.

Thomas Buck 2 years ago
parent
commit
306b8dc78b
14 changed files with 996 additions and 367 deletions
  1. 115
    4
      hardware/common.scad
  2. 32
    28
      hardware/config.scad
  3. 43
    0
      hardware/dispenser.scad
  4. 2
    15
      hardware/fuellfix.scad
  5. 370
    87
      hardware/gearbox.scad
  6. 193
    128
      hardware/table.scad
  7. 16
    18
      include/config.h
  8. 6
    15
      include/config_pins.h
  9. 1
    1
      include/statemachine.h
  10. 10
    4
      src/lcd.cpp
  11. 9
    2
      src/main.cpp
  12. 14
    5
      src/sm_value.cpp
  13. 119
    12
      src/states.cpp
  14. 66
    48
      src/steppers.cpp

+ 115
- 4
hardware/common.scad View File

@@ -122,6 +122,117 @@ module nema17(length) {
122 122
     }
123 123
 }
124 124
 
125
+module endstop_pcb() {
126
+    difference() {
127
+        cube([endstop_pcb_width, endstop_pcb_depth, endstop_pcb_height]);
128
+        
129
+        for (i = [0, 1])
130
+        translate([endstop_pcb_hole_dist_x, -1, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
131
+        rotate([-90, 0, 0])
132
+        cylinder(d = endstop_pcb_hole, h = endstop_pcb_depth + 2);
133
+    }
134
+    
135
+    translate([0, 0, endstop_pcb_height - endstop_pcb_switchpoint])
136
+    rotate([0, -90, 0])
137
+    cylinder(d = endstop_pcb_hole, h = endstop_pcb_switchpoint);
138
+}
139
+
140
+module endstop_mount_v1() {
141
+    %color("yellow")
142
+    translate([-endstop_pcb_mount_off_w, -endstop_pcb_depth - endstop_pcb_mount_off_d, endstop_pcb_mount_off_h])
143
+    endstop_pcb();
144
+    
145
+    color("blue")
146
+    difference() {
147
+        cube([endstop_mount_width, endstop_mount_depth, 40]);
148
+        
149
+        for (i = [0, 1])
150
+        translate([endstop_mount_width / 2, -1, 10 + 20 * i])
151
+        rotate([-90, 0, 0])
152
+        cylinder(d = motor_mount_hole_size, h = endstop_mount_depth + 2);
153
+    }
154
+    
155
+    color("blue")
156
+    difference() {
157
+        union() {
158
+            hull() {
159
+                translate([-endstop_mount_slot_length, 0, 40 - endstop_mount_add_height])
160
+                cube([endstop_mount_slot_length, endstop_mount_depth, endstop_mount_add_height]);
161
+                
162
+                for (i = [0, 1])
163
+                translate([0, 0, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
164
+                translate([-endstop_pcb_mount_off_w, -endstop_pcb_mount_off_d, endstop_pcb_mount_off_h - endstop_mount_slot_width / 2])
165
+                cube([endstop_mount_slot_length, endstop_mount_slot_depth, endstop_mount_slot_width]);
166
+            }
167
+        }
168
+        
169
+        translate([-endstop_pcb_mount_off_w, -endstop_pcb_depth - endstop_pcb_mount_off_d, endstop_pcb_mount_off_h])
170
+        for (i = [0, 1])
171
+        translate([endstop_pcb_hole_dist_x, -1, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
172
+        rotate([-90, 0, 0]) {
173
+            cylinder(d = endstop_pcb_hole, h = endstop_pcb_depth + 20);
174
+            
175
+            translate([0, 0, 1 + endstop_pcb_depth + endstop_mount_slot_depth])
176
+            cylinder(d = endstop_mount_nut_hole, h = 20, $fn = 6);
177
+        }
178
+    }
179
+}
180
+
181
+module endstop_mount_v2() {
182
+    %color("yellow")
183
+    translate([-endstop_pcb_mount_off_w, -endstop_pcb_depth - endstop_pcb_mount_off_d, endstop_pcb_mount_off_h])
184
+    endstop_pcb();
185
+    
186
+    color("blue")
187
+    difference() {
188
+        cube([endstop_mount_width, endstop_mount_depth, 40]);
189
+        
190
+        for (i = [0, 1])
191
+        translate([endstop_mount_width / 2, -1, 10 + 20 * i])
192
+        rotate([-90, 0, 0])
193
+        cylinder(d = motor_mount_hole_size, h = endstop_mount_depth + 2);
194
+    }
195
+    
196
+    color("blue")
197
+    difference() {
198
+        union() {
199
+            hull() {
200
+                translate([-endstop_mount_slot_length, 0, 40 - endstop_mount_add_height])
201
+                cube([endstop_mount_slot_length, endstop_mount_depth, endstop_mount_add_height]);
202
+                
203
+                translate([0, 0, endstop_pcb_height - endstop_pcb_hole_dist_y - endstop_pcb_hole_dist])
204
+                translate([-endstop_pcb_mount_off_w, -endstop_pcb_mount_off_d, endstop_pcb_mount_off_h - endstop_mount_slot_width / 2])
205
+                cube([endstop_mount_slot_length, endstop_mount_slot_depth, endstop_mount_slot_width]);
206
+            }
207
+            
208
+            hull() {
209
+                for (i = [0, 1])
210
+                translate([0, 0, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
211
+                translate([-endstop_pcb_mount_off_w, -endstop_pcb_mount_off_d, endstop_pcb_mount_off_h - endstop_mount_slot_width / 2])
212
+                cube([endstop_mount_slot_length, endstop_mount_slot_depth, endstop_mount_slot_width]);
213
+            }
214
+        }
215
+        
216
+        translate([-endstop_pcb_mount_off_w, -endstop_pcb_depth - endstop_pcb_mount_off_d, endstop_pcb_mount_off_h])
217
+        for (i = [0, 1])
218
+        translate([endstop_pcb_hole_dist_x, -1, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
219
+        rotate([-90, 0, 0]) {
220
+            cylinder(d = endstop_pcb_hole, h = endstop_pcb_depth + 20);
221
+            
222
+            translate([0, 0, 1 + endstop_pcb_depth + endstop_mount_slot_depth])
223
+            cylinder(d = endstop_mount_nut_hole, h = 20, $fn = 6);
224
+        }
225
+    }
226
+}
227
+
228
+module endstop_mount() {
229
+    if (use_endstop_mount_v2) {
230
+        endstop_mount_v2();
231
+    } else {
232
+        endstop_mount_v1();
233
+    }
234
+}
235
+
125 236
 module dispenser_arm() {
126 237
     translate([0, dispenser_arm_tab_off, dispenser_arm_tab_hole_off])
127 238
     rotate([90, 0, 0])
@@ -176,11 +287,11 @@ module dispenser() {
176 287
     cylinder(d = dispenser_handle_dia, h = dispenser_handle_length);
177 288
     
178 289
     translate([0, dispenser_top_dia / 2 + dispenser_arm_handle_y, dispenser_nozzle_end_length + dispenser_nozzle_cap_height + dispenser_nozzle_mid_height + dispenser_nozzle_top_height + dispenser_top_height + dispenser_arm_handle_z])
179
-    rotate([dispenser_arm_angle_bottom + anim_pos_extruder * (dispenser_arm_angle_top - dispenser_arm_angle_bottom), 0, 0])
290
+    rotate([dispenser_arm_angle_bottom + (-anim_pos_extruder + 1) * (dispenser_arm_angle_top - dispenser_arm_angle_bottom), 0, 0])
180 291
     dispenser_arm();
181 292
 }
182 293
 
183
-dispenser_arm_angle_top = -5;
184
-dispenser_arm_angle_bottom = 6;
294
+//endstop_pcb();
295
+endstop_mount();
185 296
 
186
-dispenser();
297
+//dispenser();

+ 32
- 28
hardware/config.scad View File

@@ -1,6 +1,9 @@
1 1
 // 3d printer specific
2 2
 screw_gap = 0.3;
3
-nut_gap = -0.1;
3
+nut_gap = -0.2;
4
+
5
+dispenser_rim_dia = 210; // TODO
6
+dispenser_rim_height = 2.0; // TODO
4 7
 
5 8
 dispenser_top_dia = 200;
6 9
 dispenser_top_height = 108;
@@ -19,6 +22,7 @@ dispenser_wall = 3;
19 22
 dispenser_handle_dia = 21;
20 23
 dispenser_handle_length = 100;
21 24
 dispenser_handle_angle = 38;
25
+dispenser_height = dispenser_top_height + dispenser_nozzle_top_height + dispenser_nozzle_mid_height + dispenser_nozzle_cap_height + dispenser_nozzle_end_length;
22 26
 
23 27
 dispenser_arm_dia = 7.0;
24 28
 dispenser_arm_len = 250;
@@ -32,6 +36,21 @@ dispenser_arm_handle_height = 2;
32 36
 dispenser_arm_handle_y = 10;
33 37
 dispenser_arm_handle_z = 15;
34 38
 
39
+dispenser_arm_angle_top = -5;
40
+dispenser_arm_angle_bottom = 6;
41
+
42
+disp_mount_wall = 20;
43
+disp_mount_overlap_x = 50;
44
+disp_mount_overlap_y = 40;
45
+disp_mount_add_x = 20;
46
+disp_mount_add_y = 50;
47
+disp_mount_width = dispenser_rim_dia / 2 - disp_mount_overlap_x + disp_mount_add_x;
48
+disp_mount_len = dispenser_rim_dia / 2 + disp_mount_overlap_y + disp_mount_add_y;
49
+disp_mount_off_x = dispenser_rim_dia / 2 - disp_mount_overlap_x;
50
+disp_mount_off_y = disp_mount_overlap_y;
51
+
52
+dispenser_mount_rail_off = dispenser_rim_dia / 2 + disp_mount_add_y;
53
+
35 54
 rail_wheel_height = 11;
36 55
 rail_wheel_center_height = 5;
37 56
 rail_wheel_outer = 24;
@@ -91,7 +110,9 @@ belt_length_center = belt_length - belt_length_wheels;
91 110
 gears_dist = belt_length_center / 2;
92 111
 
93 112
 gear_stages = 1;
94
-gear_stage_height = pulley_height + 2;
113
+
114
+// allow room for metal pulleys
115
+gear_stage_height = pulley_height + 15;
95 116
 
96 117
 gear_stages_dist = (bearing_height + 1) * 2;
97 118
 gearbox_wall = gear_stages_dist; //bearing_height + 1;
@@ -101,31 +122,15 @@ gearbox_height = gears_dist + large_dia + (gearbox_wall + gearbox_gap) * 2;
101 122
 gearbox_width = large_dia + (gearbox_wall + gearbox_gap) * 2;
102 123
 gearbox_depth = 2 * gearbox_wall + gear_stages * gear_stage_height + (gear_stages - 1) * gear_stages_dist;
103 124
 
104
-extruder_travel = 60;
105
-
106
-piston_dia = 30;
107
-piston_height = 30;
108
-piston_gap = 0.1;
109
-piston_wall = 3;
110
-piston_radius = 3;
111
-piston_bottom_gap = piston_wall + 10;
112
-cylinder_dia = piston_dia + 2 * (piston_wall + piston_gap);
113
-cylinder_height = piston_height + extruder_travel;
114
-
115
-actuator_length = 100;
116
-
117
-extruder_lever_width = 10;
118
-extruder_lever_depth = 5;
119
-extruder_lever_holes = 4.2; // TODO
120
-extruder_lever_hole_dist = extruder_travel / 2;
121
-extruder_lever_length = extruder_lever_hole_dist + 10;
125
+echo("gearbox_depth", gearbox_depth);
122 126
 
127
+extruder_travel = 60;
123 128
 extruder_wall_screw = 3.0;
124
-extruder_wall_hole_screw = extruder_wall_screw + screw_gap;
125
-extruder_wall_hole_nut = extruder_wall_screw + nut_gap;
126
-extruder_wall_hole_depth = 8.0;
129
+extruder_use_threaded_rods = true;
127 130
 
128
-additional_piston_offset = 8;
131
+extruder_wall_hole_screw = extruder_wall_screw + screw_gap;
132
+extruder_wall_hole_nut = extruder_use_threaded_rods ? extruder_wall_hole_screw : (extruder_wall_screw + nut_gap);
133
+extruder_wall_hole_depth = extruder_use_threaded_rods ? gearbox_height : 8.0;
129 134
 
130 135
 /***********************************
131 136
  ************** Table **************
@@ -226,7 +231,7 @@ x_axis_rail_len = x_axis_travel_len + y_carriage_y + motor_mount_length + belt_t
226 231
 point_that_reaches_everywhere_x = -7.5;
227 232
 point_that_reaches_everywhere_y = -17.5;
228 233
 
229
-use_anim = false;
234
+use_anim = true;
230 235
 x_axis_position = 1.0;
231 236
 y_axis_position = 0.5;
232 237
 
@@ -238,10 +243,9 @@ echo("animation position y", anim_pos_y);
238 243
 x_axis_animation_position = anim_pos_x * x_axis_travel_len;
239 244
 y_axis_animation_position = anim_pos_y * y_axis_travel_len;
240 245
 
241
-extruder_axis_position = 1.0;
246
+extruder_axis_position = 0.0;
242 247
 
243
-anim_pos_extruder = use_anim ? sin($t * 360) * 0.5 + 0.5 : extruder_axis_position;
244
-extruder_axis_anim_position = anim_pos_extruder * extruder_travel;
248
+anim_pos_extruder = use_anim ? -cos($t * 360) * 0.5 + 0.5 : extruder_axis_position;
245 249
 
246 250
 draw_pulleys = false;
247 251
 

+ 43
- 0
hardware/dispenser.scad View File

@@ -0,0 +1,43 @@
1
+include <config.scad>;
2
+use <gearbox.scad>;
3
+use <common.scad>;
4
+
5
+module dispenser_mount() {
6
+    difference() {
7
+        color("green")
8
+        cube([disp_mount_width, disp_mount_len, disp_mount_wall]);
9
+        
10
+        translate([-disp_mount_off_x, disp_mount_off_y, 0]) {
11
+            translate([0, 0, -1])
12
+            cylinder(d = dispenser_top_dia, h = disp_mount_wall + 2, $fn = 100);
13
+            
14
+            translate([0, 0, disp_mount_wall - dispenser_rim_height])
15
+            cylinder(d = dispenser_rim_dia, h = dispenser_rim_height + 1, $fn = 100);
16
+        }
17
+    }
18
+}
19
+
20
+disp_rail_len = 2 * (disp_mount_width + disp_mount_off_x);
21
+disp_mount_height = dispenser_height - disp_mount_wall + dispenser_rim_height;
22
+
23
+module dispenser_assembly() {
24
+    %color("magenta")
25
+    dispenser();
26
+    
27
+    translate([0, 0, disp_mount_height + 130])
28
+    extruder();
29
+    
30
+    for (i = [-1, 1])
31
+    scale([i, 1, 1])
32
+    translate([disp_mount_off_x, -disp_mount_off_y, disp_mount_height])
33
+    dispenser_mount();
34
+    
35
+    translate([-disp_rail_len / 2, dispenser_mount_rail_off, disp_mount_height])
36
+    rail_2020_x(disp_rail_len, "dispenser mount base rail");
37
+    
38
+    for (i = [-1, 1])
39
+    translate([i * disp_rail_len / 2 - ((i + 1) / 2) * 20, -disp_mount_off_y, disp_mount_height - 20])
40
+    rail_2020_y(disp_mount_len + 20, "dispenser mount arm rail");
41
+}
42
+
43
+dispenser_assembly();

+ 2
- 15
hardware/fuellfix.scad View File

@@ -1,7 +1,7 @@
1 1
 include <config.scad>;
2 2
 use <table.scad>;
3
-use <gearbox.scad>;
4 3
 use <common.scad>;
4
+use <dispenser.scad>;
5 5
 
6 6
 draw_assembly = true;
7 7
 
@@ -50,23 +50,10 @@ module print() {
50 50
     endstop_mount();
51 51
 }
52 52
 
53
-top_rail_len = x_axis_rail_len + plate_x - 70;
54
-top_rail_height = 200;
55
-top_rail_off = 150;
56
-
57
-echo("top rail length", top_rail_len);
58
-
59 53
 module fuellfix_assembly() {
60 54
     xy_table();
61 55
     
62
-    %color("magenta")
63
-    dispenser();
64
-    
65
-    translate([0, 0, 200 + 100])
66
-    whole_extruder();
67
-    
68
-    translate([-top_rail_len / 2, top_rail_off, top_rail_height])
69
-    rail_2020_x(top_rail_len, "top rail");
56
+    dispenser_assembly();
70 57
 }
71 58
 
72 59
 echo(); echo(); echo();    

+ 370
- 87
hardware/gearbox.scad View File

@@ -2,10 +2,75 @@ include <config.scad>;
2 2
 use <gt2_pulley.scad>;
3 3
 use <common.scad>
4 4
 
5
+extruder_slot_gap_vert = 1;
6
+extruder_slot_gap_horz = 2;
7
+
8
+extruder_real_nut_dia = 6.3;
9
+extruder_add_nut_height = 5.0;
10
+
11
+extruder_arm_dia = extruder_travel + extruder_slot_gap_vert;
12
+extruder_arm_post_dia = 9.5;
13
+extruder_arm_width = 15.0;
14
+extruder_arm_axis_dia = 20.0;
15
+extruder_arm_flare_off = 3.0;
16
+extruder_arm_axis_h = 10.0;
17
+extruder_arm_post_h = 20.0;
18
+extruder_arm_off = 10;
19
+
20
+actuator_slot_w = extruder_arm_dia + bearing_outer + extruder_slot_gap_horz;
21
+actuator_slot_h = bearing_outer + extruder_slot_gap_vert;
22
+actuator_width = actuator_slot_w + 20;
23
+actuator_height = actuator_slot_h + 20;
24
+actuator_wall = bearing_height + 2;
25
+
26
+actuator_rod_len = 100;
27
+actuator_rod_len_add_bottom = 50;
28
+
29
+show_extruder_maximum_positions = false;
30
+extruder_maximum_positions = 12;
31
+
32
+linear_bearing_inner = 8.2;
33
+linear_bearing_outer = 15.0;
34
+linear_bearing_height = 25.0;
35
+
36
+linear_mount_inner = linear_bearing_outer + 0.5;
37
+linear_mount_wall = 3.0;
38
+linear_mount_outer = linear_mount_inner + 2 * linear_mount_wall;
39
+linear_mount_height = linear_bearing_height;
40
+linear_mount_width = 40.0;
41
+linear_mount_cut = 5.0;
42
+linear_mount_tab_off = linear_mount_wall;
43
+linear_mount_tab_width = 7.0;
44
+
45
+linear_mount_add_width = 8.0;
46
+linear_mount_add_height = 35.0;
47
+
48
+actuator_rod = 8.0;
49
+actuator_rod_wall = 2.5;
50
+actuator_rod_width = actuator_rod + 2 * actuator_rod_wall;
51
+actuator_rod_h = 6.0;
52
+actuator_rod_inset = 3.0;
53
+actuator_bearing_off = 12.5;
54
+actuator_bearing_dist = extruder_arm_off + extruder_arm_post_h - actuator_wall + actuator_rod_width - 1.5; // TODO not correct formula, but matches for now
55
+
56
+gearbox_spacer = gearbox_wall / 2;
57
+
58
+gb_endstop_off = 21;
59
+gb_endstop_slit_len = 1.0;
60
+
5 61
 $fn = 42;
6 62
 
7 63
 echo("extruder gear factor", pow(large_teeth / small_teeth, gear_stages));
8 64
 
65
+module linear_bearing() {
66
+    difference() {
67
+        cylinder(d = linear_bearing_outer, h = linear_bearing_height);
68
+        
69
+        translate([0, 0, -1])
70
+        cylinder(d = linear_bearing_inner + 1, h = linear_bearing_height + 2);
71
+    }
72
+}
73
+
9 74
 module gear_pulley(dia, teeth) {
10 75
     if (draw_pulleys) {
11 76
         gt2_2mm_pulley(teeth, pulley_teeth_height);
@@ -64,18 +129,25 @@ module outer_plate() {
64 129
     }
65 130
 }
66 131
 
67
-module gearbox() {
68
-    // back wall
69
-    color("cyan")
70
-    translate([-gearbox_width / 2, -gearbox_height / 2, -gearbox_wall])
71
-    outer_plate();
72
-    
73
-    // front wall
74
-    color("cyan")
75
-    translate([-gearbox_width / 2, -gearbox_height / 2, gear_stage_height * gear_stages + gear_stages_dist * (gear_stages - 1)])
132
+module gb_front_wall() {
76 133
     difference() {
134
+        color("cyan")
135
+        translate([-gearbox_width / 2, -gearbox_height / 2, -gearbox_wall])
77 136
         outer_plate();
78 137
         
138
+        for (i = [-1, 1])
139
+        translate([0, i * gears_dist / 2, -bearing_height])
140
+        outer_bearings();
141
+    }
142
+}
143
+
144
+module gb_back_wall() {
145
+    difference() {
146
+        color("cyan")
147
+        translate([-gearbox_width / 2, -gearbox_height / 2, gear_stage_height * gear_stages + gear_stages_dist * (gear_stages - 1)])
148
+        outer_plate();
149
+        
150
+        translate([-gearbox_width / 2, -gearbox_height / 2, gear_stage_height * gear_stages + gear_stages_dist * (gear_stages - 1)])
79 151
         translate([0, (gear_stages % 2) ? 0 : gears_dist, 0])
80 152
         translate([(gearbox_width - nema17_size) / 2, -nema17_size / 2 + (gearbox_height - gears_dist) / 2, 0]) {
81 153
             nema17_holes_face(3, motor_mount_height + 5, nema17_hole_size + screw_gap);
@@ -83,7 +155,16 @@ module gearbox() {
83 155
             translate([nema17_size / 2, nema17_size / 2, -1])
84 156
             cylinder(d = nema17_center_size + 2, h = gearbox_wall + 2);
85 157
         }
158
+    
159
+        for (i = [-1, 1])
160
+        translate([0, i * gears_dist / 2, -bearing_height])
161
+        outer_bearings();
86 162
     }
163
+}
164
+
165
+module gearbox() {
166
+    gb_back_wall();
167
+    gb_front_wall();
87 168
 
88 169
     %color("yellow")
89 170
     translate([0, (gear_stages % 2) ? 0 : gears_dist, 0])
@@ -96,7 +177,7 @@ module gearbox() {
96 177
     for (i = [0 : gear_stages - 1])
97 178
     translate([0, 0, i * (gear_stage_height + gear_stages_dist)])
98 179
     rotate([0, 0, i * 180]) {
99
-        gear_stage();
180
+        %gear_stage();
100 181
         
101 182
         color("cyan")
102 183
         if (i < (gear_stages - 1))
@@ -115,125 +196,327 @@ module outer_bearings() {
115 196
     cylinder(d = bearing_outer, h = bearing_height + 0.1);
116 197
 }
117 198
 
118
-module top_cover() {
199
+module linear_bearing_mount(w = linear_mount_width) {
200
+    %color("magenta")
201
+    linear_bearing();
202
+    
119 203
     difference() {
120
-        cube([gearbox_width, gearbox_wall, gearbox_depth]);
204
+        color("green")
205
+        hull() {
206
+            cylinder(d = linear_mount_outer, h = linear_mount_height);
207
+            
208
+            translate([-w / 2, -(linear_mount_wall + linear_mount_outer) / 2, 0])
209
+            cube([w, linear_mount_wall, linear_mount_height]);
210
+        }
121 211
         
122
-        for (i = [0, gearbox_width - gearbox_wall])
123
-        for (j = [gearbox_wall / 2, gearbox_depth - gearbox_wall / 2])
124
-        translate([gearbox_wall / 2 + i, -1, j])
125
-        rotate([-90, 0, 0])
126
-        cylinder(d = extruder_wall_hole_screw, h = gearbox_wall + 2);
212
+        translate([0, 0, -1])
213
+        cylinder(d = linear_mount_inner, h = linear_mount_height + 2);
127 214
         
128
-        for (i = [0, gearbox_width - gear_stages_dist])
129
-        if (gear_stages > 1)
130
-        for (j = [1 : gear_stages - 1])
131
-        translate([gear_stages_dist / 2 + i, -1, j * (gear_stage_height + gear_stages_dist) + gear_stages_dist / 2])
132
-        rotate([-90, 0, 0])
133
-        cylinder(d = extruder_wall_hole_screw, h = gearbox_wall + 2);
215
+        translate([-linear_mount_cut / 2, 0, -1])
216
+        cube([linear_mount_cut, linear_mount_outer, linear_mount_height + 2]);
217
+    }
218
+    
219
+    for (i = [1, -1])
220
+    scale([i, 1, 1])
221
+    translate([linear_mount_cut / 2, linear_mount_outer / 2 - linear_mount_tab_off, 0])
222
+    difference() {
223
+        color("green")
224
+        cube([linear_mount_wall, linear_mount_tab_width + linear_mount_tab_off, linear_mount_height]);
225
+        
226
+        for (i = [1, 3])
227
+        translate([-1, linear_mount_tab_off * 3 / 4 + linear_mount_tab_width / 2, linear_mount_height / 4 * i])
228
+        rotate([0, 90, 0])
229
+        cylinder(d = extruder_wall_hole_screw, h = linear_mount_wall + 2);
134 230
     }
135 231
 }
136 232
 
137
-module gearbox_assembly() {
233
+module top_cover_holes(h, nuts = 0) {
234
+    for (i = [0, gearbox_width - gearbox_wall])
235
+    for (j = [gearbox_wall / 2, gearbox_depth - gearbox_wall / 2])
236
+    translate([gearbox_wall / 2 + i, -1, j])
237
+    rotate([-90, 0, 0])
238
+    if (nuts)
239
+    rotate([0, 0, 360 / 12])
240
+    cylinder(d = extruder_real_nut_dia, h = h + 2, $fn = 6);
241
+    else
242
+    cylinder(d = extruder_wall_hole_screw, h = h + 2);
243
+    
244
+    for (i = [0, gearbox_width - gear_stages_dist])
245
+    if (gear_stages > 1)
246
+    for (j = [1 : gear_stages - 1])
247
+    translate([gear_stages_dist / 2 + i, -1, j * (gear_stage_height + gear_stages_dist) + gear_stages_dist / 2])
248
+    rotate([-90, 0, 0])
249
+    cylinder(d = extruder_wall_hole_screw, h = h + 2);
250
+}
251
+
252
+module top_cover_plate(variant = 0) {
138 253
     difference() {
139
-        gearbox();
254
+        if (variant == 0) {
255
+            color("green")
256
+            translate([0, 0, -linear_mount_add_width])
257
+            cube([gearbox_width, gearbox_wall, gearbox_depth + linear_mount_add_width]);
258
+        } else if (variant == 1) {
259
+            color("green")
260
+            cube([gearbox_width, gearbox_wall, gearbox_depth]);
261
+        } else if (variant == 2) {
262
+            color("red")
263
+            cube([gearbox_width, gearbox_spacer, gearbox_depth]);
264
+        } else {
265
+            color("red")
266
+            translate([-endstop_mount_slot_depth, 0, 0])
267
+            cube([gearbox_width + endstop_mount_slot_depth, gearbox_spacer, gearbox_depth]);
268
+        }
140 269
         
270
+        if (variant == 1) {
271
+            top_cover_holes(gearbox_wall + actuator_bearing_off);
272
+        } else {
273
+            top_cover_holes(gearbox_wall);
274
+        }
275
+    }
276
+}
277
+
278
+module top_cover(variant) {
279
+    top_cover_plate(variant);
280
+    
281
+    if (variant == 0) {
282
+        translate([gearbox_width / 2, gearbox_wall + actuator_bearing_off, -actuator_bearing_dist])
283
+        rotate([-90, 0, 0])
284
+        linear_bearing_mount();
285
+    } else if (variant == 1) {
141 286
         for (i = [-1, 1])
142
-        translate([0, i * gears_dist / 2, -bearing_height])
143
-        outer_bearings();
287
+        translate([gearbox_width / 2 + i * gearbox_width / 4, gearbox_wall + actuator_bearing_off, -actuator_bearing_dist])
288
+        rotate([-90, 0, 0])
289
+        linear_bearing_mount(gearbox_width / 2);
144 290
     }
145 291
     
146 292
     color("green")
147
-    for (i = [-1, 1])
148
-    scale([1, i, 1])
149
-    translate([-gearbox_width / 2, gearbox_height / 2, -gearbox_wall])
150
-    top_cover();
293
+    difference() {
294
+        hull() {
295
+            if (variant == 0) {
296
+                translate([(gearbox_width - linear_mount_width) / 2, gearbox_wall + actuator_bearing_off, (linear_mount_wall + linear_mount_outer) / 2 - linear_mount_wall - actuator_bearing_dist])
297
+                cube([linear_mount_width, linear_mount_height, linear_mount_wall]);
298
+            } else if (variant == 1) {
299
+                translate([0, gearbox_wall + actuator_bearing_off, (linear_mount_wall + linear_mount_outer) / 2 - linear_mount_wall - actuator_bearing_dist])
300
+                cube([gearbox_width, linear_mount_height, linear_mount_wall]);
301
+            }
302
+            
303
+            if (variant == 0) {
304
+                translate([0, gearbox_wall, -linear_mount_add_width])
305
+                cube([gearbox_width, linear_mount_add_height, linear_mount_add_width]);
306
+            } else if (variant == 1) {
307
+                translate([0, gearbox_wall - 1, 0])
308
+                cube([gearbox_width, extruder_add_nut_height + 1, gearbox_depth]);
309
+            }
310
+        }
311
+        
312
+        if (variant == 1) {
313
+            translate([0, gearbox_wall - 2, 0])
314
+            top_cover_holes(actuator_bearing_off + linear_mount_height, 1);
315
+        }
316
+    }
151 317
     
152
-    %color("grey")
153
-    for (i = [-1, 1])
154
-    translate([0, i * gears_dist / 2, -gearbox_wall - 1])
155
-    cylinder(d = axis_diameter, h = gear_stages * gear_stage_height + gearbox_wall * 2 + gear_stages_dist * (gear_stages - 1) + 2);
318
+    if (variant == 3) {
319
+        difference() {
320
+            union() {
321
+                translate([-endstop_pcb_depth - endstop_mount_slot_depth, gb_endstop_off, 0])
322
+                rotate([180, 0, 90]) {
323
+                    %color("yellow")
324
+                    endstop_pcb();
325
+                    
326
+                    color("red")
327
+                    hull()
328
+                    for (i = [0, 1])
329
+                    translate([0, endstop_pcb_depth, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist - endstop_mount_slot_width / 2])
330
+                    cube([endstop_mount_slot_length, endstop_mount_slot_depth, endstop_mount_slot_width]);
331
+                }
332
+                
333
+                color("red")
334
+                hull() {
335
+                    translate([-endstop_mount_slot_depth, 0, 0])
336
+                    cube([endstop_mount_slot_depth, gearbox_spacer * 2, gearbox_depth]);
337
+                    
338
+                    translate([-endstop_mount_slot_depth, gb_endstop_off, -endstop_pcb_height + endstop_pcb_hole_dist_y + endstop_pcb_hole_dist])
339
+                    cube([endstop_mount_slot_depth, endstop_mount_slot_length, endstop_pcb_height - endstop_pcb_hole_dist_y - endstop_pcb_hole_dist]);
340
+                }
341
+            }
342
+            
343
+            // hole slots for endstop pcb
344
+            translate([-endstop_pcb_depth - endstop_mount_slot_depth, gb_endstop_off, 0])
345
+            rotate([180, 0, 90])
346
+            for (i = [0, 1])
347
+            translate([endstop_pcb_hole_dist_x, 1, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
348
+            rotate([-90, 0, 0]) {
349
+                for (j = [-1, 1])
350
+                translate([-j * gb_endstop_slit_len, 0, 0])
351
+                cylinder(d = endstop_pcb_hole, h = endstop_mount_slot_depth + 1);
352
+                
353
+                translate([-gb_endstop_slit_len, -endstop_pcb_hole / 2, 0])
354
+                cube([2 * gb_endstop_slit_len, endstop_pcb_hole, endstop_mount_slot_depth + 1]);
355
+            }
356
+        }
357
+    }
156 358
 }
157 359
 
158
-module piston() {
159
-    //cylinder(d = piston_dia, h = piston_height);
160
-    roundedcylinder(piston_dia, piston_height, piston_radius, true);
360
+module gearbox_assembly() {
361
+    gearbox();
362
+    
363
+    // spacers
364
+    for (i = [0, 1])
365
+    translate([-gearbox_width / 2, gearbox_height / 2 - i * (gearbox_height + gearbox_spacer), -gearbox_wall])
366
+    top_cover(-i + 3);
367
+    
368
+    // top and bottom covers
369
+    for (i = [0, 1])
370
+    translate([-gearbox_width / 2, gearbox_height / 2 - i * (gearbox_height + gearbox_wall) - (i * 2 - 1) * gearbox_spacer, -gearbox_wall])
371
+    top_cover(-i + 1);
372
+    
373
+    %color("grey")
374
+    for (i = [-1, 1])
375
+    translate([0, i * gears_dist / 2, -gearbox_wall + 1])
376
+    cylinder(d = axis_diameter, h = gear_stages * gear_stage_height + gearbox_wall * 2 + gear_stages_dist * (gear_stages - 1) - 2);
161 377
 }
162 378
 
163
-module piston_cyl() {
379
+module bearing() {
164 380
     difference() {
165
-        cylinder(d = cylinder_dia, h = cylinder_height);
381
+        cylinder(d = bearing_outer, h = bearing_height);
166 382
         
167
-        translate([0, 0, piston_wall])
168
-        cylinder(d = piston_dia + 2 * piston_gap, h = cylinder_height + 2);
383
+        translate([0, 0, -1])
384
+        cylinder(d = bearing_inner, h = bearing_height + 2);
169 385
     }
170 386
 }
171 387
 
172
-module piston_visual() {
173
-    color("blue")
388
+module extruder_arm() {
174 389
     difference() {
175
-        piston_cyl();
390
+        color("blue")
391
+        union() {
392
+            // post for axis
393
+            cylinder(d = extruder_arm_axis_dia, h = extruder_arm_axis_h);
394
+            
395
+            // lever body
396
+            translate([-extruder_arm_width / 2, 0, 0])
397
+            cube([extruder_arm_width, extruder_arm_dia / 2, extruder_arm_axis_h]);
398
+            
399
+            translate([0, extruder_arm_dia / 2, 0]) {
400
+                // lever body
401
+                cylinder(d = extruder_arm_width, h = extruder_arm_axis_h);
402
+                
403
+                // post for bearing
404
+                translate([0, 0, extruder_arm_axis_h])
405
+                cylinder(d1 = extruder_arm_width, d2 = extruder_arm_post_dia, h = extruder_arm_post_h - extruder_arm_axis_h - extruder_arm_flare_off);
406
+                
407
+                translate([0, 0, extruder_arm_axis_h + (extruder_arm_post_h - extruder_arm_axis_h - extruder_arm_flare_off)])
408
+                cylinder(d = extruder_arm_post_dia, h = extruder_arm_flare_off);
409
+            }
410
+        }
176 411
         
177
-        translate([-cylinder_dia / 2, -cylinder_dia / 2 - 1, -1])
178
-        cube([cylinder_dia, cylinder_dia / 2 + 1, cylinder_height + 2]);
179
-    }
180
-    
181
-    translate([0, 0, piston_bottom_gap])
182
-    translate([0, 0, extruder_axis_anim_position]) {
183
-        color("green")
184
-        piston();
412
+        // holes for axis, bearing post
413
+        for (i = [0, 1])
414
+        translate([0, i * extruder_arm_dia / 2, -1])
415
+        cylinder(d = axis_hole_diameter, h = extruder_arm_post_h + 2);
185 416
         
186
-        %color("orange")
187
-        translate([0, 0, -actuator_length])
188
-        cylinder(d = 8, h = actuator_length);
417
+        // holes for grub screws
418
+        for(i = [-90, 90])
419
+        translate([0, 0, extruder_arm_axis_h / 2])
420
+        rotate([90, 0, i])
421
+        cylinder(d = belt_pulley_fix_dia, h = extruder_arm_axis_dia);
189 422
     }
423
+            
424
+    // bearing
425
+    %color("yellow")
426
+    translate([0, extruder_arm_dia / 2, extruder_arm_post_h + 1])
427
+    bearing();
428
+    
429
+    // axis
430
+    %color("grey")
431
+    translate([0, 0, -extruder_arm_off])
432
+    cylinder(d = axis_diameter, h = extruder_arm_off + extruder_arm_axis_h);
190 433
 }
191 434
 
192
-module extruder_lever() {
193
-    translate([-extruder_lever_width / 2, 0, -extruder_lever_length + (extruder_lever_length - extruder_lever_hole_dist) / 2])
435
+module extruder_actuator() {
194 436
     difference() {
195
-        cube([extruder_lever_width, extruder_lever_depth, extruder_lever_length]);
196
-        
197
-        translate([extruder_lever_width / 2, -1, (extruder_lever_length - extruder_lever_hole_dist) / 2])
198
-        rotate([-90, 0, 0]) {
199
-            for (i = [0, extruder_lever_hole_dist])
200
-            translate([0, -i, 0])
201
-            cylinder(d = extruder_lever_holes, h = extruder_lever_depth + 2);
437
+        color("orange")
438
+        union() {
439
+            cube([actuator_width, actuator_wall, actuator_height]);
440
+            
441
+            for (i = [0, 1])
442
+            for (j = [1, -1])
443
+            translate([i * actuator_width, 0, i * actuator_height])
444
+            rotate([0, i * 180, 0])
445
+            hull() {
446
+            //union() {
447
+                cube([actuator_width, actuator_wall, (actuator_height - actuator_slot_h) / 2]);
448
+                    
449
+                translate([(actuator_width - actuator_rod_width) / 2 + i * gearbox_width / 4 * j, actuator_wall - actuator_rod_width, -actuator_rod_h])
450
+                cube([actuator_rod_width, actuator_rod_width, actuator_rod_h]);
451
+            }
202 452
         }
453
+        
454
+        // slot for bearing
455
+        translate([(actuator_width - actuator_slot_w) / 2, -1, (actuator_height - actuator_slot_h) / 2])
456
+        cube([actuator_slot_w, actuator_wall + actuator_rod_width + 2, actuator_slot_h]);
457
+        
458
+        // holes for rod
459
+        for (i = [0, 1])
460
+        for (j = [1, -1])
461
+        translate([actuator_width / 2 + i * gearbox_width / 4 * j, actuator_wall - actuator_rod_width / 2, -actuator_rod_h - 1 + i * (actuator_height + actuator_rod_h / 2 + 1)])
462
+        cylinder(d = actuator_rod, h = actuator_rod_h + actuator_rod_inset + 1);
463
+        
464
+        // holes for rod grub screws
465
+        for (i = [0, 1])
466
+        for (j = [1, -1])
467
+        for (r = [-45, 45, 180])
468
+        translate([actuator_width / 2 + i * gearbox_width / 4 * j, actuator_wall - actuator_rod_width / 2, -actuator_rod_h / 2 + i * (actuator_height + actuator_rod_h)])
469
+        rotate([90, 0, r])
470
+        cylinder(d = belt_pulley_fix_dia, h = actuator_rod_width);
203 471
     }
472
+    
473
+    // rods
474
+    %color("yellow")
475
+    for (i = [0, 1])
476
+    for (j = [1, -1])
477
+    translate([actuator_width / 2 + (-i + 1) * gearbox_width / 4 * j, actuator_rod_width / 2 + actuator_wall - actuator_rod_width, actuator_height + i * (-actuator_height - actuator_rod_len - actuator_rod_len_add_bottom) + (i - 1) * actuator_rod_inset])
478
+    cylinder(d = actuator_rod, h = actuator_rod_len + i * actuator_rod_len_add_bottom + actuator_rod_inset);
204 479
 }
205 480
 
206 481
 module extruder() {
207
-    translate([0, gearbox_depth - gearbox_wall, -gears_dist / 2])
482
+    translate([0, gearbox_depth - gearbox_wall, gearbox_height / 2 + gearbox_wall])
208 483
     rotate([90, 0, 0])
209 484
     translate([0, 0, gearbox_depth - gearbox_wall * 2])
210 485
     rotate([0, 180, 0])
211 486
     gearbox_assembly();
212 487
     
213
-    translate([0, -cylinder_dia / 2, -cylinder_height - extruder_travel / 2]) {
214
-        translate([0, 0, -additional_piston_offset])
215
-        piston_visual();
216
-        
217
-        color("red")
218
-        translate([0, 0, cylinder_height + extruder_travel / 2])
219
-        rotate([0, -acos(anim_pos_extruder * -2 + 1), 0])
220
-        extruder_lever();
488
+    translate([0, -extruder_arm_off, gearbox_wall + gearbox_height / 2 + gears_dist / 2])
489
+    rotate([90, 0, 0])
490
+    if (show_extruder_maximum_positions) {
491
+        for (i = [0 : 360 / extruder_maximum_positions : 360])
492
+        rotate([0, 0, i])
493
+        extruder_arm();
494
+    } else {
495
+        rotate([0, 0, use_anim ? ($t * -360) : (extruder_axis_position * -180)])
496
+        extruder_arm();
497
+    }
498
+    
499
+    translate([-actuator_width / 2, -actuator_wall - extruder_arm_post_h - extruder_arm_off + 1, -actuator_height / 2 + gearbox_wall + gearbox_height / 2 + gears_dist / 2 + extruder_arm_dia / 2])
500
+    if (show_extruder_maximum_positions) {
501
+        for (i = [0 : 2 / extruder_maximum_positions : 1])
502
+        translate([0, 0, -i * extruder_arm_dia])
503
+        extruder_actuator();
504
+    } else {
505
+        translate([0, 0, -anim_pos_extruder * extruder_arm_dia])
506
+        extruder_actuator();
221 507
     }
222 508
 }
223 509
 
224
-module whole_extruder() {
225
-    translate([0, 0, cylinder_height + extruder_travel / 2 + additional_piston_offset])
226
-    extruder();
227
-}
228
-
229
-//gearbox_assembly();
230
-//piston();
231
-//piston_cyl();
232
-//extruder_lever();
510
+//gb_back_wall();
511
+//gb_front_wall();
233 512
 //center_plate();
234
-//outer_plate();
235
-//top_cover();
513
+//top_cover(0);
514
+//top_cover(1);
515
+//top_cover(2);
516
+//top_cover(3);
517
+//gearbox_assembly();
236 518
 
237
-//piston_visual();
519
+//extruder_arm();
520
+//extruder_actuator();
238 521
 
239
-whole_extruder();
522
+extruder();

+ 193
- 128
hardware/table.scad View File

@@ -254,121 +254,6 @@ module plate() {
254 254
  ************** Y-Axis **************
255 255
  ************************************/
256 256
 
257
-module endstop_pcb() {
258
-    difference() {
259
-        cube([endstop_pcb_width, endstop_pcb_depth, endstop_pcb_height]);
260
-        
261
-        for (i = [0, 1])
262
-        translate([endstop_pcb_hole_dist_x, -1, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
263
-        rotate([-90, 0, 0])
264
-        cylinder(d = endstop_pcb_hole, h = endstop_pcb_depth + 2);
265
-    }
266
-    
267
-    translate([0, 0, endstop_pcb_height - endstop_pcb_switchpoint])
268
-    rotate([0, -90, 0])
269
-    cylinder(d = endstop_pcb_hole, h = endstop_pcb_switchpoint);
270
-}
271
-
272
-module endstop_mount_v1() {
273
-    %color("yellow")
274
-    translate([-endstop_pcb_mount_off_w, -endstop_pcb_depth - endstop_pcb_mount_off_d, endstop_pcb_mount_off_h])
275
-    endstop_pcb();
276
-    
277
-    color("blue")
278
-    difference() {
279
-        cube([endstop_mount_width, endstop_mount_depth, 40]);
280
-        
281
-        for (i = [0, 1])
282
-        translate([endstop_mount_width / 2, -1, 10 + 20 * i])
283
-        rotate([-90, 0, 0])
284
-        cylinder(d = motor_mount_hole_size, h = endstop_mount_depth + 2);
285
-    }
286
-    
287
-    color("blue")
288
-    difference() {
289
-        union() {
290
-            hull() {
291
-                translate([-endstop_mount_slot_length, 0, 40 - endstop_mount_add_height])
292
-                cube([endstop_mount_slot_length, endstop_mount_depth, endstop_mount_add_height]);
293
-                
294
-                translate([0, 0, endstop_pcb_height - endstop_pcb_hole_dist_y - endstop_pcb_hole_dist])
295
-                translate([-endstop_pcb_mount_off_w, -endstop_pcb_mount_off_d, endstop_pcb_mount_off_h - endstop_mount_slot_width / 2])
296
-                cube([endstop_mount_slot_length, endstop_mount_slot_depth, endstop_mount_slot_width]);
297
-                
298
-                for (i = [0, 1])
299
-                translate([0, 0, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
300
-                translate([-endstop_pcb_mount_off_w, -endstop_pcb_mount_off_d, endstop_pcb_mount_off_h - endstop_mount_slot_width / 2])
301
-                cube([endstop_mount_slot_length, endstop_mount_slot_depth, endstop_mount_slot_width]);
302
-            }
303
-        }
304
-        
305
-        translate([-endstop_pcb_mount_off_w, -endstop_pcb_depth - endstop_pcb_mount_off_d, endstop_pcb_mount_off_h])
306
-        for (i = [0, 1])
307
-        translate([endstop_pcb_hole_dist_x, -1, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
308
-        rotate([-90, 0, 0]) {
309
-            cylinder(d = endstop_pcb_hole, h = endstop_pcb_depth + 20);
310
-            
311
-            translate([0, 0, 1 + endstop_pcb_depth + endstop_mount_slot_depth])
312
-            cylinder(d = endstop_mount_nut_hole, h = 20, $fn = 6);
313
-        }
314
-    }
315
-}
316
-
317
-module endstop_mount_v2() {
318
-    %color("yellow")
319
-    translate([-endstop_pcb_mount_off_w, -endstop_pcb_depth - endstop_pcb_mount_off_d, endstop_pcb_mount_off_h])
320
-    endstop_pcb();
321
-    
322
-    color("blue")
323
-    difference() {
324
-        cube([endstop_mount_width, endstop_mount_depth, 40]);
325
-        
326
-        for (i = [0, 1])
327
-        translate([endstop_mount_width / 2, -1, 10 + 20 * i])
328
-        rotate([-90, 0, 0])
329
-        cylinder(d = motor_mount_hole_size, h = endstop_mount_depth + 2);
330
-    }
331
-    
332
-    color("blue")
333
-    difference() {
334
-        union() {
335
-            hull() {
336
-                translate([-endstop_mount_slot_length, 0, 40 - endstop_mount_add_height])
337
-                cube([endstop_mount_slot_length, endstop_mount_depth, endstop_mount_add_height]);
338
-                
339
-                translate([0, 0, endstop_pcb_height - endstop_pcb_hole_dist_y - endstop_pcb_hole_dist])
340
-                translate([-endstop_pcb_mount_off_w, -endstop_pcb_mount_off_d, endstop_pcb_mount_off_h - endstop_mount_slot_width / 2])
341
-                cube([endstop_mount_slot_length, endstop_mount_slot_depth, endstop_mount_slot_width]);
342
-            }
343
-            
344
-            hull() {
345
-                for (i = [0, 1])
346
-                translate([0, 0, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
347
-                translate([-endstop_pcb_mount_off_w, -endstop_pcb_mount_off_d, endstop_pcb_mount_off_h - endstop_mount_slot_width / 2])
348
-                cube([endstop_mount_slot_length, endstop_mount_slot_depth, endstop_mount_slot_width]);
349
-            }
350
-        }
351
-        
352
-        translate([-endstop_pcb_mount_off_w, -endstop_pcb_depth - endstop_pcb_mount_off_d, endstop_pcb_mount_off_h])
353
-        for (i = [0, 1])
354
-        translate([endstop_pcb_hole_dist_x, -1, endstop_pcb_height - endstop_pcb_hole_dist_y - i * endstop_pcb_hole_dist])
355
-        rotate([-90, 0, 0]) {
356
-            cylinder(d = endstop_pcb_hole, h = endstop_pcb_depth + 20);
357
-            
358
-            translate([0, 0, 1 + endstop_pcb_depth + endstop_mount_slot_depth])
359
-            cylinder(d = endstop_mount_nut_hole, h = 20, $fn = 6);
360
-        }
361
-    }
362
-}
363
-
364
-module endstop_mount() {
365
-    if (use_endstop_mount_v2) {
366
-        endstop_mount_v2();
367
-    } else {
368
-        endstop_mount_v1();
369
-    }
370
-}
371
-
372 257
 module belt_mount(h) {
373 258
     difference() {
374 259
         hull() {
@@ -616,24 +501,176 @@ module x_axis() {
616 501
     belt_tensioner(2, x_axis_rail_len, 0);
617 502
 }
618 503
 
619
-/************************************
620
- ************* Assembly *************
621
- ************************************/
504
+/*************************************
505
+ *************** Stuff ***************
506
+ *************************************/
507
+
508
+psu_width = 98.0;
509
+psu_height = 43.0;
510
+psu_length = 160;
511
+psu_cut_gap = 1.0;
512
+psu_cut_w = psu_width + psu_cut_gap;
513
+psu_cut_h = psu_height + psu_cut_gap;
514
+psu_wall = 4;
515
+psu_mount_len = 40 + psu_wall;
516
+psu_mount_w = psu_cut_w + 2 * psu_wall;
517
+psu_mount_h = psu_cut_h + 2 * psu_wall;
518
+psu_mount_hole_off = 10;
519
+psu_mount_tri = 3;
520
+psu_mount_del = psu_mount_tri;
521
+psu_assembly_mount_off_y = 25;
522
+psu_assembly_mount_off_z = 6;
523
+psu_hole_dia = 4.2;
524
+psu_back_hole_x = 9.5;
525
+psu_back_hole_y = 18.0;
526
+psu_cable_hole = 8.0;
527
+psu_cable_hole_off = 13.0;
528
+//psu_side_hole_y = 26.0;
529
+//psu_side_Hole_z = 20.0;
530
+
531
+power_socket_width = 48.0;
532
+power_socket_height = 28.0;
533
+power_socket_depth = 30;
534
+power_socket_hole = 2.7;
535
+power_socket_hole_off = 11.0 - 2.8 - 1.6;
536
+power_socket_rim = 11;
537
+power_socket_wr = power_socket_width + 2 * power_socket_rim;
538
+power_socket_hr = power_socket_height + 2 * power_socket_rim;
539
+
540
+power_box_width = 70;
541
+power_box_height = psu_mount_h;
542
+power_box_depth = 50;
543
+
544
+module power_socket() {
545
+    translate([-power_socket_width / 2, -power_socket_height / 2, -power_socket_depth])
546
+    cube([power_socket_width, power_socket_height, power_socket_depth]);
547
+    
548
+    difference() {
549
+        translate([-power_socket_wr / 2, -power_socket_hr / 2, 0])
550
+        cube([power_socket_wr, power_socket_hr, 2.0]);
551
+        
552
+        for (i = [-1, 1])
553
+        translate([0, i * (power_socket_height / 2 + power_socket_hole_off), -1])
554
+        cylinder(d = power_socket_hole, h = 4.0);
555
+    }
556
+}
622 557
 
623
-module assembly_y_axis_plate() {
624
-    translate([0, -y_carriage_y / 2 - y_axis_animation_position, 0])
625
-    y_axis();
558
+module power_box() {
559
+    %color("yellow")
560
+    translate([power_box_width / 2, power_box_depth, power_box_height / 2])
561
+    rotate([-90, 0, 0])
562
+    power_socket();
626 563
     
627
-    %translate([-plate_x / 2, -plate_y / 2, 20 + y_carriage_h + y_carriage_rail_dist + carriage_spacer_height])
628
-    plate();
564
+    color("cyan")
565
+    difference() {
566
+        translate([0, power_box_depth - psu_wall, 0])
567
+        cube([power_box_width, psu_wall, power_box_height]);
568
+        
569
+        translate([(power_box_width - power_socket_width) / 2, power_box_depth - 9, (power_box_height - power_socket_height) / 2])
570
+        cube([power_socket_width, 10, power_socket_height]);
571
+        
572
+        for (i = [1, -1])
573
+        translate([power_box_width / 2, power_box_depth + 1, (power_box_height - i * power_socket_height) / 2 - power_socket_hole_off * i])
574
+        rotate([90, 0, 0])
575
+        cylinder(d = power_socket_hole, h = psu_wall + 15);
576
+    }
629 577
 }
630 578
 
631
-module assembly_x_axis() {
632
-    x_axis();
579
+module psu_holder_tab() {
580
+    difference() {
581
+        translate([psu_mount_del, 0, 0])
582
+        cube([20 - psu_mount_del, psu_wall, psu_mount_len]);
583
+        
584
+        for (i = [psu_mount_hole_off, psu_mount_len - psu_mount_hole_off])
585
+        translate([10, -1, i])
586
+        rotate([-90, 0, 0])
587
+        cylinder(d = motor_mount_hole_size, h = psu_wall + 2);
588
+    }
589
+}
590
+
591
+module psu_holder_box(remove_back = 0) {
592
+    if (!remove_back)
593
+    translate([-psu_mount_w / 2, -psu_mount_h / 2 - psu_assembly_mount_off_z, 0])
594
+    cube([psu_mount_w, psu_mount_h, psu_wall]);
633 595
     
634
-    translate([x_axis_animation_position + y_carriage_y / 2, -y_axis_rail_len / 2, 20 + y_carriage_h + y_carriage_rail_dist])
635
-    translate([10, y_axis_animation_position + y_carriage_y / 2, 20])
636
-    assembly_y_axis_plate();
596
+    for (i = [-psu_mount_h / 2, psu_mount_h / 2 - psu_wall])
597
+    translate([-psu_mount_w / 2, i - psu_assembly_mount_off_z, 0])
598
+    cube([psu_mount_w, psu_wall, psu_mount_len]);
599
+    
600
+    for (i = [-psu_mount_w / 2, psu_mount_w / 2 - psu_wall])
601
+    translate([i, -psu_mount_h / 2 - psu_assembly_mount_off_z, 0])
602
+    cube([psu_wall, psu_mount_h, psu_mount_len]);
603
+    
604
+    for (i = [/* psu_mount_w / 2, */ -psu_mount_w / 2 - 20])
605
+    for (j = [10, -10 - psu_wall])
606
+    translate([i, j, 0])
607
+    psu_holder_tab();
608
+    
609
+    for (i = [0, 1])
610
+    translate([-psu_mount_w / 2 - i * psu_mount_tri, -psu_mount_tri - 10 - psu_wall + i * (psu_mount_tri + 20 + psu_wall * 2), 0])
611
+    rotate([0, -90, i * -90])
612
+    prism(psu_mount_len, psu_mount_tri, psu_mount_tri);
613
+}
614
+
615
+module psu_holder(part) {
616
+    // 0 is "back side" of psu
617
+    // 1 is "front" / cable side of psu
618
+    
619
+    difference() {
620
+        union() {
621
+            color("cyan")
622
+            translate([0, 0, part * psu_mount_len])
623
+            scale([1, 1, 1 + part * -2])
624
+            psu_holder_box(part);
625
+            
626
+            if (part == 1) {
627
+                color("cyan")
628
+                translate([0, -psu_mount_h / 2 - psu_assembly_mount_off_z, psu_mount_len])
629
+                hull() {
630
+                    translate([-power_box_width / 2, 0, power_box_depth - psu_wall - 1])
631
+                    cube([power_box_width, power_box_height, 1]);
632
+                    
633
+                    translate([-psu_mount_w / 2, 0, 0])
634
+                    cube([psu_mount_w, psu_mount_h, 1]);
635
+                }
636
+                
637
+                translate([-power_box_width / 2, psu_mount_h / 2 - psu_assembly_mount_off_z, psu_mount_len])
638
+                rotate([90, 0, 0])
639
+                power_box();
640
+            }
641
+        }
642
+        if (part == 0) {
643
+            translate([-psu_mount_w / 2 + psu_back_hole_x + psu_wall, psu_mount_h / 2 - psu_assembly_mount_off_z + 1, psu_back_hole_y + psu_wall])
644
+            rotate([90, 0, 0])
645
+            cylinder(d = psu_hole_dia, h = psu_wall + 2);
646
+        } else {
647
+            translate([0, -psu_mount_h / 2 - psu_assembly_mount_off_z, psu_mount_len])
648
+            hull() {
649
+                translate([-power_socket_width / 2, power_socket_height / 2 - psu_wall / 2, power_box_depth - psu_wall])
650
+                cube([power_socket_width, power_socket_height, 1]);
651
+                
652
+                translate([-psu_mount_w / 2 + psu_wall, psu_wall, -1])
653
+                cube([psu_mount_w - 2 * psu_wall, psu_mount_h - 2 * psu_wall, 1]);
654
+            }
655
+            
656
+            for (i = [-1, 0, 1])
657
+            translate([i * psu_cable_hole_off, 0, 0])
658
+            translate([0, -psu_mount_h / 2 + 5, psu_mount_len + power_box_depth / 4])
659
+            rotate([90, 0, 0])
660
+            cylinder(d = psu_cable_hole, h = psu_wall + 10);
661
+        }
662
+    }
663
+}
664
+
665
+module psu_holder_assembly() {
666
+    color("yellow")
667
+    translate([-psu_width / 2, psu_wall, -psu_height / 2 + psu_assembly_mount_off_z])
668
+    cube([psu_width, psu_length, psu_height]);
669
+    
670
+    for (i = [0, 1])
671
+    translate([0, i * (psu_length - psu_mount_len + 2 * psu_wall), 0])
672
+    rotate([-90, 0, 0])
673
+    psu_holder(i);
637 674
 }
638 675
 
639 676
 module rail_foot() {
@@ -659,6 +696,26 @@ module rail_foot() {
659 696
     }
660 697
 }
661 698
 
699
+/************************************
700
+ ************* Assembly *************
701
+ ************************************/
702
+
703
+module assembly_y_axis_plate() {
704
+    translate([0, -y_carriage_y / 2 - y_axis_animation_position, 0])
705
+    y_axis();
706
+    
707
+    %translate([-plate_x / 2, -plate_y / 2, 20 + y_carriage_h + y_carriage_rail_dist + carriage_spacer_height])
708
+    plate();
709
+}
710
+
711
+module assembly_x_axis() {
712
+    x_axis();
713
+    
714
+    translate([x_axis_animation_position + y_carriage_y / 2, -y_axis_rail_len / 2, 20 + y_carriage_h + y_carriage_rail_dist])
715
+    translate([10, y_axis_animation_position + y_carriage_y / 2, 20])
716
+    assembly_y_axis_plate();
717
+}
718
+
662 719
 module assembly() {
663 720
     translate([-x_axis_rail_len / 2, 0, 20]) {
664 721
         assembly_x_axis();
@@ -685,6 +742,8 @@ module assembly() {
685 742
                 %color("green")
686 743
                 rail_foot();
687 744
             }
745
+            
746
+            // TODO psu
688 747
         } else {
689 748
             color("grey")
690 749
             translate([x_axis_rail_len / 2, 0, -40])
@@ -703,6 +762,9 @@ module assembly() {
703 762
                 rail_foot();
704 763
             }
705 764
         }
765
+        
766
+        translate([bottom_support_off + psu_mount_w / 2, 10 + psu_assembly_mount_off_y, 10 - 40])
767
+        psu_holder_assembly();
706 768
     }
707 769
 }
708 770
 
@@ -719,6 +781,9 @@ module xy_table() {
719 781
 //rail_2020_x(100);
720 782
 //rail_wheel();
721 783
 //rail_foot();
784
+//psu_holder(0);
785
+//psu_holder(1);
786
+//psu_holder_assembly();
722 787
 
723 788
 //motor_mount(1);
724 789
 //motor_mount(2);

+ 16
- 18
include/config.h View File

@@ -33,13 +33,13 @@
33 33
 // xy steps per mm
34 34
 #define XY_BELT_PITCH 2.0
35 35
 #define XY_PULLEY_TEETH 40.0
36
-#define XY_MICRO_STEPS 16.0
36
+#define XY_MICRO_STEPS 8.0
37 37
 #define XY_MOTOR_STEPS_PER_REV (200.0 * XY_MICRO_STEPS)
38 38
 #define XY_STEPS_PER_MM (XY_MOTOR_STEPS_PER_REV / XY_PULLEY_TEETH / XY_BELT_PITCH)
39 39
 
40 40
 // z steps per mm
41 41
 #define Z_ROD_PITCH 2.0
42
-#define Z_MICRO_STEPS 16.0
42
+#define Z_MICRO_STEPS 8.0
43 43
 #define Z_MOTOR_STEPS_PER_REV (200.0 * Z_MICRO_STEPS)
44 44
 #define Z_STEPS_PER_MM (Z_MOTOR_STEPS_PER_REV / Z_ROD_PITCH)
45 45
 
@@ -52,7 +52,7 @@
52 52
 // 4800 / 100 = 48 steps for one percent of movement
53 53
 #define GEARBOX_MULT 3
54 54
 #define OUTPUT_TURN_DIV 2
55
-#define E_MICRO_STEPS 16.0
55
+#define E_MICRO_STEPS 8.0
56 56
 #define E_MOTOR_STEPS_PER_REV (200.0 * E_MICRO_STEPS)
57 57
 #define E_STEPS_PER_PERCENT (E_MOTOR_STEPS_PER_REV * GEARBOX_MULT / OUTPUT_TURN_DIV / 100.0)
58 58
 
@@ -73,46 +73,44 @@
73 73
 #define E_MM_TO_PERCENT(x) ((acos((x * 2.0 / E_AXIS_MAX) - 1.0) - PI) * 100.0 / PI)
74 74
 
75 75
 // maximum speeds
76
-#define XY_MAX_SPEED 50.0 // in mm/s --> 50mm/s = 2000steps/s
77
-#define Z_MAX_SPEED 1.2 // in mm/s --> 20mm/s = 32000steps/s
78
-#define E_MAX_SPEED 30.0 // in percent/s --> 50%/s = 2400steps/s
76
+#define XY_MAX_SPEED 50.0 // in mm/s --> 50mm/s = 1000steps/s
77
+#define Z_MAX_SPEED 1.2 // in mm/s --> 20mm/s = 16000steps/s
78
+#define E_MAX_SPEED 200.0 // in percent/s --> 50%/s = 1200steps/s
79 79
 
80 80
 // homing speeds
81 81
 #define XY_FAST_HOME_SPEED 25.0 // in mm/s
82 82
 #define XY_SLOW_HOME_SPEED 5.0 // in mm/s
83 83
 #define Z_FAST_HOME_SPEED 5.0 // in mm/s
84 84
 #define Z_SLOW_HOME_SPEED 1.0 // in mm/s
85
-#define E_FAST_HOME_SPEED 10.0 // in percent/s
86
-#define E_SLOW_HOME_SPEED 2.0 // in percent/s
85
+#define E_FAST_HOME_SPEED 50.0 // in percent/s
86
+#define E_SLOW_HOME_SPEED 20.0 // in percent/s
87 87
 
88 88
 // accelerations
89
-#define XY_MAX_ACCEL 100.0 // in mm/s^2
89
+#define XY_MAX_ACCEL 2000.0 // in mm/s^2
90 90
 #define Z_MAX_ACCEL 50.0 // in mm/s^2
91
-#define E_MAX_ACCEL 1000.0 // in percent/s^2
91
+#define E_MAX_ACCEL 5000.0 // in percent/s^2
92 92
 
93 93
 // axis movement directions (1.0 normal, -1.0 inverted)
94 94
 #define X_AXIS_MOVEMENT_DIR 1.0
95 95
 #define Y_AXIS_MOVEMENT_DIR 1.0
96 96
 #define Z_AXIS_MOVEMENT_DIR 1.0
97
-#define E_AXIS_MOVEMENT_DIR 1.0
97
+#define E_AXIS_MOVEMENT_DIR -1.0
98 98
 
99 99
 // homing back-off
100 100
 #define XY_BACK_OFF_DISTANCE 5.0 // in mm
101 101
 #define Z_BACK_OFF_DISTANCE 2.0 // in mm
102
-#define E_BACK_OFF_DISTANCE 1.0 // in mm
103 102
 
104 103
 #define XY_HOME_BACK_OFF_TIME (XY_BACK_OFF_DISTANCE / XY_FAST_HOME_SPEED * 1000)
105 104
 #define Z_HOME_BACK_OFF_TIME (Z_BACK_OFF_DISTANCE / Z_FAST_HOME_SPEED * 1000)
106
-#define E_HOME_BACK_OFF_TIME (E_BACK_OFF_DISTANCE / E_FAST_HOME_SPEED * 1000)
107 105
 
108 106
 // epsilon around expected endstop position where we dont abort on hits
109 107
 // if you need to increase this value, try to reduce play in your axis
110
-#define X_AXIS_EPSILON 1.0
111
-#define Y_AXIS_EPSILON 1.0
112
-#define Z_AXIS_EPSILON 1.0
113
-#define E_AXIS_EPSILON 1.0
108
+#define X_AXIS_EPSILON 2.0 // in mm
109
+#define Y_AXIS_EPSILON 2.0 // in mm
110
+#define Z_AXIS_EPSILON 1.0 // in mm
111
+#define E_AXIS_EPSILON 50.0 // TODO
114 112
 
115
-#define ENCODER_RPM_VALUE_FACTOR 2.0
113
+#define ENCODER_RPM_VALUE_FACTOR 0.5
116 114
 #define IDLE_TIMEOUT (5UL * 60UL * 1000UL) // ms, 0 to disable
117 115
 
118 116
 // TimerOne freq for steppers

+ 6
- 15
include/config_pins.h View File

@@ -19,17 +19,18 @@
19 19
 #define Z_STEP_PIN         46
20 20
 #define Z_DIR_PIN          48
21 21
 #define Z_ENABLE_PIN       62
22
+
23
+// Using a Z-MAX endstop, plugged into Z_MIN pin
22 24
 #define Z_MIN_PIN          -1 // 18
23
-#define Z_MAX_PIN          19
25
+#define Z_MAX_PIN          18 // 19
24 26
 
25 27
 //extruder 1
26 28
 #define E0_STEP_PIN        26
27 29
 #define E0_DIR_PIN         28
28 30
 #define E0_ENABLE_PIN      24
29 31
 
30
-// use the remaining z endstop pin for e axis
31
-#define E_MIN_PIN          18
32
-#define E_MAX_PIN          -1
32
+// use Z_MAX pin for e axis
33
+#define E_ENDSTOP_PIN      19
33 34
 
34 35
 //extruder 2
35 36
 #define E1_STEP_PIN        36
@@ -115,10 +116,6 @@
115 116
 #error define one of Z_MIN_PIN or Z_MAX_PIN
116 117
 #endif
117 118
 
118
-#if ((E_MIN_PIN != -1) && (E_MAX_PIN != -1)) || ((E_MIN_PIN == -1) && (E_MAX_PIN == -1))
119
-#error define one of E_MIN_PIN or E_MAX_PIN
120
-#endif
121
-
122 119
 #if (X_MIN_PIN == -1)
123 120
 #define X_HOMING_DIR 1
124 121
 #define X_ENDSTOP_PIN X_MAX_PIN
@@ -143,13 +140,7 @@
143 140
 #define Z_ENDSTOP_PIN Z_MIN_PIN
144 141
 #endif
145 142
 
146
-#if (E_MIN_PIN == -1)
147
-#define E_HOMING_DIR 1
148
-#define E_ENDSTOP_PIN E_MAX_PIN
149
-#else
150
-#define E_HOMING_DIR -1
151
-#define E_ENDSTOP_PIN E_MIN_PIN
152
-#endif
143
+#define E_HOMING_DIR -1.0
153 144
 
154 145
 #ifdef KILL_PIN
155 146
 #if (KILL_PIN == -1)

+ 1
- 1
include/statemachine.h View File

@@ -152,7 +152,7 @@ private:
152 152
     T mins[N], maxs[N];
153 153
     const char *texts[N];
154 154
     const char *heading;
155
-    size_t pos;
155
+    size_t pos, off;
156 156
     bool editing;
157 157
     UpdateFuncPtr updateFunc, updateLiveFunc;
158 158
 };

+ 10
- 4
src/lcd.cpp View File

@@ -25,7 +25,7 @@ LiquidCrystal lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5, LCD_PI
25 25
 
26 26
 #include <U8g2lib.h>
27 27
 
28
-//#define ENABLE_DYNAMIC_SCROLLING
28
+#define ENABLE_DYNAMIC_SCROLLING
29 29
 
30 30
 #define LCD_HEADING_LINES 1
31 31
 #define LCD_HEADING_WIDTH 15
@@ -254,7 +254,7 @@ void lcd_loop(void) {
254 254
 }
255 255
 
256 256
 void lcd_clear(void) {
257
-    Serial.println();
257
+    //Serial.println();
258 258
 
259 259
     text_mode = lcd_mode_none;
260 260
 
@@ -310,8 +310,14 @@ void lcd_set_text(const char *t) {
310 310
 }
311 311
 
312 312
 void lcd_set_menu_text(int line, const char *t) {
313
-    Serial.print(line);
314
-    Serial.print(F(": "));
313
+    if ((line < 0) || (line >= LCD_TEXT_LINES)) {
314
+        Serial.print(F("Invalid lcd line no: "));
315
+        Serial.println(line);
316
+        return;
317
+    }
318
+
319
+    //Serial.print(line);
320
+    //Serial.print(F(": "));
315 321
     Serial.println(t);
316 322
 
317 323
     text_mode = lcd_mode_menu;

+ 9
- 2
src/main.cpp View File

@@ -10,7 +10,7 @@
10 10
 #include "steppers.h"
11 11
 #include "states.h"
12 12
 
13
-const static float hz = min(max(max(XY_MAX_HZ, Z_MAX_HZ), E_MAX_HZ), MAX_SAMPLE_FREQ);
13
+const static float hz = min(max(max(XY_MAX_HZ, Z_MAX_HZ), E_MAX_HZ), MAX_SAMPLE_FREQ) * 2.0;
14 14
 const static float us = (1000.0 * 1000.0) / hz;
15 15
 
16 16
 void print_data(void) {
@@ -138,7 +138,7 @@ void setup() {
138 138
     Serial.println(F("Init stepper motors"));
139 139
     steppers_init();
140 140
 
141
-    //print_data();
141
+    print_data();
142 142
 
143 143
     Serial.println(F("ready, showing splash screen"));
144 144
     digitalWrite(LED_PIN, LOW);
@@ -183,6 +183,7 @@ void loop() {
183 183
     // allow rudimentary control over serial
184 184
     // with enter and w/s or arrow up/down for encoder
185 185
     // and q/k/space keys for kill
186
+    // arrow left/right do 10-increments of encoder
186 187
     static int ser_state = 0;
187 188
     while (Serial.available()) {
188 189
         int c = Serial.read();
@@ -209,6 +210,12 @@ void loop() {
209 210
                 change = 1;
210 211
             } else if (c == 'B') {
211 212
                 change = -1;
213
+            } else if (c == 'C') {
214
+                rpm = 9 * ENCODER_RPM_VALUE_FACTOR;
215
+                change = -1;
216
+            } else if (c == 'D') {
217
+                rpm = 9 * ENCODER_RPM_VALUE_FACTOR;
218
+                change = 1;
212 219
             }
213 220
             ser_state = 0;
214 221
         }

+ 14
- 5
src/sm_value.cpp View File

@@ -100,6 +100,7 @@ StateValues<T, N>::StateValues(State *_parent) : State(_parent) {
100 100
     updateFunc = NULL;
101 101
     updateLiveFunc = NULL;
102 102
     pos = 0;
103
+    off = 0;
103 104
     editing = false;
104 105
 }
105 106
 
@@ -134,7 +135,7 @@ void StateValues<T, N>::display(void) {
134 135
         lcd_set_heading(heading);
135 136
     }
136 137
 
137
-    for (size_t i = 0; i < (N + 1); i++) {
138
+    for (size_t i = off; (i < (N + 1)) && (i < (off + lcd_text_lines())); i++) {
138 139
         String s;
139 140
 
140 141
         if (i == pos) {
@@ -148,7 +149,7 @@ void StateValues<T, N>::display(void) {
148 149
         }
149 150
 
150 151
         if (i < N) {
151
-            s += texts[i] + String(*(values[i])) + F(" (") + String(mins[i]) + F("/") + String(maxs[i]) + F(")");
152
+            s += texts[i] + String(F(" ")) + String(*(values[i])) + F(" (") + String(mins[i]) + F("/") + String(maxs[i]) + F(")");
152 153
         } else {
153 154
             if (getChild() != NULL) {
154 155
                 s += F("Continue");
@@ -157,7 +158,7 @@ void StateValues<T, N>::display(void) {
157 158
             }
158 159
         }
159 160
 
160
-        lcd_set_menu_text(i, s.c_str());
161
+        lcd_set_menu_text(i - off, s.c_str());
161 162
     }
162 163
 }
163 164
 
@@ -206,12 +207,19 @@ void StateValues<T, N>::inState(StateMachineInput smi) {
206 207
                 tmp += N + 1;
207 208
             }
208 209
 
209
-            while (tmp >= (N + 1)) {
210
+            while (tmp >= N + 1) {
210 211
                 tmp -= N + 1;
211 212
             }
212 213
 
213
-            pos = tmp;
214
+            while (tmp < off) {
215
+                off--;
216
+            }
214 217
 
218
+            while (tmp >= (off + lcd_text_lines())) {
219
+                off++;
220
+            }
221
+
222
+            pos = tmp;
215 223
             display();
216 224
         }
217 225
         if (smi.click) {
@@ -237,3 +245,4 @@ void StateValues<T, N>::inState(StateMachineInput smi) {
237 245
 
238 246
 template class StateValues<uint8_t, 2>;
239 247
 template class StateValues<float, 2>;
248
+template class StateValues<float, 12>;

+ 119
- 12
src/states.cpp View File

@@ -12,11 +12,20 @@
12 12
 //#define DISABLE_HOMING_STATE
13 13
 #define ENABLE_MOVEMENT_TEST_STATE
14 14
 #define ENABLE_INPUT_TEST_STATE
15
+#define ENABLE_MAX_SPEED_ACCEL_STATE
15 16
 
16 17
 // --------------------------------------
17 18
 
18 19
 int preset_selection = 0, dispense_off = 0,  dispense_count = 0, dispense_index = 0;
19 20
 float move_pos_x = 0.0, move_pos_y = 0.0, move_pos_z = 0.0, move_pos_e = 0.0;
21
+float mod_count_x, mod_count_y;
22
+float mod_distance_x, mod_distance_y;
23
+float mod_offset_x, mod_offset_y;
24
+float mod_move_z;
25
+float mod_bottom_z, mod_top_z;
26
+float mod_extrusion_length;
27
+float mod_extrusion_bottom_wait;
28
+float mod_extrusion_top_wait;
20 29
 
21 30
 State sm_ask_homing = State();
22 31
 State sm_do_homing = State(&sm_ask_homing);
@@ -46,10 +55,10 @@ StateValues<float, 2> sm_wiz_last_pos = StateValues<float, 2>(&sm_wiz_first_pos)
46 55
 State sm_new_preset_done = State(&sm_wiz_last_pos);
47 56
 
48 57
 StateDynamicMenu sm_mod_preset = StateDynamicMenu(&sm_auto);
49
-// TODO modify
58
+StateValues<float, 12> sm_mod_values = StateValues<float, 12>(&sm_mod_preset);
50 59
 
51 60
 StateDynamicMenu sm_del_preset = StateDynamicMenu(&sm_auto);
52
-// TODO delete
61
+// TODO delete yes/no choice
53 62
 
54 63
 StateMenu sm_move = StateMenu(&sm_menu);
55 64
 StateValue<float> sm_move_x = StateValue<float>(&sm_move, move_pos_x, X_AXIS_MIN, X_AXIS_MAX);
@@ -72,7 +81,7 @@ StateValue<float> sm_conf_accel_e = StateValue<float>(&sm_config, data_options()
72 81
 
73 82
 State sm_error = State(NULL);
74 83
 
75
-#if defined(ENABLE_MOVEMENT_TEST_STATE) || defined(ENABLE_INPUT_TEST_STATE)
84
+#if defined(ENABLE_MOVEMENT_TEST_STATE) || defined(ENABLE_INPUT_TEST_STATE) || defined(ENABLE_MAX_SPEED_ACCEL_STATE)
76 85
 StateMenu sm_debug = StateMenu(&sm_menu);
77 86
 #endif
78 87
 
@@ -89,6 +98,11 @@ State sm_move_e_test = State(&sm_movement_test);
89 98
 State sm_input_test = State(&sm_debug);
90 99
 #endif // ENABLE_INPUT_TEST_STATE
91 100
 
101
+#ifdef ENABLE_MAX_SPEED_ACCEL_STATE
102
+State sm_set_max_speed = State(&sm_debug);
103
+State sm_set_max_accel = State(&sm_debug);
104
+#endif // ENABLE_MAX_SPEED_ACCEL_STATE
105
+
92 106
 // --------------------------------------
93 107
 
94 108
 State *current_state = NULL;
@@ -260,6 +274,11 @@ void states_init(void) {
260 274
         int y = dispense_index / data_preset(preset_selection)->count_x;
261 275
         int x = dispense_index % data_preset(preset_selection)->count_x;
262 276
 
277
+        // keep movements shorter by switching x axis every odd y row
278
+        if (y % 2) {
279
+            x = data_preset(preset_selection)->count_x - x - 1;
280
+        }
281
+
263 282
         Serial.print(F("xy_travel: index="));
264 283
         Serial.print(dispense_index);
265 284
         Serial.print(F(" x="));
@@ -350,12 +369,12 @@ void states_init(void) {
350 369
     });
351 370
 
352 371
     sm_wiz_count.setTitle("Container Count");
353
-    sm_wiz_count.setData(0, "X: ", &wizard_preset.count_x, 1, 50);
354
-    sm_wiz_count.setData(1, "Y: ", &wizard_preset.count_y, 1, 100);
372
+    sm_wiz_count.setData(0, "X:", &wizard_preset.count_x, 1, 50);
373
+    sm_wiz_count.setData(1, "Y:", &wizard_preset.count_y, 1, 100);
355 374
 
356 375
     sm_wiz_first_pos.setTitle("First Container Position");
357
-    sm_wiz_first_pos.setData(0, "X: ", &wizard_first_x, X_AXIS_MIN, X_AXIS_MAX);
358
-    sm_wiz_first_pos.setData(1, "Y: ", &wizard_first_y, Y_AXIS_MIN, Y_AXIS_MAX);
376
+    sm_wiz_first_pos.setData(0, "X:", &wizard_first_x, X_AXIS_MIN, X_AXIS_MAX);
377
+    sm_wiz_first_pos.setData(1, "Y:", &wizard_first_y, Y_AXIS_MIN, Y_AXIS_MAX);
359 378
     sm_wiz_first_pos.onEnter([]() {
360 379
         wizard_first_x = steppers_current_pos(0);
361 380
         wizard_first_y = steppers_current_pos(1);
@@ -376,8 +395,8 @@ void states_init(void) {
376 395
     });
377 396
 
378 397
     sm_wiz_last_pos.setTitle("Last Container Position");
379
-    sm_wiz_last_pos.setData(0, "X: ", &wizard_last_x, X_AXIS_MIN, X_AXIS_MAX);
380
-    sm_wiz_last_pos.setData(1, "Y: ", &wizard_last_y, Y_AXIS_MIN, Y_AXIS_MAX);
398
+    sm_wiz_last_pos.setData(0, "X:", &wizard_last_x, X_AXIS_MIN, X_AXIS_MAX);
399
+    sm_wiz_last_pos.setData(1, "Y:", &wizard_last_y, Y_AXIS_MIN, Y_AXIS_MAX);
381 400
     sm_wiz_last_pos.onEnter([]() {
382 401
         wizard_last_x = steppers_current_pos(0);
383 402
         wizard_last_y = steppers_current_pos(1);
@@ -416,13 +435,71 @@ void states_init(void) {
416 435
         }
417 436
     });
418 437
 
419
-    // TODO
420 438
     sm_mod_preset.setTitle("Modify Preset");
421 439
     sm_mod_preset.setPrefix("Preset ");
422 440
     sm_mod_preset.dataCount([]() {
423 441
         return (int)data_preset_count();
424 442
     });
425 443
     sm_mod_preset.dataGet(preset_name_func);
444
+    sm_mod_preset.dataCall([](int i) {
445
+        preset_selection = i;
446
+        states_go_to(&sm_mod_values);
447
+    });
448
+
449
+    sm_mod_values.setTitle("Modify Preset");
450
+    sm_mod_values.setData(0, "Count X", &mod_count_x, 1, 50);
451
+    sm_mod_values.setData(1, "Count Y", &mod_count_y, 1, 100);
452
+    sm_mod_values.setData(2, "Distance X", &mod_distance_x, X_AXIS_MIN, X_AXIS_MAX);
453
+    sm_mod_values.setData(3, "Distance Y", &mod_distance_y, Y_AXIS_MIN, Y_AXIS_MAX);
454
+    sm_mod_values.setData(4, "Offset X", &mod_offset_x, X_AXIS_MIN, X_AXIS_MAX);
455
+    sm_mod_values.setData(5, "Offset Y", &mod_offset_y, Y_AXIS_MIN, Y_AXIS_MAX);
456
+    sm_mod_values.setData(6, "Travel Z", &mod_move_z, Z_AXIS_MIN, Z_AXIS_MAX);
457
+    sm_mod_values.setData(7, "Bottom Z", &mod_bottom_z, Z_AXIS_MIN, Z_AXIS_MAX);
458
+    sm_mod_values.setData(8, "Top Z", &mod_top_z, Z_AXIS_MIN, Z_AXIS_MAX);
459
+    sm_mod_values.setData(9, "Extrusion Length", &mod_extrusion_length, E_AXIS_MIN, E_AXIS_MAX);
460
+    sm_mod_values.setData(10, "Extrusion Bottom", &mod_extrusion_bottom_wait, 0, 10);
461
+    sm_mod_values.setData(11, "Extrusion Top", &mod_extrusion_top_wait, 0, 10);
462
+    sm_mod_values.onEnter([]() {
463
+        mod_count_x = data_preset(preset_selection)->count_x;
464
+        mod_count_y = data_preset(preset_selection)->count_y;
465
+        mod_distance_x = data_preset(preset_selection)->distance_x;
466
+        mod_distance_y = data_preset(preset_selection)->distance_y;
467
+        mod_offset_x = data_preset(preset_selection)->offset_x;
468
+        mod_offset_y = data_preset(preset_selection)->offset_y;
469
+        mod_move_z = data_preset(preset_selection)->move_z;
470
+        mod_bottom_z = data_preset(preset_selection)->bottom_z;
471
+        mod_top_z = data_preset(preset_selection)->top_z;
472
+        mod_extrusion_length = data_preset(preset_selection)->extrusion_length;
473
+        mod_extrusion_bottom_wait = data_preset(preset_selection)->extrusion_bottom_wait;
474
+        mod_extrusion_top_wait = data_preset(preset_selection)->extrusion_top_wait;
475
+    });
476
+    sm_mod_values.onUpdate([](size_t i, float v) {
477
+        if (i == 0) {
478
+            data_preset(preset_selection)->count_x = v;
479
+        } else if (i == 1) {
480
+            data_preset(preset_selection)->count_y = v;
481
+        } else if (i == 2) {
482
+            data_preset(preset_selection)->distance_x = v;
483
+        } else if (i == 3) {
484
+            data_preset(preset_selection)->distance_y = v;
485
+        } else if (i == 4) {
486
+            data_preset(preset_selection)->offset_x = v;
487
+        } else if (i == 5) {
488
+            data_preset(preset_selection)->offset_y = v;
489
+        } else if (i == 6) {
490
+            data_preset(preset_selection)->move_z = v;
491
+        } else if (i == 7) {
492
+            data_preset(preset_selection)->bottom_z = v;
493
+        } else if (i == 8) {
494
+            data_preset(preset_selection)->top_z = v;
495
+        } else if (i == 9) {
496
+            data_preset(preset_selection)->extrusion_length = v;
497
+        } else if (i == 10) {
498
+            data_preset(preset_selection)->extrusion_bottom_wait = v;
499
+        } else if (i == 11) {
500
+            data_preset(preset_selection)->extrusion_top_wait = v;
501
+        }
502
+    });
426 503
 
427 504
     sm_del_preset.setTitle("Delete Preset");
428 505
     sm_del_preset.setPrefix("Preset ");
@@ -521,7 +598,7 @@ void states_init(void) {
521 598
     sm_error.setHeading("Axis Error");
522 599
     sm_error.setText("An unknown error occured!");
523 600
 
524
-#if defined(ENABLE_MOVEMENT_TEST_STATE) || defined(ENABLE_INPUT_TEST_STATE)
601
+#if defined(ENABLE_MOVEMENT_TEST_STATE) || defined(ENABLE_INPUT_TEST_STATE) || defined(ENABLE_MAX_SPEED_ACCEL_STATE)
525 602
     sm_debug.setTitle("Debug Menu");
526 603
 #endif
527 604
 
@@ -595,7 +672,7 @@ void states_init(void) {
595 672
         static bool s = false;
596 673
         if (smi.motor_done[E_AXIS]) {
597 674
             s = !s;
598
-            steppers_move_e(s ? (E_AXIS_MAX - E_AXIS_EPSILON) : (E_AXIS_MIN + E_AXIS_EPSILON));
675
+            steppers_move_e(s ? (E_AXIS_MAX /* - E_AXIS_EPSILON */) : (E_AXIS_MIN /* + E_AXIS_EPSILON */));
599 676
         }
600 677
         if (smi.click) {
601 678
             states_go_to(&sm_movement_test);
@@ -627,6 +704,36 @@ void states_init(void) {
627 704
     });
628 705
 #endif // ENABLE_INPUT_TEST_STATE
629 706
 
707
+#ifdef ENABLE_MAX_SPEED_ACCEL_STATE
708
+    sm_set_max_speed.setTitle("Set Max Speeds");
709
+    sm_set_max_speed.setText("Maximum speeds have been set for all axes. Don't forget to store to EEPROM if desired!");
710
+    sm_set_max_speed.onEnter([]() {
711
+        data_options()->speed_x = XY_MAX_SPEED;
712
+        data_options()->speed_y = XY_MAX_SPEED;
713
+        data_options()->speed_z = Z_MAX_SPEED;
714
+        data_options()->speed_e = E_MAX_SPEED;
715
+
716
+        steppers_set_speed_x(data_options()->speed_x);
717
+        steppers_set_speed_y(data_options()->speed_y);
718
+        steppers_set_speed_z(data_options()->speed_z);
719
+        steppers_set_speed_e(data_options()->speed_e);
720
+    });
721
+
722
+    sm_set_max_accel.setTitle("Set Max Accels");
723
+    sm_set_max_accel.setText("Maximum accelerations have been set for all axes. Don't forget to store to EEPROM if desired!");
724
+    sm_set_max_accel.onEnter([]() {
725
+        data_options()->accel_x = XY_MAX_ACCEL;
726
+        data_options()->accel_y = XY_MAX_ACCEL;
727
+        data_options()->accel_z = Z_MAX_ACCEL;
728
+        data_options()->accel_e = E_MAX_ACCEL;
729
+
730
+        steppers_set_accel_x(data_options()->accel_x);
731
+        steppers_set_accel_y(data_options()->accel_y);
732
+        steppers_set_accel_z(data_options()->accel_z);
733
+        steppers_set_accel_e(data_options()->accel_e);
734
+    });
735
+#endif // ENABLE_MAX_SPEED_ACCEL_STATE
736
+
630 737
     // ----------------------------------
631 738
 
632 739
     states_go_to(&sm_ask_homing);

+ 66
- 48
src/steppers.cpp View File

@@ -9,15 +9,22 @@
9 9
 #include "states.h"
10 10
 #include "steppers.h"
11 11
 
12
+#define DEBUG_PRINT_STEPPER_HOME
13
+#define DISABLE_ENDSTOP_CHECKS_AT_RUNTIME
14
+
12 15
 static AccelStepper stepper_x(AccelStepper::DRIVER, X_STEP_PIN, X_DIR_PIN, 0, 0, false);
13 16
 static AccelStepper stepper_y(AccelStepper::DRIVER, Y_STEP_PIN, Y_DIR_PIN, 0, 0, false);
14 17
 static AccelStepper stepper_z(AccelStepper::DRIVER, Z_STEP_PIN, Z_DIR_PIN, 0, 0, false);
15 18
 static AccelStepper stepper_e(AccelStepper::DRIVER, E0_STEP_PIN, E0_DIR_PIN, 0, 0, false);
16 19
 
20
+// X Y Z
17 21
 #define HOME_PHASE_START 0
18 22
 #define HOME_PHASE_BACK 1
19 23
 #define HOME_PHASE_FINE 2
20 24
 
25
+// E
26
+#define HOME_PHASE_END 3
27
+
21 28
 enum stepper_states {
22 29
     step_disabled,
23 30
     step_not_homed,
@@ -30,9 +37,10 @@ enum stepper_states {
30 37
     step_homing_z_fast,
31 38
     step_homing_z_back,
32 39
     step_homing_z_slow,
33
-    step_homing_e_fast,
34
-    step_homing_e_back,
35
-    step_homing_e_slow,
40
+    step_homing_e_start,
41
+    step_homing_e_left,
42
+    step_homing_e_right,
43
+    step_homing_e_end,
36 44
     step_homed
37 45
 };
38 46
 
@@ -89,15 +97,15 @@ void steppers_init(void) {
89 97
 }
90 98
 
91 99
 static void steppers_initiate_home(int axis, int phase) {
92
-#if 0
100
+#ifdef DEBUG_PRINT_STEPPER_HOME
93 101
     Serial.print(F("steppers_initiate_home("));
94
-    if (axis == 0) {
102
+    if (axis == X_AXIS) {
95 103
         Serial.print('X');
96
-    } else if (axis == 1) {
104
+    } else if (axis == Y_AXIS) {
97 105
         Serial.print('Y');
98
-    } else if (axis == 2) {
106
+    } else if (axis == Z_AXIS) {
99 107
         Serial.print('Z');
100
-    } else if (axis == 3) {
108
+    } else if (axis == E_AXIS) {
101 109
         Serial.print('E');
102 110
     } else {
103 111
         Serial.print(axis);
@@ -105,14 +113,13 @@ static void steppers_initiate_home(int axis, int phase) {
105 113
     Serial.print(F(", "));
106 114
     Serial.print(phase);
107 115
     Serial.println(F(")"));
108
-#endif
116
+#endif // DEBUG_PRINT_STEPPER_HOME
109 117
 
110 118
     CLEAR_STORE_INTERRUPTS();
111 119
 
112 120
     steppers_home_move_start_time = millis();
113 121
 
114 122
     if (axis == X_AXIS) {
115
-        // x
116 123
         if (phase == HOME_PHASE_START) {
117 124
             if (steppers_home_switch(axis)) {
118 125
 #if (X_MIN_PIN == -1)
@@ -121,7 +128,6 @@ static void steppers_initiate_home(int axis, int phase) {
121 128
                 stepper_x.setCurrentPosition(X_AXIS_MIN * XY_STEPS_PER_MM * X_AXIS_MOVEMENT_DIR);
122 129
 #endif
123 130
 
124
-                // TODO order of homing
125 131
                 steppers_initiate_home(Y_AXIS, HOME_PHASE_START);
126 132
             } else {
127 133
                 state = step_homing_x_fast;
@@ -135,7 +141,6 @@ static void steppers_initiate_home(int axis, int phase) {
135 141
             stepper_x.setSpeed(X_HOMING_DIR * X_AXIS_MOVEMENT_DIR * XY_SLOW_HOME_SPEED * XY_STEPS_PER_MM);
136 142
         }
137 143
     } else if (axis == Y_AXIS) {
138
-        // y
139 144
         if (phase == HOME_PHASE_START) {
140 145
             if (steppers_home_switch(axis)) {
141 146
 
@@ -145,9 +150,7 @@ static void steppers_initiate_home(int axis, int phase) {
145 150
                 stepper_y.setCurrentPosition(Y_AXIS_MIN * XY_STEPS_PER_MM * Y_AXIS_MOVEMENT_DIR);
146 151
 #endif
147 152
 
148
-                // TODO order of homing
149
-                //steppers_initiate_home(Z_AXIS, HOME_PHASE_START);
150
-                state = step_homed;
153
+                steppers_initiate_home(E_AXIS, HOME_PHASE_START);
151 154
             } else {
152 155
                 state = step_homing_y_fast;
153 156
                 stepper_y.setSpeed(Y_HOMING_DIR * Y_AXIS_MOVEMENT_DIR * XY_FAST_HOME_SPEED * XY_STEPS_PER_MM);
@@ -160,7 +163,6 @@ static void steppers_initiate_home(int axis, int phase) {
160 163
             stepper_y.setSpeed(Y_HOMING_DIR * Y_AXIS_MOVEMENT_DIR * XY_SLOW_HOME_SPEED * XY_STEPS_PER_MM);
161 164
         }
162 165
     } else if (axis == Z_AXIS) {
163
-        // z
164 166
         if (phase == HOME_PHASE_START) {
165 167
             state = step_homing_z_fast;
166 168
             stepper_z.setSpeed(Z_HOMING_DIR * Z_AXIS_MOVEMENT_DIR * Z_FAST_HOME_SPEED * Z_STEPS_PER_MM);
@@ -172,16 +174,36 @@ static void steppers_initiate_home(int axis, int phase) {
172 174
             stepper_z.setSpeed(Z_HOMING_DIR * Z_AXIS_MOVEMENT_DIR * Z_SLOW_HOME_SPEED * Z_STEPS_PER_MM);
173 175
         }
174 176
     } else if (axis == E_AXIS) {
175
-        // e
176 177
         if (phase == HOME_PHASE_START) {
177
-            state = step_homing_e_fast;
178
-            stepper_e.setSpeed(E_HOMING_DIR * E_AXIS_MOVEMENT_DIR * E_FAST_HOME_SPEED * E_STEPS_PER_PERCENT);
178
+            if (steppers_home_switch(axis)) {
179
+                Serial.println(F("already hit, continue"));
180
+
181
+                steppers_initiate_home(E_AXIS, HOME_PHASE_BACK);
182
+            } else {
183
+                Serial.println(F("moving towards endstop"));
184
+
185
+                state = step_homing_e_start;
186
+                stepper_e.setSpeed(-1.0 * E_HOMING_DIR * E_AXIS_MOVEMENT_DIR * E_FAST_HOME_SPEED * E_STEPS_PER_PERCENT);
187
+            }
179 188
         } else if (phase == HOME_PHASE_BACK) {
180
-            state = step_homing_e_back;
181
-            stepper_e.setSpeed(-1.0 * E_HOMING_DIR * E_AXIS_MOVEMENT_DIR * E_FAST_HOME_SPEED * E_STEPS_PER_PERCENT);
182
-        } else if (phase == HOME_PHASE_FINE) {
183
-            state = step_homing_e_slow;
189
+            Serial.println(F("moving toward left end"));
190
+
191
+            state = step_homing_e_left;
184 192
             stepper_e.setSpeed(E_HOMING_DIR * E_AXIS_MOVEMENT_DIR * E_SLOW_HOME_SPEED * E_STEPS_PER_PERCENT);
193
+        } else if (phase == HOME_PHASE_FINE) {
194
+            Serial.print(F("moving toward right end, at "));
195
+            Serial.println(E_MM_TO_PERCENT(E_AXIS_MAX / 2) * E_STEPS_PER_PERCENT * E_AXIS_MOVEMENT_DIR * E_HOMING_DIR);
196
+
197
+            state = step_homing_e_right;
198
+            stepper_e.setMaxSpeed(E_SLOW_HOME_SPEED * E_STEPS_PER_PERCENT);
199
+            stepper_e.moveTo(E_MM_TO_PERCENT(E_AXIS_MAX / 2) * E_STEPS_PER_PERCENT * E_AXIS_MOVEMENT_DIR * E_HOMING_DIR);
200
+        } else if (phase == HOME_PHASE_END) {
201
+            Serial.print(F("moving toward new zero, at "));
202
+            Serial.println(stepper_e.currentPosition() / 2);
203
+
204
+            state = step_homing_e_end;
205
+            stepper_e.setMaxSpeed(E_FAST_HOME_SPEED * E_STEPS_PER_PERCENT);
206
+            stepper_e.moveTo(stepper_e.currentPosition() / 2);
185 207
         }
186 208
     } else {
187 209
         Serial.println(F("home_init error: invalid axis"));
@@ -256,6 +278,7 @@ float steppers_current_pos(int axis) {
256 278
 
257 279
 void steppers_run(void) {
258 280
     if ((state == step_homed) || (state == step_not_homed)) {
281
+#ifndef DISABLE_ENDSTOP_CHECKS_AT_RUNTIME
259 282
         for (int i = 0; i < AXIS_COUNT; i++) {
260 283
 #if 0
261 284
             Serial.print(i);
@@ -288,11 +311,7 @@ void steppers_run(void) {
288 311
     #endif
289 312
                 } else if (i == E_AXIS) {
290 313
                     epsilon = E_AXIS_EPSILON;
291
-    #if (E_HOMING_DIR == 1)
292
-                    compare = E_AXIS_MAX;
293
-    #else
294
-                    compare = E_AXIS_MIN;
295
-    #endif
314
+                    // TODO compare to 0 and 200%!
296 315
                 }
297 316
 
298 317
                 if (fabs(steppers_current_pos(i) - compare) > epsilon) {
@@ -318,6 +337,7 @@ void steppers_run(void) {
318 337
                 }
319 338
             }
320 339
         }
340
+#endif // DISABLE_ENDSTOP_CHECKS_AT_RUNTIME
321 341
 
322 342
         x_finished = !stepper_x.run();
323 343
         y_finished = !stepper_y.run();
@@ -373,9 +393,7 @@ void steppers_run(void) {
373 393
             stepper_y.setCurrentPosition(Y_AXIS_MIN * XY_STEPS_PER_MM * Y_AXIS_MOVEMENT_DIR);
374 394
 #endif
375 395
 
376
-            //steppers_initiate_home(E_AXIS, HOME_PHASE_START);
377
-            // TODO
378
-            state = step_homed;
396
+            steppers_initiate_home(E_AXIS, HOME_PHASE_START);
379 397
         } else {
380 398
             stepper_y.runSpeed();
381 399
         }
@@ -406,32 +424,32 @@ void steppers_run(void) {
406 424
         } else {
407 425
             stepper_z.runSpeed();
408 426
         }
409
-    } else if (state == step_homing_e_fast) {
427
+    } else if (state == step_homing_e_start) {
410 428
         if (steppers_home_switch(E_AXIS)) {
411 429
             steppers_initiate_home(E_AXIS, HOME_PHASE_BACK);
412 430
         } else {
413 431
             stepper_e.runSpeed();
414 432
         }
415
-    } else if (state == step_homing_e_back) {
416
-        unsigned long end_time = steppers_home_move_start_time + E_HOME_BACK_OFF_TIME;
417
-        if ((!steppers_home_switch(E_AXIS)) && (millis() >= end_time)) {
433
+    } else if (state == step_homing_e_left) {
434
+        if (!steppers_home_switch(E_AXIS)) {
435
+            stepper_e.setSpeed(0);
436
+            stepper_e.setCurrentPosition(0);
418 437
             steppers_initiate_home(E_AXIS, HOME_PHASE_FINE);
419 438
         } else {
420 439
             stepper_e.runSpeed();
421 440
         }
422
-    } else if (state == step_homing_e_slow) {
423
-        if (steppers_home_switch(E_AXIS)) {
424
-            stepper_e.setSpeed(0);
425
-
426
-#if (E_MIN_PIN == -1)
427
-            stepper_e.setCurrentPosition(E_MM_TO_PERCENT(E_AXIS_MAX) * E_STEPS_PER_PERCENT * E_AXIS_MOVEMENT_DIR);
428
-#else
441
+    } else if (state == step_homing_e_right) {
442
+        if ((!steppers_home_switch(E_AXIS)) && ((stepper_e.currentPosition() > 200) || (stepper_e.currentPosition() < -200))) {
443
+            // TODO only if we've moved a bit (250 is center)
444
+            steppers_initiate_home(E_AXIS, HOME_PHASE_END);
445
+        } else {
446
+            stepper_e.run();
447
+        }
448
+    } else if (state == step_homing_e_end) {
449
+        if (!stepper_e.run()) {
450
+            stepper_e.setMaxSpeed(data_options()->speed_e * E_STEPS_PER_PERCENT);
429 451
             stepper_e.setCurrentPosition(E_MM_TO_PERCENT(E_AXIS_MIN) * E_STEPS_PER_PERCENT * E_AXIS_MOVEMENT_DIR);
430
-#endif
431
-
432 452
             state = step_homed;
433
-        } else {
434
-            stepper_e.runSpeed();
435 453
         }
436 454
     }
437 455
 }
@@ -453,7 +471,7 @@ char steppers_homing_axis(void) {
453 471
         r = 'Y';
454 472
     } else if ((state == step_homing_z_fast) || (state == step_homing_z_back) || (state == step_homing_z_slow)) {
455 473
         r = 'Z';
456
-    } else if ((state == step_homing_e_fast) || (state == step_homing_e_back) || (state == step_homing_e_slow)) {
474
+    } else if ((state == step_homing_e_start) || (state == step_homing_e_left) || (state == step_homing_e_right) || (state == step_homing_e_end)) {
457 475
         r = 'E';
458 476
     }
459 477
 
@@ -471,8 +489,8 @@ void steppers_start_homing(void) {
471 489
     stepper_z.enableOutputs();
472 490
     stepper_e.enableOutputs();
473 491
 
474
-    //steppers_initiate_home(Z_AXIS, HOME_PHASE_START);
475 492
     // TODO
493
+    //steppers_initiate_home(Z_AXIS, HOME_PHASE_START);
476 494
     steppers_initiate_home(X_AXIS, HOME_PHASE_START);
477 495
 
478 496
     RESTORE_INTERRUPTS();

Loading…
Cancel
Save