Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

center hole probing script for openbuilds #1266

Open
jeffreyb11 opened this issue Jan 11, 2025 · 0 comments
Open

center hole probing script for openbuilds #1266

jeffreyb11 opened this issue Jan 11, 2025 · 0 comments

Comments

@jeffreyb11
Copy link

i know there is probbebly a ton of awnsers but i realy cant find it.

i found this script somewhere a while back and in general it works fine, but i want to change 1 thing in its routine and i know absolutely nothing about programming or writing scripts,

idealy i want to fast find with 250mm min, pull back 2mm and slow find with 15mm sec for acuracy, then fast find the other side etc..

the script works fine. but i have no idea where to start. anyone able and willing to help me out here?

function findCircleCenter(approxCircleDia, endmillDiameter, probeFeed) {

// var approxCircleDia = 60;
// var endmillDiameter = 2
// var probeFeed = 200;

var step = 0;
var rightside = 0,
leftside = 0,
farside = 0,
nearside = 0,
centerXdistance = 0,
centerYdistance = 0;

socket.off('prbResult'); // Disable old listeners

var holefindermacroStep1 = `
; Header

G21 ; mm mode
G10 P1 L20 X0 Y0 Z0 ; zero out current location

G38.2 X+ approxCircleDia / 2 + F+ probeFeed + ; Probe X` // find right side of circle

socket.emit('runJob', {
data: holefindermacroStep1,
isJob: false,
completedMsg: false,
fileName: ""
});

socket.on('prbResult', function(prbdata) {
if (prbdata.state > 0) {
step++;
console.log("Step " + step, prbdata);

  // Steps 1-3 just positions endmill for probes that count

  if (step == 1) {
    rightside = prbdata.x
    console.log(rightside);

    var holefindermacroStep5 = `
    G4 P0.3
    G91
    G0 X-1
    G90
    G38.2 X-` + approxCircleDia / 2 + ` F` + probeFeed + ` ; Probe X` // find left side of circle

    socket.emit('runJob', {
      data: holefindermacroStep5,
      isJob: false,
      completedMsg: false,
      fileName: ""
    });
  }

  if (step == 2) {
    leftside = prbdata.x
    var centerdistance = (rightside - leftside);
    var holefindermacroStep6 = `
    G4 P0.3
    G91
    G0 X` + centerdistance / 2 + `
    G90
    G10 P1 L20 X0
    G38.2 Y` + approxCircleDia / 2 + ` F` + probeFeed + ` ; Probe Y` // find far side of circle

    socket.emit('runJob', {
      data: holefindermacroStep6,
      isJob: false,
      completedMsg: false,
      fileName: ""
    });
  }

  if (step == 3) {
    farside = prbdata.y

    var holefindermacroStep7 = `
    G4 P0.3
    G91
    G0 Y-1
    G90
    G38.2 Y-` + approxCircleDia / 2 + ` F` + probeFeed + ` ; Probe Y` // find near side of circle

    socket.emit('runJob', {
      data: holefindermacroStep7,
      isJob: false,
      completedMsg: false,
      fileName: ""
    });
  }

  if (step == 4) {
    nearside = prbdata.y
    centerYdistance = (farside - nearside);
    centerXdistance = (rightside - leftside);
    console.log(centerXdistance, centerYdistance)
    var holefindermacroStep7 = `
    G4 P0.3
    G91
    G0 Y` + centerYdistance / 2 + `
    G90
    G10 P1 L20 Y0
    `

    socket.emit('runJob', {
      data: holefindermacroStep7,
      isJob: false,
      completedMsg: `Probe Complete: Remove the Probe Clip and Probe GND before continuing... <hr>
      Probed dimension X: ` + (centerXdistance + endmillDiameter).toFixed(3) + `<br>
      Probed dimension Y: ` + (centerYdistance + endmillDiameter).toFixed(3) + `<br>
      <hr>`,
      fileName: ""
    });
  }

} else {
  console.log("Probe Failed")
}

})
}

Metro.dialog.create({
title: "Center Finding Macro",
content: `


Maximum Distance between edges



<small>This is the approximate diameter of the circle, or the maximum width between edges of the rectangular/square hole you are probing inside</small>
<hr>
<div class="row mb-0">
  <label class="cell-sm-6">Endmill Diameter</label>
  <div class="cell-sm-6">
      <input id="centerProbeEndmill" type="number" value="2" data-role="input" data-append="mm" data-prepend="<i class='fas fa-arrows-alt-h'></i>" data-clear-button="false">
  </div>
</div>
<small>Enter the Endmill Diameter</small>
<hr>
<div class="row mb-0">
  <label class="cell-sm-6">Probe Feedrate</label>
  <div class="cell-sm-6">
      <input id="centerProbeFeedrate" type="number" value="100" data-role="input" data-append="mm/min" data-prepend="<i class='fas fa-running'></i>" data-clear-button="false">
  </div>
</div>
<small>How fast the probe will move - slower is safer/more accurate</small>
`,

actions: [{
caption: "Run center finding Probe",
cls: "js-dialog-close success",
onclick: function() {
var approxCircleDia = parseFloat($("#centerProbeDistance").val())
var endmillDiameter = parseFloat($("#centerProbeEndmill").val())
var probeFeed = parseInt($("#centerProbeFeedrate").val())
findCircleCenter(approxCircleDia, endmillDiameter, probeFeed)
}
},
{
caption: "Cancel",
cls: "js-dialog-close alert",
onclick: function() {
//
}
}
]
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant