Browse Source

added a m400, that finished all moves,

and the mechanism so that if an endstop is hit it the ISR, the steps_to_be_taken are stored, and some current_block data that will be deleted in the next move
If the normal loop() then finds such an event, the position is calculated (floats would have taken too long in the ISR) A serial message is generated.
Bernhard Kubicek 13 years ago
parent
commit
9980ceb4a3
4 changed files with 78 additions and 5 deletions
  1. 2
    0
      Marlin/Marlin.h
  2. 17
    3
      Marlin/Marlin.pde
  3. 52
    2
      Marlin/stepper.cpp
  4. 7
    0
      Marlin/stepper.h

+ 2
- 0
Marlin/Marlin.h View File

6
 #include <WProgram.h>
6
 #include <WProgram.h>
7
 #include "fastio.h"
7
 #include "fastio.h"
8
 #include <avr/pgmspace.h>
8
 #include <avr/pgmspace.h>
9
+#include "Configuration.h"
9
 
10
 
10
 //#define SERIAL_ECHO(x) Serial << "echo: " << x;
11
 //#define SERIAL_ECHO(x) Serial << "echo: " << x;
11
 //#define SERIAL_ECHOLN(x) Serial << "echo: "<<x<<endl;
12
 //#define SERIAL_ECHOLN(x) Serial << "echo: "<<x<<endl;
108
 
109
 
109
 extern float homing_feedrate[];
110
 extern float homing_feedrate[];
110
 extern bool axis_relative_modes[];
111
 extern bool axis_relative_modes[];
112
+extern float current_position[NUM_AXIS] ;
111
 
113
 
112
 #endif
114
 #endif

+ 17
- 3
Marlin/Marlin.pde View File

39
 #include "cardreader.h"
39
 #include "cardreader.h"
40
 
40
 
41
 
41
 
42
-char version_string[] = "1.0.0 Alpha 1";
42
+#define VERSION_STRING  "1.0.0 Alpha 1"
43
 
43
 
44
 
44
 
45
 
45
 
99
 // M205 -  advanced settings:  minimum travel speed S=while printing T=travel only,  B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk
99
 // M205 -  advanced settings:  minimum travel speed S=while printing T=travel only,  B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk
100
 // M220 - set speed factor override percentage S:factor in percent
100
 // M220 - set speed factor override percentage S:factor in percent
101
 // M301 - Set PID parameters P I and D
101
 // M301 - Set PID parameters P I and D
102
+// M400 - Finish all moves
102
 // M500 - stores paramters in EEPROM
103
 // M500 - stores paramters in EEPROM
103
 // M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).  
104
 // M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).  
104
 // M502 - reverts to the default "factory settings".  You still need to store them in EEPROM afterwards if you want to.
105
 // M502 - reverts to the default "factory settings".  You still need to store them in EEPROM afterwards if you want to.
120
 volatile int feedmultiply=100; //100->1 200->2
121
 volatile int feedmultiply=100; //100->1 200->2
121
 int saved_feedmultiply;
122
 int saved_feedmultiply;
122
 volatile bool feedmultiplychanged=false;
123
 volatile bool feedmultiplychanged=false;
124
+float current_position[NUM_AXIS] = {  0.0, 0.0, 0.0, 0.0};
125
+
123
 
126
 
124
 //===========================================================================
127
 //===========================================================================
125
 //=============================private variables=============================
128
 //=============================private variables=============================
126
 //===========================================================================
129
 //===========================================================================
127
 const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
130
 const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
128
 static float destination[NUM_AXIS] = {  0.0, 0.0, 0.0, 0.0};
131
 static float destination[NUM_AXIS] = {  0.0, 0.0, 0.0, 0.0};
129
-static float current_position[NUM_AXIS] = {  0.0, 0.0, 0.0, 0.0};
130
 static float offset[3] = {0.0, 0.0, 0.0};
132
 static float offset[3] = {0.0, 0.0, 0.0};
131
 static bool home_all_axis = true;
133
 static bool home_all_axis = true;
132
 static float feedrate = 1500.0, next_feedrate, saved_feedrate;
134
 static float feedrate = 1500.0, next_feedrate, saved_feedrate;
211
 { 
213
 { 
212
   Serial.begin(BAUDRATE);
214
   Serial.begin(BAUDRATE);
213
   SERIAL_ECHO_START;
215
   SERIAL_ECHO_START;
214
-  SERIAL_ECHOLN(version_string);
216
+  SERIAL_ECHOLNPGM(VERSION_STRING);
215
   SERIAL_PROTOCOLLNPGM("start");
217
   SERIAL_PROTOCOLLNPGM("start");
216
   SERIAL_ECHO_START;
218
   SERIAL_ECHO_START;
217
   SERIAL_ECHOPGM("Free Memory:");
219
   SERIAL_ECHOPGM("Free Memory:");
269
   //check heater every n milliseconds
271
   //check heater every n milliseconds
270
   manage_heater();
272
   manage_heater();
271
   manage_inactivity(1);
273
   manage_inactivity(1);
274
+  checkHitEndstops();
272
   LCD_STATUS;
275
   LCD_STATUS;
273
 }
276
 }
274
 
277
 
443
     destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
446
     destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
444
     feedrate = homing_feedrate[LETTER##_AXIS]; \
447
     feedrate = homing_feedrate[LETTER##_AXIS]; \
445
     prepare_move(); \
448
     prepare_move(); \
449
+    st_synchronize();\
446
     \
450
     \
447
     current_position[LETTER##_AXIS] = 0;\
451
     current_position[LETTER##_AXIS] = 0;\
448
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
452
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
449
     destination[LETTER##_AXIS] = -5 * LETTER##_HOME_DIR;\
453
     destination[LETTER##_AXIS] = -5 * LETTER##_HOME_DIR;\
450
     prepare_move(); \
454
     prepare_move(); \
455
+    st_synchronize();\
451
     \
456
     \
452
     destination[LETTER##_AXIS] = 10 * LETTER##_HOME_DIR;\
457
     destination[LETTER##_AXIS] = 10 * LETTER##_HOME_DIR;\
453
     feedrate = homing_feedrate[LETTER##_AXIS]/2 ;  \
458
     feedrate = homing_feedrate[LETTER##_AXIS]/2 ;  \
454
     prepare_move(); \
459
     prepare_move(); \
460
+    st_synchronize();\
455
     \
461
     \
456
     current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
462
     current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
457
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
463
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
458
     destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\
464
     destination[LETTER##_AXIS] = current_position[LETTER##_AXIS];\
459
     feedrate = 0.0;\
465
     feedrate = 0.0;\
466
+    st_synchronize();\
467
+    endstops_hit_on_purpose();\
460
   }
468
   }
461
 
469
 
462
 inline void process_commands()
470
 inline void process_commands()
522
       feedrate = saved_feedrate;
530
       feedrate = saved_feedrate;
523
       feedmultiply = saved_feedmultiply;
531
       feedmultiply = saved_feedmultiply;
524
       previous_millis_cmd = millis();
532
       previous_millis_cmd = millis();
533
+      endstops_hit_on_purpose();
525
       break;
534
       break;
526
     case 90: // G90
535
     case 90: // G90
527
       relative_mode = false;
536
       relative_mode = false;
909
       
918
       
910
       break;
919
       break;
911
     #endif //PIDTEMP
920
     #endif //PIDTEMP
921
+    case 400: // finish all moves
922
+    {
923
+      st_synchronize();
924
+    }
925
+    break;
912
     case 500: // Store settings in EEPROM
926
     case 500: // Store settings in EEPROM
913
     {
927
     {
914
         StoreSettings();
928
         StoreSettings();

+ 52
- 2
Marlin/stepper.cpp View File

33
 #include "speed_lookuptable.h"
33
 #include "speed_lookuptable.h"
34
 
34
 
35
 
35
 
36
+
36
 //===========================================================================
37
 //===========================================================================
37
 //=============================public variables  ============================
38
 //=============================public variables  ============================
38
 //===========================================================================
39
 //===========================================================================
39
 block_t *current_block;  // A pointer to the block currently being traced
40
 block_t *current_block;  // A pointer to the block currently being traced
40
 
41
 
41
 
42
 
43
+
42
 //===========================================================================
44
 //===========================================================================
43
 //=============================private variables ============================
45
 //=============================private variables ============================
44
 //===========================================================================
46
 //===========================================================================
62
 static unsigned short acc_step_rate; // needed for deccelaration start point
64
 static unsigned short acc_step_rate; // needed for deccelaration start point
63
 static char step_loops;
65
 static char step_loops;
64
 
66
 
65
-
67
+volatile long endstops_trigsteps[3]={0,0,0};
68
+volatile long endstops_stepsTotal,endstops_stepsDone;
69
+static volatile bool endstops_hit=false;
66
 
70
 
67
 // if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
71
 // if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
68
 // for debugging purposes only, should be disabled by default
72
 // for debugging purposes only, should be disabled by default
152
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
156
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
153
 
157
 
154
 
158
 
159
+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
+}
155
 
178
 
179
+void checkHitEndstops()
180
+{
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;
196
+}
156
 
197
 
157
-
198
+void endstops_hit_on_purpose()
199
+{
200
+  endstops_hit=false;
201
+}
158
 
202
 
159
 //         __________________________
203
 //         __________________________
160
 //        /|                        |\     _________________         ^
204
 //        /|                        |\     _________________         ^
296
       #endif
340
       #endif
297
       #if X_MIN_PIN > -1
341
       #if X_MIN_PIN > -1
298
             if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
342
             if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
343
+              endstops_triggered(step_events_completed);
299
               step_events_completed = current_block->step_event_count;
344
               step_events_completed = current_block->step_event_count;
300
             }
345
             }
301
       #endif
346
       #endif
307
       #endif
352
       #endif
308
       #if X_MAX_PIN > -1
353
       #if X_MAX_PIN > -1
309
         if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_x >0)){
354
         if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_x >0)){
355
+          endstops_triggered(step_events_completed);
310
           step_events_completed = current_block->step_event_count;
356
           step_events_completed = current_block->step_event_count;
311
         }
357
         }
312
         #endif
358
         #endif
319
       #endif
365
       #endif
320
       #if Y_MIN_PIN > -1
366
       #if Y_MIN_PIN > -1
321
         if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {
367
         if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {
368
+          endstops_triggered(step_events_completed);
322
           step_events_completed = current_block->step_event_count;
369
           step_events_completed = current_block->step_event_count;
323
         }
370
         }
324
       #endif
371
       #endif
330
       #endif
377
       #endif
331
       #if Y_MAX_PIN > -1
378
       #if Y_MAX_PIN > -1
332
       if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){
379
       if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){
380
+          endstops_triggered(step_events_completed);
333
           step_events_completed = current_block->step_event_count;
381
           step_events_completed = current_block->step_event_count;
334
         }
382
         }
335
       #endif
383
       #endif
342
       #endif
390
       #endif
343
       #if Z_MIN_PIN > -1
391
       #if Z_MIN_PIN > -1
344
         if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {
392
         if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {
393
+          endstops_triggered(step_events_completed);
345
           step_events_completed = current_block->step_event_count;
394
           step_events_completed = current_block->step_event_count;
346
         }
395
         }
347
       #endif
396
       #endif
353
       #endif
402
       #endif
354
       #if Z_MAX_PIN > -1
403
       #if Z_MAX_PIN > -1
355
         if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_z >0)){
404
         if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_z >0)){
405
+          endstops_triggered(step_events_completed);
356
           step_events_completed = current_block->step_event_count;
406
           step_events_completed = current_block->step_event_count;
357
         }
407
         }
358
       #endif
408
       #endif

+ 7
- 0
Marlin/stepper.h View File

39
   extern volatile long count_position[NUM_AXIS];
39
   extern volatile long count_position[NUM_AXIS];
40
   extern volatile int count_direction[NUM_AXIS];
40
   extern volatile int count_direction[NUM_AXIS];
41
 #endif
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
+
42
 
47
 
43
 extern block_t *current_block;  // A pointer to the block currently being traced
48
 extern block_t *current_block;  // A pointer to the block currently being traced
49
+
50
+
44
 #endif
51
 #endif

Loading…
Cancel
Save