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

Fixed motor_disable, removing a LATER

In the process, cleaned up the axis index to name mapping
so it happens in one place, in Axes.
This commit is contained in:
Mitch Bradley
2021-06-27 12:27:29 -10:00
parent e60e5fae4c
commit e2599de958
8 changed files with 48 additions and 79 deletions

View File

@@ -19,6 +19,7 @@ axes:
acceleration: 25
max_travel: 1000
homing:
cycle: 2
mpos: 10
positive_direction: false
@@ -37,6 +38,7 @@ axes:
acceleration: 25
max_travel: 1000
homing:
cycle: 2
mpos: 10
positive_direction: false
@@ -55,6 +57,7 @@ axes:
acceleration: 25
max_travel: 1000
homing:
cycle: 1
mpos: 10
positive_direction: true

View File

@@ -39,30 +39,24 @@ namespace Machine {
}
}
void Axes::set_disable(bool disable) {
static bool previous_state = true;
//info_serial("Motors disable %d", disable);
/*
if (previous_state == disable) {
return;
}
previous_state = disable;
*/
// now loop through all the motors to see if they can individually disable
for (int axis = 0; axis < _numberAxis; axis++) {
void Axes::set_disable(int axis, bool disable) {
for (int gang_index = 0; gang_index < Axis::MAX_NUMBER_GANGED; gang_index++) {
auto a = _axis[axis]->_gangs[gang_index]->_motor;
a->set_disable(disable);
}
}
// invert only inverts the global stepper disable pin.
_sharedStepperDisable.write(disable);
}
void Axes::set_disable(bool disable) {
for (int axis = 0; axis < _numberAxis; axis++) {
set_disable(axis, disable);
}
_sharedStepperDisable.write(disable);
}
void Axes::read_settings() {
//info_serial("Read Settings");
for (uint8_t axis = X_AXIS; axis < _numberAxis; axis++) {
@@ -197,16 +191,14 @@ namespace Machine {
handler.item("number_axis", _numberAxis);
handler.item("shared_stepper_disable", _sharedStepperDisable);
const char* allAxis = "xyzabc";
char tmp[3];
tmp[2] = '\0';
for (size_t a = 0; a < MAX_NUMBER_AXIS; ++a) {
tmp[0] = allAxis[a];
for (size_t i = 0; i < MAX_NUMBER_AXIS; ++i) {
tmp[0] = tolower(_names[i]);
tmp[1] = '\0';
handler.section(tmp, _axis[a]);
handler.section(tmp, _axis[i]);
}
}

View File

@@ -28,10 +28,13 @@ namespace Motors {
namespace Machine {
class Axes : public Configuration::Configurable {
static const int MAX_NUMBER_AXIS = 6;
static constexpr const char* _names = "XYZABC";
public:
Axes();
inline char axisName(int index) { return index < MAX_NUMBER_AXIS ? _names[index] : '?'; }
Pin _sharedStepperDisable;
int _numberAxis = 3;
@@ -68,6 +71,7 @@ namespace Machine {
// The return value is a bitmask of axes that can home
uint8_t set_homing_mode(uint8_t homing_mask, bool isHoming);
void set_disable(int axis, bool disable);
void set_disable(bool disable);
void step(uint8_t step_mask, uint8_t dir_mask);
void unstep();

View File

@@ -5,6 +5,7 @@
#include "Configuration/AfterParse.h"
#include "Configuration/Validator.h"
#include "Configuration/ParseException.h"
#include "Machine/Axes.h"
#include "Regex.h"
#include "WebUI/Authentication.h"
#include "WebUI/WifiConfig.h"
@@ -420,36 +421,30 @@ Error listErrors(const char* value, WebUI::AuthenticationLevel auth_level, WebUI
}
Error motor_disable(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) {
char* s;
if (value == NULL) {
value = "\0";
while (value && isspace(*value)) {
++value;
}
if (!value || *value == '\0') {
info_all("Disabling all motors");
config->_axes->set_disable(true);
return Error::Ok;
}
s = strdup(value);
s = trim(s);
auto axes = config->_axes;
int32_t convertedValue;
char* endptr;
if (*s == '\0') {
convertedValue = 255; // all axes
} else {
convertedValue = strtol(s, &endptr, 10);
if (endptr == s || *endptr != '\0') {
// Try to convert as an axis list
convertedValue = 0;
auto axisNames = String("XYZABC");
while (*s) {
int index = axisNames.indexOf(toupper(*s++));
if (index < 0) {
return Error::BadNumberFormat;
if (axes->_sharedStepperDisable.defined()) {
info_all("Cannot disable individual axes with a shared disable pin");
return Error::InvalidStatement;
}
convertedValue |= bit(index);
for (int i = 0; i < config->_axes->_numberAxis; i++) {
char axisName = axes->axisName(i);
if (strchr(value, axisName) || strchr(value, tolower(axisName))) {
info_all("Disabling %c motors", axisName);
axes->set_disable(i, true);
}
}
}
#ifdef LATER
motors_set_disable(true, convertedValue);
#endif
return Error::Ok;
}

View File

@@ -877,25 +877,6 @@ char* report_state_text() {
return state;
}
char report_get_axis_letter(uint8_t axis) {
switch (axis) {
case X_AXIS:
return 'X';
case Y_AXIS:
return 'Y';
case Z_AXIS:
return 'Z';
case A_AXIS:
return 'A';
case B_AXIS:
return 'B';
case C_AXIS:
return 'C';
default:
return '?';
}
}
char* reportAxisLimitsMsg(uint8_t axis) {
static char msg[40];
sprintf(msg, "Limits(%0.3f,%0.3f)", limitsMinPosition(axis), limitsMaxPosition(axis));
@@ -904,13 +885,13 @@ char* reportAxisLimitsMsg(uint8_t axis) {
char* reportAxisNameMsg(uint8_t axis, uint8_t dual_axis) {
static char name[10];
sprintf(name, "%c%c Axis", report_get_axis_letter(axis), dual_axis ? '2' : ' ');
sprintf(name, "%c%c Axis", config->_axes->axisName(axis), dual_axis ? '2' : ' ');
return name;
}
char* reportAxisNameMsg(uint8_t axis) {
static char name[10];
sprintf(name, "%c Axis", report_get_axis_letter(axis));
sprintf(name, "%c Axis", config->_axes->axisName(axis));
return name;
}

View File

@@ -143,7 +143,6 @@ void report_machine_type(uint8_t client);
void report_hex_msg(char* buf, const char* prefix, int len);
void report_hex_msg(uint8_t* buf, const char* prefix, int len);
char report_get_axis_letter(uint8_t axis);
char* reportAxisLimitsMsg(uint8_t axis);
char* reportAxisNameMsg(uint8_t axis);
char* reportAxisNameMsg(uint8_t axis, uint8_t dual_axis);

View File

@@ -31,12 +31,7 @@
#include "../Report.h" // info_serial
namespace Spindles {
H2A::H2A() : VFD() {
#ifdef LATER
_baudrate = 19200;
_parity = Uart::Parity::Even;
#endif
}
H2A::H2A() : VFD() {}
void H2A::direction_command(SpindleState mode, ModbusCommand& data) {
data.tx_length = 6;

View File

@@ -374,14 +374,14 @@ namespace WebUI {
webPrintln("Incorrect command");
return Error::InvalidValue;
}
info_all("Restart ongoing");
info_all("Restarting");
COMMANDS::restart_ESP();
return Error::Ok;
}
static Error restart(char* parameter, AuthenticationLevel auth_level) {
parameter = trim(parameter);
info_all("Restart ongoing");
info_all("Restarting");
COMMANDS::restart_ESP();
return Error::Ok;
}