Browse Source

optimised some math-code

cocktailyogi 10 years ago
parent
commit
f0cab611db
2 changed files with 71 additions and 54 deletions
  1. 13
    18
      Marlin/Marlin_main.cpp
  2. 58
    36
      Marlin/example_configurations/SCARA/Configuration.h

+ 13
- 18
Marlin/Marlin_main.cpp View File

@@ -3674,10 +3674,10 @@ void calculate_SCARA_forward_Transform(float f_scara[3])
3674 3674
     //SERIAL_ECHOPGM("f_delta x="); SERIAL_ECHO(f_scara[X_AXIS]);
3675 3675
     //SERIAL_ECHOPGM(" y="); SERIAL_ECHO(f_scara[Y_AXIS]);
3676 3676
   
3677
-    x_sin = sin(f_scara[X_AXIS]/SCARA_RAD2DEG) * Linkage_1/1000;
3678
-    x_cos = cos(f_scara[X_AXIS]/SCARA_RAD2DEG) * Linkage_1/1000;
3679
-    y_sin = sin(f_scara[Y_AXIS]/SCARA_RAD2DEG) * Linkage_2/1000;
3680
-    y_cos = cos(f_scara[Y_AXIS]/SCARA_RAD2DEG) * Linkage_2/1000;
3677
+    x_sin = sin(f_scara[X_AXIS]/SCARA_RAD2DEG) * Linkage_1;
3678
+    x_cos = cos(f_scara[X_AXIS]/SCARA_RAD2DEG) * Linkage_1;
3679
+    y_sin = sin(f_scara[Y_AXIS]/SCARA_RAD2DEG) * Linkage_2;
3680
+    y_cos = cos(f_scara[Y_AXIS]/SCARA_RAD2DEG) * Linkage_2;
3681 3681
    
3682 3682
   //  SERIAL_ECHOPGM(" x_sin="); SERIAL_ECHO(x_sin);
3683 3683
   //  SERIAL_ECHOPGM(" x_cos="); SERIAL_ECHO(x_cos);
@@ -3697,33 +3697,29 @@ void calculate_delta(float cartesian[3]){
3697 3697
   // The maths and first version has been done by QHARLEY . Integrated into masterbranch 06/2014 and slightly restructured by Joachim Cerny in June 2014
3698 3698
   
3699 3699
   float SCARA_pos[2];
3700
-  static float L1_2, L2_2, SCARA_C2, SCARA_S2, SCARA_K1, SCARA_K2, SCARA_theta, SCARA_psi; 
3700
+  static float SCARA_C2, SCARA_S2, SCARA_K1, SCARA_K2, SCARA_theta, SCARA_psi; 
3701 3701
   
3702 3702
   SCARA_pos[X_AXIS] = cartesian[X_AXIS] * axis_scaling[X_AXIS] - SCARA_offset_x;  //Translate SCARA to standard X Y
3703 3703
   SCARA_pos[Y_AXIS] = cartesian[Y_AXIS] * axis_scaling[Y_AXIS] - SCARA_offset_y;  // With scaling factor.
3704 3704
   
3705
-  L1_2 = pow(Linkage_1/1000,2);
3706
-  L2_2 = pow(Linkage_2/1000,2);
3707
-  
3708 3705
   #if (Linkage_1 == Linkage_2)
3709
-    SCARA_C2 = ( ( pow(SCARA_pos[X_AXIS],2) + pow(SCARA_pos[Y_AXIS],2) ) / (2 * L1_2) ) - 1;
3706
+    SCARA_C2 = ( ( sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS]) ) / (2 * (float)L1_2) ) - 1;
3710 3707
   #else
3711
-    SCARA_C2 =   ( pow(SCARA_pos[X_AXIS],2) + pow(SCARA_pos[Y_AXIS],2) - L1_2 - L2_2 ) / 45000; 
3708
+    SCARA_C2 =   ( sq(SCARA_pos[X_AXIS]) + sq(SCARA_pos[Y_AXIS]) - (float)L1_2 - (float)L2_2 ) / 45000; 
3712 3709
   #endif
3713 3710
   
3714
-  SCARA_S2 = sqrt( 1 - pow(SCARA_C2,2) );
3711
+  SCARA_S2 = sqrt( 1 - sq(SCARA_C2) );
3715 3712
   
3716
-  SCARA_K1 = Linkage_1/1000+Linkage_2/1000*SCARA_C2;
3717
-  SCARA_K2 = Linkage_2/1000*SCARA_S2;
3713
+  SCARA_K1 = Linkage_1 + Linkage_2 * SCARA_C2;
3714
+  SCARA_K2 = Linkage_2 * SCARA_S2;
3718 3715
   
3719
-  SCARA_theta = (atan2(SCARA_pos[X_AXIS],SCARA_pos[Y_AXIS])-atan2(SCARA_K1, SCARA_K2))*-1;
3720
-  SCARA_psi = atan2(SCARA_S2,SCARA_C2);
3716
+  SCARA_theta = ( atan2(SCARA_pos[X_AXIS],SCARA_pos[Y_AXIS])-atan2(SCARA_K1, SCARA_K2) ) * -1;
3717
+  SCARA_psi   =   atan2(SCARA_S2,SCARA_C2);
3721 3718
   
3722 3719
   delta[X_AXIS] = SCARA_theta * SCARA_RAD2DEG;  // Multiply by 180/Pi  -  theta is support arm angle
3723 3720
   delta[Y_AXIS] = (SCARA_theta + SCARA_psi) * SCARA_RAD2DEG;  //       -  equal to sub arm angle (inverted motor)
3724 3721
   delta[Z_AXIS] = cartesian[Z_AXIS];
3725 3722
   
3726
-  
3727 3723
   /*
3728 3724
   SERIAL_ECHOPGM("cartesian x="); SERIAL_ECHO(cartesian[X_AXIS]);
3729 3725
   SERIAL_ECHOPGM(" y="); SERIAL_ECHO(cartesian[Y_AXIS]);
@@ -3740,8 +3736,7 @@ void calculate_delta(float cartesian[3]){
3740 3736
   SERIAL_ECHOPGM(" S2="); SERIAL_ECHO(SCARA_S2);
3741 3737
   SERIAL_ECHOPGM(" Theta="); SERIAL_ECHO(SCARA_theta);
3742 3738
   SERIAL_ECHOPGM(" Psi="); SERIAL_ECHOLN(SCARA_psi);
3743
-  SERIAL_ECHOLN(" ");
3744
-  */
3739
+  SERIAL_ECHOLN(" ");*/
3745 3740
 }
3746 3741
 
3747 3742
 #endif

+ 58
- 36
Marlin/example_configurations/SCARA/Configuration.h View File

@@ -14,11 +14,11 @@
14 14
 // You might need Z-Min endstop on SCARA-Printer to use this feature. Actually untested!
15 15
 // Uncomment to use Morgan scara mode
16 16
 #define SCARA  
17
-#define scara_segments_per_second 200
17
+#define scara_segments_per_second 200 //careful, two much will decrease performance...
18 18
 // Length of inner support arm
19
-#define Linkage_1 150000 //um      Preprocessor cannot handle decimal point...
20
-// Length of outer support arm     Measure arm lengths precisely, and enter 
21
-#define Linkage_2 150000 //um      define in micrometer
19
+#define Linkage_1 150 //mm      Preprocessor cannot handle decimal point...
20
+// Length of outer support arm     Measure arm lengths precisely and enter 
21
+#define Linkage_2 150 //mm    
22 22
 
23 23
 // SCARA tower offset (position of Tower relative to bed zero position) 
24 24
 // This needs to be reasonably accurate as it defines the printbed position in the SCARA space.
@@ -26,6 +26,13 @@
26 26
 #define SCARA_offset_y -56 //mm
27 27
 #define SCARA_RAD2DEG 57.2957795  // to convert RAD to degrees
28 28
 
29
+#define THETA_HOMING_OFFSET 0	//calculatated from Calibration Guide and command M360 / M114 see picture in http://reprap.harleystudio.co.za/?page_id=1073
30
+#define PSI_HOMING_OFFSET 0  // calculatated from Calibration Guide and command M364 / M114 see picture in http://reprap.harleystudio.co.za/?page_id=1073
31
+
32
+//some helper variables to make kinematics faster
33
+#define L1_2 sq(Linkage_1) // do not change
34
+#define L2_2 sq(Linkage_2) // do not change
35
+
29 36
 //===========================================================================
30 37
 //========================= SCARA Settings end ==================================
31 38
 //===========================================================================
@@ -162,8 +169,8 @@
162 169
 #define MAX_REDUNDANT_TEMP_SENSOR_DIFF 10
163 170
 
164 171
 // Actual temperature must be close to target for this long before M109 returns success
165
-#define TEMP_RESIDENCY_TIME 10  // (seconds)
166
-#define TEMP_HYSTERESIS 3       // (degC) range of +/- temperatures considered "close" to the target one
172
+#define TEMP_RESIDENCY_TIME 3  // (seconds)
173
+#define TEMP_HYSTERESIS 2       // (degC) range of +/- temperatures considered "close" to the target one
167 174
 #define TEMP_WINDOW     1       // (degC) Window around target to start the residency timer x degC early.
168 175
 
169 176
 // The minimal temperature defines the temperature below which the heater will not be enabled It is used
@@ -188,8 +195,8 @@
188 195
 //#define HEATER_BED_DUTY_CYCLE_DIVIDER 4
189 196
 
190 197
 // If you want the M105 heater power reported in watts, define the BED_WATTS, and (shared for all extruders) EXTRUDER_WATTS
191
-//#define EXTRUDER_WATTS (12.0*12.0/6.7) //  P=I^2/R
192
-//#define BED_WATTS (12.0*12.0/1.1)      // P=I^2/R
198
+#define EXTRUDER_WATTS (2*2/5.9) //  P=I^2/R
199
+#define BED_WATTS (5.45*5.45/2.2)      // P=I^2/R
193 200
 
194 201
 // PID settings:
195 202
 // Comment the following line to disable PID and enable bang-bang.
@@ -199,7 +206,7 @@
199 206
 #ifdef PIDTEMP
200 207
   //#define PID_DEBUG // Sends debug data to the serial port.
201 208
   //#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
202
-  #define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature
209
+  #define PID_FUNCTIONAL_RANGE 20 // If the temperature difference between the target temperature and the actual temperature
203 210
                                   // is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
204 211
   #define PID_INTEGRAL_DRIVE_MAX 255  //limit for the integral term
205 212
   #define K1 0.95 //smoothing factor within the PID
@@ -207,9 +214,19 @@
207 214
 
208 215
 // If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it
209 216
 // Ultimaker
210
-    #define  DEFAULT_Kp 22.2
211
-    #define  DEFAULT_Ki 1.08
212
-    #define  DEFAULT_Kd 114
217
+  //  #define  DEFAULT_Kp 22.2
218
+  //  #define  DEFAULT_Ki 1.08
219
+   // #define  DEFAULT_Kd 114
220
+  
221
+ // Jhead MK5: From Autotune  
222
+  //  #define  DEFAULT_Kp 20.92
223
+   // #define  DEFAULT_Ki 1.51
224
+  //  #define  DEFAULT_Kd 72.34
225
+    
226
+ //Merlin Hotend: From Autotune  
227
+    #define  DEFAULT_Kp 24.5
228
+    #define  DEFAULT_Ki 1.72
229
+    #define  DEFAULT_Kd 87.73
213 230
 
214 231
 // MakerGear
215 232
 //    #define  DEFAULT_Kp 7.0
@@ -217,9 +234,9 @@
217 234
 //    #define  DEFAULT_Kd 12
218 235
 
219 236
 // Mendel Parts V9 on 12V
220
-//    #define  DEFAULT_Kp 63.0
221
-//    #define  DEFAULT_Ki 2.25
222
-//    #define  DEFAULT_Kd 440
237
+  //  #define  DEFAULT_Kp 63.0
238
+   // #define  DEFAULT_Ki 2.25
239
+   // #define  DEFAULT_Kd 440
223 240
 #endif // PIDTEMP
224 241
 
225 242
 // Bed Temperature Control
@@ -232,9 +249,9 @@
232 249
 // If your configuration is significantly different than this and you don't understand the issues involved, you probably
233 250
 // shouldn't use bed PID until someone else verifies your hardware works.
234 251
 // If this is enabled, find your own PID constants below.
235
-//#define PIDTEMPBED
252
+#define PIDTEMPBED
236 253
 //
237
-//#define BED_LIMIT_SWITCHING
254
+#define BED_LIMIT_SWITCHING
238 255
 
239 256
 // This sets the max power delivered to the bed, and replaces the HEATER_BED_DUTY_CYCLE_DIVIDER option.
240 257
 // all forms of bed control obey this (PID, bang-bang, bang-bang with hysteresis)
@@ -245,9 +262,9 @@
245 262
 #ifdef PIDTEMPBED
246 263
 //120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
247 264
 //from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10)
248
-    #define  DEFAULT_bedKp 10.00
249
-    #define  DEFAULT_bedKi .023
250
-    #define  DEFAULT_bedKd 305.4
265
+  //  #define  DEFAULT_bedKp 10.00
266
+  //  #define  DEFAULT_bedKi .023
267
+  //  #define  DEFAULT_bedKd 305.4
251 268
 
252 269
 //120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
253 270
 //from pidautotune
@@ -255,6 +272,12 @@
255 272
 //    #define  DEFAULT_bedKi 1.41
256 273
 //    #define  DEFAULT_bedKd 1675.16
257 274
 
275
+//12v Heatbed Mk3 12V in parallel
276
+//from pidautotune
277
+    #define  DEFAULT_bedKp 630.14
278
+    #define  DEFAULT_bedKi 121.71
279
+    #define  DEFAULT_bedKd 815.64
280
+    
258 281
 // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
259 282
 #endif // PIDTEMPBED
260 283
 
@@ -262,11 +285,11 @@
262 285
 
263 286
 //this prevents dangerous Extruder moves, i.e. if the temperature is under the limit
264 287
 //can be software-disabled for whatever purposes by
265
-#define PREVENT_DANGEROUS_EXTRUDE
288
+//#define PREVENT_DANGEROUS_EXTRUDE
266 289
 //if PREVENT_DANGEROUS_EXTRUDE is on, you can still disable (uncomment) very long bits of extrusion separately.
267 290
 #define PREVENT_LENGTHY_EXTRUDE
268 291
 
269
-#define EXTRUDE_MINTEMP 170
292
+#define EXTRUDE_MINTEMP 150
270 293
 #define EXTRUDE_MAXLENGTH (X_MAX_LENGTH+Y_MAX_LENGTH) //prevent extrusion of very large distances.
271 294
 
272 295
 //===========================================================================
@@ -329,7 +352,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
329 352
 #define INVERT_X_DIR false    // for Mendel set to false, for Orca set to true
330 353
 #define INVERT_Y_DIR false    // for Mendel set to true, for Orca set to false
331 354
 #define INVERT_Z_DIR true     // for Mendel set to false, for Orca set to true
332
-#define INVERT_E0_DIR true   // for direct drive extruder v9 set to true, for geared extruder set to false
355
+#define INVERT_E0_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
333 356
 #define INVERT_E1_DIR false    // for direct drive extruder v9 set to true, for geared extruder set to false
334 357
 #define INVERT_E2_DIR false   // for direct drive extruder v9 set to true, for geared extruder set to false
335 358
 
@@ -451,8 +474,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
451 474
 //Manual homing switch locations:
452 475
 // For deltabots this means top and center of the Cartesian print volume.
453 476
 // For SCARA: Offset between HomingPosition and Bed X=0 / Y=0
454
-#define MANUAL_X_HOME_POS -20
455
-#define MANUAL_Y_HOME_POS -48
477
+#define MANUAL_X_HOME_POS -22.
478
+#define MANUAL_Y_HOME_POS -52.
456 479
 #define MANUAL_Z_HOME_POS 0.1  // Distance between nozzle and print surface after homing.
457 480
 
458 481
 
@@ -462,24 +485,23 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
462 485
 
463 486
 // default settings
464 487
 
465
-//#define DEFAULT_AXIS_STEPS_PER_UNIT   {85.6,85.6,200/1.25,970}  // default steps per unit for Ultimaker
466
-#define DEFAULT_AXIS_STEPS_PER_UNIT   {109,109,200/1.25,970}  // default steps per unit for Ultimaker
467
-#define DEFAULT_MAX_FEEDRATE          {200, 200, 30, 45}    // (mm/sec)
468
-#define DEFAULT_MAX_ACCELERATION      {300,300,30,1500}    // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for Skeinforge 40+, for older versions raise them a lot.
488
+#define DEFAULT_AXIS_STEPS_PER_UNIT   {103.69,106.65,200/1.25,1000}  // default steps per unit for SCARA
489
+#define DEFAULT_MAX_FEEDRATE          {300, 300, 30, 25}    // (mm/sec)
490
+#define DEFAULT_MAX_ACCELERATION      {300,300,20,1000}    // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for Skeinforge 40+, for older versions raise them a lot.
469 491
 
470
-#define DEFAULT_ACCELERATION          300    // X, Y, Z and E max acceleration in mm/s^2 for printing moves
471
-#define DEFAULT_RETRACT_ACCELERATION  3000   // X, Y, Z and E max acceleration in mm/s^2 for retracts
492
+#define DEFAULT_ACCELERATION          400    // X, Y, Z and E max acceleration in mm/s^2 for printing moves
493
+#define DEFAULT_RETRACT_ACCELERATION  2000  // X, Y, Z and E max acceleration in mm/s^2 for retracts
472 494
 
473 495
 // Offset of the extruders (uncomment if using more than one and relying on firmware to position when changing).
474
-// The offset has to be X=0, Y=0 for the extruder 0 hotend (default extruder).
496
+// The offset has to be X=0, Y=0 for extruder 0 hotend (default extruder).
475 497
 // For the other hotends it is their distance from the extruder 0 hotend.
476 498
 // #define EXTRUDER_OFFSET_X {0.0, 20.00} // (in mm) for each extruder, offset of the hotend on the X axis
477 499
 // #define EXTRUDER_OFFSET_Y {0.0, 5.00}  // (in mm) for each extruder, offset of the hotend on the Y axis
478 500
 
479 501
 // The speed change that does not require acceleration (i.e. the software might assume it can be done instantaneously)
480
-#define DEFAULT_XYJERK                10.0    // (mm/sec)
481
-#define DEFAULT_ZJERK                 10.0     // (mm/sec)
482
-#define DEFAULT_EJERK                 5.0    // (mm/sec)
502
+#define DEFAULT_XYJERK                5    // (mm/sec)
503
+#define DEFAULT_ZJERK                 0.4    // (mm/sec)
504
+#define DEFAULT_EJERK                 3    // (mm/sec)
483 505
 
484 506
 //===========================================================================
485 507
 //=============================Additional Features===========================
@@ -500,7 +522,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
500 522
 // M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).
501 523
 // M502 - reverts to the default "factory settings".  You still need to store them in EEPROM afterwards if you want to.
502 524
 //define this to enable EEPROM support
503
-#define EEPROM_SETTINGS
525
+//#define EEPROM_SETTINGS
504 526
 //to disable EEPROM Serial responses and decrease program space by ~1700 byte: comment this out:
505 527
 // please keep turned on if you can.
506 528
 #define EEPROM_CHITCHAT

Loading…
Cancel
Save