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

Trinamic reporting (#656)

* Enhanced reporting of errors

* Change "motor" to "driver" for clarity.

* Added better way to show changed Setting values from Mitch

* Update build date
This commit is contained in:
bdring
2020-11-02 15:34:29 -06:00
committed by GitHub
parent 54d78582ea
commit 44cd6f8954
3 changed files with 101 additions and 30 deletions

View File

@@ -126,7 +126,7 @@ namespace Motors {
void TrinamicDriver::config_message() { void TrinamicDriver::config_message() {
grbl_msg_sendf(CLIENT_SERIAL, grbl_msg_sendf(CLIENT_SERIAL,
MsgLevel::Info, MsgLevel::Info,
"%s Trinamic TMC%d Step:%s Dir:%s CS:%s Disable:%s Index:%d %s", "%s Trinamic TMC%d Step:%s Dir:%s CS:%s Disable:%s Index:%d R:%0.3f %s",
reportAxisNameMsg(_axis_index, _dual_axis_index), reportAxisNameMsg(_axis_index, _dual_axis_index),
_driver_part_number, _driver_part_number,
pinName(_step_pin).c_str(), pinName(_step_pin).c_str(),
@@ -134,6 +134,7 @@ namespace Motors {
pinName(_cs_pin).c_str(), pinName(_cs_pin).c_str(),
pinName(_disable_pin).c_str(), pinName(_disable_pin).c_str(),
_spi_index, _spi_index,
_r_sense,
reportAxisLimitsMsg(_axis_index)); reportAxisLimitsMsg(_axis_index));
} }
@@ -161,24 +162,17 @@ namespace Motors {
status.sr = tmcstepper->DRV_STATUS(); status.sr = tmcstepper->DRV_STATUS();
bool err = false; bool err = false;
// look for open or short to ground on a and b
if (status.s2ga || status.s2gb) { // look for errors
grbl_msg_sendf(CLIENT_SERIAL, if (report_short_to_ground(status)) {
MsgLevel::Info,
"%s Motor Short Coil a:%s b:%s",
reportAxisNameMsg(_axis_index, _dual_axis_index),
status.s2ga ? "Y" : "N",
status.s2gb ? "Y" : "N");
err = true; err = true;
} }
// check for over temp or pre-warning
if (status.ot || status.otpw) { if (report_over_temp(status)) {
grbl_msg_sendf(CLIENT_SERIAL, err = true;
MsgLevel::Info, }
"%s Driver Temp Warning:%s Fault:%s",
reportAxisNameMsg(_axis_index, _dual_axis_index), if (report_short_to_ps(status)) {
status.otpw ? "Y" : "N",
status.ot ? "Y" : "N");
err = true; err = true;
} }
@@ -214,7 +208,6 @@ namespace Motors {
if (hold_i_percent > 1.0) if (hold_i_percent > 1.0)
hold_i_percent = 1.0; hold_i_percent = 1.0;
} }
//grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "%s Current run %d hold %f", reportAxisNameMsg(_axis_index, _dual_axis_index), run_i_ma, hold_i_percent);
tmcstepper->microsteps(axis_settings[_axis_index]->microsteps->get()); tmcstepper->microsteps(axis_settings[_axis_index]->microsteps->get());
tmcstepper->rms_current(run_i_ma, hold_i_percent); tmcstepper->rms_current(run_i_ma, hold_i_percent);
@@ -293,6 +286,22 @@ namespace Motors {
tmcstepper->sg_result(), tmcstepper->sg_result(),
feedrate, feedrate,
axis_settings[_axis_index]->stallguard->get()); axis_settings[_axis_index]->stallguard->get());
TMC2130_n ::DRV_STATUS_t status { 0 }; // a useful struct to access the bits.
status.sr = tmcstepper->DRV_STATUS();
// these only report if there is a fault condition
report_open_load(status);
report_short_to_ground(status);
report_over_temp(status);
report_short_to_ps(status);
// grbl_msg_sendf(CLIENT_SERIAL,
// MsgLevel::Info,
// "%s Status Register %08x GSTAT %02x",
// reportAxisNameMsg(_axis_index, _dual_axis_index),
// status.sr,
// tmcstepper->GSTAT());
} }
// calculate a tstep from a rate // calculate a tstep from a rate
@@ -366,4 +375,59 @@ namespace Motors {
reportTaskStackSize(uxHighWaterMark); reportTaskStackSize(uxHighWaterMark);
} }
} }
// =========== Reporting functions ========================
bool TrinamicDriver::report_open_load(TMC2130_n ::DRV_STATUS_t status) {
if (status.ola || status.olb) {
grbl_msg_sendf(CLIENT_SERIAL,
MsgLevel::Info,
"%s Driver Open Load a:%s b:%s",
reportAxisNameMsg(_axis_index, _dual_axis_index),
status.ola ? "Y" : "N",
status.olb ? "Y" : "N");
return true;
}
return false; // no error
}
bool TrinamicDriver::report_short_to_ground(TMC2130_n ::DRV_STATUS_t status) {
if (status.s2ga || status.s2gb) {
grbl_msg_sendf(CLIENT_SERIAL,
MsgLevel::Info,
"%s Driver Short Coil a:%s b:%s",
reportAxisNameMsg(_axis_index, _dual_axis_index),
status.s2ga ? "Y" : "N",
status.s2gb ? "Y" : "N");
return true;
}
return false; // no error
}
bool TrinamicDriver::report_over_temp(TMC2130_n ::DRV_STATUS_t status) {
if (status.ot || status.otpw) {
grbl_msg_sendf(CLIENT_SERIAL,
MsgLevel::Info,
"%s Driver Temp Warning:%s Fault:%s",
reportAxisNameMsg(_axis_index, _dual_axis_index),
status.otpw ? "Y" : "N",
status.ot ? "Y" : "N");
return true;
}
return false; // no error
}
bool TrinamicDriver::report_short_to_ps(TMC2130_n ::DRV_STATUS_t status) {
// check for short to power supply
if ((status.sr & bit(12)) || (status.sr & bit(13))) {
grbl_msg_sendf(CLIENT_SERIAL,
MsgLevel::Info,
"%s Driver Short vsa:%s vsb:%s",
reportAxisNameMsg(_axis_index, _dual_axis_index),
(status.sr & bit(12)) ? "Y" : "N",
(status.sr & bit(13)) ? "Y" : "N");
return true;
}
return false; // no error
}
} }

View File

@@ -78,9 +78,7 @@ namespace Motors {
uint8_t cs_pin, uint8_t cs_pin,
uint16_t driver_part_number, uint16_t driver_part_number,
float r_sense) : float r_sense) :
TrinamicDriver(axis_index, step_pin, dir_pin, disable_pin, TrinamicDriver(axis_index, step_pin, dir_pin, disable_pin, cs_pin, driver_part_number, r_sense, get_next_index()) {}
cs_pin, driver_part_number, r_sense, get_next_index())
{}
TrinamicDriver(uint8_t axis_index, TrinamicDriver(uint8_t axis_index,
uint8_t step_pin, uint8_t step_pin,
@@ -112,18 +110,23 @@ namespace Motors {
bool _disabled; bool _disabled;
TrinamicMode _mode = TrinamicMode::None; TrinamicMode _mode = TrinamicMode::None;
bool test(); bool test();
void set_mode(bool isHoming); void set_mode(bool isHoming);
void trinamic_test_response(); void trinamic_test_response();
void trinamic_stepper_enable(bool enable); void trinamic_stepper_enable(bool enable);
bool report_open_load(TMC2130_n ::DRV_STATUS_t status);
bool report_short_to_ground(TMC2130_n ::DRV_STATUS_t status);
bool report_over_temp(TMC2130_n ::DRV_STATUS_t status);
bool report_short_to_ps(TMC2130_n ::DRV_STATUS_t status);
uint8_t get_next_index(); uint8_t get_next_index();
// Linked list of Trinamic driver instances, used by the // Linked list of Trinamic driver instances, used by the
// StallGuard reporting task. // StallGuard reporting task.
static TrinamicDriver* List; static TrinamicDriver* List;
TrinamicDriver* link; TrinamicDriver* link;
static void readSgTask(void*); static void readSgTask(void*);
protected: protected:
void config_message() override; void config_message() override;

View File

@@ -156,9 +156,13 @@ Error list_settings(const char* value, WebUI::AuthenticationLevel auth_level, We
} }
Error list_changed_settings(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) { Error list_changed_settings(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) {
for (Setting* s = Setting::List; s; s = s->next()) { for (Setting* s = Setting::List; s; s = s->next()) {
const char* value = s->getStringValue(); const char* value = s->getStringValue();
if (!auth_failed(s, value, auth_level) && strcmp(value, s->getDefaultString())) { const char* defval = s->getDefaultString();
show_setting(s->getName(), value, NULL, out); if (!auth_failed(s, value, auth_level) && strcmp(value, defval)) {
String message = "(Default=";
message += defval;
message += ")";
show_setting(s->getName(), value, message.c_str(), out);
} }
} }
grbl_sendf(out->client(), "(Passwords not shown)\r\n"); grbl_sendf(out->client(), "(Passwords not shown)\r\n");