Skip to content

Commit 465cdd3

Browse files
committed
Improved grbl.on_probe_fixture event signature, some minor fixes
1 parent 79882cf commit 465cdd3

11 files changed

+88
-14
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It has been written to complement grblHAL and has features such as proper keyboa
1111

1212
---
1313

14-
Latest build date is 20211010, see the [changelog](changelog.md) for details.
14+
Latest build date is 20211015, see the [changelog](changelog.md) for details.
1515
__NOTE:__ Drivers built with more than three axes configured \(`N_AXIS` > `3`\) will force a settings reset when upgraded. Backup and restore of settings is recommended for these.
1616

1717
---
@@ -80,4 +80,4 @@ List of Supported G-Codes:
8080
Some [plugins](https://github.com/grblHAL/plugins) implements additional M-codes.
8181

8282
---
83-
2021-10-10
83+
2021-10-15

changelog.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
## grblHAL changelog
22

3+
Build 2021015:
4+
5+
Core:
6+
7+
* Improved `grbl.on_probe_fixture` event signature by adding pointer to the pending tool when fired when M6 is executing \(NULL if not\) and a flag indicating that the current XY-position is within 5mm of G59.3.
8+
* A few minor fixes.
9+
10+
Plugins:
11+
12+
* I2C keypad: Switch to metric mode when jogging.
13+
* WebUI: added option to store read-only webui files in flash.
14+
15+
Templates:
16+
17+
* Updated the [probe select](https://github.com/grblHAL/Templates/blob/master/my_plugin/probe%20select/my_plugin.c) example for the `grbl.on_probe_fixture` signature change and added an optional mode select parameter to M401.
18+
19+
---
20+
321
Build 2021010:
422

523
Core:
624
* Added enum and associated get function for system defined named parameters.
7-
* Added events (function pointers) for tool change mode 2 and 3 events (can be used to switch between probes) and for publishing active homing feedrate.
25+
* Added events (function pointers) for tool change mode 2 and 3 events \(can be used to switch between probes\) and for publishing active homing feedrate.
826

927
Drivers:
1028
* Improved stream support in many drivers by adding support for _write_n_ characters. This is mainly used for outputting human readable settings descriptions.

config.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,14 @@ __NOTE:__ these definitions are only referenced in this file. Do __NOT__ change!
361361
//#define DEFAULT_TOOLCHANGE_SEEK_RATE 200.0f // mm/min
362362
//#define DEFAULT_TOOLCHANGE_PULLOFF_RATE 200.0f // mm/min
363363

364+
// The grbl.on_probe_fixture event handler is called by the default tool change algorithm when probing at G59.3.
365+
// In addition it will be called on a "normal" probe sequence if the XY position is
366+
// within the radius of the G59.3 position defined below.
367+
// Uncomment and change if the default value of 5mm is not suitable or set it to 0.0f to disable.
368+
// NOTE: A grbl.on_probe_fixture event handler is not installed by the core, it has to be provided
369+
// by a driver or a plugin.
370+
//#define TOOLSETTER_RADIUS 5.0f
371+
364372
// By default, Grbl sets all input pins to normal-low operation with their internal pull-up resistors
365373
// enabled. This simplifies the wiring for users by requiring only a normally closed (NC) switch connected
366374
// to ground. It is not recommended to use normally-open (NO) switches as this increases the risk
@@ -642,6 +650,10 @@ __NOTE:__ these definitions are only referenced in this file. Do __NOT__ change!
642650
#endif // DEFAULT_HOMING_ENABLE
643651

644652
// Uncomment to enable experimental support for parameters and expressions
645-
#define NGC_EXPRESSIONS_ENABLE 1
653+
//#define NGC_EXPRESSIONS_ENABLE 1
654+
655+
#ifndef TOOLSETTER_RADIUS
656+
#define TOOLSETTER_RADIUS 5.0f // Default value - do not change here!
657+
#endif
646658

647659
#endif

core_handlers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typedef void (*on_unknown_feedback_message_ptr)(stream_write_ptr stream_write);
8080
typedef void (*on_stream_changed_ptr)(stream_type_t type);
8181
typedef bool (*on_laser_ppi_enable_ptr)(uint_fast16_t ppi, uint_fast16_t pulse_length);
8282
typedef void (*on_homing_rate_set_ptr)(axes_signals_t axes, float rate);
83-
typedef void (*on_probe_fixture_ptr)(bool on);
83+
typedef bool (*on_probe_fixture_ptr)(tool_data_t *tool, bool at_g59_3, bool on);
8484
typedef status_code_t (*on_unknown_sys_command_ptr)(sys_state_t state, char *line); // return Status_Unhandled.
8585
typedef status_code_t (*on_user_command_ptr)(char *line);
8686
typedef sys_commands_t *(*on_get_commands_ptr)(void);

grbl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#else
3535
#define GRBL_VERSION "1.1f"
3636
#endif
37-
#define GRBL_VERSION_BUILD "20211010"
37+
#define GRBL_VERSION_BUILD "20211015"
3838

3939
// The following symbols are set here if not already set by the compiler or in config.h
4040
// Do NOT change here!

motion_control.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ status_code_t mc_homing_cycle (axes_signals_t cycle)
792792
gc_state.modal.coolant.mask = 0;
793793
coolant_set_state(gc_state.modal.coolant);
794794

795-
// -------------------------------------------------------------------------------------
795+
// ---------------------------------------------------------------------------
796796
// Perform homing routine. NOTE: Special motion case. Only system reset works.
797797

798798
if (!home_all) // Perform homing cycle based on mask.
@@ -835,7 +835,7 @@ status_code_t mc_homing_cycle (axes_signals_t cycle)
835835
}
836836

837837
// Homing cycle complete! Setup system for normal operation.
838-
// -------------------------------------------------------------------------------------
838+
// ---------------------------------------------------------
839839

840840
// Sync gcode parser and planner positions to homed position.
841841
sync_position();
@@ -848,7 +848,6 @@ status_code_t mc_homing_cycle (axes_signals_t cycle)
848848
: Status_OK;
849849
}
850850

851-
852851
// Perform tool length probe cycle. Requires probe switch.
853852
// NOTE: Upon probe failure, the program will be stopped and placed into ALARM state.
854853
gc_probe_t mc_probe_cycle (float *target, plan_line_data_t *pl_data, gc_parser_flags_t parser_flags)
@@ -882,6 +881,13 @@ gc_probe_t mc_probe_cycle (float *target, plan_line_data_t *pl_data, gc_parser_f
882881
// Activate the probing state monitor in the stepper module.
883882
sys.probing_state = Probing_Active;
884883

884+
#if COMPATIBILITY_LEVEL <= 1
885+
bool at_g59_3 = false, probe_fixture = grbl.on_probe_fixture != NULL && state_get() != STATE_TOOL_CHANGE;
886+
887+
if(probe_fixture)
888+
grbl.on_probe_fixture(NULL, at_g59_3 = system_xy_at_fixture(CoordinateSystem_G59_3, TOOLSETTER_RADIUS), true);
889+
#endif
890+
885891
// Perform probing cycle. Wait here until probe is triggered or motion completes.
886892
system_set_exec_state_flag(EXEC_CYCLE_START);
887893
do {
@@ -904,6 +910,11 @@ gc_probe_t mc_probe_cycle (float *target, plan_line_data_t *pl_data, gc_parser_f
904910
hal.probe.configure(false, false); // Re-initialize invert mask.
905911
protocol_execute_realtime(); // Check and execute run-time commands
906912

913+
#if COMPATIBILITY_LEVEL <= 1
914+
if(probe_fixture)
915+
grbl.on_probe_fixture(NULL, at_g59_3, false);
916+
#endif
917+
907918
// Reset the stepper and planner buffers to remove the remainder of the probe motion.
908919
st_reset(); // Reset step segment buffer.
909920
plan_reset(); // Reset planner buffer. Zero planner positions. Ensure probing motion is cleared.

ngc_expr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static status_code_t execute_unary (float *operand, ngc_unary_op_t operation)
254254
break;
255255

256256
case NGCUnaryOp_FIX:
257-
*operand = floor(*operand);
257+
*operand = floorf(*operand);
258258
break;
259259

260260
case NGCUnaryOp_FUP:

nuts_bolts.h

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
#endif
5858
#endif
5959

60+
#ifdef __MSP430F5529__
61+
#define isnanf(x) __isnanf(x)
62+
#define isinff(x) __isinff(x)
63+
#endif
64+
6065
// Axis array index values. Must start with 0 and be continuous.
6166
#define X_AXIS 0 // Axis indexing value.
6267
#define Y_AXIS 1

system.c

+23
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ static status_code_t set_startup_line1 (sys_state_t state, char *args);
8383
static status_code_t output_memmap (sys_state_t state, char *args);
8484
#endif
8585

86+
// Simple hypotenuse computation function.
87+
inline static float hypot_f (float x, float y)
88+
{
89+
return sqrtf(x*x + y*y);
90+
}
91+
8692
// Pin change interrupt for pin-out commands, i.e. cycle start, feed hold, and reset. Sets
8793
// only the realtime command execute variable to have the main program execute these when
8894
// its ready. This works exactly like the character-based realtime commands when picked off
@@ -898,6 +904,23 @@ void system_convert_array_steps_to_mpos (float *position, int32_t *steps)
898904
#endif
899905
}
900906

907+
// Checks if XY position is within coordinate system XY with given tolerance.
908+
// If tolerance is 0 false is returned.
909+
bool system_xy_at_fixture (coord_system_id_t id, float tolerance)
910+
{
911+
bool ok = false;
912+
913+
coord_data_t target, position;
914+
915+
if(tolerance > 0.0f && settings_read_coord_data(id, &target.values)) {
916+
system_convert_array_steps_to_mpos(position.values, sys.position);
917+
ok = hypot_f(position.x - target.x, position.y - target.y) <= tolerance;
918+
}
919+
920+
return ok;
921+
}
922+
923+
901924
// Checks and reports if target array exceeds machine travel limits. Returns false if check failed.
902925
// NOTE: max_travel is stored as negative
903926
// TODO: only check homed axes?

system.h

+3
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ void system_flag_wco_change (void);
287287
//! Updates a machine 'position' array based on the 'step' array sent.
288288
void system_convert_array_steps_to_mpos (float *position, int32_t *steps);
289289

290+
//! Checks if XY position is within coordinate system XY with given tolerance.
291+
bool system_xy_at_fixture (coord_system_id_t id, float tolerance);
292+
290293
//! Checks and reports if target array exceeds machine travel limits.
291294
bool system_check_travel_limits (float *target);
292295

tool_change.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void change_completed (void)
7979
}
8080

8181
if(probe_fixture)
82-
grbl.on_probe_fixture(false);
82+
grbl.on_probe_fixture(&current_tool, true, false);
8383

8484
grbl.on_probe_completed = NULL;
8585
gc_state.tool_change = probe_fixture = false;
@@ -175,7 +175,7 @@ static void execute_probe (sys_state_t state)
175175
gc_parser_flags_t flags = {0};
176176

177177
if(probe_fixture)
178-
grbl.on_probe_fixture(true);
178+
grbl.on_probe_fixture(next_tool, true, true);
179179

180180
// G59.3 contains offsets to position of TLS.
181181
settings_read_coord_data(CoordinateSystem_G59_3, &offset.values);
@@ -328,7 +328,9 @@ static status_code_t tool_change (parser_state_t *parser_state)
328328

329329
execute_posted = false;
330330
probe_fixture = grbl.on_probe_fixture != NULL &&
331-
(settings.tool_change.mode == ToolChange_Manual_G59_3 || settings.tool_change.mode == ToolChange_SemiAutomatic);
331+
(settings.tool_change.mode == ToolChange_Manual ||
332+
settings.tool_change.mode == ToolChange_Manual_G59_3 ||
333+
settings.tool_change.mode == ToolChange_SemiAutomatic);
332334
parser_state->tool_change = true;
333335

334336
// Save current position.
@@ -443,7 +445,7 @@ status_code_t tc_probe_workpiece (void)
443445
plan_line_data_t plan_data = {0};
444446

445447
if(probe_fixture)
446-
grbl.on_probe_fixture(true);
448+
grbl.on_probe_fixture(next_tool, system_xy_at_fixture(CoordinateSystem_G59_3, TOOLSETTER_RADIUS), true);
447449

448450
// Get current position.
449451
system_convert_array_steps_to_mpos(target.values, sys.position);

0 commit comments

Comments
 (0)