generated from github/codespaces-blank
/
ManualPlacementProbing.py
61 lines (44 loc) · 2.14 KB
/
ManualPlacementProbing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Disclaimer: The provided code is open-source and free to use, modify, and distribute.
# The author shall not be held responsible for any injury, damage, or loss resulting from the use of this code.
# By using this code, you agree to assume all responsibility and risk associated with the use of the code.
# author Erwan Le Foll 11/11/2023
# created for dylan https://en.cs-lab.eu/forum/topic/help-with-a-tool-length-macro/
# replace the code in your probing.py by this one
import sys
# Get the tool number
current_tool = d.getSpindleToolNumber()
# Retrieve the machine's position and name it "position".
position = d.getPosition(CoordMode.Machine)
#MODIFY HERE WHAT NEEDED
probeIndex = 0 #see in simcnc what number is your prob 0 1 2 or 3
speed_down = 200
speed_up = 800
refToolProbePos = -100 #Height at which your reference tool touches the probe (if your reference tool touches at Z-100mm and you indicate - 100mm here, then it will be referenced to 0mm)
go_down = 3 # go down for 3mm , if no prob touch during those 3 mm dissent it stop moving
#-----------------------------------------------------------
# Start moving
#-----------------------------------------------------------
print(f"------------------\n Tool {current_tool} Launching the measurement process .\n------------------")
# Start measuring
position[Axis.Z.value] -= go_down
probeResult = d.executeProbing(CoordMode.Machine, position, probeIndex, speed_down)
if(probeResult == False):
sys.exit((" probing failed!"))
# récupère la mesure lente
probeFinishPos = d.getProbingPosition(CoordMode.Machine)
# Calculate the tool offset
new_tool_length = probeFinishPos[Axis.Z.value] - refToolProbePos
# Print in console
print(f"Tool Z offset({current_tool}): {new_tool_length:.4f}")
# Export new tool info to simcnc
d.setToolLength(current_tool, new_tool_length)
d.setToolOffsetNumber(current_tool)
d.setSpindleToolNumber(current_tool)
# Z to 0
position[Axis.Z.value] = 0
d.moveToPosition(CoordMode.Machine, position, speed_up)
# Print in console
print("End")
#-----------------------------------------------------------
# End script probing
#-----------------------------------------------------------