Browse Source

Moved corexy implementation from stepper to planner

(Thanks iquizzle)
Erik van der Zalm 11 years ago
parent
commit
ff6fa09ecf
3 changed files with 61 additions and 93 deletions
  1. 5
    0
      Marlin/Configuration.h
  2. 28
    4
      Marlin/planner.cpp
  3. 28
    89
      Marlin/stepper.cpp

+ 5
- 0
Marlin/Configuration.h View File

@@ -238,6 +238,11 @@ const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
238 238
 const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
239 239
 //#define DISABLE_MAX_ENDSTOPS
240 240
 
241
+// Disable max endstops for compatibility with endstop checking routine
242
+#if defined(COREXY) && !defined(DISABLE_MAX_ENDSTOPS)
243
+  #define DISABLE_MAX_ENDSTOPS
244
+#endif
245
+
241 246
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
242 247
 #define X_ENABLE_ON 0
243 248
 #define Y_ENABLE_ON 0

+ 28
- 4
Marlin/planner.cpp View File

@@ -564,8 +564,16 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
564 564
   block->busy = false;
565 565
 
566 566
   // Number of steps for each axis
567
-  block->steps_x = labs(target[X_AXIS]-position[X_AXIS]);
568
-  block->steps_y = labs(target[Y_AXIS]-position[Y_AXIS]);
567
+#ifndef COREXY
568
+// default non-h-bot planning
569
+block->steps_x = labs(target[X_AXIS]-position[X_AXIS]);
570
+block->steps_y = labs(target[Y_AXIS]-position[Y_AXIS]);
571
+#else
572
+// corexy planning
573
+// these equations follow the form of the dA and dB equations on http://www.corexy.com/theory.html
574
+block->steps_x = labs((target[X_AXIS]-position[X_AXIS]) + (target[Y_AXIS]-position[Y_AXIS]));
575
+block->steps_y = labs((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]));
576
+#endif
569 577
   block->steps_z = labs(target[Z_AXIS]-position[Z_AXIS]);
570 578
   block->steps_e = labs(target[E_AXIS]-position[E_AXIS]);
571 579
   block->steps_e *= extrudemultiply;
@@ -586,6 +594,7 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
586 594
 
587 595
   // Compute direction bits for this block 
588 596
   block->direction_bits = 0;
597
+#ifndef COREXY
589 598
   if (target[X_AXIS] < position[X_AXIS])
590 599
   {
591 600
     block->direction_bits |= (1<<X_AXIS); 
@@ -594,6 +603,16 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
594 603
   {
595 604
     block->direction_bits |= (1<<Y_AXIS); 
596 605
   }
606
+#else
607
+  if ((target[X_AXIS]-position[X_AXIS]) + (target[Y_AXIS]-position[Y_AXIS]) < 0)
608
+  {
609
+    block->direction_bits |= (1<<X_AXIS); 
610
+  }
611
+  if ((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]) < 0)
612
+  {
613
+    block->direction_bits |= (1<<Y_AXIS); 
614
+  }
615
+#endif
597 616
   if (target[Z_AXIS] < position[Z_AXIS])
598 617
   {
599 618
     block->direction_bits |= (1<<Z_AXIS); 
@@ -638,8 +657,13 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
638 657
   } 
639 658
 
640 659
   float delta_mm[4];
641
-  delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
642
-  delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
660
+  #ifndef COREXY
661
+    delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
662
+    delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
663
+  #else
664
+    delta_mm[X_AXIS] = ((target[X_AXIS]-position[X_AXIS]) + (target[Y_AXIS]-position[Y_AXIS]))/axis_steps_per_unit[X_AXIS];
665
+    delta_mm[Y_AXIS] = ((target[X_AXIS]-position[X_AXIS]) - (target[Y_AXIS]-position[Y_AXIS]))/axis_steps_per_unit[Y_AXIS];
666
+  #endif
643 667
   delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/axis_steps_per_unit[Z_AXIS];
644 668
   delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*extrudemultiply/100.0;
645 669
   if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments )

+ 28
- 89
Marlin/stepper.cpp View File

@@ -345,12 +345,31 @@ ISR(TIMER1_COMPA_vect)
345 345
     // Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
346 346
     out_bits = current_block->direction_bits;
347 347
 
348
+
349
+    // Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
350
+    if((out_bits & (1<<X_AXIS))!=0){
351
+      WRITE(X_DIR_PIN, INVERT_X_DIR);
352
+      count_direction[X_AXIS]=-1;
353
+    }
354
+    else{
355
+      WRITE(X_DIR_PIN, !INVERT_X_DIR);
356
+      count_direction[X_AXIS]=1;
357
+    }
358
+    if((out_bits & (1<<Y_AXIS))!=0){
359
+      WRITE(Y_DIR_PIN, INVERT_Y_DIR);
360
+      count_direction[Y_AXIS]=-1;
361
+    }
362
+    else{
363
+      WRITE(Y_DIR_PIN, !INVERT_Y_DIR);
364
+      count_direction[Y_AXIS]=1;
365
+    }
366
+    
348 367
     // Set direction en check limit switches
368
+    #ifndef COREXY
349 369
     if ((out_bits & (1<<X_AXIS)) != 0) {   // stepping along -X axis
350
-      #if !defined COREXY  //NOT COREXY
351
-        WRITE(X_DIR_PIN, INVERT_X_DIR);
352
-      #endif
353
-      count_direction[X_AXIS]=-1;
370
+    #else
371
+    if ((((out_bits & (1<<X_AXIS)) != 0)&&(out_bits & (1<<Y_AXIS)) != 0)) {   //-X occurs for -A and -B
372
+    #endif
354 373
       CHECK_ENDSTOPS
355 374
       {
356 375
         #if defined(X_MIN_PIN) && X_MIN_PIN > -1
@@ -365,11 +384,6 @@ ISR(TIMER1_COMPA_vect)
365 384
       }
366 385
     }
367 386
     else { // +direction
368
-      #if !defined COREXY  //NOT COREXY
369
-        WRITE(X_DIR_PIN,!INVERT_X_DIR);
370
-      #endif
371
-      
372
-      count_direction[X_AXIS]=1;
373 387
       CHECK_ENDSTOPS 
374 388
       {
375 389
         #if defined(X_MAX_PIN) && X_MAX_PIN > -1
@@ -384,11 +398,11 @@ ISR(TIMER1_COMPA_vect)
384 398
       }
385 399
     }
386 400
 
401
+    #ifndef COREXY
387 402
     if ((out_bits & (1<<Y_AXIS)) != 0) {   // -direction
388
-      #if !defined COREXY  //NOT COREXY
389
-        WRITE(Y_DIR_PIN,INVERT_Y_DIR);
390
-      #endif
391
-      count_direction[Y_AXIS]=-1;
403
+    #else
404
+    if ((((out_bits & (1<<X_AXIS)) != 0)&&(out_bits & (1<<Y_AXIS)) == 0)) {   // -Y occurs for -A and +B
405
+    #endif
392 406
       CHECK_ENDSTOPS
393 407
       {
394 408
         #if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
@@ -403,10 +417,6 @@ ISR(TIMER1_COMPA_vect)
403 417
       }
404 418
     }
405 419
     else { // +direction
406
-      #if !defined COREXY  //NOT COREXY
407
-        WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
408
-      #endif
409
-      count_direction[Y_AXIS]=1;
410 420
       CHECK_ENDSTOPS
411 421
       {
412 422
         #if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
@@ -420,28 +430,7 @@ ISR(TIMER1_COMPA_vect)
420 430
         #endif
421 431
       }
422 432
     }
423
-    
424
-    
425
-    #ifdef COREXY  //coreXY kinematics defined
426
-      if((current_block->steps_x >= current_block->steps_y)&&((out_bits & (1<<X_AXIS)) == 0)){  //+X is major axis
427
-        WRITE(X_DIR_PIN, !INVERT_X_DIR);
428
-        WRITE(Y_DIR_PIN, !INVERT_Y_DIR);
429
-      }
430
-      if((current_block->steps_x >= current_block->steps_y)&&((out_bits & (1<<X_AXIS)) != 0)){  //-X is major axis
431
-        WRITE(X_DIR_PIN, INVERT_X_DIR);
432
-        WRITE(Y_DIR_PIN, INVERT_Y_DIR);
433
-      }      
434
-      if((current_block->steps_y > current_block->steps_x)&&((out_bits & (1<<Y_AXIS)) == 0)){  //+Y is major axis
435
-        WRITE(X_DIR_PIN, !INVERT_X_DIR);
436
-        WRITE(Y_DIR_PIN, INVERT_Y_DIR);
437
-      }        
438
-      if((current_block->steps_y > current_block->steps_x)&&((out_bits & (1<<Y_AXIS)) != 0)){  //-Y is major axis
439
-        WRITE(X_DIR_PIN, INVERT_X_DIR);
440
-        WRITE(Y_DIR_PIN, !INVERT_Y_DIR);
441
-      }  
442
-    #endif //coreXY
443
-    
444
-    
433
+
445 434
     if ((out_bits & (1<<Z_AXIS)) != 0) {   // -direction
446 435
       WRITE(Z_DIR_PIN,INVERT_Z_DIR);
447 436
       
@@ -516,7 +505,6 @@ ISR(TIMER1_COMPA_vect)
516 505
       }    
517 506
       #endif //ADVANCE
518 507
 
519
-      #if !defined COREXY      
520 508
         counter_x += current_block->steps_x;
521 509
         if (counter_x > 0) {
522 510
           WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
@@ -532,56 +520,7 @@ ISR(TIMER1_COMPA_vect)
532 520
           count_position[Y_AXIS]+=count_direction[Y_AXIS]; 
533 521
           WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
534 522
         }
535
-      #endif
536 523
   
537
-      #ifdef COREXY
538
-        counter_x += current_block->steps_x;        
539
-        counter_y += current_block->steps_y;
540
-        
541
-        if ((counter_x > 0)&&!(counter_y>0)){  //X step only
542
-          WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
543
-          WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
544
-          counter_x -= current_block->step_event_count; 
545
-          count_position[X_AXIS]+=count_direction[X_AXIS];         
546
-          WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
547
-          WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
548
-        }
549
-        
550
-        if (!(counter_x > 0)&&(counter_y>0)){  //Y step only
551
-          WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
552
-          WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
553
-          counter_y -= current_block->step_event_count; 
554
-          count_position[Y_AXIS]+=count_direction[Y_AXIS];
555
-          WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
556
-          WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
557
-        }        
558
-        
559
-        if ((counter_x > 0)&&(counter_y>0)){  //step in both axes
560
-          if (((out_bits & (1<<X_AXIS)) == 0)^((out_bits & (1<<Y_AXIS)) == 0)){  //X and Y in different directions
561
-            WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
562
-            counter_x -= current_block->step_event_count;             
563
-            WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
564
-            step_wait();
565
-            count_position[X_AXIS]+=count_direction[X_AXIS];
566
-            count_position[Y_AXIS]+=count_direction[Y_AXIS];
567
-            WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
568
-            counter_y -= current_block->step_event_count;
569
-            WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
570
-          }
571
-          else{  //X and Y in same direction
572
-            WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
573
-            counter_x -= current_block->step_event_count;             
574
-            WRITE(X_STEP_PIN, INVERT_X_STEP_PIN) ;
575
-            step_wait();
576
-            count_position[X_AXIS]+=count_direction[X_AXIS];
577
-            count_position[Y_AXIS]+=count_direction[Y_AXIS];
578
-            WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN); 
579
-            counter_y -= current_block->step_event_count;    
580
-            WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);        
581
-          }
582
-        }
583
-      #endif //corexy
584
-      
585 524
       counter_z += current_block->steps_z;
586 525
       if (counter_z > 0) {
587 526
         WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);

Loading…
Cancel
Save