1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-30 01:30:05 +02:00

Fixes to homing (#706)

* Fixes to homing

* Update Grbl.h

* Clean up after code review.
This commit is contained in:
bdring
2020-12-13 13:29:47 -06:00
committed by GitHub
parent 8e3e23c148
commit 6a0e3a7335
6 changed files with 40 additions and 22 deletions

View File

@@ -51,9 +51,15 @@ float three_axis_dist(float* point1, float* point2);
void machine_init() {
// print a startup message to show the kinematics are enable
#ifdef MIDTBOT
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "CoreXY (midTbot) Kinematics Init");
#else
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "CoreXY Kinematics Init");
#endif
}
// Cycle mask is 0 unless the user sends a single axis command like $HZ
// This will always return true to prevent the normal Grbl homing cycle
bool user_defined_homing(uint8_t cycle_mask) {
uint8_t n_cycle; // each home is a multi cycle operation approach, pulloff, approach.....
@@ -61,12 +67,6 @@ bool user_defined_homing(uint8_t cycle_mask) {
float max_travel;
uint8_t axis;
// check for single axis homing
if (cycle_mask != 0) {
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "CoreXY Single axis homing not allowed. Use $H only");
return true;
}
// check for multi axis homing per cycle ($Homing/Cycle0=XY type)...not allowed in CoreXY
bool setting_error = false;
for (int cycle = 0; cycle < 3; cycle++) {
@@ -90,9 +90,21 @@ bool user_defined_homing(uint8_t cycle_mask) {
pl_data->motion.systemMotion = 1;
pl_data->motion.noFeedOverride = 1;
for (int cycle = 0; cycle < 3; cycle++) {
AxisMask mask = homing_cycle[cycle]->get();
uint8_t cycle_count = (cycle_mask == 0) ? 3 : 1; // if we have a cycle_mask, we are only going to do one axis
AxisMask mask = 0;
for (int cycle = 0; cycle < cycle_count; cycle++) {
// if we have a cycle_mask, do that. Otherwise get the cycle from the settings
mask = cycle_mask ? cycle_mask : homing_cycle[cycle]->get();
// If not X or Y do a normal home
if (!(bitnum_istrue(mask, X_AXIS) || bitnum_istrue(mask, Y_AXIS))) {
limits_go_home(mask); // Homing cycle 0
continue; // continue to next item in for loop
}
mask = motors_set_homing_mode(mask, true); // non standard homing motors will do their own thing and get removed from the mask
for (uint8_t axis = X_AXIS; axis <= Z_AXIS; axis++) {
if (bit(axis) == mask) {
// setup for the homing of this axis
@@ -190,7 +202,7 @@ bool user_defined_homing(uint8_t cycle_mask) {
} while (n_cycle-- > 0);
}
}
}
} // for
// after sussefully setting X & Y axes, we set the current positions
@@ -231,7 +243,7 @@ void inverse_kinematics(float* position) {
motors[X_AXIS] = geometry_factor * position[X_AXIS] + position[Y_AXIS];
motors[Y_AXIS] = geometry_factor * position[X_AXIS] - position[Y_AXIS];
motors[Z_AXIS] = position[Z_AXIS];
motors[Z_AXIS] = position[Z_AXIS];
position[0] = motors[0];
position[1] = motors[1];

View File

@@ -23,7 +23,7 @@
// Grbl versioning system
const char* const GRBL_VERSION = "1.3a";
const char* const GRBL_VERSION_BUILD = "20201207";
const char* const GRBL_VERSION_BUILD = "20201212";
//#include <sdkconfig.h>
#include <Arduino.h>

View File

@@ -44,10 +44,14 @@ namespace Motors {
}
void StandardStepper::init() {
init_step_dir_pins();
read_settings();
config_message();
}
void StandardStepper::read_settings() {
init_step_dir_pins();
}
void StandardStepper::init_step_dir_pins() {
_invert_step_pin = bitnum_istrue(step_invert_mask->get(), _axis_index);
_invert_dir_pin = bitnum_istrue(dir_invert_mask->get(), _axis_index);

View File

@@ -15,6 +15,7 @@ namespace Motors {
void set_direction(bool) override;
void step() override;
void unstep() override;
void read_settings() override;
void init_step_dir_pins();

View File

@@ -67,8 +67,7 @@ namespace Motors {
return;
}
_has_errors = false;
init_step_dir_pins(); // from StandardStepper
_has_errors = false;
digitalWrite(_cs_pin, HIGH);
pinMode(_cs_pin, OUTPUT);
@@ -211,6 +210,8 @@ namespace Motors {
}
tmcstepper->microsteps(axis_settings[_axis_index]->microsteps->get());
tmcstepper->rms_current(run_i_ma, hold_i_percent);
init_step_dir_pins();
}
bool TrinamicDriver::set_homing_mode(bool isHoming) {

View File

@@ -179,7 +179,7 @@ static bool checkStartupLine(char* value) {
return gc_execute_line(value, CLIENT_SERIAL) == Error::Ok;
}
static bool postTMC(char* value) {
static bool postMotorSetting(char* value) {
if (!value) {
motors_read_settings();
}
@@ -258,28 +258,28 @@ void make_settings() {
for (axis = MAX_N_AXIS - 1; axis >= 0; axis--) {
def = &axis_defaults[axis];
auto setting =
new IntSetting(EXTENDED, WG, makeGrblName(axis, 170), makename(def->name, "StallGuard"), def->stallguard, -64, 63, postTMC);
new IntSetting(EXTENDED, WG, makeGrblName(axis, 170), makename(def->name, "StallGuard"), def->stallguard, -64, 63, postMotorSetting);
setting->setAxis(axis);
axis_settings[axis]->stallguard = setting;
}
for (axis = MAX_N_AXIS - 1; axis >= 0; axis--) {
def = &axis_defaults[axis];
auto setting =
new IntSetting(EXTENDED, WG, makeGrblName(axis, 160), makename(def->name, "Microsteps"), def->microsteps, 0, 256, postTMC);
new IntSetting(EXTENDED, WG, makeGrblName(axis, 160), makename(def->name, "Microsteps"), def->microsteps, 0, 256, postMotorSetting);
setting->setAxis(axis);
axis_settings[axis]->microsteps = setting;
}
for (axis = MAX_N_AXIS - 1; axis >= 0; axis--) {
def = &axis_defaults[axis];
auto setting = new FloatSetting(
EXTENDED, WG, makeGrblName(axis, 150), makename(def->name, "Current/Hold"), def->hold_current, 0.05, 20.0, postTMC); // Amps
EXTENDED, WG, makeGrblName(axis, 150), makename(def->name, "Current/Hold"), def->hold_current, 0.05, 20.0, postMotorSetting); // Amps
setting->setAxis(axis);
axis_settings[axis]->hold_current = setting;
}
for (axis = MAX_N_AXIS - 1; axis >= 0; axis--) {
def = &axis_defaults[axis];
auto setting = new FloatSetting(
EXTENDED, WG, makeGrblName(axis, 140), makename(def->name, "Current/Run"), def->run_current, 0.0, 20.0, postTMC); // Amps
EXTENDED, WG, makeGrblName(axis, 140), makename(def->name, "Current/Run"), def->run_current, 0.0, 20.0, postMotorSetting); // Amps
setting->setAxis(axis);
axis_settings[axis]->run_current = setting;
}
@@ -377,12 +377,12 @@ void make_settings() {
probe_invert = new FlagSetting(GRBL, WG, "6", "Probe/Invert", DEFAULT_INVERT_PROBE_PIN);
limit_invert = new FlagSetting(GRBL, WG, "5", "Limits/Invert", DEFAULT_INVERT_LIMIT_PINS);
step_enable_invert = new FlagSetting(GRBL, WG, "4", "Stepper/EnableInvert", DEFAULT_INVERT_ST_ENABLE);
dir_invert_mask = new AxisMaskSetting(GRBL, WG, "3", "Stepper/DirInvert", DEFAULT_DIRECTION_INVERT_MASK);
step_invert_mask = new AxisMaskSetting(GRBL, WG, "2", "Stepper/StepInvert", DEFAULT_STEPPING_INVERT_MASK);
dir_invert_mask = new AxisMaskSetting(GRBL, WG, "3", "Stepper/DirInvert", DEFAULT_DIRECTION_INVERT_MASK, postMotorSetting);
step_invert_mask = new AxisMaskSetting(GRBL, WG, "2", "Stepper/StepInvert", DEFAULT_STEPPING_INVERT_MASK, postMotorSetting);
stepper_idle_lock_time = new IntSetting(GRBL, WG, "1", "Stepper/IdleTime", DEFAULT_STEPPER_IDLE_LOCK_TIME, 0, 255);
pulse_microseconds = new IntSetting(GRBL, WG, "0", "Stepper/Pulse", DEFAULT_STEP_PULSE_MICROSECONDS, 3, 1000);
stallguard_debug_mask = new AxisMaskSetting(EXTENDED, WG, NULL, "Report/StallGuard", 0, postTMC);
stallguard_debug_mask = new AxisMaskSetting(EXTENDED, WG, NULL, "Report/StallGuard", 0, postMotorSetting);
homing_cycle[5] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle5", DEFAULT_HOMING_CYCLE_5);
homing_cycle[4] = new AxisMaskSetting(EXTENDED, WG, NULL, "Homing/Cycle4", DEFAULT_HOMING_CYCLE_4);