Selaa lähdekoodia

Added endstop reporting

Erik van der Zalm 12 vuotta sitten
vanhempi
commit
4e5becfc51
4 muutettua tiedostoa jossa 138 lisäystä ja 146 poistoa
  1. 11
    13
      Marlin/Marlin.pde
  2. 1
    0
      Marlin/planner.cpp
  3. 76
    83
      Marlin/stepper.cpp
  4. 50
    50
      Marlin/stepper.h

+ 11
- 13
Marlin/Marlin.pde Näytä tiedosto

@@ -465,24 +465,22 @@ inline bool code_seen(char code)
465 465
     destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
466 466
     feedrate = homing_feedrate[LETTER##_AXIS]; \
467 467
     prepare_move(); \
468
-    st_synchronize();\
469 468
     \
470 469
     current_position[LETTER##_AXIS] = 0;\
471 470
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
472 471
     destination[LETTER##_AXIS] = -5 * LETTER##_HOME_DIR;\
473 472
     prepare_move(); \
474
-    st_synchronize();\
475 473
     \
476 474
     destination[LETTER##_AXIS] = 10 * LETTER##_HOME_DIR;\
477 475
     feedrate = homing_feedrate[LETTER##_AXIS]/2 ;  \
478 476
     prepare_move(); \
479
-    st_synchronize();\
480 477
     \
481 478
     current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
482 479
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
483 480
     destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\
484 481
     feedrate = 0.0;\
485 482
     st_synchronize();\
483
+    plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
486 484
     endstops_hit_on_purpose();\
487 485
   }
488 486
 
@@ -680,7 +678,7 @@ inline void process_commands()
680 678
     case 140: // M140 set bed temp
681 679
       if (code_seen('S')) setTargetBed(code_value());
682 680
       break;
683
-    case 105: // M105
681
+    case 105 : // M105
684 682
       //SERIAL_ECHOLN(freeMemory());
685 683
        //test watchdog:
686 684
        //delay(20000);
@@ -817,7 +815,7 @@ inline void process_commands()
817 815
       axis_relative_modes[3] = true;
818 816
       break;
819 817
     case 18: //compatibility
820
-    case 84:
818
+    case 84: // M84
821 819
       if(code_seen('S')){ 
822 820
         stepper_inactive_time = code_value() * 1000; 
823 821
       }
@@ -854,14 +852,14 @@ inline void process_commands()
854 852
       SERIAL_PROTOCOL(current_position[Z_AXIS]);
855 853
       SERIAL_PROTOCOLPGM("E:");      
856 854
       SERIAL_PROTOCOL(current_position[E_AXIS]);
857
-      #ifdef DEBUG_STEPS
858
-        SERIAL_PROTOCOLPGM(" Count X:");
859
-        SERIAL_PROTOCOL(float(count_position[X_AXIS])/axis_steps_per_unit[X_AXIS]);
860
-        SERIAL_PROTOCOLPGM("Y:");
861
-        SERIAL_PROTOCOL(float(count_position[Y_AXIS])/axis_steps_per_unit[Y_AXIS]);
862
-        SERIAL_PROTOCOLPGM("Z:");
863
-        SERIAL_PROTOCOL(float(count_position[Z_AXIS])/axis_steps_per_unit[Z_AXIS]);
864
-      #endif
855
+      
856
+      SERIAL_PROTOCOLPGM(" Count X:");
857
+      SERIAL_PROTOCOL(float(st_get_position(X_AXIS))/axis_steps_per_unit[X_AXIS]);
858
+      SERIAL_PROTOCOLPGM("Y:");
859
+      SERIAL_PROTOCOL(float(st_get_position(Y_AXIS))/axis_steps_per_unit[Y_AXIS]);
860
+      SERIAL_PROTOCOLPGM("Z:");
861
+      SERIAL_PROTOCOL(float(st_get_position(Z_AXIS))/axis_steps_per_unit[Z_AXIS]);
862
+      
865 863
       SERIAL_PROTOCOLLN("");
866 864
       break;
867 865
     case 119: // M119

+ 1
- 0
Marlin/planner.cpp Näytä tiedosto

@@ -754,6 +754,7 @@ void plan_set_position(const float &x, const float &y, const float &z, const flo
754 754
   position[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]);
755 755
   position[Z_AXIS] = lround(z*axis_steps_per_unit[Z_AXIS]);     
756 756
   position[E_AXIS] = lround(e*axis_steps_per_unit[E_AXIS]);  
757
+  st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]);
757 758
   previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
758 759
   previous_speed[0] = 0.0;
759 760
   previous_speed[1] = 0.0;

+ 76
- 83
Marlin/stepper.cpp Näytä tiedosto

@@ -66,14 +66,12 @@ static char step_loops;
66 66
 
67 67
 volatile long endstops_trigsteps[3]={0,0,0};
68 68
 volatile long endstops_stepsTotal,endstops_stepsDone;
69
-static volatile bool endstops_hit=false;
69
+static volatile bool endstop_x_hit=false;
70
+static volatile bool endstop_y_hit=false;
71
+static volatile bool endstop_z_hit=false;
70 72
 
71
-// if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
72
-// for debugging purposes only, should be disabled by default
73
-#ifdef DEBUG_STEPS
74
-  volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
75
-  volatile int count_direction[NUM_AXIS] = { 1, 1, 1, 1};
76
-#endif
73
+volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
74
+volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
77 75
 
78 76
 //===========================================================================
79 77
 //=============================functions         ============================
@@ -155,49 +153,32 @@ asm volatile ( \
155 153
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  TIMSK1 |= (1<<OCIE1A)
156 154
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
157 155
 
158
-
159
-inline void endstops_triggered(const unsigned long &stepstaken)  
160
-{
161
-  //this will only work if there is no bufferig
162
-  //however, if you perform a move at which the endstops should be triggered, and wait for it to complete, i.e. by blocking command, it should work
163
-  //yes, it uses floats, but: if endstops are triggered, thats hopefully not critical anymore anyways.
164
-  //endstops_triggerpos;
165
-  
166
-  if(endstops_hit) //hitting a second time while the first hit is not reported
167
-    return;
168
-  if(current_block == NULL)
169
-    return;
170
-  endstops_stepsTotal=current_block->step_event_count;
171
-  endstops_stepsDone=stepstaken;
172
-  endstops_trigsteps[0]=current_block->steps_x;
173
-  endstops_trigsteps[1]=current_block->steps_y;
174
-  endstops_trigsteps[2]=current_block->steps_z;
175
-
176
-  endstops_hit=true;
177
-}
178
-
179 156
 void checkHitEndstops()
180 157
 {
181
-  if( !endstops_hit)
182
-   return;
183
-  float endstops_triggerpos[3]={0,0,0};
184
-  float ratiodone=endstops_stepsDone/float(endstops_stepsTotal);  //ratio of current_block thas was performed
185
-  
186
-  endstops_triggerpos[0]=current_position[0]-(endstops_trigsteps[0]*ratiodone)/float(axis_steps_per_unit[0]);
187
-  endstops_triggerpos[1]=current_position[1]-(endstops_trigsteps[1]*ratiodone)/float(axis_steps_per_unit[1]);
188
-  endstops_triggerpos[2]=current_position[2]-(endstops_trigsteps[2]*ratiodone)/float(axis_steps_per_unit[2]);
189
- SERIAL_ECHO_START;
190
- SERIAL_ECHOPGM("endstops hit: ");
191
- SERIAL_ECHOPAIR(" X:",endstops_triggerpos[0]);
192
- SERIAL_ECHOPAIR(" Y:",endstops_triggerpos[1]);
193
- SERIAL_ECHOPAIR(" Z:",endstops_triggerpos[2]);
194
- SERIAL_ECHOLN("");
195
- endstops_hit=false;
158
+ if( endstop_x_hit || endstop_y_hit || endstop_z_hit) {
159
+   SERIAL_ECHO_START;
160
+   SERIAL_ECHOPGM("endstops hit: ");
161
+   if(endstop_x_hit) {
162
+     SERIAL_ECHOPAIR(" X:",(float)endstops_trigsteps[X_AXIS]/axis_steps_per_unit[X_AXIS]);
163
+   }
164
+   if(endstop_y_hit) {
165
+     SERIAL_ECHOPAIR(" Y:",(float)endstops_trigsteps[Y_AXIS]/axis_steps_per_unit[Y_AXIS]);
166
+   }
167
+   if(endstop_z_hit) {
168
+     SERIAL_ECHOPAIR(" Z:",(float)endstops_trigsteps[Z_AXIS]/axis_steps_per_unit[Z_AXIS]);
169
+   }
170
+   SERIAL_ECHOLN("");
171
+   endstop_x_hit=false;
172
+   endstop_y_hit=false;
173
+   endstop_z_hit=false;
174
+ }
196 175
 }
197 176
 
198 177
 void endstops_hit_on_purpose()
199 178
 {
200
-  endstops_hit=false;
179
+  endstop_x_hit=false;
180
+  endstop_y_hit=false;
181
+  endstop_z_hit=false;
201 182
 }
202 183
 
203 184
 //         __________________________
@@ -312,24 +293,22 @@ ISR(TIMER1_COMPA_vect)
312 293
     // Set direction en check limit switches
313 294
     if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction
314 295
       WRITE(X_DIR_PIN, INVERT_X_DIR);
315
-      #ifdef DEBUG_STEPS
316
-        count_direction[X_AXIS]=-1;
317
-      #endif
296
+      count_direction[X_AXIS]=-1;
318 297
       #if X_MIN_PIN > -1
319
-        if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
320
- //         endstops_triggered(step_events_completed);
298
+        if((READ(X_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x > 0)) {
299
+          endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
300
+          endstop_x_hit=true;
321 301
           step_events_completed = current_block->step_event_count;
322 302
         }
323 303
       #endif
324 304
     }
325 305
     else { // +direction 
326 306
       WRITE(X_DIR_PIN,!INVERT_X_DIR);
327
-      #ifdef DEBUG_STEPS
328
-        count_direction[X_AXIS]=1;
329
-      #endif
307
+      count_direction[X_AXIS]=1;
330 308
       #if X_MAX_PIN > -1
331
-        if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_x >0)){
332
- //         endstops_triggered(step_events_completed);
309
+        if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x > 0)){
310
+          endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
311
+          endstop_x_hit=true;
333 312
           step_events_completed = current_block->step_event_count;
334 313
         }
335 314
       #endif
@@ -337,24 +316,22 @@ ISR(TIMER1_COMPA_vect)
337 316
 
338 317
     if ((out_bits & (1<<Y_AXIS)) != 0) {   // -direction
339 318
       WRITE(Y_DIR_PIN,INVERT_Y_DIR);
340
-      #ifdef DEBUG_STEPS
341
-        count_direction[Y_AXIS]=-1;
342
-      #endif
319
+      count_direction[Y_AXIS]=-1;
343 320
       #if Y_MIN_PIN > -1
344
-        if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {
345
-//          endstops_triggered(step_events_completed);
321
+        if((READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y > 0)) {
322
+          endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
323
+          endstop_y_hit=true;
346 324
           step_events_completed = current_block->step_event_count;
347 325
         }
348 326
       #endif
349 327
     }
350 328
     else { // +direction
351 329
     WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
352
-      #ifdef DEBUG_STEPS
353
-        count_direction[Y_AXIS]=1;
354
-      #endif
330
+      count_direction[Y_AXIS]=1;
355 331
       #if Y_MAX_PIN > -1
356
-      if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){
357
- //         endstops_triggered(step_events_completed);
332
+      if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y > 0)){
333
+          endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
334
+          endstop_y_hit=true;
358 335
           step_events_completed = current_block->step_event_count;
359 336
         }
360 337
       #endif
@@ -362,34 +339,36 @@ ISR(TIMER1_COMPA_vect)
362 339
 
363 340
     if ((out_bits & (1<<Z_AXIS)) != 0) {   // -direction
364 341
       WRITE(Z_DIR_PIN,INVERT_Z_DIR);
365
-      #ifdef DEBUG_STEPS
366 342
       count_direction[Z_AXIS]=-1;
367
-      #endif
368 343
       #if Z_MIN_PIN > -1
369
-        if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {
370
- //         endstops_triggered(step_events_completed);
344
+        if((READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z > 0)) {
345
+          endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
346
+          endstop_z_hit=true;
371 347
           step_events_completed = current_block->step_event_count;
372 348
         }
373 349
       #endif
374 350
     }
375 351
     else { // +direction
376 352
       WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
377
-      #ifdef DEBUG_STEPS
378 353
         count_direction[Z_AXIS]=1;
379
-      #endif
380 354
       #if Z_MAX_PIN > -1
381
-        if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_z >0)){
382
- //         endstops_triggered(step_events_completed);
355
+        if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_z > 0)){
356
+          endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
357
+          endstop_z_hit=true;
383 358
           step_events_completed = current_block->step_event_count;
384 359
         }
385 360
       #endif
386 361
     }
387 362
 
388 363
     #ifndef ADVANCE
389
-      if ((out_bits & (1<<E_AXIS)) != 0)   // -direction
364
+      if ((out_bits & (1<<E_AXIS)) != 0) {  // -direction
390 365
         WRITE(E_DIR_PIN,INVERT_E_DIR);
391
-      else // +direction
366
+        count_direction[E_AXIS]=-1;
367
+      }
368
+      else { // +direction
392 369
         WRITE(E_DIR_PIN,!INVERT_E_DIR);
370
+        count_direction[E_AXIS]=-1;
371
+      }
393 372
     #endif //!ADVANCE
394 373
 
395 374
     for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves) 
@@ -422,9 +401,7 @@ ISR(TIMER1_COMPA_vect)
422 401
         WRITE(X_STEP_PIN, HIGH);
423 402
         counter_x -= current_block->step_event_count;
424 403
         WRITE(X_STEP_PIN, LOW);
425
-        #ifdef DEBUG_STEPS
426
-          count_position[X_AXIS]+=count_direction[X_AXIS];   
427
-        #endif
404
+        count_position[X_AXIS]+=count_direction[X_AXIS];   
428 405
       }
429 406
 
430 407
       counter_y += current_block->steps_y;
@@ -432,9 +409,7 @@ ISR(TIMER1_COMPA_vect)
432 409
         WRITE(Y_STEP_PIN, HIGH);
433 410
         counter_y -= current_block->step_event_count;
434 411
         WRITE(Y_STEP_PIN, LOW);
435
-        #ifdef DEBUG_STEPS
436
-          count_position[Y_AXIS]+=count_direction[Y_AXIS];
437
-        #endif
412
+        count_position[Y_AXIS]+=count_direction[Y_AXIS];
438 413
       }
439 414
 
440 415
       counter_z += current_block->steps_z;
@@ -442,9 +417,7 @@ ISR(TIMER1_COMPA_vect)
442 417
         WRITE(Z_STEP_PIN, HIGH);
443 418
         counter_z -= current_block->step_event_count;
444 419
         WRITE(Z_STEP_PIN, LOW);
445
-        #ifdef DEBUG_STEPS
446
-          count_position[Z_AXIS]+=count_direction[Z_AXIS];
447
-        #endif
420
+        count_position[Z_AXIS]+=count_direction[Z_AXIS];
448 421
       }
449 422
 
450 423
       #ifndef ADVANCE
@@ -453,6 +426,7 @@ ISR(TIMER1_COMPA_vect)
453 426
           WRITE(E_STEP_PIN, HIGH);
454 427
           counter_e -= current_block->step_event_count;
455 428
           WRITE(E_STEP_PIN, LOW);
429
+          count_position[E_AXIS]+=count_direction[E_AXIS];
456 430
         }
457 431
       #endif //!ADVANCE
458 432
       step_events_completed += 1;  
@@ -669,3 +643,22 @@ void st_synchronize()
669 643
     LCD_STATUS;
670 644
   }   
671 645
 }
646
+
647
+void st_set_position(const long &x, const long &y, const long &z, const long &e)
648
+{
649
+  CRITICAL_SECTION_START;
650
+  count_position[X_AXIS] = x;
651
+  count_position[Y_AXIS] = y;
652
+  count_position[Z_AXIS] = z;
653
+  count_position[E_AXIS] = e;
654
+  CRITICAL_SECTION_END;
655
+}
656
+
657
+long st_get_position(char axis)
658
+{
659
+  long count_pos;
660
+  CRITICAL_SECTION_START;
661
+  count_pos = count_position[axis];
662
+  CRITICAL_SECTION_END;
663
+  return count_pos;
664
+}

+ 50
- 50
Marlin/stepper.h Näytä tiedosto

@@ -1,51 +1,51 @@
1
-/*
2
-  stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors
3
-  Part of Grbl
4
-
5
-  Copyright (c) 2009-2011 Simen Svale Skogsrud
6
-
7
-  Grbl is free software: you can redistribute it and/or modify
8
-  it under the terms of the GNU General Public License as published by
9
-  the Free Software Foundation, either version 3 of the License, or
10
-  (at your option) any later version.
11
-
12
-  Grbl is distributed in the hope that it will be useful,
13
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-  GNU General Public License for more details.
16
-
17
-  You should have received a copy of the GNU General Public License
18
-  along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
19
-*/
20
-
21
-#ifndef stepper_h
22
-#define stepper_h 
23
-
24
-#include "planner.h"
25
-
26
-// Initialize and start the stepper motor subsystem
27
-void st_init();
28
-
29
-// Block until all buffered steps are executed
30
-void st_synchronize();
31
-
32
-// The stepper subsystem goes to sleep when it runs out of things to execute. Call this
33
-// to notify the subsystem that it is time to go to work.
34
-void st_wake_up();
35
-
36
-// if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
37
-// for debugging purposes only, should be disabled by default
38
-#ifdef DEBUG_STEPS
39
-  extern volatile long count_position[NUM_AXIS];
40
-  extern volatile int count_direction[NUM_AXIS];
41
-#endif
42
-  
43
-void checkHitEndstops(); //call from somwhere to create an serial error message with the locations the endstops where hit, in case they were triggered
44
-void endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homeing and before a routine call of checkHitEndstops();
45
-
46
-
47
-
48
-extern block_t *current_block;  // A pointer to the block currently being traced
49
-
50
-
1
+/*
2
+  stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors
3
+  Part of Grbl
4
+
5
+  Copyright (c) 2009-2011 Simen Svale Skogsrud
6
+
7
+  Grbl is free software: you can redistribute it and/or modify
8
+  it under the terms of the GNU General Public License as published by
9
+  the Free Software Foundation, either version 3 of the License, or
10
+  (at your option) any later version.
11
+
12
+  Grbl is distributed in the hope that it will be useful,
13
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+  GNU General Public License for more details.
16
+
17
+  You should have received a copy of the GNU General Public License
18
+  along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
19
+*/
20
+
21
+#ifndef stepper_h
22
+#define stepper_h 
23
+
24
+#include "planner.h"
25
+
26
+// Initialize and start the stepper motor subsystem
27
+void st_init();
28
+
29
+// Block until all buffered steps are executed
30
+void st_synchronize();
31
+
32
+// Set current position in steps
33
+void st_set_position(const long &x, const long &y, const long &z, const long &e);
34
+
35
+// Get current position in steps
36
+long st_get_position(char axis);
37
+
38
+// The stepper subsystem goes to sleep when it runs out of things to execute. Call this
39
+// to notify the subsystem that it is time to go to work.
40
+void st_wake_up();
41
+
42
+  
43
+void checkHitEndstops(); //call from somwhere to create an serial error message with the locations the endstops where hit, in case they were triggered
44
+void endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homeing and before a routine call of checkHitEndstops();
45
+
46
+
47
+
48
+extern block_t *current_block;  // A pointer to the block currently being traced
49
+
50
+
51 51
 #endif

Loading…
Peruuta
Tallenna