Sfoglia il codice sorgente

Add realtime delta geometry in Marlin_main.cpp.

Johann Rocholl 12 anni fa
parent
commit
8e2519e88b
2 ha cambiato i file con 66 aggiunte e 30 eliminazioni
  1. 1
    0
      Marlin/Marlin.h
  2. 65
    30
      Marlin/Marlin_main.cpp

+ 1
- 0
Marlin/Marlin.h Vedi File

@@ -159,6 +159,7 @@ void FlushSerialRequestResend();
159 159
 void ClearToSend();
160 160
 
161 161
 void get_coordinates();
162
+void calculate_delta(float cartesian[3]);
162 163
 void prepare_move();
163 164
 void kill();
164 165
 void Stop();

+ 65
- 30
Marlin/Marlin_main.cpp Vedi File

@@ -169,6 +169,7 @@ int fanSpeed=0;
169 169
 //===========================================================================
170 170
 const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
171 171
 static float destination[NUM_AXIS] = {  0.0, 0.0, 0.0, 0.0};
172
+static float delta[3] = {0.0, 0.0, 0.0};
172 173
 static float offset[3] = {0.0, 0.0, 0.0};
173 174
 static bool home_all_axis = true;
174 175
 static float feedrate = 1500.0, next_feedrate, saved_feedrate;
@@ -731,34 +732,25 @@ void process_commands()
731 732
       feedrate = 0.0;
732 733
       home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));
733 734
       
734
-      #if Z_HOME_DIR > 0                      // If homing away from BED do Z first
735
-      if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
736
-        HOMEAXIS(Z);
737
-      }
738
-      #endif
739
-      
740 735
       #ifdef QUICK_HOME
741
-      if((home_all_axis)||( code_seen(axis_codes[X_AXIS]) && code_seen(axis_codes[Y_AXIS])) )  //first diagonal move
736
+      if (home_all_axis)  // Move all carriages up together until the first endstop is hit.
742 737
       {
743
-        current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0;  
744
-
738
+        current_position[X_AXIS] = 0;
739
+        current_position[Y_AXIS] = 0;
740
+        current_position[Z_AXIS] = 0;
745 741
         plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); 
746
-        destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR;  
747
-        feedrate = homing_feedrate[X_AXIS]; 
748
-        if(homing_feedrate[Y_AXIS]<feedrate)
749
-          feedrate =homing_feedrate[Y_AXIS]; 
750
-        plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
751
-        st_synchronize();
752
-    
753
-        axis_is_at_home(X_AXIS);
754
-        axis_is_at_home(Y_AXIS);
755
-        plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
756
-        destination[X_AXIS] = current_position[X_AXIS];
757
-        destination[Y_AXIS] = current_position[Y_AXIS];
742
+
743
+        destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;
744
+        destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR;
745
+        destination[Z_AXIS] = 1.5 * Z_MAX_LENGTH * Z_HOME_DIR;
746
+        feedrate = 1.732 * homing_feedrate[X_AXIS];
758 747
         plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
759
-        feedrate = 0.0;
760 748
         st_synchronize();
761 749
         endstops_hit_on_purpose();
750
+
751
+        current_position[X_AXIS] = destination[X_AXIS];
752
+        current_position[Y_AXIS] = destination[Y_AXIS];
753
+        current_position[Z_AXIS] = destination[Z_AXIS];
762 754
       }
763 755
       #endif
764 756
       
@@ -771,11 +763,9 @@ void process_commands()
771 763
         HOMEAXIS(Y);
772 764
       }
773 765
       
774
-      #if Z_HOME_DIR < 0                      // If homing towards BED do Z last
775 766
       if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
776 767
         HOMEAXIS(Z);
777 768
       }
778
-      #endif
779 769
       
780 770
       if(code_seen(axis_codes[X_AXIS])) 
781 771
       {
@@ -795,7 +785,8 @@ void process_commands()
795 785
           current_position[Z_AXIS]=code_value()+add_homeing[2];
796 786
         }
797 787
       }
798
-      plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
788
+      calculate_delta(current_position);
789
+      plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
799 790
       
800 791
       #ifdef ENDSTOPS_ONLY_FOR_HOMING
801 792
         enable_endstops(false);
@@ -1688,18 +1679,62 @@ void clamp_to_software_endstops(float target[3])
1688 1679
   }
1689 1680
 }
1690 1681
 
1682
+void calculate_delta(float cartesian[3])
1683
+{
1684
+  delta[X_AXIS] = sqrt(sq(DELTA_DIAGONAL_ROD)
1685
+                       - sq(DELTA_TOWER1_X-cartesian[X_AXIS])
1686
+                       - sq(DELTA_TOWER1_Y-cartesian[Y_AXIS])
1687
+                       ) + cartesian[Z_AXIS];
1688
+  delta[Y_AXIS] = sqrt(sq(DELTA_DIAGONAL_ROD)
1689
+                       - sq(DELTA_TOWER2_X-cartesian[X_AXIS])
1690
+                       - sq(DELTA_TOWER2_Y-cartesian[Y_AXIS])
1691
+                       ) + cartesian[Z_AXIS];
1692
+  delta[Z_AXIS] = sqrt(sq(DELTA_DIAGONAL_ROD)
1693
+                       - sq(DELTA_TOWER3_X-cartesian[X_AXIS])
1694
+                       - sq(DELTA_TOWER3_Y-cartesian[Y_AXIS])
1695
+                       ) + cartesian[Z_AXIS];
1696
+  /*
1697
+  SERIAL_ECHOPGM("cartesian x="); SERIAL_ECHO(cartesian[X_AXIS]);
1698
+  SERIAL_ECHOPGM(" y="); SERIAL_ECHO(cartesian[Y_AXIS]);
1699
+  SERIAL_ECHOPGM(" z="); SERIAL_ECHOLN(cartesian[Z_AXIS]);
1700
+
1701
+  SERIAL_ECHOPGM("delta x="); SERIAL_ECHO(delta[X_AXIS]);
1702
+  SERIAL_ECHOPGM(" y="); SERIAL_ECHO(delta[Y_AXIS]);
1703
+  SERIAL_ECHOPGM(" z="); SERIAL_ECHOLN(delta[Z_AXIS]);
1704
+  */
1705
+}
1706
+
1691 1707
 void prepare_move()
1692 1708
 {
1693 1709
   clamp_to_software_endstops(destination);
1694 1710
 
1695 1711
   previous_millis_cmd = millis(); 
1696
-  // Do not use feedmultiply for E or Z only moves
1697
-  if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) {
1698
-      plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
1712
+
1713
+  float difference[NUM_AXIS];
1714
+  for (int8_t i=0; i < NUM_AXIS; i++) {
1715
+    difference[i] = destination[i] - current_position[i];
1699 1716
   }
1700
-  else {
1701
-    plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
1717
+  float cartesian_mm = sqrt(sq(difference[X_AXIS]) +
1718
+                            sq(difference[Y_AXIS]) +
1719
+                            sq(difference[Z_AXIS]));
1720
+  if (cartesian_mm < 0.000001) { cartesian_mm = abs(difference[E_AXIS]); }
1721
+  if (cartesian_mm < 0.000001) { return; }
1722
+  float seconds = 6000 * cartesian_mm / feedrate / feedmultiply;
1723
+  int steps = max(1, int(DELTA_SEGMENTS_PER_SECOND * seconds));
1724
+  // SERIAL_ECHOPGM("mm="); SERIAL_ECHO(cartesian_mm);
1725
+  // SERIAL_ECHOPGM(" seconds="); SERIAL_ECHO(seconds);
1726
+  // SERIAL_ECHOPGM(" steps="); SERIAL_ECHOLN(steps);
1727
+  for (int s = 1; s <= steps; s++) {
1728
+    float fraction = float(s) / float(steps);
1729
+    for(int8_t i=0; i < NUM_AXIS; i++) {
1730
+      destination[i] = current_position[i] + difference[i] * fraction;
1731
+    }
1732
+    calculate_delta(destination);
1733
+    plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS],
1734
+                     destination[E_AXIS], feedrate*feedmultiply/60/100.0,
1735
+                     active_extruder);
1702 1736
   }
1737
+
1703 1738
   for(int8_t i=0; i < NUM_AXIS; i++) {
1704 1739
     current_position[i] = destination[i];
1705 1740
   }

Loading…
Annulla
Salva