Advertisement
tlse72

M31

May 29th, 2023 (edited)
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //M31 probing macro
  2.  
  3. double probeX = 200;
  4. double probeY = 300;
  5. double Zmin = -100;
  6. double FeedrateFast = 1000;
  7. double FeedrateSlow = 100;
  8. double SafeZ = 100;
  9. double retractheight = 5;
  10. double retractforsecondmeasurement = 5;
  11. double offsetGivareZ = -2.0;
  12.  
  13. bool domoveXY = false; //Enable XY movement
  14. bool dodualcycle = true; //Do probing from 2 cycles, first with Fast and second with Slow feedrates
  15.  
  16. if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58)) // If machine was not homed then it is unsafe to move in machine coordinates, stop here...
  17. {
  18.   MessageBox.Show("The machine was not yet homed, home the machine before run to parking position!");
  19.   exec.Stop();
  20.   return;
  21. }
  22.  
  23. while(exec.IsMoving()){}
  24.  
  25. double Xoriginalpos = exec.GetXmachpos(); // Get the current machine coordinates
  26. double Yoriginalpos = exec.GetYmachpos(); // Get the current machine coordinates
  27.  
  28. if(domoveXY) // Make XY movement only if enabled
  29. {
  30.   exec.Code("G80 G00 G53 Z" + SafeZ); // Move Z up first
  31.   while(exec.IsMoving()){}
  32.  
  33.   exec.Code("G80 G00 G53 X" + probeX +" Y" + probeY); // Move to the probe sensor position in XY
  34.   while(exec.IsMoving()){}
  35. }
  36.  
  37. if(dodualcycle)
  38. {
  39.   exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first
  40.   while(exec.IsMoving()){}
  41.  
  42.   exec.Code("G91 G80 G0 Z" + retractforsecondmeasurement);
  43.   exec.Code("G90");
  44. }
  45.  
  46. while(exec.IsMoving()){}
  47. exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading
  48. while(exec.IsMoving()){}
  49.  
  50. if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate new tool number
  51. {
  52.  exec.mainform.sumoffsetcontrol1.G54.newCzinput(offsetGivareZ);  // Set G54 to new Zzero
  53.     exec.mainform.sumoffsetcontrol1.G55.newCzinput(offsetGivareZ);  // Set G55 to new Zzero
  54.     exec.mainform.sumoffsetcontrol1.G56.newCzinput(offsetGivareZ);  // Set G56 to new Zzero
  55.     exec.mainform.sumoffsetcontrol1.G57.newCzinput(offsetGivareZ);  // Set G57 to new Zzero
  56.     exec.mainform.sumoffsetcontrol1.G58.newCzinput(offsetGivareZ);  // Set G58 to new Zzero
  57.     exec.mainform.sumoffsetcontrol1.G59.newCzinput(offsetGivareZ);  // Set G59 to new Zzero
  58.     while(exec.IsMoving()){}
  59.     exec.Wait(200);
  60.  
  61.  //double Zup = exec.GetZmachpos() + retractheight;
  62.  
  63.  //if(Zup > SafeZ)
  64.  //{
  65.  //  Zup = SafeZ;
  66.  //}
  67.  
  68.  exec.Code("G80 G00 G54 Z" + retractheight); // Move 10mm above probe plate
  69.  while(exec.IsMoving()){}
  70.  
  71. if(domoveXY) // Make XY movement back to start position only if XY movement is enabled
  72. {
  73.   exec.Code("G80 G00 G53 X" + Xoriginalpos +" Y" + Yoriginalpos); // Move back to the original XY position
  74.   while(exec.IsMoving()){}
  75. }
  76.  
  77. }
  78.  
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement