Browse Source

Patched up, cleaned up

Scott Lahteine 8 years ago
parent
commit
a2864ab7fe
6 changed files with 254 additions and 251 deletions
  1. 107
    52
      Marlin/Configuration.h
  2. 9
    3
      Marlin/Configuration_adv.h
  3. 3
    4
      Marlin/Marlin.h
  4. 109
    171
      Marlin/Marlin_main.cpp
  5. 11
    0
      Marlin/SanityCheck.h
  6. 15
    21
      Marlin/endstops.cpp

+ 107
- 52
Marlin/Configuration.h View File

@@ -86,7 +86,7 @@
86 86
 // User-specified version info of this build to display in [Pronterface, etc] terminal window during
87 87
 // startup. Implementation of an idea by Prof Braino to inform user that any changes made to this
88 88
 // build by the user have been successfully uploaded into firmware.
89
-#define STRING_CONFIG_H_AUTHOR "Bob Kuhn, G2/G3 radius testing" // Who made the changes.
89
+#define STRING_CONFIG_H_AUTHOR "(none, default config)" // Who made the changes.
90 90
 #define SHOW_BOOTSCREEN
91 91
 #define STRING_SPLASH_LINE1 SHORT_BUILD_VERSION // will be shown during bootup in line 1
92 92
 #define STRING_SPLASH_LINE2 WEBSITE_URL         // will be shown during bootup in line 2
@@ -105,15 +105,24 @@
105 105
 //#define SHOW_CUSTOM_BOOTSCREEN
106 106
 // @section machine
107 107
 
108
-// SERIAL_PORT selects which serial port should be used for communication with the host.
109
-// This allows the connection of wireless adapters (for instance) to non-default port pins.
110
-// Serial port 0 is still used by the Arduino bootloader regardless of this setting.
111
-// :[0,1,2,3,4,5,6,7]
108
+/**
109
+ * Select which serial port on the board will be used for communication with the host.
110
+ * This allows the connection of wireless adapters (for instance) to non-default port pins.
111
+ * Serial port 0 is always used by the Arduino bootloader regardless of this setting.
112
+ *
113
+ * :[0,1,2,3,4,5,6,7]
114
+ */
112 115
 #define SERIAL_PORT 0
113 116
 
114
-// This determines the communication speed of the printer
115
-// :[2400,9600,19200,38400,57600,115200,250000]
116
-#define BAUDRATE 115200
117
+#define BAUDRATE 250000
118
+/**
119
+ * This setting determines the communication speed of the printer.
120
+ *
121
+ * 250000 works in most cases, but you might try a lower speed if
122
+ * you commonly experience drop-outs during host printing.
123
+ *
124
+ * :[2400,9600,19200,38400,57600,115200,250000]
125
+ */
117 126
 
118 127
 // Enable the Bluetooth serial interface on AT90USB devices
119 128
 //#define BLUETOOTH
@@ -121,7 +130,7 @@
121 130
 // The following define selects which electronics board you have.
122 131
 // Please choose the name from boards.h that matches your setup
123 132
 #ifndef MOTHERBOARD
124
-  #define MOTHERBOARD BOARD_AZTEEG_X3_PRO     
133
+  #define MOTHERBOARD BOARD_RAMPS_14_EFB
125 134
 #endif
126 135
 
127 136
 // Optional custom name for your RepStrap or other custom machine
@@ -169,14 +178,22 @@
169 178
 //#define HOTEND_OFFSET_X {0.0, 20.00} // (in mm) for each extruder, offset of the hotend on the X axis
170 179
 //#define HOTEND_OFFSET_Y {0.0, 5.00}  // (in mm) for each extruder, offset of the hotend on the Y axis
171 180
 
172
-//// The following define selects which power supply you have. Please choose the one that matches your setup
173
-// 1 = ATX
174
-// 2 = X-Box 360 203Watts (the blue wire connected to PS_ON and the red wire to VCC)
175
-// :{1:'ATX',2:'X-Box 360'}
176
-#define POWER_SUPPLY 1
181
+/**
182
+ * Select your power supply here. Use 0 if you haven't connected the PS_ON_PIN
183
+ *
184
+ * 0 = No Power Switch
185
+ * 1 = ATX
186
+ * 2 = X-Box 360 203Watts (the blue wire connected to PS_ON and the red wire to VCC)
187
+ *
188
+ * :{0:'No power switch',1:'ATX',2:'X-Box 360'}
189
+ */
190
+#define POWER_SUPPLY 0
177 191
 
178
-// Define this to have the electronics keep the power supply off on startup. If you don't know what this is leave it.
179
-//#define PS_DEFAULT_OFF
192
+#if POWER_SUPPLY > 0
193
+  // Enable this option to leave the PSU off at startup.
194
+  // Power to steppers and heaters will need to be turned on with M80.
195
+  //#define PS_DEFAULT_OFF
196
+#endif
180 197
 
181 198
 // @section temperature
182 199
 
@@ -222,10 +239,10 @@
222 239
 // 110 is Pt100 with 1k pullup (non standard)
223 240
 // 998 and 999 are Dummy Tables. They will ALWAYS read 25°C or the temperature defined below.
224 241
 //     Use it for Testing or Development purposes. NEVER for production machine.
225
-#define DUMMY_THERMISTOR_998_VALUE 25
242
+//#define DUMMY_THERMISTOR_998_VALUE 25
226 243
 //#define DUMMY_THERMISTOR_999_VALUE 100
227 244
 // :{ '0': "Not used",'1':"100k / 4.7k - EPCOS",'2':"200k / 4.7k - ATC Semitec 204GT-2",'3':"Mendel-parts / 4.7k",'4':"10k !! do not use for a hotend. Bad resolution at high temp. !!",'5':"100K / 4.7k - ATC Semitec 104GT-2 (Used in ParCan & J-Head)",'6':"100k / 4.7k EPCOS - Not as accurate as Table 1",'7':"100k / 4.7k Honeywell 135-104LAG-J01",'8':"100k / 4.7k 0603 SMD Vishay NTCS0603E3104FXT",'9':"100k / 4.7k GE Sensing AL03006-58.2K-97-G1",'10':"100k / 4.7k RS 198-961",'11':"100k / 4.7k beta 3950 1%",'12':"100k / 4.7k 0603 SMD Vishay NTCS0603E3104FXT (calibrated for Makibox hot bed)",'13':"100k Hisens 3950  1% up to 300°C for hotend 'Simple ONE ' & hotend 'All In ONE'",'20':"PT100 (Ultimainboard V2.x)",'51':"100k / 1k - EPCOS",'52':"200k / 1k - ATC Semitec 204GT-2",'55':"100k / 1k - ATC Semitec 104GT-2 (Used in ParCan & J-Head)",'60':"100k Maker's Tool Works Kapton Bed Thermistor beta=3950",'66':"Dyze Design 4.7M High Temperature thermistor",'70':"the 100K thermistor found in the bq Hephestos 2",'71':"100k / 4.7k Honeywell 135-104LAF-J01",'147':"Pt100 / 4.7k",'1047':"Pt1000 / 4.7k",'110':"Pt100 / 1k (non-standard)",'1010':"Pt1000 / 1k (non standard)",'-3':"Thermocouple + MAX31855 (only for sensor 0)",'-2':"Thermocouple + MAX6675 (only for sensor 0)",'-1':"Thermocouple + AD595",'998':"Dummy 1",'999':"Dummy 2" }
228
-#define TEMP_SENSOR_0 998
245
+#define TEMP_SENSOR_0 1
229 246
 #define TEMP_SENSOR_1 0
230 247
 #define TEMP_SENSOR_2 0
231 248
 #define TEMP_SENSOR_3 0
@@ -355,8 +372,9 @@
355 372
 #define EXTRUDE_MINTEMP 170
356 373
 
357 374
 // This option prevents a single extrusion longer than EXTRUDE_MAXLENGTH.
375
+// Note that for Bowden Extruders a too-small value here may prevent loading.
358 376
 #define PREVENT_LENGTHY_EXTRUDE
359
-#define EXTRUDE_MAXLENGTH (X_MAX_LENGTH+Y_MAX_LENGTH)
377
+#define EXTRUDE_MAXLENGTH 200
360 378
 
361 379
 //===========================================================================
362 380
 //======================== Thermal Runaway Protection =======================
@@ -403,9 +421,9 @@
403 421
 #define USE_XMIN_PLUG
404 422
 #define USE_YMIN_PLUG
405 423
 #define USE_ZMIN_PLUG
406
-#define USE_XMAX_PLUG
407
-#define USE_YMAX_PLUG
408
-#define USE_ZMAX_PLUG
424
+//#define USE_XMAX_PLUG
425
+//#define USE_YMAX_PLUG
426
+//#define USE_ZMAX_PLUG
409 427
 
410 428
 // coarse Endstop Settings
411 429
 #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
@@ -422,13 +440,13 @@
422 440
 #endif
423 441
 
424 442
 // Mechanical endstop with COM to ground and NC to Signal uses "false" here (most common setup).
425
-#define X_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
426
-#define Y_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
427
-#define Z_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
428
-#define X_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
429
-#define Y_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
430
-#define Z_MAX_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
431
-#define Z_MIN_PROBE_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
443
+#define X_MIN_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
444
+#define Y_MIN_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
445
+#define Z_MIN_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
446
+#define X_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
447
+#define Y_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
448
+#define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
449
+#define Z_MIN_PROBE_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
432 450
 
433 451
 
434 452
 //=============================================================================
@@ -436,20 +454,56 @@
436 454
 //=============================================================================
437 455
 // @section motion
438 456
 
439
-#define DEFAULT_AXIS_STEPS_PER_UNIT   {8*24.8139,8*24.8139,8*24.8139,100}  
440
-#define DEFAULT_MAX_FEEDRATE          {35, 35, 25, 25}        // (mm/sec)
441
-#define DEFAULT_MAX_ACCELERATION      {3000,3000,100,10000}    // 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.
457
+/**
458
+ * Default Settings
459
+ *
460
+ * These settings can be reset by M502
461
+ *
462
+ * Note that if EEPROM is enabled, saved values will override these.
463
+ */
464
+
465
+/**
466
+ * Default Axis Steps Per Unit (steps/mm)
467
+ * Override with M92
468
+ */
469
+#define DEFAULT_AXIS_STEPS_PER_UNIT   { 80, 80, 4000, 500 }
470
+
471
+/**
472
+ * Default Max Feed Rate (mm/s)
473
+ * Override with M203
474
+ */
475
+#define DEFAULT_MAX_FEEDRATE          { 300, 300, 5, 25 }
476
+
477
+/**
478
+ * Default Max Acceleration (change/s) change = mm/s
479
+ * Override with M201
480
+ *
481
+ * Maximum start speed for accelerated moves: { X, Y, Z, E }
482
+ */
483
+#define DEFAULT_MAX_ACCELERATION      { 3000, 3000, 100, 10000 }
442 484
 
443
-#define DEFAULT_ACCELERATION          3000    // X, Y, Z and E acceleration in mm/s^2 for printing moves
444
-#define DEFAULT_RETRACT_ACCELERATION  3000    // E acceleration in mm/s^2 for retracts
445
-#define DEFAULT_TRAVEL_ACCELERATION   3000    // X, Y, Z acceleration in mm/s^2 for travel (non printing) moves
485
+/**
486
+ * Default Acceleration (change/s) change = mm/s
487
+ * Override with M204
488
+ *
489
+ *   M204 P    Acceleration
490
+ *   M204 R    Retract Acceleration
491
+ *   M204 T    Travel Acceleration
492
+ */
493
+#define DEFAULT_ACCELERATION          3000    // X, Y, Z and E acceleration for printing moves
494
+#define DEFAULT_RETRACT_ACCELERATION  3000    // E acceleration for retracts
495
+#define DEFAULT_TRAVEL_ACCELERATION   3000    // X, Y, Z acceleration for travel (non printing) moves
446 496
 
447
-// "Jerk" specifies the minimum speed change that requires acceleration.
448
-// When changing speed and direction, if the difference is less than the
449
-// value set here, it may happen instantaneously.
450
-#define DEFAULT_XYJERK                20.0    // (mm/sec)
451
-#define DEFAULT_ZJERK                  0.4    // (mm/sec)
452
-#define DEFAULT_EJERK                  5.0    // (mm/sec)
497
+/**
498
+ * Defult Jerk (mm/s)
499
+ *
500
+ * "Jerk" specifies the minimum speed change that requires acceleration.
501
+ * When changing speed and direction, if the difference is less than the
502
+ * value set here, it may happen instantaneously.
503
+ */
504
+#define DEFAULT_XYJERK                20.0
505
+#define DEFAULT_ZJERK                  0.4
506
+#define DEFAULT_EJERK                  5.0
453 507
 
454 508
 
455 509
 //===========================================================================
@@ -474,6 +528,7 @@
474 528
 //#define FIX_MOUNTED_PROBE
475 529
 
476 530
 // The BLTouch probe emulates a servo probe.
531
+// The default connector is SERVO 0. Set Z_ENDSTOP_SERVO_NR below to override.
477 532
 //#define BLTOUCH
478 533
 
479 534
 // Z Servo Probe, such as an endstop switch on a rotating arm.
@@ -610,9 +665,9 @@
610 665
 // @section machine
611 666
 
612 667
 // Invert the stepper direction. Change (or reverse the motor connector) if an axis goes the wrong way.
613
-#define INVERT_X_DIR true    // positive is away from the motor
614
-#define INVERT_Y_DIR false    // positive is towards the motor
615
-#define INVERT_Z_DIR true    // positive is away from the motor
668
+#define INVERT_X_DIR false
669
+#define INVERT_Y_DIR true
670
+#define INVERT_Z_DIR false
616 671
 
617 672
 // @section extruder
618 673
 
@@ -640,12 +695,12 @@
640 695
 // @section machine
641 696
 
642 697
 // Travel limits after homing (units are in mm)
643
-#define X_MIN_POS -100
644
-#define Y_MIN_POS -100
645
-#define Z_MIN_POS -100
646
-#define X_MAX_POS 375
647
-#define Y_MAX_POS 450
648
-#define Z_MAX_POS 450
698
+#define X_MIN_POS 0
699
+#define Y_MIN_POS 0
700
+#define Z_MIN_POS 0
701
+#define X_MAX_POS 200
702
+#define Y_MAX_POS 200
703
+#define Z_MAX_POS 200
649 704
 
650 705
 //===========================================================================
651 706
 //========================= Filament Runout Sensor ==========================
@@ -1005,7 +1060,7 @@
1005 1060
 // SD Card support is disabled by default. If your controller has an SD slot,
1006 1061
 // you must uncomment the following option or it won't work.
1007 1062
 //
1008
-#define SDSUPPORT
1063
+//#define SDSUPPORT
1009 1064
 
1010 1065
 //
1011 1066
 // SD CARD: SPI SPEED
@@ -1022,7 +1077,7 @@
1022 1077
 //
1023 1078
 // Use CRC checks and retries on the SD communication.
1024 1079
 //
1025
-#define SD_CHECK_AND_RETRY
1080
+//#define SD_CHECK_AND_RETRY
1026 1081
 
1027 1082
 //
1028 1083
 // ENCODER SETTINGS

+ 9
- 3
Marlin/Configuration_adv.h View File

@@ -244,16 +244,16 @@
244 244
 // Dual Y Steppers
245 245
 // Uncomment this option to drive two Y axis motors.
246 246
 // The next unused E driver will be assigned to the second Y stepper.
247
-#define Y_DUAL_STEPPER_DRIVERS
247
+//#define Y_DUAL_STEPPER_DRIVERS
248 248
 #if ENABLED(Y_DUAL_STEPPER_DRIVERS)
249 249
   // Set true if the two Y motors need to rotate in opposite directions
250
-  #define INVERT_Y2_VS_Y_DIR false
250
+  #define INVERT_Y2_VS_Y_DIR true
251 251
 #endif
252 252
 
253 253
 // A single Z stepper driver is usually used to drive 2 stepper motors.
254 254
 // Uncomment this option to use a separate stepper driver for each Z axis motor.
255 255
 // The next unused E driver will be assigned to the second Z stepper.
256
-#define Z_DUAL_STEPPER_DRIVERS
256
+//#define Z_DUAL_STEPPER_DRIVERS
257 257
 
258 258
 #if ENABLED(Z_DUAL_STEPPER_DRIVERS)
259 259
 
@@ -532,6 +532,12 @@
532 532
 // Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
533 533
 //#define BEZIER_CURVE_SUPPORT
534 534
 
535
+// G38 Probe Target
536
+//#define G38_2_3
537
+#if ENABLED(G38_2_3)
538
+  #define G38_MINIMUM_MOVE 0.0275 // minimum distance in mm that will produce a move (determined using the print statement in check_move)
539
+#endif
540
+
535 541
 // Moves (or segments) with fewer steps than this will be joined with the next move
536 542
 #define MIN_STEPS_PER_SEGMENT 6
537 543
 

+ 3
- 4
Marlin/Marlin.h View File

@@ -209,10 +209,9 @@ void manage_inactivity(bool ignore_stepper_queue = false);
209 209
 
210 210
 #endif // !MIXING_EXTRUDER
211 211
 
212
-#define G38_2_3
213
-#ifdef G38_2_3
214
-extern bool G38_flag ;   //flag to tell the interrupt handler that a G38 command is being run
215
-extern bool G38_flag_pass ;   //flag from the interrupt handler to indicate if the endstop went active
212
+#if ENABLED(G38_2_3)
213
+  extern bool G38_move,        // flag to tell the interrupt handler that a G38 command is being run
214
+              G38_endstop_hit; // flag from the interrupt handler to indicate if the endstop went active
216 215
 #endif
217 216
 
218 217
 /**

+ 109
- 171
Marlin/Marlin_main.cpp View File

@@ -117,7 +117,7 @@
117 117
  * G30 - Single Z probe, probes bed at current XY location.
118 118
  * G31 - Dock sled (Z_PROBE_SLED only)
119 119
  * G32 - Undock sled (Z_PROBE_SLED only)
120
- * G38 - Probe target - similar to G28 except it uses the Z_Probe for all three axis
120
+ * G38 - Probe target - similar to G28 except it uses the Z_MIN endstop for all three axes
121 121
  * G90 - Use Absolute Coordinates
122 122
  * G91 - Use Relative Coordinates
123 123
  * G92 - Set current position to coordinates given
@@ -277,9 +277,9 @@
277 277
   TWIBus i2c;
278 278
 #endif
279 279
 
280
-#ifdef G38_2_3
281
-bool G38_flag = false;   // init G38 flags
282
-bool G38_flag_pass = false;
280
+#if ENABLED(G38_2_3)
281
+  bool G38_move = false,
282
+       G38_endstop_hit = false;
283 283
 #endif
284 284
 
285 285
 bool Running = true;
@@ -1343,7 +1343,7 @@ static void set_home_offset(AxisEnum axis, float v) {
1343 1343
  * SCARA should wait until all XY homing is done before setting the XY
1344 1344
  * current_position to home, because neither X nor Y is at home until
1345 1345
  * both are at home. Z can however be homed individually.
1346
- * 
1346
+ *
1347 1347
  */
1348 1348
 static void set_axis_is_at_home(AxisEnum axis) {
1349 1349
   #if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -2331,146 +2331,6 @@ static void clean_up_after_endstop_or_probe_move() {
2331 2331
 
2332 2332
 #endif // AUTO_BED_LEVELING_BILINEAR
2333 2333
 
2334
-
2335
-#ifdef G38_2_3
2336
-
2337
-#define G38_minimum_move  0.0275   // minimum distance in mm that will produce a move (determined using the print statement in check_move)
2338
-
2339
-bool check_move()  //checks that at least one of the axis in the command line has an actual move
2340
-                   // motion planner only does moves of 0.001mm and larger
2341
-{
2342
-	
2343
-  bool move_flag = false;
2344
-  for(int8_t i=0; i < 3; i++) {
2345
-/* debug used to determine prints
2346
-		SERIAL_PROTOCOLPGM("axis: ");
2347
-		SERIAL_PROTOCOL(axis_codes[i]);
2348
-		SERIAL_PROTOCOLPGM("  code_seen :  ");
2349
-		SERIAL_PROTOCOL(code_seen(axis_codes[i]));
2350
-		SERIAL_PROTOCOLPGM("  destination : ");
2351
-		SERIAL_PROTOCOL(destination[i]);
2352
-		SERIAL_PROTOCOLPGM("  current : ");
2353
-		SERIAL_PROTOCOL(current_position[i]);
2354
-		SERIAL_PROTOCOLPGM("  dif x 1000 : ");
2355
-		SERIAL_PROTOCOLLN((destination[i] - current_position[i]) * 1000);
2356
- */		
2357
-  if (code_seen(axis_codes[i]) && (fabs(destination[i] - current_position[i]) >= G38_minimum_move)) move_flag = true ;
2358
-/*
2359
- ??  0.0275mm produced a move on my machine along with an updated current position. 
2360
-     0.0265mm did NOT produce a move and did NOT change the current position
2361
-     this is very different than the 0.001 in the planner.
2362
-       0.001" is .0254mm so maybe the 0.0275 observed comes from digital storage limitations/conversion/rounding
2363
- */
2364
-  }
2365
-  return move_flag;
2366
-}
2367
-
2368
-
2369
-static void G38_run_probe(bool *G38_pass_fail) {
2370
- 
2371
-  G38_flag = true;  //tell the interrupt handler that we're doing a G38 probe
2372
-  *G38_pass_fail = false;  
2373
-  
2374
-#ifdef X_HOME_BUMP_MM
2375
-#ifdef Y_HOME_BUMP_MM
2376
-#ifdef Z_HOME_BUMP_MM
2377
-  float G38_X_retract_mm = home_bump_mm(X_AXIS);
2378
-  float G38_Y_retract_mm = home_bump_mm(Y_AXIS);
2379
-  float G38_Z_retract_mm = home_bump_mm(Z_AXIS);
2380
-  
2381
-#else
2382
-    
2383
-  float G38_X_retract_mm = 5;
2384
-  float G38_Y_retract_mm = 5;
2385
-  float G38_Z_retract_mm = 2;
2386
-
2387
-#endif
2388
-#endif  
2389
-#endif  
2390
-  
2391
-  // only retract the axis if the axis is in the command
2392
-  if( (!code_seen('X') || (code_value_axis_units(X_AXIS) == 0)))  G38_X_retract_mm = 0;   
2393
-  if( (!code_seen('Y') || (code_value_axis_units(Y_AXIS) == 0)))  G38_Y_retract_mm = 0;
2394
-  if( (!code_seen('Z') || (code_value_axis_units(Z_AXIS) == 0)))  G38_Z_retract_mm = 0;
2395
-
2396
-  // change the direction of the retract if needed
2397
-  if ((destination[X_AXIS] - current_position[X_AXIS])>0) G38_X_retract_mm = -G38_X_retract_mm;
2398
-  if ((destination[Y_AXIS] - current_position[Y_AXIS])>0) G38_Y_retract_mm = -G38_Y_retract_mm;
2399
-  if ((destination[Z_AXIS] - current_position[Z_AXIS])>0) G38_Z_retract_mm = -G38_Z_retract_mm;
2400
-
2401
-  
2402
-  stepper.synchronize();  // wait until the machine is idle
2403
-  
2404
-  bool save_endstops = endstops.enabled;    //remember state of endstops so we can retore them at the end
2405
-  endstops.enable(true);
2406
-    
2407
-  // move until you reach the destination or hit an endstop or hit the target
2408
-  // it's an error unless have hit the target
2409
-  G38_flag_pass = false;
2410
-  *G38_pass_fail = false;
2411
-  
2412
-  planner.buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate_mm_s, active_extruder);
2413
-  stepper.synchronize();
2414
-
2415
-  // we have to let the planner know where we are right now as it is not where we said to go.
2416
-  //  and we need to update current_position[axis]
2417
-  current_position[X_AXIS] = stepper.get_axis_position_mm(X_AXIS);
2418
-  current_position[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
2419
-  current_position[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
2420
-  planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS] , current_position[Z_AXIS] , current_position[E_AXIS]);
2421
-
2422
-  *G38_pass_fail = G38_flag_pass ;  // only care if hit target on the first move
2423
-    
2424
-  if (*G38_pass_fail) {  // no sense in doing the remaining moves if we didn't hit the endstop  
2425
-    // move away the retract distance
2426
-    float xPosition = current_position[X_AXIS] + G38_X_retract_mm;
2427
-    float yPosition = current_position[Y_AXIS] + G38_Y_retract_mm;
2428
-    float zPosition = current_position[Z_AXIS] + G38_Z_retract_mm;
2429
-     
2430
-
2431
-  
2432
-    // disable endstops on retract otherwise sometimes can't get away  
2433
-    endstops.enable(false);
2434
-    G38_flag = false; 
2435
-    
2436
-    planner.buffer_line(xPosition, yPosition , zPosition , current_position[E_AXIS], feedrate_mm_s/4, active_extruder);
2437
-    stepper.synchronize();
2438
-
2439
-
2440
-    // move back slowly
2441
-    xPosition -= G38_X_retract_mm * 2;
2442
-    yPosition -= G38_Y_retract_mm * 2;
2443
-    zPosition -= G38_Z_retract_mm * 2;
2444
- 
2445
-
2446
-    // enable endstops on move back
2447
-    endstops.enable(true);
2448
-    G38_flag = true; 
2449
-    
2450
-    planner.buffer_line(xPosition, yPosition , zPosition , current_position[E_AXIS], feedrate_mm_s/4, active_extruder);
2451
-    stepper.synchronize();
2452
-
2453
-    // we have to let the planner know where we are right now as it is not where we said to go.
2454
-    //  and we need to update current_position[axis]
2455
-    current_position[X_AXIS] = stepper.get_axis_position_mm(X_AXIS);
2456
-    current_position[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
2457
-    current_position[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
2458
-    planner.set_position_mm(current_position[X_AXIS], current_position[Y_AXIS] , current_position[Z_AXIS] , current_position[E_AXIS]);
2459
-    
2460
-  }  
2461
-  
2462
-//  clean_up_after_endstop_move();
2463
-
2464
-  endstops.enable(save_endstops);   //restore endstops to same state as when we started
2465
-
2466
-  endstops.hit_on_purpose();
2467
-  G38_flag = false;  //tell the interrupt handler that we're done
2468
-  
2469
-}
2470
-
2471
-#endif  //G38_2_3
2472
-
2473
-
2474 2334
 /**
2475 2335
  * Home an individual linear axis
2476 2336
  */
@@ -4306,25 +4166,93 @@ inline void gcode_G28() {
4306 4166
 
4307 4167
 #endif // HAS_BED_PROBE
4308 4168
 
4309
-#ifdef G38_2_3
4310
-  inline void gcode_G38(float code_num) { 
4311
-  #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) || ENABLED(Z_MIN_PROBE_ENDSTOP)  //must have valid Z_MIN_PROBE definition for this command to work  
4312
-    if ((code_num == 38.2 || code_num == 38.3  ) && (code_seen('X') || code_seen('Y') || code_seen('Z'))) {
4313
-      gcode_get_destination(); // For X Y Z E F
4314
-      if (check_move()) {   // see if the commanded movement will result in a physical movement
4315
-		bool G38_pass_fail = false;
4316
-		G38_run_probe(&G38_pass_fail);
4317
-        if (!G38_pass_fail && (code_num == 38.2) ) SERIAL_PROTOCOLLNPGM(" ERROR - failed to reach target ");
4318
-      }
4169
+#if ENABLED(G38_2_3)
4170
+
4171
+  static bool G38_run_probe() {
4172
+
4173
+    bool G38_pass_fail = false;
4174
+
4175
+    // Get direction of move and retract
4176
+    float retract_mm[XYZ];
4177
+    LOOP_XYZ(i) {
4178
+      float dist = destination[i] - current_position[i];
4179
+      retract_mm[i] = fabs(dist) < G38_MINIMUM_MOVE ? 0 : home_bump_mm(i) * (dist > 0 ? -1 : 1);
4319 4180
     }
4181
+
4182
+    stepper.synchronize();  // wait until the machine is idle
4183
+
4184
+    // Move until destination reached or target hit
4185
+    endstops.enable(true);
4186
+    G38_move = true;
4187
+    G38_endstop_hit = false;
4188
+    prepare_move_to_destination();
4189
+    stepper.synchronize();
4190
+    G38_move = false;
4191
+
4192
+    endstops.hit_on_purpose();
4193
+    set_current_from_steppers_for_axis(ALL_AXES);
4194
+    SYNC_PLAN_POSITION_KINEMATIC();
4195
+
4196
+    // Only do remaining moves if target was hit
4197
+    if (G38_endstop_hit) {
4198
+
4199
+      G38_pass_fail = true;
4200
+
4201
+      // Move away by the retract distance
4202
+      set_destination_to_current();
4203
+      LOOP_XYZ(i) destination[i] += retract_mm[i];
4204
+      endstops.enable(false);
4205
+      prepare_move_to_destination();
4206
+      stepper.synchronize();
4207
+
4208
+      feedrate_mm_s /= 4;
4209
+
4210
+      // Bump the target more slowly
4211
+      LOOP_XYZ(i) destination[i] -= retract_mm[i] * 2;
4212
+
4213
+      endstops.enable(true);
4214
+      G38_move = true;
4215
+      prepare_move_to_destination();
4216
+      stepper.synchronize();
4217
+      G38_move = false;
4218
+
4219
+      set_current_from_steppers_for_axis(ALL_AXES);
4220
+      SYNC_PLAN_POSITION_KINEMATIC();
4221
+    }
4222
+
4223
+    endstops.hit_on_purpose();
4224
+    endstops.not_homing();
4225
+    return G38_pass_fail;
4320 4226
   }
4321
-#else
4322
- 
4323
-    SERIAL_PROTOCOLLNPGM(" ERROR - Z_MIN_PROBE must be enabled ");	
4227
+
4228
+  /**
4229
+   * G38.2 - probe toward workpiece, stop on contact, signal error if failure
4230
+   * G38.3 - probe toward workpiece, stop on contact
4231
+   *
4232
+   * Like G28 except uses Z min endstop for all axes
4233
+   */
4234
+  inline void gcode_G38(bool is_38_2) {
4235
+    // Get X Y Z E F
4236
+    gcode_get_destination();
4237
+
4238
+    setup_for_endstop_or_probe_move();
4239
+
4240
+    // If any axis has enough movement, do the move
4241
+    LOOP_XYZ(i)
4242
+      if (fabs(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) {
4243
+        if (!code_seen('F')) feedrate_mm_s = homing_feedrate_mm_s[i];
4244
+        // If G38.2 fails throw an error
4245
+        if (!G38_run_probe() && is_38_2) {
4246
+          SERIAL_ERROR_START;
4247
+          SERIAL_ERRORLNPGM("Failed to reach target");
4248
+        }
4249
+        break;
4250
+      }
4251
+
4252
+    clean_up_after_endstop_or_probe_move();
4324 4253
   }
4325
-#endif	
4326
-#endif //G38_2_3
4327 4254
 
4255
+#endif // G38_2_3
4328 4256
 
4329 4257
 /**
4330 4258
  * G92: Set current position to given X Y Z E
@@ -7447,23 +7375,32 @@ void process_next_command() {
7447 7375
   // Skip spaces to get the numeric part
7448 7376
   while (*cmd_ptr == ' ') cmd_ptr++;
7449 7377
 
7378
+  // Allow for decimal point in command
7379
+  #if ENABLED(G38_2_3)
7380
+    uint8_t subcode = 0;
7381
+  #endif
7382
+
7450 7383
   uint16_t codenum = 0; // define ahead of goto
7451 7384
 
7452 7385
   // Bail early if there's no code
7453 7386
   bool code_is_good = NUMERIC(*cmd_ptr);
7454 7387
   if (!code_is_good) goto ExitUnknownCommand;
7455 7388
 
7456
-#ifdef G38_2_3
7457
-  double codenum_float;
7458
-  codenum_float = atof(cmd_ptr);  //allow for decimal point in command
7459
-#endif
7460
-
7461 7389
   // Get and skip the code number
7462 7390
   do {
7463 7391
     codenum = (codenum * 10) + (*cmd_ptr - '0');
7464 7392
     cmd_ptr++;
7465 7393
   } while (NUMERIC(*cmd_ptr));
7466 7394
 
7395
+  // Allow for decimal point in command
7396
+  #if ENABLED(G38_2_3)
7397
+    if (*cmd_ptr == '.') {
7398
+      cmd_ptr++;
7399
+      while (NUMERIC(*cmd_ptr))
7400
+        subcode = (subcode * 10) + (*cmd_ptr++ - '0');
7401
+    }
7402
+  #endif
7403
+
7467 7404
   // Skip all spaces to get to the first argument, or nul
7468 7405
   while (*cmd_ptr == ' ') cmd_ptr++;
7469 7406
 
@@ -7564,12 +7501,13 @@ void process_next_command() {
7564 7501
         #endif // Z_PROBE_SLED
7565 7502
       #endif // HAS_BED_PROBE
7566 7503
 
7567
-      #ifdef G38_2_3
7568
-	   case 38:  //G38.2 & G38.3
7569
-	     gcode_G38(codenum_float);
7504
+      #if ENABLED(G38_2_3)
7505
+        case 38: // G38.2 & G38.3
7506
+          if (subcode == 2 || subcode == 3)
7507
+            gcode_G38(subcode == 2);
7570 7508
           break;
7571
-	 #endif
7572
- 
7509
+      #endif
7510
+
7573 7511
       case 90: // G90
7574 7512
         relative_mode = false;
7575 7513
         break;
@@ -9078,7 +9016,7 @@ void prepare_move_to_destination() {
9078 9016
    * Morgan SCARA Inverse Kinematics. Results in delta[].
9079 9017
    *
9080 9018
    * See http://forums.reprap.org/read.php?185,283327
9081
-   * 
9019
+   *
9082 9020
    * Maths and first version by QHARLEY.
9083 9021
    * Integrated into Marlin and slightly restructured by Joachim Cerny.
9084 9022
    */

+ 11
- 0
Marlin/SanityCheck.h View File

@@ -852,6 +852,17 @@
852 852
 #endif
853 853
 
854 854
 /**
855
+ * G38 Probe Target
856
+ */
857
+#if ENABLED(G38_2_3)
858
+  #if !HAS_BED_PROBE
859
+    #error "G38_2_3 requires a bed probe."
860
+  #elif !IS_CARTESIAN
861
+    #error "G38_2_3 requires a Cartesian machine."
862
+  #endif
863
+#endif
864
+
865
+/**
855 866
  * Make sure only one display is enabled
856 867
  *
857 868
  * Note: BQ_LCD_SMART_CONTROLLER => REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER

+ 15
- 21
Marlin/endstops.cpp View File

@@ -243,33 +243,27 @@ void Endstops::update() {
243 243
   // COPY_BIT: copy the value of COPY_BIT to BIT in bits
244 244
   #define COPY_BIT(bits, COPY_BIT, BIT) SET_BIT(bits, BIT, TEST(bits, COPY_BIT))
245 245
 
246
- 
247
-#if defined(G38_2_3) && defined(Z_MIN_PIN) && Z_MIN_PIN > -1  // If G38 command then check Z_MIN for every axis and every direction  
248
-  #define UPDATE_ENDSTOP(AXIS,MINMAX) do { \
249
-      UPDATE_ENDSTOP_BIT(AXIS, MINMAX); \
250
-      if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && stepper.current_block->steps[_AXIS(AXIS)] > 0) { \
251
-        _ENDSTOP_HIT(AXIS); \
252
-        stepper.endstop_triggered(_AXIS(AXIS)); \
253
-      } \
254
-      if (G38_flag) {\
255
-        UPDATE_ENDSTOP_BIT(Z, MIN); \
256
-        if (TEST_ENDSTOP(_ENDSTOP(Z, MIN)) && stepper.current_block->steps[_AXIS(AXIS)] > 0) { \
257
-          _ENDSTOP_HIT(AXIS); \
258
-          stepper.endstop_triggered(_AXIS(AXIS)); \
259
-		  G38_flag_pass = true;\
260
-        } \
261
-      } \
262
-    } while(0)
263
-#else	
264
-  #define UPDATE_ENDSTOP(AXIS,MINMAX) do { \
246
+  #define _UPDATE_ENDSTOP(AXIS,MINMAX,CODE) do { \
265 247
       UPDATE_ENDSTOP_BIT(AXIS, MINMAX); \
266 248
       if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && stepper.current_block->steps[_AXIS(AXIS)] > 0) { \
267 249
         _ENDSTOP_HIT(AXIS); \
268 250
         stepper.endstop_triggered(_AXIS(AXIS)); \
251
+        CODE; \
269 252
       } \
270 253
     } while(0)
271
-	
272
-#endif	  		
254
+
255
+  #if ENABLED(G38_2_3) && PIN_EXISTS(Z_MIN)  // If G38 command then check Z_MIN for every axis and every direction  
256
+
257
+    #define UPDATE_ENDSTOP(AXIS,MINMAX) do { \
258
+        _UPDATE_ENDSTOP(AXIS,MINMAX,NOOP); \
259
+        if (G38_move) _UPDATE_ENDSTOP(Z, MIN, G38_endstop_hit = true); \
260
+      } while(0)
261
+
262
+  #else	
263
+
264
+    #define UPDATE_ENDSTOP(AXIS,MINMAX) _UPDATE_ENDSTOP(AXIS,MINMAX,NOOP)
265
+
266
+  #endif
273 267
 
274 268
   #if ENABLED(COREXY) || ENABLED(COREXZ)
275 269
     // Head direction in -X axis for CoreXY and CoreXZ bots.

Loading…
Cancel
Save