Browse Source

CAB: Added code for Z-probe with Z endstop mounted on a sled.

Charles Bell 11 years ago
parent
commit
d2fcb3ee56
1 changed files with 66 additions and 7 deletions
  1. 66
    7
      Marlin/Marlin_main.cpp

+ 66
- 7
Marlin/Marlin_main.cpp View File

78
 // G28 - Home all Axis
78
 // G28 - Home all Axis
79
 // G29 - Detailed Z-Probe, probes the bed at 3 or more points.  Will fail if you haven't homed yet.
79
 // G29 - Detailed Z-Probe, probes the bed at 3 or more points.  Will fail if you haven't homed yet.
80
 // G30 - Single Z Probe, probes bed at current XY location.
80
 // G30 - Single Z Probe, probes bed at current XY location.
81
+// G31 - Dock sled (Z_PROBE_SLED only)
82
+// G32 - Undock sled (Z_PROBE_SLED only)
81
 // G90 - Use Absolute Coordinates
83
 // G90 - Use Absolute Coordinates
82
 // G91 - Use Relative Coordinates
84
 // G91 - Use Relative Coordinates
83
 // G92 - Set current position to coordinates given
85
 // G92 - Set current position to coordinates given
548
   #ifdef DIGIPOT_I2C
550
   #ifdef DIGIPOT_I2C
549
     digipot_i2c_init();
551
     digipot_i2c_init();
550
   #endif
552
   #endif
553
+#ifdef Z_PROBE_SLED
554
+  pinMode(SERVO0_PIN, OUTPUT);
555
+  digitalWrite(SERVO0_PIN, LOW); // turn it off
556
+#endif // Z_PROBE_SLED
551
 }
557
 }
552
 
558
 
553
 
559
 
1035
   do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before);
1041
   do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], z_before);
1036
   do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
1042
   do_blocking_move_to(x - X_PROBE_OFFSET_FROM_EXTRUDER, y - Y_PROBE_OFFSET_FROM_EXTRUDER, current_position[Z_AXIS]);
1037
 
1043
 
1044
+#ifndef Z_PROBE_SLED
1038
   engage_z_probe();   // Engage Z Servo endstop if available
1045
   engage_z_probe();   // Engage Z Servo endstop if available
1046
+#endif // Z_PROBE_SLED
1039
   run_z_probe();
1047
   run_z_probe();
1040
   float measured_z = current_position[Z_AXIS];
1048
   float measured_z = current_position[Z_AXIS];
1049
+#ifndef Z_PROBE_SLED
1041
   retract_z_probe();
1050
   retract_z_probe();
1051
+#endif // Z_PROBE_SLED
1042
 
1052
 
1043
   SERIAL_PROTOCOLPGM(MSG_BED);
1053
   SERIAL_PROTOCOLPGM(MSG_BED);
1044
   SERIAL_PROTOCOLPGM(" x: ");
1054
   SERIAL_PROTOCOLPGM(" x: ");
1071
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1081
     plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1072
 
1082
 
1073
 
1083
 
1084
+#ifndef Z_PROBE_SLED
1074
     // Engage Servo endstop if enabled
1085
     // Engage Servo endstop if enabled
1075
     #ifdef SERVO_ENDSTOPS
1086
     #ifdef SERVO_ENDSTOPS
1076
       #if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
1087
       #if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
1083
         servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
1094
         servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
1084
       }
1095
       }
1085
     #endif
1096
     #endif
1086
-
1097
+#endif // Z_PROBE_SLED
1087
     destination[axis] = 1.5 * max_length(axis) * axis_home_dir;
1098
     destination[axis] = 1.5 * max_length(axis) * axis_home_dir;
1088
     feedrate = homing_feedrate[axis];
1099
     feedrate = homing_feedrate[axis];
1089
     plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
1100
     plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder);
1125
       }
1136
       }
1126
     #endif
1137
     #endif
1127
 #if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
1138
 #if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
1128
-    if (axis==Z_AXIS) retract_z_probe();
1139
+//    if (axis==Z_AXIS) retract_z_probe();
1129
 #endif
1140
 #endif
1130
 
1141
 
1131
   }
1142
   }
1180
   } //retract
1191
   } //retract
1181
 #endif //FWRETRACT
1192
 #endif //FWRETRACT
1182
 
1193
 
1194
+#ifdef ENABLE_AUTO_BED_LEVELING
1195
+//
1196
+// Method to dock/undock a sled designed by Charles Bell.
1197
+//
1198
+// dock[in]     If true, move to MAX_X and engage the electromagnet
1199
+// offset[in]   The additional distance to move to adjust docking location
1200
+//
1201
+static void dock_sled(bool dock, int offset=0) {
1202
+ int z_loc;
1203
+ 
1204
+ if (!((axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]))) {
1205
+   LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
1206
+   SERIAL_ECHO_START;
1207
+   SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
1208
+   return;
1209
+ }
1210
+
1211
+ if (dock) {
1212
+   do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset,
1213
+                       current_position[Y_AXIS],
1214
+                       current_position[Z_AXIS]);
1215
+   // turn off magnet
1216
+   digitalWrite(SERVO0_PIN, LOW);
1217
+ } else {
1218
+   if (current_position[Z_AXIS] < (Z_RAISE_BEFORE_PROBING + 5))
1219
+     z_loc = Z_RAISE_BEFORE_PROBING;
1220
+   else
1221
+     z_loc = current_position[Z_AXIS];
1222
+   do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset,
1223
+                       Y_PROBE_OFFSET_FROM_EXTRUDER, z_loc);
1224
+   // turn on magnet
1225
+   digitalWrite(SERVO0_PIN, HIGH);
1226
+ }
1227
+}
1228
+#endif
1229
+
1183
 void process_commands()
1230
 void process_commands()
1184
 {
1231
 {
1185
   unsigned long codenum; //throw away variable
1232
   unsigned long codenum; //throw away variable
1490
                 break; // abort G29, since we don't know where we are
1537
                 break; // abort G29, since we don't know where we are
1491
             }
1538
             }
1492
 
1539
 
1540
+#ifdef Z_PROBE_SLED
1541
+            dock_sled(false);
1542
+#endif // Z_PROBE_SLED
1493
             st_synchronize();
1543
             st_synchronize();
1494
             // make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly
1544
             // make sure the bed_level_rotation_matrix is identity or the planner will get it incorectly
1495
             //vector_3 corrected_position = plan_get_position_mm();
1545
             //vector_3 corrected_position = plan_get_position_mm();
1615
             apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp);         //Apply the correction sending the probe offset
1665
             apply_rotation_xyz(plan_bed_level_matrix, x_tmp, y_tmp, z_tmp);         //Apply the correction sending the probe offset
1616
             current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS];   //The difference is added to current position and sent to planner.
1666
             current_position[Z_AXIS] = z_tmp - real_z + current_position[Z_AXIS];   //The difference is added to current position and sent to planner.
1617
             plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1667
             plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1668
+#ifdef Z_PROBE_SLED
1669
+            dock_sled(true, -SLED_DOCKING_OFFSET); // correct for over travel.
1670
+#endif // Z_PROBE_SLED
1618
         }
1671
         }
1619
         break;
1672
         break;
1620
-
1673
+#ifndef Z_PROBE_SLED
1621
     case 30: // G30 Single Z Probe
1674
     case 30: // G30 Single Z Probe
1622
         {
1675
         {
1623
             engage_z_probe(); // Engage Z Servo endstop if available
1676
             engage_z_probe(); // Engage Z Servo endstop if available
1624
-
1625
             st_synchronize();
1677
             st_synchronize();
1626
             // TODO: make sure the bed_level_rotation_matrix is identity or the planner will get set incorectly
1678
             // TODO: make sure the bed_level_rotation_matrix is identity or the planner will get set incorectly
1627
             setup_for_endstop_move();
1679
             setup_for_endstop_move();
1639
             SERIAL_PROTOCOLPGM("\n");
1691
             SERIAL_PROTOCOLPGM("\n");
1640
 
1692
 
1641
             clean_up_after_endstop_move();
1693
             clean_up_after_endstop_move();
1642
-
1643
             retract_z_probe(); // Retract Z Servo endstop if available
1694
             retract_z_probe(); // Retract Z Servo endstop if available
1644
         }
1695
         }
1645
         break;
1696
         break;
1697
+#else
1698
+    case 31: // dock the sled
1699
+        dock_sled(true);
1700
+        break;
1701
+    case 32: // undock the sled
1702
+        dock_sled(false);
1703
+        break;
1704
+#endif // Z_PROBE_SLED
1646
 #endif // ENABLE_AUTO_BED_LEVELING
1705
 #endif // ENABLE_AUTO_BED_LEVELING
1647
     case 90: // G90
1706
     case 90: // G90
1648
       relative_mode = false;
1707
       relative_mode = false;
1982
 
2041
 
1983
       /* See if we are heating up or cooling down */
2042
       /* See if we are heating up or cooling down */
1984
       target_direction = isHeatingHotend(tmp_extruder); // true if heating, false if cooling
2043
       target_direction = isHeatingHotend(tmp_extruder); // true if heating, false if cooling
1985
-      
2044
+
1986
       cancel_heatup = false;
2045
       cancel_heatup = false;
1987
 
2046
 
1988
       #ifdef TEMP_RESIDENCY_TIME
2047
       #ifdef TEMP_RESIDENCY_TIME
2758
       st_synchronize();
2817
       st_synchronize();
2759
     }
2818
     }
2760
     break;
2819
     break;
2761
-#if defined(ENABLE_AUTO_BED_LEVELING) && defined(SERVO_ENDSTOPS)
2820
+#if defined(ENABLE_AUTO_BED_LEVELING) && defined(SERVO_ENDSTOPS) && not defined(Z_PROBE_SLED)
2762
     case 401:
2821
     case 401:
2763
     {
2822
     {
2764
         engage_z_probe();    // Engage Z Servo endstop if available
2823
         engage_z_probe();    // Engage Z Servo endstop if available

Loading…
Cancel
Save