Parcourir la 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 il y a 13 ans
Parent
révision
9980ceb4a3
4 fichiers modifiés avec 78 ajouts et 5 suppressions
  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 Voir le fichier

@@ -6,6 +6,7 @@
6 6
 #include <WProgram.h>
7 7
 #include "fastio.h"
8 8
 #include <avr/pgmspace.h>
9
+#include "Configuration.h"
9 10
 
10 11
 //#define SERIAL_ECHO(x) Serial << "echo: " << x;
11 12
 //#define SERIAL_ECHOLN(x) Serial << "echo: "<<x<<endl;
@@ -108,5 +109,6 @@ void enquecommand(const char *cmd); //put an ascii command at the end of the cur
108 109
 
109 110
 extern float homing_feedrate[];
110 111
 extern bool axis_relative_modes[];
112
+extern float current_position[NUM_AXIS] ;
111 113
 
112 114
 #endif

+ 17
- 3
Marlin/Marlin.pde Voir le fichier

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

+ 52
- 2
Marlin/stepper.cpp Voir le fichier

@@ -33,12 +33,14 @@
33 33
 #include "speed_lookuptable.h"
34 34
 
35 35
 
36
+
36 37
 //===========================================================================
37 38
 //=============================public variables  ============================
38 39
 //===========================================================================
39 40
 block_t *current_block;  // A pointer to the block currently being traced
40 41
 
41 42
 
43
+
42 44
 //===========================================================================
43 45
 //=============================private variables ============================
44 46
 //===========================================================================
@@ -62,7 +64,9 @@ static long acceleration_time, deceleration_time;
62 64
 static unsigned short acc_step_rate; // needed for deccelaration start point
63 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 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 72
 // for debugging purposes only, should be disabled by default
@@ -152,9 +156,49 @@ asm volatile ( \
152 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,6 +340,7 @@ ISR(TIMER1_COMPA_vect)
296 340
       #endif
297 341
       #if X_MIN_PIN > -1
298 342
             if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
343
+              endstops_triggered(step_events_completed);
299 344
               step_events_completed = current_block->step_event_count;
300 345
             }
301 346
       #endif
@@ -307,6 +352,7 @@ ISR(TIMER1_COMPA_vect)
307 352
       #endif
308 353
       #if X_MAX_PIN > -1
309 354
         if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_x >0)){
355
+          endstops_triggered(step_events_completed);
310 356
           step_events_completed = current_block->step_event_count;
311 357
         }
312 358
         #endif
@@ -319,6 +365,7 @@ ISR(TIMER1_COMPA_vect)
319 365
       #endif
320 366
       #if Y_MIN_PIN > -1
321 367
         if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {
368
+          endstops_triggered(step_events_completed);
322 369
           step_events_completed = current_block->step_event_count;
323 370
         }
324 371
       #endif
@@ -330,6 +377,7 @@ ISR(TIMER1_COMPA_vect)
330 377
       #endif
331 378
       #if Y_MAX_PIN > -1
332 379
       if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){
380
+          endstops_triggered(step_events_completed);
333 381
           step_events_completed = current_block->step_event_count;
334 382
         }
335 383
       #endif
@@ -342,6 +390,7 @@ ISR(TIMER1_COMPA_vect)
342 390
       #endif
343 391
       #if Z_MIN_PIN > -1
344 392
         if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {
393
+          endstops_triggered(step_events_completed);
345 394
           step_events_completed = current_block->step_event_count;
346 395
         }
347 396
       #endif
@@ -353,6 +402,7 @@ ISR(TIMER1_COMPA_vect)
353 402
       #endif
354 403
       #if Z_MAX_PIN > -1
355 404
         if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_z >0)){
405
+          endstops_triggered(step_events_completed);
356 406
           step_events_completed = current_block->step_event_count;
357 407
         }
358 408
       #endif

+ 7
- 0
Marlin/stepper.h Voir le fichier

@@ -39,6 +39,13 @@ void st_wake_up();
39 39
   extern volatile long count_position[NUM_AXIS];
40 40
   extern volatile int count_direction[NUM_AXIS];
41 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 48
 extern block_t *current_block;  // A pointer to the block currently being traced
49
+
50
+
44 51
 #endif

Chargement…
Annuler
Enregistrer