|
@@ -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
|