From 79882cf09485bf7813c0fb9daa00f6d964d73013 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Mon, 11 Oct 2021 13:16:58 +0200 Subject: [PATCH] Added enum and associated get function for system defined named parameters. Added core event handler function pointers and calls if provided. Some other minor changes. --- README.md | 4 +- changelog.md | 51 +++++ config.h | 4 +- core_handlers.h | 4 + driver_opts.h | 4 + gcode.c | 10 +- grbl.h | 2 +- limits.c | 3 + ngc_expr.c | 27 ++- ngc_params.c | 497 +++++++++++++++++++++++------------------------- ngc_params.h | 50 +++++ planner.c | 2 +- settings.c | 6 +- stream.h | 10 + tool_change.c | 15 +- 15 files changed, 411 insertions(+), 278 deletions(-) diff --git a/README.md b/README.md index 348fae4..ae11572 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It has been written to complement grblHAL and has features such as proper keyboa --- -Latest build date is 20210928, see the [changelog](changelog.md) for details. +Latest build date is 20211010, see the [changelog](changelog.md) for details. __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. --- @@ -80,4 +80,4 @@ List of Supported G-Codes: Some [plugins](https://github.com/grblHAL/plugins) implements additional M-codes. --- -2021-09-28 +2021-10-10 diff --git a/changelog.md b/changelog.md index ca43149..6c3e671 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,26 @@ ## grblHAL changelog +Build 2021010: + +Core: +* Added enum and associated get function for system defined named parameters. +* 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. + +Drivers: +* Improved stream support in many drivers by adding support for _write_n_ characters. This is mainly used for outputting human readable settings descriptions. +* Added TMC2209 UART support to the STM32F407 based BTT SKR 2.0 board. By @fitch22. + +Plugins: +* Added support for reading files from flash based storage to http daemon support code. + If a file is not found in the SD-card _www_ folder an attempt will be made to locate in in flash. + Added `WEBUI_INFLASH` option to _my_machine.h_ for storing WebUI files \(_index.html.gz_ and _favicon.ico_\) in flash. + Note that if these files are found in the SD card _www_ folder they will be used instead. +* Improved Trinamic driver support both generally and for the TMC2209 silent stepstick. + The default feedrate for switching to SpreadCycle mode has been changed to 0 \(never switch\), use [M913](https://github.com/grblHAL/Plugins_motor) to set it or set the default value in [trinamic.h](https://github.com/grblHAL/Plugins_motor/blob/master/trinamic.h) by changing the `PWM_THRESHOLD_VELOCITY` symbol. + This is still work in progress, sensorless homing is most problematic and is likely to require tuning of several parameters. E.g. the slow approach feed rate should not be too slow - the default 25 mm/min certainly seems to be. + +--- + Build 20210928: Core: @@ -21,6 +42,8 @@ Drivers & plugins: * Added [WebUI plugin](https://github.com/grblHAL/Plugin_WebUI) support for some networking capable boards. * Updated some drivers for internal API changes. Some minor bug fixes. +--- + Build 20210907: Core: @@ -33,6 +56,8 @@ Drivers & plugins: * Added PWM inversion option to [iMXRT1062 driver](https://github.com/grblHAL/iMXRT1062). * Significantly improved [STM32F7xx driver](https://github.com/grblHAL/STM32F7xx), still work in progress. +--- + Build 20210819: Core: @@ -49,6 +74,8 @@ Drivers & plugins: * Cleaned up/simplified many pin mapping files, mostly by moving pin to bit transforms to a common preprocessor file. * Some general driver and plugin improvements, e.g. more flexible spindle PWM to pin mappings for STM32F4xx and STM32F7xx drivers. +--- + Build 20210803: Core: @@ -61,6 +88,8 @@ Drivers & plugins: * Updated motors plugin to match updated [Trinamic library](https://github.com/terjeio/Trinamic-library), added support for TMC2209++. * Some minor bug fixes and improvements. +--- + Build 20210726: Core: @@ -76,6 +105,8 @@ Drivers & plugins: * Fixed some bugs and regressions. * Added support for ganged/autosquared axes to RP2040 driver. +--- + Build 20210707: Core: @@ -108,31 +139,43 @@ __NOTE:__ For driver developers: `hal.stream.get_rx_buffer_available` has been r * Added number of auxillary I/O ports available to `$I` command response. * Added value read from last `M66` to the first real-time report following the read. The element `|In:` is used for the report. If the value reported is `-1` the read failed. +--- + Build 20210608: * Fixes for `$70` setting handling, networking services. Only compile time enabled services \(or protocols\) can now be configured. +--- + Build 20210604: * Added some HAL entry points and properties, shared file for mapped step and dir output. * Added `$pins` system command, for listing current pin assignments. Work in progress, only supported by a couple of drivers. For now only plain GPIO pins are listed. * Some minor bugs fixed. +--- + Build 20210515: * Fixed G43 "bug" by changing to LinuxCNC specification. NIST specification is ambiguous. * Added acceleration override handling, to be used by OpenPNP plugin M-code. +--- + Build 20210505: * Some bug fixes: relative canned cycles repeat error, comment handling... * Check mode changes to allow use with SD card streaming. * Internal buffer changes for reducing RAM footprint. Some HAL extensions. +--- + Build 20210314: * Added support for tool change protocol to networking protocols using shared stream buffer. * Added `$S` system command for toggling single step mode, when enabled cycle start has to be issued after each block. * Some bug fixes. +--- + Build 20210207: * Added `#define BOARD_MY_MACHINE` option in _my_machine.h_ for building using _my_machine-map.c_, this for simpler handling of user defined pin mappings. @@ -231,6 +274,8 @@ __NOTE:__ Not extensively tested. Use with care! * Improved auto squaring. If a limit switch is engaged when homing starts the axis will be moved pull-off distance * 5 away from them. If still engaged homing will fail. __NOTE:__ Auto squaring is currently only tested with a simulator. Use with care! +--- + Build 20201103: * Added data structures for spindle encoder/spindle sync to the core. Used by drivers supporting spindle sync. @@ -240,6 +285,8 @@ __NOTE:__ Spindle sync support is still in alpha stage! The current code has onl * Moved some symbols in preparation for adding $-settings for them. * Improved rewind capability (on `M2`) of SD card plugin. Added `$` command for dumping SD card file contents to output stream. +--- + Build 20201020: __NOTE:__ Settings data format has been changed and settings will be reset to default on update. Backup and restore. @@ -264,6 +311,8 @@ Ten setting codes are reserved for user defined plugins. * HAL pointers refactored for code readability, many moved to separate structures for each subsystem. Added typedefs. * Some minor bug fixes and other code readability improvements. Prepared for switch to 16-bit CRC for settings data validation. +--- + Build 20200923: * Added support for STM32F411 based Blackpill boards to STM32F4xx driver. @@ -275,6 +324,8 @@ An empy message will now be sent when tool change is complete, this to clear any Use this feature for your private plugin only, multiple public plugins using this name cannot coexist! * Some changes to improve code readability and added strict check for `G59.x` gcodes. +--- + Build 20200911: * Core refactored for better support for non-volatile storage. Some HAL entry points renamed for readability and moved to a new data structure. diff --git a/config.h b/config.h index 760ceef..4f937d2 100644 --- a/config.h +++ b/config.h @@ -24,6 +24,8 @@ // performance tuning or adjusting to non-typical machines. // IMPORTANT: Any changes here requires a full re-compiling of the source code to propagate them. +// A reset of non-volatile storage with $RST=* after reflashing is also required as +// most are just default values for settings. #ifndef _GRBL_CONFIG_H_ #define _GRBL_CONFIG_H_ @@ -640,6 +642,6 @@ __NOTE:__ these definitions are only referenced in this file. Do __NOT__ change! #endif // DEFAULT_HOMING_ENABLE // Uncomment to enable experimental support for parameters and expressions -//#define NGC_EXPRESSIONS_ENABLE 1 +#define NGC_EXPRESSIONS_ENABLE 1 #endif diff --git a/core_handlers.h b/core_handlers.h index 1e22ccc..da9844b 100644 --- a/core_handlers.h +++ b/core_handlers.h @@ -79,6 +79,8 @@ typedef void (*on_realtime_report_ptr)(stream_write_ptr stream_write, report_tra typedef void (*on_unknown_feedback_message_ptr)(stream_write_ptr stream_write); typedef void (*on_stream_changed_ptr)(stream_type_t type); typedef bool (*on_laser_ppi_enable_ptr)(uint_fast16_t ppi, uint_fast16_t pulse_length); +typedef void (*on_homing_rate_set_ptr)(axes_signals_t axes, float rate); +typedef void (*on_probe_fixture_ptr)(bool on); typedef status_code_t (*on_unknown_sys_command_ptr)(sys_state_t state, char *line); // return Status_Unhandled. typedef status_code_t (*on_user_command_ptr)(char *line); typedef sys_commands_t *(*on_get_commands_ptr)(void); @@ -105,6 +107,8 @@ typedef struct { on_get_commands_ptr on_get_commands; on_user_command_ptr on_user_command; on_stream_changed_ptr on_stream_changed; + on_homing_rate_set_ptr on_homing_rate_set; + on_probe_fixture_ptr on_probe_fixture; on_laser_ppi_enable_ptr on_laser_ppi_enable; // core entry points - set up by core before driver_init() is called. enqueue_gcode_ptr enqueue_gcode; diff --git a/driver_opts.h b/driver_opts.h index bb30659..4884e5e 100644 --- a/driver_opts.h +++ b/driver_opts.h @@ -162,6 +162,10 @@ #define WEBUI_AUTH_ENABLE 0 #endif +#ifndef WEBUI_INFLASH +#define WEBUI_INFLASH 0 +#endif + #if WEBUI_ENABLE && !defined(ESP_PLATFORM) #ifdef ETHERNET_ENABLE diff --git a/gcode.c b/gcode.c index 5ab0d4a..1018391 100644 --- a/gcode.c +++ b/gcode.c @@ -2982,17 +2982,19 @@ status_code_t gc_execute_block(char *block) // Execute coordinate change and spindle/coolant stop. if (!check_mode) { + if (!(settings_read_coord_data(gc_state.modal.coord_system.id, &gc_state.modal.coord_system.xyz))) + FAIL(Status_SettingReadFail); + +#if COMPATIBILITY_LEVEL <= 1 float g92_offset_stored[N_AXIS]; if(settings_read_coord_data(CoordinateSystem_G92, &g92_offset_stored) && !isequal_position_vector(g92_offset_stored, gc_state.g92_coord_offset)) settings_write_coord_data(CoordinateSystem_G92, &gc_state.g92_coord_offset); // Save G92 offsets to non-volatile storage +#endif - if (!(settings_read_coord_data(gc_state.modal.coord_system.id, &gc_state.modal.coord_system.xyz))) - FAIL(Status_SettingReadFail); system_flag_wco_change(); // Set to refresh immediately just in case something altered. hal.spindle.set_state(gc_state.modal.spindle, 0.0f); hal.coolant.set_state(gc_state.modal.coolant); - sys.report.spindle = On; // Set to report change immediately - sys.report.coolant = On; // ... + sys.report.spindle = sys.report.coolant = On; // Set to report change immediately } if(grbl.on_program_completed) diff --git a/grbl.h b/grbl.h index 04a8580..aacac35 100644 --- a/grbl.h +++ b/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210928" +#define GRBL_VERSION_BUILD "20211010" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/limits.c b/limits.c index 7289e71..1074b60 100644 --- a/limits.c +++ b/limits.c @@ -315,6 +315,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate *= sqrtf(n_active_axis); // [sqrt(N_AXIS)] Adjust so individual axes all move at homing rate. sys.homing_axis_lock.mask = axislock.mask; + if(grbl.on_homing_rate_set) + grbl.on_homing_rate_set(cycle, homing_rate); + // Perform homing cycle. Planner buffer should be empty, as required to initiate the homing cycle. plan_data.feed_rate = homing_rate; // Set current homing rate. plan_buffer_line(target, &plan_data); // Bypass mc_line(). Directly plan homing motion. diff --git a/ngc_expr.c b/ngc_expr.c index 2f69728..00e570a 100644 --- a/ngc_expr.c +++ b/ngc_expr.c @@ -511,9 +511,9 @@ static status_code_t read_operation_unary (char *line, uint_fast8_t *pos, ngc_un if(!strncmp(line + *pos, "XP", 2)) { *operation = NGCUnaryOp_EXP; *pos += 2; -/* } else if(!strncmp(line + *pos, "XISTS", 5)) { + } else if(!strncmp(line + *pos, "XISTS", 5)) { *operation = NGCUnaryOp_Exists; - *pos += 5; */ + *pos += 5; } else status = Status_ExpressionUknownOp; break; @@ -672,15 +672,26 @@ static status_code_t read_unary (char *line, uint_fast8_t *pos, float *value) if(line[*pos] != '[') status = Status_ExpressionSyntaxError; // Left bracket missing after unary operation name + else { - /* if (operation == NGCUnaryOp_Exists) { - CHP(read_bracketed_parameter(line, pos, value, true)); - return Status_OK; - } - */ - if((status = ngc_eval_expression(line, pos, value)) == Status_OK) { + + char *arg = &line[++(*pos)], *s; + + s = arg; + while(*s && *s != ']') + s++; + + if(*s == ']') { + *s = '\0'; + *value = ngc_named_param_exists(arg) ? 1.0f : 0.0f; + *s = ']'; + *pos = *pos + s - arg + 1; + } else + status = Status_ExpressionSyntaxError; + + } else if((status = ngc_eval_expression(line, pos, value)) == Status_OK) { if(operation == NGCUnaryOp_ATAN) status = read_atan(line, pos, value); else diff --git a/ngc_params.c b/ngc_params.c index afce94e..741a453 100644 --- a/ngc_params.c +++ b/ngc_params.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "system.h" #include "settings.h" @@ -52,6 +53,7 @@ typedef struct ngc_rw_param { typedef struct { const char *name; + ncg_name_param_id_t id; ngc_named_param_get_ptr get; } ngc_named_ro_param_t; @@ -66,9 +68,14 @@ ngc_named_rw_param_t *rw_global_params = NULL; static float _relative_pos (uint_fast8_t axis) { - float value = sys.position[axis] / settings.axis[axis].steps_per_mm - gc_get_offset(axis); - if(settings.flags.report_inches) - value *= 25.4f; + float value; + + if(axis < N_AXIS) { + value = sys.position[axis] / settings.axis[axis].steps_per_mm - gc_get_offset(axis); + if(settings.flags.report_inches) + value *= 25.4f; + } else + value = 0.0f; return value; } @@ -284,264 +291,241 @@ bool ngc_param_set (ngc_param_id_t id, float value) return ok; } +PROGMEM static const ngc_named_ro_param_t ngc_named_ro_param[] = { + { .name = "_vmajor", .id = NGCParam_vmajor }, + { .name = "_vminor", .id = NGCParam_vminor }, + { .name = "_line", .id = NGCParam_line }, + { .name = "_motion_mode", .id = NGCParam_motion_mode }, + { .name = "_plane", .id = NGCParam_plane }, + { .name = "_ccomp", .id = NGCParam_ccomp }, + { .name = "_metric", .id = NGCParam_metric }, + { .name = "_imperial", .id = NGCParam_imperial }, + { .name = "_absolute", .id = NGCParam_absolute }, + { .name = "_incremental", .id = NGCParam_incremental }, + { .name = "_inverse_time", .id = NGCParam_inverse_time }, + { .name = "_units_per_minute", .id = NGCParam_units_per_minute }, + { .name = "_units_per_rev", .id = NGCParam_units_per_rev }, + { .name = "_coord_system", .id = NGCParam_coord_system }, + { .name = "_tool_offset", .id = NGCParam_tool_offset }, + { .name = "_retract_r_plane", .id = NGCParam_retract_r_plane }, + { .name = "_retract_old_z", .id = NGCParam_retract_old_z }, + { .name = "_spindle_rpm_mode", .id = NGCParam_spindle_rpm_mode }, + { .name = "_spindle_css_mode", .id = NGCParam_spindle_css_mode }, + { .name = "_ijk_absolute_mode", .id = NGCParam_ijk_absolute_mode }, + { .name = "_lathe_diameter_mode", .id = NGCParam_lathe_diameter_mode }, + { .name = "_lathe_radius_mode", .id = NGCParam_lathe_radius_mode }, + { .name = "_spindle_on", .id = NGCParam_spindle_on }, + { .name = "_spindle_cw", .id = NGCParam_spindle_cw }, + { .name = "_mist", .id = NGCParam_mist }, + { .name = "_flood", .id = NGCParam_flood }, + { .name = "_speed_override", .id = NGCParam_speed_override }, + { .name = "_feed_override", .id = NGCParam_feed_override }, + { .name = "_adaptive_feed", .id = NGCParam_adaptive_feed }, + { .name = "_feed_hold", .id = NGCParam_feed_hold }, + { .name = "_feed", .id = NGCParam_feed }, + { .name = "_rpm", .id = NGCParam_rpm }, + { .name = "_x", .id = NGCParam_x }, + { .name = "_y", .id = NGCParam_y }, + { .name = "_z", .id = NGCParam_z }, + { .name = "_a", .id = NGCParam_a }, + { .name = "_b", .id = NGCParam_b }, + { .name = "_c", .id = NGCParam_c }, + { .name = "_u", .id = NGCParam_u }, + { .name = "_v", .id = NGCParam_v }, + { .name = "_w", .id = NGCParam_w }, + { .name = "_current_tool", .id = NGCParam_current_tool }, + { .name = "_current_pocket", .id = NGCParam_current_pocket }, + { .name = "_selected_tool", .id = NGCParam_selected_tool }, + { .name = "_selected_pocket", .id = NGCParam_selected_pocket }, +}; + // Named parameters -static float _line (void) +float ngc_named_param_get_by_id (ncg_name_param_id_t id) { - return (float)gc_state.line_number; + float value; + + switch(id) { + + case NGCParam_vmajor: + value = 1.1f; + break; + + case NGCParam_vminor: + value = 0.0f; // TODO: derive from version letter? + break; + + case NGCParam_line: + value = (float)gc_state.line_number; + break; + + case NGCParam_motion_mode: + value = (float)(gc_state.modal.motion * 10); // TODO: Fix G38.x + break; + + case NGCParam_plane: + value = (float)(170 + gc_state.modal.plane_select * 10); + break; + + case NGCParam_ccomp: + value = 400.0f; + break; + + case NGCParam_metric: + value = gc_state.modal.units_imperial ? 0.0f : 1.0f; + break; + + case NGCParam_imperial: + value = gc_state.modal.units_imperial ? 1.0f : 0.0f; + break; + + case NGCParam_absolute: + value = gc_state.modal.distance_incremental ? 0.0f : 1.0f; + break; + + case NGCParam_incremental: + value = gc_state.modal.distance_incremental ? 1.0f : 0.0f; + break; + + case NGCParam_inverse_time: + value = gc_state.modal.feed_mode == FeedMode_InverseTime ? 1.0f : 0.0f; + break; + + case NGCParam_units_per_minute: + value = gc_state.modal.feed_mode == FeedMode_UnitsPerMin ? 1.0f : 0.0f; + break; + + case NGCParam_units_per_rev: + value = gc_state.modal.feed_mode == FeedMode_UnitsPerRev ? 1.0f : 0.0f; + break; + + case NGCParam_coord_system: + { + uint_fast16_t id = gc_state.modal.coord_system.id * 10; + + if(id > (CoordinateSystem_G59 * 10)) + id = (CoordinateSystem_G59 * 10) + gc_state.modal.coord_system.id - CoordinateSystem_G59; + + value = (float)(540 + id); + } + break; + + case NGCParam_tool_offset: + value = gc_state.modal.tool_offset_mode >= ToolLengthOffset_Enable ? 1.0f : 0.0f; + break; + + case NGCParam_retract_r_plane: + value = gc_state.modal.retract_mode == CCRetractMode_Previous ? 1.0f : 0.0f; + break; + + case NGCParam_retract_old_z: + value = gc_state.modal.retract_mode == CCRetractMode_RPos ? 1.0f : 0.0f; + break; + + case NGCParam_spindle_rpm_mode: + value = gc_state.modal.spindle_rpm_mode == SpindleSpeedMode_RPM ? 1.0f : 0.0f; + break; + + case NGCParam_spindle_css_mode: + value = gc_state.modal.spindle_rpm_mode == SpindleSpeedMode_CSS ? 1.0f : 0.0f; + break; + + case NGCParam_ijk_absolute_mode: + value = 0.0f; + break; + + case NGCParam_lathe_diameter_mode: + value = gc_state.modal.diameter_mode ? 1.0f : 0.0f; + break; + + case NGCParam_lathe_radius_mode: + value = gc_state.modal.diameter_mode ? 0.0f : 1.0f; + break; + + case NGCParam_spindle_on: + value = gc_state.modal.spindle.on ? 1.0f : 0.0f; + break; + + case NGCParam_spindle_cw: + value = gc_state.modal.spindle.ccw ? 1.0f : 0.0f; + break; + + case NGCParam_mist: + value = gc_state.modal.coolant.mist ? 1.0f : 0.0f; + break; + + case NGCParam_flood: + value = gc_state.modal.coolant.flood ? 1.0f : 0.0f; + break; + + case NGCParam_speed_override: + value = gc_state.modal.override_ctrl.spindle_rpm_disable ? 0.0f : 1.0f; + break; + + case NGCParam_feed_override: + value = gc_state.modal.override_ctrl.feed_rate_disable ? 0.0f : 1.0f; + break; + + case NGCParam_adaptive_feed: + value = 0.0f; + break; + + case NGCParam_feed_hold: + value = gc_state.modal.override_ctrl.feed_hold_disable ? 0.0f : 1.0f; + break; + + case NGCParam_feed: + value = gc_state.feed_rate; + break; + + case NGCParam_rpm: + value = gc_state.spindle.rpm; + break; + + case NGCParam_x: + //no break + case NGCParam_y: + //no break + case NGCParam_z: + //no break + case NGCParam_a: + //no break + case NGCParam_b: + //no break + case NGCParam_c: + //no break + case NGCParam_u: + //no break + case NGCParam_v: + //no break + case NGCParam_w: + value = _relative_pos(id - NGCParam_x); + break; + + case NGCParam_current_tool: + value = (float)gc_state.tool->tool; + break; + + case NGCParam_current_pocket: + value = 0.0f; + break; + + case NGCParam_selected_tool: + value = gc_state.tool_change ? (float)gc_state.tool_pending : -1.0f; + break; + + case NGCParam_selected_pocket: + value = 0.0f; + break; + + default: + value = NAN; + } + + return value; } -static float _motion_mode (void) -{ - return (float)(gc_state.modal.motion * 10); // TODO: Fix G38.x -} - -static float _plane (void) -{ - return (float)(170 + gc_state.modal.plane_select * 10); -} - -static float _ccomp (void) -{ - return 400.0f; -} - -static float _metric (void) -{ - return gc_state.modal.units_imperial ? 0.0f : 1.0f; -} - -static float _imperial (void) -{ - return gc_state.modal.units_imperial ? 1.0f : 0.0f; -} - -static float _absolute (void) -{ - return gc_state.modal.distance_incremental ? 0.0f : 1.0f; -} - -static float _incremental (void) -{ - return gc_state.modal.distance_incremental ? 1.0f : 0.0f; -} - -static float _inverse_time (void) -{ - return gc_state.modal.feed_mode == FeedMode_InverseTime ? 1.0f : 0.0f; -} - -static float _units_per_minute (void) -{ - return gc_state.modal.feed_mode == FeedMode_UnitsPerMin ? 1.0f : 0.0f; -} - -static float _units_per_rev (void) -{ - return gc_state.modal.feed_mode == FeedMode_UnitsPerRev ? 1.0f : 0.0f; -} - -static float _coord_system (void) -{ - uint_fast16_t id = gc_state.modal.coord_system.id * 10; - - if(id > (CoordinateSystem_G59 * 10)) - id = (CoordinateSystem_G59 * 10) + gc_state.modal.coord_system.id - CoordinateSystem_G59; - - return (float)(540 + id); -} - -static float _tool_offset (void) -{ - return gc_state.modal.tool_offset_mode >= ToolLengthOffset_Enable ? 1.0f : 0.0f; -} - -static float _retract_r_plane (void) -{ - return gc_state.modal.retract_mode == CCRetractMode_Previous ? 1.0f : 0.0f; -} - -static float _retract_old_z (void) -{ - return gc_state.modal.retract_mode == CCRetractMode_RPos ? 1.0f : 0.0f; -} - -static float _spindle_rpm_mode (void) -{ - return gc_state.modal.spindle_rpm_mode == SpindleSpeedMode_RPM ? 1.0f : 0.0f; -} - -static float _spindle_css_mode (void) -{ - return gc_state.modal.spindle_rpm_mode == SpindleSpeedMode_CSS ? 1.0f : 0.0f; -} - -static float _lathe_diameter_mode (void) -{ - return gc_state.modal.diameter_mode ? 1.0f : 0.0f; -} - -static float _lathe_radius_mode (void) -{ - return gc_state.modal.diameter_mode ? 0.0f : 1.0f; -} - -static float _spindle_on (void) -{ - return gc_state.modal.spindle.on ? 1.0f : 0.0f; -} - -static float _spindle_cw (void) -{ - return gc_state.modal.spindle.ccw ? 1.0f : 0.0f; -} - -static float _mist (void) -{ - return gc_state.modal.coolant.mist ? 1.0f : 0.0f; -} - -static float _flood (void) -{ - return gc_state.modal.coolant.flood ? 1.0f : 0.0f; -} - -static float _speed_override (void) -{ - return gc_state.modal.override_ctrl.spindle_rpm_disable ? 0.0f : 1.0f; -} - -static float _feed_override (void) -{ - return gc_state.modal.override_ctrl.feed_rate_disable ? 0.0f : 1.0f; -} - -static float _feed_hold (void) -{ - return gc_state.modal.override_ctrl.feed_hold_disable ? 0.0f : 1.0f; -} - -static float _feed (void) -{ - return gc_state.feed_rate; -} - -static float _rpm (void) -{ - return gc_state.spindle.rpm; -} - -static float _x (void) -{ - return _relative_pos(X_AXIS); -} - -static float _y (void) -{ - return _relative_pos(Y_AXIS); -} - -static float _z (void) -{ - return _relative_pos(Z_AXIS); -} - -static float _a (void) -{ -#ifdef A_AXIS - return _relative_pos(A_AXIS); -#else - return 0.0f; -#endif -} - -static float _b (void) -{ -#ifdef B_AXIS - return _relative_pos(B_AXIS); -#else - return 0.0f; -#endif -} - -static float _c (void) -{ -#ifdef C_AXIS - return _relative_pos(C_AXIS); -#else - return 0.0f; -#endif -} - -static float _current_tool (void) -{ - return (float)gc_state.tool->tool; -} - -static float _selected_tool (void) -{ - return gc_state.tool_change ? (float)gc_state.tool_pending : -1.0f; -} - -static float _false (void) -{ - return 0.0f; -} - -static float _true (void) -{ - return 1.0f; -} - -PROGMEM static const ngc_named_ro_param_t ngc_named_ro_param[] = { - { .name = "_vmajor", .get = _true }, - { .name = "_vminor", .get = _true }, - { .name = "_line", .get = _line }, - { .name = "_motion_mode", .get = _motion_mode }, - { .name = "_plane", .get = _plane }, - { .name = "_ccomp", .get = _ccomp }, - { .name = "_metric", .get = _metric }, - { .name = "_imperial", .get = _imperial }, - { .name = "_absolute", .get = _absolute }, - { .name = "_incremental", .get = _incremental }, - { .name = "_inverse_time", .get = _inverse_time }, - { .name = "_units_per_minute", .get = _units_per_minute }, - { .name = "_units_per_rev", .get = _units_per_rev }, - { .name = "_coord_system", .get = _coord_system }, - { .name = "_tool_offset", .get = _tool_offset }, - { .name = "_retract_r_plane", .get = _retract_r_plane }, - { .name = "_retract_old_z", .get = _retract_old_z }, - { .name = "_spindle_rpm_mode", .get = _spindle_rpm_mode }, - { .name = "_spindle_css_mode", .get = _spindle_css_mode }, - { .name = "_ijk_absolute_mode", .get = _false }, - { .name = "_lathe_diameter_mode", .get = _lathe_diameter_mode }, - { .name = "_lathe_radius_mode", .get = _lathe_radius_mode }, - { .name = "_spindle_on", .get = _spindle_on }, - { .name = "_spindle_cw", .get = _spindle_cw }, - { .name = "_mist", .get = _mist }, - { .name = "_flood", .get = _flood }, - { .name = "_speed_override", .get = _speed_override }, - { .name = "_feed_override", .get = _feed_override }, - { .name = "_adaptive_feed", .get = _false }, - { .name = "_feed_hold", .get = _feed_hold }, - { .name = "_feed", .get = _feed }, - { .name = "_rpm", .get = _rpm }, - { .name = "_x", .get = _x }, // = 5420 - { .name = "_y", .get = _y }, // = 5421 - { .name = "_z", .get = _z }, // = 5422 - { .name = "_a", .get = _a }, // = 5423 - { .name = "_b", .get = _b }, // = 5424 - { .name = "_c", .get = _c }, // = 5425 - { .name = "_u", .get = _false }, // = 5426 - { .name = "_v", .get = _false }, // = 5427 - { .name = "_w", .get = _false }, // = 5428 - { .name = "_current_tool", .get = _current_tool }, - { .name = "_current_pocket", .get = _false }, - { .name = "_selected_tool", .get = _selected_tool }, - { .name = "_selected_pocket", .get = _false } -}; - bool ngc_named_param_get (char *name, float *value) { char c, *s = name; @@ -557,7 +541,7 @@ bool ngc_named_param_get (char *name, float *value) if(*name == '_') do { idx--; if((found = !strcmp(name, ngc_named_ro_param[idx].name))) - *value = ngc_named_ro_param[idx].get(); + *value = ngc_named_param_get_by_id(ngc_named_ro_param[idx].id); } while(idx && !found); if(!found) { @@ -587,6 +571,7 @@ bool ngc_named_param_exists (char *name) // Check if name is supplied, return false if not. if((*name == '_' ? *(name + 1) : *name) == '\0') + return false; // Check if it is a (read only) predefined parameter. if(*name == '_') do { diff --git a/ngc_params.h b/ngc_params.h index d4517ff..38052fa 100644 --- a/ngc_params.h +++ b/ngc_params.h @@ -35,11 +35,61 @@ typedef struct { float value; } ngc_param_t; +typedef enum { + NGCParam_vmajor, + NGCParam_vminor, + NGCParam_line, + NGCParam_motion_mode, + NGCParam_plane, + NGCParam_ccomp, + NGCParam_metric, + NGCParam_imperial, + NGCParam_absolute, + NGCParam_incremental, + NGCParam_inverse_time, + NGCParam_units_per_minute, + NGCParam_units_per_rev, + NGCParam_coord_system, + NGCParam_tool_offset, + NGCParam_retract_r_plane, + NGCParam_retract_old_z, + NGCParam_spindle_rpm_mode, + NGCParam_spindle_css_mode, + NGCParam_ijk_absolute_mode, + NGCParam_lathe_diameter_mode, + NGCParam_lathe_radius_mode, + NGCParam_spindle_on, + NGCParam_spindle_cw, + NGCParam_mist, + NGCParam_flood, + NGCParam_speed_override, + NGCParam_feed_override, + NGCParam_adaptive_feed, + NGCParam_feed_hold, + NGCParam_feed, + NGCParam_rpm, + NGCParam_x, + NGCParam_y, + NGCParam_z, + NGCParam_a, + NGCParam_b, + NGCParam_c, + NGCParam_u, + NGCParam_v, + NGCParam_w, + NGCParam_current_tool, + NGCParam_current_pocket, + NGCParam_selected_tool, + NGCParam_selected_pocket, + NGCParam_Last +} ncg_name_param_id_t; + bool ngc_param_get (ngc_param_id_t id, float *value); bool ngc_param_set (ngc_param_id_t id, float value); bool ngc_param_is_rw (ngc_param_id_t id); bool ngc_param_exists (ngc_param_id_t id); bool ngc_named_param_get (char *name, float *value); +float ngc_named_param_get_by_id (ncg_name_param_id_t id); bool ngc_named_param_set (char *name, float value); bool ngc_named_param_exists (char *name); diff --git a/planner.c b/planner.c index 9ba9ecd..b3bd33d 100644 --- a/planner.c +++ b/planner.c @@ -315,7 +315,7 @@ inline static float plan_compute_profile_parameters (plan_block_t *block, float } // Re-calculates buffered motions profile parameters upon a motion-based override change. -static void plan_update_velocity_profile_parameters () +void plan_update_velocity_profile_parameters () { plan_block_t *block = block_buffer_tail; float prev_nominal_speed = SOME_LARGE_VALUE; // Set high for first block nominal speed calculation. diff --git a/settings.c b/settings.c index 78d19ec..4cbfffc 100644 --- a/settings.c +++ b/settings.c @@ -511,7 +511,7 @@ PROGMEM static const setting_descr_t setting_descr[] = { { Setting_StepperIdleLockTime, "Sets a short hold delay when stopping to let dynamics settle before disabling steppers. Value 255 keeps motors enabled." }, { Setting_StepInvertMask, "Inverts the step signals (active low)." }, { Setting_DirInvertMask, "Inverts the direction signals (active low)." }, - { Setting_InvertStepperEnable, "Inverts the stepper driver enable signals (active low). If the stepper drivers shares the same enable signal only X is used." }, + { Setting_InvertStepperEnable, "Inverts the stepper driver enable signals (active low). If the stepper drivers shares the same enable signal only X is used." }, { Setting_LimitPinsInvertMask, "Inverts the axis limit input signals." }, { Setting_InvertProbePin, "Inverts the probe input pin signal." }, { Setting_SpindlePWMBehaviour, "" }, @@ -522,10 +522,10 @@ PROGMEM static const setting_descr_t setting_descr[] = { { Setting_JunctionDeviation, "Sets how fast Grbl travels through consecutive motions. Lower value slows it down." }, { Setting_ArcTolerance, "Sets the G2 and G3 arc tracing accuracy based on radial error. Beware: A very small value may effect performance." }, { Setting_ReportInches, "Enables inch units when returning any position and rate value that is not a settings value." }, - { Setting_ControlInvertMask, "Inverts the control signals (active low).\\n" + { Setting_ControlInvertMask, "Inverts the control signals (active low).\\n" "NOTE: Block delete, Optional stop, EStop and Probe connected are optional signals, availability is driver dependent." }, - { Setting_CoolantInvertMask, "Inverts the coolant and mist signals (active low)." }, + { Setting_CoolantInvertMask, "Inverts the coolant and mist signals (active low)." }, { Setting_SpindleInvertMask, "Inverts the spindle on, counterclockwise and PWM signals (active low)." }, { Setting_ControlPullUpDisableMask, "Disable the control signals pullup resistors. Potentially enables pulldown resistor if available.\\n" "NOTE: Block delete, Optional stop and EStop are optional signals, availability is driver dependent." diff --git a/stream.h b/stream.h index 4f180f6..46e3ac5 100644 --- a/stream.h +++ b/stream.h @@ -242,6 +242,16 @@ typedef struct { char data[BLOCK_TX_BUFFER_SIZE]; } stream_block_tx_buffer_t; +// double buffered tx stream +typedef struct { + uint_fast16_t length; + uint_fast16_t max_length; + char *s; + bool use_tx2data; + char data[BLOCK_TX_BUFFER_SIZE]; + char data2[BLOCK_TX_BUFFER_SIZE]; +} stream_block_tx_buffer2_t; + #ifdef __cplusplus extern "C" { #endif diff --git a/tool_change.c b/tool_change.c index f98abd0..42bda5b 100644 --- a/tool_change.c +++ b/tool_change.c @@ -37,7 +37,7 @@ #define TOOL_CHANGE_PROBE_RETRACT_DISTANCE 2.0f #endif -static bool block_cycle_start; +static bool block_cycle_start, probe_fixture; static volatile bool execute_posted = false; static volatile uint32_t spin_lock = 0; static float tool_change_position; @@ -78,8 +78,11 @@ static void change_completed (void) hal.irq_enable(); } + if(probe_fixture) + grbl.on_probe_fixture(false); + grbl.on_probe_completed = NULL; - gc_state.tool_change = false; + gc_state.tool_change = probe_fixture = false; } @@ -171,6 +174,9 @@ static void execute_probe (sys_state_t state) plan_line_data_t plan_data = {0}; gc_parser_flags_t flags = {0}; + if(probe_fixture) + grbl.on_probe_fixture(true); + // G59.3 contains offsets to position of TLS. settings_read_coord_data(CoordinateSystem_G59_3, &offset.values); @@ -321,6 +327,8 @@ static status_code_t tool_change (parser_state_t *parser_state) hal.coolant.set_state((coolant_state_t){0}); execute_posted = false; + probe_fixture = grbl.on_probe_fixture != NULL && + (settings.tool_change.mode == ToolChange_Manual_G59_3 || settings.tool_change.mode == ToolChange_SemiAutomatic); parser_state->tool_change = true; // Save current position. @@ -434,6 +442,9 @@ status_code_t tc_probe_workpiece (void) gc_parser_flags_t flags = {0}; plan_line_data_t plan_data = {0}; + if(probe_fixture) + grbl.on_probe_fixture(true); + // Get current position. system_convert_array_steps_to_mpos(target.values, sys.position);