Homing question/request
I know you can home and set that position to 0/0. Is there a way to home and set that position to other coordinates?
I want 0/0 to be lower left but I home to upper left. My other software I use on another machine let's you set the home position to any coordinates you want but I don't see a way in grblhal. Is this possible now or can it be added?
It's an interesting concept. I don't believe this is supported but here are a few ideas.
You can definitely change the homing direction using $23. As for setting home to arbitrary coordinates, see this discussion: https://github.com/grbl/grbl/issues/257.
I think your best option is to home the physical machine to upper left, but then set up an offset work coordinate system with 0,0 in the lower left as required by your job. I don't know if soft limits would be supported in this configuration.
@terjeio could you shed some light on whether working in the negative machine coordinate space is possible?
Working in the negative is definitely possible and not a problem until you want to use absolute coordinates. Then you have to remember it's negative. That's why other software allows for setting the home to whatever coordinates you want which keeps the absolute in the positive. There are easy workarounds, like the link you posted, but just being able to enter it in the config would be more elegant.
Is there a way to home and set that position to other coordinates?
Yes, a plugin can be written that expands on the current functionality. Internally a work envelope is kept that holds the min and max values of the machine coordinate system. This is set prior to firing the on_homing_completed event. If subscribed to by a plugin it can then set the work envelope to whatever it sees fit.
In addition the functions for handling limits checks can also be overridden by a plugin since they are called via function pointers initialized on boot. If overridden all kinds of work envelopes can be implemented, circular, oval, ... These do not have to use the internal work envelope variables. If the internal variables are used and the work envelope is rectangular it is a fair chance that the provided functions will work as-is - though this needs to be verified.
I'm referring more to adding that option to the current homing settings. Add another option with "set home to - X=zzz Y=zzz" along with the other homing options such as set home to 0/0. Can you add something like that?
Adding the option to the core will trigger a settings revision which I am not yet ready for. A plugin can add settings without affecting the core.
Here is a skeleton plugin to start with, I would appreciate if someone can add the missing code and verify it. If not I can put it on my todo list for later.
#include "grbl/hal.h"
#include "grbl/nvs_buffer.h"
typedef union
{
uint8_t value;
struct {
uint8_t opt1 :1,
opt2 :1,
opt3 :1,
undefined :5;
};
} adv_homing_flags_t;
typedef struct {
adv_homing_flags_t flags;
coord_data_t home_position;
} adv_homing_settings_t;
static adv_homing_settings_t adv_homing_settings;
static nvs_address_t nvs_address;
static on_report_options_ptr on_report_options;
static on_homing_completed_ptr on_homing_completed = NULL;
static const setting_detail_t user_settings[] = {
{ Setting_UserDefined_0, Group_Homing, "Adv. options", NULL, Format_Bitfield, "Opt1,Opt2,Opt3", NULL, NULL, Setting_NonCore, &adv_homing_settings.flags.value, NULL, NULL },
{ Setting_UserDefined_1, Group_Homing, "X home", "mm", Format_Decimal, "#####0.000", NULL, NULL, Setting_NonCore, &adv_homing_settings.home_position.x, NULL, NULL },
{ Setting_UserDefined_2, Group_Homing, "Y home", "mm", Format_Decimal, "#####0.000", NULL, NULL, Setting_NonCore, &adv_homing_settings.home_position.y, NULL, NULL },
};
static const setting_descr_t user_settings_descr[] = {
{ Setting_UserDefined_0, "Advanced homing options." },
{ Setting_UserDefined_1, "X home position." },
{ Setting_UserDefined_2, "Y home position." },
};
static void plugin_settings_save (void)
{
hal.nvs.memcpy_to_nvs(nvs_address, (uint8_t *)&adv_homing_settings, sizeof(adv_homing_settings_t), true);
}
static void plugin_settings_restore (void)
{
memset(&adv_homing_settings, 0, sizeof(adv_homing_settings_t));
hal.nvs.memcpy_to_nvs(nvs_address, (uint8_t *)&adv_homing_settings, sizeof(adv_homing_settings_t), true);
}
static void plugin_settings_load (void)
{
if(hal.nvs.memcpy_from_nvs((uint8_t *)&adv_homing_settings, nvs_address, sizeof(adv_homing_settings_t), true) != NVS_TransferResult_OK)
plugin_settings_restore();
}
static void onHomingComplete (axes_signals_t cycle, bool success)
{
if(success) {
if(adv_homing_settings.flags.opt1) {
// set sys.position[] and sys.home_position[] for axes homed in cycle if need to be changed - see limits_set_machine_positions(()
// set sys.work_envelope - see limits_set_work_envelope()
// ...
} // else ...
}
if(on_homing_completed)
on_homing_completed(cycle, success);
}
static void onReportOptions (bool newopt)
{
on_report_options(newopt);
if(!newopt)
report_plugin("Advanced homing", "0.0");
}
void my_plugin_init (void)
{
static setting_details_t setting_details = {
.settings = user_settings,
.n_settings = sizeof(user_settings) / sizeof(setting_detail_t),
.descriptions = user_settings_descr,
.n_descriptions = sizeof(user_settings_descr) / sizeof(setting_descr_t),
.save = plugin_settings_save,
.load = plugin_settings_load,
.restore = plugin_settings_restore
};
if((nvs_address = nvs_alloc(sizeof(adv_homing_settings_t)))) {
on_report_options = grbl.on_report_options;
grbl.on_report_options = onReportOptions;
on_homing_completed = grbl.on_homing_completed;
grbl.on_homing_completed = onHomingComplete;
settings_register(&setting_details);
}
}
I think I found another reason to add this but maybe I'm just missing it. Is there an offset for homing? What I mean is if the home switch is farther negative than zero, in other programs (even Marlin for printers) you can tell the software to offset by the amount of the negative value. Is this already available somewhere?
$27 is the homing pull off distance, not sure if this is what you want.