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
 const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
238
 const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
239
 //#define DISABLE_MAX_ENDSTOPS
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
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
246
 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
242
 #define X_ENABLE_ON 0
247
 #define X_ENABLE_ON 0
243
 #define Y_ENABLE_ON 0
248
 #define Y_ENABLE_ON 0

+ 28
- 4
Marlin/planner.cpp View File

564
   block->busy = false;
564
   block->busy = false;
565
 
565
 
566
   // Number of steps for each axis
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
   block->steps_z = labs(target[Z_AXIS]-position[Z_AXIS]);
577
   block->steps_z = labs(target[Z_AXIS]-position[Z_AXIS]);
570
   block->steps_e = labs(target[E_AXIS]-position[E_AXIS]);
578
   block->steps_e = labs(target[E_AXIS]-position[E_AXIS]);
571
   block->steps_e *= extrudemultiply;
579
   block->steps_e *= extrudemultiply;
586
 
594
 
587
   // Compute direction bits for this block 
595
   // Compute direction bits for this block 
588
   block->direction_bits = 0;
596
   block->direction_bits = 0;
597
+#ifndef COREXY
589
   if (target[X_AXIS] < position[X_AXIS])
598
   if (target[X_AXIS] < position[X_AXIS])
590
   {
599
   {
591
     block->direction_bits |= (1<<X_AXIS); 
600
     block->direction_bits |= (1<<X_AXIS); 
594
   {
603
   {
595
     block->direction_bits |= (1<<Y_AXIS); 
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
   if (target[Z_AXIS] < position[Z_AXIS])
616
   if (target[Z_AXIS] < position[Z_AXIS])
598
   {
617
   {
599
     block->direction_bits |= (1<<Z_AXIS); 
618
     block->direction_bits |= (1<<Z_AXIS); 
638
   } 
657
   } 
639
 
658
 
640
   float delta_mm[4];
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
   delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/axis_steps_per_unit[Z_AXIS];
667
   delta_mm[Z_AXIS] = (target[Z_AXIS]-position[Z_AXIS])/axis_steps_per_unit[Z_AXIS];
644
   delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*extrudemultiply/100.0;
668
   delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*extrudemultiply/100.0;
645
   if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments )
669
   if ( block->steps_x <=dropsegments && block->steps_y <=dropsegments && block->steps_z <=dropsegments )

+ 28
- 89
Marlin/stepper.cpp View File

345
     // Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
345
     // Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
346
     out_bits = current_block->direction_bits;
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
     // Set direction en check limit switches
367
     // Set direction en check limit switches
368
+    #ifndef COREXY
349
     if ((out_bits & (1<<X_AXIS)) != 0) {   // stepping along -X axis
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
       CHECK_ENDSTOPS
373
       CHECK_ENDSTOPS
355
       {
374
       {
356
         #if defined(X_MIN_PIN) && X_MIN_PIN > -1
375
         #if defined(X_MIN_PIN) && X_MIN_PIN > -1
365
       }
384
       }
366
     }
385
     }
367
     else { // +direction
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
       CHECK_ENDSTOPS 
387
       CHECK_ENDSTOPS 
374
       {
388
       {
375
         #if defined(X_MAX_PIN) && X_MAX_PIN > -1
389
         #if defined(X_MAX_PIN) && X_MAX_PIN > -1
384
       }
398
       }
385
     }
399
     }
386
 
400
 
401
+    #ifndef COREXY
387
     if ((out_bits & (1<<Y_AXIS)) != 0) {   // -direction
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
       CHECK_ENDSTOPS
406
       CHECK_ENDSTOPS
393
       {
407
       {
394
         #if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
408
         #if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
403
       }
417
       }
404
     }
418
     }
405
     else { // +direction
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
       CHECK_ENDSTOPS
420
       CHECK_ENDSTOPS
411
       {
421
       {
412
         #if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
422
         #if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
420
         #endif
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
     if ((out_bits & (1<<Z_AXIS)) != 0) {   // -direction
434
     if ((out_bits & (1<<Z_AXIS)) != 0) {   // -direction
446
       WRITE(Z_DIR_PIN,INVERT_Z_DIR);
435
       WRITE(Z_DIR_PIN,INVERT_Z_DIR);
447
       
436
       
516
       }    
505
       }    
517
       #endif //ADVANCE
506
       #endif //ADVANCE
518
 
507
 
519
-      #if !defined COREXY      
520
         counter_x += current_block->steps_x;
508
         counter_x += current_block->steps_x;
521
         if (counter_x > 0) {
509
         if (counter_x > 0) {
522
           WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
510
           WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
532
           count_position[Y_AXIS]+=count_direction[Y_AXIS]; 
520
           count_position[Y_AXIS]+=count_direction[Y_AXIS]; 
533
           WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
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
       counter_z += current_block->steps_z;
524
       counter_z += current_block->steps_z;
586
       if (counter_z > 0) {
525
       if (counter_z > 0) {
587
         WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
526
         WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);

Loading…
Cancel
Save