Browse Source

Add realtime delta geometry in Marlin_main.cpp.

Johann Rocholl 12 years ago
parent
commit
8e2519e88b
2 changed files with 66 additions and 30 deletions
  1. 1
    0
      Marlin/Marlin.h
  2. 65
    30
      Marlin/Marlin_main.cpp

+ 1
- 0
Marlin/Marlin.h View File

159
 void ClearToSend();
159
 void ClearToSend();
160
 
160
 
161
 void get_coordinates();
161
 void get_coordinates();
162
+void calculate_delta(float cartesian[3]);
162
 void prepare_move();
163
 void prepare_move();
163
 void kill();
164
 void kill();
164
 void Stop();
165
 void Stop();

+ 65
- 30
Marlin/Marlin_main.cpp View File

169
 //===========================================================================
169
 //===========================================================================
170
 const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
170
 const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
171
 static float destination[NUM_AXIS] = {  0.0, 0.0, 0.0, 0.0};
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
 static float offset[3] = {0.0, 0.0, 0.0};
173
 static float offset[3] = {0.0, 0.0, 0.0};
173
 static bool home_all_axis = true;
174
 static bool home_all_axis = true;
174
 static float feedrate = 1500.0, next_feedrate, saved_feedrate;
175
 static float feedrate = 1500.0, next_feedrate, saved_feedrate;
731
       feedrate = 0.0;
732
       feedrate = 0.0;
732
       home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));
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
       #ifdef QUICK_HOME
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
         plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); 
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
         plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
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
         st_synchronize();
748
         st_synchronize();
761
         endstops_hit_on_purpose();
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
       #endif
755
       #endif
764
       
756
       
771
         HOMEAXIS(Y);
763
         HOMEAXIS(Y);
772
       }
764
       }
773
       
765
       
774
-      #if Z_HOME_DIR < 0                      // If homing towards BED do Z last
775
       if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
766
       if((home_all_axis) || (code_seen(axis_codes[Z_AXIS]))) {
776
         HOMEAXIS(Z);
767
         HOMEAXIS(Z);
777
       }
768
       }
778
-      #endif
779
       
769
       
780
       if(code_seen(axis_codes[X_AXIS])) 
770
       if(code_seen(axis_codes[X_AXIS])) 
781
       {
771
       {
795
           current_position[Z_AXIS]=code_value()+add_homeing[2];
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
       #ifdef ENDSTOPS_ONLY_FOR_HOMING
791
       #ifdef ENDSTOPS_ONLY_FOR_HOMING
801
         enable_endstops(false);
792
         enable_endstops(false);
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
 void prepare_move()
1707
 void prepare_move()
1692
 {
1708
 {
1693
   clamp_to_software_endstops(destination);
1709
   clamp_to_software_endstops(destination);
1694
 
1710
 
1695
   previous_millis_cmd = millis(); 
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
   for(int8_t i=0; i < NUM_AXIS; i++) {
1738
   for(int8_t i=0; i < NUM_AXIS; i++) {
1704
     current_position[i] = destination[i];
1739
     current_position[i] = destination[i];
1705
   }
1740
   }

Loading…
Cancel
Save