Problem: When my probe comes into contact with the tool setter, the tool setter triggers first, but then the probe suddenly moves downward.
Wiki Search Terms
probe
Controller Board
6-pack
Machine Description
Input Circuits
Configuration file
board: 6x CNC Controller
name: 6x Default
stepping:
engine: I2S_STREAM
idle_ms: 255
pulse_us: 4
dir_delay_us: 4
disable_delay_us: 0
axes:
shared_stepper_disable_pin: NO_PIN
x:
steps_per_mm: 800.000
max_rate_mm_per_min: 3000.000
acceleration_mm_per_sec2: 500.000
max_travel_mm: 184.000
soft_limits: false
homing:
cycle: 2
positive_direction: false
mpos_mm: 0.000
feed_mm_per_min: 100.000
seek_mm_per_min: 800.000
settle_ms: 500
seek_scaler: 1.100
feed_scaler: 1.100
motor0:
limit_neg_pin: gpio.2:low:pu
limit_pos_pin: NO_PIN
limit_all_pin: NO_PIN
hard_limits: false
pulloff_mm: 1.000
standard_stepper:
step_pin: I2SO.2
direction_pin: I2SO.1
disable_pin: I2SO.0
y:
steps_per_mm: 1600.000
max_rate_mm_per_min: 3000.000
acceleration_mm_per_sec2: 500.000
max_travel_mm: 142.000
soft_limits: false
homing:
cycle: 2
positive_direction: false
mpos_mm: 0.000
feed_mm_per_min: 100.000
seek_mm_per_min: 800.000
settle_ms: 500
seek_scaler: 1.100
feed_scaler: 1.100
motor0:
limit_neg_pin: gpio.26:low:pu
limit_pos_pin: NO_PIN
limit_all_pin: NO_PIN
hard_limits: false
pulloff_mm: 1.000
standard_stepper:
step_pin: I2SO.5
direction_pin: I2SO.4:high
disable_pin: I2SO.7
z:
steps_per_mm: 800.000
max_rate_mm_per_min: 3000.000
acceleration_mm_per_sec2: 500.000
max_travel_mm: 130.000
soft_limits: false
homing:
cycle: 1
positive_direction: true
mpos_mm: 0.000
feed_mm_per_min: 100.000
seek_mm_per_min: 800.000
settle_ms: 500
seek_scaler: 1.100
feed_scaler: 1.100
motor0:
limit_neg_pin: gpio.33:low
limit_pos_pin: NO_PIN
limit_all_pin: NO_PIN
hard_limits: false
pulloff_mm: 1.000
standard_stepper:
step_pin: I2SO.10
direction_pin: I2SO.9:low
disable_pin: I2SO.8
# a:
# steps_per_mm: 53.400
# max_rate_mm_per_min: 5000.000
# acceleration_mm_per_sec2: 100.000
# max_travel_mm: 960.000
# soft_limits: false
# homing:
# cycle: 2
# positive_direction: false
# mpos_mm: 150.000
# feed_mm_per_min: 100.000
# seek_mm_per_min: 200.000
# settle_ms: 500
# seek_scaler: 1.100
# feed_scaler: 1.100
# motor0:
# limit_neg_pin: gpio.32:low
# limit_pos_pin: NO_PIN
# limit_all_pin: NO_PIN
# hard_limits: false
# pulloff_mm: 3.000
# standard_stepper:
# step_pin: I2SO.13
# direction_pin: I2SO.12
# disable_pin: I2SO.15
# b:
# steps_per_mm: 808.000
# max_rate_mm_per_min: 5000.000
# acceleration_mm_per_sec2: 100.000
# max_travel_mm: 200.000
# soft_limits: false
# homing:
# cycle: 1
# positive_direction: false
# mpos_mm: 150.000
# feed_mm_per_min: 100.000
# seek_mm_per_min: 800.000
# settle_ms: 500
# seek_scaler: 1.100
# feed_scaler: 1.100
# motor0:
# limit_neg_pin: gpio.35:low
# limit_pos_pin: NO_PIN
# limit_all_pin: NO_PIN
# hard_limits: false
# pulloff_mm: 3.000
# standard_stepper:
# step_pin: I2SO.18
# direction_pin: I2SO.17
# disable_pin: I2SO.16
# c:
# steps_per_mm: 808.000
# max_rate_mm_per_min: 5000.000
# acceleration_mm_per_sec2: 100.000
# max_travel_mm: 200.000
# soft_limits: false
# homing:
# cycle: 1
# positive_direction: false
# mpos_mm: 150.000
# feed_mm_per_min: 100.000
# seek_mm_per_min: 800.000
# settle_ms: 500
# seek_scaler: 1.100
# feed_scaler: 1.100
# motor0:
# limit_neg_pin: gpio.34:low
# limit_pos_pin: NO_PIN
# limit_all_pin: NO_PIN
# hard_limits: false
# pulloff_mm: 3.000
# standard_stepper:
# step_pin: I2SO.21
# direction_pin: I2SO.20
# disable_pin: I2SO.23
i2so:
bck_pin: gpio.22
data_pin: gpio.21
ws_pin: gpio.17
spi:
miso_pin: gpio.19
mosi_pin: gpio.23
sck_pin: gpio.18
sdcard:
card_detect_pin: NO_PIN
cs_pin: gpio.5
probe:
pin: gpio.32
toolsetter_pin: gpio.35
# Using MOSFETs (Check Spindle Pin Usage
coolant:
flood_pin: gpio.12
mist_pin: gpio.4
delay_ms: 0
start:
must_home: false
uart1:
txd_pin: gpio.25
rxd_pin: gpio.27
rts_pin: NO_PIN
cts_pin: NO_PIN
baud: 1000000
mode: 8N1
uart_channel1:
report_interval_ms: 75
uart_num: 1
## Begin Huanyang
# uart1:
# txd_pin: gpio.15
# rxd_pin: gpio.16
# rts_pin: gpio.14
# baud: 9600
# mode: 8N1
# Huanyang:
# uart_num: 1
# modbus_id: 1
# tool_num: 0
# speed_map: 0=0% 0=25% 6000=25% 24000=100%
# off_on_alarm: false
# #begin PWM
# pwm:
# pwm_hz: 5000
# direction_pin: gpio.15
# output_pin: gpio.13
# enable_pin: gpio.14
# disable_with_s0: false
# s0_with_disable: true
# spinup_ms: 0
# spindown_ms: 0
# tool_num: 0
# speed_map: 0=0.000% 10000=100.000%
# off_on_alarm: false
# #begin Laser
# Laser:
# pwm_hz: 5000
# output_pin: gpio.4
# enable_pin: gpio.12
# disable_with_s0: false
# s0_with_disable: true
# tool_num: 1
# speed_map: 0=0.000% 255=100.000%
# off_on_alarm: true
# #begin 10V
10V:
forward_pin: gpio.15
reverse_pin: gpio.14
pwm_hz: 5000
output_pin: gpio.13
enable_pin: NO_PIN
direction_pin: NO_PIN
disable_with_s0: false
s0_with_disable: true
spinup_ms: 0
spindown_ms: 0
tool_num: 0
speed_map: 0=0.000% 24000=100.000%
off_on_alarm: false
atc: atc_manual
atc_manual:
safe_z_mpos_mm: -1.000000
probe_seek_rate_mm_per_min: 200.000000
probe_feed_rate_mm_per_min: 50.000000
change_mpos_mm: 90.000 2.000 -1.000
ets_mpos_mm: 182.300 44.600 -63.20
ets_rapid_z_mpos_mm: -1.000000
Startup Messages
22:44:20] [ M61Q1 ] [MSG:INFO: 10V spindle changed to tool:1 using atc_manual]
[22:44:20] [ M61Q1 ] ok
[22:44:38] Centre finding probe cycle in progress
[22:44:38] [ G91 ] ok
[22:44:38] [ $G ] [GC:G0 G54 G17 G21 G91 G94 M5 M9 T1 F0 S0]
[22:44:38] [ $G ] ok
[22:44:38] [ G21 ] ok
[22:44:38] [ $G ] [GC:G0 G54 G17 G21 G91 G94 M5 M9 T1 F0 S0]
[22:44:38] [ $G ] ok
[22:44:38] [ G10 P0 L20 X0 ] ok
[22:44:38] [ G0 X-62.000 ] ok
[22:44:38] [ G1 Z-10 F400 ] ok
[22:44:43] [ [ PROBE ] ] Probe Completed.
[22:44:43] [ G38.2 X62.000 F200 ] [PRB:44.572,82.000,-56.000:1]
[22:44:43] [ G38.2 X62.000 F200 ] ok
[22:44:43] [ G4 P0.3 ] ok
[22:44:43] [ G0 X-3 ] ok
[22:44:46] [ [ PROBE ] ] Probe Completed.
[22:44:46] [ G38.2 X62.000 F80 ] [PRB:44.643,82.000,-56.000:1]
[22:44:46] [ G38.2 X62.000 F80 ] ok
[22:44:46] [ G4 P0.3 ] ok
[22:44:46] [ G0 X-3 ] ok
[22:44:46] [ G0 Z10 ] ok
[22:44:46] [ G90 ] ok
[22:44:46] [ $G ] [GC:G0 G54 G17 G21 G90 G94 M5 M9 T1 F80 S0]
[22:44:46] [ $G ] ok
[22:44:46] [ G0 X62.000 ] ok
[22:44:46] [ G91 ] ok
[22:44:46] [ $G ] [GC:G0 G54 G17 G21 G91 G94 M5 M9 T1 F80 S0]
[22:44:46] [ $G ] ok
[22:44:46] [ G1 Z -10 F400 ] ok
[22:44:54] [ [ PROBE ] ] Probe Completed.
[22:44:54] [ G38.2 X-62.000 F200 ] [PRB:147.290,82.000,-56.000:1]
[22:44:54] [ G38.2 X-62.000 F200 ] ok
[22:44:54] [ G4 P0.3 ] ok
[22:44:54] [ G0 X3 ] ok
[22:44:57] [ [ PROBE ] ] Probe Completed.
[22:44:57] [ G38.2 X-62.000 F80 ] [PRB:147.268,82.000,-56.000:1]
[22:44:57] [ G38.2 X-62.000 F80 ] ok
[22:44:57] [ G4 P0.3 ] ok
[22:44:57] [ G0 X3 ] ok
[22:44:57] [ G0 Z10 ] ok
[22:44:57] [ G53 G0 X95.9555 ] ok
[22:44:59] [ G10 P0 L20 X0 ] ok
[22:44:59] [ G91 ] ok
[22:44:59] [ $G ] [GC:G0 G54 G17 G21 G91 G94 M5 M9 T1 F80 S0]
[22:44:59] [ $G ] ok
[22:44:59] [ G21 ] ok
[22:44:59] [ $G ] [GC:G0 G54 G17 G21 G91 G94 M5 M9 T1 F80 S0]
[22:44:59] [ $G ] ok
[22:44:59] [ G10 P0 L20 Y0 ] ok
[22:44:59] [ G0 Y-62.000 ] ok
[22:44:59] [ G1 Z -10 F400 ] ok
[22:45:11] [ [ PROBE ] ] Probe Completed.
[22:45:11] [ G38.2 Y62.000 F200 ] [PRB:95.955,52.594,-56.000:1]
[22:45:11] [ G38.2 Y62.000 F200 ] ok
[22:45:11] [ G4 P0.3 ] ok
[22:45:11] [ G0 Y-3 ] ok
[22:45:14] [ [ PROBE ] ] Probe Completed.
[22:45:14] [ G38.2 Y62.000 F80 ] [PRB:95.955,52.667,-56.000:1]
[22:45:14] [ G38.2 Y62.000 F80 ] ok
[22:45:14] [ G4 P0.3 ] ok
[22:45:14] [ G0 Y-3 ] ok
[22:45:14] [ G0 Z10 ] ok
[22:45:14] [ G90 ] ok
[22:45:14] [ $G ] [GC:G0 G54 G17 G21 G90 G94 M5 M9 T1 F80 S0]
[22:45:14] [ $G ] ok
[22:45:14] [ G0 Y62.000 ] ok
[22:45:14] [ G91 ] ok
[22:45:14] [ $G ] [GC:G0 G54 G17 G21 G91 G94 M5 M9 T1 F80 S0]
[22:45:14] [ $G ] ok
[22:45:14] [ G1 Z -10 F400 ] ok
[22:45:27] [ [ PROBE ] ] Probe Completed.
[22:45:27] [ G38.2 Y-62.000 F200 ] [PRB:95.955,114.137,-56.000:1]
[22:45:27] [ G38.2 Y-62.000 F200 ] ok
[22:45:27] [ G4 P0.3 ] ok
[22:45:27] [ G0 Y3 ] ok
[22:45:29] [ [ PROBE ] ] Probe Completed.
[22:45:29] Probing Cycle Complete X measurement 100.625 mm Y Measurement 59.487 mm
[22:45:29] [ G38.2 Y-62.000 F80 ] [PRB:95.955,114.154,-56.000:1]
[22:45:29] [ G38.2 Y-62.000 F80 ] ok
[22:45:30] [ G4 P0.3 ] ok
[22:45:30] [ G0 Y3 ] ok
[22:45:30] [ G0 Z10 ] ok
[22:45:30] [ G53 G0 Y83.4105 ] ok
[22:45:31] [ G10 P0 L20 Y0 ] ok
[22:45:31] [ G21 ] ok
[22:45:31] [ $G ] [GC:G0 G54 G17 G21 G91 G94 M5 M9 T1 F80 S0]
[22:45:31] [ $G ] ok
[22:45:31] [ G90 ] ok
[22:45:31] [ $G ] [GC:G0 G54 G17 G21 G90 G94 M5 M9 T1 F80 S0]
[22:45:31] [ $G ] ok
[22:45:36] [ G21 ] ok
[22:45:36] [ $G ] [GC:G0 G54 G17 G21 G90 G94 M5 M9 T1 F80 S0]
[22:45:36] [ $G ] ok
[22:45:36] [ G91 ] ok
[22:45:36] [ $G ] [GC:G0 G54 G17 G21 G91 G94 M5 M9 T1 F80 S0]
[22:45:36] [ $G ] ok
[22:45:37] [ [ PROBE ] ] Probe Completed.
[22:45:37] [ G38.2 Z-10 F160 ] [PRB:95.955,83.411,-49.965:1]
[22:45:37] [ G38.2 Z-10 F160 ] ok
[22:45:37] [ G0 Z2 ] ok
[22:45:42] [ [ PROBE ] ] Probe Completed.
[22:45:42] [ G38.2 Z-10 F20 ] [PRB:95.955,83.411,-49.936:1]
[22:45:42] [ G38.2 Z-10 F20 ] ok
[22:45:42] [ G10 L20 P0 Z0 ] ok
[22:45:42] [ G91 G0 Z5 ] ok
[22:45:42] [ $G ] [GC:G0 G54 G17 G21 G91 G94 M5 M9 T1 F20 S0]
[22:45:42] [ $G ] ok
[22:45:54] [ M6T2 ] [MSG:INFO: Sel:2 Cur:1]
[22:45:54] [ M6T2 ] [MSG:INFO: 10V spindle changed to tool:2 using atc_manual]
[22:45:54] [ M6T2 ] ok
[22:46:15] [ [ PROBE ] ] Probe Completed.
[22:46:15] [ $G ] [PRB:182.300,44.600,-63.560:1]
[22:46:16] [ $G ] [MSG:INFO: ALARM: Probe Fail Initial]
[22:46:16] [ ALARM ] ALARM: 4 - Probe fail. The probe is not in the expected initial state before starting probe cycle, where G38.2 and G38.3 is not triggered and G38.4 and G38.5 is triggered. [ $G ]
[22:46:16] [ ] ALARM: 4 - Probe fail. The probe is not in the expected initial state before starting probe cycle, where G38.2 and G38.3 is not triggered and G38.4 and G38.5 is triggered. [ $G ]
[22:46:16] [ $G ] ALARM:4
[22:46:16] [ $G ] [GC:G38.2 G54 G17 G21 G91 G94 M5 M9 T2 F50 S0]
[22:46:16] [ $G ] ok
[22:46:26] [ [clear alarm] ] Operator clicked Clear Alarm: Cleared Lockout and Emptied Queue
[22:46:26] [ ] Grbl 3.9 [FluidNC v3.9.6 (wifi) '$' for help]
[22:46:26] [ ] [MSG:INFO: Caution: Unlocked]
[22:46:26] [ ] ok
User Interface Software
No response
What happened?
all home->M61Q1->Search for object shape macro program->Z0macro->M6t2->When my probe comes into contact with the tool setter, the tool setter triggers first, but then the probe suddenly moves downward
GCode File
No response
Other Information
No response
I am not sure what is happening. I was hoping you would do everything manually and not use a gcode sender's automated probing. It is hard to see what it is doing.
Let me try to set up a similar machine. I will will test it again and then send you a procedure to do manually at a FluidTerm or Web Installer console.
When testing I usually manually trigger switches before machine contact to protect the switches and probes. I have never used dual probes, because my probes do not activate in the correct order. It will probably still work, but not be accurate.
It will take a while to set everything up.
Possible place this is happening:
_macro.addf("G53 G38.2 Z%0.3f F%0.3f", _ets_mpos[2], _probe_seek_rate);
_macro.addf("G0Z[#<_z> + 5]"); // retract befor next probe
That G0 is in work coordinates. Could the coordinate offset be changing?
Perhaps this is the downward move
_macro.addf("G53G0Z #</ atc_manual / ets_rapid_z_mpos_mm>"); // rapid down
If so, the "not homed" hypothesis is in play.
The sender log above shows the commands from the sender, but not the ones from the auto-generated atc_manual macro. I think that $GCode/Echo=On would show both.
Here is my run with $Gcode/Echo=on.
Grbl 3.9 [FluidNC v3.9.8 (wifi) '$' for help]
[MSG:INFO: ALARM: Unhomed]
ALARM:14
$H
[echo: $H]
[MSG:Homed:Z]
[MSG:Homed:XY]
ok
$localfs/run=atc_demo.gcode
[echo: $localfs/run=atc_demo.gcode]
ok
[echo: G0 X0 Y0]
[echo: G53 G0 Z-20]
[echo: G38.2 Z-50 F150 P0]
[PRB:55.000,110.000,-27.440:1]
[MSG:INFO: Probe offset applied:]
[echo: G53 G0 Z-1]
[echo: M61Q1]
[MSG:INFO: PWM spindle changed to tool:1 using atc_manual]
[echo: M6T2]
[MSG:INFO: Sel:2 Cur:1]
[MSG:INFO: PWM spindle changed to tool:2 using atc_manual]
[echo: #<start_x >= #<_x>]
[echo: #<start_y >= #<_y>]
[echo: #<start_z >= #<_z>]
[echo: G53G0Z-2.000]
[echo: G53G0Z-2.000]
[echo: G53G0X1.500Y139.000]
[echo: G53G0Z #</ atc_manual / ets_rapid_z_mpos_mm>]
[echo: G53 G38.2 Z-40.000 F200.000]
[PRB:1.500,139.000,-14.834:1]
[echo: G0Z[#<_z> + 5]]
[echo: G53 G38.2 Z-40.000 F100.000]
[PRB:1.500,139.000,-14.896:1]
[echo: #<_ets_tool1_z>=[#5063]]
[echo: G53G0Z-2.000]
[echo: G53G0X75.000Y145.000Z-1.000]
[echo: G4P0 0.1]
[echo: (MSG: Install tool #2 then resume to continue)]
[MSG:INFO: MSG, Install tool #2 then resume to continue]
[echo: M0]
[CycleStart]
[echo: G53G0Z-2.000]
[echo: G53G0Z-2.000]
[echo: G53G0X1.500Y139.000]
[echo: G53G0Z #</ atc_manual / ets_rapid_z_mpos_mm>]
[echo: G53 G38.2 Z-40.000 F200.000]
[PRB:1.500,139.000,-14.775:1]
[echo: G0Z[#<_z> + 5]]
[echo: G53 G38.2 Z-40.000 F100.000]
[PRB:1.500,139.000,-14.750:1]
[echo: #<_my_tlo_z >=[#5063 - #<_ets_tool1_z>]]
[echo: G43.1Z#<_my_tlo_z>]
[echo: G53G0Z-2.000]
[echo: G0X#<start_x>Y#<start_y>]
[echo: G0Z#<start_z>]
[echo: G0 X0 Y0 Z0]
[echo: ]
This is my atc_manual section...atc_demo.gcode
atc_manual:
safe_z_mpos_mm: -2.000000
probe_seek_rate_mm_per_min: 200.000000
probe_feed_rate_mm_per_min: 100.000000
change_mpos_mm: 75.000 145.000 -1.000
ets_mpos_mm: 1.500 139.000 -40.000
ets_rapid_z_mpos_mm: -5.000000
This is the gcode file I ran
G0 X0 Y0
G53 G0 Z-20
G38.2 Z-50 F150 P0
G53 G0 Z-1
M61Q1
M6T2
G0 X0 Y0 Z0
[22:46:15] [ $G ] [PRB:182.300,44.600,-63.560:1]
shows that mpos.z is -63.560 and /atc_manual/ets_rapid_z_mpos_mm is -1.000000, so the G53G0Z #</ atc_manual / ets_rapid_z_mpos_mm> seems unlikely to go downward.
The OP's successful initial probes to find edges and whatnot are done in G91 / G54 incremental mode. The atc probes are done in G90 / G53 absolute mode. He has:
ets_mpos_mm: 182.300 44.600 -63.20
yet the result of the probe is
[PRB:182.300,44.600,-63.560:1]
which is just below the place where the probe should have given up.
We need to see the gcode echo to see the probe command. The sender is doing so much that it is hard to tell where the commands are coming from.
AHA!
[22:45:42] [ $G ] [GC:G0 G54 G17 G21 G91 G94 M5 M9 T1 F20 S0]
[22:45:42] [ $G ] ok
[22:45:54] [ M6T2 ] [MSG:INFO: Sel:2 Cur:1]
The system is in G91 when the toolchange starts. I expect that has not been tested. It will affect all of the coordinates.
G53 is supposed to be G91 independent. it appears that it is.
G91
<Idle|MPos:0.000,150.000,-1.000|FS:0,0|Ov:100,100,100>
G53 G0 Z-1
[echo: G53 G0 Z-1]
ok
G53 G0 Z-1
[echo: G53 G0 Z-1]
ok
G53 G0 Z-1
[echo: G53 G0 Z-1]
ok
<Idle|MPos:0.000,150.000,-1.000|FS:0,0>
There are a number of G0-without-G53 moves in atc_manual. Perhaps it is one of them.
-
A good gcode sender should not leave you in G91 without you knowing about it.
-
A good post processors or gcode file should have a G90 at the beginning.
-
I could save and restore the G90/G91
-
I could use the newly uncovered
_abs_zand G53 for the little G0 nudges.
Yep.
Here's what I think is happening specifically:
G53 G38.2 Z-63.20 F200.000
[PRB:182.300,44.600,-63.560:1]
An earlier G10 L20 P0 Z0 left G54 Z at 0, so <_z> (in G54) is now -63.56. Then
_macro.addf("G0Z[#<_z> + 5]"); // retract befor next probe
in G91 is a 58.56 mm downward move (-63.56 + 5).
Another approach would be to add a check for G91 mode and alarm out with a message like "Fix your sender".
Using G53 exclusively seems like a good idea.
A new PR makes this safe from G91 and Non G17 planes.
https://github.com/bdring/FluidNC/pull/1570
External Feature Center Finding Macro: // Centre Finding Macro For OpenBuilds Control // V 2.1 // // Finds the centre of external edges of features. // Position the probe over the approximate centre of the feature before use. // Dimensions entered in the dialog must be sufficient for the probe to clear the feature or there will be a crash // // Z travel must be sufficient for probe to lower enough to detect the part when probing without unwanted contact // // X and Y centres can be found independently // Z heights are preserved // The machine is positioned over the centre after use and active WCS X and/or Y is set to zero. // // Default feature size: Line 305 // Default probe diameter: Line 314 // Default Z travel: Line 381 // Default Z Feedrate: Line 389 // // Change the value of 'simpleUI' (below) to show or hide Z speed and probe retract distance in the dialog // // Use at own risk! // DAG 7/11/23 // // V2.1 8/8/24 Added option to display measurement result after probe
var simpleUI = "false"; // "false" = Show Z feedrate and probe retract distance input boxes in dialog // "true" = hide them
function probeBoss(featureSize, probeDiameter, probeFast, probeSlow, extraTravel, zTravel, zFeed, doX, doY, retract, doubleTap, showResult) { var rightside = 0, leftside = 0, farside = 0, nearside = 0, centreXdistance = 0, centreYdistance = 0;
var initialMove = ""+ ((featureSize / 2)+ extraTravel + (probeDiameter / 2)).toFixed(3);
window.unitsmode = laststatus.machine.modals["unitsmode"]; //save any modal settings that we might change or reference
window.distmode = laststatus.machine.modals["distancemode"];
var step = 0; // 1 Find left hand X edge
// 2 Refine left hand X edge
// 3 Find right hand X edge
// 4 Refine right hand X edge
// 5 Find near Y edge
// 6 Refine near Y edge
// 7 Find far Y edge
// 8 Refine far Y edge
// 9 All done
if (doX == false) step = 5; else step = 1;
const probeString = [];
//Find LH X edge from starting point
probeString[1] = G91 G21 G10 P0 L20 X0 G0 X- + initialMove + G1 Z- + zTravel + F+ zFeed + G38.2 X + initialMove + F + probeFast;
// Refine LH X edge
probeString[2] = G4 P0.3 G0 X- + retract + G38.2 X + initialMove + F + probeSlow;
//Find RH X edge from LH edge
probeString[3] = G4 P0.3 G0 X- + retract + G0 Z + zTravel + G90 G0 X + initialMove + G91 G1 Z - + zTravel + F+ zFeed + G38.2 X- + initialMove + F + probeFast;
// Refine RH X edge
probeString[4] = G4 P0.3 G0 X + retract + G38.2 X- + initialMove + F + probeSlow;
//Find near Y edge from starting point
probeString[5] = G91 G21 G10 P0 L20 Y0 G0 Y- + initialMove + G1 Z - + zTravel + F+ zFeed + G38.2 Y + initialMove + F + probeFast;
// Refine near Y edge
probeString[6] = G4 P0.3 G0 Y- + retract + G38.2 Y + initialMove + F + probeSlow;
//Find far Y edge from near edge
probeString[7] = G4 P0.3 G0 Y- + retract + G0 Z + zTravel + G90 G0 Y + initialMove + G91 G1 Z - + zTravel + F+ zFeed + G38.2 Y- + initialMove + F + probeFast;
// Refine far Y edge
probeString[8] = G4 P0.3 G0 Y + retract + G38.2 Y- + initialMove + F + probeSlow;
printLog("Centre finding probe cycle in progress");
socket.off('prbResult'); // Disable old listeners
runGcode(probeString[step]);
socket.on('prbResult', function(prbdata) {
if (prbdata.state > 0) {
console.log("Step " + step, prbdata);
switch (step)
{
case 1: // Found LH X
{
leftside = prbdata.x;
console.log("X min 1 " + leftside);
step++;
if (doubleTap == false) step++; //Skip the next step if we don't want to repeat the probe
runGcode(probeString[step]);
break;
}
case 2: // Refine LH X
{
leftside = prbdata.x;
console.log("X min 2 " + leftside);
step++;
runGcode(probeString[step]);
break;
}
case 3: // Found RH X
{
rightside = prbdata.x;
console.log("X max 1 " + rightside);
step++
if (doubleTap == true){ //Extra step if we want to repeat the probe
runGcode(probeString[step]);
break;
}
// No break here, because we want to run through
}
case 4: // Refine LH X
{
if (doubleTap==true){
rightside = prbdata.x;
console.log("X max 2 " + rightside);
}
centreXdistance = (rightside - leftside - probeDiameter);
console.log("X distance =" + centreXdistance);
var xCentre = ((leftside*1)+ (rightside*1)) / 2;
console.log("X centre = " + xCentre);
var setX0 =`
G4 P0.3
G0 X` + retract +`
G0 Z` + zTravel +`
G53 G0 X` + xCentre + `
G10 P0 L20 X0`;
runGcode(setX0);
if (doY == false){
// report X results
step = 9;
}
else {
step = 5
runGcode (probeString[step]);
}
break;
}
case 5: // Found near Y
{
nearside = prbdata.y
console.log("Y min 1 " + nearside);
step++;
if (doubleTap == false) step++; //Skip the next step if we don't want to repeat the probe
runGcode(probeString[step]);
break;
}
case 6: // Refine near Y
{
nearside = prbdata.y
console.log("Y min 2 " + nearside);
step++;
runGcode(probeString[step]);
break;
}
case 7: // Found far Y
{
farside = prbdata.y
console.log("Ymax 1 " + farside);
step++
if (doubleTap == true){ //Extra step if we want to repeat the probe
runGcode(probeString[step]);
break;
}
// No break here, because we want to run through
}
case 8:
{
if (doubleTap==true){
farside = prbdata.y
console.log("Ymax 2 " + farside);
}
centreYdistance = (farside - nearside - probeDiameter);
console.log("Y distance =" + centreYdistance);
var yCentre = ((farside*1) + (nearside*1)) / 2;
console.log("Y centre = " + yCentre);
step = 9;
var setY0 = `
G4 P0.3
G0 Y` + retract +`
G0 Z` + zTravel +`
G53 G0 Y` + yCentre + `
G10 P0 L20 Y0
`
runGcode(setY0);
break;
}
default:
{
//stuff
}
}
if (step==9){ //Finished. The switch statement won't be revisited, so need to do this here
socket.off('prbResult');
printLog("Probing Cycle Complete\nX measurement " + centreXdistance.toFixed(3)+ " mm\nY Measurement " + centreYdistance.toFixed(3)+ " mm" );
if (showResult == true){
var message = "<div>";
if (doX==true) message = message + "X Distance " + centreXdistance.toFixed(2) +" mm<br>";
if (doY==true) message = message + "Y Distance " + centreYdistance.toFixed(2) +" mm<br>";
message = message +"</div>";
Metro.dialog.create({title: "Probe Complete", content: message, closeButton: true});
}
if(unitsmode != "") {sendGcode(unitsmode);} // Restore modal settings if they were read
if(distmode != "") {sendGcode (distmode);}
}
} else {
console.log("Probe Failed")
}
}) } function runGcode(dataString) { socket.emit('runJob', { data: dataString, isJob: false, completedMsg: false, fileName: "" }); }
Metro.dialog.create({
title: "中心定位 - 外部特征 `,
onShow: function(){
var el1 = document.getElementById("retractRow");
var el2 = document.getElementById("zFeedRow"); actions: [{
caption: "运行探测程序",
cls: "js-dialog-close success",
onclick: function() {
var featureSize = parseFloat($("#featureSizeInput").val())
var probeDiameter = parseFloat($("#probeDiaInput").val())
var probeFast = parseInt($("#probeSeekRate").val())
var probeSlow = parseInt($("#probeSlowRate").val())
var extraTravel = parseFloat($("#probeOffsetInput").val())
var zTravel = parseFloat($("#probeZTravelInput").val())
var zFeed = parseFloat($("#probeZFeedInput").val())
var retract = parseFloat($("#probeRetractInput").val()) ]
});
在继续操作之前,应将探头大致移动到该特征的正中央位置。",
content: `
<div class="row mb-0">
<div class="cell-sm-4">
<canvas id="e3f901b501ee4b44ae24fd1c3ca6f4ee"></canvas>
</div>
</div>
</div>
</div>
<hr>
<div class="row mb-0">
<div class="cell-sm-4">
<canvas id="ecc29b1e6d6243219912dd32ea3f53a0"></canvas>
</div>
</div>
<hr>
<div class="row mb-0">
<label>探头速度 (快和慢)</label>
</div>
<div class="row mb-0">
<div class="cell-sm-6">
<input id="probeSeekRate" type="number" value="200" data-role="input" data-append="mm/min" data-prepend="<i class='fas fa-running'></i>" data-clear-button="false">
</div>
<div class="cell-sm-6">
<input id="probeSlowRate" type="number" value="20" data-role="input" data-append="mm/min" data-prepend="<i class='fas fa-walking'></i>" data-clear-button="false">
</div>
</div>
<hr>
<div class="row mb-0">
<div class="cell-sm-3">
<input id="centreX" type="checkbox" checked data-role="checkbox" data-caption="X轴分中">
</div>
<div class="cell-sm-3">
<input id="centreY" type="checkbox" checked data-role="checkbox" data-caption="Y轴分中">
</div>
<div class="cell-sm-3">
<input id="slowProbe" type="checkbox" checked data-role="checkbox" data-caption="探头慢速">
</div>
<div class="cell-sm-3">
<input id="showResult" type="checkbox" unchecked data-role="checkbox" data-caption="显示结果">
</div>
</div>
if (simpleUI == "true") {
el1.hidden = "true";
el2.hidden = "true";
}
},
var doX = ($("#centreX").prop ("checked" ))
var doY = ($("#centreY").prop ("checked" ))
var doubleTap = ($("#slowProbe").prop ("checked" ))
var showResult = ($("#showResult").prop ("checked" ))
if((doY ==false) && (doX == false)) alert ("Error: at least one of X or Y must be checked!");
else probeBoss(featureSize, probeDiameter, probeFast, probeSlow, extraTravel, zTravel, zFeed, doX, doY, retract, doubleTap, showResult);
}
},
{
caption: "取消",
cls: "js-dialog-close alert",
onclick: function() {
//
}
},
Z-Plane Finding Macro: // Z平面探测 function probeZPlane(zTravel, zSpeedQ, zSpeedS, retract) { console.log("开始Z平面探测");
const originalDistMode = laststatus.machine.modals["distancemode"] || "G90";
const originalUnitsMode = laststatus.machine.modals["unitsmode"] || "G21";
socket.off('prbResult');
// 执行第一次探测
runGcode(`G21\nG91\nG38.2 Z-${zTravel} F${zSpeedQ}`);
// 监听第一次探测结果
socket.on('prbResult', function(prbdata) {
socket.off('prbResult'); // 移除监听器避免重复触发
if (prbdata.state > 0) { // 第一次探测成功
// 回收距离
runGcode(`G0 Z${retract}`);
// 执行第二次探测
runGcode(`G38.2 Z-${zTravel} F${zSpeedS}`);
// 监听第二次探测结果
socket.on('prbResult', function(prbdata2) {
socket.off('prbResult'); // 移除监听器
if (prbdata2.state > 0) { // 第二次探测成功
const probedZ = prbdata2.z;
// 关键:将当前Z位置设置为工件坐标系零点
// 使用G10 L20 P0 Z0 将当前Z位置设置为工件坐标系零点
runGcode(`G10 L20 P0 Z0`);
// 或者使用G92设置当前坐标
// runGcode(`G92 Z0`);
// 安全抬升
runGcode(`G91 G0 Z5`);
// 显示成功消息
Metro.dialog.create({
title: "探测成功",
content: `<div>Z零点已设置: ${probedZ.toFixed(3)} mm</div>`,
width: 300
});
} else {
// 第二次探测失败
handleProbeFailure(originalDistMode, originalUnitsMode);
}
});
} else {
// 第一次探测失败
handleProbeFailure(originalDistMode, originalUnitsMode);
}
});
}
// 处理探测失败的辅助函数
function handleProbeFailure(originalDistMode, originalUnitsMode) {
runGcode(${originalDistMode}\n${originalUnitsMode});
Metro.dialog.create({
title: "探测失败",
content: "Z平面探测失败",
closeButton: true
});
}
// 创建Z探测对话框 - 修正版本
Metro.dialog.create({
id: 'z-probe-dialog',
title: "Z平面探测",
content: <div class="row"> <div class="cell-6"> <label>Z移动距离</label> <input id="probeZTravelInput" type="number" value="10" data-role="input" data-append="mm"> </div> <div class="cell-6"> <label>粗测速度</label> <input id="probezSpeedQInput" type="number" value="160" data-role="input" data-append="mm/min"> </div> <div class="cell-6"> <label>抬升距离</label> <input id="probeRetractInput" type="number" value="2" data-role="input" data-append="mm"> </div> <div class="cell-6"> <label>慢测速度</label> <input id="probezSpeedSInput" type="number" value="80" data-role="input" data-append="mm/min"> </div> </div>,
actions: [
{
caption: "运行探测",
cls: "js-dialog-close success",
onclick: function() {
const zTravel = parseFloat($("#probeZTravelInput").val());
const zSpeedQ = parseFloat($("#probezSpeedQInput").val());
const zSpeedS = parseFloat($("#probezSpeedSInput").val());
const retract = parseFloat($("#probeRetractInput").val());
if(isNaN(zTravel) || isNaN(zSpeedQ) || isNaN(zSpeedS) || isNaN(retract)) return;
probeZPlane(zTravel, zSpeedQ, zSpeedS, retract);
}
},
{
caption: "取消",
cls: "js-dialog-close alert",
onclick: function() {
// 修正:正确关闭对话框
}
}
]
}); // 运行G代码函数 function runGcode(dataString) { socket.emit('runJob', { data: dataString, isJob: false, completedMsg: true, fileName: "" }); }
function probeZPlane restores originalDistMode only in the probe failure case. If the probe succeeds, it does not undo the G91 from this line
// 执行第一次探测
runGcode(`G21\nG91\nG38.2 Z-${zTravel} F${zSpeedQ}`);
and then later it sets G91 mode again from
// 安全抬升
runGcode(`G91 G0 Z5`);
leaving a CNC system in G91 mode is unwise.
函数 probeZPlane 仅在探针失败的情况下恢复原始 DistMode。如果探测成功,则不会从该线撤消 G91
// 执行第一次探测 runGcode(
G21\nG91\nG38.2 Z-${zTravel} F${zSpeedQ}); 然后它再次从// 安全抬升 runGcode(`G91 G0 Z5`);将 CNC 系统置于 G91 模式是不明智的。 How should I revise this?
Add a G90 line afterwards.
runGcode('G91 G0 Z5');
runGcode('G90');