//This macro is the inital probing for automatic tool length measuring after M6 calls //It probes at the current location, then moves to the fixed plate location and probes again. //The Z distance between the fixed plate and the mobile plate is stored in the C-axis DRO //----------------------------------------------------------------------------------------------------------------- double FixedPlateX = 50; //Fixed plate X position (machine coordinate) double FixedPlateY = 550; //Fixed plate Y position double PlateThickness = 0; //thickness of the probing plate double SafeZ = -.01; //Safe Z in machine coordinates double ZRetractHeight = 30; //Height above Z0 to which probe will retract double CoarseRate = 200; //Feedrate for initial probing double FineRate = 1; //Feedrate for fine probing double Zmin = -180; //maximum probing distance int PlateThicknessDRO = 20002; // User field label number int FixtureClearDRO = 20005; int FastProbeDRO = 20006; int SlowProbeDRO = 20007; //----------------------------------------------------------------------------------------------------------------- PlateThickness = Convert.ToDouble(AS3.Getfield(PlateThicknessDRO)); CoarseRate = Convert.ToDouble(AS3.Getfield(FastProbeDRO)); FineRate = Convert.ToDouble(AS3.Getfield(SlowProbeDRO)); ZRetractHeight = Convert.ToDouble(AS3.Getfield(FixtureClearDRO)); double CombinedOffset = 0 - (PlateThickness * -1) ; //really for use later when PlateThickness and MaterialOffset are DROs if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58)) // If machine was not homed then it is not smart to do this, stop here... { MessageBox.Show("The machine was not yet homed, home the machine before setting Z-zero"); exec.Stop(); return; } // G91 Sets incremental mode, // G90 Sets absolute distance mode // G53 Sets move in absolute coordinate for that line //int originaldistancemode = exec.actualdistmode; // remember the distance mode //int originalmodalmode = exec.actualmodal; // remember the modal mode exec.Code ("G91"); //sets incremental mode for the whole macro double XOriginalPos = exec.GetXmachpos(); // Get current X double YOriginalPos = exec.GetYmachpos(); // Get current Y double ZOriginalPos = exec.GetZmachpos(); // Get current Z exec.Miston(); //Turn Mist On exec.Code("G31 Z" + Zmin + "F" + CoarseRate); // Probe Z quickly to get rough height while(exec.IsMoving()){} exec.Wait(200); exec.Code ("G00 Z" + .3); // Retract .3" above the plate while(exec.IsMoving()){} exec.Wait(100); exec.Code("G31 Z" + Zmin + "F" + FineRate); // Probe Z slowly for better resolution while(exec.IsMoving()){} exec.Wait(200); double Zzero = exec.GetZmachpos(); //temporary variable with Zzero in machine coordinate exec.mainform.sumoffsetcontrol1.G54.newCzinput(CombinedOffset); // Set G54 to new Zzero exec.mainform.sumoffsetcontrol1.G55.newCzinput(CombinedOffset); // Set G55 to new Zzero exec.mainform.sumoffsetcontrol1.G56.newCzinput(CombinedOffset); // Set G56 to new Zzero exec.mainform.sumoffsetcontrol1.G57.newCzinput(CombinedOffset); // Set G57 to new Zzero exec.mainform.sumoffsetcontrol1.G58.newCzinput(CombinedOffset); // Set G58 to new Zzero exec.mainform.sumoffsetcontrol1.G59.newCzinput(CombinedOffset); // Set G59 to new Zzero exec.Code("G00 Z" + ZRetractHeight); //Retracts Z for move to plate while(exec.IsMoving()){} exec.Wait(1000); exec.Stopcoolant(); // Turn Mist Off exec.Code ("G53 G00 X" + FixedPlateX + " Y" + FixedPlateY); //Move to fixed plate position while (exec.IsMoving ()){} exec.Wait (200); exec.Miston(); //Turn Mist On exec.Code("G31 Z" + Zmin + "F" + CoarseRate); // Probe Z quickly to get rough height while(exec.IsMoving()){} exec.Wait(200); exec.Code ("G00 Z" + .3); // Retract .3" above the plate while(exec.IsMoving()){} exec.Wait(100); exec.Code("G31 Z" + Zmin + "F" + FineRate); // Probe Z slowly for better resolution while(exec.IsMoving()){} exec.Wait(200); exec.Stopcoolant(); // Turn Mist Off double Zcurrent = exec.GetZmachpos(); // Gets the Z-value for the fixed Plate double PlateDifference = Zcurrent - Zzero + CombinedOffset; // calculates the difference between the fixed plate and Zzero exec.mainform.sumoffsetcontrol1.G54.newCcinput(PlateDifference); // writes Plate Difference to axis C DRO for all offsets exec.mainform.sumoffsetcontrol1.G55.newCcinput(PlateDifference); exec.mainform.sumoffsetcontrol1.G56.newCcinput(PlateDifference); exec.mainform.sumoffsetcontrol1.G57.newCcinput(PlateDifference); exec.mainform.sumoffsetcontrol1.G58.newCcinput(PlateDifference); exec.mainform.sumoffsetcontrol1.G59.newCcinput(PlateDifference); exec.Code ("G53 G00 Z" + SafeZ); //Retracts Z to SafeZ while(exec.IsMoving()){} exec.Wait(200); exec.Code ("G90"); //sets back to absolute mode for next move exec.Code ("G53 G00 X" + XOriginalPos + " Y" + YOriginalPos); //Return to original XY position while(exec.IsMoving()){} exec.Wait(200); double SaferZ = ZOriginalPos+ZRetractHeight; exec.Code ("G53 G00 Z" + SaferZ); //Return to original Z position + retrace height just to be safe while(exec.IsMoving()){} exec.Wait(200); //exec.Code("G" + originaldistancemode); // Set system back to the original distance mode //exec.Code("G" + originalmodalmode); // Set system back to the original distance mode