Browse Source

move e axis when filling. fix bug that prevented states showing their heading. fix encoder rpm scaling.

Thomas Buck 2 years ago
parent
commit
01c66d643b
3 changed files with 66 additions and 15 deletions
  1. 1
    1
      include/config.h
  2. 3
    3
      src/statemachine.cpp
  3. 62
    11
      src/states.cpp

+ 1
- 1
include/config.h View File

@@ -110,7 +110,7 @@
110 110
 #define Z_AXIS_EPSILON 1.0 // in mm
111 111
 #define E_AXIS_EPSILON 50.0 // TODO
112 112
 
113
-#define ENCODER_RPM_VALUE_FACTOR 0.5
113
+#define ENCODER_RPM_VALUE_FACTOR 4.2
114 114
 #define IDLE_TIMEOUT (5UL * 60UL * 1000UL) // ms, 0 to disable
115 115
 
116 116
 // TimerOne freq for steppers

+ 3
- 3
src/statemachine.cpp View File

@@ -28,13 +28,13 @@ State::State(State *_parent)
28 28
 void State::updateText(void) {
29 29
     lcd_clear();
30 30
 
31
-    if (heading != NULL) {
31
+    if ((heading != NULL) && (strlen(heading) > 0)) {
32 32
         lcd_set_heading(heading);
33
-    } else if (getTitle() != NULL) {
33
+    } else if ((getTitle() != NULL) && (strlen(getTitle()) > 0)) {
34 34
         lcd_set_heading(getTitle());
35 35
     }
36 36
 
37
-    if (text != NULL) {
37
+    if ((text != NULL) && (strlen(text) > 0)) {
38 38
         lcd_set_text(text);
39 39
     }
40 40
 }

+ 62
- 11
src/states.cpp View File

@@ -40,8 +40,12 @@ State sm_disp_go = State(&sm_disp_cnt);
40 40
 State sm_disp_run_z_travel = State(&sm_disp_go);
41 41
 State sm_disp_run_xy_travel = State(&sm_disp_run_z_travel);
42 42
 State sm_disp_run_z_disp = State(&sm_disp_run_xy_travel);
43
+// TODO add state for extrusion_bottom_wait
43 44
 State sm_disp_run = State(&sm_disp_run_z_disp);
44
-State sm_disp_done = State(&sm_disp_run);
45
+State sm_disp_run_back = State(&sm_disp_run);
46
+// TODO add state for extrusion_top_wait
47
+State sm_disp_done = State(&sm_disp_run_back);
48
+State sm_disp_really_done = State(&sm_disp_done);
45 49
 
46 50
 State sm_new_preset = State(&sm_auto);
47 51
 State sm_wiz_move = State(&sm_new_preset);
@@ -260,10 +264,13 @@ void states_init(void) {
260 264
     sm_disp_run_z_travel.setTitle("Z Travel");
261 265
     sm_disp_run_z_travel.onEnter([]() {
262 266
         // TODO move z to travel height
267
+
268
+        // print status text
269
+        strbuf = String(F("Filling ")) + String(dispense_index + 1);
270
+        strbuf += String(F(" / ")) + String(data_preset(preset_selection)->count_x * data_preset(preset_selection)->count_y);
271
+        sm_disp_run_z_travel.setText(strbuf.c_str());
263 272
     });
264 273
     sm_disp_run_z_travel.whenIn([](StateMachineInput smi) {
265
-        // TODO update status screen
266
-
267 274
         if (smi.all_motors_done) {
268 275
             states_go_to(&sm_disp_run_xy_travel);
269 276
         }
@@ -291,10 +298,13 @@ void states_init(void) {
291 298
 
292 299
         steppers_move_x(x_pos);
293 300
         steppers_move_y(y_pos);
301
+
302
+        // print status text
303
+        strbuf = String(F("Filling ")) + String(dispense_index + 1);
304
+        strbuf += String(F(" / ")) + String(data_preset(preset_selection)->count_x * data_preset(preset_selection)->count_y);
305
+        sm_disp_run_xy_travel.setText(strbuf.c_str());
294 306
     });
295 307
     sm_disp_run_xy_travel.whenIn([](StateMachineInput smi) {
296
-        // TODO update status screen
297
-
298 308
         if (smi.all_motors_done) {
299 309
             states_go_to(&sm_disp_run_z_disp);
300 310
         }
@@ -302,11 +312,14 @@ void states_init(void) {
302 312
 
303 313
     sm_disp_run_z_disp.setTitle("Z Dispense");
304 314
     sm_disp_run_z_disp.onEnter([]() {
305
-        // TODO move z to dispension height
315
+        // TODO move z to bottom_z
316
+
317
+        // print status text
318
+        strbuf = String(F("Filling ")) + String(dispense_index + 1);
319
+        strbuf += String(F(" / ")) + String(data_preset(preset_selection)->count_x * data_preset(preset_selection)->count_y);
320
+        sm_disp_run_z_disp.setText(strbuf.c_str());
306 321
     });
307 322
     sm_disp_run_z_disp.whenIn([](StateMachineInput smi) {
308
-        // TODO update status screen
309
-
310 323
         if (smi.all_motors_done) {
311 324
             states_go_to(&sm_disp_run);
312 325
         }
@@ -314,11 +327,33 @@ void states_init(void) {
314 327
 
315 328
     sm_disp_run.setTitle("Dispensing");
316 329
     sm_disp_run.onEnter([]() {
317
-        // TODO start dispensing with e and moving z up
330
+        // TODO move z to top_z
331
+
332
+        // move e to extrusion_length (bottom of press)
333
+        steppers_move_e(data_preset(preset_selection)->extrusion_length);
334
+
335
+        // print status text
336
+        strbuf = String(F("Filling ")) + String(dispense_index + 1);
337
+        strbuf += String(F(" / ")) + String(data_preset(preset_selection)->count_x * data_preset(preset_selection)->count_y);
338
+        sm_disp_run.setText(strbuf.c_str());
318 339
     });
319 340
     sm_disp_run.whenIn([](StateMachineInput smi) {
320
-        // TODO update status screen
341
+        if (smi.all_motors_done) {
342
+            states_go_to(&sm_disp_run_back);
343
+        }
344
+    });
345
+
346
+    sm_disp_run_back.setTitle("Dispensing Back");
347
+    sm_disp_run_back.onEnter([]() {
348
+        // move e back to 0 (top)
349
+        steppers_move_e(0.0);
321 350
 
351
+        // print status text
352
+        strbuf = String(F("Filling ")) + String(dispense_index + 1);
353
+        strbuf += String(F(" / ")) + String(data_preset(preset_selection)->count_x * data_preset(preset_selection)->count_y);
354
+        sm_disp_run_back.setText(strbuf.c_str());
355
+    });
356
+    sm_disp_run_back.whenIn([](StateMachineInput smi) {
322 357
         if (smi.all_motors_done) {
323 358
             dispense_index++;
324 359
             if (dispense_index >= (dispense_count + dispense_off)) {
@@ -330,10 +365,26 @@ void states_init(void) {
330 365
     });
331 366
 
332 367
     sm_disp_done.setTitle("Finished");
368
+    sm_disp_done.setText("Moving to take-out position.");
333 369
     sm_disp_done.onEnter([]() {
334
-        // TODO show end screen, "stats"
370
+        steppers_move_x(X_AXIS_MAX - 20.0);
371
+        steppers_move_y(Y_AXIS_MAX - 20.0);
372
+        // TODO move z to travel height
335 373
     });
336 374
     sm_disp_done.whenIn([](StateMachineInput smi) {
375
+        if (smi.click || smi.all_motors_done) {
376
+            states_go_to(&sm_disp_really_done);
377
+        }
378
+    });
379
+
380
+    sm_disp_really_done.setTitle("Finished");
381
+    sm_disp_really_done.setText("Please remove tray and click to continue.");
382
+    sm_disp_really_done.onEnter([]() {
383
+        // "stop" steppers without killing them
384
+        steppers_move_x(steppers_current_pos(X_AXIS));
385
+        steppers_move_y(steppers_current_pos(Y_AXIS));
386
+    });
387
+    sm_disp_really_done.whenIn([](StateMachineInput smi) {
337 388
         if (smi.click) {
338 389
             states_go_to(&sm_auto);
339 390
         }

Loading…
Cancel
Save