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:
@@ -19,6 +19,7 @@ axes:
|
|||||||
acceleration: 25
|
acceleration: 25
|
||||||
max_travel: 1000
|
max_travel: 1000
|
||||||
homing:
|
homing:
|
||||||
|
cycle: 2
|
||||||
mpos: 10
|
mpos: 10
|
||||||
positive_direction: false
|
positive_direction: false
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ axes:
|
|||||||
acceleration: 25
|
acceleration: 25
|
||||||
max_travel: 1000
|
max_travel: 1000
|
||||||
homing:
|
homing:
|
||||||
|
cycle: 2
|
||||||
mpos: 10
|
mpos: 10
|
||||||
positive_direction: false
|
positive_direction: false
|
||||||
|
|
||||||
@@ -55,6 +57,7 @@ axes:
|
|||||||
acceleration: 25
|
acceleration: 25
|
||||||
max_travel: 1000
|
max_travel: 1000
|
||||||
homing:
|
homing:
|
||||||
|
cycle: 1
|
||||||
mpos: 10
|
mpos: 10
|
||||||
positive_direction: true
|
positive_direction: true
|
||||||
|
|
||||||
|
@@ -39,30 +39,24 @@ namespace Machine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Axes::set_disable(bool disable) {
|
void Axes::set_disable(int axis, bool disable) {
|
||||||
static bool previous_state = true;
|
for (int gang_index = 0; gang_index < Axis::MAX_NUMBER_GANGED; gang_index++) {
|
||||||
|
auto a = _axis[axis]->_gangs[gang_index]->_motor;
|
||||||
//info_serial("Motors disable %d", disable);
|
a->set_disable(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++) {
|
|
||||||
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.
|
// invert only inverts the global stepper disable pin.
|
||||||
_sharedStepperDisable.write(disable);
|
_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() {
|
void Axes::read_settings() {
|
||||||
//info_serial("Read Settings");
|
//info_serial("Read Settings");
|
||||||
for (uint8_t axis = X_AXIS; axis < _numberAxis; axis++) {
|
for (uint8_t axis = X_AXIS; axis < _numberAxis; axis++) {
|
||||||
@@ -197,16 +191,14 @@ namespace Machine {
|
|||||||
handler.item("number_axis", _numberAxis);
|
handler.item("number_axis", _numberAxis);
|
||||||
handler.item("shared_stepper_disable", _sharedStepperDisable);
|
handler.item("shared_stepper_disable", _sharedStepperDisable);
|
||||||
|
|
||||||
const char* allAxis = "xyzabc";
|
|
||||||
|
|
||||||
char tmp[3];
|
char tmp[3];
|
||||||
tmp[2] = '\0';
|
tmp[2] = '\0';
|
||||||
|
|
||||||
for (size_t a = 0; a < MAX_NUMBER_AXIS; ++a) {
|
for (size_t i = 0; i < MAX_NUMBER_AXIS; ++i) {
|
||||||
tmp[0] = allAxis[a];
|
tmp[0] = tolower(_names[i]);
|
||||||
tmp[1] = '\0';
|
tmp[1] = '\0';
|
||||||
|
|
||||||
handler.section(tmp, _axis[a]);
|
handler.section(tmp, _axis[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,11 +27,14 @@ namespace Motors {
|
|||||||
|
|
||||||
namespace Machine {
|
namespace Machine {
|
||||||
class Axes : public Configuration::Configurable {
|
class Axes : public Configuration::Configurable {
|
||||||
static const int MAX_NUMBER_AXIS = 6;
|
static const int MAX_NUMBER_AXIS = 6;
|
||||||
|
static constexpr const char* _names = "XYZABC";
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Axes();
|
Axes();
|
||||||
|
|
||||||
|
inline char axisName(int index) { return index < MAX_NUMBER_AXIS ? _names[index] : '?'; }
|
||||||
|
|
||||||
Pin _sharedStepperDisable;
|
Pin _sharedStepperDisable;
|
||||||
|
|
||||||
int _numberAxis = 3;
|
int _numberAxis = 3;
|
||||||
@@ -68,6 +71,7 @@ namespace Machine {
|
|||||||
|
|
||||||
// The return value is a bitmask of axes that can home
|
// The return value is a bitmask of axes that can home
|
||||||
uint8_t set_homing_mode(uint8_t homing_mask, bool isHoming);
|
uint8_t set_homing_mode(uint8_t homing_mask, bool isHoming);
|
||||||
|
void set_disable(int axis, bool disable);
|
||||||
void set_disable(bool disable);
|
void set_disable(bool disable);
|
||||||
void step(uint8_t step_mask, uint8_t dir_mask);
|
void step(uint8_t step_mask, uint8_t dir_mask);
|
||||||
void unstep();
|
void unstep();
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
#include "Configuration/AfterParse.h"
|
#include "Configuration/AfterParse.h"
|
||||||
#include "Configuration/Validator.h"
|
#include "Configuration/Validator.h"
|
||||||
#include "Configuration/ParseException.h"
|
#include "Configuration/ParseException.h"
|
||||||
|
#include "Machine/Axes.h"
|
||||||
#include "Regex.h"
|
#include "Regex.h"
|
||||||
#include "WebUI/Authentication.h"
|
#include "WebUI/Authentication.h"
|
||||||
#include "WebUI/WifiConfig.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) {
|
Error motor_disable(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) {
|
||||||
char* s;
|
while (value && isspace(*value)) {
|
||||||
if (value == NULL) {
|
++value;
|
||||||
value = "\0";
|
}
|
||||||
|
if (!value || *value == '\0') {
|
||||||
|
info_all("Disabling all motors");
|
||||||
|
config->_axes->set_disable(true);
|
||||||
|
return Error::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = strdup(value);
|
auto axes = config->_axes;
|
||||||
s = trim(s);
|
|
||||||
|
|
||||||
int32_t convertedValue;
|
if (axes->_sharedStepperDisable.defined()) {
|
||||||
char* endptr;
|
info_all("Cannot disable individual axes with a shared disable pin");
|
||||||
if (*s == '\0') {
|
return Error::InvalidStatement;
|
||||||
convertedValue = 255; // all axes
|
}
|
||||||
} else {
|
|
||||||
convertedValue = strtol(s, &endptr, 10);
|
for (int i = 0; i < config->_axes->_numberAxis; i++) {
|
||||||
if (endptr == s || *endptr != '\0') {
|
char axisName = axes->axisName(i);
|
||||||
// Try to convert as an axis list
|
|
||||||
convertedValue = 0;
|
if (strchr(value, axisName) || strchr(value, tolower(axisName))) {
|
||||||
auto axisNames = String("XYZABC");
|
info_all("Disabling %c motors", axisName);
|
||||||
while (*s) {
|
axes->set_disable(i, true);
|
||||||
int index = axisNames.indexOf(toupper(*s++));
|
|
||||||
if (index < 0) {
|
|
||||||
return Error::BadNumberFormat;
|
|
||||||
}
|
|
||||||
convertedValue |= bit(index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef LATER
|
|
||||||
motors_set_disable(true, convertedValue);
|
|
||||||
#endif
|
|
||||||
return Error::Ok;
|
return Error::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -877,25 +877,6 @@ char* report_state_text() {
|
|||||||
return state;
|
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) {
|
char* reportAxisLimitsMsg(uint8_t axis) {
|
||||||
static char msg[40];
|
static char msg[40];
|
||||||
sprintf(msg, "Limits(%0.3f,%0.3f)", limitsMinPosition(axis), limitsMaxPosition(axis));
|
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) {
|
char* reportAxisNameMsg(uint8_t axis, uint8_t dual_axis) {
|
||||||
static char name[10];
|
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;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* reportAxisNameMsg(uint8_t axis) {
|
char* reportAxisNameMsg(uint8_t axis) {
|
||||||
static char name[10];
|
static char name[10];
|
||||||
sprintf(name, "%c Axis", report_get_axis_letter(axis));
|
sprintf(name, "%c Axis", config->_axes->axisName(axis));
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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(char* buf, const char* prefix, int len);
|
||||||
void report_hex_msg(uint8_t* 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* reportAxisLimitsMsg(uint8_t axis);
|
||||||
char* reportAxisNameMsg(uint8_t axis);
|
char* reportAxisNameMsg(uint8_t axis);
|
||||||
char* reportAxisNameMsg(uint8_t axis, uint8_t dual_axis);
|
char* reportAxisNameMsg(uint8_t axis, uint8_t dual_axis);
|
||||||
|
@@ -31,12 +31,7 @@
|
|||||||
#include "../Report.h" // info_serial
|
#include "../Report.h" // info_serial
|
||||||
|
|
||||||
namespace Spindles {
|
namespace Spindles {
|
||||||
H2A::H2A() : VFD() {
|
H2A::H2A() : VFD() {}
|
||||||
#ifdef LATER
|
|
||||||
_baudrate = 19200;
|
|
||||||
_parity = Uart::Parity::Even;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void H2A::direction_command(SpindleState mode, ModbusCommand& data) {
|
void H2A::direction_command(SpindleState mode, ModbusCommand& data) {
|
||||||
data.tx_length = 6;
|
data.tx_length = 6;
|
||||||
|
@@ -374,14 +374,14 @@ namespace WebUI {
|
|||||||
webPrintln("Incorrect command");
|
webPrintln("Incorrect command");
|
||||||
return Error::InvalidValue;
|
return Error::InvalidValue;
|
||||||
}
|
}
|
||||||
info_all("Restart ongoing");
|
info_all("Restarting");
|
||||||
COMMANDS::restart_ESP();
|
COMMANDS::restart_ESP();
|
||||||
return Error::Ok;
|
return Error::Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Error restart(char* parameter, AuthenticationLevel auth_level) {
|
static Error restart(char* parameter, AuthenticationLevel auth_level) {
|
||||||
parameter = trim(parameter);
|
parameter = trim(parameter);
|
||||||
info_all("Restart ongoing");
|
info_all("Restarting");
|
||||||
COMMANDS::restart_ESP();
|
COMMANDS::restart_ESP();
|
||||||
return Error::Ok;
|
return Error::Ok;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user